1 //==========================================================================
5 // CAN TX test for multiple CAN channels
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 TX test for multiple CAN controller channels
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 //===========================================================================
76 //===========================================================================
77 typedef struct st_thread_data
80 long stack[CYGNUM_HAL_STACK_SIZE_TYPICAL];
85 //===========================================================================
87 //===========================================================================
88 cyg_thread_entry_t can_thread;
89 thread_data_t can0_thread_data;
90 cyg_io_handle_t hCAN_Tbl[4];
93 //===========================================================================
95 //===========================================================================
96 void can_thread(cyg_addrword_t data)
99 cyg_can_message tx_msg;
100 cyg_can_info_t can_info;
101 cyg_can_baud_rate_t baud;
106 // Check that all cannels have the same baudrate
108 #ifdef CYGPKG_DEVS_CAN_LPC2XXX_CAN0
109 len = sizeof(can_info);
110 if (ENOERR != cyg_io_get_config(hCAN_Tbl[0], CYG_IO_GET_CONFIG_CAN_INFO, &can_info, &len))
112 CYG_TEST_FAIL_FINISH("Error reading baudrate of CAN channel 0");
116 baud = can_info.baud;
121 #ifdef CYGPKG_DEVS_CAN_LPC2XXX_CAN1
122 len = sizeof(can_info);
123 if (ENOERR != cyg_io_get_config(hCAN_Tbl[1], CYG_IO_GET_CONFIG_CAN_INFO, &can_info, &len))
125 CYG_TEST_FAIL_FINISH("Error reading baudrate of CAN channel 1");
129 if (i && (baud != can_info.baud))
131 CYG_TEST_FAIL_FINISH("Error - different baudrates for CAN channel 0 and 1");
133 baud = can_info.baud;
138 #ifdef CYGPKG_DEVS_CAN_LPC2XXX_CAN2
139 len = sizeof(can_info);
140 if (ENOERR != cyg_io_get_config(hCAN_Tbl[2], CYG_IO_GET_CONFIG_CAN_INFO, &can_info, &len))
142 CYG_TEST_FAIL_FINISH("Error reading baudrate of CAN channel 2");
146 if (i && (baud != can_info.baud))
148 CYG_TEST_FAIL_FINISH("Error - different baudrates for CAN channel 1 and 2");
150 baud = can_info.baud;
155 #ifdef CYGPKG_DEVS_CAN_LPC2XXX_CAN3
156 len = sizeof(can_info);
157 if (ENOERR != cyg_io_get_config(hCAN_Tbl[3], CYG_IO_GET_CONFIG_CAN_INFO, &can_info, &len))
159 CYG_TEST_FAIL_FINISH("Error reading baudrate of CAN channel 3");
163 if (i && (baud != can_info.baud))
165 CYG_TEST_FAIL_FINISH("Error - different baudrates for CAN channel 2 and 3");
167 baud = can_info.baud;
172 diag_printf("\n\nYou should no receive 4 CAN messages from each active CAN channel\n");
175 // Now each CAN channel sends 10 CAN messages
177 for (i = 0; i < 4; ++i)
181 CYG_CAN_MSG_SET_PARAM(tx_msg, i * 0x100, CYGNUM_CAN_ID_STD, 4, CYGNUM_CAN_FRAME_DATA);
182 tx_msg.data.dwords[0] = 0;
183 tx_msg.data.dwords[1] = 0;
185 diag_snprintf(err_msg, sizeof(err_msg), "Error sending TX using CAN channel %d", i);
186 for (j = 0; j < 4; ++j)
188 tx_msg.id = i * 0x100 + j;
189 tx_msg.data.bytes[0] = j;
190 len = sizeof(tx_msg);
191 if (ENOERR != cyg_io_write(hCAN_Tbl[i], &tx_msg, &len))
193 CYG_TEST_FAIL_FINISH(err_msg);
196 } // if (hCAN_Tbl[i])
197 } // for (i = 0; i < 4; ++i)
199 CYG_TEST_PASS_FINISH("LPC2xxx CAN multi channel TX test OK");
209 #ifdef CYGPKG_DEVS_CAN_LPC2XXX_CAN0
211 // open CAN device driver
213 if (ENOERR != cyg_io_lookup(CYGPKG_DEVS_CAN_LPC2XXX_CAN0_NAME, &hCAN_Tbl[0]))
215 CYG_TEST_FAIL_FINISH("Error opening CAN channel 0");
221 #ifdef CYGPKG_DEVS_CAN_LPC2XXX_CAN1
223 // open CAN device driver
225 if (ENOERR != cyg_io_lookup(CYGPKG_DEVS_CAN_LPC2XXX_CAN1_NAME, &hCAN_Tbl[1]))
227 CYG_TEST_FAIL_FINISH("Error opening CAN channel 1");
233 #ifdef CYGPKG_DEVS_CAN_LPC2XXX_CAN2
235 // open CAN device driver
237 if (ENOERR != cyg_io_lookup(CYGPKG_DEVS_CAN_LPC2XXX_CAN2_NAME, &hCAN_Tbl[2]))
239 CYG_TEST_FAIL_FINISH("Error opening CAN channel 2");
245 #ifdef CYGPKG_DEVS_CAN_LPC2XXX_CAN3
247 // open CAN device driver
249 if (ENOERR != cyg_io_lookup(CYGPKG_DEVS_CAN_LPC2XXX_CAN3_NAME, &hCAN_Tbl[3]))
251 CYG_TEST_FAIL_FINISH("Error opening CAN channel 3");
258 // create the thread that accesses the CAN device driver
260 cyg_thread_create(4, can_thread,
263 (void *) can0_thread_data.stack,
265 &can0_thread_data.hdl,
266 &can0_thread_data.obj);
268 cyg_thread_resume(can0_thread_data.hdl);
270 cyg_scheduler_start();
274 #else // CYGFUN_KERNEL_API_C
275 #define N_A_MSG "Needs kernel C API"
278 #else // CYGPKG_IO_CAN && CYGPKG_KERNEL
279 #define N_A_MSG "Needs Kernel"
287 CYG_TEST_NA(N_A_MSG);
291 //---------------------------------------------------------------------------
292 // EOF can_multichan_tx.c