Mercurial > ecos
annotate packages/devs/can/loop/current/tests/can_overrun1.c @ 3292:7f8e529b4d82 default tip
Fix FREESCALE_EDMA_NBYTES_MLOFFYES_MLOFF() so it works with negative offsets.
| author | vae |
|---|---|
| date | Wed, 29 Apr 2015 23:31:48 +0000 |
| parents | 74dbf4c3f2e1 |
| children |
| rev | line source |
|---|---|
| 2059 | 1 //========================================================================== |
| 2 // | |
| 3 // can_overrun1.c | |
| 4 // | |
| 5 // Test CAN device drivers | |
| 6 // | |
| 7 //========================================================================== | |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2424
diff
changeset
|
8 // ####ECOSGPLCOPYRIGHTBEGIN#### |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2424
diff
changeset
|
9 // ------------------------------------------- |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2424
diff
changeset
|
10 // This file is part of eCos, the Embedded Configurable Operating System. |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2424
diff
changeset
|
11 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc. |
| 2059 | 12 // |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2424
diff
changeset
|
13 // eCos is free software; you can redistribute it and/or modify it under |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2424
diff
changeset
|
14 // the terms of the GNU General Public License as published by the Free |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2424
diff
changeset
|
15 // Software Foundation; either version 2 or (at your option) any later |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2424
diff
changeset
|
16 // version. |
| 2059 | 17 // |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2424
diff
changeset
|
18 // eCos is distributed in the hope that it will be useful, but WITHOUT |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2424
diff
changeset
|
19 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2424
diff
changeset
|
20 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2424
diff
changeset
|
21 // for more details. |
| 2059 | 22 // |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2424
diff
changeset
|
23 // You should have received a copy of the GNU General Public License |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2424
diff
changeset
|
24 // along with eCos; if not, write to the Free Software Foundation, Inc., |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2424
diff
changeset
|
25 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 2059 | 26 // |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2424
diff
changeset
|
27 // As a special exception, if other files instantiate templates or use |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2424
diff
changeset
|
28 // macros or inline functions from this file, or you compile this file |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2424
diff
changeset
|
29 // and link it with other works to produce a work based on this file, |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2424
diff
changeset
|
30 // this file does not by itself cause the resulting work to be covered by |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2424
diff
changeset
|
31 // the GNU General Public License. However the source code for this file |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2424
diff
changeset
|
32 // must still be made available in accordance with section (3) of the GNU |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2424
diff
changeset
|
33 // General Public License v2. |
| 2059 | 34 // |
|
2729
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2424
diff
changeset
|
35 // This exception does not invalidate any other reasons why a work based |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2424
diff
changeset
|
36 // on this file might be covered by the GNU General Public License. |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2424
diff
changeset
|
37 // ------------------------------------------- |
|
74dbf4c3f2e1
Update all copyright banners to reflect FSF ownership; fix and improve licence text.
jlarmour
parents:
2424
diff
changeset
|
38 // ####ECOSGPLCOPYRIGHTEND#### |
| 2059 | 39 //========================================================================== |
| 40 //#####DESCRIPTIONBEGIN#### | |
| 41 // | |
| 42 // Author(s): Uwe Kindler | |
| 43 // Contributors: Uwe Kindler | |
| 44 // Date: 2005-08-07 | |
| 45 // Description: Simple read/write test of CAN driver | |
| 46 //####DESCRIPTIONEND#### | |
| 47 | |
| 48 | |
| 49 //=========================================================================== | |
| 50 // INCLUDES | |
| 51 //=========================================================================== | |
| 52 #include <pkgconf/system.h> | |
| 53 | |
| 54 #include <cyg/infra/testcase.h> // test macros | |
| 55 #include <cyg/infra/cyg_ass.h> // assertion macros | |
| 56 #include <cyg/infra/diag.h> | |
| 57 | |
| 58 // Package requirements | |
| 59 #if defined(CYGPKG_IO_CAN) && defined(CYGPKG_KERNEL) | |
| 60 | |
| 61 #include <pkgconf/kernel.h> | |
| 62 #include <cyg/io/io.h> | |
| 63 #include <cyg/io/canio.h> | |
| 64 | |
| 65 // Package option requirements | |
| 66 #if defined(CYGFUN_KERNEL_API_C) | |
| 67 | |
| 68 #include <cyg/hal/hal_arch.h> // CYGNUM_HAL_STACK_SIZE_TYPICAL | |
| 69 #include <cyg/kernel/kapi.h> | |
| 70 | |
| 71 // tx event support required | |
| 72 #if defined(CYGOPT_IO_CAN_TX_EVENT_SUPPORT) | |
| 73 | |
| 74 | |
| 75 //=========================================================================== | |
| 76 // DATA TYPES | |
| 77 //=========================================================================== | |
| 78 typedef struct st_thread_data | |
| 79 { | |
| 80 cyg_thread obj; | |
| 81 long stack[CYGNUM_HAL_STACK_SIZE_TYPICAL]; | |
| 82 cyg_handle_t hdl; | |
| 83 } thread_data_t; | |
| 84 | |
| 85 | |
| 86 //=========================================================================== | |
| 87 // LOCAL DATA | |
| 88 //=========================================================================== | |
| 89 cyg_thread_entry_t can0_thread; | |
| 90 thread_data_t can0_thread_data; | |
| 91 | |
| 92 | |
| 93 //=========================================================================== | |
| 94 // LOCAL FUNCTIONS | |
| 95 //=========================================================================== | |
| 96 #include "can_test_aux.inl" // include CAN test auxiliary functions | |
| 97 | |
| 98 | |
| 99 //=========================================================================== | |
| 100 // WRITER THREAD | |
| 101 //=========================================================================== | |
| 102 void can0_thread(cyg_addrword_t data) | |
| 103 { | |
| 104 cyg_io_handle_t hCAN0; | |
| 105 cyg_uint8 i; | |
| 106 cyg_uint32 len; | |
| 107 cyg_can_buf_info_t buf_info; | |
| 108 cyg_can_event rx_event; | |
| 109 cyg_can_message tx_msg = | |
| 110 { | |
| 111 0x000, // CAN identifier | |
| 2377 | 112 data : |
| 113 { | |
| 114 {0x00, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7 }// 8 data bytes | |
| 115 }, | |
| 2059 | 116 CYGNUM_CAN_ID_STD, // standard frame |
| 117 CYGNUM_CAN_FRAME_DATA, // data frame | |
|
2424
4c366bd69cd5
* tests/can_overrun1.c (can0_thread): Fix the length of the data
asl
parents:
2377
diff
changeset
|
118 1, // data length code |
| 2059 | 119 }; |
| 120 | |
| 121 if (ENOERR != cyg_io_lookup("/dev/can0", &hCAN0)) | |
| 122 { | |
| 123 CYG_TEST_FAIL_FINISH("Error opening /dev/can0"); | |
| 124 } | |
| 125 | |
| 126 len = sizeof(buf_info); | |
| 127 if (ENOERR != cyg_io_get_config(hCAN0, CYG_IO_GET_CONFIG_CAN_BUFFER_INFO ,&buf_info, &len)) | |
| 128 { | |
| 129 CYG_TEST_FAIL_FINISH("Error reading config of /dev/can0"); | |
| 130 } | |
| 131 | |
| 132 if (buf_info.rx_count > 0) | |
| 133 { | |
| 134 CYG_TEST_FAIL_FINISH("Empty RX buffer expected for /dev/can0"); | |
| 135 } | |
| 136 | |
| 137 // | |
| 138 // now we send exactly one CAN message more than it is space in left in buffer | |
| 139 // Because each TX message will cause a TX event in receive queue we should | |
| 140 // get a RX queue overrun | |
| 141 // | |
| 142 diag_printf("Sending %d CAN messages to /dev/can0\n", buf_info.rx_bufsize + 1); | |
| 143 for (i = 0; i <= buf_info.rx_bufsize; ++i) | |
| 144 { | |
| 2377 | 145 CYG_CAN_MSG_SET_STD_ID(tx_msg, 0x000 + i); |
| 146 CYG_CAN_MSG_SET_DATA(tx_msg, 0, i); | |
| 2059 | 147 len = sizeof(tx_msg); |
| 148 | |
| 149 if (ENOERR != cyg_io_write(hCAN0, &tx_msg, &len)) | |
| 150 { | |
| 151 CYG_TEST_FAIL_FINISH("Error writing to /dev/can0"); | |
| 152 } | |
| 153 else | |
| 154 { | |
| 155 print_can_msg(&tx_msg, ""); | |
| 156 } | |
| 157 } | |
|
2424
4c366bd69cd5
* tests/can_overrun1.c (can0_thread): Fix the length of the data
asl
parents:
2377
diff
changeset
|
158 |
|
4c366bd69cd5
* tests/can_overrun1.c (can0_thread): Fix the length of the data
asl
parents:
2377
diff
changeset
|
159 // |
|
4c366bd69cd5
* tests/can_overrun1.c (can0_thread): Fix the length of the data
asl
parents:
2377
diff
changeset
|
160 // 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
|
161 // |
|
4c366bd69cd5
* tests/can_overrun1.c (can0_thread): Fix the length of the data
asl
parents:
2377
diff
changeset
|
162 cyg_thread_delay(10); |
| 2059 | 163 |
| 164 // | |
| 165 // now check if receive queue is completely filled - that means number of rx events should | |
| 166 // be equal to RX queue size | |
| 167 // | |
| 168 if (ENOERR != cyg_io_get_config(hCAN0, CYG_IO_GET_CONFIG_CAN_BUFFER_INFO ,&buf_info, &len)) | |
| 169 { | |
| 170 CYG_TEST_FAIL_FINISH("Error reading config of /dev/can0"); | |
| 171 } | |
| 172 | |
| 173 if (buf_info.rx_bufsize != buf_info.rx_count) | |
| 174 { | |
| 175 CYG_TEST_FAIL_FINISH("Number of events in /dev/can0 RX queue differs from queue size"); | |
| 176 } | |
| 177 | |
| 178 // | |
| 179 // Now read all events from receive queue - if everything is o.k. than the oldest | |
| 180 // event should be overwritten by the latest sent message and the last event in | |
| 181 // queue should indicate a RX overrun | |
| 182 // | |
| 183 diag_printf("\nReceiving %d CAN messages from /dev/can0\n", buf_info.rx_bufsize); | |
| 184 for (i = 0; i < buf_info.rx_bufsize; ++i) | |
| 185 { | |
| 186 len = sizeof(rx_event); | |
| 187 | |
| 188 if (ENOERR != cyg_io_read(hCAN0, &rx_event, &len)) | |
| 189 { | |
| 190 CYG_TEST_FAIL_FINISH("Error reading from /dev/can1"); | |
| 191 } | |
| 192 else | |
| 193 { | |
| 194 // | |
| 195 // if we received a valid TX event then we can print the message | |
| 196 // | |
| 197 if (rx_event.flags & CYGNUM_CAN_EVENT_TX) | |
| 198 { | |
| 199 print_can_msg(&rx_event.msg, ""); | |
| 2377 | 200 if (rx_event.msg.data.bytes[0] != (i + 1)) |
| 2059 | 201 { |
| 202 CYG_TEST_FAIL_FINISH("Received /dev/can0 TX event contains invalid data"); | |
| 203 } | |
| 204 } | |
| 205 else | |
| 206 { | |
| 207 CYG_TEST_FAIL_FINISH("Unexpected CAN event for /dev/can0"); | |
| 208 } | |
| 209 | |
| 210 // | |
| 211 // now check if any other flag is set | |
| 212 // | |
| 213 if (rx_event.flags & CYGNUM_CAN_EVENT_OVERRUN_RX) | |
| 214 { | |
| 215 diag_printf("RX queue overrun successfully indicated for /dev/can0\n"); | |
| 216 if (i < (buf_info.rx_bufsize - 1)) | |
| 217 { | |
| 218 CYG_TEST_FAIL_FINISH("RX queue overrun occured too early /dev/can0"); | |
| 219 } | |
| 220 else | |
| 221 { | |
| 222 CYG_TEST_PASS_FINISH("can_overrun1 test OK"); | |
| 223 } | |
| 224 } // if (rx_event.flags & CYGNUM_CAN_EVENT_OVERRUN_RX) | |
| 225 } | |
| 226 } // for (i = 0; i < buf_info.rx_bufsize; ++i) | |
| 227 | |
| 228 CYG_TEST_FAIL_FINISH("RX overrun expected but not received for /dev/can0"); | |
| 229 } | |
| 230 | |
| 231 | |
| 232 | |
| 233 void | |
| 234 cyg_start(void) | |
| 235 { | |
| 236 CYG_TEST_INIT(); | |
| 237 | |
| 238 // | |
| 239 // create the two threads which access the CAN device driver | |
| 240 // | |
| 241 cyg_thread_create(4, can0_thread, | |
| 242 (cyg_addrword_t) 0, | |
| 243 "can0_thread", | |
| 244 (void *) can0_thread_data.stack, | |
| 245 1024 * sizeof(long), | |
| 246 &can0_thread_data.hdl, | |
| 247 &can0_thread_data.obj); | |
| 248 | |
| 249 cyg_thread_resume(can0_thread_data.hdl); | |
| 250 | |
| 251 cyg_scheduler_start(); | |
| 252 } | |
| 253 | |
| 254 #else // CYGOPT_IO_CAN_TX_EVENT_SUPPORT | |
| 255 #define N_A_MSG "TX event support required for IO/CAN" | |
| 256 #endif | |
| 257 | |
| 258 #else // CYGFUN_KERNEL_API_C | |
| 259 #define N_A_MSG "Needs kernel C API" | |
| 260 #endif | |
| 261 | |
| 262 #else // CYGPKG_IO_CAN && CYGPKG_KERNEL | |
| 263 #define N_A_MSG "Needs IO/CAN and Kernel" | |
| 264 #endif | |
| 265 | |
| 266 #ifdef N_A_MSG | |
| 267 void | |
| 268 cyg_start( void ) | |
| 269 { | |
| 270 CYG_TEST_INIT(); | |
| 271 CYG_TEST_NA( N_A_MSG); | |
| 272 } | |
| 273 #endif // N_A_MSG | |
| 274 | |
| 275 // EOF serial4.c |
