porthardware.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. * FreeRTOS Kernel V10.4.6
  3. * Copyright (C) 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  4. *
  5. * SPDX-License-Identifier: MIT
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a copy of
  8. * this software and associated documentation files (the "Software"), to deal in
  9. * the Software without restriction, including without limitation the rights to
  10. * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  11. * the Software, and to permit persons to whom the Software is furnished to do so,
  12. * subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be included in all
  15. * copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  19. * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  20. * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  21. * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  22. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  23. *
  24. * https://www.FreeRTOS.org
  25. * https://github.com/FreeRTOS
  26. *
  27. */
  28. #ifndef PORTHARDWARE_H
  29. #define PORTHARDWARE_H
  30. #ifndef __IAR_SYSTEMS_ASM__
  31. #include <ioavr.h>
  32. #endif
  33. #include "FreeRTOSConfig.h"
  34. /*-----------------------------------------------------------*/
  35. #if ( configUSE_TIMER_INSTANCE == 0 )
  36. #define TICK_INT_vect TCB0_INT_vect
  37. #define INT_FLAGS TCB0_INTFLAGS
  38. #define INT_MASK TCB_CAPT_bm
  39. #define TICK_init() \
  40. { \
  41. TCB0.CCMP = configCPU_CLOCK_HZ / configTICK_RATE_HZ; \
  42. TCB0.INTCTRL = TCB_CAPT_bm; \
  43. TCB0.CTRLA = TCB_ENABLE_bm; \
  44. }
  45. #elif ( configUSE_TIMER_INSTANCE == 1 )
  46. #define TICK_INT_vect TCB1_INT_vect
  47. #define INT_FLAGS TCB1_INTFLAGS
  48. #define INT_MASK TCB_CAPT_bm
  49. #define TICK_init() \
  50. { \
  51. TCB1.CCMP = configCPU_CLOCK_HZ / configTICK_RATE_HZ; \
  52. TCB1.INTCTRL = TCB_CAPT_bm; \
  53. TCB1.CTRLA = TCB_ENABLE_bm; \
  54. }
  55. #elif ( configUSE_TIMER_INSTANCE == 2 )
  56. #define TICK_INT_vect TCB2_INT_vect
  57. #define INT_FLAGS TCB2_INTFLAGS
  58. #define INT_MASK TCB_CAPT_bm
  59. #define TICK_init() \
  60. { \
  61. TCB2.CCMP = configCPU_CLOCK_HZ / configTICK_RATE_HZ; \
  62. TCB2.INTCTRL = TCB_CAPT_bm; \
  63. TCB2.CTRLA = TCB_ENABLE_bm; \
  64. }
  65. #elif ( configUSE_TIMER_INSTANCE == 3 )
  66. #define TICK_INT_vect TCB3_INT_vect
  67. #define INT_FLAGS TCB3_INTFLAGS
  68. #define INT_MASK TCB_CAPT_bm
  69. #define TICK_init() \
  70. { \
  71. TCB3.CCMP = configCPU_CLOCK_HZ / configTICK_RATE_HZ; \
  72. TCB3.INTCTRL = TCB_CAPT_bm; \
  73. TCB3.CTRLA = TCB_ENABLE_bm; \
  74. }
  75. #elif ( configUSE_TIMER_INSTANCE == 4 )
  76. #define TICK_INT_vect TCB4_INT_vect
  77. #define INT_FLAGS TCB4_INTFLAGS
  78. #define INT_MASK TCB_CAPT_bm
  79. #define TICK_init() \
  80. { \
  81. TCB4.CCMP = configCPU_CLOCK_HZ / configTICK_RATE_HZ; \
  82. TCB4.INTCTRL = TCB_CAPT_bm; \
  83. TCB4.CTRLA = TCB_ENABLE_bm; \
  84. }
  85. #elif ( configUSE_TIMER_INSTANCE == 5 )
  86. #define TICK_INT_vect RTC_CNT_vect
  87. #define INT_FLAGS RTC_INTFLAGS
  88. #define INT_MASK RTC_OVF_bm
  89. /* Hertz to period for RTC setup */
  90. #define RTC_PERIOD_HZ( x ) ( 32768 * ( ( 1.0 / x ) ) )
  91. #define TICK_init() \
  92. { \
  93. while( RTC.STATUS > 0 ) {; } \
  94. RTC.CTRLA = RTC_PRESCALER_DIV1_gc | 1 << RTC_RTCEN_bp; \
  95. RTC.PER = RTC_PERIOD_HZ( configTICK_RATE_HZ ); \
  96. RTC.INTCTRL |= 1 << RTC_OVF_bp; \
  97. }
  98. #else /* if ( configUSE_TIMER_INSTANCE == 0 ) */
  99. #undef TICK_INT_vect
  100. #undef INT_FLAGS
  101. #undef INT_MASK
  102. #undef TICK_init()
  103. #error Invalid timer setting.
  104. #endif /* if ( configUSE_TIMER_INSTANCE == 0 ) */
  105. /*-----------------------------------------------------------*/
  106. #endif /* PORTHARDWARE_H */