Rev 127 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 127 | Rev 142 | ||
|---|---|---|---|
| 1 | /** |
1 | /** |
| 2 | * CAN test program. |
2 | * CAN test program. |
| 3 | * |
3 | * |
| 4 | * @target AVR |
4 | * @target AVR |
| 5 | * @date 2006-10-29 |
5 | * @date 2006-10-29 |
| 6 | * @author Jimmy Myhrman |
6 | * @author Jimmy Myhrman |
| 7 | * |
7 | * |
| 8 | */ |
8 | */ |
| 9 | 9 | ||
| 10 | /*----------------------------------------------------------------------------- |
10 | /*----------------------------------------------------------------------------- |
| 11 | * Includes |
11 | * Includes |
| 12 | *---------------------------------------------------------------------------*/ |
12 | *---------------------------------------------------------------------------*/ |
| 13 | /* system files */ |
13 | /* system files */ |
| 14 | #include <avr/io.h> |
14 | #include <avr/io.h> |
| 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 <uart.h> |
20 | #include <uart.h> |
| 21 | #include <timebase.h> |
21 | #include <timebase.h> |
| 22 | #include <protocol.h> |
22 | #include <protocol.h> |
| 23 | 23 | ||
| 24 | 24 | ||
| 25 | /*----------------------------------------------------------------------------- |
25 | /*----------------------------------------------------------------------------- |
| 26 | * Main Program |
26 | * Main Program |
| 27 | *---------------------------------------------------------------------------*/ |
27 | *---------------------------------------------------------------------------*/ |
| 28 | int main(void) { |
28 | int main(void) { |
| 29 | Timebase_Init(); |
29 | Timebase_Init(); |
| 30 | Uart_Init(); |
30 | Uart_Init(); |
| 31 | sei(); |
31 | sei(); |
| 32 | 32 | ||
| 33 | printf("\n------------------------------\n"); |
33 | printf("\n------------------------------\n"); |
| 34 | printf(" CAN Monitor\n"); |
34 | printf(" CAN Monitor\n"); |
| 35 | printf("------------------------------\n"); |
35 | printf("------------------------------\n"); |
| 36 | 36 | ||
| 37 | printf("CanInit..."); |
37 | printf("CanInit..."); |
| 38 | if (Can_Init() != CAN_OK) { |
38 | if (Can_Init() != CAN_OK) { |
| 39 | printf("FAILED!\n"); |
39 | printf("FAILED!\n"); |
| 40 | } |
40 | } |
| 41 | else { |
41 | else { |
| 42 | printf("OK!\n"); |
42 | printf("OK!\n"); |
| 43 | } |
43 | } |
| 44 | 44 | ||
| 45 | uint32_t timeStamp = 0; |
45 | uint32_t timeStamp = 0; |
| 46 | 46 | ||
| 47 | Can_Message_t txMsg; |
47 | Can_Message_t txMsg; |
| 48 | Can_Message_t rxMsg; |
48 | Can_Message_t rxMsg; |
| 49 | - | ||
| 50 | txMsg.DataLength = 8; |
49 | txMsg.DataLength = 8; |
| 51 | txMsg.Data.bytes[0] = 7; |
50 | txMsg.Data.bytes[0] = 7; |
| 52 | txMsg.Id = 0; |
51 | txMsg.Id = 0; |
| 53 | txMsg.RemoteFlag = 0; |
52 | txMsg.RemoteFlag = 0; |
| 54 | txMsg.ExtendedFlag = 1; |
53 | txMsg.ExtendedFlag = 1; |
| 55 | 54 | ||
| 56 | /* main loop */ |
55 | /* main loop */ |
| 57 | while (1) { |
56 | while (1) { |
| 58 | /* |
57 | /* service the CAN routines */ |
| 59 |
|
58 | Can_Service(); |
| 60 | ProtocolParseCanMessage(&rxMsg); |
- | |
| 61 | } |
- | |
| 62 | 59 | ||
| 63 | /* send CAN message and check for CAN errors once every second */ |
60 | /* send CAN message and check for CAN errors once every second */ |
| 64 | if (Timebase_PassedTimeMillis(timeStamp) >= 1000) { |
61 | if (Timebase_PassedTimeMillis(timeStamp) >= 1000) { |
| - | 62 | timeStamp = Timebase_CurrentTime(); |
|
| 65 | /* send txMsg */ |
63 | /* send txMsg */ |
| 66 | txMsg.Id++; |
64 | txMsg.Id++; |
| 67 | Can_Send |
65 | //Can_Send(&txMsg); |
| 68 |
|
66 | printf("."); |
| - | 67 | } |
|
| - | 68 | ||
| 69 |
|
69 | /* check if any messages have been received */ |
| 70 |
|
70 | while (Can_Receive(&rxMsg) == CAN_OK) { |
| - | 71 | //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)); |
|
| - | 72 | //printf("data={ "); |
|
| - | 73 | /*for (uint8_t i=0; i<rxMsg.DataLength; i++) { |
|
| 71 |
|
74 | printf("%x ", rxMsg.Data.bytes[i]); |
| - | 75 | }*/ |
|
| - | 76 | //printf("}\n"); |
|
| - | 77 | if (Can_Send(&rxMsg) != CAN_OK) { |
|
| - | 78 | break; |
|
| 72 | } |
79 | } |
| 73 | } |
80 | } |
| 74 | } |
81 | } |
| 75 | 82 | ||
| 76 | return 0; |
83 | return 0; |
| 77 | } |
84 | } |
| 78 | 85 | ||