Subversion Repositories HomeAutomation

Rev

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

Rev Author Line No. Line
59 jimmy 1
#ifndef CAN_H_
2
#define CAN_H_
3
 
4
/*-----------------------------------------------------------------------------
5
 * Includes
6
 *---------------------------------------------------------------------------*/
7
#include <inttypes.h>
8
#include <can_cfg.h>
9
 
10
 
11
/*-----------------------------------------------------------------------------
12
 * Type Definitions
13
 *---------------------------------------------------------------------------*/
14
/**
15
 * CAN Bitrate type.
16
 */
17
typedef enum {
18
    CAN_BITRATE_125K = 0,
19
    CAN_BITRATE_250K = 1,
20
    CAN_BITRATE_500K = 2,
21
    CAN_BITRATE_1M = 3
127 jimmy 22
} Can_Bitrate_t;
59 jimmy 23
 
24
/**
25
 * CAN Return Type. Most CAN functions return one of these.
26
 */
27
typedef enum {
28
    CAN_OK = 0,
29
    CAN_FAILINIT = 1,
30
    CAN_FAILTX = 2,
31
    CAN_MSGAVAIL = 3,
32
    CAN_NOMSG = 4,
33
    CAN_CTRLERROR = 5,
34
    CAN_FAIL = 0xFF
127 jimmy 35
} Can_Return_t;
59 jimmy 36
 
37
/**
38
 * CAN Message Type. Stores a complete CAN frame.
39
 */
40
typedef struct {
41
    /*
69 jimmy 42
     * ID section. Contains either 29bit ID or 11bit ID (depending on ExtendedFlag).
59 jimmy 43
     */
44
    uint32_t Id;
45
 
46
    /*
47
     * DLC section. Contains the data length expressed in number of bytes. Range [0,8].
48
     */
49
    uint8_t DataLength;
50
 
51
    /**
52
     * Extended frame flag. Set to 1 if the ID is 29bit, or 0 if it is 11bit.
53
     */
54
    uint8_t ExtendedFlag;
55
 
56
    /**
57
     * Remote frame flag. Set to 1 if the frame is a remote frame. 0 otherwise.
58
     */
59
    uint8_t RemoteFlag;
60
 
61
    /*
62
     * DATA section. Contains the 8 data bytes.
63
     */
64
    union {
65
        /* read as 8bit unsigned data */
66
        uint8_t bytes[8];
67
 
68
        /* read as 16bit unsigned data */
69
        uint16_t words[4];
70
 
71
        /* read as 32bit unsigned data */
72
        uint32_t dwords[2];
73
    } Data;
127 jimmy 74
} Can_Message_t;
59 jimmy 75
 
76
 
77
/*-----------------------------------------------------------------------------
78
 * Public Function Prototypes
79
 *---------------------------------------------------------------------------*/
80
 
127 jimmy 81
Can_Return_t Can_Init(void);
82
Can_Return_t Can_Send(Can_Message_t* msg);
83
Can_Return_t Can_ReceiveAvailable(void);
84
Can_Return_t Can_Receive(Can_Message_t *msg);
85
Can_Return_t Can_CheckError(void);
59 jimmy 86
 
87
#if (CANDEBUG)
88
void can_debug1(void);
89
void can_dumpMessage(CanMessage *msg);
90
uint8_t can_testTransmit(const uint8_t ext, const uint8_t data2);
91
void can_dumpStatus(void);
92
#endif
93
 
94
#endif