1- version 1.2 :
1+ version 3.0.0.1 :
22
33The APIs below are meant to be generic and are not tied to any specific CAN
44hardware. However some of the APIs are specific to Baidu CAN
55(specifically noted below) and are exposed to advanced users.
66
7+ ======================================================
781. CAN CHANNEL ACCESS:
8- ---------------------
9+ ======================================================
9101.1)
10- int
11- bcan_open(uint32_t dev_index, uint32_t flags, uint64_t tx_timeout, uint64_t
11+ int bcan_open(uint32_t dev_index, uint32_t flags, uint64_t tx_timeout, uint64_t
1212 rx_timeout, bcan_hdl_t *hdl)
1313
1414This call will return a logical handle 'hdl' to a physical CAN interface. The
@@ -22,15 +22,14 @@ completely transparent to user).
2222Return value: 0 on success, error code (see Section 5) on failure.
2323
24241.2)
25- int
26- bcan_close(bcan_hdl_t hdl)
25+ int bcan_close(bcan_hdl_t hdl)
2726
2827This call will close the logical handle 'hdl'.
2928
3029Return value: 0 on success, error code (see Section 5) on failure.
3130
32311.3)
33- bcan_start(bcan_hdl_t hdl)
32+ int bcan_start(bcan_hdl_t hdl)
3433
3534This call will initialize the channel and put it in a state ready for transmitting
3635and receiving CAN frames.
@@ -39,7 +38,7 @@ For Baidu CAN: This will put the card in 'NORMAL' mode.
3938Return value: 0 on success, error code (see Section 5) on failure.
4039
41401.4)
42- bcan_stop(bcan_hdl_t hdl)
41+ int bcan_stop(bcan_hdl_t hdl)
4342
4443This call will stop any data from being received or transmitted on this channel.
4544Error counter and status registers will be reset.
@@ -57,35 +56,9 @@ This call return current libbcan version as a string.
5756
5857======================================================
59582. CHANNEL CONFIGURATION
60- ------------------------
61- Below bcan_id_*() APIs are a filter to receive messages from only desired CAN
62- IDs. These APIs are optional. By default all CAN messages will be accepted. All
63- bcan_id_*() call return 0 on success, error code (see Section 5) on failure.
59+ ======================================================
64602.1)
65- bcan_id_add(bcan_hdl_t hdl, uint32_t id_start, uint32_t id_end)
66-
67- All ids from 'id_start' to 'id_end' will be added to the receive acceptance
68- filter.
69-
70- 2.2)
71- bcan_id_add_all(bcan_hdl_t hdl)
72-
73- All CAN messages will be accepted.
74-
75- 2.3)
76- bcan_id_remove(bcan_hdl_t hdl, uint32_t id_start, uint32_t id_end)
77-
78- All ids from 'id_start' to 'id_end' will be removed from the receive acceptance
79- filter.
80-
81- 2.4)
82- bcan_id_remove_all(bcan_hdl_t hdl)
83-
84- No CAN messages will be received.
85-
86- 2.5)
87- int
88- bcan_set_baudrate(bcan_hdl_t hdl, uint32_t rate)
61+ int bcan_set_baudrate(bcan_hdl_t hdl, uint32_t rate)
8962
9063Specify 'rate' using one of the below supported values (defined in bcan.h). For
9164e.g. BCAN_BAUDRATE_500K means 500Kbps.
@@ -97,34 +70,31 @@ BCAN_BAUDRATE_1M
9770
9871Return value: 0 on success, error code (see Section 5) on failure.
9972
100- 2.6)
101- int
102- bcan_get_baudrate(bcan_hdl_t hdl, uint32_t *rate)
73+ 2.2)
74+ int bcan_get_baudrate(bcan_hdl_t hdl, uint32_t *rate)
10375
10476This call will return the current baudrate in Kbps via 'rate'.
10577Return value: 0 on success, error code (see Section 5) on failure.
10678
107- 2.7)
108- int
109- bcan_set_loopback(bcan_hdl_t hdl)
79+ 2.3)
80+ int bcan_set_loopback(bcan_hdl_t hdl)
11081
11182This API will cause all messages sent on Tx to be received on Rx. This is
11283effectively a self-test mode. Note all CAN devices may not support this mode.
11384
11485Return value: 0 on success, error code (see Section 5) on failure.
11586
116- 2.8)
117- int
118- bcan_unset_loopback(bcan_hdl_t hdl)
87+ 2.4)
88+ int bcan_unset_loopback(bcan_hdl_t hdl)
11989
12090This call will stop the loopback mode and will return the channel to normal
12191operational mode.
12292
12393Return value: 0 on success, error code (see Section 5) on failure.
12494
125- ==================================
95+ ======================================================
126963. DATA PATH
127- ------------
97+ ======================================================
12898typedef struct bcan_msg {
12999 uint32_t bcan_msg_id; // source CAN node id
130100 uint8_t bcan_msg_rsv[3]; // reserved for future
@@ -134,8 +104,7 @@ typedef struct bcan_msg {
134104} bcan_msg_t;
135105
1361063.1)
137- int
138- bcan_recv(bcan_hdl_t hdl, bcan_msg_t *buf, uint32_t num_msg)
107+ int bcan_recv(bcan_hdl_t hdl, bcan_msg_t *buf, uint32_t num_msg)
139108
140109This call will return with either the requested number of messages 'num_msg' or
141110the number of available messages in the RX FIFO, which ever is smaller. If Rx
@@ -148,8 +117,7 @@ On success this call will return the number of messages received. A error code
148117(see Section 5) is returned on failure.
149118
1501193.2)
151- int
152- bcan_send(bcan_hdl_t hdl, bcan_msg_t *buf, uint32_t num_msg)
120+ int bcan_send(bcan_hdl_t hdl, bcan_msg_t *buf, uint32_t num_msg)
153121
154122'num_msg' is the number of CAN messages to be sent. 'num_msg' should not exceed
155123BCAN_MAX_TX_MSG. The 'tx_timeout' specified in bcan_open() will be enforced by
@@ -161,22 +129,21 @@ has been enqueued in the Tx FIFO. A error code (see Section 5) is returned on
161129failure.
162130
1631313.3)
164- int
165- bcan_send_hi_pri(bcan_hdl_t hdl, bcan_msg_t *buf);
166- Baidu CAN CAN specific. Only 1 high priority message can be sent at a time.
132+ int bcan_send_hi_pri(bcan_hdl_t hdl, bcan_msg_t *buf);
133+ Baidu CAN specific. Only 1 high priority message can be sent at a time.
167134'tx_timeout' specified in bcan_open() does not apply to this call. Instead this
168135call will return immediately with either success or failure.
169136
170137Return value: On success this call will return the number of messages transmitted
171138which is 1. A error code (see Section 5) is returned on failure.
172139
173- =====================================
140+ ======================================================
1741414. DIAGNOSTIC:
175- -------------
176- Baidu CAN CAN specific
142+ ======================================================
143+ Baidu CAN specific.
144+
1771454.1)
178- int
179- bcan_get_status(bcan_hdl_t hdl)
146+ int bcan_get_status(bcan_hdl_t hdl)
180147
181148This call will return the overall status of the channel hardware. A error code
182149(defined in section 5) is returned on error.
@@ -187,48 +154,38 @@ register, 'value' is the return value from bcan_get_status().
187154BCAN_GET_FIFO_STATUS(value) -> returns Acceptance filter status, Tx FIFO and
188155 High Priority Buffer status.
189156
190- BCAN_GET_ERR_STATUS(value) -> returns error active, error passive or bus off
191- state.
157+ BCAN_GET_ERR_STATUS(value) -> returns error active, error passive or bus off state.
192158
193159BCAN_GET_BUS_STATUS(value) -> returns Busy or Idle
194160
195161BCAN_GET_MODE_STATUS(value) -> returns Normal, Sleep, Loopback, Configuration
196162
197-
1981634.2)
199- int
200- bcan_get_err_counter(bcan_hdl_t hdl, uint8_t *rx_err_counter, uint8_t *tx_err_counter)
164+ int bcan_get_err_counter(bcan_hdl_t hdl, uint8_t *rx_err_counter, uint8_t *tx_err_counter)
201165
202166After this call 'rx_err_counter' and 'tx_err_counter' will contain the
203167respective values from the Error Count register. These values are a indicator
204168of the health of the CAN controller and bus.
205169
206170Return value: 0 on success, error code (see Section 5) on failure.
207171
208-
209- ================================================
172+ ======================================================
2101735. Version & Build Info
174+ ======================================================
175+ 5.1)
176+ const char *bcan_get_libversion(void)
211177
212- New in 1.2. See tools/bcan/can_app.c for usage examples.
213-
214- - Returns bcan library version; e.g., "1.2".
215- const char *bcan_get_libversion(void)
216-
217- - Returns detailed bcan library build info.
218- const char *bcan_bld_info(void);
219-
220- - Returns brief bcan library build info.
221- const char *bcan_bld_info_short(void);
222-
178+ Return bcan library version; e.g., "3.0.0.1".
223179
224- ================================================
180+ ======================================================
2251816. Error codes
182+ ======================================================
183+ 6.1)
184+ const char *bcan_get_err_msg(int err_code);
226185
227- API (new in 1.2):
228-
229- - Returns error message corresponding to the given error code.
230- const char *bcan_get_err_msg(int err_code);
186+ Return error message corresponding to the given error code.
231187
188+ 6.2)
232189List of error code; all values below are negative.
233190
234191- BCAN_HDL_INVALID
0 commit comments