can-halal/can-halal.h

51 lines
1.5 KiB
C
Raw Normal View History

2023-03-18 20:20:00 +01:00
#ifndef CAN_HALAL_H
#define CAN_HALAL_H
2023-03-14 16:22:58 +01:00
#if defined(STM32F3)
#include "stm32f3xx_hal.h"
#define FTCAN_IS_BXCAN
2023-03-16 22:45:44 +01:00
#define FTCAN_NUM_FILTERS 13
#elif defined(STM32H7)
#include "stm32h7xx_hal.h"
#define FTCAN_IS_FDCAN
2023-03-14 16:22:58 +01:00
#else
#error "Couldn't detect STM family"
2023-03-16 22:45:44 +01:00
#endif
2023-03-14 16:22:58 +01:00
2023-03-16 22:45:44 +01:00
#if defined(FTCAN_IS_BXCAN)
2023-03-14 16:22:58 +01:00
HAL_StatusTypeDef ftcan_init(CAN_HandleTypeDef *handle);
2023-03-16 22:45:44 +01:00
#elif defined(FTCAN_IS_FDCAN)
HAL_StatusTypeDef ftcan_init(FDCAN_HandleTypeDef *handle);
#else
#error "Unknown CAN peripheral"
#endif
2023-03-14 16:22:58 +01:00
2023-03-15 18:04:44 +01:00
HAL_StatusTypeDef ftcan_transmit(uint16_t id, const uint8_t *data,
2023-03-14 16:22:58 +01:00
size_t datalen);
2023-03-15 18:04:44 +01:00
HAL_StatusTypeDef ftcan_add_filter(uint16_t id, uint16_t mask);
2023-03-14 16:22:58 +01:00
/**
* Define this function to be notified of incoming CAN messages
*/
2023-03-15 18:04:44 +01:00
void ftcan_msg_received_cb(uint16_t id, size_t datalen, const uint8_t *data);
2023-03-14 16:22:58 +01:00
/**
* Read num_bytes bytes from a message (unmarshalled network byte order). The
* msg pointer is advanced by the corresponding number of bytes.
*
* Both methods return a 64-bit integer, but you can safely cast it to a smaller
* integer type.
*/
uint64_t ftcan_unmarshal_unsigned(const uint8_t **data, size_t num_bytes);
int64_t ftcan_unmarshal_signed(const uint8_t **data, size_t num_bytes);
/**
* Write num_bytes to a message (marshalled in network byte order). The pointer
* is advanced by the corresponding number of bytes and returned.
*/
uint8_t *ftcan_marshal_unsigned(uint8_t *data, uint64_t val, size_t num_bytes);
uint8_t *ftcan_marshal_signed(uint8_t *data, int64_t val, size_t num_bytes);
2023-03-18 20:20:00 +01:00
#endif // CAN_HALAL_H