]> git.karo-electronics.de Git - karo-tx-redboot.git/blob - packages/io/can/v2_0/tests/can_hdi.c
Initial revision
[karo-tx-redboot.git] / packages / io / can / v2_0 / tests / can_hdi.c
1 //==========================================================================
2 //
3 //        can_hdi.c
4 //
5 //        CAN hardware description information test
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:          2007-03-22
46 // Description:   CAN hardware desciption information test
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
73 //===========================================================================
74 //                               DATA TYPES
75 //===========================================================================
76 typedef struct st_thread_data
77 {
78     cyg_thread   obj;
79     long         stack[CYGNUM_HAL_STACK_SIZE_TYPICAL];
80     cyg_handle_t hdl;
81 } thread_data_t;
82
83
84 //===========================================================================
85 //                              LOCAL DATA
86 //===========================================================================
87 cyg_thread_entry_t can0_thread;
88 thread_data_t      can0_thread_data;
89
90
91 cyg_io_handle_t    hCAN0;
92
93
94 //===========================================================================
95 //                          LOCAL FUNCTIONS
96 //===========================================================================
97 #include "can_test_aux.inl" // include CAN test auxiliary functions
98
99
100 //===========================================================================
101 // Main thread
102 //===========================================================================
103 void can0_thread(cyg_addrword_t data)
104 {
105     cyg_uint32             len;
106     cyg_can_hdi            hdi;
107     cyg_can_msgbuf_info    msgbox_info;
108
109     
110     //
111     // Query information about hardware of CAN controller
112     //
113     len = sizeof(hdi);
114     if (ENOERR != cyg_io_get_config(hCAN0, CYG_IO_GET_CONFIG_CAN_HDI ,&hdi, &len))
115     {
116         CYG_TEST_FAIL_FINISH("Error reading config of /dev/can0");
117     } 
118     
119     //
120     // Check type of CAN controller - type of supported CAN frames
121     //
122     diag_printf("\n\nSupported message formats:\n");
123     if (hdi.support_flags & CYGNUM_CAN_HDI_FRAMETYPE_STD)
124     {
125         diag_printf("  Standard CAN (2.0A):         yes\n");
126         diag_printf("  Extended CAN (2.0B):         no\n");
127     } 
128     else if (hdi.support_flags & CYGNUM_CAN_HDI_FRAMETYPE_EXT_PASSIVE)
129     {
130         diag_printf("  Standard CAN (2.0A):         yes\n");
131         diag_printf("  Extended CAN (2.0B):         passive\n"); 
132     }
133     else if (hdi.support_flags & CYGNUM_CAN_HDI_FRAMETYPE_EXT_ACTIVE)
134     {
135         diag_printf("  Standard CAN (2.0A):         yes\n");
136         diag_printf("  Extended CAN (2.0B):         yes\n"); 
137     }
138     
139     //
140     // Check if this is a FullCAN controller
141     //
142     diag_printf("\nController type:               ");
143     if (hdi.support_flags & CYGNUM_CAN_HDI_FULLCAN)
144     {
145         diag_printf("FullCAN\n");
146         //
147         // FullCAN means the controller supports a number of message buffers.
148         // Now query number of available and free message buffers
149         //
150         len = sizeof(msgbox_info);
151         if (ENOERR != cyg_io_get_config(hCAN0, CYG_IO_GET_CONFIG_CAN_MSGBUF_INFO ,&msgbox_info, &len))
152         {
153              CYG_TEST_FAIL_FINISH("Error reading config of /dev/can0");
154         } 
155     
156         diag_printf("  Message buffers:             %d\n", msgbox_info.count);
157         diag_printf("  Message buffers free:        %d\n", msgbox_info.free);
158     }
159     else
160     {
161         diag_printf("BasicCAN\n");      
162     }
163         
164     //
165     // Check if automatic baudrate detection is supported
166     //
167     if (hdi.support_flags & CYGNUM_CAN_HDI_AUTBAUD)
168     {
169         diag_printf("\nAutomatic baudrate detection:  supported\n"); 
170     }
171     
172     //
173     // Check if driver supports timestamps
174     //
175     if (hdi.support_flags & CYGNUM_CAN_HDI_TIMESTAMP)
176     {
177         diag_printf("Timestamps:                    supported\n"); 
178     }
179     
180     diag_printf("\n\n"); 
181     CYG_TEST_PASS_FINISH("can_hdi test OK");
182 }
183
184
185 void
186 cyg_start(void)
187 {
188     CYG_TEST_INIT();
189     
190     //
191     // open CAN device driver
192     //
193     if (ENOERR != cyg_io_lookup("/dev/can0", &hCAN0)) 
194     {
195         CYG_TEST_FAIL_FINISH("Error opening /dev/can0");
196     }
197     
198    
199     //
200     // create the two threads which access the CAN device driver
201     // a reader thread with a higher priority and a writer thread
202     // with a lower priority
203     //
204     cyg_thread_create(4, can0_thread, 
205                         (cyg_addrword_t) 0,
206                                 "can0_thread", 
207                                 (void *) can0_thread_data.stack, 
208                                 1024 * sizeof(long),
209                                 &can0_thread_data.hdl, 
210                                 &can0_thread_data.obj);
211                                 
212     cyg_thread_resume(can0_thread_data.hdl);
213     
214     cyg_scheduler_start();
215 }
216
217 #else // CYGFUN_KERNEL_API_C
218 #define N_A_MSG "Needs kernel C API"
219 #endif
220
221 #else // CYGPKG_IO_CAN && CYGPKG_KERNEL
222 #define N_A_MSG "Needs IO/CAN and Kernel"
223 #endif
224
225 #ifdef N_A_MSG
226 void
227 cyg_start( void )
228 {
229     CYG_TEST_INIT();
230     CYG_TEST_NA( N_A_MSG);
231 }
232 #endif // N_A_MSG
233
234 //---------------------------------------------------------------------------
235 // EOF can_hdi.c