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.

46 lines
926 B

11 months ago
  1. #pragma once
  2. #include "cmsis_os.h"
  3. #include "stm32basic/stm32basic.hpp"
  4. #include "stm32basic/zqueue.hpp"
  5. namespace iflytop {
  6. using namespace std;
  7. typedef struct {
  8. uint32_t extid;
  9. uint8_t rxpacket[8];
  10. int32_t rkpacketlen;
  11. } zcanrx_t;
  12. class ZCAN1 {
  13. zmutex m_lock = {"ZCAN1"};
  14. ZThread canListener;
  15. ZQueue<zcanrx_t> rxQueue;
  16. function<void(zcanrx_t* rx)> onZcanRx;
  17. public:
  18. ZCAN1() {}
  19. static ZCAN1 *ins() {
  20. static ZCAN1 instance;
  21. return &instance;
  22. }
  23. void init();
  24. bool txMsg(const uint32_t extid, const uint8_t txdata[], uint32_t txdatalen, int32_t overtime);
  25. bool getRxMsg(zcanrx_t *rx);
  26. void regOnCanMessagePending(function<void()> fn);
  27. public:
  28. void STM32_HAL_onCAN_RxFifo0MsgPending(CAN_HandleTypeDef *can);
  29. void STM32_HAL_onCAN_Error(CAN_HandleTypeDef *can);
  30. private:
  31. HAL_StatusTypeDef initializeFilter();
  32. HAL_StatusTypeDef activateRxIT();
  33. };
  34. } // namespace iflytop