port.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522
  1. /*
  2. FreeRTOS V9.0.0 - Copyright (C) 2016 Real Time Engineers Ltd.
  3. All rights reserved
  4. VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
  5. This file is part of the FreeRTOS distribution.
  6. FreeRTOS is free software; you can redistribute it and/or modify it under
  7. the terms of the GNU General Public License (version 2) as published by the
  8. Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception.
  9. ***************************************************************************
  10. >>! NOTE: The modification to the GPL is included to allow you to !<<
  11. >>! distribute a combined work that includes FreeRTOS without being !<<
  12. >>! obliged to provide the source code for proprietary components !<<
  13. >>! outside of the FreeRTOS kernel. !<<
  14. ***************************************************************************
  15. FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
  16. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  17. FOR A PARTICULAR PURPOSE. Full license text is available on the following
  18. link: http://www.freertos.org/a00114.html
  19. ***************************************************************************
  20. * *
  21. * FreeRTOS provides completely free yet professionally developed, *
  22. * robust, strictly quality controlled, supported, and cross *
  23. * platform software that is more than just the market leader, it *
  24. * is the industry's de facto standard. *
  25. * *
  26. * Help yourself get started quickly while simultaneously helping *
  27. * to support the FreeRTOS project by purchasing a FreeRTOS *
  28. * tutorial book, reference manual, or both: *
  29. * http://www.FreeRTOS.org/Documentation *
  30. * *
  31. ***************************************************************************
  32. http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading
  33. the FAQ page "My application does not run, what could be wrong?". Have you
  34. defined configASSERT()?
  35. http://www.FreeRTOS.org/support - In return for receiving this top quality
  36. embedded software for free we request you assist our global community by
  37. participating in the support forum.
  38. http://www.FreeRTOS.org/training - Investing in training allows your team to
  39. be as productive as possible as early as possible. Now you can receive
  40. FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
  41. Ltd, and the world's leading authority on the world's leading RTOS.
  42. http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
  43. including FreeRTOS+Trace - an indispensable productivity tool, a DOS
  44. compatible FAT file system, and our tiny thread aware UDP/IP stack.
  45. http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
  46. Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
  47. http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
  48. Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
  49. licenses offer ticketed support, indemnification and commercial middleware.
  50. http://www.SafeRTOS.com - High Integrity Systems also provide a safety
  51. engineered and independently SIL3 certified version for use in safety and
  52. mission critical applications that require provable dependability.
  53. 1 tab == 4 spaces!
  54. */
  55. /* Standard includes. */
  56. #include <stdlib.h>
  57. /* Scheduler includes. */
  58. #include "FreeRTOS.h"
  59. #include "task.h"
  60. #ifndef configINTERRUPT_CONTROLLER_BASE_ADDRESS
  61. #error configINTERRUPT_CONTROLLER_BASE_ADDRESS must be defined. See http://www.freertos.org/Using-FreeRTOS-on-Cortex-A-Embedded-Processors.html
  62. #endif
  63. #ifndef configINTERRUPT_CONTROLLER_CPU_INTERFACE_OFFSET
  64. #error configINTERRUPT_CONTROLLER_CPU_INTERFACE_OFFSET must be defined. See http://www.freertos.org/Using-FreeRTOS-on-Cortex-A-Embedded-Processors.html
  65. #endif
  66. #ifndef configUNIQUE_INTERRUPT_PRIORITIES
  67. #error configUNIQUE_INTERRUPT_PRIORITIES must be defined. See http://www.freertos.org/Using-FreeRTOS-on-Cortex-A-Embedded-Processors.html
  68. #endif
  69. #ifndef configSETUP_TICK_INTERRUPT
  70. #error configSETUP_TICK_INTERRUPT() must be defined. See http://www.freertos.org/Using-FreeRTOS-on-Cortex-A-Embedded-Processors.html
  71. #endif /* configSETUP_TICK_INTERRUPT */
  72. #ifndef configMAX_API_CALL_INTERRUPT_PRIORITY
  73. #error configMAX_API_CALL_INTERRUPT_PRIORITY must be defined. See http://www.freertos.org/Using-FreeRTOS-on-Cortex-A-Embedded-Processors.html
  74. #endif
  75. #if configMAX_API_CALL_INTERRUPT_PRIORITY == 0
  76. #error configMAX_API_CALL_INTERRUPT_PRIORITY must not be set to 0
  77. #endif
  78. #if configMAX_API_CALL_INTERRUPT_PRIORITY > configUNIQUE_INTERRUPT_PRIORITIES
  79. #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
  80. #endif
  81. #if configUSE_PORT_OPTIMISED_TASK_SELECTION == 1
  82. /* Check the configuration. */
  83. #if( configMAX_PRIORITIES > 32 )
  84. #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.
  85. #endif
  86. #endif /* configUSE_PORT_OPTIMISED_TASK_SELECTION */
  87. /* In case security extensions are implemented. */
  88. #if configMAX_API_CALL_INTERRUPT_PRIORITY <= ( configUNIQUE_INTERRUPT_PRIORITIES / 2 )
  89. #error configMAX_API_CALL_INTERRUPT_PRIORITY must be greater than ( configUNIQUE_INTERRUPT_PRIORITIES / 2 )
  90. #endif
  91. #ifndef configCLEAR_TICK_INTERRUPT
  92. #define configCLEAR_TICK_INTERRUPT()
  93. #endif
  94. /* The number of bits to shift for an interrupt priority is dependent on the
  95. number of bits implemented by the interrupt controller. */
  96. #if configUNIQUE_INTERRUPT_PRIORITIES == 16
  97. #define portPRIORITY_SHIFT 4
  98. #define portMAX_BINARY_POINT_VALUE 3
  99. #elif configUNIQUE_INTERRUPT_PRIORITIES == 32
  100. #define portPRIORITY_SHIFT 3
  101. #define portMAX_BINARY_POINT_VALUE 2
  102. #elif configUNIQUE_INTERRUPT_PRIORITIES == 64
  103. #define portPRIORITY_SHIFT 2
  104. #define portMAX_BINARY_POINT_VALUE 1
  105. #elif configUNIQUE_INTERRUPT_PRIORITIES == 128
  106. #define portPRIORITY_SHIFT 1
  107. #define portMAX_BINARY_POINT_VALUE 0
  108. #elif configUNIQUE_INTERRUPT_PRIORITIES == 256
  109. #define portPRIORITY_SHIFT 0
  110. #define portMAX_BINARY_POINT_VALUE 0
  111. #else
  112. #error Invalid configUNIQUE_INTERRUPT_PRIORITIES setting. configUNIQUE_INTERRUPT_PRIORITIES must be set to the number of unique priorities implemented by the target hardware
  113. #endif
  114. /* A critical section is exited when the critical section nesting count reaches
  115. this value. */
  116. #define portNO_CRITICAL_NESTING ( ( uint32_t ) 0 )
  117. /* In all GICs 255 can be written to the priority mask register to unmask all
  118. (but the lowest) interrupt priority. */
  119. #define portUNMASK_VALUE ( 0xFFUL )
  120. /* Tasks are not created with a floating point context, but can be given a
  121. floating point context after they have been created. A variable is stored as
  122. part of the tasks context that holds portNO_FLOATING_POINT_CONTEXT if the task
  123. does not have an FPU context, or any other value if the task does have an FPU
  124. context. */
  125. #define portNO_FLOATING_POINT_CONTEXT ( ( StackType_t ) 0 )
  126. /* Interrupt controller access addresses. */
  127. #define portICCPMR_PRIORITY_MASK_OFFSET ( 0x04 )
  128. #define portICCIAR_INTERRUPT_ACKNOWLEDGE_OFFSET ( 0x0C )
  129. #define portICCEOIR_END_OF_INTERRUPT_OFFSET ( 0x10 )
  130. #define portICCBPR_BINARY_POINT_OFFSET ( 0x08 )
  131. #define portICCRPR_RUNNING_PRIORITY_OFFSET ( 0x14 )
  132. #define portINTERRUPT_CONTROLLER_CPU_INTERFACE_ADDRESS ( configINTERRUPT_CONTROLLER_BASE_ADDRESS + configINTERRUPT_CONTROLLER_CPU_INTERFACE_OFFSET )
  133. #define portICCPMR_PRIORITY_MASK_REGISTER ( *( ( volatile uint32_t * ) ( portINTERRUPT_CONTROLLER_CPU_INTERFACE_ADDRESS + portICCPMR_PRIORITY_MASK_OFFSET ) ) )
  134. #define portICCIAR_INTERRUPT_ACKNOWLEDGE_REGISTER_ADDRESS ( portINTERRUPT_CONTROLLER_CPU_INTERFACE_ADDRESS + portICCIAR_INTERRUPT_ACKNOWLEDGE_OFFSET )
  135. #define portICCEOIR_END_OF_INTERRUPT_REGISTER_ADDRESS ( portINTERRUPT_CONTROLLER_CPU_INTERFACE_ADDRESS + portICCEOIR_END_OF_INTERRUPT_OFFSET )
  136. #define portICCPMR_PRIORITY_MASK_REGISTER_ADDRESS ( portINTERRUPT_CONTROLLER_CPU_INTERFACE_ADDRESS + portICCPMR_PRIORITY_MASK_OFFSET )
  137. #define portICCBPR_BINARY_POINT_REGISTER ( *( ( const volatile uint32_t * ) ( portINTERRUPT_CONTROLLER_CPU_INTERFACE_ADDRESS + portICCBPR_BINARY_POINT_OFFSET ) ) )
  138. #define portICCRPR_RUNNING_PRIORITY_REGISTER ( *( ( const volatile uint32_t * ) ( portINTERRUPT_CONTROLLER_CPU_INTERFACE_ADDRESS + portICCRPR_RUNNING_PRIORITY_OFFSET ) ) )
  139. /* Used by portASSERT_IF_INTERRUPT_PRIORITY_INVALID() when ensuring the binary
  140. point is zero. */
  141. #define portBINARY_POINT_BITS ( ( uint8_t ) 0x03 )
  142. /* Constants required to setup the initial task context. */
  143. #define portINITIAL_SPSR ( ( StackType_t ) 0x1f ) /* System mode, ARM mode, interrupts enabled. */
  144. #define portTHUMB_MODE_BIT ( ( StackType_t ) 0x20 )
  145. #define portTHUMB_MODE_ADDRESS ( 0x01UL )
  146. /* Masks all bits in the APSR other than the mode bits. */
  147. #define portAPSR_MODE_BITS_MASK ( 0x1F )
  148. /* The value of the mode bits in the APSR when the CPU is executing in user
  149. mode. */
  150. #define portAPSR_USER_MODE ( 0x10 )
  151. /* Macro to unmask all interrupt priorities. */
  152. #define portCLEAR_INTERRUPT_MASK() \
  153. { \
  154. __disable_irq(); \
  155. portICCPMR_PRIORITY_MASK_REGISTER = portUNMASK_VALUE; \
  156. __asm( "DSB \n" \
  157. "ISB \n" ); \
  158. __enable_irq(); \
  159. }
  160. /*-----------------------------------------------------------*/
  161. /*
  162. * Starts the first task executing. This function is necessarily written in
  163. * assembly code so is implemented in portASM.s.
  164. */
  165. extern void vPortRestoreTaskContext( void );
  166. /*
  167. * Used to catch tasks that attempt to return from their implementing function.
  168. */
  169. static void prvTaskExitError( void );
  170. /*-----------------------------------------------------------*/
  171. /* A variable is used to keep track of the critical section nesting. This
  172. variable has to be stored as part of the task context and must be initialised to
  173. a non zero value to ensure interrupts don't inadvertently become unmasked before
  174. the scheduler starts. As it is stored as part of the task context it will
  175. automatically be set to 0 when the first task is started. */
  176. volatile uint32_t ulCriticalNesting = 9999UL;
  177. /* Used to pass constants into the ASM code. The address at which variables are
  178. placed is the constant value so indirect loads in the asm code are not
  179. required. */
  180. uint32_t ulICCIAR __attribute__( ( at( portICCIAR_INTERRUPT_ACKNOWLEDGE_REGISTER_ADDRESS ) ) );
  181. uint32_t ulICCEOIR __attribute__( ( at( portICCEOIR_END_OF_INTERRUPT_REGISTER_ADDRESS ) ) );
  182. uint32_t ulICCPMR __attribute__( ( at( portICCPMR_PRIORITY_MASK_REGISTER_ADDRESS ) ) );
  183. uint32_t ulAsmAPIPriorityMask __attribute__( ( at( configMAX_API_CALL_INTERRUPT_PRIORITY << portPRIORITY_SHIFT ) ) );
  184. /* Saved as part of the task context. If ulPortTaskHasFPUContext is non-zero then
  185. a floating point context must be saved and restored for the task. */
  186. uint32_t ulPortTaskHasFPUContext = pdFALSE;
  187. /* Set to 1 to pend a context switch from an ISR. */
  188. uint32_t ulPortYieldRequired = pdFALSE;
  189. /* Counts the interrupt nesting depth. A context switch is only performed if
  190. if the nesting depth is 0. */
  191. uint32_t ulPortInterruptNesting = 0UL;
  192. /*-----------------------------------------------------------*/
  193. /*
  194. * See header file for description.
  195. */
  196. StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t pxCode, void *pvParameters )
  197. {
  198. /* Setup the initial stack of the task. The stack is set exactly as
  199. expected by the portRESTORE_CONTEXT() macro.
  200. The fist real value on the stack is the status register, which is set for
  201. system mode, with interrupts enabled. A few NULLs are added first to ensure
  202. GDB does not try decoding a non-existent return address. */
  203. *pxTopOfStack = NULL;
  204. pxTopOfStack--;
  205. *pxTopOfStack = NULL;
  206. pxTopOfStack--;
  207. *pxTopOfStack = NULL;
  208. pxTopOfStack--;
  209. *pxTopOfStack = ( StackType_t ) portINITIAL_SPSR;
  210. if( ( ( uint32_t ) pxCode & portTHUMB_MODE_ADDRESS ) != 0x00UL )
  211. {
  212. /* The task will start in THUMB mode. */
  213. *pxTopOfStack |= portTHUMB_MODE_BIT;
  214. }
  215. pxTopOfStack--;
  216. /* Next the return address, which in this case is the start of the task. */
  217. *pxTopOfStack = ( StackType_t ) pxCode;
  218. pxTopOfStack--;
  219. /* Next all the registers other than the stack pointer. */
  220. *pxTopOfStack = ( StackType_t ) prvTaskExitError; /* R14 */
  221. pxTopOfStack--;
  222. *pxTopOfStack = ( StackType_t ) 0x12121212; /* R12 */
  223. pxTopOfStack--;
  224. *pxTopOfStack = ( StackType_t ) 0x11111111; /* R11 */
  225. pxTopOfStack--;
  226. *pxTopOfStack = ( StackType_t ) 0x10101010; /* R10 */
  227. pxTopOfStack--;
  228. *pxTopOfStack = ( StackType_t ) 0x09090909; /* R9 */
  229. pxTopOfStack--;
  230. *pxTopOfStack = ( StackType_t ) 0x08080808; /* R8 */
  231. pxTopOfStack--;
  232. *pxTopOfStack = ( StackType_t ) 0x07070707; /* R7 */
  233. pxTopOfStack--;
  234. *pxTopOfStack = ( StackType_t ) 0x06060606; /* R6 */
  235. pxTopOfStack--;
  236. *pxTopOfStack = ( StackType_t ) 0x05050505; /* R5 */
  237. pxTopOfStack--;
  238. *pxTopOfStack = ( StackType_t ) 0x04040404; /* R4 */
  239. pxTopOfStack--;
  240. *pxTopOfStack = ( StackType_t ) 0x03030303; /* R3 */
  241. pxTopOfStack--;
  242. *pxTopOfStack = ( StackType_t ) 0x02020202; /* R2 */
  243. pxTopOfStack--;
  244. *pxTopOfStack = ( StackType_t ) 0x01010101; /* R1 */
  245. pxTopOfStack--;
  246. *pxTopOfStack = ( StackType_t ) pvParameters; /* R0 */
  247. pxTopOfStack--;
  248. /* The task will start with a critical nesting count of 0 as interrupts are
  249. enabled. */
  250. *pxTopOfStack = portNO_CRITICAL_NESTING;
  251. pxTopOfStack--;
  252. /* The task will start without a floating point context. A task that uses
  253. the floating point hardware must call vPortTaskUsesFPU() before executing
  254. any floating point instructions. */
  255. *pxTopOfStack = portNO_FLOATING_POINT_CONTEXT;
  256. return pxTopOfStack;
  257. }
  258. /*-----------------------------------------------------------*/
  259. static void prvTaskExitError( void )
  260. {
  261. /* A function that implements a task must not exit or attempt to return to
  262. its caller as there is nothing to return to. If a task wants to exit it
  263. should instead call vTaskDelete( NULL ).
  264. Artificially force an assert() to be triggered if configASSERT() is
  265. defined, then stop here so application writers can catch the error. */
  266. configASSERT( ulPortInterruptNesting == ~0UL );
  267. portDISABLE_INTERRUPTS();
  268. for( ;; );
  269. }
  270. /*-----------------------------------------------------------*/
  271. BaseType_t xPortStartScheduler( void )
  272. {
  273. uint32_t ulAPSR;
  274. /* Only continue if the CPU is not in User mode. The CPU must be in a
  275. Privileged mode for the scheduler to start. */
  276. __asm( "MRS ulAPSR, APSR" );
  277. ulAPSR &= portAPSR_MODE_BITS_MASK;
  278. configASSERT( ulAPSR != portAPSR_USER_MODE );
  279. if( ulAPSR != portAPSR_USER_MODE )
  280. {
  281. /* Only continue if the binary point value is set to its lowest possible
  282. setting. See the comments in vPortValidateInterruptPriority() below for
  283. more information. */
  284. configASSERT( ( portICCBPR_BINARY_POINT_REGISTER & portBINARY_POINT_BITS ) <= portMAX_BINARY_POINT_VALUE );
  285. if( ( portICCBPR_BINARY_POINT_REGISTER & portBINARY_POINT_BITS ) <= portMAX_BINARY_POINT_VALUE )
  286. {
  287. /* Start the timer that generates the tick ISR. */
  288. configSETUP_TICK_INTERRUPT();
  289. __enable_irq();
  290. vPortRestoreTaskContext();
  291. }
  292. }
  293. /* Will only get here if vTaskStartScheduler() was called with the CPU in
  294. a non-privileged mode or the binary point register was not set to its lowest
  295. possible value. */
  296. return 0;
  297. }
  298. /*-----------------------------------------------------------*/
  299. void vPortEndScheduler( void )
  300. {
  301. /* Not implemented in ports where there is nothing to return to.
  302. Artificially force an assert. */
  303. configASSERT( ulCriticalNesting == 1000UL );
  304. }
  305. /*-----------------------------------------------------------*/
  306. void vPortEnterCritical( void )
  307. {
  308. /* Disable interrupts as per portDISABLE_INTERRUPTS(); */
  309. ulPortSetInterruptMask();
  310. /* Now interrupts are disabled ulCriticalNesting can be accessed
  311. directly. Increment ulCriticalNesting to keep a count of how many times
  312. portENTER_CRITICAL() has been called. */
  313. ulCriticalNesting++;
  314. /* This is not the interrupt safe version of the enter critical function so
  315. assert() if it is being called from an interrupt context. Only API
  316. functions that end in "FromISR" can be used in an interrupt. Only assert if
  317. the critical nesting count is 1 to protect against recursive calls if the
  318. assert function also uses a critical section. */
  319. if( ulCriticalNesting == 1 )
  320. {
  321. configASSERT( ulPortInterruptNesting == 0 );
  322. }
  323. }
  324. /*-----------------------------------------------------------*/
  325. void vPortExitCritical( void )
  326. {
  327. if( ulCriticalNesting > portNO_CRITICAL_NESTING )
  328. {
  329. /* Decrement the nesting count as the critical section is being
  330. exited. */
  331. ulCriticalNesting--;
  332. /* If the nesting level has reached zero then all interrupt
  333. priorities must be re-enabled. */
  334. if( ulCriticalNesting == portNO_CRITICAL_NESTING )
  335. {
  336. /* Critical nesting has reached zero so all interrupt priorities
  337. should be unmasked. */
  338. portCLEAR_INTERRUPT_MASK();
  339. }
  340. }
  341. }
  342. /*-----------------------------------------------------------*/
  343. void FreeRTOS_Tick_Handler( void )
  344. {
  345. /* Set interrupt mask before altering scheduler structures. The tick
  346. handler runs at the lowest priority, so interrupts cannot already be masked,
  347. so there is no need to save and restore the current mask value. */
  348. __disable_irq();
  349. portICCPMR_PRIORITY_MASK_REGISTER = ( uint32_t ) ( configMAX_API_CALL_INTERRUPT_PRIORITY << portPRIORITY_SHIFT );
  350. __asm( "DSB \n"
  351. "ISB \n" );
  352. __enable_irq();
  353. /* Increment the RTOS tick. */
  354. if( xTaskIncrementTick() != pdFALSE )
  355. {
  356. ulPortYieldRequired = pdTRUE;
  357. }
  358. /* Ensure all interrupt priorities are active again. */
  359. portCLEAR_INTERRUPT_MASK();
  360. configCLEAR_TICK_INTERRUPT();
  361. }
  362. /*-----------------------------------------------------------*/
  363. void vPortTaskUsesFPU( void )
  364. {
  365. uint32_t ulInitialFPSCR = 0;
  366. /* A task is registering the fact that it needs an FPU context. Set the
  367. FPU flag (which is saved as part of the task context). */
  368. ulPortTaskHasFPUContext = pdTRUE;
  369. /* Initialise the floating point status register. */
  370. __asm( "FMXR FPSCR, ulInitialFPSCR" );
  371. }
  372. /*-----------------------------------------------------------*/
  373. void vPortClearInterruptMask( uint32_t ulNewMaskValue )
  374. {
  375. if( ulNewMaskValue == pdFALSE )
  376. {
  377. portCLEAR_INTERRUPT_MASK();
  378. }
  379. }
  380. /*-----------------------------------------------------------*/
  381. uint32_t ulPortSetInterruptMask( void )
  382. {
  383. uint32_t ulReturn;
  384. __disable_irq();
  385. if( portICCPMR_PRIORITY_MASK_REGISTER == ( uint32_t ) ( configMAX_API_CALL_INTERRUPT_PRIORITY << portPRIORITY_SHIFT ) )
  386. {
  387. /* Interrupts were already masked. */
  388. ulReturn = pdTRUE;
  389. }
  390. else
  391. {
  392. ulReturn = pdFALSE;
  393. portICCPMR_PRIORITY_MASK_REGISTER = ( uint32_t ) ( configMAX_API_CALL_INTERRUPT_PRIORITY << portPRIORITY_SHIFT );
  394. __asm( "DSB \n"
  395. "ISB \n" );
  396. }
  397. __enable_irq();
  398. return ulReturn;
  399. }
  400. /*-----------------------------------------------------------*/
  401. #if( configASSERT_DEFINED == 1 )
  402. void vPortValidateInterruptPriority( void )
  403. {
  404. /* The following assertion will fail if a service routine (ISR) for
  405. an interrupt that has been assigned a priority above
  406. configMAX_SYSCALL_INTERRUPT_PRIORITY calls an ISR safe FreeRTOS API
  407. function. ISR safe FreeRTOS API functions must *only* be called
  408. from interrupts that have been assigned a priority at or below
  409. configMAX_SYSCALL_INTERRUPT_PRIORITY.
  410. Numerically low interrupt priority numbers represent logically high
  411. interrupt priorities, therefore the priority of the interrupt must
  412. be set to a value equal to or numerically *higher* than
  413. configMAX_SYSCALL_INTERRUPT_PRIORITY.
  414. FreeRTOS maintains separate thread and ISR API functions to ensure
  415. interrupt entry is as fast and simple as possible.
  416. The following links provide detailed information:
  417. http://www.freertos.org/RTOS-Cortex-M3-M4.html
  418. http://www.freertos.org/FAQHelp.html */
  419. configASSERT( portICCRPR_RUNNING_PRIORITY_REGISTER >= ( configMAX_API_CALL_INTERRUPT_PRIORITY << portPRIORITY_SHIFT ) );
  420. /* Priority grouping: The interrupt controller (GIC) allows the bits
  421. that define each interrupt's priority to be split between bits that
  422. define the interrupt's pre-emption priority bits and bits that define
  423. the interrupt's sub-priority. For simplicity all bits must be defined
  424. to be pre-emption priority bits. The following assertion will fail if
  425. this is not the case (if some bits represent a sub-priority).
  426. The priority grouping is configured by the GIC's binary point register
  427. (ICCBPR). Writting 0 to ICCBPR will ensure it is set to its lowest
  428. possible value (which may be above 0). */
  429. configASSERT( portICCBPR_BINARY_POINT_REGISTER <= portMAX_BINARY_POINT_VALUE );
  430. }
  431. #endif /* configASSERT_DEFINED */