portmacro.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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 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. #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 8
  63. #define portSTACK_GROWTH -1
  64. #define portTICK_PERIOD_MS ( ( TickType_t ) 1000 / configTICK_RATE_HZ )
  65. /*-----------------------------------------------------------*/
  66. /* Critical section management. */
  67. #define portIPL_SHIFT ( 10UL )
  68. /* Don't straddle the CEE bit. Interrupts calling FreeRTOS functions should
  69. never have higher IPL bits set anyway. */
  70. #define portALL_IPL_BITS ( 0x7FUL << portIPL_SHIFT )
  71. #define portSW0_BIT ( 0x01 << 8 )
  72. /* Interrupt priority conversion */
  73. #define portIPL_TO_CODE( iplNumber ) ( ( iplNumber >> 1 ) & 0x03ul )
  74. #define portCODE_TO_IPL( iplCode ) ( ( iplCode << 1 ) | 0x01ul )
  75. /*-----------------------------------------------------------*/
  76. static inline uint32_t ulPortGetCP0Status( void )
  77. {
  78. uint32_t rv;
  79. __asm volatile(
  80. "\n\t"
  81. "mfc0 %0,$12,0 \n\t"
  82. : "=r" ( rv ) :: );
  83. return rv;
  84. }
  85. /*-----------------------------------------------------------*/
  86. static inline void vPortSetCP0Status( uint32_t new_status)
  87. {
  88. ( void ) new_status;
  89. __asm__ __volatile__(
  90. "\n\t"
  91. "mtc0 %0,$12,0 \n\t"
  92. "ehb \n\t"
  93. :
  94. :"r" ( new_status ) : );
  95. }
  96. /*-----------------------------------------------------------*/
  97. static inline uint32_t ulPortGetCP0Cause( void )
  98. {
  99. uint32_t rv;
  100. __asm volatile(
  101. "\n\t"
  102. "mfc0 %0,$13,0 \n\t"
  103. : "=r" ( rv ) :: );
  104. return rv;
  105. }
  106. /*-----------------------------------------------------------*/
  107. static inline void vPortSetCP0Cause( uint32_t new_cause )
  108. {
  109. ( void ) new_cause;
  110. __asm__ __volatile__(
  111. "\n\t"
  112. "mtc0 %0,$13,0 \n\t"
  113. "ehb \n\t"
  114. :
  115. :"r" ( new_cause ) : );
  116. }
  117. /*-----------------------------------------------------------*/
  118. /* This clears the IPL bits, then sets them to
  119. configMAX_SYSCALL_INTERRUPT_PRIORITY. An extra check is performed if
  120. configASSERT() is defined to ensure an assertion handler does not inadvertently
  121. attempt to lower the IPL when the call to assert was triggered because the IPL
  122. value was found to be above configMAX_SYSCALL_INTERRUPT_PRIORITY when an ISR
  123. safe FreeRTOS API function was executed. ISR safe FreeRTOS API functions are
  124. those that end in FromISR. FreeRTOS maintains a separate interrupt API to
  125. ensure API function and interrupt entry is as fast and as simple as possible. */
  126. #ifdef configASSERT
  127. #define portDISABLE_INTERRUPTS() \
  128. { \
  129. uint32_t ulStatus; \
  130. /* Mask interrupts at and below the kernel interrupt priority. */ \
  131. ulStatus = ulPortGetCP0Status(); \
  132. /* Is the current IPL below configMAX_SYSCALL_INTERRUPT_PRIORITY? */ \
  133. if( ( ( ulStatus & portALL_IPL_BITS ) >> portIPL_SHIFT ) < configMAX_SYSCALL_INTERRUPT_PRIORITY ) \
  134. { \
  135. ulStatus &= ~portALL_IPL_BITS; \
  136. vPortSetCP0Status( ( ulStatus | ( configMAX_SYSCALL_INTERRUPT_PRIORITY << portIPL_SHIFT ) ) ); \
  137. } \
  138. }
  139. #else /* configASSERT */
  140. #define portDISABLE_INTERRUPTS() \
  141. { \
  142. uint32_t ulStatus; \
  143. /* Mask interrupts at and below the kernel interrupt priority. */ \
  144. ulStatus = ulPortGetCP0Status(); \
  145. ulStatus &= ~portALL_IPL_BITS; \
  146. vPortSetCP0Status( ( ulStatus | ( configMAX_SYSCALL_INTERRUPT_PRIORITY << portIPL_SHIFT ) ) ); \
  147. }
  148. #endif /* configASSERT */
  149. #define portENABLE_INTERRUPTS() \
  150. { \
  151. uint32_t ulStatus; \
  152. /* Unmask all interrupts. */ \
  153. ulStatus = ulPortGetCP0Status(); \
  154. ulStatus &= ~portALL_IPL_BITS; \
  155. vPortSetCP0Status( ulStatus ); \
  156. }
  157. extern void vTaskEnterCritical( void );
  158. extern void vTaskExitCritical( void );
  159. #define portCRITICAL_NESTING_IN_TCB 1
  160. #define portENTER_CRITICAL() vTaskEnterCritical()
  161. #define portEXIT_CRITICAL() vTaskExitCritical()
  162. extern UBaseType_t uxPortSetInterruptMaskFromISR();
  163. extern void vPortClearInterruptMaskFromISR( UBaseType_t );
  164. #define portSET_INTERRUPT_MASK_FROM_ISR() uxPortSetInterruptMaskFromISR()
  165. #define portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedStatusRegister ) vPortClearInterruptMaskFromISR( uxSavedStatusRegister )
  166. #ifndef configUSE_PORT_OPTIMISED_TASK_SELECTION
  167. #define configUSE_PORT_OPTIMISED_TASK_SELECTION 1
  168. #endif
  169. #if configUSE_PORT_OPTIMISED_TASK_SELECTION == 1
  170. /* Check the configuration. */
  171. #if( configMAX_PRIORITIES > 32 )
  172. #error configUSE_PORT_OPTIMISED_TASK_SELECTION can only be set to 1 when configMAX_PRIORITIES is less than or equal to 32. It is very rare that a system requires more than 10 to 15 difference priorities as tasks that share a priority will time slice.
  173. #endif
  174. /* Store/clear the ready priorities in a bit map. */
  175. #define portRECORD_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) |= ( 1UL << ( uxPriority ) )
  176. #define portRESET_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) &= ~( 1UL << ( uxPriority ) )
  177. /*-----------------------------------------------------------*/
  178. #define portGET_HIGHEST_PRIORITY( uxTopPriority, uxReadyPriorities ) uxTopPriority = ( 31 - _clz( ( uxReadyPriorities ) ) )
  179. #endif /* taskRECORD_READY_PRIORITY */
  180. /*-----------------------------------------------------------*/
  181. /* Task utilities. */
  182. #define portYIELD() \
  183. { \
  184. uint32_t ulCause; \
  185. /* Trigger software interrupt. */ \
  186. ulCause = ulPortGetCP0Cause(); \
  187. ulCause |= portSW0_BIT; \
  188. vPortSetCP0Cause( ulCause ); \
  189. }
  190. extern volatile UBaseType_t uxInterruptNesting;
  191. #define portASSERT_IF_IN_ISR() configASSERT( uxInterruptNesting == 0 )
  192. #define portNOP() __asm volatile ( "nop" )
  193. /*-----------------------------------------------------------*/
  194. /* Task function macros as described on the FreeRTOS.org WEB site. */
  195. #define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void *pvParameters ) __attribute__((noreturn))
  196. #define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void *pvParameters )
  197. /*-----------------------------------------------------------*/
  198. #define portEND_SWITCHING_ISR( xSwitchRequired ) do { if( xSwitchRequired ) { portYIELD(); } } while( 0 )
  199. /* Required by the kernel aware debugger. */
  200. #ifdef __DEBUG
  201. #define portREMOVE_STATIC_QUALIFIER
  202. #endif
  203. #ifdef __cplusplus
  204. }
  205. #endif
  206. #endif /* PORTMACRO_H */