Mercurial > ecos
annotate packages/devs/can/loop/current/tests/can_txevent.c @ 2424:4c366bd69cd5
* tests/can_overrun1.c (can0_thread): Fix the length of the data
in the message. Add a delay to allow the CAN device to process
the packets.
* test/can_txcevent.c: (can0_thread): Add a delay to allow the CAN device
to process the packet.s
* src/loop_can.c (FIFO_SIZE): Changed to one more than the TX
queue size. If it is less, the loopback tests don't pass because
packets don't get transmitted.
| author | asl |
|---|---|
| date | Tue, 28 Aug 2007 15:56:03 +0000 |
| parents | 1ca46bebd705 |
| children | 74dbf4c3f2e1 |
| rev | line source |
|---|---|
| 2059 | 1 //========================================================================== |
| 2 // | |
| 3 // can_txevent.c | |
| 4 // | |
| 5 // Test CAN device driver timeouts | |
| 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-07 | |
| 46 // Description: Timeout test of CAN device driver | |
| 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 // tx event support required | |
| 73 #if defined(CYGOPT_IO_CAN_TX_EVENT_SUPPORT) | |
| 74 | |
| 75 | |
| 76 //=========================================================================== | |
| 77 // DATA TYPES | |
| 78 //=========================================================================== | |
| 79 typedef struct st_thread_data | |
| 80 { | |
| 81 cyg_thread obj; | |
| 82 long stack[CYGNUM_HAL_STACK_SIZE_TYPICAL]; | |
| 83 cyg_handle_t hdl; | |
| 84 } thread_data_t; | |
| 85 | |
| 86 | |
| 87 //=========================================================================== | |
| 88 // LOCAL DATA | |
| 89 //=========================================================================== | |
| 90 cyg_thread_entry_t can0_thread; | |
| 91 thread_data_t can0_thread_data; | |
| 92 | |
| 93 | |
| 94 //=========================================================================== | |
| 95 // LOCAL FUNCTIONS | |
| 96 //=========================================================================== | |
| 97 #include "can_test_aux.inl" // include CAN test auxiliary functions | |
| 98 | |
| 99 | |
| 100 //=========================================================================== | |
| 101 // WRITER THREAD | |
| 102 //=========================================================================== | |
| 103 void can0_thread(cyg_addrword_t data) | |
| 104 { | |
| 105 cyg_io_handle_t hCAN0; | |
| 106 cyg_uint32 len; | |
| 107 cyg_can_buf_info_t buf_info; | |
| 108 cyg_uint16 i; | |
| 109 cyg_can_event rx_event; | |
| 110 cyg_can_message tx_msg = | |
| 111 { | |
| 112 0x000, // CAN identifier | |
| 2377 | 113 data : |
| 114 { | |
| 115 {0x00, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7 }// 8 data bytes | |
| 116 }, | |
| 2059 | 117 CYGNUM_CAN_ID_STD, // standard frame |
| 118 CYGNUM_CAN_FRAME_DATA, // data frame | |
| 119 4, // data length code | |
| 120 }; | |
| 121 | |
| 122 | |
| 123 if (ENOERR != cyg_io_lookup("/dev/can0", &hCAN0)) | |
| 124 { | |
| 125 CYG_TEST_FAIL_FINISH("Error opening /dev/can0"); | |
| 126 } | |
| 127 | |
| 128 // | |
| 129 // first we read the buffer info | |
| 130 // | |
| 131 len = sizeof(buf_info); | |
| 132 if (ENOERR != cyg_io_get_config(hCAN0, CYG_IO_GET_CONFIG_CAN_BUFFER_INFO ,&buf_info, &len)) | |
| 133 { | |
| 134 CYG_TEST_FAIL_FINISH("Error reading config of /dev/can0"); | |
| 135 } | |
| 136 | |
| 137 // | |
| 138 // check if buffer is really empty | |
| 139 // | |
| 140 if (buf_info.rx_count != 0) | |
| 141 { | |
| 142 CYG_TEST_FAIL_FINISH("Receive buffer of /dev/can0 is not empty."); | |
| 143 } | |
| 144 | |
| 145 // | |
| 146 // now send messages - because TX events are supported each transmitted CAN message | |
| 147 // will cause a TX event that is filled into receive queue | |
| 148 // | |
| 149 diag_printf("Sending %d CAN messages to /dev/can0 \n", buf_info.rx_bufsize); | |
| 150 for (i = 0; i < buf_info.rx_bufsize; ++i) | |
| 151 { | |
| 2377 | 152 CYG_CAN_MSG_SET_STD_ID(tx_msg, 0x000 + i); |
| 153 CYG_CAN_MSG_SET_DATA(tx_msg, 0, i); | |
| 2059 | 154 len = sizeof(tx_msg); |
| 155 | |
| 156 if (ENOERR != cyg_io_write(hCAN0, &tx_msg, &len)) | |
| 157 { | |
| 158 CYG_TEST_FAIL_FINISH("Error writing to /dev/can0"); | |
| 159 } | |
| 160 else | |
| 161 { | |
| 162 print_can_msg(&tx_msg, ""); | |
| 163 } | |
| 164 } | |
| 165 | |
| 166 // | |
|
2424
4c366bd69cd5
* tests/can_overrun1.c (can0_thread): Fix the length of the data
asl
parents:
2377
diff
changeset
|
167 // Give the loop back driver time to process all those messages. |
|
4c366bd69cd5
* tests/can_overrun1.c (can0_thread): Fix the length of the data
asl
parents:
2377
diff
changeset
|
168 // |
|
4c366bd69cd5
* tests/can_overrun1.c (can0_thread): Fix the length of the data
asl
parents:
2377
diff
changeset
|
169 cyg_thread_delay(10); |
|
4c366bd69cd5
* tests/can_overrun1.c (can0_thread): Fix the length of the data
asl
parents:
2377
diff
changeset
|
170 |
|
4c366bd69cd5
* tests/can_overrun1.c (can0_thread): Fix the length of the data
asl
parents:
2377
diff
changeset
|
171 // |
| 2059 | 172 // now we read the buffer info - we expect a completely filled recieve queue |
| 173 // | |
| 174 len = sizeof(buf_info); | |
| 175 if (ENOERR != cyg_io_get_config(hCAN0, CYG_IO_GET_CONFIG_CAN_BUFFER_INFO ,&buf_info, &len)) | |
| 176 { | |
| 177 CYG_TEST_FAIL_FINISH("Error reading config of /dev/can0"); | |
| 178 } | |
| 179 | |
| 180 // | |
| 181 // if receive queue is not completely filled, then we have an error here | |
| 182 // | |
| 183 if (buf_info.rx_bufsize != buf_info.rx_count) | |
| 184 { | |
| 185 diag_printf("RX bufsize: %d events in RX buffer: %d\n", buf_info.rx_bufsize, buf_info.rx_count); | |
| 186 CYG_TEST_FAIL_FINISH("Receive queue of /dev/can0 not completely filled."); | |
| 187 } | |
| 188 | |
| 189 // | |
| 190 // now we read the receive queue | |
| 191 // | |
| 192 diag_printf("Receiving %d TX events from /dev/can0 \n", buf_info.rx_count); | |
| 193 for (i = 0; i < buf_info.rx_count; ++i) | |
| 194 { | |
| 195 len = sizeof(rx_event); | |
| 196 | |
| 197 if (ENOERR != cyg_io_read(hCAN0, &rx_event, &len)) | |
| 198 { | |
| 199 CYG_TEST_FAIL_FINISH("Error reading from /dev/can0"); | |
| 200 } | |
| 201 | |
| 202 // | |
| 203 // we expect only a set TX flag because no other events may arrive for the | |
| 204 // loopback driver | |
| 205 // | |
| 206 if (!(rx_event.flags & CYGNUM_CAN_EVENT_TX) || (rx_event.flags & !CYGNUM_CAN_EVENT_TX)) | |
| 207 { | |
| 208 CYG_TEST_FAIL_FINISH("Unexpected receive event flags."); | |
| 209 } | |
| 210 | |
| 211 // | |
| 212 // Now check if TX events contain valid data - we know that the ID and the first | |
| 213 // data byte contain the message number | |
| 214 // | |
| 2377 | 215 if ((rx_event.msg.id != i) || (rx_event.msg.data.bytes[0] != i)) |
| 2059 | 216 { |
| 217 CYG_TEST_FAIL_FINISH("Received invalid data in TX event"); | |
| 218 } | |
| 219 else | |
| 220 { | |
| 221 print_can_msg(&rx_event.msg, ""); | |
| 222 } | |
| 223 } // for (i = 0; i < buf_info.rx_count; ++i) | |
| 224 | |
| 225 CYG_TEST_PASS_FINISH("can_txevent test OK"); | |
| 226 } | |
| 227 | |
| 228 | |
| 229 | |
| 230 void | |
| 231 cyg_start(void) | |
| 232 { | |
| 233 CYG_TEST_INIT(); | |
| 234 | |
| 235 // | |
| 236 // create the thread which access the CAN device driver | |
| 237 // | |
| 238 cyg_thread_create(4, can0_thread, | |
| 239 (cyg_addrword_t) 0, | |
| 240 "can0_thread", | |
| 241 (void *) can0_thread_data.stack, | |
| 242 1024 * sizeof(long), | |
| 243 &can0_thread_data.hdl, | |
| 244 &can0_thread_data.obj); | |
| 245 | |
| 246 cyg_thread_resume(can0_thread_data.hdl); | |
| 247 | |
| 248 cyg_scheduler_start(); | |
| 249 } | |
| 250 | |
| 251 #else // CYGOPT_IO_CAN_TX_EVENT_SUPPORT | |
| 252 #define N_A_MSG "TX event support required for IO/CAN" | |
| 253 #endif | |
| 254 | |
| 255 #else // CYGFUN_KERNEL_API_C | |
| 256 #define N_A_MSG "Needs kernel C API" | |
| 257 #endif | |
| 258 | |
| 259 #else // CYGPKG_IO_CAN && CYGPKG_KERNEL | |
| 260 #define N_A_MSG "Needs IO/CAN and Kernel" | |
| 261 #endif | |
| 262 | |
| 263 #ifdef N_A_MSG | |
| 264 void | |
| 265 cyg_start( void ) | |
| 266 { | |
| 267 CYG_TEST_INIT(); | |
| 268 CYG_TEST_NA( N_A_MSG); | |
| 269 } | |
| 270 #endif // N_A_MSG | |
| 271 | |
| 272 // EOF serial4.c |
