Rev 244 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 244 | Rev 250 | ||
|---|---|---|---|
| 1 | #ifndef CAN_H_ |
1 | #ifndef CAN_H_ |
| 2 | #define CAN_H_ |
2 | #define CAN_H_ |
| 3 | 3 | ||
| 4 | /*----------------------------------------------------------------------------- |
4 | /*----------------------------------------------------------------------------- |
| 5 | * Includes |
5 | * Includes |
| 6 | *---------------------------------------------------------------------------*/ |
6 | *---------------------------------------------------------------------------*/ |
| 7 | #include <inttypes.h> |
7 | #include <inttypes.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 */ |
- | |
| 20 | 8 | ||
| 21 | 9 | ||
| 22 | /*----------------------------------------------------------------------------- |
10 | /*----------------------------------------------------------------------------- |
| 23 | * Type Definitions |
11 | * Type Definitions |
| 24 | *---------------------------------------------------------------------------*/ |
12 | *---------------------------------------------------------------------------*/ |
| 25 | - | ||
| 26 | #if 0 |
- | |
| 27 | /** |
- | |
| 28 | * CAN Bitrate Type. The supported bitrates. |
- | |
| 29 | */ |
- | |
| 30 | typedef enum { |
- | |
| 31 | CAN_BITRATE_125K = 0, /* Max cable length: 500m */ |
- | |
| 32 | CAN_BITRATE_250K = 1, /* Max cable length: 250m */ |
- | |
| 33 | CAN_BITRATE_500K = 2, /* Max cable length: 100m */ |
- | |
| 34 | CAN_BITRATE_1M = 3 /* Max cable length: 40m */ |
- | |
| 35 | } Can_Bitrate_t; |
- | |
| 36 | #endif |
- | |
| 37 | 13 | ||
| 38 | 14 | ||
| 39 | /** |
15 | /** |
| 40 | * CAN Return Type. Most CAN functions return one of these. |
16 | * CAN Return Type. Most CAN functions return one of these. |
| 41 | */ |
17 | */ |
| 42 | typedef enum { |
18 | typedef enum { |
| 43 | CAN_FAIL = -1, /* The function failed */ |
19 | CAN_FAIL = -1, /* The function failed */ |
| 44 | CAN_OK = 1, /* The function succeeded */ |
20 | CAN_OK = 1, /* The function succeeded */ |
| 45 | 21 | ||
| 46 | CAN_MSG_AVAILABLE = 2, /* Messsages are available */ |
22 | CAN_MSG_AVAILABLE = 2, /* Messsages are available */ |
| 47 | CAN_NO_MSG_AVAILABLE = -2, /* Messages are NOT available */ |
23 | CAN_NO_MSG_AVAILABLE = -2, /* Messages are NOT available */ |
| 48 | 24 | ||
| 49 | //CAN_CTRLERROR = -4 |
25 | //CAN_CTRLERROR = -4 |
| 50 | } Can_Return_t; |
26 | } Can_Return_t; |
| 51 | 27 | ||
| 52 | 28 | ||
| 53 | /** |
29 | /** |
| 54 | * CAN Message Type. Stores a complete CAN frame. |
30 | * CAN Message Type. Stores a complete CAN frame. |
| 55 | */ |
31 | */ |
| 56 | typedef struct { |
32 | typedef struct { |
| 57 | /* |
33 | /* |
| 58 | * ID section. Contains either 29bit ID or 11bit ID (depending on ExtendedFlag). |
34 | * ID section. Contains either 29bit ID or 11bit ID (depending on ExtendedFlag). |
| 59 | */ |
35 | */ |
| 60 | uint32_t Id; |
36 | uint32_t Id; |
| 61 | 37 | ||
| 62 | /* |
38 | /* |
| 63 | * DLC section. Contains the data length expressed in number of bytes. Range [0,8]. |
39 | * DLC section. Contains the data length expressed in number of bytes. Range [0,8]. |
| 64 | */ |
40 | */ |
| 65 | uint8_t DataLength; |
41 | uint8_t DataLength; |
| 66 | 42 | ||
| 67 | /** |
43 | /** |
| 68 | * Extended frame flag. Set to 1 if the ID is 29bit, or 0 if it is 11bit. |
44 | * Extended frame flag. Set to 1 if the ID is 29bit, or 0 if it is 11bit. |
| 69 | */ |
45 | */ |
| 70 | uint8_t ExtendedFlag; |
46 | uint8_t ExtendedFlag; |
| 71 | 47 | ||
| 72 | /** |
48 | /** |
| 73 | * Remote frame flag. Set to 1 if the frame is a remote frame. 0 otherwise. |
49 | * Remote frame flag. Set to 1 if the frame is a remote frame. 0 otherwise. |
| 74 | */ |
50 | */ |
| 75 | uint8_t RemoteFlag; |
51 | uint8_t RemoteFlag; |
| 76 | 52 | ||
| 77 | /* |
53 | /* |
| 78 | * DATA section. Contains the 8 data bytes. |
54 | * DATA section. Contains the 8 data bytes. |
| 79 | */ |
55 | */ |
| 80 | union { |
56 | union { |
| 81 | /* read as 8bit unsigned data */ |
57 | /* read as 8bit unsigned data */ |
| 82 | uint8_t bytes[8]; |
58 | uint8_t bytes[8]; |
| 83 | 59 | ||
| 84 | /* read as 16bit unsigned data */ |
60 | /* read as 16bit unsigned data */ |
| 85 | uint16_t words[4]; |
61 | uint16_t words[4]; |
| 86 | 62 | ||
| 87 | /* read as 32bit unsigned data */ |
63 | /* read as 32bit unsigned data */ |
| 88 | uint32_t dwords[2]; |
64 | uint32_t dwords[2]; |
| 89 | } Data; |
65 | } Data; |
| 90 | } Can_Message_t; |
66 | } Can_Message_t; |
| 91 | 67 | ||
| 92 | 68 | ||
| 93 | /*----------------------------------------------------------------------------- |
69 | /*----------------------------------------------------------------------------- |
| 94 | * Public Function Prototypes |
70 | * Public Function Prototypes |
| 95 | *---------------------------------------------------------------------------*/ |
71 | *---------------------------------------------------------------------------*/ |
| 96 | 72 | ||
| 97 | Can_Return_t Can_Init |
73 | //Can_Return_t Can_Init(void); |
| 98 | Can_Return_t Can_Send |
74 | //Can_Return_t Can_Send(Can_Message_t* msg); |
| 99 |
|
75 | //void Can_Service(void); |
| 100 | Can_Return_t Can_Receive |
76 | //Can_Return_t Can_Receive(Can_Message_t *msg); |
| 101 | 77 | ||
| 102 | #endif |
78 | #endif |
| 103 | 79 | ||