Rev 161 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 161 | Rev 163 | ||
|---|---|---|---|
| 1 | /** |
1 | /** |
| 2 | * CAN Test. This program sends a CAN message once every second. The ID of the |
2 | * CAN Test. This program sends a CAN message once every second. The ID of the |
| 3 | * message is increased each time for testing purposes. |
3 | * message is increased each time for testing purposes. |
| 4 | * Added LCD output |
4 | * Added LCD output |
| 5 | * |
5 | * |
| 6 | * @date 2006-11-21, LCD addition 2006-12-11 |
6 | * @date 2006-11-21, LCD addition 2006-12-11 |
| 7 | * @author Jimmy Myhrman, Erik Larsson |
7 | * @author Jimmy Myhrman, Erik Larsson |
| 8 | * |
8 | * |
| 9 | */ |
9 | */ |
| 10 | 10 | ||
| 11 | /*----------------------------------------------------------------------------- |
11 | /*----------------------------------------------------------------------------- |
| 12 | * Includes |
12 | * Includes |
| 13 | *---------------------------------------------------------------------------*/ |
13 | *---------------------------------------------------------------------------*/ |
| 14 | /* system files */ |
14 | /* system files */ |
| 15 | #include <avr/io.h> |
15 | #include <avr/io.h> |
| 16 | #include <avr/interrupt.h> |
16 | #include <avr/interrupt.h> |
| 17 | #include <avr/wdt.h> |
17 | #include <avr/wdt.h> |
| 18 | #include <stdio.h> |
18 | #include <stdio.h> |
| 19 | /* lib files */ |
19 | /* lib files */ |
| 20 | #include <can.h> |
20 | #include <can.h> |
| 21 | #include <serial.h> |
21 | #include <serial.h> |
| 22 | #include <timebase.h> |
22 | #include <timebase.h> |
| 23 | #include < |
23 | #include <lcd_HD44780.h> |
| 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 | Serial_Init(); |
30 | Serial_Init(); |
| 31 | sei(); |
31 | sei(); |
| 32 | lcd_init( LCD_DISP_ON ); |
32 | lcd_init( LCD_DISP_ON ); |
| 33 | 33 | ||
| 34 | printf("\n------------------------------------------------------------\n"); |
34 | printf("\n------------------------------------------------------------\n"); |
| 35 | printf( " CAN Test: Periodic Transmission\n"); |
35 | printf( " CAN Test: Periodic Transmission\n"); |
| 36 | printf( "------------------------------------------------------------\n"); |
36 | printf( "------------------------------------------------------------\n"); |
| 37 | 37 | ||
| 38 | lcd_clrscr(); |
38 | lcd_clrscr(); |
| 39 | lcd_puts("CAN LCD test\n"); |
39 | lcd_puts("CAN LCD test\n"); |
| 40 | 40 | ||
| 41 | printf("CanInit..."); |
41 | printf("CanInit..."); |
| 42 | lcd_puts("CanInit... "); |
42 | lcd_puts("CanInit... "); |
| 43 | if (Can_Init() != CAN_OK) { |
43 | if (Can_Init() != CAN_OK) { |
| 44 | printf("FAILED!\n"); |
44 | printf("FAILED!\n"); |
| 45 | lcd_puts("FAILED!\n"); |
45 | lcd_puts("FAILED!\n"); |
| 46 | } |
46 | } |
| 47 | else { |
47 | else { |
| 48 | printf("OK!\n"); |
48 | printf("OK!\n"); |
| 49 | lcd_puts("OK!\n"); |
49 | lcd_puts("OK!\n"); |
| 50 | } |
50 | } |
| 51 | 51 | ||
| 52 | uint32_t timeStamp = 0; |
52 | uint32_t timeStamp = 0; |
| 53 | 53 | ||
| 54 | Can_Message_t txMsg; |
54 | Can_Message_t txMsg; |
| 55 | Can_Message_t rxMsg; |
55 | Can_Message_t rxMsg; |
| 56 | txMsg.Id = 0; |
56 | txMsg.Id = 0; |
| 57 | txMsg.RemoteFlag = 0; |
57 | txMsg.RemoteFlag = 0; |
| 58 | txMsg.ExtendedFlag = 1; //DataLength and the databytes are just what happens to be in the memory. They are never set. |
58 | txMsg.ExtendedFlag = 1; //DataLength and the databytes are just what happens to be in the memory. They are never set. |
| 59 | 59 | ||
| 60 | /* main loop */ |
60 | /* main loop */ |
| 61 | while (1) { |
61 | while (1) { |
| 62 | /* service the CAN routines */ |
62 | /* service the CAN routines */ |
| 63 | Can_Service(); |
63 | Can_Service(); |
| 64 | 64 | ||
| 65 | /* send CAN message and check for CAN errors once every second */ |
65 | /* send CAN message and check for CAN errors once every second */ |
| 66 | if (Timebase_PassedTimeMillis(timeStamp) >= 1000) { |
66 | if (Timebase_PassedTimeMillis(timeStamp) >= 1000) { |
| 67 | timeStamp = Timebase_CurrentTime(); |
67 | timeStamp = Timebase_CurrentTime(); |
| 68 | /* send txMsg */ |
68 | /* send txMsg */ |
| 69 | txMsg.Id++; |
69 | txMsg.Id++; |
| 70 | Can_Send(&txMsg); |
70 | Can_Send(&txMsg); |
| 71 | } |
71 | } |
| 72 | 72 | ||
| 73 | /* check if any messages have been received */ |
73 | /* check if any messages have been received */ |
| 74 | while (Can_Receive(&rxMsg) == CAN_OK) { |
74 | while (Can_Receive(&rxMsg) == CAN_OK) { |
| 75 | 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)); |
75 | 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)); |
| 76 | printf("data={ "); |
76 | printf("data={ "); |
| 77 | for (uint8_t i=0; i<rxMsg.DataLength; i++) { |
77 | for (uint8_t i=0; i<rxMsg.DataLength; i++) { |
| 78 | printf("%x ", rxMsg.Data.bytes[i]); |
78 | printf("%x ", rxMsg.Data.bytes[i]); |
| 79 | } |
79 | } |
| 80 | printf("}\n"); |
80 | printf("}\n"); |
| 81 | } |
81 | } |
| 82 | } |
82 | } |
| 83 | 83 | ||
| 84 | return 0; |
84 | return 0; |
| 85 | } |
85 | } |
| 86 | 86 | ||