portmacro.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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 PORTMACRO_H
  29. #define PORTMACRO_H
  30. /*-----------------------------------------------------------
  31. * Port specific definitions.
  32. *
  33. * The settings in this file configure FreeRTOS correctly for the
  34. * given hardware and compiler.
  35. *
  36. * These settings should not be altered.
  37. *-----------------------------------------------------------
  38. */
  39. /* Type definitions. */
  40. #define portCHAR char
  41. #define portFLOAT float
  42. #define portDOUBLE double
  43. #define portLONG long
  44. #define portSHORT short
  45. #define portSTACK_TYPE uint8_t
  46. #define portBASE_TYPE char
  47. typedef portSTACK_TYPE StackType_t;
  48. typedef signed char BaseType_t;
  49. typedef unsigned char UBaseType_t;
  50. #if( configUSE_16_BIT_TICKS == 1 )
  51. typedef uint16_t TickType_t;
  52. #define portMAX_DELAY ( TickType_t ) 0xffff
  53. #else
  54. typedef uint32_t TickType_t;
  55. #define portMAX_DELAY ( TickType_t ) 0xffffffffUL
  56. #endif
  57. /*-----------------------------------------------------------*/
  58. /* Hardware specifics. */
  59. #define portBYTE_ALIGNMENT 1
  60. #define portSTACK_GROWTH ( -1 )
  61. #define portTICK_PERIOD_MS ( ( TickType_t ) 1000 / configTICK_RATE_HZ )
  62. #define portYIELD() __asm( "swi" );
  63. #define portNOP() __asm( "nop" );
  64. /*-----------------------------------------------------------*/
  65. /* Critical section handling. */
  66. #define portENABLE_INTERRUPTS() __asm( "cli" )
  67. #define portDISABLE_INTERRUPTS() __asm( "sei" )
  68. /*
  69. * Disable interrupts before incrementing the count of critical section nesting.
  70. * The nesting count is maintained so we know when interrupts should be
  71. * re-enabled. Once interrupts are disabled the nesting count can be accessed
  72. * directly. Each task maintains its own nesting count.
  73. */
  74. #define portENTER_CRITICAL() \
  75. { \
  76. extern volatile UBaseType_t uxCriticalNesting; \
  77. \
  78. portDISABLE_INTERRUPTS(); \
  79. uxCriticalNesting++; \
  80. }
  81. /*
  82. * Interrupts are disabled so we can access the nesting count directly. If the
  83. * nesting is found to be 0 (no nesting) then we are leaving the critical
  84. * section and interrupts can be re-enabled.
  85. */
  86. #define portEXIT_CRITICAL() \
  87. { \
  88. extern volatile UBaseType_t uxCriticalNesting; \
  89. \
  90. uxCriticalNesting--; \
  91. if( uxCriticalNesting == 0 ) \
  92. { \
  93. portENABLE_INTERRUPTS(); \
  94. } \
  95. }
  96. /*-----------------------------------------------------------*/
  97. /* Task utilities. */
  98. /*
  99. * These macros are very simple as the processor automatically saves and
  100. * restores its registers as interrupts are entered and exited. In
  101. * addition to the (automatically stacked) registers we also stack the
  102. * critical nesting count. Each task maintains its own critical nesting
  103. * count as it is legitimate for a task to yield from within a critical
  104. * section. If the banked memory model is being used then the PPAGE
  105. * register is also stored as part of the tasks context.
  106. */
  107. #ifdef BANKED_MODEL
  108. /*
  109. * Load the stack pointer for the task, then pull the critical nesting
  110. * count and PPAGE register from the stack. The remains of the
  111. * context are restored by the RTI instruction.
  112. */
  113. #define portRESTORE_CONTEXT() \
  114. { \
  115. extern volatile void * pxCurrentTCB; \
  116. extern volatile UBaseType_t uxCriticalNesting; \
  117. \
  118. __asm( "ldx pxCurrentTCB" ); \
  119. __asm( "lds 0, x" ); \
  120. __asm( "pula" ); \
  121. __asm( "staa uxCriticalNesting" ); \
  122. __asm( "pula" ); \
  123. __asm( "staa 0x30" ); /* 0x30 = PPAGE */ \
  124. }
  125. /*
  126. * By the time this macro is called the processor has already stacked the
  127. * registers. Simply stack the nesting count and PPAGE value, then save
  128. * the task stack pointer.
  129. */
  130. #define portSAVE_CONTEXT() \
  131. { \
  132. extern volatile void * pxCurrentTCB; \
  133. extern volatile UBaseType_t uxCriticalNesting; \
  134. \
  135. __asm( "ldaa 0x30" ); /* 0x30 = PPAGE */ \
  136. __asm( "psha" ); \
  137. __asm( "ldaa uxCriticalNesting" ); \
  138. __asm( "psha" ); \
  139. __asm( "ldx pxCurrentTCB" ); \
  140. __asm( "sts 0, x" ); \
  141. }
  142. #else
  143. /*
  144. * These macros are as per the BANKED versions above, but without saving
  145. * and restoring the PPAGE register.
  146. */
  147. #define portRESTORE_CONTEXT() \
  148. { \
  149. extern volatile void * pxCurrentTCB; \
  150. extern volatile UBaseType_t uxCriticalNesting; \
  151. \
  152. __asm( "ldx pxCurrentTCB" ); \
  153. __asm( "lds 0, x" ); \
  154. __asm( "pula" ); \
  155. __asm( "staa uxCriticalNesting" ); \
  156. }
  157. #define portSAVE_CONTEXT() \
  158. { \
  159. extern volatile void * pxCurrentTCB; \
  160. extern volatile UBaseType_t uxCriticalNesting; \
  161. \
  162. __asm( "ldaa uxCriticalNesting" ); \
  163. __asm( "psha" ); \
  164. __asm( "ldx pxCurrentTCB" ); \
  165. __asm( "sts 0, x" ); \
  166. }
  167. #endif
  168. /*
  169. * Utility macro to call macros above in correct order in order to perform a
  170. * task switch from within a standard ISR. This macro can only be used if
  171. * the ISR does not use any local (stack) variables. If the ISR uses stack
  172. * variables portYIELD() should be used in it's place.
  173. */
  174. #define portTASK_SWITCH_FROM_ISR() \
  175. portSAVE_CONTEXT(); \
  176. vTaskSwitchContext(); \
  177. portRESTORE_CONTEXT();
  178. /* Task function macros as described on the FreeRTOS.org WEB site. */
  179. #define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void *pvParameters )
  180. #define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void *pvParameters )
  181. #endif /* PORTMACRO_H */