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.

47 lines
985 B

11 months ago
11 months ago
11 months ago
11 months ago
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. bool inited = false;
  18. public:
  19. ZCAN1() {}
  20. static ZCAN1 *ins() {
  21. static ZCAN1 instance;
  22. return &instance;
  23. }
  24. void init();
  25. bool txMsg(const uint32_t extid, const uint8_t txdata[], uint32_t txdatalen, int32_t overtime);
  26. bool getRxMsg(zcanrx_t *rx);
  27. void regOnCanMessage(function<void(zcanrx_t *rx)> onmessage);
  28. public:
  29. void STM32_HAL_onCAN_RxFifo0MsgPending(CAN_HandleTypeDef *can);
  30. void STM32_HAL_onCAN_Error(CAN_HandleTypeDef *can);
  31. private:
  32. HAL_StatusTypeDef initializeFilter();
  33. HAL_StatusTypeDef activateRxIT();
  34. };
  35. } // namespace iflytop