Rev 384 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 384 | Rev 386 | ||
|---|---|---|---|
| Line 1... | Line 1... | ||
| 1 | /** |
1 | /** |
| 2 | * CAN Test. |
2 | * CAN Test. |
| 3 | * |
3 | * Tests if sending CAN messages is ok. |
| 4 | * |
4 | * |
| 5 | * @date 2006-11-21 |
5 | * @date 2006-11-21 |
| 6 | * @author Jimmy Myhrman |
6 | * @author Jimmy Myhrman |
| 7 | * |
7 | * |
| 8 | */ |
8 | */ |
| Line 15... | Line 15... | ||
| 15 | #include <avr/interrupt.h> |
15 | #include <avr/interrupt.h> |
| 16 | #include <avr/wdt.h> |
16 | #include <avr/wdt.h> |
| 17 | #include <stdio.h> |
17 | #include <stdio.h> |
| 18 | /* lib files */ |
18 | /* lib files */ |
| 19 | #include <can.h> |
19 | #include <can.h> |
| 20 | #include <serial.h> |
- | |
| 21 | #include <timebase.h> |
20 | #include <timebase.h> |
| 22 | 21 | ||
| 23 | - | ||
| - | 22 | #define INTERVAL 1000 |
|
| - | 23 | #define SENDER_ID 0xff |
|
| 24 | /*----------------------------------------------------------------------------- |
24 | /*----------------------------------------------------------------------------- |
| 25 | * Main Program |
25 | * Main Program |
| 26 | *---------------------------------------------------------------------------*/ |
26 | *---------------------------------------------------------------------------*/ |
| 27 | int main(void) { |
27 | int main(void) { |
| 28 | Mcu_Init(); |
- | |
| 29 | Timebase_Init(); |
28 | Timebase_Init(); |
| 30 | Serial_Init(); |
- | |
| 31 | 29 | ||
| 32 | sei(); |
30 | sei(); |
| 33 | 31 | ||
| 34 | printf("\n------------------------------------------------------------\n"); |
- | |
| 35 | printf( " CAN Test: Periodic Transmission\n"); |
- | |
| 36 | printf( "------------------------------------------------------------\n"); |
- | |
| 37 | - | ||
| 38 |
|
32 | Can_Init(); |
| 39 | if (Can_Init() != CAN_OK) { |
- | |
| 40 | printf("FAILED!\n"); |
- | |
| 41 | } |
- | |
| 42 | else { |
- | |
| 43 | printf("OK!\n"); |
- | |
| 44 | } |
- | |
| 45 | 33 | ||
| 46 | uint32_t timeStamp = 0; |
34 | uint32_t timeStamp = 0; |
| 47 | 35 | ||
| 48 | Can_Message_t txMsg; |
36 | Can_Message_t txMsg; |
| - | 37 | ||
| 49 |
|
38 | txMsg.Id = SENDER_ID; |
| 50 | //The databytes are just what happens to be in the memory. They are never set. |
- | |
| 51 | txMsg.RemoteFlag = 0; |
39 | txMsg.RemoteFlag = 0; |
| 52 | txMsg.ExtendedFlag = 1; |
40 | txMsg.ExtendedFlag = 1; |
| 53 | #define NODENUMBER 1 |
- | |
| 54 | #if NODENUMBER == 1 |
- | |
| 55 | txMsg.Id = 16; |
- | |
| 56 | txMsg.DataLength = |
41 | txMsg.DataLength = 1; |
| 57 | #elif NODENUMBER == 2 |
- | |
| 58 | txMsg.Id = 32; |
- | |
| 59 | txMsg. |
42 | txMsg.Data.bytes[0] = 0xff; |
| 60 | #else |
- | |
| 61 | # error NODENUMBER not set! |
- | |
| 62 | #endif |
- | |
| 63 | 43 | ||
| 64 | /* main loop */ |
44 | /* main loop */ |
| 65 | while (1) { |
45 | while (1) { |
| 66 | /* service the CAN routines */ |
46 | /* service the CAN routines */ |
| 67 | Can_Service(); |
47 | Can_Service(); |
| 68 | 48 | ||
| 69 | /* send CAN message |
49 | /* send CAN message */ |
| 70 | if (Timebase_PassedTimeMillis(timeStamp) >= |
50 | if (Timebase_PassedTimeMillis(timeStamp) >= INTERVAL) { |
| 71 | timeStamp = Timebase_CurrentTime(); |
51 | timeStamp = Timebase_CurrentTime(); |
| 72 | /* send txMsg */ |
52 | /* send txMsg */ |
| 73 | txMsg.Id++; |
- | |
| 74 | Can_Send(&txMsg); |
53 | Can_Send(&txMsg); |
| 75 | } |
- | |
| 76 | - | ||
| 77 | /* check if any messages have been received */ |
- | |
| 78 | while (Can_Receive(&rxMsg) == CAN_OK) { |
- | |
| 79 | printf("MSG Received: ID=%lx, DLC=%u, EXT=%u, RTR=%u, ", rxMsg.Id, (uint16_t)(rxMsg.DataLength), (uint16_t)(rxMsg.ExtendedFlag), (uint16_t)(rxMsg.RemoteFlag)); |
- | |
| 80 | printf("data={ "); |
- | |
| 81 | for (uint8_t i=0; i<rxMsg.DataLength; i++) { |
- | |
| 82 | printf("%x ", rxMsg.Data.bytes[i]); |
- | |
| 83 | } |
- | |
| 84 | printf("}\n"); |
- | |
| 85 | } |
54 | } |
| 86 | } |
55 | } |
| 87 | 56 | ||
| 88 | return 0; |
57 | return 0; |
| 89 | } |
58 | } |