Details | Last modification | View Log | SVN | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 61 | jimmy | 1 | /** |
| 2 | * CAN test program. |
||
| 3 | * |
||
| 4 | * @target AVR |
||
| 5 | * @date 2006-10-29 |
||
| 6 | * @author Jimmy Myhrman |
||
| 7 | * |
||
| 8 | */ |
||
| 9 | |||
| 10 | /*----------------------------------------------------------------------------- |
||
| 11 | * Includes |
||
| 12 | *---------------------------------------------------------------------------*/ |
||
| 13 | /* system files */ |
||
| 14 | #include <avr/io.h> |
||
| 15 | #include <avr/interrupt.h> |
||
| 16 | #include <avr/wdt.h> |
||
| 17 | #include <stdio.h> |
||
| 18 | /* lib files */ |
||
| 19 | #include <can.h> |
||
| 20 | #include <uart.h> |
||
| 21 | #include <timebase.h> |
||
| 22 | #include <protocol.h> |
||
| 23 | |||
| 24 | |||
| 25 | /*----------------------------------------------------------------------------- |
||
| 26 | * Main Program |
||
| 27 | *---------------------------------------------------------------------------*/ |
||
| 28 | int main(void) { |
||
| 29 | TimebaseInit(); |
||
| 30 | UartInit(); |
||
| 31 | sei(); |
||
| 32 | |||
| 33 | printf("\n------------------------------\n"); |
||
| 34 | printf(" CAN Monitor\n"); |
||
| 35 | printf("------------------------------\n"); |
||
| 36 | |||
| 37 | printf("CanInit..."); |
||
| 38 | if (CanInit(CAN_BITRATE_1M) != CAN_OK) { |
||
| 39 | printf("FAILED!\n"); |
||
| 40 | } |
||
| 41 | else { |
||
| 42 | printf("OK!\n"); |
||
| 43 | } |
||
| 44 | |||
| 45 | uint32_t timeStamp = 0; |
||
| 46 | |||
| 47 | CanMessage_t txMsg; |
||
| 48 | CanMessage_t rxMsg; |
||
| 49 | |||
| 50 | txMsg.DataLength = 8; |
||
| 51 | txMsg.Data.bytes[0] = 7; |
||
| 52 | txMsg.Id = 733; |
||
| 53 | txMsg.RemoteFlag = 0; |
||
| 54 | txMsg.ExtendedFlag = 1; |
||
| 55 | |||
| 56 | /* main loop */ |
||
| 57 | while (1) { |
||
| 58 | /* any new CAN messages received? */ |
||
| 59 | if (CanReceive(&rxMsg) == CAN_OK) { |
||
| 60 | ProtocolParseCanMessage(&rxMsg); |
||
| 61 | } |
||
| 62 | |||
| 63 | /* send CAN message and check for CAN errors once every second */ |
||
| 64 | if (TimebasePassedTimeMS(timeStamp) >= 1000) { |
||
| 65 | /* increase ID and send txMsg */ |
||
| 66 | txMsg.Id++; |
||
| 67 | CanSend(&txMsg); |
||
| 68 | /* check for errors */ |
||
| 69 | timeStamp = TimebaseCurrentTime(); |
||
| 70 | if (CanCheckError() != CAN_OK) { |
||
| 71 | printf("CAN ERROR detected!\n"); |
||
| 72 | } |
||
| 73 | } |
||
| 74 | } |
||
| 75 | |||
| 76 | return 0; |
||
| 77 | } |