blob: 20843c6345c29a290b9dff8871f8833dd2ededdf (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
#ifndef __PLATFORM_STM32_CAN_H
#define __PLATFORM_STM32_CAN_H
#include <compiler.h>
#include <stdbool.h>
#include <stdint.h>
#include <sys/types.h>
typedef struct {
unsigned id:11; // Standard CAN identifier.
unsigned id_ex:18; // Extended CAN identifier.
unsigned rtr:1; // Remote transmit request.
unsigned ide:1; // Identifier extension.
unsigned pad:1;
uint8_t dlc; // Data length.
uint8_t data[8];
} __PACKED can_msg_t;
/**
* can_init
*
* Initialize the CAN peripheral.
*
* @param[in] loopback If true, puts the can interface in loopback mode.
*/
void can_init(bool loopback);
/**
* can_send
*
* Queues a can message to be sent. Does not block if there is no space
* in the CAN mailboxes.
*
* @param[in] msg Message to send.
*
* @return Negative error code on error, size of data queued on success.
*/
ssize_t can_send(const can_msg_t *msg);
/**
* can_recv
*
* @param[out] msg Received message
* @param[in] block If true, can_recv() will block until a message is received.
*
* @return Negative error code on error, size of data received on success.
*/
ssize_t can_recv(can_msg_t *msg, bool block);
#endif // __PLATFORM_STM32_CAN_H
|