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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [devs/] [adc/] [arm/] [lpc24xx/] [current/] [tests/] [lpc24xx_adc_test.c] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
//==========================================================================
2
//
3
//        lpc24xx_adc_test.c
4
//
5
//        ADC performance test for LPC24xxx
6
//
7
//==========================================================================
8
// ####ECOSGPLCOPYRIGHTBEGIN####                                            
9
// -------------------------------------------                              
10
// This file is part of eCos, the Embedded Configurable Operating System.   
11
// Copyright (C) 2008 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):     Uwe Kindler
43
// Contributors:
44
// Date:          2008-11-01
45
// Description:   ADC performance test for LPC24xxx
46
//####DESCRIPTIONEND####
47
 
48
 
49
//===========================================================================
50
//                                INCLUDES
51
//===========================================================================
52
#include <pkgconf/system.h>
53
 
54
#include <cyg/infra/testcase.h>         // test macros
55
#include <cyg/infra/cyg_ass.h>          // assertion macros
56
#include <cyg/infra/diag.h>
57
#include <cyg/hal/hal_diag.h>
58
#include <cyg/hal/hal_arch.h>           // CYGNUM_HAL_STACK_SIZE_TYPICAL
59
 
60
// Package requirements
61
#if defined(CYGPKG_IO_ADC) && defined(CYGPKG_KERNEL)
62
 
63
#include <pkgconf/kernel.h>
64
#include <cyg/io/io.h>
65
#include <cyg/io/adc.h>
66
#include <pkgconf/devs_adc_arm_lpc24xx.h>
67
 
68
// Package option requirements
69
#if defined(CYGFUN_KERNEL_API_C)
70
 
71
#include <cyg/kernel/kapi.h>
72
 
73
#if CYGINT_DEVS_ADC_ARM_LPC24XX_CHANNELS > 0
74
 
75
//===========================================================================
76
//                               DATA TYPES
77
//===========================================================================
78
typedef struct st_thread_data
79
{
80
    cyg_thread   obj;
81
    long         stack[CYGNUM_HAL_STACK_SIZE_TYPICAL];
82
    cyg_handle_t hdl;
83
} thread_data_t;
84
 
85
 
86
//===========================================================================
87
//                              LOCAL DATA
88
//===========================================================================
89
cyg_thread_entry_t adc_thread;
90
thread_data_t      adc_thread_data;
91
 
92
 
