Subversion Repositories HomeAutomation

Rev

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

Rev 127 Rev 142
Line 4... Line 4...
4
/*-----------------------------------------------------------------------------
4
/*-----------------------------------------------------------------------------
5
 * Includes
5
 * Includes
6
 *---------------------------------------------------------------------------*/
6
 *---------------------------------------------------------------------------*/
7
#include <inttypes.h>
7
#include <inttypes.h>
8
#include <can_cfg.h>
8
#include <can_cfg.h>
-
 
9
 
-
 
10
 
-
 
11
/*-----------------------------------------------------------------------------
-
 
12
 * Defines
-
 
13
 *---------------------------------------------------------------------------*/
-
 
14
 
-
 
15
/*
-
 
16
 * The supported CAN controller devices are listed below.
-
 
17
 */
-
 
18
#define CAN_CONTROLLER_NULL     0       /* Virtual null-device */
-
 
19
#define CAN_CONTROLLER_MCP2515  1       /* Microchip MCP2515 via SPI */
9
 
20
 
10
 
21
 
11
/*-----------------------------------------------------------------------------
22
/*-----------------------------------------------------------------------------
12
 * Type Definitions
23
 * Type Definitions
13
 *---------------------------------------------------------------------------*/
24
 *---------------------------------------------------------------------------*/
-
 
25
 
14
/**
26
/**
15
 * CAN Bitrate type.
27
 * CAN Bitrate Type. The supported bitrates.
16
 */
28
 */
17
typedef enum {
29
typedef enum {
18
    CAN_BITRATE_125K = 0,
30
    CAN_BITRATE_125K = 0,           /* Max cable length: 500m */
19
    CAN_BITRATE_250K = 1,
31
    CAN_BITRATE_250K = 1,           /* Max cable length: 250m */
20
    CAN_BITRATE_500K = 2,
32
    CAN_BITRATE_500K = 2,           /* Max cable length: 100m */
21
    CAN_BITRATE_1M = 3
33
    CAN_BITRATE_1M = 3              /* Max cable length: 40m */
22
} Can_Bitrate_t;
34
} Can_Bitrate_t;
-
 
35
 
23
 
36
 
24
/**
37
/**
25
 * CAN Return Type. Most CAN functions return one of these.
38
 * CAN Return Type. Most CAN functions return one of these.
26
 */
39
 */
27
typedef enum {
40
typedef enum {
28
    CAN_OK = 0,
41
    CAN_FAIL = -1,                  /* The function failed */
29
    CAN_FAILINIT = 1,
42
    CAN_OK = 1,                     /* The function succeeded */
-
 
43
   
30
    CAN_FAILTX = 2,
44
    CAN_MSG_AVAILABLE = 2,          /* Messsages are available */
31
    CAN_MSGAVAIL = 3,
45
    CAN_NO_MSG_AVAILABLE = -2,      /* Messages are NOT available */
32
    CAN_NOMSG = 4,
46
   
33
    CAN_CTRLERROR = 5,
47
    //CAN_CTRLERROR = -4
34
    CAN_FAIL = 0xFF
-
 
35
} Can_Return_t;
48
} Can_Return_t;
-
 
49
 
36
 
50
 
37
/**
51
/**
38
 * CAN Message Type. Stores a complete CAN frame.
52
 * CAN Message Type. Stores a complete CAN frame.
39
 */
53
 */
40
typedef struct {
54
typedef struct {
41
    /*
55
    /*
42
     * ID section. Contains either 29bit ID or 11bit ID (depending on ExtendedFlag).
56
     * ID section. Contains either 29bit ID or 11bit ID (depending on ExtendedFlag).
43
     */
57
     */
44
    uint32_t Id;
58
    uint32_t Id;
45
   
59
   
46
    /*
60
    /*
47
     * DLC section. Contains the data length expressed in number of bytes. Range [0,8].
61
     * DLC section. Contains the data length expressed in number of bytes. Range [0,8].
48
     */
62
     */
49
    uint8_t DataLength;
63
    uint8_t DataLength;
50
   
64
   
51
    /**
65
    /**
Line 78... Line 92...
78
 * Public Function Prototypes
92
 * Public Function Prototypes
79
 *---------------------------------------------------------------------------*/
93
 *---------------------------------------------------------------------------*/
80
 
94
 
81
Can_Return_t Can_Init(void);
95
Can_Return_t Can_Init(void);
82
Can_Return_t Can_Send(Can_Message_t* msg);
96
Can_Return_t Can_Send(Can_Message_t* msg);
83
Can_Return_t Can_ReceiveAvailable(void);
97
void Can_Service(void);
84
Can_Return_t Can_Receive(Can_Message_t *msg);
98
Can_Return_t Can_Receive(Can_Message_t *msg);
85
Can_Return_t Can_CheckError(void);
-
 
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
 
99
 
94
#endif
100
#endif