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