Subversion Repositories HomeAutomation

Rev

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