port.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531
  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. /* 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. Refer to Cortex-A equivalent: http: /*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. Refer to Cortex-A equivalent: http: /*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. Refer to Cortex-A equivalent: http: /*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. Refer to Cortex-A equivalent: http: /*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. Refer to Cortex-A equivalent: http: /*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 ( ( uint32_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 portINITIAL_SPSR ( ( StackType_t ) 0x1f ) /* System mode, ARM mode, IRQ enabled FIQ enabled. */
  83. #define portTHUMB_MODE_BIT ( ( StackType_t ) 0x20 )
  84. #define portINTERRUPT_ENABLE_BIT ( 0x80UL )
  85. #define portTHUMB_MODE_ADDRESS ( 0x01UL )
  86. /* Used by portASSERT_IF_INTERRUPT_PRIORITY_INVALID() when ensuring the binary
  87. * point is zero. */
  88. #define portBINARY_POINT_BITS ( ( uint8_t ) 0x03 )
  89. /* Masks all bits in the APSR other than the mode bits. */
  90. #define portAPSR_MODE_BITS_MASK ( 0x1F )
  91. /* The value of the mode bits in the APSR when the CPU is executing in user
  92. * mode. */
  93. #define portAPSR_USER_MODE ( 0x10 )
  94. /* The critical section macros only mask interrupts up to an application
  95. * determined priority level. Sometimes it is necessary to turn interrupt off in
  96. * the CPU itself before modifying certain hardware registers. */
  97. #define portCPU_IRQ_DISABLE() \
  98. __asm volatile ( "CPSID i" ::: "memory" ); \
  99. __asm volatile ( "DSB" ); \
  100. __asm volatile ( "ISB" );
  101. #define portCPU_IRQ_ENABLE() \
  102. __asm volatile ( "CPSIE i" ::: "memory" ); \
  103. __asm volatile ( "DSB" ); \
  104. __asm volatile ( "ISB" );
  105. /* Macro to unmask all interrupt priorities. */
  106. #define portCLEAR_INTERRUPT_MASK() \
  107. { \
  108. portCPU_IRQ_DISABLE(); \
  109. portICCPMR_PRIORITY_MASK_REGISTER = portUNMASK_VALUE; \
  110. __asm volatile ( "DSB \n" \
  111. "ISB \n"); \
  112. portCPU_IRQ_ENABLE(); \
  113. }
  114. #define portINTERRUPT_PRIORITY_REGISTER_OFFSET 0x400UL
  115. #define portMAX_8_BIT_VALUE ( ( uint8_t ) 0xff )
  116. #define portBIT_0_SET ( ( uint8_t ) 0x01 )
  117. /* Let the user override the pre-loading of the initial LR with the address of
  118. * prvTaskExitError() in case is messes up unwinding of the stack in the
  119. * debugger. */
  120. #ifdef configTASK_RETURN_ADDRESS
  121. #define portTASK_RETURN_ADDRESS configTASK_RETURN_ADDRESS
  122. #else
  123. #define portTASK_RETURN_ADDRESS prvTaskExitError
  124. #endif
  125. /*-----------------------------------------------------------*/
  126. /*
  127. * Starts the first task executing. This function is necessarily written in
  128. * assembly code so is implemented in portASM.s.
  129. */
  130. extern void vPortRestoreTaskContext( void );
  131. /*
  132. * Used to catch tasks that attempt to return from their implementing function.
  133. */
  134. static void prvTaskExitError( void );
  135. /*-----------------------------------------------------------*/
  136. /* A variable is used to keep track of the critical section nesting. This
  137. * variable has to be stored as part of the task context and must be initialised to
  138. * a non zero value to ensure interrupts don't inadvertently become unmasked before
  139. * the scheduler starts. As it is stored as part of the task context it will
  140. * automatically be set to 0 when the first task is started. */
  141. volatile uint32_t ulCriticalNesting = 9999UL;
  142. /* Saved as part of the task context. If ulPortTaskHasFPUContext is non-zero then
  143. * a floating point context must be saved and restored for the task. */
  144. uint32_t ulPortTaskHasFPUContext = pdFALSE;
  145. /* Set to 1 to pend a context switch from an ISR. */
  146. uint32_t ulPortYieldRequired = pdFALSE;
  147. /* Counts the interrupt nesting depth. A context switch is only performed if
  148. * if the nesting depth is 0. */
  149. uint32_t ulPortInterruptNesting = 0UL;
  150. /* Used in asm code. */
  151. __attribute__( ( used ) ) const uint32_t ulICCIAR = portICCIAR_INTERRUPT_ACKNOWLEDGE_REGISTER_ADDRESS;
  152. __attribute__( ( used ) ) const uint32_t ulICCEOIR = portICCEOIR_END_OF_INTERRUPT_REGISTER_ADDRESS;
  153. __attribute__( ( used ) ) const uint32_t ulICCPMR = portICCPMR_PRIORITY_MASK_REGISTER_ADDRESS;
  154. __attribute__( ( used ) ) const uint32_t ulMaxAPIPriorityMask = ( configMAX_API_CALL_INTERRUPT_PRIORITY << portPRIORITY_SHIFT );
  155. /*-----------------------------------------------------------*/
  156. /*
  157. * See header file for description.
  158. */
  159. StackType_t * pxPortInitialiseStack( StackType_t * pxTopOfStack,
  160. TaskFunction_t pxCode,
  161. void * pvParameters )
  162. {
  163. /* Setup the initial stack of the task. The stack is set exactly as
  164. * expected by the portRESTORE_CONTEXT() macro.
  165. *
  166. * The fist real value on the stack is the status register, which is set for
  167. * system mode, with interrupts enabled. A few NULLs are added first to ensure
  168. * GDB does not try decoding a non-existent return address. */
  169. *pxTopOfStack = ( StackType_t ) NULL;
  170. pxTopOfStack--;
  171. *pxTopOfStack = ( StackType_t ) NULL;
  172. pxTopOfStack--;
  173. *pxTopOfStack = ( StackType_t ) NULL;
  174. pxTopOfStack--;
  175. *pxTopOfStack = ( StackType_t ) portINITIAL_SPSR;
  176. if( ( ( uint32_t ) pxCode & portTHUMB_MODE_ADDRESS ) != 0x00UL )
  177. {
  178. /* The task will start in THUMB mode. */
  179. *pxTopOfStack |= portTHUMB_MODE_BIT;
  180. }
  181. pxTopOfStack--;
  182. /* Next the return address, which in this case is the start of the task. */
  183. *pxTopOfStack = ( StackType_t ) pxCode;
  184. pxTopOfStack--;
  185. /* Next all the registers other than the stack pointer. */
  186. *pxTopOfStack = ( StackType_t ) portTASK_RETURN_ADDRESS; /* R14 */
  187. pxTopOfStack--;
  188. *pxTopOfStack = ( StackType_t ) 0x12121212; /* R12 */
  189. pxTopOfStack--;
  190. *pxTopOfStack = ( StackType_t ) 0x11111111; /* R11 */
  191. pxTopOfStack--;
  192. *pxTopOfStack = ( StackType_t ) 0x10101010; /* R10 */
  193. pxTopOfStack--;
  194. *pxTopOfStack = ( StackType_t ) 0x09090909; /* R9 */
  195. pxTopOfStack--;
  196. *pxTopOfStack = ( StackType_t ) 0x08080808; /* R8 */
  197. pxTopOfStack--;
  198. *pxTopOfStack = ( StackType_t ) 0x07070707; /* R7 */
  199. pxTopOfStack--;
  200. *pxTopOfStack = ( StackType_t ) 0x06060606; /* R6 */
  201. pxTopOfStack--;
  202. *pxTopOfStack = ( StackType_t ) 0x05050505; /* R5 */
  203. pxTopOfStack--;
  204. *pxTopOfStack = ( StackType_t ) 0x04040404; /* R4 */
  205. pxTopOfStack--;
  206. *pxTopOfStack = ( StackType_t ) 0x03030303; /* R3 */
  207. pxTopOfStack--;
  208. *pxTopOfStack = ( StackType_t ) 0x02020202; /* R2 */
  209. pxTopOfStack--;
  210. *pxTopOfStack = ( StackType_t ) 0x01010101; /* R1 */
  211. pxTopOfStack--;
  212. *pxTopOfStack = ( StackType_t ) pvParameters; /* R0 */
  213. pxTopOfStack--;
  214. /* The task will start with a critical nesting count of 0 as interrupts are
  215. * enabled. */
  216. *pxTopOfStack = portNO_CRITICAL_NESTING;
  217. pxTopOfStack--;
  218. /* The task will start without a floating point context. A task that uses
  219. * the floating point hardware must call vPortTaskUsesFPU() before executing
  220. * any floating point instructions. */
  221. *pxTopOfStack = portNO_FLOATING_POINT_CONTEXT;
  222. return pxTopOfStack;
  223. }
  224. /*-----------------------------------------------------------*/
  225. static void prvTaskExitError( void )
  226. {
  227. /* A function that implements a task must not exit or attempt to return to
  228. * its caller as there is nothing to return to. If a task wants to exit it
  229. * should instead call vTaskDelete( NULL ).
  230. *
  231. * Artificially force an assert() to be triggered if configASSERT() is
  232. * defined, then stop here so application writers can catch the error. */
  233. configASSERT( ulPortInterruptNesting == ~0UL );
  234. portDISABLE_INTERRUPTS();
  235. for( ; ; )
  236. {
  237. }
  238. }
  239. /*-----------------------------------------------------------*/
  240. BaseType_t xPortStartScheduler( void )
  241. {
  242. uint32_t ulAPSR, ulCycles = 8; /* 8 bits per byte. */
  243. #if ( configASSERT_DEFINED == 1 )
  244. {
  245. volatile uint32_t ulOriginalPriority;
  246. volatile uint8_t * const pucFirstUserPriorityRegister = ( volatile uint8_t * const ) ( configINTERRUPT_CONTROLLER_BASE_ADDRESS + portINTERRUPT_PRIORITY_REGISTER_OFFSET );
  247. volatile uint8_t ucMaxPriorityValue;
  248. /* Determine how many priority bits are implemented in the GIC.
  249. *
  250. * Save the interrupt priority value that is about to be clobbered. */
  251. ulOriginalPriority = *pucFirstUserPriorityRegister;
  252. /* Determine the number of priority bits available. First write to
  253. * all possible bits. */
  254. *pucFirstUserPriorityRegister = portMAX_8_BIT_VALUE;
  255. /* Read the value back to see how many bits stuck. */
  256. ucMaxPriorityValue = *pucFirstUserPriorityRegister;
  257. /* Shift to the least significant bits. */
  258. while( ( ucMaxPriorityValue & portBIT_0_SET ) != portBIT_0_SET )
  259. {
  260. ucMaxPriorityValue >>= ( uint8_t ) 0x01;
  261. /* If ulCycles reaches 0 then ucMaxPriorityValue must have been
  262. * read as 0, indicating a misconfiguration. */
  263. ulCycles--;
  264. if( ulCycles == 0 )
  265. {
  266. break;
  267. }
  268. }
  269. /* Sanity check configUNIQUE_INTERRUPT_PRIORITIES matches the read
  270. * value. */
  271. configASSERT( ucMaxPriorityValue == portLOWEST_INTERRUPT_PRIORITY );
  272. /* Restore the clobbered interrupt priority register to its original
  273. * value. */
  274. *pucFirstUserPriorityRegister = ulOriginalPriority;
  275. }
  276. #endif /* configASSERT_DEFINED */
  277. /* Only continue if the CPU is not in User mode. The CPU must be in a
  278. * Privileged mode for the scheduler to start. */
  279. __asm volatile ( "MRS %0, APSR" : "=r" ( ulAPSR )::"memory" );
  280. ulAPSR &= portAPSR_MODE_BITS_MASK;
  281. configASSERT( ulAPSR != portAPSR_USER_MODE );
  282. if( ulAPSR != portAPSR_USER_MODE )
  283. {
  284. /* Only continue if the binary point value is set to its lowest possible
  285. * setting. See the comments in vPortValidateInterruptPriority() below for
  286. * more information. */
  287. configASSERT( ( portICCBPR_BINARY_POINT_REGISTER & portBINARY_POINT_BITS ) <= portMAX_BINARY_POINT_VALUE );
  288. if( ( portICCBPR_BINARY_POINT_REGISTER & portBINARY_POINT_BITS ) <= portMAX_BINARY_POINT_VALUE )
  289. {
  290. /* Interrupts are turned off in the CPU itself to ensure tick does
  291. * not execute while the scheduler is being started. Interrupts are
  292. * automatically turned back on in the CPU when the first task starts
  293. * executing. */
  294. portCPU_IRQ_DISABLE();
  295. /* Start the timer that generates the tick ISR. */
  296. configSETUP_TICK_INTERRUPT();
  297. /* Start the first task executing. */
  298. vPortRestoreTaskContext();
  299. }
  300. }
  301. /* Will only get here if vTaskStartScheduler() was called with the CPU in
  302. * a non-privileged mode or the binary point register was not set to its lowest
  303. * possible value. prvTaskExitError() is referenced to prevent a compiler
  304. * warning about it being defined but not referenced in the case that the user
  305. * defines their own exit address. */
  306. ( void ) prvTaskExitError;
  307. return 0;
  308. }
  309. /*-----------------------------------------------------------*/
  310. void vPortEndScheduler( void )
  311. {
  312. /* Not implemented in ports where there is nothing to return to.
  313. * Artificially force an assert. */
  314. configASSERT( ulCriticalNesting == 1000UL );
  315. }
  316. /*-----------------------------------------------------------*/
  317. void vPortEnterCritical( void )
  318. {
  319. /* Mask interrupts up to the max syscall interrupt priority. */
  320. ulPortSetInterruptMask();
  321. /* Now interrupts are disabled ulCriticalNesting can be accessed
  322. * directly. Increment ulCriticalNesting to keep a count of how many times
  323. * portENTER_CRITICAL() has been called. */
  324. ulCriticalNesting++;
  325. /* This is not the interrupt safe version of the enter critical function so
  326. * assert() if it is being called from an interrupt context. Only API
  327. * functions that end in "FromISR" can be used in an interrupt. Only assert if
  328. * the critical nesting count is 1 to protect against recursive calls if the
  329. * assert function also uses a critical section. */
  330. if( ulCriticalNesting == 1 )
  331. {
  332. configASSERT( ulPortInterruptNesting == 0 );
  333. }
  334. }
  335. /*-----------------------------------------------------------*/
  336. void vPortExitCritical( void )
  337. {
  338. if( ulCriticalNesting > portNO_CRITICAL_NESTING )
  339. {
  340. /* Decrement the nesting count as the critical section is being
  341. * exited. */
  342. ulCriticalNesting--;
  343. /* If the nesting level has reached zero then all interrupt
  344. * priorities must be re-enabled. */
  345. if( ulCriticalNesting == portNO_CRITICAL_NESTING )
  346. {
  347. /* Critical nesting has reached zero so all interrupt priorities
  348. * should be unmasked. */
  349. portCLEAR_INTERRUPT_MASK();
  350. }
  351. }
  352. }
  353. /*-----------------------------------------------------------*/
  354. void FreeRTOS_Tick_Handler( void )
  355. {
  356. /* Set interrupt mask before altering scheduler structures. The tick
  357. * handler runs at the lowest priority, so interrupts cannot already be masked,
  358. * so there is no need to save and restore the current mask value. It is
  359. * necessary to turn off interrupts in the CPU itself while the ICCPMR is being
  360. * updated. */
  361. portCPU_IRQ_DISABLE();
  362. portICCPMR_PRIORITY_MASK_REGISTER = ( uint32_t ) ( configMAX_API_CALL_INTERRUPT_PRIORITY << portPRIORITY_SHIFT );
  363. __asm volatile ( "dsb \n"
  364. "isb \n"::: "memory" );
  365. portCPU_IRQ_ENABLE();
  366. /* Increment the RTOS tick. */
  367. if( xTaskIncrementTick() != pdFALSE )
  368. {
  369. ulPortYieldRequired = pdTRUE;
  370. }
  371. /* Ensure all interrupt priorities are active again. */
  372. portCLEAR_INTERRUPT_MASK();
  373. configCLEAR_TICK_INTERRUPT();
  374. }
  375. /*-----------------------------------------------------------*/
  376. void vPortTaskUsesFPU( void )
  377. {
  378. uint32_t ulInitialFPSCR = 0;
  379. /* A task is registering the fact that it needs an FPU context. Set the
  380. * FPU flag (which is saved as part of the task context). */
  381. ulPortTaskHasFPUContext = pdTRUE;
  382. /* Initialise the floating point status register. */
  383. __asm volatile ( "FMXR FPSCR, %0" ::"r" ( ulInitialFPSCR ) : "memory" );
  384. }
  385. /*-----------------------------------------------------------*/
  386. void vPortClearInterruptMask( uint32_t ulNewMaskValue )
  387. {
  388. if( ulNewMaskValue == pdFALSE )
  389. {
  390. portCLEAR_INTERRUPT_MASK();
  391. }
  392. }
  393. /*-----------------------------------------------------------*/
  394. uint32_t ulPortSetInterruptMask( void )
  395. {
  396. uint32_t ulReturn;
  397. /* Interrupt in the CPU must be turned off while the ICCPMR is being
  398. * updated. */
  399. portCPU_IRQ_DISABLE();
  400. if( portICCPMR_PRIORITY_MASK_REGISTER == ( uint32_t ) ( configMAX_API_CALL_INTERRUPT_PRIORITY << portPRIORITY_SHIFT ) )
  401. {
  402. /* Interrupts were already masked. */
  403. ulReturn = pdTRUE;
  404. }
  405. else
  406. {
  407. ulReturn = pdFALSE;
  408. portICCPMR_PRIORITY_MASK_REGISTER = ( uint32_t ) ( configMAX_API_CALL_INTERRUPT_PRIORITY << portPRIORITY_SHIFT );
  409. __asm volatile ( "dsb \n"
  410. "isb \n"::: "memory" );
  411. }
  412. portCPU_IRQ_ENABLE();
  413. return ulReturn;
  414. }
  415. /*-----------------------------------------------------------*/
  416. #if ( configASSERT_DEFINED == 1 )
  417. void vPortValidateInterruptPriority( void )
  418. {
  419. /* The following assertion will fail if a service routine (ISR) for
  420. * an interrupt that has been assigned a priority above
  421. * configMAX_SYSCALL_INTERRUPT_PRIORITY calls an ISR safe FreeRTOS API
  422. * function. ISR safe FreeRTOS API functions must *only* be called
  423. * from interrupts that have been assigned a priority at or below
  424. * configMAX_SYSCALL_INTERRUPT_PRIORITY.
  425. *
  426. * Numerically low interrupt priority numbers represent logically high
  427. * interrupt priorities, therefore the priority of the interrupt must
  428. * be set to a value equal to or numerically *higher* than
  429. * configMAX_SYSCALL_INTERRUPT_PRIORITY.
  430. *
  431. * FreeRTOS maintains separate thread and ISR API functions to ensure
  432. * interrupt entry is as fast and simple as possible. */
  433. configASSERT( portICCRPR_RUNNING_PRIORITY_REGISTER >= ( uint32_t ) ( configMAX_API_CALL_INTERRUPT_PRIORITY << portPRIORITY_SHIFT ) );
  434. /* Priority grouping: The interrupt controller (GIC) allows the bits
  435. * that define each interrupt's priority to be split between bits that
  436. * define the interrupt's pre-emption priority bits and bits that define
  437. * the interrupt's sub-priority. For simplicity all bits must be defined
  438. * to be pre-emption priority bits. The following assertion will fail if
  439. * this is not the case (if some bits represent a sub-priority).
  440. *
  441. * The priority grouping is configured by the GIC's binary point register
  442. * (ICCBPR). Writing 0 to ICCBPR will ensure it is set to its lowest
  443. * possible value (which may be above 0). */
  444. configASSERT( ( portICCBPR_BINARY_POINT_REGISTER & portBINARY_POINT_BITS ) <= portMAX_BINARY_POINT_VALUE );
  445. }
  446. #endif /* configASSERT_DEFINED */
  447. /*-----------------------------------------------------------*/