port.c 21 KB

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