Subversion Repositories HomeAutomation

Rev

Rev 325 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

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