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

1 year ago
  1. #include "zirq_dispatcher.hpp"
  2. using namespace iflytop;
  3. using namespace std;
  4. extern "C" {
  5. /**
  6. * @brief HAL_TIM_PeriodElapsedCallback中调用
  7. *
  8. * @param htim
  9. */
  10. void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) {
  11. #ifdef PC_SYS_ZTICKET_TIMER
  12. if (htim->Instance == PC_SYS_ZTICKET_TIMER) {
  13. HAL_IncTick();
  14. return;
  15. }
  16. #endif
  17. ZIRQDispatcher::instance()._callOnTimIrq(htim);
  18. }
  19. void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size) {
  20. ZIRQDispatcher::uart_irq_data_t data = {0};
  21. data.huart = huart;
  22. data.Size = Size;
  23. ZIRQDispatcher::instance()._callOnUartIrq(ZIRQDispatcher::konHAL_UART_TxCpltCallback, data);
  24. }
  25. void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart) {
  26. ZIRQDispatcher::uart_irq_data_t data = {0};
  27. data.huart = huart;
  28. ZIRQDispatcher::instance()._callOnUartIrq(ZIRQDispatcher::konHAL_UART_TxCpltCallback, data);
  29. }
  30. void HAL_UART_TxHalfCpltCallback(UART_HandleTypeDef *huart) {
  31. ZIRQDispatcher::uart_irq_data_t data = {0};
  32. data.huart = huart;
  33. ZIRQDispatcher::instance()._callOnUartIrq(ZIRQDispatcher::konHAL_UART_TxHalfCpltCallback, data);
  34. }
  35. void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) {
  36. ZIRQDispatcher::uart_irq_data_t data = {0};
  37. data.huart = huart;
  38. ZIRQDispatcher::instance()._callOnUartIrq(ZIRQDispatcher::konHAL_UART_RxCpltCallback, data);
  39. }
  40. void HAL_UART_RxHalfCpltCallback(UART_HandleTypeDef *huart) {
  41. ZIRQDispatcher::uart_irq_data_t data = {0};
  42. data.huart = huart;
  43. ZIRQDispatcher::instance()._callOnUartIrq(ZIRQDispatcher::konHAL_UART_RxHalfCpltCallback, data);
  44. }
  45. void HAL_UART_ErrorCallback(UART_HandleTypeDef *huart) {
  46. ZIRQDispatcher::uart_irq_data_t data = {0};
  47. data.huart = huart;
  48. ZIRQDispatcher::instance()._callOnUartIrq(ZIRQDispatcher::konHAL_UART_ErrorCallback, data);
  49. }
  50. void HAL_UART_AbortCpltCallback(UART_HandleTypeDef *huart) {
  51. ZIRQDispatcher::uart_irq_data_t data = {0};
  52. data.huart = huart;
  53. ZIRQDispatcher::instance()._callOnUartIrq(ZIRQDispatcher::konHAL_UART_AbortCpltCallback, data);
  54. }
  55. void HAL_UART_AbortTransmitCpltCallback(UART_HandleTypeDef *huart) {
  56. ZIRQDispatcher::uart_irq_data_t data = {0};
  57. data.huart = huart;
  58. ZIRQDispatcher::instance()._callOnUartIrq(ZIRQDispatcher::konHAL_UART_AbortTransmitCpltCallback, data);
  59. }
  60. void HAL_UART_AbortReceiveCpltCallback(UART_HandleTypeDef *huart) {
  61. ZIRQDispatcher::uart_irq_data_t data = {0};
  62. data.huart = huart;
  63. ZIRQDispatcher::instance()._callOnUartIrq(ZIRQDispatcher::konHAL_UART_AbortReceiveCpltCallback, data);
  64. }
  65. }
  66. ZIRQDispatcher &ZIRQDispatcher::instance() {
  67. static ZIRQDispatcher instance;
  68. return instance;
  69. }
  70. void ZIRQDispatcher::regTimIrqListener(ontimirq_t listener) { m_ontimirqs.push_back(listener); }
  71. void ZIRQDispatcher::regUartIrqListener(on_uart_irq_t cb) { m_onuartirqs.push_back(cb); }
  72. void ZIRQDispatcher::_callOnTimIrq(zchip_tim_t *tim) {
  73. for (auto &listener : m_ontimirqs) {
  74. listener(tim);
  75. }
  76. }
  77. void ZIRQDispatcher::_callOnUartIrq(uart_irq_t irq_type, uart_irq_data_t data) {
  78. for (auto &listener : m_onuartirqs) {
  79. listener(irq_type, data);
  80. }
  81. }