Subversion Repositories HomeAutomation

Rev

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

Rev Author Line No. Line
170 jimmy 1
/**
2
 * Communication services.
3
 *
173 jimmy 4
 * @date    2006-12-17
170 jimmy 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
 */
173 jimmy 72
static void Com_ParseReceivedMessage(Can_Message_t *canMsg) {
73
    /*
74
     * Prepare a COM message.
75
     */
76
    Com_Message_t comMsg;
174 jimmy 77
    /* Unpack the header fields */
173 jimmy 78
    comMsg.Funct =  (canMsg->Id & 0x1E000000L) >> 25;   /* bit[25..28] */
79
    comMsg.Funcc =  (canMsg->Id & 0x01FF8000L) >> 15;   /* bit[15..24] */
80
    comMsg.Nid =    (canMsg->Id & 0x00007E00L) >> 9;    /* bit[9..14] */
81
    comMsg.Sid =    (canMsg->Id & 0x000001FFL) >> 0;    /* bit[0..8] */
174 jimmy 82
    /* Copy data */
83
    comMsg.Data.dwords[0] = canMsg->Data.dwords[0];
84
    comMsg.Data.dwords[1] = canMsg->Data.dwords[1];
170 jimmy 85
 
173 jimmy 86
    /*
87
     * Parse the COM message.
88
     */
89
    //TODO
170 jimmy 90
}