You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
88 lines
3.3 KiB
88 lines
3.3 KiB
#include "zirq_dispatcher.hpp"
|
|
|
|
using namespace iflytop;
|
|
using namespace std;
|
|
|
|
extern "C" {
|
|
/**
|
|
* @brief 这个方法必须在HAL_TIM_PeriodElapsedCallback中调用
|
|
*
|
|
* @param htim
|
|
*/
|
|
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) {
|
|
#ifdef PC_SYS_ZTICKET_TIMER
|
|
if (htim->Instance == PC_SYS_ZTICKET_TIMER) {
|
|
HAL_IncTick();
|
|
return;
|
|
}
|
|
#endif
|
|
ZIRQDispatcher::instance()._callOnTimIrq(htim);
|
|
}
|
|
|
|
void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size) {
|
|
ZIRQDispatcher::uart_irq_data_t data = {0};
|
|
data.huart = huart;
|
|
data.Size = Size;
|
|
ZIRQDispatcher::instance()._callOnUartIrq(ZIRQDispatcher::konHAL_UART_TxCpltCallback, data);
|
|
}
|
|
|
|
void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart) {
|
|
ZIRQDispatcher::uart_irq_data_t data = {0};
|
|
data.huart = huart;
|
|
ZIRQDispatcher::instance()._callOnUartIrq(ZIRQDispatcher::konHAL_UART_TxCpltCallback, data);
|
|
}
|
|
void HAL_UART_TxHalfCpltCallback(UART_HandleTypeDef *huart) {
|
|
ZIRQDispatcher::uart_irq_data_t data = {0};
|
|
data.huart = huart;
|
|
ZIRQDispatcher::instance()._callOnUartIrq(ZIRQDispatcher::konHAL_UART_TxHalfCpltCallback, data);
|
|
}
|
|
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) {
|
|
ZIRQDispatcher::uart_irq_data_t data = {0};
|
|
data.huart = huart;
|
|
ZIRQDispatcher::instance()._callOnUartIrq(ZIRQDispatcher::konHAL_UART_RxCpltCallback, data);
|
|
}
|
|
void HAL_UART_RxHalfCpltCallback(UART_HandleTypeDef *huart) {
|
|
ZIRQDispatcher::uart_irq_data_t data = {0};
|
|
data.huart = huart;
|
|
ZIRQDispatcher::instance()._callOnUartIrq(ZIRQDispatcher::konHAL_UART_RxHalfCpltCallback, data);
|
|
}
|
|
void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart) {
|
|
ZIRQDispatcher::uart_irq_data_t data = {0};
|
|
data.huart = huart;
|
|
ZIRQDispatcher::instance()._callOnUartIrq(ZIRQDispatcher::konHAL_UART_ErrorCallback, data);
|
|
}
|
|
void HAL_UART_AbortCpltCallback(UART_HandleTypeDef *huart) {
|
|
ZIRQDispatcher::uart_irq_data_t data = {0};
|
|
data.huart = huart;
|
|
ZIRQDispatcher::instance()._callOnUartIrq(ZIRQDispatcher::konHAL_UART_AbortCpltCallback, data);
|
|
}
|
|
void HAL_UART_AbortTransmitCpltCallback(UART_HandleTypeDef *huart) {
|
|
ZIRQDispatcher::uart_irq_data_t data = {0};
|
|
data.huart = huart;
|
|
ZIRQDispatcher::instance()._callOnUartIrq(ZIRQDispatcher::konHAL_UART_AbortTransmitCpltCallback, data);
|
|
}
|
|
void HAL_UART_AbortReceiveCpltCallback(UART_HandleTypeDef *huart) {
|
|
ZIRQDispatcher::uart_irq_data_t data = {0};
|
|
data.huart = huart;
|
|
ZIRQDispatcher::instance()._callOnUartIrq(ZIRQDispatcher::konHAL_UART_AbortReceiveCpltCallback, data);
|
|
}
|
|
}
|
|
|
|
ZIRQDispatcher &ZIRQDispatcher::instance() {
|
|
static ZIRQDispatcher instance;
|
|
return instance;
|
|
}
|
|
|
|
void ZIRQDispatcher::regTimIrqListener(ontimirq_t listener) { m_ontimirqs.push_back(listener); }
|
|
void ZIRQDispatcher::regUartIrqListener(on_uart_irq_t cb) { m_onuartirqs.push_back(cb); }
|
|
|
|
void ZIRQDispatcher::_callOnTimIrq(zchip_tim_t *tim) {
|
|
for (auto &listener : m_ontimirqs) {
|
|
listener(tim);
|
|
}
|
|
}
|
|
void ZIRQDispatcher::_callOnUartIrq(uart_irq_t irq_type, uart_irq_data_t data) {
|
|
for (auto &listener : m_onuartirqs) {
|
|
listener(irq_type, data);
|
|
}
|
|
}
|