Subversion Repositories HomeAutomation

Rev

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

Rev Author Line No. Line
170 jimmy 1
/**
2
 * Communication services.
3
 *
4
 * @date    2006-10-29
5
 * @author  Jimmy Myhrman
6
 */
7
 
8
/*-----------------------------------------------------------------------------
9
 * Includes
10
 *---------------------------------------------------------------------------*/
11
#include <com.h>
12
#include <can.h>
13
#include <stdio.h>
14
 
15
 
16
/*-----------------------------------------------------------------------------
17
 * Variables
18
 *---------------------------------------------------------------------------*/
19
 
20
 
21
/*-----------------------------------------------------------------------------
22
 * Private Function Prototypes
23
 *---------------------------------------------------------------------------*/
24
static void Com_ParseReceivedMessage(Can_Message_t *msg);
25
 
26
 
27
/*-----------------------------------------------------------------------------
28
 * Public Functions
29
 *---------------------------------------------------------------------------*/
30
 
31
/**
32
 * Initializes the communication subsystem.
33
 */
34
void Com_Init() {
35
    //TODO
36
}
37
 
38
 
39
/**
40
 * Services the communication subsystems.
41
 */
42
void Com_Service() {
43
    Can_Message_t msgBuf;
44
 
45
    /*
46
     * Empty the CAN receive FIFO and parse the messages.
47
     * TODO: don't empty the whole FIFO. best flow is probably obtained if
48
     *       we pull the same number of messages as the number of RX buffers
49
     *       the used CC has.
50
     */
51
    while (Can_Receive(&msgBuf)) {
52
        Com_ParseReceivedMessage(&msgBuf);
53
    }
54
 
55
    /*
56
     * Service the CAN drivers. Receive and transmit pending CAN messages.
57
     */
58
    Can_Service();
59
}
60
 
61
 
62
/*-----------------------------------------------------------------------------
63
 * Private Functions
64
 *---------------------------------------------------------------------------*/
65
 
66
/**
67
 * Parses a received CAN message in accordance with the protocol.
68
 *
69
 * @param msg
70
 *          Pointer to the CAN message structure.
71
 */
72
static void Com_ParseReceivedMessage(Can_Message_t *msg) {
73
#if 0
74
    printf("Com_ParseReceivedMessage: {ID=%x, DLC=%u, EXT=%u, RTR=%u}\n\r", msg->Id, msg->DataLength, msg->ExtendedFlag, msg->RemoteFlag);
75
#endif
76
 
77
    //TODO: pack
78
 
79
}