1 //==========================================================================
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: Simple write test of CAN driver
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>
58 #include <cyg/hal/hal_diag.h>
60 // Package requirements
61 #if defined(CYGPKG_IO_CAN) && defined(CYGPKG_KERNEL)
63 #include <pkgconf/kernel.h>
64 #include <cyg/io/io.h>
65 #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 can0_thread;
89 thread_data_t can0_thread_data;
92 //===========================================================================
94 //===========================================================================
95 #include "can_test_aux.inl" // include CAN test auxiliary functions
98 //===========================================================================
100 //===========================================================================
101 void can0_thread(cyg_addrword_t data)
103 cyg_io_handle_t hCAN0;
106 CYG_CAN_MSG_INIT(tx_msg, 0x001, CYGNUM_CAN_ID_STD, 1, CYGNUM_CAN_FRAME_DATA);
109 // Open device and check return value
111 if (ENOERR != cyg_io_lookup("/dev/can0", &hCAN0))
113 CYG_TEST_FAIL_FINISH("Error opening /dev/can0");
116 #ifdef CYGOPT_IO_CAN_STD_CAN_ID
118 // Now send 1000 messages with standard identifier.
119 // Each message contains the message number in its identifier
120 // and in the first data byte
122 for (i = 0; i < 1000; ++i)
124 CYG_CAN_MSG_SET_STD_ID(tx_msg, i);
125 CYG_CAN_MSG_SET_DATA(tx_msg, 0, i);
126 len = sizeof(tx_msg);
129 // Each message with an odd identifier should be a remote request message
133 CYG_CAN_MSG_SET_FRAME_TYPE(tx_msg, CYGNUM_CAN_FRAME_RTR);
137 CYG_CAN_MSG_SET_FRAME_TYPE(tx_msg, CYGNUM_CAN_FRAME_DATA);
141 // Sending CAN messages is blocking so the thread waits until there is
142 // space in the tx queue
144 if (ENOERR != cyg_io_write(hCAN0, &tx_msg, &len))
146 CYG_TEST_FAIL_FINISH("Error writing to /dev/can0");
151 #ifdef CYGOPT_IO_CAN_EXT_CAN_ID
153 // Now send 1000 messages with extended identifier.
154 // Each message contains the message number in its identifier
155 // and in the first data byte
157 for (i = 0; i < 1000; ++i)
159 CYG_CAN_MSG_SET_EXT_ID(tx_msg, i + 0x800);
160 CYG_CAN_MSG_SET_DATA(tx_msg, 0, i);
161 CYG_CAN_MSG_SET_DATA_LEN(tx_msg, 8);
162 len = sizeof(tx_msg);
165 // Each message with an odd identifier should be a remote request message
169 CYG_CAN_MSG_SET_FRAME_TYPE(tx_msg, CYGNUM_CAN_FRAME_RTR);
173 CYG_CAN_MSG_SET_FRAME_TYPE(tx_msg, CYGNUM_CAN_FRAME_DATA);
177 // Sending CAN messages is blocking so the thread waits until there is
178 // space in the tx queue
180 if (ENOERR != cyg_io_write(hCAN0, &tx_msg, &len))
182 CYG_TEST_FAIL_FINISH("Error writing to /dev/can0");
188 CYG_TEST_PASS_FINISH("CAN TX test OK");
198 // create the threads that access the CAN device driver
200 cyg_thread_create(4, can0_thread,
203 (void *) can0_thread_data.stack,
205 &can0_thread_data.hdl,
206 &can0_thread_data.obj);
208 cyg_thread_resume(can0_thread_data.hdl);
210 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 IO/CAN and Kernel"
226 CYG_TEST_NA( N_A_MSG);