93
//===========================================================================
94
//                             ADC THREAD
95
//===========================================================================
96
void adc_thread(cyg_addrword_t data)
97
{
98
    int             res;
99
    cyg_io_handle_t handle[8]     = {0, 0, 0, 0, 0, 0, 0, 0};
100
    cyg_uint32      sample_cnt[8] = {0, 0, 0, 0, 0, 0, 0, 0};
101
    cyg_uint32      cfg_data;
102
    cyg_uint32      len;
103
    cyg_uint32      start_time;
104
    cyg_uint32      end_time;
105
    int             i;
106
    cyg_uint8       seconds = 0;
107
    float           final_seconds;
108
    cyg_uint32      samples_expected;
109
 
110
 
111
    diag_printf("This test reads samples from all enabled ADC channels.\n"
112
                "Each second the number of already acquired samples\n"
113
                "will be printed. After 10 seconds all ADC channels\n"
114
                "will be stopped and each ADC buffer will be read until\n"
115
                "it is empty. If the number of acquired samples is much\n"
116
                "smaller than the number of expected samples, then you\n"
117
                "should lower the sample rate.\n\n");
118
 
119
    // Get a handle for ADC device 0 channel 1 - 8
120
    res = cyg_io_lookup( "/dev/adc00", &handle[0]);
121
    res = cyg_io_lookup( "/dev/adc01", &handle[1]);
122
    res = cyg_io_lookup( "/dev/adc02", &handle[2]);
123
    res = cyg_io_lookup( "/dev/adc03", &handle[3]);
124
    res = cyg_io_lookup( "/dev/adc04", &handle[4]);
125
    res = cyg_io_lookup( "/dev/adc05", &handle[5]);
126
    res = cyg_io_lookup( "/dev/adc06", &handle[6]);
127
    res = cyg_io_lookup( "/dev/adc07", &handle[7]);
128
 
129
    //
130
    // switch all channels to non blocking
131
    //
132
    for (i = 0; i < 8; ++i)
133
    {
134
        if (handle[i])
135
        {
136
            cfg_data = 0;
137
            len = sizeof(cfg_data);
138
            res = cyg_io_set_config(handle[i],
139
                                    CYG_IO_SET_CONFIG_READ_BLOCKING,
140
                                    &cfg_data,
141
                                    &len);
142
            if (ENOERR != res)
143
            {
144
                CYG_TEST_FAIL_FINISH("Error switching ADC channel to non blocking");
145
            }
146
            sample_cnt[i] = 0;
147
        } // if (handle[i])
148
    } // for (i = 0; i < 8; ++i)
149
 
150
    start_time = cyg_current_time();
151
    do
152
    {
153
        for (i = 0; i < 8; ++i)
154
        {
155
            if (handle[i])
156
            {
157
                cyg_adc_sample_t sample;
158
 
159
                // read a sample from the channel
160
                do
161
                {
162
                    cyg_uint32 len = sizeof(sample);
163
                    res = cyg_io_read( handle[i], &sample, &len );
164
                }
165
                while (-EAGAIN == res);
166
                if (ENOERR == res)
167
                {
168
                    sample_cnt[i]++;
169
                }
170
            } // if (handle[i])
171
        }
172
        //
173
        // print number of acquired samples - if one second is expired.
174
        // we expect that the number of acquired samples is nearly the
175
        // sample rate
176
        //
177
        end_time = cyg_current_time();
178
        if ((end_time - start_time) >= 100)
179
        {
180
            start_time = end_time;
181
            diag_printf("%d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\n",
182
                        sample_cnt[0],
183
                        sample_cnt[1],
184
                        sample_cnt[2],
185
                        sample_cnt[3],
186
                        sample_cnt[4],
187
                        sample_cnt[5],
188
                        sample_cnt[6],
189
                        sample_cnt[7]);
190
            seconds++;
191
        } // if ((end_time - start_time) >= 100)
192
    } while (seconds < 10);
193
 
194
    //
195
    // Now stop all channels
196
    //
197
    for (i = 0; i < 8; ++i)
198
    {
199
        if (handle[i])
200
        {
201
            res = cyg_io_set_config(handle[i],
202
                                    CYG_IO_SET_CONFIG_ADC_DISABLE,
203
                                    0,
204
                                    0);
205
            if (ENOERR != res)
206
            {
207
                CYG_TEST_FAIL_FINISH("Error disabling ADC channel");
208
            }
209
        } // if (handle[i])
210
    }
211
    end_time = cyg_current_time();
212
    end_time = seconds * 1000 + (end_time - start_time) * 10;
213
    final_seconds = end_time / 1000.0;
214
 
215
    //
216
    // Now read all remaining samples from buffer
217
    //
218
    for (i = 0; i < 8; ++i)
219
    {
220
        if (handle[i])
221
        {
222
            do
223
            {
224
                cyg_adc_sample_t sample;
225
                cyg_uint32 len = sizeof(sample);
226
                res = cyg_io_read( handle[i], &sample, &len );
227
                if (ENOERR == res)
228
                {
229
                    sample_cnt[i]++;
230
                }
231
            } while (ENOERR == res);
232
        } // if (handle[i])
233
    }
234
 
235
    diag_printf("\n\n----------------------------------------\n");
236
    samples_expected = final_seconds * CYGNUM_DEVS_ADC_ARM_LPC24XX_DEFAULT_RATE;
237
    diag_printf("Samples expected after %d milliseconds: %d\n",
238
                end_time, samples_expected);
239
    diag_printf("Samples read (per channel):\n");
240
    diag_printf("%d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\n",
241
                sample_cnt[0],
242
                sample_cnt[1],
243
                sample_cnt[2],
244
                sample_cnt[3],
245
                sample_cnt[4],
246
                sample_cnt[5],
247
                sample_cnt[6],
248
                sample_cnt[7]);
249
 
250
    CYG_TEST_PASS_FINISH("ADC test OK");
251
}
252
 
253
 
254
void
255
cyg_start(void)
256
{
257
    CYG_TEST_INIT();
258
 
259
    //
260
    // create the main ADC test thread
261
    //
262
    cyg_thread_create(4, adc_thread,
263
                      (cyg_addrword_t) 0,
264
                      "lpc24xx_adc_thread",
265
                      (void *) adc_thread_data.stack,
266
                      1024 * sizeof(long),
267
                      &adc_thread_data.hdl,
268
                      &adc_thread_data.obj);
269
 
270
    cyg_thread_resume(adc_thread_data.hdl);
271
 
272
    cyg_scheduler_start();
273
}
274
#else // CYGINT_DEVS_ADC_ARM_LPC24XX_CHANNELS > 0
275
#define N_A_MSG "Needs at least one enabled ADC channel"
276
#endif
277
 
278
#else // CYGFUN_KERNEL_API_C
279
#define N_A_MSG "Needs kernel C API"
280
#endif
281
 
282
#else // CYGPKG_IO_ADC && CYGPKG_KERNEL
283
#define N_A_MSG "Needs Kernel and ADC support"
284
#endif
285
 
286
#ifdef N_A_MSG
287
void
288
cyg_start( void )
289
{
290
    CYG_TEST_INIT();
291
    CYG_TEST_NA(N_A_MSG);
292
}
293
#endif // N_A_MSG
294
 
295
 
296
// EOF can_tx.c
297
 
298
//---------------------------------------------------------------------------
299
// eof i2c_test.c
300
 

powered by: WebSVN 2.1.0

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