Eric Ebert
/
CoOS
CoOS Demonstrator adapted to mbed Hardware.
serviceReq.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 serviceReq.c |
ericebert | 0:57690853989a | 4 | * @version V1.1.3 |
ericebert | 0:57690853989a | 5 | * @date 2010.04.26 |
ericebert | 0:57690853989a | 6 | * @brief servive request management implementation code of CooCox CoOS kernel. |
ericebert | 0:57690853989a | 7 | ******************************************************************************* |
ericebert | 0:57690853989a | 8 | * @copy |
ericebert | 0:57690853989a | 9 | * |
ericebert | 0:57690853989a | 10 | * INTERNAL FILE,DON'T PUBLIC. |
ericebert | 0:57690853989a | 11 | * |
ericebert | 0:57690853989a | 12 | * <h2><center>© COPYRIGHT 2009 CooCox </center></h2> |
ericebert | 0:57690853989a | 13 | ******************************************************************************* |
ericebert | 0:57690853989a | 14 | */ |
ericebert | 0:57690853989a | 15 | |
ericebert | 0:57690853989a | 16 | |
ericebert | 0:57690853989a | 17 | |
ericebert | 0:57690853989a | 18 | /*---------------------------- Include ---------------------------------------*/ |
ericebert | 0:57690853989a | 19 | #include <coocox.h> |
ericebert | 0:57690853989a | 20 | |
ericebert | 0:57690853989a | 21 | #if (CFG_TASK_WAITTING_EN > 0) || (CFG_TMR_EN >0) |
ericebert | 0:57690853989a | 22 | |
ericebert | 0:57690853989a | 23 | #if CFG_MAX_SERVICE_REQUEST > 0 |
ericebert | 0:57690853989a | 24 | /*---------------------------- Variable Define -------------------------------*/ |
ericebert | 0:57690853989a | 25 | SRQ ServiceReq = {0,0}; /*!< ISR server request queue */ |
ericebert | 0:57690853989a | 26 | #endif |
ericebert | 0:57690853989a | 27 | BOOL IsrReq = FALSE; |
ericebert | 0:57690853989a | 28 | #if (CFG_TASK_WAITTING_EN > 0) |
ericebert | 0:57690853989a | 29 | BOOL TimeReq = FALSE; /*!< Time delay dispose request */ |
ericebert | 0:57690853989a | 30 | #endif |
ericebert | 0:57690853989a | 31 | |
ericebert | 0:57690853989a | 32 | #if CFG_TMR_EN > 0 |
ericebert | 0:57690853989a | 33 | BOOL TimerReq = FALSE; /*!< Timer dispose request */ |
ericebert | 0:57690853989a | 34 | #endif |
ericebert | 0:57690853989a | 35 | |
ericebert | 0:57690853989a | 36 | /** |
ericebert | 0:57690853989a | 37 | ******************************************************************************* |
ericebert | 0:57690853989a | 38 | * @brief Insert into service requst queue |
ericebert | 0:57690853989a | 39 | * @param[in] type Service request type. |
ericebert | 0:57690853989a | 40 | * @param[in] id Service request event id,event id/flag id. |
ericebert | 0:57690853989a | 41 | * @param[in] arg Service request argument. |
ericebert | 0:57690853989a | 42 | * @param[out] None |
ericebert | 0:57690853989a | 43 | * |
ericebert | 0:57690853989a | 44 | * @retval FALSE Successfully insert into service request queue. |
ericebert | 0:57690853989a | 45 | * @retval TRUE Failure to insert into service request queue. |
ericebert | 0:57690853989a | 46 | * |
ericebert | 0:57690853989a | 47 | * @par Description |
ericebert | 0:57690853989a | 48 | * @details This function be called to insert a requst into service request |
ericebert | 0:57690853989a | 49 | * queue. |
ericebert | 0:57690853989a | 50 | * @note |
ericebert | 0:57690853989a | 51 | ******************************************************************************* |
ericebert | 0:57690853989a | 52 | */ |
ericebert | 0:57690853989a | 53 | #if (CFG_MAX_SERVICE_REQUEST > 0) |
ericebert | 0:57690853989a | 54 | BOOL InsertInSRQ(U8 type,U8 id,void* arg) |
ericebert | 0:57690853989a | 55 | { |
ericebert | 0:57690853989a | 56 | P_SQC pcell; |
ericebert | 0:57690853989a | 57 | U8 cnt; |
ericebert | 0:57690853989a | 58 | U8 heed; |
ericebert | 0:57690853989a | 59 | IRQ_DISABLE_SAVE(); |
ericebert | 0:57690853989a | 60 | if (ServiceReq.cnt >= CFG_MAX_SERVICE_REQUEST) |
ericebert | 0:57690853989a | 61 | { |
ericebert | 0:57690853989a | 62 | IRQ_ENABLE_RESTORE (); |
ericebert | 0:57690853989a | 63 | |
ericebert | 0:57690853989a | 64 | return FALSE; /* Error return */ |
ericebert | 0:57690853989a | 65 | } |
ericebert | 0:57690853989a | 66 | cnt = Inc8(&ServiceReq.cnt); |
ericebert | 0:57690853989a | 67 | heed = ServiceReq.head; |
ericebert | 0:57690853989a | 68 | IsrReq = TRUE; |
ericebert | 0:57690853989a | 69 | pcell = &ServiceReq.cell[((cnt+heed)%CFG_MAX_SERVICE_REQUEST)];/*the tail */ |
ericebert | 0:57690853989a | 70 | pcell->type = type; /* Save service request type, */ |
ericebert | 0:57690853989a | 71 | pcell->id = id; /* event id */ |
ericebert | 0:57690853989a | 72 | pcell->arg = arg; /* and parameter */ |
ericebert | 0:57690853989a | 73 | IRQ_ENABLE_RESTORE (); |
ericebert | 0:57690853989a | 74 | |
ericebert | 0:57690853989a | 75 | return TRUE; /* Return OK */ |
ericebert | 0:57690853989a | 76 | } |
ericebert | 0:57690853989a | 77 | #endif |
ericebert | 0:57690853989a | 78 | |
ericebert | 0:57690853989a | 79 | |
ericebert | 0:57690853989a | 80 | |
ericebert | 0:57690853989a | 81 | /** |
ericebert | 0:57690853989a | 82 | ******************************************************************************* |
ericebert | 0:57690853989a | 83 | * @brief Respond the request in the service request queue. |
ericebert | 0:57690853989a | 84 | * @param[in] None |
ericebert | 0:57690853989a | 85 | * @param[out] None |
ericebert | 0:57690853989a | 86 | * @retval None |
ericebert | 0:57690853989a | 87 | * |
ericebert | 0:57690853989a | 88 | * @par Description |
ericebert | 0:57690853989a | 89 | * @details This function be called to respond the request in the service |
ericebert | 0:57690853989a | 90 | * request queue. |
ericebert | 0:57690853989a | 91 | * @note |
ericebert | 0:57690853989a | 92 | ******************************************************************************* |
ericebert | 0:57690853989a | 93 | */ |
ericebert | 0:57690853989a | 94 | void RespondSRQ(void) |
ericebert | 0:57690853989a | 95 | { |
ericebert | 0:57690853989a | 96 | |
ericebert | 0:57690853989a | 97 | #if CFG_MAX_SERVICE_REQUEST > 0 |
ericebert | 0:57690853989a | 98 | SQC cell; |
ericebert | 0:57690853989a | 99 | |
ericebert | 0:57690853989a | 100 | #endif |
ericebert | 0:57690853989a | 101 | |
ericebert | 0:57690853989a | 102 | #if (CFG_TASK_WAITTING_EN > 0) |
ericebert | 0:57690853989a | 103 | if(TimeReq == TRUE) /* Time delay request? */ |
ericebert | 0:57690853989a | 104 | { |
ericebert | 0:57690853989a | 105 | TimeDispose(); /* Yes,call handler */ |
ericebert | 0:57690853989a | 106 | TimeReq = FALSE; /* Reset time delay request false */ |
ericebert | 0:57690853989a | 107 | } |
ericebert | 0:57690853989a | 108 | #endif |
ericebert | 0:57690853989a | 109 | #if CFG_TMR_EN > 0 |
ericebert | 0:57690853989a | 110 | if(TimerReq == TRUE) /* Timer request? */ |
ericebert | 0:57690853989a | 111 | { |
ericebert | 0:57690853989a | 112 | TmrDispose(); /* Yes,call handler */ |
ericebert | 0:57690853989a | 113 | TimerReq = FALSE; /* Reset timer request false */ |
ericebert | 0:57690853989a | 114 | } |
ericebert | 0:57690853989a | 115 | #endif |
ericebert | 0:57690853989a | 116 | |
ericebert | 0:57690853989a | 117 | #if CFG_MAX_SERVICE_REQUEST > 0 |
ericebert | 0:57690853989a | 118 | |
ericebert | 0:57690853989a | 119 | while (ServiceReq.cnt != 0) |
ericebert | 0:57690853989a | 120 | { |
ericebert | 0:57690853989a | 121 | IRQ_DISABLE_SAVE (); /* need to protect the following */ |
ericebert | 0:57690853989a | 122 | cell = ServiceReq.cell[ServiceReq.head]; /* extract one cell */ |
ericebert | 0:57690853989a | 123 | ServiceReq.head = (ServiceReq.head + 1) % /* move head (pop) */ |
ericebert | 0:57690853989a | 124 | CFG_MAX_SERVICE_REQUEST; |
ericebert | 0:57690853989a | 125 | ServiceReq.cnt--; |
ericebert | 0:57690853989a | 126 | IRQ_ENABLE_RESTORE (); /* now use the cell copy */ |
ericebert | 0:57690853989a | 127 | |
ericebert | 0:57690853989a | 128 | switch(cell.type) /* Judge service request type */ |
ericebert | 0:57690853989a | 129 | { |
ericebert | 0:57690853989a | 130 | #if CFG_SEM_EN > 0 |
ericebert | 0:57690853989a | 131 | case SEM_REQ: /* Semaphore post request,call handler*/ |
ericebert | 0:57690853989a | 132 | CoPostSem(cell.id); |
ericebert | 0:57690853989a | 133 | break; |
ericebert | 0:57690853989a | 134 | #endif |
ericebert | 0:57690853989a | 135 | #if CFG_MAILBOX_EN > 0 |
ericebert | 0:57690853989a | 136 | case MBOX_REQ: /* Mailbox post request,call handler */ |
ericebert | 0:57690853989a | 137 | CoPostMail(cell.id, cell.arg); |
ericebert | 0:57690853989a | 138 | break; |
ericebert | 0:57690853989a | 139 | #endif |
ericebert | 0:57690853989a | 140 | #if CFG_FLAG_EN > 0 |
ericebert | 0:57690853989a | 141 | case FLAG_REQ: /* Flag set request,call handler */ |
ericebert | 0:57690853989a | 142 | CoSetFlag(cell.id); |
ericebert | 0:57690853989a | 143 | break; |
ericebert | 0:57690853989a | 144 | #endif |
ericebert | 0:57690853989a | 145 | #if CFG_QUEUE_EN > 0 |
ericebert | 0:57690853989a | 146 | case QUEUE_REQ: /* Queue post request,call handler */ |
ericebert | 0:57690853989a | 147 | CoPostQueueMail(cell.id, cell.arg); |
ericebert | 0:57690853989a | 148 | break; |
ericebert | 0:57690853989a | 149 | #endif |
ericebert | 0:57690853989a | 150 | default: /* Others,break */ |
ericebert | 0:57690853989a | 151 | break; |
ericebert | 0:57690853989a | 152 | } |
ericebert | 0:57690853989a | 153 | } |
ericebert | 0:57690853989a | 154 | #endif |
ericebert | 0:57690853989a | 155 | IRQ_DISABLE_SAVE (); /* need to protect the following */ |
ericebert | 0:57690853989a | 156 | |
ericebert | 0:57690853989a | 157 | if (ServiceReq.cnt == 0) /* another item in the queue already? */ |
ericebert | 0:57690853989a | 158 | { |
ericebert | 0:57690853989a | 159 | IsrReq = FALSE; /* queue still empty here */ |
ericebert | 0:57690853989a | 160 | } |
ericebert | 0:57690853989a | 161 | IRQ_ENABLE_RESTORE (); /* now it is done and return */ |
ericebert | 0:57690853989a | 162 | } |
ericebert | 0:57690853989a | 163 | |
ericebert | 0:57690853989a | 164 | #endif |
ericebert | 0:57690853989a | 165 |