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.

50 lines
1.2 KiB

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