portmacro.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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. /* System include files */
  31. #include <xc.h>
  32. #ifdef __cplusplus
  33. extern "C" {
  34. #endif
  35. /*-----------------------------------------------------------
  36. * Port specific definitions.
  37. *
  38. * The settings in this file configure FreeRTOS correctly for the
  39. * given hardware 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 uint32_t
  51. #define portBASE_TYPE long
  52. typedef portSTACK_TYPE StackType_t;
  53. typedef long BaseType_t;
  54. typedef unsigned long UBaseType_t;
  55. #if( configUSE_16_BIT_TICKS == 1 )
  56. typedef uint16_t TickType_t;
  57. #define portMAX_DELAY ( TickType_t ) 0xffff
  58. #else
  59. typedef uint32_t TickType_t;
  60. #define portMAX_DELAY ( TickType_t ) 0xffffffffUL
  61. /* 32-bit tick type on a 32-bit architecture, so reads of the tick count do
  62. not need to be guarded with a critical section. */
  63. #define portTICK_TYPE_IS_ATOMIC 1
  64. #endif
  65. /*-----------------------------------------------------------*/
  66. /* Hardware specifics. */
  67. #define portBYTE_ALIGNMENT 8
  68. #define portSTACK_GROWTH -1
  69. #define portTICK_PERIOD_MS ( ( TickType_t ) 1000 / configTICK_RATE_HZ )
  70. /*-----------------------------------------------------------*/
  71. /* Critical section management. */
  72. #define portIPL_SHIFT ( 10UL )
  73. /* Don't straddle the CEE bit. Interrupts calling FreeRTOS functions should
  74. never have higher IPL bits set anyway. */
  75. #define portALL_IPL_BITS ( 0x7FUL << portIPL_SHIFT )
  76. #define portSW0_BIT ( 0x01 << 8 )
  77. /* This clears the IPL bits, then sets them to
  78. configMAX_SYSCALL_INTERRUPT_PRIORITY. An extra check is performed if
  79. configASSERT() is defined to ensure an assertion handler does not inadvertently
  80. attempt to lower the IPL when the call to assert was triggered because the IPL
  81. value was found to be above configMAX_SYSCALL_INTERRUPT_PRIORITY when an ISR
  82. safe FreeRTOS API function was executed. ISR safe FreeRTOS API functions are
  83. those that end in FromISR. FreeRTOS maintains a separate interrupt API to
  84. ensure API function and interrupt entry is as fast and as simple as possible. */
  85. #ifdef configASSERT
  86. #define portDISABLE_INTERRUPTS() \
  87. { \
  88. uint32_t ulStatus; \
  89. \
  90. /* Mask interrupts at and below the kernel interrupt priority. */ \
  91. ulStatus = _CP0_GET_STATUS(); \
  92. \
  93. /* Is the current IPL below configMAX_SYSCALL_INTERRUPT_PRIORITY? */ \
  94. if( ( ( ulStatus & portALL_IPL_BITS ) >> portIPL_SHIFT ) < configMAX_SYSCALL_INTERRUPT_PRIORITY ) \
  95. { \
  96. ulStatus &= ~portALL_IPL_BITS; \
  97. _CP0_SET_STATUS( ( ulStatus | ( configMAX_SYSCALL_INTERRUPT_PRIORITY << portIPL_SHIFT ) ) ); \
  98. } \
  99. }
  100. #else /* configASSERT */
  101. #define portDISABLE_INTERRUPTS() \
  102. { \
  103. uint32_t ulStatus; \
  104. \
  105. /* Mask interrupts at and below the kernel interrupt priority. */ \
  106. ulStatus = _CP0_GET_STATUS(); \
  107. ulStatus &= ~portALL_IPL_BITS; \
  108. _CP0_SET_STATUS( ( ulStatus | ( configMAX_SYSCALL_INTERRUPT_PRIORITY << portIPL_SHIFT ) ) ); \
  109. }
  110. #endif /* configASSERT */
  111. #define portENABLE_INTERRUPTS() \
  112. { \
  113. uint32_t ulStatus; \
  114. \
  115. /* Unmask all interrupts. */ \
  116. ulStatus = _CP0_GET_STATUS(); \
  117. ulStatus &= ~portALL_IPL_BITS; \
  118. _CP0_SET_STATUS( ulStatus ); \
  119. }
  120. extern void vTaskEnterCritical( void );
  121. extern void vTaskExitCritical( void );
  122. #define portCRITICAL_NESTING_IN_TCB 1
  123. #define portENTER_CRITICAL() vTaskEnterCritical()
  124. #define portEXIT_CRITICAL() vTaskExitCritical()
  125. extern UBaseType_t uxPortSetInterruptMaskFromISR();
  126. extern void vPortClearInterruptMaskFromISR( UBaseType_t );
  127. #define portSET_INTERRUPT_MASK_FROM_ISR() uxPortSetInterruptMaskFromISR()
  128. #define portCLEAR_INTERRUPT_MASK_FROM_ISR( uxSavedStatusRegister ) vPortClearInterruptMaskFromISR( uxSavedStatusRegister )
  129. #if ( __mips_hard_float == 0 ) && ( configUSE_TASK_FPU_SUPPORT == 1 )
  130. #error configUSE_TASK_FPU_SUPPORT can only be set to 1 when the part supports a hardware FPU module.
  131. #endif
  132. #if ( __mips_hard_float == 1 ) && ( configUSE_TASK_FPU_SUPPORT == 1 )
  133. void vPortTaskUsesFPU( void );
  134. #define portTASK_USES_FLOATING_POINT() vPortTaskUsesFPU()
  135. #endif
  136. #ifndef configUSE_PORT_OPTIMISED_TASK_SELECTION
  137. #define configUSE_PORT_OPTIMISED_TASK_SELECTION 1
  138. #endif
  139. #if configUSE_PORT_OPTIMISED_TASK_SELECTION == 1
  140. /* Check the configuration. */
  141. #if( configMAX_PRIORITIES > 32 )
  142. #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.
  143. #endif
  144. /* Store/clear the ready priorities in a bit map. */
  145. #define portRECORD_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) |= ( 1UL << ( uxPriority ) )
  146. #define portRESET_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) &= ~( 1UL << ( uxPriority ) )
  147. /*-----------------------------------------------------------*/
  148. #define portGET_HIGHEST_PRIORITY( uxTopPriority, uxReadyPriorities ) uxTopPriority = ( 31UL - _clz( ( uxReadyPriorities ) ) )
  149. #endif /* taskRECORD_READY_PRIORITY */
  150. /*-----------------------------------------------------------*/
  151. /* Task utilities. */
  152. #define portYIELD() \
  153. { \
  154. uint32_t ulCause; \
  155. \
  156. /* Trigger software interrupt. */ \
  157. ulCause = _CP0_GET_CAUSE(); \
  158. ulCause |= portSW0_BIT; \
  159. _CP0_SET_CAUSE( ulCause ); \
  160. }
  161. extern volatile UBaseType_t uxInterruptNesting;
  162. #define portASSERT_IF_IN_ISR() configASSERT( uxInterruptNesting == 0 )
  163. #define portNOP() __asm volatile ( "nop" )
  164. /*-----------------------------------------------------------*/
  165. /* Task function macros as described on the FreeRTOS.org WEB site. */
  166. #define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void *pvParameters ) __attribute__((noreturn))
  167. #define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void *pvParameters )
  168. /*-----------------------------------------------------------*/
  169. #define portEND_SWITCHING_ISR( xSwitchRequired ) do { if( xSwitchRequired ) { portYIELD(); } } while( 0 )
  170. /* Required by the kernel aware debugger. */
  171. #ifdef __DEBUG
  172. #define portREMOVE_STATIC_QUALIFIER
  173. #endif
  174. #ifdef __cplusplus
  175. }
  176. #endif
  177. #endif /* PORTMACRO_H */