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