Subversion Repositories HomeAutomation

Rev

Rev 290 | Blame | Last modification | View Log | SVN | RSS feed

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