CANInternal.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. #include <hal.h>
  43. #include <ch.h>
  44. /**
  45. * Debug output
  46. */
  47. #ifndef UAVCAN_STM32_LOG
  48. # if 0
  49. # define UAVCAN_STM32_LOG(fmt, ...) syslog("uavcan_stm32: " fmt "\n", ##__VA_ARGS__)
  50. # else
  51. # define UAVCAN_STM32_LOG(...) ((void)0)
  52. # endif
  53. #endif
  54. /**
  55. * IRQ handler macros
  56. */
  57. # define UAVCAN_STM32_IRQ_HANDLER(id) CH_IRQ_HANDLER(id)
  58. # define UAVCAN_STM32_IRQ_PROLOGUE() CH_IRQ_PROLOGUE()
  59. # define UAVCAN_STM32_IRQ_EPILOGUE() CH_IRQ_EPILOGUE()
  60. /**
  61. * Priority mask for timer and CAN interrupts.
  62. */
  63. # ifndef UAVCAN_STM32_IRQ_PRIORITY_MASK
  64. # if (CH_KERNEL_MAJOR == 2)
  65. # define UAVCAN_STM32_IRQ_PRIORITY_MASK CORTEX_PRIORITY_MASK(CORTEX_MAX_KERNEL_PRIORITY)
  66. # else // ChibiOS 3+
  67. # define UAVCAN_STM32_IRQ_PRIORITY_MASK CORTEX_MAX_KERNEL_PRIORITY
  68. # endif
  69. # endif
  70. /**
  71. * Glue macros
  72. */
  73. #define UAVCAN_STM32_GLUE2_(A, B) A##B
  74. #define UAVCAN_STM32_GLUE2(A, B) UAVCAN_STM32_GLUE2_(A, B)
  75. #define UAVCAN_STM32_GLUE3_(A, B, C) A##B##C
  76. #define UAVCAN_STM32_GLUE3(A, B, C) UAVCAN_STM32_GLUE3_(A, B, C)
  77. namespace ChibiOS_CAN {
  78. struct CriticalSectionLocker {
  79. CriticalSectionLocker()
  80. {
  81. chSysSuspend();
  82. }
  83. ~CriticalSectionLocker()
  84. {
  85. chSysEnable();
  86. }
  87. };
  88. namespace clock {
  89. uint64_t getUtcUSecFromCanInterrupt();
  90. }
  91. }
  92. #endif //HAL_WITH_UAVCAN