PER Firmware
Loading...
Searching...
No Matches
can.h
Go to the documentation of this file.
1
12#ifndef _PHAL_CAN_H
13#define _PHAL_CAN_H
14
15#include "common/phal_F4_F7/phal_F4_F7.h"
16
17#define PHAL_CAN_TX_TIMEOUT (5000U)
18#define PHAL_CAN_INIT_TIMEOUT (5000U)
19
20// Bit timing recovered from http://www.bittiming.can-wiki.info/
21
22#define PHAL_CAN_16MHz_1M (0x033a0000)
23#define PHAL_CAN_24MHz_1M (0x03270001)
24#define PHAL_CAN_36MHz_1M (0x033c0001)
25#define PHAL_CAN_42MHz_1M (0x034e0001)
26
27#define PHAL_CAN_16MHz_500k (0x033a0001) // sample point = 75%, SJW = 4
28#define PHAL_CAN_24MHz_500k (0x033a0002) // sample point = 75%, SJW = 4
29#define PHAL_CAN_36MHz_500k (0x03270005)
30#define PHAL_CAN_42MHz_500k (0x034e0003) // sample point = 75%, SJW = 4
31
32#define PHAL_CAN_16MHz_250k (0x003a0003) // sample point = 75%
33#define PHAL_CAN_24MHz_250k (0x003a0005) // sample point = 75%
34#define PHAL_CAN_36MHz_250k (0x003a0008) // sample point = 75%
35
36typedef struct
37{
38 CAN_TypeDef* Bus;
39 uint16_t StdId;
40 uint32_t ExtId;
41 uint32_t IDE;
42 uint32_t DLC;
43 uint8_t Data[8];
45
55bool PHAL_initCAN(CAN_TypeDef* bus, bool test_mode, uint32_t bit_rate);
56
57bool PHAL_deinitCAN(CAN_TypeDef* bus);
58
68bool PHAL_txCANMessage(CanMsgTypeDef_t* msg, uint8_t mbx);
69bool PHAL_txMailboxFree(CAN_TypeDef* bus, uint8_t mbx);
70void PHAL_txCANAbort(CAN_TypeDef* bus, uint8_t mbx);
71bool PHAL_rxCANMessage(CAN_TypeDef *bus, uint8_t fifo, CanMsgTypeDef_t *msg);
72bool PHAL_anyTxMailboxFree(CAN_TypeDef* bus);
73bool PHAL_getFreeTxMailbox(CAN_TypeDef* bus, uint8_t* mbx);
74extern void PHAL_CAN_rxCallback(CanMsgTypeDef_t *msg);
75extern void PHAL_CAN_txCallback(CAN_TypeDef *can);
76
77#endif // _PHAL_CAN_H
bool PHAL_txCANMessage(CanMsgTypeDef_t *msg, uint8_t mbx)
Find an empty TX mailbox and transmit a CAN message if one is found. Function will block until sucess...
Definition can.c:160
bool PHAL_initCAN(CAN_TypeDef *bus, bool test_mode, uint32_t bit_rate)
Initilize CAN peripheral to bit_rate.
Definition can.c:15
Definition can.h:37
uint32_t ExtId
Definition can.h:40
CAN_TypeDef * Bus
Definition can.h:38
uint32_t DLC
Definition can.h:42
uint16_t StdId
Definition can.h:39
uint32_t IDE
Definition can.h:41