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> |
| 5 | |||
| 6 | static int app_putchar(char c, FILE *stream); |
||
| 7 | static int app_getchar(FILE *stream); |
||
| 8 | |||
| 9 | static FILE mystdio = FDEV_SETUP_STREAM(app_putchar, app_getchar, |
||
| 10 | _FDEV_SETUP_RW); |
||
| 11 | |||
| 12 | static int app_putchar(char c, FILE *stream) { |
||
| 267 | andfri | 13 | bios->debug_putchar(c); |
| 223 | andfri | 14 | return 0; |
| 183 | andfri | 15 | } |
| 16 | |||
| 17 | static int app_getchar(FILE *stream) { |
||
| 267 | andfri | 18 | return bios->debug_getchar(); |
| 183 | andfri | 19 | } |
| 20 | |||
| 290 | arune | 21 | void can_receive(Can_Message_t *msg) { |
| 22 | printf("candata!\n"); |
||
| 23 | } |
||
| 24 | |||
| 183 | andfri | 25 | int main(void) |
| 26 | { |
||
| 268 | arune | 27 | unsigned long time; |
| 290 | arune | 28 | unsigned long time1 = bios->timebase_get(); |
| 29 | unsigned long time2 = bios->timebase_get(); |
||
| 183 | andfri | 30 | |
| 223 | andfri | 31 | sei(); |
| 32 | |||
| 183 | andfri | 33 | stdout = &mystdio; |
| 34 | stdin = &mystdio; |
||
| 290 | arune | 35 | |
| 36 | Can_Message_t txMsg; |
||
| 37 | txMsg.Id = 100; |
||
| 38 | txMsg.DataLength = 0; |
||
| 39 | txMsg.RemoteFlag = 0; |
||
| 40 | txMsg.ExtendedFlag = 1; |
||
| 183 | andfri | 41 | |
| 290 | arune | 42 | //set up callback for candata |
| 43 | bios->can_callback = &can_receive; |
||
| 44 | |||
| 183 | andfri | 45 | printf("AVR Test Application\n"); |
| 223 | andfri | 46 | printf("Using AVR BIOS version %x\n", bios->version); |
| 183 | andfri | 47 | |
| 223 | andfri | 48 | while (1) { |
| 49 | time = bios->timebase_get(); |
||
| 50 | if ((time - time1) >= 2000) { |
||
| 290 | arune | 51 | //test-send a canmessage |
| 52 | bios->can_send(&txMsg); |
||
| 223 | andfri | 53 | time1 = time; |
| 54 | printf("Two seconds passed, time is now %d.\n", (int)time); |
||
| 55 | } |
||
| 56 | |||
| 57 | if ((time - time2) >= 20000) { |
||
| 58 | time2 = time; |
||
| 59 | printf("Will now hang node.\n"); |
||
| 60 | cli(); |
||
| 61 | } |
||
| 62 | } |
||
| 63 | |||
| 64 | return 0; |
||
| 183 | andfri | 65 | } |