portmacro.h 7.3 KB

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