portmacro_cmsis.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /*
  2. * FreeRTOS Kernel V10.0.0
  3. * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a copy of
  6. * this software and associated documentation files (the "Software"), to deal in
  7. * the Software without restriction, including without limitation the rights to
  8. * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  9. * the Software, and to permit persons to whom the Software is furnished to do so,
  10. * subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be included in all
  13. * copies or substantial portions of the Software. If you wish to use our Amazon
  14. * FreeRTOS name, please do so in a fair use way that does not cause confusion.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  18. * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  19. * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  20. * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  21. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. *
  23. * http://www.FreeRTOS.org
  24. * http://aws.amazon.com/freertos
  25. *
  26. * 1 tab == 4 spaces!
  27. */
  28. #ifndef PORTMACRO_CMSIS_H
  29. #define PORTMACRO_CMSIS_H
  30. #include "app_util.h"
  31. #ifdef __cplusplus
  32. extern "C" {
  33. #endif
  34. /*-----------------------------------------------------------
  35. * Port specific definitions.
  36. *
  37. * The settings in this file configure FreeRTOS correctly for the
  38. * given hardware and compiler.
  39. *
  40. * These settings should not be altered.
  41. *-----------------------------------------------------------
  42. */
  43. /* Type definitions. */
  44. #define portCHAR char
  45. #define portFLOAT float
  46. #define portDOUBLE double
  47. #define portLONG long
  48. #define portSHORT short
  49. #define portSTACK_TYPE uint32_t
  50. #define portBASE_TYPE long
  51. typedef portSTACK_TYPE StackType_t;
  52. typedef long BaseType_t;
  53. typedef uint32_t UBaseType_t; /* to provide compatibility with CMSIS */
  54. #if ( configUSE_16_BIT_TICKS == 1 )
  55. typedef uint16_t TickType_t;
  56. #define portMAX_DELAY ( TickType_t ) 0xffff
  57. #else
  58. typedef uint32_t TickType_t;
  59. #define portMAX_DELAY ( TickType_t ) 0xffffffffUL
  60. /* 32-bit tick type on a 32-bit architecture, so reads of the tick count do
  61. not need to be guarded with a critical section. */
  62. #define portTICK_TYPE_IS_ATOMIC 1
  63. #endif
  64. /*-----------------------------------------------------------*/
  65. /* Architecture specifics. */
  66. #define portSTACK_GROWTH ( -1 )
  67. #define portTICK_PERIOD_MS ( ( TickType_t ) 1000 / configTICK_RATE_HZ )
  68. #define portBYTE_ALIGNMENT 8
  69. /* RTC register */
  70. #define portNRF_RTC_REG NRF_RTC1
  71. /* IRQn used by the selected RTC */
  72. #define portNRF_RTC_IRQn RTC1_IRQn
  73. /* Constants required to manipulate the NVIC. */
  74. #define portNRF_RTC_PRESCALER ( (uint32_t) (ROUNDED_DIV(configSYSTICK_CLOCK_HZ, configTICK_RATE_HZ) - 1) )
  75. /* Maximum RTC ticks */
  76. #define portNRF_RTC_MAXTICKS ((1U<<24)-1U)
  77. /*-----------------------------------------------------------*/
  78. /* Scheduler utilities. */
  79. #define portYIELD() do \
  80. { \
  81. /* Set a PendSV to request a context switch. */ \
  82. SCB->ICSR = SCB_ICSR_PENDSVSET_Msk; \
  83. __SEV(); \
  84. /* Barriers are normally not required but do ensure the code is completely \
  85. within the specified behaviour for the architecture. */ \
  86. __DSB(); \
  87. __ISB(); \
  88. }while (0)
  89. #define portEND_SWITCHING_ISR( xSwitchRequired ) if ( (xSwitchRequired) != pdFALSE ) portYIELD()
  90. #define portYIELD_FROM_ISR( x ) portEND_SWITCHING_ISR( x )
  91. /*-----------------------------------------------------------*/
  92. /* Critical section management. */
  93. extern void vPortEnterCritical( void );
  94. extern void vPortExitCritical( void );
  95. #define portSET_INTERRUPT_MASK_FROM_ISR() ulPortRaiseBASEPRI()
  96. #define portCLEAR_INTERRUPT_MASK_FROM_ISR(x) vPortSetBASEPRI(x)
  97. #define portDISABLE_INTERRUPTS() vPortRaiseBASEPRI()
  98. #define portENABLE_INTERRUPTS() vPortSetBASEPRI(0)
  99. #define portENTER_CRITICAL() vPortEnterCritical()
  100. #define portEXIT_CRITICAL() vPortExitCritical()
  101. /*-----------------------------------------------------------*/
  102. /* Task function macros as described on the FreeRTOS.org WEB site. These are
  103. not necessary for to use this port. They are defined so the common demo files
  104. (which build with all the ports) will build. */
  105. #define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void *pvParameters )
  106. #define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void *pvParameters )
  107. /*-----------------------------------------------------------*/
  108. /* Tickless idle/low power functionality. */
  109. #ifndef portSUPPRESS_TICKS_AND_SLEEP
  110. extern void vPortSuppressTicksAndSleep( TickType_t xExpectedIdleTime );
  111. #define portSUPPRESS_TICKS_AND_SLEEP( xExpectedIdleTime ) vPortSuppressTicksAndSleep( xExpectedIdleTime )
  112. #endif
  113. /*-----------------------------------------------------------*/
  114. /* Architecture specific optimisations. */
  115. #ifndef configUSE_PORT_OPTIMISED_TASK_SELECTION
  116. #define configUSE_PORT_OPTIMISED_TASK_SELECTION 1
  117. #endif
  118. #if configUSE_PORT_OPTIMISED_TASK_SELECTION == 1
  119. /* Count leading zeros helper. */
  120. #define ucPortCountLeadingZeros( bits ) __CLZ( bits )
  121. /* Check the configuration. */
  122. #if ( configMAX_PRIORITIES > 32 )
  123. #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.
  124. #endif
  125. /* Store/clear the ready priorities in a bit map. */
  126. #define portRECORD_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) |= ( 1UL << ( uxPriority ) )
  127. #define portRESET_READY_PRIORITY( uxPriority, uxReadyPriorities ) ( uxReadyPriorities ) &= ~( 1UL << ( uxPriority ) )
  128. /*-----------------------------------------------------------*/
  129. #define portGET_HIGHEST_PRIORITY( uxTopPriority, uxReadyPriorities ) uxTopPriority = ( 31 - ucPortCountLeadingZeros( ( uxReadyPriorities ) ) )
  130. #endif /* configUSE_PORT_OPTIMISED_TASK_SELECTION */
  131. /*-----------------------------------------------------------*/
  132. #ifdef configASSERT
  133. void vPortValidateInterruptPriority( void );
  134. #define portASSERT_IF_INTERRUPT_PRIORITY_INVALID() vPortValidateInterruptPriority()
  135. #endif
  136. /*-----------------------------------------------------------*/
  137. #define vPortSetBASEPRI( ulNewMaskValue ) __set_BASEPRI(ulNewMaskValue)
  138. /*-----------------------------------------------------------*/
  139. #define vPortRaiseBASEPRI( ) vPortSetBASEPRI(configMAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS))
  140. /*-----------------------------------------------------------*/
  141. __STATIC_INLINE uint32_t ulPortRaiseBASEPRI( void )
  142. {
  143. uint32_t ulOriginalBASEPRI = __get_BASEPRI();
  144. vPortRaiseBASEPRI();
  145. return ulOriginalBASEPRI;
  146. }
  147. /*-----------------------------------------------------------*/
  148. #ifdef __cplusplus
  149. }
  150. #endif
  151. #endif /* PORTMACRO_CMSIS_H */