Details | Last modification | View Log | SVN | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 183 | andfri | 1 | #include <inttypes.h> |
| 223 | andfri | 2 | #include <avr/interrupt.h> |
| 267 | andfri | 3 | #include <stdio.h> |
| 183 | andfri | 4 | #include <bios.h> |
| 325 | andfri | 5 | #include <serial.h> |
| 183 | andfri | 6 | |
| 325 | andfri | 7 | #define APP_TYPE 0xf001 |
| 8 | #define APP_VERSION 0x0001 |
||
| 183 | andfri | 9 | |
| 290 | arune | 10 | void can_receive(Can_Message_t *msg) { |
| 11 | printf("candata!\n"); |
||
| 12 | } |
||
| 13 | |||
| 183 | andfri | 14 | int main(void) |
| 15 | { |
||
| 268 | arune | 16 | unsigned long time; |
| 290 | arune | 17 | unsigned long time1 = bios->timebase_get(); |
| 18 | unsigned long time2 = bios->timebase_get(); |
||
| 183 | andfri | 19 | |
| 223 | andfri | 20 | sei(); |
| 21 | |||
| 325 | andfri | 22 | Serial_Init(); |
| 23 | |||
| 290 | arune | 24 | Can_Message_t txMsg; |
| 325 | andfri | 25 | txMsg.Id = (CAN_NMT_APP_START << CAN_SHIFT_NMT_TYPE) | (NODE_ID << CAN_SHIFT_NMT_SID); |
| 26 | txMsg.DataLength = 4; |
||
| 290 | arune | 27 | txMsg.RemoteFlag = 0; |
| 28 | txMsg.ExtendedFlag = 1; |
||
| 325 | andfri | 29 | txMsg.Data.words[0] = APP_TYPE; |
| 30 | txMsg.Data.words[1] = APP_VERSION; |
||
| 183 | andfri | 31 | |
| 290 | arune | 32 | //set up callback for candata |
| 33 | bios->can_callback = &can_receive; |
||
| 325 | andfri | 34 | // Send CAN_NMT_APP_START |
| 35 | bios->can_send(&txMsg); |
||
| 290 | arune | 36 | |
| 183 | andfri | 37 | printf("AVR Test Application\n"); |
| 223 | andfri | 38 | printf("Using AVR BIOS version %x\n", bios->version); |
| 183 | andfri | 39 | |
| 325 | andfri | 40 | txMsg.Id = (CAN_TST << CAN_SHIFT_CLASS) | NODE_ID; |
| 41 | txMsg.Data.dwords[0] = 0x01020304; |
||
| 42 | txMsg.Data.dwords[1] = 0xfffefdfc; |
||
| 43 | txMsg.DataLength = 8; |
||
| 44 | |||
| 223 | andfri | 45 | while (1) { |
| 46 | time = bios->timebase_get(); |
||
| 47 | if ((time - time1) >= 2000) { |
||
| 290 | arune | 48 | //test-send a canmessage |
| 49 | bios->can_send(&txMsg); |
||
| 223 | andfri | 50 | time1 = time; |
| 325 | andfri | 51 | printf("Two seconds passed, time is now %ld.\n", time); |
| 223 | andfri | 52 | } |
| 53 | } |
||
| 54 | |||
| 55 | return 0; |
||
| 183 | andfri | 56 | } |