2 * Copyright (C) 2017 C-SKY Microsystems Co., Ltd. All rights reserved.
4 * Permission is hereby granted, free of charge, to any person obtaining a copy of
5 * this software and associated documentation files (the "Software"), to deal in
6 * the Software without restriction, including without limitation the rights to
7 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
8 * the Software, and to permit persons to whom the Software is furnished to do so,
9 * subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in all
12 * copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
16 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
17 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
18 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 /* Kernel includes. */
28 extern void vPortStartTask(void);
30 /* Used to keep track of the number of nested calls to taskENTER_CRITICAL(). This
31 will be set to 0 prior to the first task being started. */
32 portLONG ulCriticalNesting = 0x9999UL;
34 /* Used to record one tack want to swtich task after enter critical area, we need know it
35 * and implement task switch after exit critical area */
36 portLONG pendsvflag = 0;
38 StackType_t *pxPortInitialiseStack( StackType_t * pxTopOfStack, TaskFunction_t pxCode, void *pvParameters )
40 StackType_t *stk = NULL;
44 *(--stk) = (uint32_t)pxCode; /* Entry Point */
45 *(--stk) = (uint32_t)0xE0000140L; /* PSR */
46 *(--stk) = (uint32_t)0xFFFFFFFEL; /* R15 (LR) (init value will cause fault if ever used) */
47 *(--stk) = (uint32_t)0x13131313L; /* R13 */
48 *(--stk) = (uint32_t)0x12121212L; /* R12 */
49 *(--stk) = (uint32_t)0x11111111L; /* R11 */
50 *(--stk) = (uint32_t)0x10101010L; /* R10 */
51 *(--stk) = (uint32_t)0x09090909L; /* R9 */
52 *(--stk) = (uint32_t)0x08080808L; /* R8 */
53 *(--stk) = (uint32_t)0x07070707L; /* R7 */
54 *(--stk) = (uint32_t)0x06060606L; /* R6 */
55 *(--stk) = (uint32_t)0x05050505L; /* R5 */
56 *(--stk) = (uint32_t)0x04040404L; /* R4 */
57 *(--stk) = (uint32_t)0x03030303L; /* R3 */
58 *(--stk) = (uint32_t)0x02020202L; /* R2 */
59 *(--stk) = (uint32_t)0x01010101L; /* R1 */
60 *(--stk) = (uint32_t)pvParameters; /* R0 : argument */
65 BaseType_t xPortStartScheduler( void )
67 ulCriticalNesting = 0UL;
75 void vPortEndScheduler( void )
77 /* Not implemented as there is nothing to return to. */
80 void vPortEnterCritical( void )
82 portDISABLE_INTERRUPTS();
86 void vPortExitCritical( void )
88 if (ulCriticalNesting == 0) {
93 if (ulCriticalNesting == 0)
95 portENABLE_INTERRUPTS();
105 #if configUSE_PREEMPTION == 0
106 void xPortSysTickHandler( void )
110 ulDummy = portSET_INTERRUPT_MASK_FROM_ISR();
111 xTaskIncrementTick();
112 portCLEAR_INTERRUPT_MASK_FROM_ISR( ulDummy );
116 void xPortSysTickHandler( void )
120 ulDummy = portSET_INTERRUPT_MASK_FROM_ISR();
122 if (xTaskIncrementTick() != pdFALSE)
124 portYIELD_FROM_ISR(pdTRUE);
127 portCLEAR_INTERRUPT_MASK_FROM_ISR( ulDummy );
131 void vPortYieldHandler( void )
133 uint32_t ulSavedInterruptMask;
135 ulSavedInterruptMask = portSET_INTERRUPT_MASK_FROM_ISR();
137 vTaskSwitchContext();
139 portCLEAR_INTERRUPT_MASK_FROM_ISR( ulSavedInterruptMask );
142 __attribute__((weak)) void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed portCHAR *pcTaskName )
147 __attribute__((weak)) void vApplicationMallocFailedHook( void )