Subversion Repositories HomeAutomation

Rev

Details | Last modification | View Log | SVN | RSS feed

Rev Author Line No. Line
61 jimmy 1
/**
2
 * CAN test program.
3
 *
4
 * @target  AVR
5
 * @date    2006-10-29
6
 * @author  Jimmy Myhrman
7
 *  
8
 */
9
 
10
/*-----------------------------------------------------------------------------
11
 * Includes
12
 *---------------------------------------------------------------------------*/
13
/* system files */
14
#include <avr/io.h>
15
#include <avr/interrupt.h>
16
#include <avr/wdt.h>
17
#include <stdio.h>
18
/* lib files */
19
#include <can.h>
20
#include <uart.h>
21
#include <timebase.h>
22
#include <protocol.h>
23
 
24
 
25
/*-----------------------------------------------------------------------------
26
 * Main Program
27
 *---------------------------------------------------------------------------*/
28
int main(void) {
127 jimmy 29
    Timebase_Init();
30
    Uart_Init();
61 jimmy 31
    sei();
32
 
33
    printf("\n------------------------------\n");
34
    printf("   CAN Monitor\n");
35
    printf("------------------------------\n");
36
 
37
    printf("CanInit...");
127 jimmy 38
    if (Can_Init() != CAN_OK) {
61 jimmy 39
        printf("FAILED!\n");
40
    }
41
    else {
42
        printf("OK!\n");
43
    }
44
 
45
    uint32_t timeStamp = 0;
46
 
127 jimmy 47
    Can_Message_t txMsg;
48
    Can_Message_t rxMsg;
61 jimmy 49
 
50
    txMsg.DataLength = 8;
51
    txMsg.Data.bytes[0] = 7;
127 jimmy 52
    txMsg.Id = 0;
61 jimmy 53
    txMsg.RemoteFlag = 0;
54
    txMsg.ExtendedFlag = 1;
55
 
56
    /* main loop */
57
    while (1) {
58
        /* any new CAN messages received? */
127 jimmy 59
        if (Can_Receive(&rxMsg) == CAN_OK) {
61 jimmy 60
            ProtocolParseCanMessage(&rxMsg);
61
        }
62
 
63
        /* send CAN message and check for CAN errors once every second */
127 jimmy 64
        if (Timebase_PassedTimeMillis(timeStamp) >= 1000) {
65
            /* send txMsg */
61 jimmy 66
            txMsg.Id++;
127 jimmy 67
            Can_Send(&txMsg);
61 jimmy 68
            /* check for errors */
127 jimmy 69
            timeStamp = Timebase_CurrentTime();
70
            if (Can_CheckError() != CAN_OK) {
61 jimmy 71
                printf("CAN ERROR detected!\n");
72
            }
73
        }
74
    }
75
 
76
    return 0;
77
}