Subversion Repositories HomeAutomation

Rev

Rev 378 | Blame | Compare with Previous | 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.    
  19.     sei();
  20.    
  21.     Serial_Init();
  22.    
  23.     Can_Message_t txMsg;
  24.     txMsg.Id = (CAN_NMT_APP_START << CAN_SHIFT_NMT_TYPE) | (NODE_ID << CAN_SHIFT_NMT_SID);
  25.     txMsg.DataLength = 4;
  26.     txMsg.RemoteFlag = 0;
  27.     txMsg.ExtendedFlag = 1;
  28.     txMsg.Data.words[0] = APP_TYPE;
  29.     txMsg.Data.words[1] = APP_VERSION;
  30.    
  31.     //set up callback for candata
  32.     bios->can_callback = &can_receive;
  33.     // Send CAN_NMT_APP_START
  34.     bios->can_send(&txMsg);
  35.    
  36.     printf("AVR Test Application\n");
  37.     printf("Using AVR BIOS version %x\n", bios->version);
  38.    
  39.     txMsg.Id = (CAN_TST << CAN_SHIFT_CLASS) | NODE_ID;
  40.     //txMsg.Data.dwords[0] = 0x01020304;
  41.     //txMsg.Data.dwords[1] = 0xfffefdfc;
  42.     txMsg.DataLength = 4;
  43.  
  44.     while (1) {
  45.         time = bios->timebase_get();
  46.         if ((time - time1) >= 2000) {
  47.             //test-send a canmessage
  48.             txMsg.Data.bytes[0] = time & 0x000000FF;
  49.             txMsg.Data.bytes[1] = (time & 0x0000FF00)>>8;
  50.             txMsg.Data.bytes[2] = (time & 0x00FF0000)>>16;
  51.             txMsg.Data.bytes[3] = (time & 0xFF000000)>>24;
  52.             bios->can_send(&txMsg);
  53.             time1 = time;
  54.             printf("Two seconds passed, time is now %ld.\n", time);
  55.         }
  56.     }
  57.    
  58.     return 0;
  59. }
  60.