PER Firmware
Loading...
Searching...
No Matches
can.h
Go to the documentation of this file.
1
9#ifndef _PHAL_CAN_H
10#define _PHAL_CAN_H
11
12#include "phal_F4/phal_F4.h"
13
14// Bit timing recovered from http://www.bittiming.can-wiki.info/
15
16#define PHAL_CAN_16MHZ_1M (0x033a0000)
17#define PHAL_CAN_24MHZ_1M (0x03270001)
18#define PHAL_CAN_36MHZ_1M (0x033c0001)
19#define PHAL_CAN_42MHZ_1M (0x034e0001)
20
21#define PHAL_CAN_16MHZ_500K (0x033a0001) // sample point = 75%, SJW = 4
22#define PHAL_CAN_24MHZ_500K (0x033a0002) // sample point = 75%, SJW = 4
23#define PHAL_CAN_25MHZ_500K (0x01160004) // 10 time quanta, sample point = 80%, SJW = 2
24#define PHAL_CAN_36MHZ_500K (0x03270005)
25#define PHAL_CAN_42MHZ_500K (0x034e0003) // sample point = 75%, SJW = 4
26
27#define PHAL_CAN_16MHZ_250K (0x003a0003) // sample point = 75%
28#define PHAL_CAN_24MHZ_250K (0x003a0005) // sample point = 75%
29#define PHAL_CAN_36MHZ_250K (0x003a0008) // sample point = 75%
30
31#define PHAL_CAN_MAX_NUM_SID_FILTER (28U)
32#define PHAL_CAN_MAX_NUM_XID_FILTER (8U)
33
37typedef enum : uint32_t {
38 FDCAN_BAUD_250K = 250'000U,
39 FDCAN_BAUD_500K = 500'000U,
40 FDCAN_BAUD_1M = 1'000'000U
42
48typedef struct {
49 CAN_TypeDef *Bus;
51 bool IDE;
52
53 union {
54 uint16_t StdId;
55 uint32_t ExtId;
56 };
57
58 uint8_t DLC;
59 uint8_t Data[8];
61
67bool PHAL_CAN_init(CAN_TypeDef *bus, PHAL_FDCAN_BaudRate_t bit_rate);
68
70bool PHAL_CAN_setFilters(CAN_TypeDef *bus,
71 const uint32_t *sid_list,
72 uint32_t num_sid,
73 const uint32_t *xid_list,
74 uint32_t num_xid);
75
78
80bool PHAL_CAN_txFifoFree(const CAN_TypeDef *bus);
81
82/* Override these weak callbacks in application code. RX messages live only during the callback. */
83
84extern void PHAL_CAN_rxCallback(CanMsgTypeDef_t *msg);
85extern void PHAL_CAN_txCallback(CAN_TypeDef *can);
86
87#endif // _PHAL_CAN_H
bool PHAL_CAN_init(CAN_TypeDef *bus, PHAL_FDCAN_BaudRate_t bit_rate)
Definition can.c:104
bool PHAL_CAN_setFilters(CAN_TypeDef *bus, const uint32_t *sid_list, uint32_t num_sid, const uint32_t *xid_list, uint32_t num_xid)
Definition can.c:138
bool PHAL_CAN_send(CanMsgTypeDef_t *msg)
Definition can.c:163
bool PHAL_CAN_txFifoFree(const CAN_TypeDef *bus)
Definition can.c:197
PHAL_FDCAN_BaudRate_t
Supported baud rates for PER F4 CAN HAL.
Definition can.h:37
@ FDCAN_BAUD_1M
Definition can.h:40
@ FDCAN_BAUD_500K
Definition can.h:39
@ FDCAN_BAUD_250K
Definition can.h:38
void PHAL_CAN_txCallback(CAN_TypeDef *can)
Definition can.c:263
void PHAL_CAN_rxCallback(CanMsgTypeDef_t *msg)
Definition can_callback.c:32
Classic CAN frame.
Definition can.h:48
uint32_t ExtId
Definition can.h:55
CAN_TypeDef * Bus
Definition can.h:49
uint8_t DLC
Definition can.h:58
uint16_t StdId
Definition can.h:54
bool IDE
Definition can.h:51