]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - packages/devs/can/loop/v2_0/tests/can_nonblock.c
unified MX27, MX25, MX37 trees
[karo-tx-redboot.git] / packages / devs / can / loop / v2_0 / tests / can_nonblock.c
1 //==========================================================================
2 //
3 //        can_nonblock.c
4 //
5 //        CAN driver test of nonblocking calls
6 //
7 //==========================================================================
8 //####ECOSGPLCOPYRIGHTBEGIN####
9 // -------------------------------------------
10 // This file is part of eCos, the Embedded Configurable Operating System.
11 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, 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 version.
16 //
17 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
18 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
20 // for more details.
21 //
22 // You should have received a copy of the GNU General Public License along
23 // with eCos; if not, write to the Free Software Foundation, Inc.,
24 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
25 //
26 // As a special exception, if other files instantiate templates or use macros
27 // or inline functions from this file, or you compile this file and link it
28 // with other works to produce a work based on this file, this file does not
29 // by itself cause the resulting work to be covered by the GNU General Public
30 // License. However the source code for this file must still be made available
31 // in accordance with section (3) of the GNU General Public License.
32 //
33 // This exception does not invalidate any other reasons why a work based on
34 // this file might be covered by the GNU General Public License.
35 //
36 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
37 // at http://sources.redhat.com/ecos/ecos-license/
38 // -------------------------------------------
39 //####ECOSGPLCOPYRIGHTEND####
40 //==========================================================================
41 //#####DESCRIPTIONBEGIN####
42 //
43 // Author(s):     Uwe Kindler
44 // Contributors:  Uwe Kindler
45 // Date:          2005-08-14
46 // Description:   CAN driver test of nonblocking callst
47 //####DESCRIPTIONEND####
48
49
50 //===========================================================================
51 //                                INCLUDES
52 //===========================================================================
53 #include <pkgconf/system.h>
54
55 #include <cyg/infra/testcase.h>         // test macros
56 #include <cyg/infra/cyg_ass.h>          // assertion macros
57 #include <cyg/infra/diag.h>
58
59 // Package requirements
60 #if defined(CYGPKG_IO_CAN) && defined(CYGPKG_KERNEL)
61
62 #include <pkgconf/kernel.h>
63 #include <cyg/io/io.h>
64 #include <cyg/io/canio.h>
65
66 // Package option requirements
67 #if defined(CYGFUN_KERNEL_API_C)
68
69 #include <cyg/hal/hal_arch.h>           // CYGNUM_HAL_STACK_SIZE_TYPICAL
70 #include <cyg/kernel/kapi.h>
71
72 // Package option requirements
73 #if defined(CYGOPT_IO_CAN_SUPPORT_NONBLOCKING)
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 can0_thread;
90 thread_data_t      can0_thread_data;
91
92
93 cyg_io_handle_t    hDrvFlexCAN;
94
95
96 //===========================================================================
97 //                          LOCAL FUNCTIONS
98 //===========================================================================
99 #include "can_test_aux.inl" // include CAN test auxiliary functions
100
101
102 //===========================================================================
103 //                             READER THREAD 
104 //===========================================================================
105 void can0_thread(cyg_addrword_t data)
106 {
107     cyg_uint32             len;
108     cyg_uint32             blocking;
109     cyg_can_event          rx_event;
110     Cyg_ErrNo              res;
111
112     blocking = 0;
113     len = sizeof(blocking);
114     if (ENOERR != cyg_io_set_config(hDrvFlexCAN, CYG_IO_SET_CONFIG_READ_BLOCKING ,&blocking, &len))
115     {
116         CYG_TEST_FAIL_FINISH("Error writing config of /dev/can0");
117     } 
118     
119     len = sizeof(rx_event);  
120     res = cyg_io_read(hDrvFlexCAN, &rx_event, &len);
121             
122     if (-EAGAIN == res)
123     {
124         CYG_TEST_PASS_FINISH("can_test1 test OK");
125     }
126     else if (-EINTR == res)
127     {
128         CYG_TEST_PASS_FINISH("can_test1 test OK");
129     }
130     else
131     {
132         CYG_TEST_FAIL_FINISH("Error reading from /dev/can0");
133     }           
134 }
135
136
137 void
138 cyg_start(void)
139 {
140     cyg_uint32     len;
141     cyg_can_info_t can_cfg;
142     
143     CYG_TEST_INIT();
144     
145     //
146     // open flexcan device driver
147     //
148     if (ENOERR != cyg_io_lookup("/dev/can0", &hDrvFlexCAN)) 
149     {
150         CYG_TEST_FAIL_FINISH("Error opening /dev/can0");
151     }
152     
153     //
154     // setup CAN baudrate 250 KBaud
155     //
156     can_cfg.baud = CYGNUM_CAN_KBAUD_250;
157     len = sizeof(can_cfg);
158     if (ENOERR != cyg_io_set_config(hDrvFlexCAN, CYG_IO_SET_CONFIG_CAN_INFO ,&can_cfg, &len))
159     {
160         CYG_TEST_FAIL_FINISH("Error writing config of /dev/can0");
161     }
162     
163     //
164     // create the main thread
165     //
166     cyg_thread_create(4, can0_thread, 
167                         (cyg_addrword_t) 0,
168                                 "can0_thread", 
169                                 (void *) can0_thread_data.stack, 
170                                 1024 * sizeof(long),
171                                 &can0_thread_data.hdl, 
172                                 &can0_thread_data.obj);
173                                 
174     cyg_thread_resume(can0_thread_data.hdl);
175     
176     cyg_scheduler_start();
177 }
178
179 #else // #if defined(CYGOPT_IO_CAN_SUPPORT_NONBLOCKING)
180 #define N_A_MSG "Needs nonblocking calls"
181 #endif
182
183 #else // CYGFUN_KERNEL_API_C
184 #define N_A_MSG "Needs kernel C API"
185 #endif
186
187 #else // CYGPKG_IO_CAN && CYGPKG_KERNEL
188 #define N_A_MSG "Needs IO/CAN and Kernel"
189 #endif
190
191 #ifdef N_A_MSG
192 void
193 cyg_start( void )
194 {
195     CYG_TEST_INIT();
196     CYG_TEST_NA( N_A_MSG);
197 }
198 #endif // N_A_MSG
199
200 // EOF can_nonblock.c