OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [io/] [adc/] [current/] [tests/] [adc1.c] - Blame information for rev 825

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
//==========================================================================
2
//
3
//        adc1.c
4
//
5
//        ADC test
6
//
7
//==========================================================================
8
// ####ECOSGPLCOPYRIGHTBEGIN####                                            
9
// -------------------------------------------                              
10
// This file is part of eCos, the Embedded Configurable Operating System.   
11
// Copyright (C) 2009 Free Software Foundation, Inc.                        
12
//
13
// eCos is free software; you can redistribute it and/or modify it under    
14
// the terms of the GNU General Public License as published by the Free     
15
// Software Foundation; either version 2 or (at your option) any later      
16
// version.                                                                 
17
//
18
// eCos is distributed in the hope that it will be useful, but WITHOUT      
19
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or    
20
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License    
21
// for more details.                                                        
22
//
23
// You should have received a copy of the GNU General Public License        
24
// along with eCos; if not, write to the Free Software Foundation, Inc.,    
25
// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.            
26
//
27
// As a special exception, if other files instantiate templates or use      
28
// macros or inline functions from this file, or you compile this file      
29
// and link it with other works to produce a work based on this file,       
30
// this file does not by itself cause the resulting work to be covered by   
31
// the GNU General Public License. However the source code for this file    
32
// must still be made available in accordance with section (3) of the GNU   
33
// General Public License v2.                                               
34
//
35
// This exception does not invalidate any other reasons why a work based    
36
// on this file might be covered by the GNU General Public License.         
37
// -------------------------------------------                              
38
// ####ECOSGPLCOPYRIGHTEND####                                              
39
//==========================================================================
40
//#####DESCRIPTIONBEGIN####
41
//
42
// Author(s):     Simon Kallweit <simon.kallweit@intefo.ch>
43
// Contributors:
44
// Date:          2009-03-02
45
// Description:   ADC test
46
//####DESCRIPTIONEND####
47
 
48
#include <pkgconf/system.h>
49
 
50
#include <cyg/infra/testcase.h>
51
#include <cyg/infra/cyg_ass.h>
52
#include <cyg/infra/diag.h>
53
#include <cyg/hal/hal_diag.h>
54
#include <cyg/hal/hal_arch.h>
55
 
56
// Package requirements
57
#if defined(CYGPKG_IO_ADC) && defined(CYGPKG_KERNEL)
58
 
59
#include <pkgconf/kernel.h>
60
#include <cyg/io/io.h>
61
#include <cyg/io/devtab.h>
62
#include <cyg/io/adc.h>
63
 
64
// Package option requirements
65
#if defined(CYGFUN_KERNEL_API_C)
66
 
67
#include <cyg/kernel/kapi.h>
68
 
69
#define TEST_RATE                   100 // Data acquisition rate for test
70
#define TEST_SAMPLES                10  // Number of samples to acquire
71
 
72
// Thread data
73
cyg_handle_t thread_handle;
74
cyg_thread thread_data;
75
cyg_uint8 thread_stack[CYGNUM_HAL_STACK_SIZE_TYPICAL];
76
 
77
static void
78
test_channel(const char *dev, cyg_io_handle_t channel)
79
{
80
    Cyg_ErrNo res;
81
    cyg_uint32 cfg_data;
82
    cyg_uint32 len;
83
    cyg_adc_sample_t sample;
84
    int count;
85
 
86
    diag_printf("\nTesting ADC channel '%s'\n", dev);
87
 
88
    // Disable channel
89
    res = cyg_io_set_config(channel, CYG_IO_SET_CONFIG_ADC_DISABLE, 0, 0);
90
    if (res != ENOERR)
91
        CYG_TEST_FAIL_FINISH("Failed to disable ADC channel");
92
 
93
    // Make channel non-blocking
94
    cfg_data = 0;
95
    len = sizeof(cfg_data);
96
    res = cyg_io_set_config(channel, CYG_IO_SET_CONFIG_READ_BLOCKING,
97
                            &cfg_data, &len);
98
    if (res != ENOERR)
99
        CYG_TEST_FAIL_FINISH("Failed to make ADC channel non-blocking");
100
 
101
    // Set channel sampling rate
102
    cfg_data = TEST_RATE;
103
    len = sizeof(cfg_data);
104
    res = cyg_io_set_config(channel, CYG_IO_SET_CONFIG_ADC_RATE,
105
                            &cfg_data, &len);
106
    if (res != ENOERR)
107
        CYG_TEST_FAIL_FINISH("Failed to set ADC channel sampling rate");
108
 
109
    // Flush channel
110
    do {
111
        len = sizeof(sample);
112
        res = cyg_io_read(channel, &sample, &len);
113
    } while (res == ENOERR);
114
 
115
    // Enable channel
116
    res = cyg_io_set_config(channel, CYG_IO_SET_CONFIG_ADC_ENABLE, 0, 0);
117
    if (res != ENOERR)
118
        CYG_TEST_FAIL_FINISH("Failed to enable ADC channel");
119
 
120
    // Read from channel
121
    count = 0;
122
    while (count < TEST_SAMPLES) {
123
        len = sizeof(sample);
124
        res = cyg_io_read(channel, &sample, &len);
125
        if (res == ENOERR) {
126
            diag_printf("%d\n", sample);
127
            count++;
128
        }
129
    }
130
 
131
    // Disable channel
132
    res = cyg_io_set_config(channel, CYG_IO_SET_CONFIG_ADC_DISABLE, 0, 0);
133
    if (res != ENOERR)
134
        CYG_TEST_FAIL_FINISH("Failed to disable ADC channel");
135
}
136
 
137
static void
138
adc_thread(cyg_addrword_t data)
139
{
140
    cyg_io_handle_t channel;
141
    cyg_devtab_entry_t *t;
142
 
143
    CYG_TEST_INFO("ADC test");
144
 
145
    for (t = &__DEVTAB__[0]; t != &__DEVTAB_END__; t++) {
146
        if (t->handlers != &cyg_io_adc_devio)
147
            continue;
148
        if (cyg_io_lookup(t->name, &channel) == ENOERR) {
149
            test_channel(t->name, channel);
150
        } else {
151
            CYG_TEST_FAIL_FINISH("Cannot open ADC channel");
152
        }
153
    }
154
 
155
    CYG_TEST_PASS_FINISH("ADC test OK");
156
}
157
 
158
 
159
void
160
cyg_start(void)
161
{
162
    CYG_TEST_INIT();
163
 
164
    // Create the main ADC test thread
165
    cyg_thread_create(
166
        4,
167
        adc_thread,
168
        (cyg_addrword_t) 0,
169
        "adc1",
170
        thread_stack,
171
        sizeof(thread_stack),
172
        &thread_handle,
173
        &thread_data
174
    );
175
    cyg_thread_resume(thread_handle);
176
    cyg_scheduler_start();
177
}
178
 
179
#else // CYGFUN_KERNEL_API_C
180
#define N_A_MSG "Needs kernel C API"
181
#endif
182
 
183
#else // CYGPKG_IO_ADC && CYGPKG_KERNEL
184
#define N_A_MSG "Needs Kernel and ADC support"
185
#endif
186
 
187
#ifdef N_A_MSG
188
void
189
cyg_start( void )
190
{
191
    CYG_TEST_INIT();
192
    CYG_TEST_NA(N_A_MSG);
193
}
194
#endif // N_A_MSG

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.