portmacro.h 8.5 KB

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