![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Quick and dirty CoOS + LWIP ( Webserver )
CoOS/portable/arch.c@0:94897d537b31, 2011-09-10 (annotated)
- Committer:
- astroboy
- Date:
- Sat Sep 10 22:41:10 2011 +0000
- Revision:
- 0:94897d537b31
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
astroboy | 0:94897d537b31 | 1 | /** |
astroboy | 0:94897d537b31 | 2 | ******************************************************************************* |
astroboy | 0:94897d537b31 | 3 | * @file arch.c |
astroboy | 0:94897d537b31 | 4 | * @version V1.1.4 |
astroboy | 0:94897d537b31 | 5 | * @date 2011.04.20 |
astroboy | 0:94897d537b31 | 6 | * @brief This file provides InitTaskContext() and SysTick_Handler(). |
astroboy | 0:94897d537b31 | 7 | ******************************************************************************* |
astroboy | 0:94897d537b31 | 8 | * @copy |
astroboy | 0:94897d537b31 | 9 | * WRITE COPY INFORMATION USE CAPITAL LETTER |
astroboy | 0:94897d537b31 | 10 | * |
astroboy | 0:94897d537b31 | 11 | * <h2><center>© COPYRIGHT 2009 CooCox </center></h2> |
astroboy | 0:94897d537b31 | 12 | ******************************************************************************* |
astroboy | 0:94897d537b31 | 13 | */ |
astroboy | 0:94897d537b31 | 14 | |
astroboy | 0:94897d537b31 | 15 | /*---------------------------- Include ---------------------------------------*/ |
astroboy | 0:94897d537b31 | 16 | #include <coocox.h> |
astroboy | 0:94897d537b31 | 17 | U64 OSTickCnt = 0; /*!< Current system tick counter */ |
astroboy | 0:94897d537b31 | 18 | |
astroboy | 0:94897d537b31 | 19 | /** |
astroboy | 0:94897d537b31 | 20 | ****************************************************************************** |
astroboy | 0:94897d537b31 | 21 | * @brief Initial task context |
astroboy | 0:94897d537b31 | 22 | * @param[in] task Entry point of task. |
astroboy | 0:94897d537b31 | 23 | * @param[in] param The parameter pass to task. |
astroboy | 0:94897d537b31 | 24 | * @param[in] pstk The pointer to stack top. |
astroboy | 0:94897d537b31 | 25 | * @param[out] None |
astroboy | 0:94897d537b31 | 26 | * @retval Returns location of new stack top. |
astroboy | 0:94897d537b31 | 27 | * |
astroboy | 0:94897d537b31 | 28 | * @par Description |
astroboy | 0:94897d537b31 | 29 | * @details This function is called to initialize the stack frame of the |
astroboy | 0:94897d537b31 | 30 | * task being created. |
astroboy | 0:94897d537b31 | 31 | ****************************************************************************** |
astroboy | 0:94897d537b31 | 32 | */ |
astroboy | 0:94897d537b31 | 33 | OS_STK *InitTaskContext(FUNCPtr task,void *param,OS_STK *pstk) |
astroboy | 0:94897d537b31 | 34 | { |
astroboy | 0:94897d537b31 | 35 | OS_STK *context; |
astroboy | 0:94897d537b31 | 36 | context = pstk; |
astroboy | 0:94897d537b31 | 37 | *(context--) = (U32)0x01000000L; /* xPSR */ |
astroboy | 0:94897d537b31 | 38 | *(context--) = (U32)task; /* Entry point of task. */ |
astroboy | 0:94897d537b31 | 39 | *(context) = (U32)0xFFFFFFFEL; |
astroboy | 0:94897d537b31 | 40 | context = context - 5; |
astroboy | 0:94897d537b31 | 41 | *(context) = (U32)param; /* R0: argument */ |
astroboy | 0:94897d537b31 | 42 | context = context - 8; |
astroboy | 0:94897d537b31 | 43 | |
astroboy | 0:94897d537b31 | 44 | return (context); /* Returns location of new stack top. */ |
astroboy | 0:94897d537b31 | 45 | } |
astroboy | 0:94897d537b31 | 46 | |
astroboy | 0:94897d537b31 | 47 | |
astroboy | 0:94897d537b31 | 48 | |
astroboy | 0:94897d537b31 | 49 | /** |
astroboy | 0:94897d537b31 | 50 | ******************************************************************************* |
astroboy | 0:94897d537b31 | 51 | * @brief System tick interrupt handler. |
astroboy | 0:94897d537b31 | 52 | * @param[in] None |
astroboy | 0:94897d537b31 | 53 | * @param[out] None |
astroboy | 0:94897d537b31 | 54 | * @retval None |
astroboy | 0:94897d537b31 | 55 | * |
astroboy | 0:94897d537b31 | 56 | * @par Description |
astroboy | 0:94897d537b31 | 57 | * @details This is system tick interrupt headler. |
astroboy | 0:94897d537b31 | 58 | * @note CoOS may schedule when exiting this ISR. |
astroboy | 0:94897d537b31 | 59 | ******************************************************************************* |
astroboy | 0:94897d537b31 | 60 | */ |
astroboy | 0:94897d537b31 | 61 | extern "C" void SysTick_Handler(void) |
astroboy | 0:94897d537b31 | 62 | { |
astroboy | 0:94897d537b31 | 63 | OSSchedLock++; /* Lock scheduler. */ |
astroboy | 0:94897d537b31 | 64 | OSTickCnt++; /* Increment systerm time. */ |
astroboy | 0:94897d537b31 | 65 | #if CFG_TASK_WAITTING_EN >0 |
astroboy | 0:94897d537b31 | 66 | if(DlyList != Co_NULL) /* Have task in delay list? */ |
astroboy | 0:94897d537b31 | 67 | { |
astroboy | 0:94897d537b31 | 68 | if(DlyList->delayTick > 1) /* Delay time > 1? */ |
astroboy | 0:94897d537b31 | 69 | { |
astroboy | 0:94897d537b31 | 70 | DlyList->delayTick--; /* Decrease delay time of the list head. */ |
astroboy | 0:94897d537b31 | 71 | } |
astroboy | 0:94897d537b31 | 72 | else |
astroboy | 0:94897d537b31 | 73 | { |
astroboy | 0:94897d537b31 | 74 | DlyList->delayTick = 0; |
astroboy | 0:94897d537b31 | 75 | isr_TimeDispose(); /* Call hander for delay time list */ |
astroboy | 0:94897d537b31 | 76 | } |
astroboy | 0:94897d537b31 | 77 | } |
astroboy | 0:94897d537b31 | 78 | #endif |
astroboy | 0:94897d537b31 | 79 | |
astroboy | 0:94897d537b31 | 80 | #if CFG_TMR_EN > 0 |
astroboy | 0:94897d537b31 | 81 | if(TmrList != Co_NULL) /* Have timer in working? */ |
astroboy | 0:94897d537b31 | 82 | { |
astroboy | 0:94897d537b31 | 83 | if(TmrList->tmrCnt > 1) /* Timer time > 1? */ |
astroboy | 0:94897d537b31 | 84 | { |
astroboy | 0:94897d537b31 | 85 | TmrList->tmrCnt--; /* Decrease timer time of the list head. */ |
astroboy | 0:94897d537b31 | 86 | } |
astroboy | 0:94897d537b31 | 87 | else |
astroboy | 0:94897d537b31 | 88 | { |
astroboy | 0:94897d537b31 | 89 | TmrList->tmrCnt = 0; |
astroboy | 0:94897d537b31 | 90 | isr_TmrDispose(); /* Call hander for timer list */ |
astroboy | 0:94897d537b31 | 91 | } |
astroboy | 0:94897d537b31 | 92 | } |
astroboy | 0:94897d537b31 | 93 | #endif |
astroboy | 0:94897d537b31 | 94 | TaskSchedReq = Co_TRUE; |
astroboy | 0:94897d537b31 | 95 | OsSchedUnlock(); |
astroboy | 0:94897d537b31 | 96 | } |