CAN.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * This file is free software: you can redistribute it and/or modify it
  3. * under the terms of the GNU General Public License as published by the
  4. * Free Software Foundation, either version 3 of the License, or
  5. * (at your option) any later version.
  6. *
  7. * This file is distributed in the hope that it will be useful, but
  8. * WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. * See the GNU General Public License for more details.
  11. *
  12. * You should have received a copy of the GNU General Public License along
  13. * with this program. If not, see <http://www.gnu.org/licenses/>.
  14. *
  15. * Code by Andrew Tridgell and Siddharth Bharat Purohit
  16. */
  17. #pragma once
  18. #include "AP_HAL_ChibiOS.h"
  19. #if HAL_WITH_UAVCAN
  20. #define CAN_STM32_LOG(fmt, ...) hal.console->printf("CANManager: " fmt "\n", ##__VA_ARGS__)
  21. #include <uavcan/uavcan.hpp>
  22. #include <uavcan/time.hpp>
  23. #include "CANThread.h"
  24. #include "CANClock.h"
  25. #if defined(STM32H7XX)
  26. #include "CANFDIface.h"
  27. #else
  28. #include "CANIface.h"
  29. #endif
  30. #define MAX_NUMBER_OF_CAN_INTERFACES 2
  31. #define MAX_NUMBER_OF_CAN_DRIVERS 2
  32. #define CAN_STM32_RX_QUEUE_SIZE 64
  33. namespace ChibiOS {
  34. /**
  35. * Generic CAN driver.
  36. */
  37. class CANManager: public AP_HAL::CANManager {
  38. public:
  39. CANManager()
  40. : can_helper(), AP_HAL::CANManager(&can_helper.driver) { }
  41. /**
  42. * Whether at least one iface had at least one successful IO since previous call of this method.
  43. * This is designed for use with iface activity LEDs.
  44. */
  45. //bool hadActivity();
  46. static CANManager *from(AP_HAL::CANManager *can)
  47. {
  48. return static_cast<CANManager*>(can);
  49. }
  50. bool begin(uint32_t bitrate, uint8_t can_number) override;
  51. /*
  52. Test if CAN manager is ready and initialized
  53. return false - CAN manager not initialized
  54. true - CAN manager is initialized
  55. */
  56. bool is_initialized() override;
  57. void initialized(bool val) override;
  58. private:
  59. bool initialized_;
  60. ChibiOS_CAN::CanInitHelper<CAN_STM32_RX_QUEUE_SIZE> can_helper;
  61. };
  62. }
  63. #endif