fdcan.hpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * The MIT License (MIT)
  3. *
  4. * Copyright (c) 2014 Pavel Kirienko
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy of
  7. * this software and associated documentation files (the "Software"), to deal in
  8. * the Software without restriction, including without limitation the rights to
  9. * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  10. * the Software, and to permit persons to whom the Software is furnished to do so,
  11. * subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in all
  14. * copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  18. * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  19. * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  20. * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  21. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. */
  23. /*
  24. * This file is free software: you can redistribute it and/or modify it
  25. * under the terms of the GNU General Public License as published by the
  26. * Free Software Foundation, either version 3 of the License, or
  27. * (at your option) any later version.
  28. *
  29. * This file is distributed in the hope that it will be useful, but
  30. * WITHOUT ANY WARRANTY; without even the implied warranty of
  31. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  32. * See the GNU General Public License for more details.
  33. *
  34. * You should have received a copy of the GNU General Public License along
  35. * with this program. If not, see <http://www.gnu.org/licenses/>.
  36. *
  37. * Code by Siddharth Bharat Purohit
  38. */
  39. #pragma once
  40. #include "AP_HAL_ChibiOS.h"
  41. #if HAL_WITH_UAVCAN
  42. #if defined(STM32H7XX)
  43. #include <uavcan/uavcan.hpp>
  44. #include <stdint.h>
  45. #ifndef UAVCAN_CPP_VERSION
  46. # error UAVCAN_CPP_VERSION
  47. #endif
  48. #if UAVCAN_CPP_VERSION < UAVCAN_CPP11
  49. // #undef'ed at the end of this file
  50. # define constexpr const
  51. #endif
  52. namespace ChibiOS_CAN
  53. {
  54. namespace fdcan
  55. {
  56. typedef FDCAN_GlobalTypeDef CanType;
  57. constexpr unsigned long IDE = (0x40000000U); // Identifier Extension
  58. constexpr unsigned long STID_MASK = (0x1FFC0000U); // Standard Identifier Mask
  59. constexpr unsigned long EXID_MASK = (0x1FFFFFFFU); // Extended Identifier Mask
  60. constexpr unsigned long RTR = (0x20000000U); // Remote Transmission Request
  61. constexpr unsigned long DLC_MASK = (0x000F0000U); // Data Length Code
  62. /**
  63. * CANx register sets
  64. */
  65. CanType* const Can[UAVCAN_STM32_NUM_IFACES] = {
  66. reinterpret_cast<CanType*>(FDCAN1_BASE)
  67. #if UAVCAN_STM32_NUM_IFACES > 1
  68. ,
  69. reinterpret_cast<CanType*>(FDCAN2_BASE)
  70. #endif
  71. };
  72. }
  73. }
  74. #if UAVCAN_CPP_VERSION < UAVCAN_CPP11
  75. # undef constexpr
  76. #endif
  77. #endif //defined(STM32H7XX)
  78. #endif //HAL_WITH_UAVCAN