Subversion Repositories HomeAutomation

Rev

Rev 290 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

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