|
| 1 | +/** |
| 2 | + ******************************************************************************* |
| 3 | + * @file arch.c |
| 4 | + * @version V1.1.6 |
| 5 | + * @date 2014.05.23 |
| 6 | + * @brief This file provides InitTaskContext() and SysTick_Handler(). |
| 7 | + ******************************************************************************* |
| 8 | + * @copy |
| 9 | + * Redistribution and use in source and binary forms, with or without |
| 10 | + * modification, are permitted provided that the following conditions |
| 11 | + * are met: |
| 12 | + * |
| 13 | + * * Redistributions of source code must retain the above copyright |
| 14 | + * notice, this list of conditions and the following disclaimer. |
| 15 | + * * Redistributions in binary form must reproduce the above copyright |
| 16 | + * notice, this list of conditions and the following disclaimer in the |
| 17 | + * documentation and/or other materials provided with the distribution. |
| 18 | + * * Neither the name of the <ORGANIZATION> nor the names of its |
| 19 | + * contributors may be used to endorse or promote products derived |
| 20 | + * from this software without specific prior written permission. |
| 21 | + * |
| 22 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 23 | + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 24 | + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 25 | + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
| 26 | + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 27 | + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 28 | + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 29 | + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 30 | + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 31 | + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
| 32 | + * THE POSSIBILITY OF SUCH DAMAGE. |
| 33 | + * |
| 34 | + * <h2><center>© COPYRIGHT 2014 CooCox </center></h2> |
| 35 | + ******************************************************************************* |
| 36 | + */ |
| 37 | + |
| 38 | +/*---------------------------- Include ---------------------------------------*/ |
| 39 | +#include <coocox.h> |
| 40 | +U64 OSTickCnt = 0; /*!< Current system tick counter */ |
| 41 | + |
| 42 | +/** |
| 43 | + ****************************************************************************** |
| 44 | + * @brief Initial task context |
| 45 | + * @param[in] task Entry point of task. |
| 46 | + * @param[in] param The parameter pass to task. |
| 47 | + * @param[in] pstk The pointer to stack top. |
| 48 | + * @param[out] None |
| 49 | + * @retval Returns location of new stack top. |
| 50 | + * |
| 51 | + * @par Description |
| 52 | + * @details This function is called to initialize the stack frame of the |
| 53 | + * task being created. |
| 54 | + ****************************************************************************** |
| 55 | + */ |
| 56 | +OS_STK *InitTaskContext(FUNCPtr task,void *param,OS_STK *pstk) |
| 57 | +{ |
| 58 | + OS_STK *context; |
| 59 | + context = pstk; |
| 60 | +#if CFG_CHIP_TYPE == 3 |
| 61 | + context = context - 18; |
| 62 | +#endif |
| 63 | + *(context--) = (U32)0x01000000L; /* xPSR */ |
| 64 | + *(context--) = (U32)task; /* Entry point of task. */ |
| 65 | + *(context) = (U32)0xFFFFFFFEL; |
| 66 | + context = context - 5; |
| 67 | + *(context) = (U32)param; /* R0: argument */ |
| 68 | + context = context - 8; |
| 69 | +#if CFG_CHIP_TYPE == 3 |
| 70 | + context = context - 16; |
| 71 | +#endif |
| 72 | +// *(--context) = 0xfffffffd; /* LR */ |
| 73 | + |
| 74 | + return (context); /* Returns location of new stack top. */ |
| 75 | +} |
| 76 | + |
| 77 | + |
| 78 | + |
| 79 | +/** |
| 80 | + ******************************************************************************* |
| 81 | + * @brief System tick interrupt handler. |
| 82 | + * @param[in] None |
| 83 | + * @param[out] None |
| 84 | + * @retval None |
| 85 | + * |
| 86 | + * @par Description |
| 87 | + * @details This is system tick interrupt headler. |
| 88 | + * @note CoOS may schedule when exiting this ISR. |
| 89 | + ******************************************************************************* |
| 90 | + */ |
| 91 | +void CoSysTick_Handler(void) |
| 92 | +{ |
| 93 | + OSSchedLock++; /* Lock scheduler. */ |
| 94 | + OSTickCnt++; /* Increment systerm time. */ |
| 95 | +#if CFG_TASK_WAITTING_EN >0 |
| 96 | + if(DlyList != Co_NULL) /* Have task in delay list? */ |
| 97 | + { |
| 98 | + if(DlyList->delayTick > 1) /* Delay time > 1? */ |
| 99 | + { |
| 100 | + DlyList->delayTick--; /* Decrease delay time of the list head. */ |
| 101 | + } |
| 102 | + else |
| 103 | + { |
| 104 | + DlyList->delayTick = 0; |
| 105 | + isr_TimeDispose(); /* Call hander for delay time list */ |
| 106 | + } |
| 107 | + } |
| 108 | +#endif |
| 109 | + |
| 110 | +#if CFG_TMR_EN > 0 |
| 111 | + if(TmrList != Co_NULL) /* Have timer in working? */ |
| 112 | + { |
| 113 | + if(TmrList->tmrCnt > 1) /* Timer time > 1? */ |
| 114 | + { |
| 115 | + TmrList->tmrCnt--; /* Decrease timer time of the list head. */ |
| 116 | + } |
| 117 | + else |
| 118 | + { |
| 119 | + TmrList->tmrCnt = 0; |
| 120 | + isr_TmrDispose(); /* Call hander for timer list */ |
| 121 | + } |
| 122 | + } |
| 123 | +#endif |
| 124 | + TaskSchedReq = Co_TRUE; |
| 125 | + OsSchedUnlock(); |
| 126 | +} |
0 commit comments