portmacro.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. /*
  2. * FreeRTOS Kernel <DEVELOPMENT BRANCH>
  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. /* *INDENT-OFF* */
  31. #ifdef __cplusplus
  32. extern "C" {
  33. #endif
  34. /* *INDENT-ON* */
  35. /*-----------------------------------------------------------
  36. * Port specific definitions.
  37. *
  38. * The settings in this file configure FreeRTOS correctly for the given hardware
  39. * and compiler.
  40. *
  41. * These settings should not be altered.
  42. *-----------------------------------------------------------
  43. */
  44. /* Type definitions. */
  45. #define portCHAR char
  46. #define portFLOAT float
  47. #define portDOUBLE double
  48. #define portLONG long
  49. #define portSHORT short
  50. #define portSTACK_TYPE size_t
  51. #define portBASE_TYPE long
  52. typedef portSTACK_TYPE StackType_t;
  53. typedef portBASE_TYPE BaseType_t;
  54. typedef uint64_t UBaseType_t;
  55. typedef uint64_t TickType_t;
  56. #define portMAX_DELAY ( ( TickType_t ) 0xffffffffffffffff )
  57. /* 32-bit tick type on a 32-bit architecture, so reads of the tick count do
  58. * not need to be guarded with a critical section. */
  59. #define portTICK_TYPE_IS_ATOMIC 1
  60. /*-----------------------------------------------------------*/
  61. /* Hardware specifics. */
  62. #define portSTACK_GROWTH ( -1 )
  63. #define portTICK_PERIOD_MS ( ( TickType_t ) 1000 / configTICK_RATE_HZ )
  64. #define portBYTE_ALIGNMENT 16
  65. #define portPOINTER_SIZE_TYPE uint64_t
  66. /*-----------------------------------------------------------*/
  67. /* Task utilities. */
  68. /* Called at the end of an ISR that can cause a context switch. */
  69. #define portEND_SWITCHING_ISR( xSwitchRequired ) \
  70. { \
  71. extern uint64_t ullPortYieldRequired; \
  72. \
  73. if( xSwitchRequired != pdFALSE ) \
  74. { \
  75. ullPortYieldRequired = pdTRUE; \
  76. } \
  77. }
  78. #define portYIELD_FROM_ISR( x ) portEND_SWITCHING_ISR( x )
  79. #if defined( GUEST )
  80. #define portYIELD() __asm volatile ( "SVC 0" ::: "memory" )
  81. #else
  82. #define portYIELD() __asm volatile ( "SMC 0" ::: "memory" )
  83. #endif
  84. /*-----------------------------------------------------------
  85. * Critical section control
  86. *----------------------------------------------------------*/
  87. extern void vPortEnterCritical( void );
  88. extern void vPortExitCritical( void );
  89. extern UBaseType_t uxPortSetInterruptMask( void );
  90. extern void vPortClearInterruptMask( UBaseType_t uxNewMaskValue );
  91. extern void vPortInstallFreeRTOSVectorTable( void );
  92. #define portDISABLE_INTERRUPTS() \
  93. __asm volatile ( "MSR DAIFSET, #2" ::: "memory" ); \
  94. __asm volatile ( "DSB SY" ); \
  95. __asm volatile ( "ISB SY" );
  96. #define portENABLE_INTERRUPTS() \
  97. __asm volatile ( "MSR DAIFCLR, #2" ::: "memory" ); \
  98. __asm volatile ( "DSB SY" ); \
  99. __asm volatile ( "ISB SY" );
  100. /* These macros do not globally disable/enable interrupts. They do mask off
  101. * interrupts that have a priority below configMAX_API_CALL_INTERRUPT_PRIORITY. */
  102. #define portENTER_CRITICAL() vPortEnterCritical();
  103. #define portEXIT_CRITICAL() vPortExitCritical();
  104. #define portSET_INTERRUPT_MASK_FROM_ISR() uxPortSetInterruptMask()
  105. #define portCLEAR_INTERRUPT_MASK_FROM_ISR( x ) vPortClearInterruptMask( x )
  106. /*-----------------------------------------------------------*/
  107. /* Task function macros as described on the FreeRTOS.org WEB site. These are
  108. * not required for this port but included in case common demo code that uses these
  109. * macros is used. */
  110. #define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void * pvParameters )
  111. #define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void * pvParameters )
  112. /* Prototype of the FreeRTOS tick handler. This must be installed as the
  113. * handler for whichever peripheral is used to generate the RTOS tick. */
  114. void FreeRTOS_Tick_Handler( void );
  115. /* If configUSE_TASK_FPU_SUPPORT is set to 1 (or left undefined) then tasks are
  116. * created without an FPU context and must call vPortTaskUsesFPU() to give
  117. * themselves an FPU context before using any FPU instructions. If
  118. * configUSE_TASK_FPU_SUPPORT is set to 2 then all tasks will have an FPU context
  119. * by default. */
  120. #if ( configUSE_TASK_FPU_SUPPORT != 2 )
  121. void vPortTaskUsesFPU( void );
  122. #else
  123. /* Each task has an FPU context already, so define this function away to
  124. * nothing to prevent it from being called accidentally. */
  125. #define vPortTaskUsesFPU()
  126. #endif
  127. #define portTASK_USES_FLOATING_POINT() vPortTaskUsesFPU()
  128. #define portLOWEST_INTERRUPT_PRIORITY ( ( ( uint32_t ) configUNIQUE_INTERRUPT_PRIORITIES ) - 1UL )
  129. #define portLOWEST_USABLE_INTERRUPT_PRIORITY ( portLOWEST_INTERRUPT_PRIORITY - 1UL )
  130. /* Architecture specific optimisations. */
  131. #ifndef configUSE_PORT_OPTIMISED_TASK_SELECTION
  132. #define configUSE_PORT_OPTIMISED_TASK_SELECTION 1
  133. #endif
  134. #if configUSE_PORT_OPTIMISED_TASK_SELECTION == 1
  135. /* Store/clear the ready priorities in a bit map. */
  136. #define portRECORD_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) |= ( 1UL << ( uxPriority ) )
  137. #define portRESET_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) &= ~( 1UL << ( uxPriority ) )
  138. /*-----------------------------------------------------------*/
  139. #define portGET_HIGHEST_PRIORITY( uxTopPriority, uxReadyPriorities ) uxTopPriority = ( 31 - __builtin_clz( uxReadyPriorities ) )
  140. #endif /* configUSE_PORT_OPTIMISED_TASK_SELECTION */
  141. #if ( configASSERT_DEFINED == 1 )
  142. void vPortValidateInterruptPriority( void );
  143. #define portASSERT_IF_INTERRUPT_PRIORITY_INVALID() vPortValidateInterruptPriority()
  144. #endif /* configASSERT */
  145. #define portNOP() __asm volatile ( "NOP" )
  146. #define portINLINE __inline
  147. /* The number of bits to shift for an interrupt priority is dependent on the
  148. * number of bits implemented by the interrupt controller. */
  149. #if configUNIQUE_INTERRUPT_PRIORITIES == 16
  150. #define portPRIORITY_SHIFT 4
  151. #define portMAX_BINARY_POINT_VALUE 3
  152. #elif configUNIQUE_INTERRUPT_PRIORITIES == 32
  153. #define portPRIORITY_SHIFT 3
  154. #define portMAX_BINARY_POINT_VALUE 2
  155. #elif configUNIQUE_INTERRUPT_PRIORITIES == 64
  156. #define portPRIORITY_SHIFT 2
  157. #define portMAX_BINARY_POINT_VALUE 1
  158. #elif configUNIQUE_INTERRUPT_PRIORITIES == 128
  159. #define portPRIORITY_SHIFT 1
  160. #define portMAX_BINARY_POINT_VALUE 0
  161. #elif configUNIQUE_INTERRUPT_PRIORITIES == 256
  162. #define portPRIORITY_SHIFT 0
  163. #define portMAX_BINARY_POINT_VALUE 0
  164. #else /* if configUNIQUE_INTERRUPT_PRIORITIES == 16 */
  165. #error Invalid configUNIQUE_INTERRUPT_PRIORITIES setting. configUNIQUE_INTERRUPT_PRIORITIES must be set to the number of unique priorities implemented by the target hardware
  166. #endif /* if configUNIQUE_INTERRUPT_PRIORITIES == 16 */
  167. /* Interrupt controller access addresses. */
  168. #define portICCPMR_PRIORITY_MASK_OFFSET ( 0x04 )
  169. #define portICCIAR_INTERRUPT_ACKNOWLEDGE_OFFSET ( 0x0C )
  170. #define portICCEOIR_END_OF_INTERRUPT_OFFSET ( 0x10 )
  171. #define portICCBPR_BINARY_POINT_OFFSET ( 0x08 )
  172. #define portICCRPR_RUNNING_PRIORITY_OFFSET ( 0x14 )
  173. #define portINTERRUPT_CONTROLLER_CPU_INTERFACE_ADDRESS ( configINTERRUPT_CONTROLLER_BASE_ADDRESS + configINTERRUPT_CONTROLLER_CPU_INTERFACE_OFFSET )
  174. #define portICCPMR_PRIORITY_MASK_REGISTER ( *( ( volatile uint32_t * ) ( portINTERRUPT_CONTROLLER_CPU_INTERFACE_ADDRESS + portICCPMR_PRIORITY_MASK_OFFSET ) ) )
  175. #define portICCIAR_INTERRUPT_ACKNOWLEDGE_REGISTER_ADDRESS ( portINTERRUPT_CONTROLLER_CPU_INTERFACE_ADDRESS + portICCIAR_INTERRUPT_ACKNOWLEDGE_OFFSET )
  176. #define portICCEOIR_END_OF_INTERRUPT_REGISTER_ADDRESS ( portINTERRUPT_CONTROLLER_CPU_INTERFACE_ADDRESS + portICCEOIR_END_OF_INTERRUPT_OFFSET )
  177. #define portICCPMR_PRIORITY_MASK_REGISTER_ADDRESS ( portINTERRUPT_CONTROLLER_CPU_INTERFACE_ADDRESS + portICCPMR_PRIORITY_MASK_OFFSET )
  178. #define portICCBPR_BINARY_POINT_REGISTER ( *( ( const volatile uint32_t * ) ( portINTERRUPT_CONTROLLER_CPU_INTERFACE_ADDRESS + portICCBPR_BINARY_POINT_OFFSET ) ) )
  179. #define portICCRPR_RUNNING_PRIORITY_REGISTER ( *( ( const volatile uint32_t * ) ( portINTERRUPT_CONTROLLER_CPU_INTERFACE_ADDRESS + portICCRPR_RUNNING_PRIORITY_OFFSET ) ) )
  180. #define portMEMORY_BARRIER() __asm volatile ( "" ::: "memory" )
  181. /* *INDENT-OFF* */
  182. #ifdef __cplusplus
  183. }
  184. #endif
  185. /* *INDENT-ON* */
  186. #endif /* PORTMACRO_H */