can-halal/can-halal.h

72 lines
2.2 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
// Define family macros if none are defined and we recognize a chip macro
2024-11-02 17:31:54 +01:00
#if !defined(STM32F3) && !defined(STM32H7) && !defined(STM32F0)
#if defined(STM32F302x6) || defined(STM32F302x8) || defined(STM32F302xB) || \
defined(STM32F302xC)
#define STM32F3
#endif
#if defined(STM32H7A3xx)
#define STM32H7
#endif
2024-11-02 17:31:54 +01:00
#if defined(STM32F042x6)
#define STM32F0
#endif
#endif
2023-03-14 16:22:58 +01:00
#if defined(STM32F3)
2024-11-02 17:31:54 +01:00
#include "stm32f3xx_hal.h"
#define FTCAN_IS_BXCAN
#define FTCAN_NUM_FILTERS 13
2023-03-16 22:45:44 +01:00
#elif defined(STM32H7)
2024-11-02 17:31:54 +01:00
#include "stm32h7xx_hal.h"
#define FTCAN_IS_FDCAN
#ifndef FTCAN_NUM_FILTERS
#error "Please configure the number of filters in CubeMX, and then add a compiler define for FTCAN_NUM_FILTERS"
#endif
#elif defined(STM32F0)
#include "stm32f0xx_hal.h"
#define FTCAN_IS_BXCAN
#define FTCAN_NUM_FILTERS 13
2023-03-14 16:22:58 +01:00
#else
2024-11-02 17:31:54 +01:00
#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