mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/sta-core.git
synced 2025-06-10 16:55:58 +00:00
Merge pull request 'feature/secondary_can' (#33) from feature/secondary_can into main
Reviewed-on: https://git.intern.spaceteamaachen.de/ALPAKA/sta-core/pulls/33
This commit is contained in:
commit
519048b32b
@ -46,8 +46,10 @@ namespace sta
|
|||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* @param handle CAN handle
|
* @param handle CAN handle
|
||||||
|
*
|
||||||
|
* @param filter_start Start index for filters (default: 0 for can1, 14 for can2)
|
||||||
*/
|
*/
|
||||||
STM32CanController(CAN_HandleTypeDef * handle);
|
STM32CanController(CAN_HandleTypeDef * handle, uint32_t filter_start = 0);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Enable RX pending interrupts.
|
* @brief Enable RX pending interrupts.
|
||||||
@ -97,6 +99,7 @@ namespace sta
|
|||||||
private:
|
private:
|
||||||
CAN_HandleTypeDef * handle_; /**< CAN handle */
|
CAN_HandleTypeDef * handle_; /**< CAN handle */
|
||||||
CAN_FilterTypeDef filters_[MAX_FILTER_COUNT]; /**< Filter settings */
|
CAN_FilterTypeDef filters_[MAX_FILTER_COUNT]; /**< Filter settings */
|
||||||
|
uint32_t filter_start_; /**< Start index for filters */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -117,6 +120,15 @@ namespace sta
|
|||||||
* @ingroup sta_core_stm32_can
|
* @ingroup sta_core_stm32_can
|
||||||
*/
|
*/
|
||||||
void CanBus_RxPendingCallback();
|
void CanBus_RxPendingCallback();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Interrupt handler for pending RX frames. Secondary handler.
|
||||||
|
*
|
||||||
|
* May be implemented by application.
|
||||||
|
*
|
||||||
|
* @ingroup sta_core_stm32_can
|
||||||
|
*/
|
||||||
|
void CanBus_RxPendingCallbackSecondary();
|
||||||
#endif // STA_STM32_CAN_GLOBAL
|
#endif // STA_STM32_CAN_GLOBAL
|
||||||
} // namespace sta
|
} // namespace sta
|
||||||
|
|
||||||
|
@ -7,8 +7,8 @@
|
|||||||
|
|
||||||
namespace sta
|
namespace sta
|
||||||
{
|
{
|
||||||
STM32CanController::STM32CanController(CAN_HandleTypeDef * handle)
|
STM32CanController::STM32CanController(CAN_HandleTypeDef * handle, uint32_t filter_start)
|
||||||
: handle_{handle}
|
: handle_{handle}, filter_start_{filter_start}
|
||||||
{
|
{
|
||||||
initFilters();
|
initFilters();
|
||||||
}
|
}
|
||||||
@ -141,7 +141,7 @@ namespace sta
|
|||||||
|
|
||||||
void STM32CanController::clearFilters()
|
void STM32CanController::clearFilters()
|
||||||
{
|
{
|
||||||
for (uint32_t i = 0; i < MAX_FILTER_COUNT; ++i)
|
for (uint32_t i = filter_start_; i < filter_start_ + MAX_FILTER_COUNT; ++i)
|
||||||
{
|
{
|
||||||
CAN_FilterTypeDef * config = &filters_[i];
|
CAN_FilterTypeDef * config = &filters_[i];
|
||||||
|
|
||||||
@ -157,17 +157,23 @@ namespace sta
|
|||||||
|
|
||||||
void STM32CanController::initFilters()
|
void STM32CanController::initFilters()
|
||||||
{
|
{
|
||||||
for (uint32_t i = 0; i < MAX_FILTER_COUNT; ++i)
|
CAN_FilterTypeDef * config = &filters_[filter_start_];
|
||||||
{
|
if (filter_start_ == 0){
|
||||||
CAN_FilterTypeDef * config = &filters_[i];
|
config->FilterBank = 0;
|
||||||
|
}else{
|
||||||
config->FilterBank = i;
|
// Split can peripheral bank for any STM F4 series supporting multiple CAN peripherals
|
||||||
config->FilterMode = CAN_FILTERMODE_IDMASK;
|
config->FilterBank = filter_start_+1;
|
||||||
config->FilterScale = CAN_FILTERSCALE_32BIT;
|
|
||||||
config->FilterActivation = CAN_FILTER_DISABLE;
|
|
||||||
config->SlaveStartFilterBank = MAX_FILTER_COUNT;
|
|
||||||
HAL_CAN_ConfigFilter(handle_, config);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
config->FilterMode = CAN_FILTERMODE_IDMASK;
|
||||||
|
config->FilterScale = CAN_FILTERSCALE_32BIT;
|
||||||
|
config->FilterActivation = ENABLE;
|
||||||
|
config->FilterIdHigh = 0x0000;
|
||||||
|
config->FilterIdLow = 0x0000;
|
||||||
|
config->FilterMaskIdHigh = 0x0000;
|
||||||
|
config->FilterMaskIdLow = 0x0000;
|
||||||
|
config->SlaveStartFilterBank = filter_start_;
|
||||||
|
HAL_CAN_ConfigFilter(handle_, config);
|
||||||
}
|
}
|
||||||
|
|
||||||
CanPendingRxFifos STM32CanController::getPendingRxFifos(){
|
CanPendingRxFifos STM32CanController::getPendingRxFifos(){
|
||||||
@ -215,6 +221,10 @@ namespace sta
|
|||||||
STA_WEAK
|
STA_WEAK
|
||||||
void CanBus_RxPendingCallback(uint32_t fifo)
|
void CanBus_RxPendingCallback(uint32_t fifo)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
STA_WEAK
|
||||||
|
void CanBus_RxPendingCallbackSecondary(uint32_t fifo)
|
||||||
|
{}
|
||||||
} // namespace sta
|
} // namespace sta
|
||||||
|
|
||||||
|
|
||||||
@ -226,6 +236,10 @@ extern "C"
|
|||||||
{
|
{
|
||||||
sta::CanBus_RxPendingCallback(CAN_RX_FIFO0);
|
sta::CanBus_RxPendingCallback(CAN_RX_FIFO0);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sta::CanBus_RxPendingCallbackSecondary(CAN_RX_FIFO0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void HAL_CAN_RxFifo1MsgPendingCallback(CAN_HandleTypeDef *hcan)
|
void HAL_CAN_RxFifo1MsgPendingCallback(CAN_HandleTypeDef *hcan)
|
||||||
@ -234,6 +248,9 @@ extern "C"
|
|||||||
{
|
{
|
||||||
sta::CanBus_RxPendingCallback(CAN_RX_FIFO1);
|
sta::CanBus_RxPendingCallback(CAN_RX_FIFO1);
|
||||||
}
|
}
|
||||||
|
else{
|
||||||
|
sta::CanBus_RxPendingCallbackSecondary(CAN_RX_FIFO1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user