Quick and dirty CoOS + LWIP ( Webserver )

Dependencies:   mbed lwip

Committer:
astroboy
Date:
Sat Sep 10 22:41:10 2011 +0000
Revision:
0:94897d537b31

        

Who changed what in which revision?

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