port.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  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. /* Standard includes. */
  29. #include <stdlib.h>
  30. /* Scheduler includes. */
  31. #include "FreeRTOS.h"
  32. #include "task.h"
  33. #ifndef configINTERRUPT_CONTROLLER_BASE_ADDRESS
  34. #error "configINTERRUPT_CONTROLLER_BASE_ADDRESS must be defined. See www.FreeRTOS.org/Using-FreeRTOS-on-Cortex-A-Embedded-Processors.html"
  35. #endif
  36. #ifndef configINTERRUPT_CONTROLLER_CPU_INTERFACE_OFFSET
  37. #error "configINTERRUPT_CONTROLLER_CPU_INTERFACE_OFFSET must be defined. See www.FreeRTOS.org/Using-FreeRTOS-on-Cortex-A-Embedded-Processors.html"
  38. #endif
  39. #ifndef configUNIQUE_INTERRUPT_PRIORITIES
  40. #error "configUNIQUE_INTERRUPT_PRIORITIES must be defined. See www.FreeRTOS.org/Using-FreeRTOS-on-Cortex-A-Embedded-Processors.html"
  41. #endif
  42. #ifndef configSETUP_TICK_INTERRUPT
  43. #error "configSETUP_TICK_INTERRUPT() must be defined. See www.FreeRTOS.org/Using-FreeRTOS-on-Cortex-A-Embedded-Processors.html"
  44. #endif /* configSETUP_TICK_INTERRUPT */
  45. #ifndef configMAX_API_CALL_INTERRUPT_PRIORITY
  46. #error "configMAX_API_CALL_INTERRUPT_PRIORITY must be defined. See www.FreeRTOS.org/Using-FreeRTOS-on-Cortex-A-Embedded-Processors.html"
  47. #endif
  48. #if configMAX_API_CALL_INTERRUPT_PRIORITY == 0
  49. #error "configMAX_API_CALL_INTERRUPT_PRIORITY must not be set to 0"
  50. #endif
  51. #if configMAX_API_CALL_INTERRUPT_PRIORITY > configUNIQUE_INTERRUPT_PRIORITIES
  52. #error "configMAX_API_CALL_INTERRUPT_PRIORITY must be less than or equal to configUNIQUE_INTERRUPT_PRIORITIES as the lower the numeric priority value the higher the logical interrupt priority"
  53. #endif
  54. #if configUSE_PORT_OPTIMISED_TASK_SELECTION == 1
  55. /* Check the configuration. */
  56. #if ( configMAX_PRIORITIES > 32 )
  57. #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."
  58. #endif
  59. #endif /* configUSE_PORT_OPTIMISED_TASK_SELECTION */
  60. /* In case security extensions are implemented. */
  61. #if configMAX_API_CALL_INTERRUPT_PRIORITY <= ( configUNIQUE_INTERRUPT_PRIORITIES / 2 )
  62. #error "configMAX_API_CALL_INTERRUPT_PRIORITY must be greater than ( configUNIQUE_INTERRUPT_PRIORITIES / 2 )"
  63. #endif
  64. /* Some vendor specific files default configCLEAR_TICK_INTERRUPT() in
  65. * portmacro.h. */
  66. #ifndef configCLEAR_TICK_INTERRUPT
  67. #define configCLEAR_TICK_INTERRUPT()
  68. #endif
  69. /* A critical section is exited when the critical section nesting count reaches
  70. * this value. */
  71. #define portNO_CRITICAL_NESTING ( ( size_t ) 0 )
  72. /* In all GICs 255 can be written to the priority mask register to unmask all
  73. * (but the lowest) interrupt priority. */
  74. #define portUNMASK_VALUE ( 0xFFUL )
  75. /* Tasks are not created with a floating point context, but can be given a
  76. * floating point context after they have been created. A variable is stored as
  77. * part of the tasks context that holds portNO_FLOATING_POINT_CONTEXT if the task
  78. * does not have an FPU context, or any other value if the task does have an FPU
  79. * context. */
  80. #define portNO_FLOATING_POINT_CONTEXT ( ( StackType_t ) 0 )
  81. /* Constants required to setup the initial task context. */
  82. #define portSP_ELx ( ( StackType_t ) 0x01 )
  83. #define portSP_EL0 ( ( StackType_t ) 0x00 )
  84. #if defined( GUEST )
  85. #define portEL1 ( ( StackType_t ) 0x04 )
  86. #define portINITIAL_PSTATE ( portEL1 | portSP_EL0 )
  87. #else
  88. #define portEL3 ( ( StackType_t ) 0x0c )
  89. /* At the time of writing, the BSP only supports EL3. */
  90. #define portINITIAL_PSTATE ( portEL3 | portSP_EL0 )
  91. #endif
  92. /* Used by portASSERT_IF_INTERRUPT_PRIORITY_INVALID() when ensuring the binary
  93. * point is zero. */
  94. #define portBINARY_POINT_BITS ( ( uint8_t ) 0x03 )
  95. /* Masks all bits in the APSR other than the mode bits. */
  96. #define portAPSR_MODE_BITS_MASK ( 0x0C )
  97. /* The I bit in the DAIF bits. */
  98. #define portDAIF_I ( 0x80 )
  99. /* Macro to unmask all interrupt priorities. */
  100. #define portCLEAR_INTERRUPT_MASK() \
  101. { \
  102. portDISABLE_INTERRUPTS(); \
  103. portICCPMR_PRIORITY_MASK_REGISTER = portUNMASK_VALUE; \
  104. __asm volatile ( "DSB SY \n" \
  105. "ISB SY \n" ); \
  106. portENABLE_INTERRUPTS(); \
  107. }
  108. /* Hardware specifics used when sanity checking the configuration. */
  109. #define portINTERRUPT_PRIORITY_REGISTER_OFFSET 0x400UL
  110. #define portMAX_8_BIT_VALUE ( ( uint8_t ) 0xff )
  111. #define portBIT_0_SET ( ( uint8_t ) 0x01 )
  112. /* The space on the stack required to hold the FPU registers.
  113. * There are 32 128-bit registers.*/
  114. #define portFPU_REGISTER_WORDS ( 32 * 2 )
  115. /*-----------------------------------------------------------*/
  116. /*
  117. * Starts the first task executing. This function is necessarily written in
  118. * assembly code so is implemented in portASM.s.
  119. */
  120. extern void vPortRestoreTaskContext( void );
  121. /*-----------------------------------------------------------*/
  122. /* A variable is used to keep track of the critical section nesting. This
  123. * variable has to be stored as part of the task context and must be initialised to
  124. * a non zero value to ensure interrupts don't inadvertently become unmasked before
  125. * the scheduler starts. As it is stored as part of the task context it will
  126. * automatically be set to 0 when the first task is started. */
  127. volatile uint64_t ullCriticalNesting = 9999ULL;
  128. /* Saved as part of the task context. If ullPortTaskHasFPUContext is non-zero
  129. * then floating point context must be saved and restored for the task. */
  130. uint64_t ullPortTaskHasFPUContext = pdFALSE;
  131. /* Set to 1 to pend a context switch from an ISR. */
  132. uint64_t ullPortYieldRequired = pdFALSE;
  133. /* Counts the interrupt nesting depth. A context switch is only performed if
  134. * if the nesting depth is 0. */
  135. uint64_t ullPortInterruptNesting = 0;
  136. /* Used in the ASM code. */
  137. __attribute__( ( used ) ) const uint64_t ullICCEOIR = portICCEOIR_END_OF_INTERRUPT_REGISTER_ADDRESS;
  138. __attribute__( ( used ) ) const uint64_t ullICCIAR = portICCIAR_INTERRUPT_ACKNOWLEDGE_REGISTER_ADDRESS;
  139. __attribute__( ( used ) ) const uint64_t ullICCPMR = portICCPMR_PRIORITY_MASK_REGISTER_ADDRESS;
  140. __attribute__( ( used ) ) const uint64_t ullMaxAPIPriorityMask = ( configMAX_API_CALL_INTERRUPT_PRIORITY << portPRIORITY_SHIFT );
  141. /*-----------------------------------------------------------*/
  142. /*
  143. * See header file for description.
  144. */
  145. StackType_t * pxPortInitialiseStack( StackType_t * pxTopOfStack,
  146. TaskFunction_t pxCode,
  147. void * pvParameters )
  148. {
  149. /* Setup the initial stack of the task. The stack is set exactly as
  150. * expected by the portRESTORE_CONTEXT() macro. */
  151. /* First all the general purpose registers. */
  152. pxTopOfStack--;
  153. *pxTopOfStack = 0x0101010101010101ULL; /* R1 */
  154. pxTopOfStack--;
  155. *pxTopOfStack = ( StackType_t ) pvParameters; /* R0 */
  156. pxTopOfStack--;
  157. *pxTopOfStack = 0x0303030303030303ULL; /* R3 */
  158. pxTopOfStack--;
  159. *pxTopOfStack = 0x0202020202020202ULL; /* R2 */
  160. pxTopOfStack--;
  161. *pxTopOfStack = 0x0505050505050505ULL; /* R5 */
  162. pxTopOfStack--;
  163. *pxTopOfStack = 0x0404040404040404ULL; /* R4 */
  164. pxTopOfStack--;
  165. *pxTopOfStack = 0x0707070707070707ULL; /* R7 */
  166. pxTopOfStack--;
  167. *pxTopOfStack = 0x0606060606060606ULL; /* R6 */
  168. pxTopOfStack--;
  169. *pxTopOfStack = 0x0909090909090909ULL; /* R9 */
  170. pxTopOfStack--;
  171. *pxTopOfStack = 0x0808080808080808ULL; /* R8 */
  172. pxTopOfStack--;
  173. *pxTopOfStack = 0x1111111111111111ULL; /* R11 */
  174. pxTopOfStack--;
  175. *pxTopOfStack = 0x1010101010101010ULL; /* R10 */
  176. pxTopOfStack--;
  177. *pxTopOfStack = 0x1313131313131313ULL; /* R13 */
  178. pxTopOfStack--;
  179. *pxTopOfStack = 0x1212121212121212ULL; /* R12 */
  180. pxTopOfStack--;
  181. *pxTopOfStack = 0x1515151515151515ULL; /* R15 */
  182. pxTopOfStack--;
  183. *pxTopOfStack = 0x1414141414141414ULL; /* R14 */
  184. pxTopOfStack--;
  185. *pxTopOfStack = 0x1717171717171717ULL; /* R17 */
  186. pxTopOfStack--;
  187. *pxTopOfStack = 0x1616161616161616ULL; /* R16 */
  188. pxTopOfStack--;
  189. *pxTopOfStack = 0x1919191919191919ULL; /* R19 */
  190. pxTopOfStack--;
  191. *pxTopOfStack = 0x1818181818181818ULL; /* R18 */
  192. pxTopOfStack--;
  193. *pxTopOfStack = 0x2121212121212121ULL; /* R21 */
  194. pxTopOfStack--;
  195. *pxTopOfStack = 0x2020202020202020ULL; /* R20 */
  196. pxTopOfStack--;
  197. *pxTopOfStack = 0x2323232323232323ULL; /* R23 */
  198. pxTopOfStack--;
  199. *pxTopOfStack = 0x2222222222222222ULL; /* R22 */
  200. pxTopOfStack--;
  201. *pxTopOfStack = 0x2525252525252525ULL; /* R25 */
  202. pxTopOfStack--;
  203. *pxTopOfStack = 0x2424242424242424ULL; /* R24 */
  204. pxTopOfStack--;
  205. *pxTopOfStack = 0x2727272727272727ULL; /* R27 */
  206. pxTopOfStack--;
  207. *pxTopOfStack = 0x2626262626262626ULL; /* R26 */
  208. pxTopOfStack--;
  209. *pxTopOfStack = 0x2929292929292929ULL; /* R29 */
  210. pxTopOfStack--;
  211. *pxTopOfStack = 0x2828282828282828ULL; /* R28 */
  212. pxTopOfStack--;
  213. *pxTopOfStack = ( StackType_t ) 0x00; /* XZR - has no effect, used so there are an even number of registers. */
  214. pxTopOfStack--;
  215. *pxTopOfStack = ( StackType_t ) 0x00; /* R30 - procedure call link register. */
  216. pxTopOfStack--;
  217. *pxTopOfStack = portINITIAL_PSTATE;
  218. pxTopOfStack--;
  219. *pxTopOfStack = ( StackType_t ) pxCode; /* Exception return address. */
  220. #if ( configUSE_TASK_FPU_SUPPORT == 1 )
  221. {
  222. /* The task will start with a critical nesting count of 0 as interrupts are
  223. * enabled. */
  224. pxTopOfStack--;
  225. *pxTopOfStack = portNO_CRITICAL_NESTING;
  226. /* The task will start without a floating point context. A task that
  227. * uses the floating point hardware must call vPortTaskUsesFPU() before
  228. * executing any floating point instructions. */
  229. pxTopOfStack--;
  230. *pxTopOfStack = portNO_FLOATING_POINT_CONTEXT;
  231. }
  232. #elif ( configUSE_TASK_FPU_SUPPORT == 2 )
  233. {
  234. /* The task will start with a floating point context. Leave enough
  235. * space for the registers - and ensure they are initialised to 0. */
  236. pxTopOfStack -= portFPU_REGISTER_WORDS;
  237. memset( pxTopOfStack, 0x00, portFPU_REGISTER_WORDS * sizeof( StackType_t ) );
  238. /* The task will start with a critical nesting count of 0 as interrupts are
  239. * enabled. */
  240. pxTopOfStack--;
  241. *pxTopOfStack = portNO_CRITICAL_NESTING;
  242. pxTopOfStack--;
  243. *pxTopOfStack = pdTRUE;
  244. ullPortTaskHasFPUContext = pdTRUE;
  245. }
  246. #else /* if ( configUSE_TASK_FPU_SUPPORT == 1 ) */
  247. {
  248. #error "Invalid configUSE_TASK_FPU_SUPPORT setting - configUSE_TASK_FPU_SUPPORT must be set to 1, 2, or left undefined."
  249. }
  250. #endif /* if ( configUSE_TASK_FPU_SUPPORT == 1 ) */
  251. return pxTopOfStack;
  252. }
  253. /*-----------------------------------------------------------*/
  254. BaseType_t xPortStartScheduler( void )
  255. {
  256. uint32_t ulAPSR;
  257. #if ( configASSERT_DEFINED == 1 )
  258. {
  259. volatile uint8_t ucOriginalPriority;
  260. volatile uint8_t * const pucFirstUserPriorityRegister = ( volatile uint8_t * const ) ( configINTERRUPT_CONTROLLER_BASE_ADDRESS + portINTERRUPT_PRIORITY_REGISTER_OFFSET );
  261. volatile uint8_t ucMaxPriorityValue;
  262. /* Determine how many priority bits are implemented in the GIC.
  263. *
  264. * Save the interrupt priority value that is about to be clobbered. */
  265. ucOriginalPriority = *pucFirstUserPriorityRegister;
  266. /* Determine the number of priority bits available. First write to
  267. * all possible bits. */
  268. *pucFirstUserPriorityRegister = portMAX_8_BIT_VALUE;
  269. /* Read the value back to see how many bits stuck. */
  270. ucMaxPriorityValue = *pucFirstUserPriorityRegister;
  271. /* Shift to the least significant bits. */
  272. while( ( ucMaxPriorityValue & portBIT_0_SET ) != portBIT_0_SET )
  273. {
  274. ucMaxPriorityValue >>= ( uint8_t ) 0x01;
  275. }
  276. /* Sanity check configUNIQUE_INTERRUPT_PRIORITIES matches the read
  277. * value. */
  278. configASSERT( ucMaxPriorityValue >= portLOWEST_INTERRUPT_PRIORITY );
  279. /* Restore the clobbered interrupt priority register to its original
  280. * value. */
  281. *pucFirstUserPriorityRegister = ucOriginalPriority;
  282. }
  283. #endif /* configASSERT_DEFINED */
  284. /* At the time of writing, the BSP only supports EL3. */
  285. __asm volatile ( "MRS %0, CurrentEL" : "=r" ( ulAPSR ) );
  286. ulAPSR &= portAPSR_MODE_BITS_MASK;
  287. #if defined( GUEST )
  288. #warning "Building for execution as a guest under XEN. THIS IS NOT A FULLY TESTED PATH."
  289. configASSERT( ulAPSR == portEL1 );
  290. if( ulAPSR == portEL1 )
  291. #else
  292. configASSERT( ulAPSR == portEL3 );
  293. if( ulAPSR == portEL3 )
  294. #endif
  295. {
  296. /* Only continue if the binary point value is set to its lowest possible
  297. * setting. See the comments in vPortValidateInterruptPriority() below for
  298. * more information. */
  299. configASSERT( ( portICCBPR_BINARY_POINT_REGISTER & portBINARY_POINT_BITS ) <= portMAX_BINARY_POINT_VALUE );
  300. if( ( portICCBPR_BINARY_POINT_REGISTER & portBINARY_POINT_BITS ) <= portMAX_BINARY_POINT_VALUE )
  301. {
  302. /* Interrupts are turned off in the CPU itself to ensure a tick does
  303. * not execute while the scheduler is being started. Interrupts are
  304. * automatically turned back on in the CPU when the first task starts
  305. * executing. */
  306. portDISABLE_INTERRUPTS();
  307. /* Start the timer that generates the tick ISR. */
  308. configSETUP_TICK_INTERRUPT();
  309. /* Start the first task executing. */
  310. vPortRestoreTaskContext();
  311. }
  312. }
  313. return 0;
  314. }
  315. /*-----------------------------------------------------------*/
  316. void vPortEndScheduler( void )
  317. {
  318. /* Not implemented in ports where there is nothing to return to.
  319. * Artificially force an assert. */
  320. configASSERT( ullCriticalNesting == 1000ULL );
  321. }
  322. /*-----------------------------------------------------------*/
  323. void vPortEnterCritical( void )
  324. {
  325. /* Mask interrupts up to the max syscall interrupt priority. */
  326. uxPortSetInterruptMask();
  327. /* Now interrupts are disabled ullCriticalNesting can be accessed
  328. * directly. Increment ullCriticalNesting to keep a count of how many times
  329. * portENTER_CRITICAL() has been called. */
  330. ullCriticalNesting++;
  331. /* This is not the interrupt safe version of the enter critical function so
  332. * assert() if it is being called from an interrupt context. Only API
  333. * functions that end in "FromISR" can be used in an interrupt. Only assert if
  334. * the critical nesting count is 1 to protect against recursive calls if the
  335. * assert function also uses a critical section. */
  336. if( ullCriticalNesting == 1ULL )
  337. {
  338. configASSERT( ullPortInterruptNesting == 0 );
  339. }
  340. }
  341. /*-----------------------------------------------------------*/
  342. void vPortExitCritical( void )
  343. {
  344. if( ullCriticalNesting > portNO_CRITICAL_NESTING )
  345. {
  346. /* Decrement the nesting count as the critical section is being
  347. * exited. */
  348. ullCriticalNesting--;
  349. /* If the nesting level has reached zero then all interrupt
  350. * priorities must be re-enabled. */
  351. if( ullCriticalNesting == portNO_CRITICAL_NESTING )
  352. {
  353. /* Critical nesting has reached zero so all interrupt priorities
  354. * should be unmasked. */
  355. portCLEAR_INTERRUPT_MASK();
  356. }
  357. }
  358. }
  359. /*-----------------------------------------------------------*/
  360. void FreeRTOS_Tick_Handler( void )
  361. {
  362. /* Must be the lowest possible priority. */
  363. #if !defined( QEMU )
  364. {
  365. configASSERT( portICCRPR_RUNNING_PRIORITY_REGISTER == ( uint32_t ) ( portLOWEST_USABLE_INTERRUPT_PRIORITY << portPRIORITY_SHIFT ) );
  366. }
  367. #endif
  368. /* Interrupts should not be enabled before this point. */
  369. #if ( configASSERT_DEFINED == 1 )
  370. {
  371. uint32_t ulMaskBits;
  372. __asm volatile ( "mrs %0, daif" : "=r" ( ulMaskBits )::"memory" );
  373. configASSERT( ( ulMaskBits & portDAIF_I ) != 0 );
  374. }
  375. #endif /* configASSERT_DEFINED */
  376. /* Set interrupt mask before altering scheduler structures. The tick
  377. * handler runs at the lowest priority, so interrupts cannot already be masked,
  378. * so there is no need to save and restore the current mask value. It is
  379. * necessary to turn off interrupts in the CPU itself while the ICCPMR is being
  380. * updated. */
  381. portICCPMR_PRIORITY_MASK_REGISTER = ( uint32_t ) ( configMAX_API_CALL_INTERRUPT_PRIORITY << portPRIORITY_SHIFT );
  382. __asm volatile ( "dsb sy \n"
  383. "isb sy \n" ::: "memory" );
  384. /* Ok to enable interrupts after the interrupt source has been cleared. */
  385. configCLEAR_TICK_INTERRUPT();
  386. portENABLE_INTERRUPTS();
  387. /* Increment the RTOS tick. */
  388. if( xTaskIncrementTick() != pdFALSE )
  389. {
  390. ullPortYieldRequired = pdTRUE;
  391. }
  392. /* Ensure all interrupt priorities are active again. */
  393. portCLEAR_INTERRUPT_MASK();
  394. }
  395. /*-----------------------------------------------------------*/
  396. #if ( configUSE_TASK_FPU_SUPPORT != 2 )
  397. void vPortTaskUsesFPU( void )
  398. {
  399. /* A task is registering the fact that it needs an FPU context. Set the
  400. * FPU flag (which is saved as part of the task context). */
  401. ullPortTaskHasFPUContext = pdTRUE;
  402. /* Consider initialising the FPSR here - but probably not necessary in
  403. * AArch64. */
  404. }
  405. #endif /* configUSE_TASK_FPU_SUPPORT */
  406. /*-----------------------------------------------------------*/
  407. void vPortClearInterruptMask( UBaseType_t uxNewMaskValue )
  408. {
  409. if( uxNewMaskValue == pdFALSE )
  410. {
  411. portCLEAR_INTERRUPT_MASK();
  412. }
  413. }
  414. /*-----------------------------------------------------------*/
  415. UBaseType_t uxPortSetInterruptMask( void )
  416. {
  417. uint32_t ulReturn;
  418. /* Interrupt in the CPU must be turned off while the ICCPMR is being
  419. * updated. */
  420. portDISABLE_INTERRUPTS();
  421. if( portICCPMR_PRIORITY_MASK_REGISTER == ( uint32_t ) ( configMAX_API_CALL_INTERRUPT_PRIORITY << portPRIORITY_SHIFT ) )
  422. {
  423. /* Interrupts were already masked. */
  424. ulReturn = pdTRUE;
  425. }
  426. else
  427. {
  428. ulReturn = pdFALSE;
  429. portICCPMR_PRIORITY_MASK_REGISTER = ( uint32_t ) ( configMAX_API_CALL_INTERRUPT_PRIORITY << portPRIORITY_SHIFT );
  430. __asm volatile ( "dsb sy \n"
  431. "isb sy \n" ::: "memory" );
  432. }
  433. portENABLE_INTERRUPTS();
  434. return ulReturn;
  435. }
  436. /*-----------------------------------------------------------*/
  437. #if ( configASSERT_DEFINED == 1 )
  438. void vPortValidateInterruptPriority( void )
  439. {
  440. /* The following assertion will fail if a service routine (ISR) for
  441. * an interrupt that has been assigned a priority above
  442. * configMAX_SYSCALL_INTERRUPT_PRIORITY calls an ISR safe FreeRTOS API
  443. * function. ISR safe FreeRTOS API functions must *only* be called
  444. * from interrupts that have been assigned a priority at or below
  445. * configMAX_SYSCALL_INTERRUPT_PRIORITY.
  446. *
  447. * Numerically low interrupt priority numbers represent logically high
  448. * interrupt priorities, therefore the priority of the interrupt must
  449. * be set to a value equal to or numerically *higher* than
  450. * configMAX_SYSCALL_INTERRUPT_PRIORITY.
  451. *
  452. * FreeRTOS maintains separate thread and ISR API functions to ensure
  453. * interrupt entry is as fast and simple as possible. */
  454. configASSERT( portICCRPR_RUNNING_PRIORITY_REGISTER >= ( uint32_t ) ( configMAX_API_CALL_INTERRUPT_PRIORITY << portPRIORITY_SHIFT ) );
  455. /* Priority grouping: The interrupt controller (GIC) allows the bits
  456. * that define each interrupt's priority to be split between bits that
  457. * define the interrupt's pre-emption priority bits and bits that define
  458. * the interrupt's sub-priority. For simplicity all bits must be defined
  459. * to be pre-emption priority bits. The following assertion will fail if
  460. * this is not the case (if some bits represent a sub-priority).
  461. *
  462. * The priority grouping is configured by the GIC's binary point register
  463. * (ICCBPR). Writing 0 to ICCBPR will ensure it is set to its lowest
  464. * possible value (which may be above 0). */
  465. configASSERT( ( portICCBPR_BINARY_POINT_REGISTER & portBINARY_POINT_BITS ) <= portMAX_BINARY_POINT_VALUE );
  466. }
  467. #endif /* configASSERT_DEFINED */
  468. /*-----------------------------------------------------------*/