the changes on the rtos to adapt the wifi

Fork of mbed-rtos by mbed official

Committer:
emilmont
Date:
Tue Apr 30 10:51:19 2013 +0000
Revision:
11:db1fc233faa9
Parent:
6:350b53afb889
Child:
31:015df9e602b6
In the Keil MDK toolchain "RTX_Config.h" is a special system library header file

Who changed what in which revision?

UserRevisionLine numberNew contents of line
emilmont 6:350b53afb889 1 /*----------------------------------------------------------------------------
emilmont 6:350b53afb889 2 * RL-ARM - RTX
emilmont 6:350b53afb889 3 *----------------------------------------------------------------------------
emilmont 6:350b53afb889 4 * Name: RT_LIST.C
emilmont 6:350b53afb889 5 * Purpose: Functions for the management of different lists
emilmont 6:350b53afb889 6 * Rev.: V4.60
emilmont 6:350b53afb889 7 *----------------------------------------------------------------------------
emilmont 6:350b53afb889 8 *
emilmont 6:350b53afb889 9 * Copyright (c) 1999-2009 KEIL, 2009-2012 ARM Germany GmbH
emilmont 6:350b53afb889 10 * All rights reserved.
emilmont 6:350b53afb889 11 * Redistribution and use in source and binary forms, with or without
emilmont 6:350b53afb889 12 * modification, are permitted provided that the following conditions are met:
emilmont 6:350b53afb889 13 * - Redistributions of source code must retain the above copyright
emilmont 6:350b53afb889 14 * notice, this list of conditions and the following disclaimer.
emilmont 6:350b53afb889 15 * - Redistributions in binary form must reproduce the above copyright
emilmont 6:350b53afb889 16 * notice, this list of conditions and the following disclaimer in the
emilmont 6:350b53afb889 17 * documentation and/or other materials provided with the distribution.
emilmont 6:350b53afb889 18 * - Neither the name of ARM nor the names of its contributors may be used
emilmont 6:350b53afb889 19 * to endorse or promote products derived from this software without
emilmont 6:350b53afb889 20 * specific prior written permission.
emilmont 6:350b53afb889 21 *
emilmont 6:350b53afb889 22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
emilmont 6:350b53afb889 23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
emilmont 6:350b53afb889 24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
emilmont 6:350b53afb889 25 * ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
emilmont 6:350b53afb889 26 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
emilmont 6:350b53afb889 27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
emilmont 6:350b53afb889 28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
emilmont 6:350b53afb889 29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
emilmont 6:350b53afb889 30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
emilmont 6:350b53afb889 31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
emilmont 6:350b53afb889 32 * POSSIBILITY OF SUCH DAMAGE.
emilmont 6:350b53afb889 33 *---------------------------------------------------------------------------*/
emilmont 6:350b53afb889 34
emilmont 6:350b53afb889 35 #include "rt_TypeDef.h"
emilmont 11:db1fc233faa9 36 #include "RTX_Conf.h"
emilmont 6:350b53afb889 37 #include "rt_System.h"
emilmont 6:350b53afb889 38 #include "rt_List.h"
emilmont 6:350b53afb889 39 #include "rt_Task.h"
emilmont 6:350b53afb889 40 #include "rt_Time.h"
emilmont 6:350b53afb889 41 #include "rt_HAL_CM.h"
emilmont 6:350b53afb889 42
emilmont 6:350b53afb889 43 /*----------------------------------------------------------------------------
emilmont 6:350b53afb889 44 * Global Variables
emilmont 6:350b53afb889 45 *---------------------------------------------------------------------------*/
emilmont 6:350b53afb889 46
emilmont 6:350b53afb889 47 /* List head of chained ready tasks */
emilmont 6:350b53afb889 48 struct OS_XCB os_rdy;
emilmont 6:350b53afb889 49 /* List head of chained delay tasks */
emilmont 6:350b53afb889 50 struct OS_XCB os_dly;
emilmont 6:350b53afb889 51
emilmont 6:350b53afb889 52
emilmont 6:350b53afb889 53 /*----------------------------------------------------------------------------
emilmont 6:350b53afb889 54 * Functions
emilmont 6:350b53afb889 55 *---------------------------------------------------------------------------*/
emilmont 6:350b53afb889 56
emilmont 6:350b53afb889 57
emilmont 6:350b53afb889 58 /*--------------------------- rt_put_prio -----------------------------------*/
emilmont 6:350b53afb889 59
emilmont 6:350b53afb889 60 void rt_put_prio (P_XCB p_CB, P_TCB p_task) {
emilmont 6:350b53afb889 61 /* Put task identified with "p_task" into list ordered by priority. */
emilmont 6:350b53afb889 62 /* "p_CB" points to head of list; list has always an element at end with */
emilmont 6:350b53afb889 63 /* a priority less than "p_task->prio". */
emilmont 6:350b53afb889 64 P_TCB p_CB2;
emilmont 6:350b53afb889 65 U32 prio;
emilmont 6:350b53afb889 66 BOOL sem_mbx = __FALSE;
emilmont 6:350b53afb889 67
emilmont 6:350b53afb889 68 if (p_CB->cb_type == SCB || p_CB->cb_type == MCB || p_CB->cb_type == MUCB) {
emilmont 6:350b53afb889 69 sem_mbx = __TRUE;
emilmont 6:350b53afb889 70 }
emilmont 6:350b53afb889 71 prio = p_task->prio;
emilmont 6:350b53afb889 72 p_CB2 = p_CB->p_lnk;
emilmont 6:350b53afb889 73 /* Search for an entry in the list */
emilmont 6:350b53afb889 74 while (p_CB2 != NULL && prio <= p_CB2->prio) {
emilmont 6:350b53afb889 75 p_CB = (P_XCB)p_CB2;
emilmont 6:350b53afb889 76 p_CB2 = p_CB2->p_lnk;
emilmont 6:350b53afb889 77 }
emilmont 6:350b53afb889 78 /* Entry found, insert the task into the list */
emilmont 6:350b53afb889 79 p_task->p_lnk = p_CB2;
emilmont 6:350b53afb889 80 p_CB->p_lnk = p_task;
emilmont 6:350b53afb889 81 if (sem_mbx) {
emilmont 6:350b53afb889 82 if (p_CB2 != NULL) {
emilmont 6:350b53afb889 83 p_CB2->p_rlnk = p_task;
emilmont 6:350b53afb889 84 }
emilmont 6:350b53afb889 85 p_task->p_rlnk = (P_TCB)p_CB;
emilmont 6:350b53afb889 86 }
emilmont 6:350b53afb889 87 else {
emilmont 6:350b53afb889 88 p_task->p_rlnk = NULL;
emilmont 6:350b53afb889 89 }
emilmont 6:350b53afb889 90 }
emilmont 6:350b53afb889 91
emilmont 6:350b53afb889 92
emilmont 6:350b53afb889 93 /*--------------------------- rt_get_first ----------------------------------*/
emilmont 6:350b53afb889 94
emilmont 6:350b53afb889 95 P_TCB rt_get_first (P_XCB p_CB) {
emilmont 6:350b53afb889 96 /* Get task at head of list: it is the task with highest priority. */
emilmont 6:350b53afb889 97 /* "p_CB" points to head of list. */
emilmont 6:350b53afb889 98 P_TCB p_first;
emilmont 6:350b53afb889 99
emilmont 6:350b53afb889 100 p_first = p_CB->p_lnk;
emilmont 6:350b53afb889 101 p_CB->p_lnk = p_first->p_lnk;
emilmont 6:350b53afb889 102 if (p_CB->cb_type == SCB || p_CB->cb_type == MCB || p_CB->cb_type == MUCB) {
emilmont 6:350b53afb889 103 if (p_first->p_lnk != NULL) {
emilmont 6:350b53afb889 104 p_first->p_lnk->p_rlnk = (P_TCB)p_CB;
emilmont 6:350b53afb889 105 p_first->p_lnk = NULL;
emilmont 6:350b53afb889 106 }
emilmont 6:350b53afb889 107 p_first->p_rlnk = NULL;
emilmont 6:350b53afb889 108 }
emilmont 6:350b53afb889 109 else {
emilmont 6:350b53afb889 110 p_first->p_lnk = NULL;
emilmont 6:350b53afb889 111 }
emilmont 6:350b53afb889 112 return (p_first);
emilmont 6:350b53afb889 113 }
emilmont 6:350b53afb889 114
emilmont 6:350b53afb889 115
emilmont 6:350b53afb889 116 /*--------------------------- rt_put_rdy_first ------------------------------*/
emilmont 6:350b53afb889 117
emilmont 6:350b53afb889 118 void rt_put_rdy_first (P_TCB p_task) {
emilmont 6:350b53afb889 119 /* Put task identified with "p_task" at the head of the ready list. The */
emilmont 6:350b53afb889 120 /* task must have at least a priority equal to highest priority in list. */
emilmont 6:350b53afb889 121 p_task->p_lnk = os_rdy.p_lnk;
emilmont 6:350b53afb889 122 p_task->p_rlnk = NULL;
emilmont 6:350b53afb889 123 os_rdy.p_lnk = p_task;
emilmont 6:350b53afb889 124 }
emilmont 6:350b53afb889 125
emilmont 6:350b53afb889 126
emilmont 6:350b53afb889 127 /*--------------------------- rt_get_same_rdy_prio --------------------------*/
emilmont 6:350b53afb889 128
emilmont 6:350b53afb889 129 P_TCB rt_get_same_rdy_prio (void) {
emilmont 6:350b53afb889 130 /* Remove a task of same priority from ready list if any exists. Other- */
emilmont 6:350b53afb889 131 /* wise return NULL. */
emilmont 6:350b53afb889 132 P_TCB p_first;
emilmont 6:350b53afb889 133
emilmont 6:350b53afb889 134 p_first = os_rdy.p_lnk;
emilmont 6:350b53afb889 135 if (p_first->prio == os_tsk.run->prio) {
emilmont 6:350b53afb889 136 os_rdy.p_lnk = os_rdy.p_lnk->p_lnk;
emilmont 6:350b53afb889 137 return (p_first);
emilmont 6:350b53afb889 138 }
emilmont 6:350b53afb889 139 return (NULL);
emilmont 6:350b53afb889 140 }
emilmont 6:350b53afb889 141
emilmont 6:350b53afb889 142
emilmont 6:350b53afb889 143 /*--------------------------- rt_resort_prio --------------------------------*/
emilmont 6:350b53afb889 144
emilmont 6:350b53afb889 145 void rt_resort_prio (P_TCB p_task) {
emilmont 6:350b53afb889 146 /* Re-sort ordered lists after the priority of 'p_task' has changed. */
emilmont 6:350b53afb889 147 P_TCB p_CB;
emilmont 6:350b53afb889 148
emilmont 6:350b53afb889 149 if (p_task->p_rlnk == NULL) {
emilmont 6:350b53afb889 150 if (p_task->state == READY) {
emilmont 6:350b53afb889 151 /* Task is chained into READY list. */
emilmont 6:350b53afb889 152 p_CB = (P_TCB)&os_rdy;
emilmont 6:350b53afb889 153 goto res;
emilmont 6:350b53afb889 154 }
emilmont 6:350b53afb889 155 }
emilmont 6:350b53afb889 156 else {
emilmont 6:350b53afb889 157 p_CB = p_task->p_rlnk;
emilmont 6:350b53afb889 158 while (p_CB->cb_type == TCB) {
emilmont 6:350b53afb889 159 /* Find a header of this task chain list. */
emilmont 6:350b53afb889 160 p_CB = p_CB->p_rlnk;
emilmont 6:350b53afb889 161 }
emilmont 6:350b53afb889 162 res:rt_rmv_list (p_task);
emilmont 6:350b53afb889 163 rt_put_prio ((P_XCB)p_CB, p_task);
emilmont 6:350b53afb889 164 }
emilmont 6:350b53afb889 165 }
emilmont 6:350b53afb889 166
emilmont 6:350b53afb889 167
emilmont 6:350b53afb889 168 /*--------------------------- rt_put_dly ------------------------------------*/
emilmont 6:350b53afb889 169
emilmont 6:350b53afb889 170 void rt_put_dly (P_TCB p_task, U16 delay) {
emilmont 6:350b53afb889 171 /* Put a task identified with "p_task" into chained delay wait list using */
emilmont 6:350b53afb889 172 /* a delay value of "delay". */
emilmont 6:350b53afb889 173 P_TCB p;
emilmont 6:350b53afb889 174 U32 delta,idelay = delay;
emilmont 6:350b53afb889 175
emilmont 6:350b53afb889 176 p = (P_TCB)&os_dly;
emilmont 6:350b53afb889 177 if (p->p_dlnk == NULL) {
emilmont 6:350b53afb889 178 /* Delay list empty */
emilmont 6:350b53afb889 179 delta = 0;
emilmont 6:350b53afb889 180 goto last;
emilmont 6:350b53afb889 181 }
emilmont 6:350b53afb889 182 delta = os_dly.delta_time;
emilmont 6:350b53afb889 183 while (delta < idelay) {
emilmont 6:350b53afb889 184 if (p->p_dlnk == NULL) {
emilmont 6:350b53afb889 185 /* End of list found */
emilmont 6:350b53afb889 186 last: p_task->p_dlnk = NULL;
emilmont 6:350b53afb889 187 p->p_dlnk = p_task;
emilmont 6:350b53afb889 188 p_task->p_blnk = p;
emilmont 6:350b53afb889 189 p->delta_time = (U16)(idelay - delta);
emilmont 6:350b53afb889 190 p_task->delta_time = 0;
emilmont 6:350b53afb889 191 return;
emilmont 6:350b53afb889 192 }
emilmont 6:350b53afb889 193 p = p->p_dlnk;
emilmont 6:350b53afb889 194 delta += p->delta_time;
emilmont 6:350b53afb889 195 }
emilmont 6:350b53afb889 196 /* Right place found */
emilmont 6:350b53afb889 197 p_task->p_dlnk = p->p_dlnk;
emilmont 6:350b53afb889 198 p->p_dlnk = p_task;
emilmont 6:350b53afb889 199 p_task->p_blnk = p;
emilmont 6:350b53afb889 200 if (p_task->p_dlnk != NULL) {
emilmont 6:350b53afb889 201 p_task->p_dlnk->p_blnk = p_task;
emilmont 6:350b53afb889 202 }
emilmont 6:350b53afb889 203 p_task->delta_time = (U16)(delta - idelay);
emilmont 6:350b53afb889 204 p->delta_time -= p_task->delta_time;
emilmont 6:350b53afb889 205 }
emilmont 6:350b53afb889 206
emilmont 6:350b53afb889 207
emilmont 6:350b53afb889 208 /*--------------------------- rt_dec_dly ------------------------------------*/
emilmont 6:350b53afb889 209
emilmont 6:350b53afb889 210 void rt_dec_dly (void) {
emilmont 6:350b53afb889 211 /* Decrement delta time of list head: remove tasks having a value of zero.*/
emilmont 6:350b53afb889 212 P_TCB p_rdy;
emilmont 6:350b53afb889 213
emilmont 6:350b53afb889 214 if (os_dly.p_dlnk == NULL) {
emilmont 6:350b53afb889 215 return;
emilmont 6:350b53afb889 216 }
emilmont 6:350b53afb889 217 os_dly.delta_time--;
emilmont 6:350b53afb889 218 while ((os_dly.delta_time == 0) && (os_dly.p_dlnk != NULL)) {
emilmont 6:350b53afb889 219 p_rdy = os_dly.p_dlnk;
emilmont 6:350b53afb889 220 if (p_rdy->p_rlnk != NULL) {
emilmont 6:350b53afb889 221 /* Task is really enqueued, remove task from semaphore/mailbox */
emilmont 6:350b53afb889 222 /* timeout waiting list. */
emilmont 6:350b53afb889 223 p_rdy->p_rlnk->p_lnk = p_rdy->p_lnk;
emilmont 6:350b53afb889 224 if (p_rdy->p_lnk != NULL) {
emilmont 6:350b53afb889 225 p_rdy->p_lnk->p_rlnk = p_rdy->p_rlnk;
emilmont 6:350b53afb889 226 p_rdy->p_lnk = NULL;
emilmont 6:350b53afb889 227 }
emilmont 6:350b53afb889 228 p_rdy->p_rlnk = NULL;
emilmont 6:350b53afb889 229 }
emilmont 6:350b53afb889 230 rt_put_prio (&os_rdy, p_rdy);
emilmont 6:350b53afb889 231 os_dly.delta_time = p_rdy->delta_time;
emilmont 6:350b53afb889 232 if (p_rdy->state == WAIT_ITV) {
emilmont 6:350b53afb889 233 /* Calculate the next time for interval wait. */
emilmont 6:350b53afb889 234 p_rdy->delta_time = p_rdy->interval_time + (U16)os_time;
emilmont 6:350b53afb889 235 }
emilmont 6:350b53afb889 236 p_rdy->state = READY;
emilmont 6:350b53afb889 237 os_dly.p_dlnk = p_rdy->p_dlnk;
emilmont 6:350b53afb889 238 if (p_rdy->p_dlnk != NULL) {
emilmont 6:350b53afb889 239 p_rdy->p_dlnk->p_blnk = (P_TCB)&os_dly;
emilmont 6:350b53afb889 240 p_rdy->p_dlnk = NULL;
emilmont 6:350b53afb889 241 }
emilmont 6:350b53afb889 242 p_rdy->p_blnk = NULL;
emilmont 6:350b53afb889 243 }
emilmont 6:350b53afb889 244 }
emilmont 6:350b53afb889 245
emilmont 6:350b53afb889 246
emilmont 6:350b53afb889 247 /*--------------------------- rt_rmv_list -----------------------------------*/
emilmont 6:350b53afb889 248
emilmont 6:350b53afb889 249 void rt_rmv_list (P_TCB p_task) {
emilmont 6:350b53afb889 250 /* Remove task identified with "p_task" from ready, semaphore or mailbox */
emilmont 6:350b53afb889 251 /* waiting list if enqueued. */
emilmont 6:350b53afb889 252 P_TCB p_b;
emilmont 6:350b53afb889 253
emilmont 6:350b53afb889 254 if (p_task->p_rlnk != NULL) {
emilmont 6:350b53afb889 255 /* A task is enqueued in semaphore / mailbox waiting list. */
emilmont 6:350b53afb889 256 p_task->p_rlnk->p_lnk = p_task->p_lnk;
emilmont 6:350b53afb889 257 if (p_task->p_lnk != NULL) {
emilmont 6:350b53afb889 258 p_task->p_lnk->p_rlnk = p_task->p_rlnk;
emilmont 6:350b53afb889 259 }
emilmont 6:350b53afb889 260 return;
emilmont 6:350b53afb889 261 }
emilmont 6:350b53afb889 262
emilmont 6:350b53afb889 263 p_b = (P_TCB)&os_rdy;
emilmont 6:350b53afb889 264 while (p_b != NULL) {
emilmont 6:350b53afb889 265 /* Search the ready list for task "p_task" */
emilmont 6:350b53afb889 266 if (p_b->p_lnk == p_task) {
emilmont 6:350b53afb889 267 p_b->p_lnk = p_task->p_lnk;
emilmont 6:350b53afb889 268 return;
emilmont 6:350b53afb889 269 }
emilmont 6:350b53afb889 270 p_b = p_b->p_lnk;
emilmont 6:350b53afb889 271 }
emilmont 6:350b53afb889 272 }
emilmont 6:350b53afb889 273
emilmont 6:350b53afb889 274
emilmont 6:350b53afb889 275 /*--------------------------- rt_rmv_dly ------------------------------------*/
emilmont 6:350b53afb889 276
emilmont 6:350b53afb889 277 void rt_rmv_dly (P_TCB p_task) {
emilmont 6:350b53afb889 278 /* Remove task identified with "p_task" from delay list if enqueued. */
emilmont 6:350b53afb889 279 P_TCB p_b;
emilmont 6:350b53afb889 280
emilmont 6:350b53afb889 281 p_b = p_task->p_blnk;
emilmont 6:350b53afb889 282 if (p_b != NULL) {
emilmont 6:350b53afb889 283 /* Task is really enqueued */
emilmont 6:350b53afb889 284 p_b->p_dlnk = p_task->p_dlnk;
emilmont 6:350b53afb889 285 if (p_task->p_dlnk != NULL) {
emilmont 6:350b53afb889 286 /* 'p_task' is in the middle of list */
emilmont 6:350b53afb889 287 p_b->delta_time += p_task->delta_time;
emilmont 6:350b53afb889 288 p_task->p_dlnk->p_blnk = p_b;
emilmont 6:350b53afb889 289 p_task->p_dlnk = NULL;
emilmont 6:350b53afb889 290 }
emilmont 6:350b53afb889 291 else {
emilmont 6:350b53afb889 292 /* 'p_task' is at the end of list */
emilmont 6:350b53afb889 293 p_b->delta_time = 0;
emilmont 6:350b53afb889 294 }
emilmont 6:350b53afb889 295 p_task->p_blnk = NULL;
emilmont 6:350b53afb889 296 }
emilmont 6:350b53afb889 297 }
emilmont 6:350b53afb889 298
emilmont 6:350b53afb889 299
emilmont 6:350b53afb889 300 /*--------------------------- rt_psq_enq ------------------------------------*/
emilmont 6:350b53afb889 301
emilmont 6:350b53afb889 302 void rt_psq_enq (OS_ID entry, U32 arg) {
emilmont 6:350b53afb889 303 /* Insert post service request "entry" into ps-queue. */
emilmont 6:350b53afb889 304 U32 idx;
emilmont 6:350b53afb889 305
emilmont 6:350b53afb889 306 idx = rt_inc_qi (os_psq->size, &os_psq->count, &os_psq->first);
emilmont 6:350b53afb889 307 if (idx < os_psq->size) {
emilmont 6:350b53afb889 308 os_psq->q[idx].id = entry;
emilmont 6:350b53afb889 309 os_psq->q[idx].arg = arg;
emilmont 6:350b53afb889 310 }
emilmont 6:350b53afb889 311 else {
emilmont 6:350b53afb889 312 os_error (OS_ERR_FIFO_OVF);
emilmont 6:350b53afb889 313 }
emilmont 6:350b53afb889 314 }
emilmont 6:350b53afb889 315
emilmont 6:350b53afb889 316
emilmont 6:350b53afb889 317 /*----------------------------------------------------------------------------
emilmont 6:350b53afb889 318 * end of file
emilmont 6:350b53afb889 319 *---------------------------------------------------------------------------*/
emilmont 6:350b53afb889 320