1 //==========================================================================
5 // CAN test of all supported baudrates
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.
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.
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
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.
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.
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.
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####
43 // Author(s): Uwe Kindler
44 // Contributors: Uwe Kindler
46 // Description: CAN LPC2xxx baudrate test
47 //####DESCRIPTIONEND####
50 //===========================================================================
52 //===========================================================================
53 #include <pkgconf/system.h>
55 #include <cyg/infra/testcase.h> // test macros
56 #include <cyg/infra/cyg_ass.h> // assertion macros
57 #include <cyg/infra/diag.h>
59 // Package requirements
60 #if defined(CYGPKG_IO_CAN) && defined(CYGPKG_KERNEL)
62 #include <pkgconf/kernel.h>
63 #include <cyg/io/io.h>
64 #include <cyg/io/canio.h>
67 // Package option requirements
68 #if defined(CYGFUN_KERNEL_API_C)
70 #include <cyg/hal/hal_arch.h> // CYGNUM_HAL_STACK_SIZE_TYPICAL
71 #include <cyg/kernel/kapi.h>
74 #include "can_test_aux.inl" // include CAN test auxiliary functions
75 //===========================================================================
77 //===========================================================================
78 typedef struct st_thread_data
81 long stack[CYGNUM_HAL_STACK_SIZE_TYPICAL];
86 //===========================================================================
88 //===========================================================================
89 cyg_thread_entry_t can0_thread;
90 thread_data_t can0_thread_data;
95 // The table of baudrates to test
97 static cyg_can_baud_rate_t baudrate_tbl[9] =
102 CYGNUM_CAN_KBAUD_100,
103 CYGNUM_CAN_KBAUD_125,
104 CYGNUM_CAN_KBAUD_250,
105 CYGNUM_CAN_KBAUD_500,
106 CYGNUM_CAN_KBAUD_800,
107 CYGNUM_CAN_KBAUD_1000,
111 // String table forprinting supported baudrates
113 static char* baudrate_strings_tbl[9] =
127 //===========================================================================
129 //===========================================================================
130 void can0_thread(cyg_addrword_t data)
133 cyg_can_event rx_event;
135 cyg_can_info_t can_info;
137 diag_printf("\n\nWhen the LPC2xxx driver selects a new baudrate then you need\n"
138 "to setup your hardware to the new baudrate and send one CAN\n"
139 "single CAN standard message.\n");
141 // Test all supported baudrates
143 for (i = 0; i < 9; ++i)
145 diag_printf("\n\nBaudrate: %s Kbaud\n", baudrate_strings_tbl[i]);
146 can_info.baud = baudrate_tbl[i];
147 len = sizeof(can_info);
148 if (ENOERR != cyg_io_set_config(hCAN, CYG_IO_SET_CONFIG_CAN_INFO, &can_info, &len))
150 diag_printf("not supported\n");
155 diag_printf("waiting for CAN message...\n");
158 len = sizeof(rx_event);
160 // First receive CAN event from real CAN hardware
162 len = sizeof(rx_event);
163 if (ENOERR != cyg_io_read(hCAN, &rx_event, &len))
165 CYG_TEST_FAIL_FINISH("Error reading from channel 0");
168 if (rx_event.flags & CYGNUM_CAN_EVENT_RX)
170 print_can_msg(&rx_event.msg, "RX chan 1:");
171 } // if (rx_event.flags & CYGNUM_CAN_EVENT_RX)
174 print_can_flags(rx_event.flags, "");
175 CYG_TEST_FAIL_FINISH("Rx message expected");
177 } // for (i = 0; i < 9; ++i)
179 CYG_TEST_PASS_FINISH("CAN baudrate test OK");
183 //===========================================================================
185 //===========================================================================
191 // open CAN device driver channel 1
193 if (ENOERR != cyg_io_lookup(CYGPKG_DEVS_CAN_LPC2XXX_CAN0_NAME, &hCAN))
195 CYG_TEST_FAIL_FINISH("Error opening CAN channel 0");
199 // create the main thread
201 cyg_thread_create(5, can0_thread,
204 (void *) can0_thread_data.stack,
206 &can0_thread_data.hdl,
207 &can0_thread_data.obj);
209 cyg_thread_resume(can0_thread_data.hdl);
211 cyg_scheduler_start();
213 #else // CYGFUN_KERNEL_API_C
214 #define N_A_MSG "Needs kernel C API"
217 #else // CYGPKG_IO_CAN && CYGPKG_KERNEL
218 #define N_A_MSG "Needs Kernel"
226 CYG_TEST_NA(N_A_MSG);
230 //---------------------------------------------------------------------------