CANManager.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. * Based on stm32 can driver by Pavel Kirienko
  17. */
  18. #include "CAN.h"
  19. #if HAL_WITH_UAVCAN
  20. #include "CANInternal.h"
  21. #include "CANClock.h"
  22. extern const AP_HAL::HAL& hal;
  23. using namespace ChibiOS;
  24. namespace ChibiOS_CAN {
  25. uint64_t clock::getUtcUSecFromCanInterrupt()
  26. {
  27. return AP_HAL::micros64();
  28. }
  29. uavcan::MonotonicTime clock::getMonotonic()
  30. {
  31. return uavcan::MonotonicTime::fromUSec(AP_HAL::micros64());
  32. }
  33. }
  34. bool CANManager::begin(uint32_t bitrate, uint8_t can_number)
  35. {
  36. return (can_helper.init(bitrate, ChibiOS_CAN::CanIface::OperatingMode::NormalMode, can_number) == 0);
  37. }
  38. bool CANManager::is_initialized()
  39. {
  40. return initialized_;
  41. }
  42. void CANManager::initialized(bool val)
  43. {
  44. initialized_ = val;
  45. }
  46. #endif //HAL_WITH_UAVCAN