in OS_TSK, rename run as tsk_run and new as tsk_new.

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?

UserRevisionLine numberNew contents of line
jonathonfletcher 0:5f46ebd8588e 1 /*----------------------------------------------------------------------------
jonathonfletcher 0:5f46ebd8588e 2 * RL-ARM - RTX
jonathonfletcher 0:5f46ebd8588e 3 *----------------------------------------------------------------------------
jonathonfletcher 0:5f46ebd8588e 4 * Name: RT_TASK.C
jonathonfletcher 0:5f46ebd8588e 5 * Purpose: Task functions and system start up.
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_Task.h"
jonathonfletcher 0:5f46ebd8588e 39 #include "rt_List.h"
jonathonfletcher 0:5f46ebd8588e 40 #include "rt_MemBox.h"
jonathonfletcher 0:5f46ebd8588e 41 #include "rt_Robin.h"
jonathonfletcher 0:5f46ebd8588e 42 #include "rt_HAL_CM.h"
jonathonfletcher 0:5f46ebd8588e 43
jonathonfletcher 0:5f46ebd8588e 44 /*----------------------------------------------------------------------------
jonathonfletcher 0:5f46ebd8588e 45 * Global Variables
jonathonfletcher 0:5f46ebd8588e 46 *---------------------------------------------------------------------------*/
jonathonfletcher 0:5f46ebd8588e 47
jonathonfletcher 0:5f46ebd8588e 48 /* Running and next task info. */
jonathonfletcher 0:5f46ebd8588e 49 struct OS_TSK os_tsk;
jonathonfletcher 0:5f46ebd8588e 50
jonathonfletcher 0:5f46ebd8588e 51 /* Task Control Blocks of idle demon */
jonathonfletcher 0:5f46ebd8588e 52 struct OS_TCB os_idle_TCB;
jonathonfletcher 0:5f46ebd8588e 53
jonathonfletcher 0:5f46ebd8588e 54
jonathonfletcher 0:5f46ebd8588e 55 /*----------------------------------------------------------------------------
jonathonfletcher 0:5f46ebd8588e 56 * Local Functions
jonathonfletcher 0:5f46ebd8588e 57 *---------------------------------------------------------------------------*/
jonathonfletcher 0:5f46ebd8588e 58
jonathonfletcher 0:5f46ebd8588e 59 OS_TID rt_get_TID (void) {
jonathonfletcher 0:5f46ebd8588e 60 U32 tid;
jonathonfletcher 0:5f46ebd8588e 61
jonathonfletcher 0:5f46ebd8588e 62 for (tid = 1; tid <= os_maxtaskrun; tid++) {
jonathonfletcher 0:5f46ebd8588e 63 if (os_active_TCB[tid-1] == NULL) {
jonathonfletcher 0:5f46ebd8588e 64 return ((OS_TID)tid);
jonathonfletcher 0:5f46ebd8588e 65 }
jonathonfletcher 0:5f46ebd8588e 66 }
jonathonfletcher 0:5f46ebd8588e 67 return (0);
jonathonfletcher 0:5f46ebd8588e 68 }
jonathonfletcher 0:5f46ebd8588e 69
jonathonfletcher 0:5f46ebd8588e 70 #if defined (__CC_ARM) && !defined (__MICROLIB)
jonathonfletcher 0:5f46ebd8588e 71 /*--------------------------- __user_perthread_libspace ---------------------*/
jonathonfletcher 0:5f46ebd8588e 72 extern void *__libspace_start;
jonathonfletcher 0:5f46ebd8588e 73
jonathonfletcher 0:5f46ebd8588e 74 void *__user_perthread_libspace (void) {
jonathonfletcher 0:5f46ebd8588e 75 /* Provide a separate libspace for each task. */
jonathonfletcher 0:5f46ebd8588e 76 if (os_tsk.tsk_run == NULL) {
jonathonfletcher 0:5f46ebd8588e 77 /* RTX not running yet. */
jonathonfletcher 0:5f46ebd8588e 78 return (&__libspace_start);
jonathonfletcher 0:5f46ebd8588e 79 }
jonathonfletcher 0:5f46ebd8588e 80 return (void *)(os_tsk.tsk_run->std_libspace);
jonathonfletcher 0:5f46ebd8588e 81 }
jonathonfletcher 0:5f46ebd8588e 82 #endif
jonathonfletcher 0:5f46ebd8588e 83
jonathonfletcher 0:5f46ebd8588e 84 /*--------------------------- rt_init_context -------------------------------*/
jonathonfletcher 0:5f46ebd8588e 85
jonathonfletcher 0:5f46ebd8588e 86 void rt_init_context (P_TCB p_TCB, U8 priority, FUNCP task_body) {
jonathonfletcher 0:5f46ebd8588e 87 /* Initialize general part of the Task Control Block. */
jonathonfletcher 0:5f46ebd8588e 88 p_TCB->cb_type = TCB;
jonathonfletcher 0:5f46ebd8588e 89 p_TCB->state = READY;
jonathonfletcher 0:5f46ebd8588e 90 p_TCB->prio = priority;
jonathonfletcher 0:5f46ebd8588e 91 p_TCB->p_lnk = NULL;
jonathonfletcher 0:5f46ebd8588e 92 p_TCB->p_rlnk = NULL;
jonathonfletcher 0:5f46ebd8588e 93 p_TCB->p_dlnk = NULL;
jonathonfletcher 0:5f46ebd8588e 94 p_TCB->p_blnk = NULL;
jonathonfletcher 0:5f46ebd8588e 95 p_TCB->delta_time = 0;
jonathonfletcher 0:5f46ebd8588e 96 p_TCB->interval_time = 0;
jonathonfletcher 0:5f46ebd8588e 97 p_TCB->events = 0;
jonathonfletcher 0:5f46ebd8588e 98 p_TCB->waits = 0;
jonathonfletcher 0:5f46ebd8588e 99 p_TCB->stack_frame = 0;
jonathonfletcher 0:5f46ebd8588e 100
jonathonfletcher 0:5f46ebd8588e 101 rt_init_stack (p_TCB, task_body);
jonathonfletcher 0:5f46ebd8588e 102 }
jonathonfletcher 0:5f46ebd8588e 103
jonathonfletcher 0:5f46ebd8588e 104
jonathonfletcher 0:5f46ebd8588e 105 /*--------------------------- rt_switch_req ---------------------------------*/
jonathonfletcher 0:5f46ebd8588e 106
jonathonfletcher 0:5f46ebd8588e 107 void rt_switch_req (P_TCB p_new) {
jonathonfletcher 0:5f46ebd8588e 108 /* Switch to next task (identified by "p_new"). */
jonathonfletcher 0:5f46ebd8588e 109 os_tsk.tsk_new = p_new;
jonathonfletcher 0:5f46ebd8588e 110 p_new->state = RUNNING;
jonathonfletcher 0:5f46ebd8588e 111 DBG_TASK_SWITCH(p_new->task_id);
jonathonfletcher 0:5f46ebd8588e 112 }
jonathonfletcher 0:5f46ebd8588e 113
jonathonfletcher 0:5f46ebd8588e 114
jonathonfletcher 0:5f46ebd8588e 115 /*--------------------------- rt_dispatch -----------------------------------*/
jonathonfletcher 0:5f46ebd8588e 116
jonathonfletcher 0:5f46ebd8588e 117 void rt_dispatch (P_TCB next_TCB) {
jonathonfletcher 0:5f46ebd8588e 118 /* Dispatch next task if any identified or dispatch highest ready task */
jonathonfletcher 0:5f46ebd8588e 119 /* "next_TCB" identifies a task to run or has value NULL (=no next task) */
jonathonfletcher 0:5f46ebd8588e 120 if (next_TCB == NULL) {
jonathonfletcher 0:5f46ebd8588e 121 /* Running task was blocked: continue with highest ready task */
jonathonfletcher 0:5f46ebd8588e 122 next_TCB = rt_get_first (&os_rdy);
jonathonfletcher 0:5f46ebd8588e 123 rt_switch_req (next_TCB);
jonathonfletcher 0:5f46ebd8588e 124 }
jonathonfletcher 0:5f46ebd8588e 125 else {
jonathonfletcher 0:5f46ebd8588e 126 /* Check which task continues */
jonathonfletcher 0:5f46ebd8588e 127 if (next_TCB->prio > os_tsk.tsk_run->prio) {
jonathonfletcher 0:5f46ebd8588e 128 /* preempt running task */
jonathonfletcher 0:5f46ebd8588e 129 rt_put_rdy_first (os_tsk.tsk_run);
jonathonfletcher 0:5f46ebd8588e 130 os_tsk.tsk_run->state = READY;
jonathonfletcher 0:5f46ebd8588e 131 rt_switch_req (next_TCB);
jonathonfletcher 0:5f46ebd8588e 132 }
jonathonfletcher 0:5f46ebd8588e 133 else {
jonathonfletcher 0:5f46ebd8588e 134 /* put next task into ready list, no task switch takes place */
jonathonfletcher 0:5f46ebd8588e 135 next_TCB->state = READY;
jonathonfletcher 0:5f46ebd8588e 136 rt_put_prio (&os_rdy, next_TCB);
jonathonfletcher 0:5f46ebd8588e 137 }
jonathonfletcher 0:5f46ebd8588e 138 }
jonathonfletcher 0:5f46ebd8588e 139 }
jonathonfletcher 0:5f46ebd8588e 140
jonathonfletcher 0:5f46ebd8588e 141
jonathonfletcher 0:5f46ebd8588e 142 /*--------------------------- rt_block --------------------------------------*/
jonathonfletcher 0:5f46ebd8588e 143
jonathonfletcher 0:5f46ebd8588e 144 void rt_block (U16 timeout, U8 block_state) {
jonathonfletcher 0:5f46ebd8588e 145 /* Block running task and choose next ready task. */
jonathonfletcher 0:5f46ebd8588e 146 /* "timeout" sets a time-out value or is 0xffff (=no time-out). */
jonathonfletcher 0:5f46ebd8588e 147 /* "block_state" defines the appropriate task state */
jonathonfletcher 0:5f46ebd8588e 148 P_TCB next_TCB;
jonathonfletcher 0:5f46ebd8588e 149
jonathonfletcher 0:5f46ebd8588e 150 if (timeout) {
jonathonfletcher 0:5f46ebd8588e 151 if (timeout < 0xffff) {
jonathonfletcher 0:5f46ebd8588e 152 rt_put_dly (os_tsk.tsk_run, timeout);
jonathonfletcher 0:5f46ebd8588e 153 }
jonathonfletcher 0:5f46ebd8588e 154 os_tsk.tsk_run->state = block_state;
jonathonfletcher 0:5f46ebd8588e 155 next_TCB = rt_get_first (&os_rdy);
jonathonfletcher 0:5f46ebd8588e 156 rt_switch_req (next_TCB);
jonathonfletcher 0:5f46ebd8588e 157 }
jonathonfletcher 0:5f46ebd8588e 158 }
jonathonfletcher 0:5f46ebd8588e 159
jonathonfletcher 0:5f46ebd8588e 160
jonathonfletcher 0:5f46ebd8588e 161 /*--------------------------- rt_tsk_pass -----------------------------------*/
jonathonfletcher 0:5f46ebd8588e 162
jonathonfletcher 0:5f46ebd8588e 163 void rt_tsk_pass (void) {
jonathonfletcher 0:5f46ebd8588e 164 /* Allow tasks of same priority level to run cooperatively.*/
jonathonfletcher 0:5f46ebd8588e 165 P_TCB p_new;
jonathonfletcher 0:5f46ebd8588e 166
jonathonfletcher 0:5f46ebd8588e 167 p_new = rt_get_same_rdy_prio();
jonathonfletcher 0:5f46ebd8588e 168 if (p_new != NULL) {
jonathonfletcher 0:5f46ebd8588e 169 rt_put_prio ((P_XCB)&os_rdy, os_tsk.tsk_run);
jonathonfletcher 0:5f46ebd8588e 170 os_tsk.tsk_run->state = READY;
jonathonfletcher 0:5f46ebd8588e 171 rt_switch_req (p_new);
jonathonfletcher 0:5f46ebd8588e 172 }
jonathonfletcher 0:5f46ebd8588e 173 }
jonathonfletcher 0:5f46ebd8588e 174
jonathonfletcher 0:5f46ebd8588e 175
jonathonfletcher 0:5f46ebd8588e 176 /*--------------------------- rt_tsk_self -----------------------------------*/
jonathonfletcher 0:5f46ebd8588e 177
jonathonfletcher 0:5f46ebd8588e 178 OS_TID rt_tsk_self (void) {
jonathonfletcher 0:5f46ebd8588e 179 /* Return own task identifier value. */
jonathonfletcher 0:5f46ebd8588e 180 if (os_tsk.tsk_run == NULL) {
jonathonfletcher 0:5f46ebd8588e 181 return (0);
jonathonfletcher 0:5f46ebd8588e 182 }
jonathonfletcher 0:5f46ebd8588e 183 return (os_tsk.tsk_run->task_id);
jonathonfletcher 0:5f46ebd8588e 184 }
jonathonfletcher 0:5f46ebd8588e 185
jonathonfletcher 0:5f46ebd8588e 186
jonathonfletcher 0:5f46ebd8588e 187 /*--------------------------- rt_tsk_prio -----------------------------------*/
jonathonfletcher 0:5f46ebd8588e 188
jonathonfletcher 0:5f46ebd8588e 189 OS_RESULT rt_tsk_prio (OS_TID task_id, U8 new_prio) {
jonathonfletcher 0:5f46ebd8588e 190 /* Change execution priority of a task to "new_prio". */
jonathonfletcher 0:5f46ebd8588e 191 P_TCB p_task;
jonathonfletcher 0:5f46ebd8588e 192
jonathonfletcher 0:5f46ebd8588e 193 if (task_id == 0) {
jonathonfletcher 0:5f46ebd8588e 194 /* Change execution priority of calling task. */
jonathonfletcher 0:5f46ebd8588e 195 os_tsk.tsk_run->prio = new_prio;
jonathonfletcher 0:5f46ebd8588e 196 run:if (rt_rdy_prio() > new_prio) {
jonathonfletcher 0:5f46ebd8588e 197 rt_put_prio (&os_rdy, os_tsk.tsk_run);
jonathonfletcher 0:5f46ebd8588e 198 os_tsk.tsk_run->state = READY;
jonathonfletcher 0:5f46ebd8588e 199 rt_dispatch (NULL);
jonathonfletcher 0:5f46ebd8588e 200 }
jonathonfletcher 0:5f46ebd8588e 201 return (OS_R_OK);
jonathonfletcher 0:5f46ebd8588e 202 }
jonathonfletcher 0:5f46ebd8588e 203
jonathonfletcher 0:5f46ebd8588e 204 /* Find the task in the "os_active_TCB" array. */
jonathonfletcher 0:5f46ebd8588e 205 if (task_id > os_maxtaskrun || os_active_TCB[task_id-1] == NULL) {
jonathonfletcher 0:5f46ebd8588e 206 /* Task with "task_id" not found or not started. */
jonathonfletcher 0:5f46ebd8588e 207 return (OS_R_NOK);
jonathonfletcher 0:5f46ebd8588e 208 }
jonathonfletcher 0:5f46ebd8588e 209 p_task = os_active_TCB[task_id-1];
jonathonfletcher 0:5f46ebd8588e 210 p_task->prio = new_prio;
jonathonfletcher 0:5f46ebd8588e 211 if (p_task == os_tsk.tsk_run) {
jonathonfletcher 0:5f46ebd8588e 212 goto run;
jonathonfletcher 0:5f46ebd8588e 213 }
jonathonfletcher 0:5f46ebd8588e 214 rt_resort_prio (p_task);
jonathonfletcher 0:5f46ebd8588e 215 if (p_task->state == READY) {
jonathonfletcher 0:5f46ebd8588e 216 /* Task enqueued in a ready list. */
jonathonfletcher 0:5f46ebd8588e 217 p_task = rt_get_first (&os_rdy);
jonathonfletcher 0:5f46ebd8588e 218 rt_dispatch (p_task);
jonathonfletcher 0:5f46ebd8588e 219 }
jonathonfletcher 0:5f46ebd8588e 220 return (OS_R_OK);
jonathonfletcher 0:5f46ebd8588e 221 }
jonathonfletcher 0:5f46ebd8588e 222
jonathonfletcher 0:5f46ebd8588e 223 /*--------------------------- rt_tsk_delete ---------------------------------*/
jonathonfletcher 0:5f46ebd8588e 224
jonathonfletcher 0:5f46ebd8588e 225 OS_RESULT rt_tsk_delete (OS_TID task_id) {
jonathonfletcher 0:5f46ebd8588e 226 /* Terminate the task identified with "task_id". */
jonathonfletcher 0:5f46ebd8588e 227 P_TCB task_context;
jonathonfletcher 0:5f46ebd8588e 228
jonathonfletcher 0:5f46ebd8588e 229 if (task_id == 0 || task_id == os_tsk.tsk_run->task_id) {
jonathonfletcher 0:5f46ebd8588e 230 /* Terminate itself. */
jonathonfletcher 0:5f46ebd8588e 231 os_tsk.tsk_run->state = INACTIVE;
jonathonfletcher 0:5f46ebd8588e 232 os_tsk.tsk_run->tsk_stack = rt_get_PSP ();
jonathonfletcher 0:5f46ebd8588e 233 rt_stk_check ();
jonathonfletcher 0:5f46ebd8588e 234 os_active_TCB[os_tsk.tsk_run->task_id-1] = NULL;
jonathonfletcher 0:5f46ebd8588e 235
jonathonfletcher 0:5f46ebd8588e 236 os_tsk.tsk_run->stack = NULL;
jonathonfletcher 0:5f46ebd8588e 237 DBG_TASK_NOTIFY(os_tsk.run, __FALSE);
jonathonfletcher 0:5f46ebd8588e 238 os_tsk.tsk_run = NULL;
jonathonfletcher 0:5f46ebd8588e 239 rt_dispatch (NULL);
jonathonfletcher 0:5f46ebd8588e 240 /* The program should never come to this point. */
jonathonfletcher 0:5f46ebd8588e 241 }
jonathonfletcher 0:5f46ebd8588e 242 else {
jonathonfletcher 0:5f46ebd8588e 243 /* Find the task in the "os_active_TCB" array. */
jonathonfletcher 0:5f46ebd8588e 244 if (task_id > os_maxtaskrun || os_active_TCB[task_id-1] == NULL) {
jonathonfletcher 0:5f46ebd8588e 245 /* Task with "task_id" not found or not started. */
jonathonfletcher 0:5f46ebd8588e 246 return (OS_R_NOK);
jonathonfletcher 0:5f46ebd8588e 247 }
jonathonfletcher 0:5f46ebd8588e 248 task_context = os_active_TCB[task_id-1];
jonathonfletcher 0:5f46ebd8588e 249 rt_rmv_list (task_context);
jonathonfletcher 0:5f46ebd8588e 250 rt_rmv_dly (task_context);
jonathonfletcher 0:5f46ebd8588e 251 os_active_TCB[task_id-1] = NULL;
jonathonfletcher 0:5f46ebd8588e 252
jonathonfletcher 0:5f46ebd8588e 253 task_context->stack = NULL;
jonathonfletcher 0:5f46ebd8588e 254 DBG_TASK_NOTIFY(task_context, __FALSE);
jonathonfletcher 0:5f46ebd8588e 255 }
jonathonfletcher 0:5f46ebd8588e 256 return (OS_R_OK);
jonathonfletcher 0:5f46ebd8588e 257 }
jonathonfletcher 0:5f46ebd8588e 258
jonathonfletcher 0:5f46ebd8588e 259
jonathonfletcher 0:5f46ebd8588e 260 /*--------------------------- rt_sys_init -----------------------------------*/
jonathonfletcher 0:5f46ebd8588e 261 void rt_sys_init (void) {
jonathonfletcher 0:5f46ebd8588e 262 /* Initialize system and start up task declared with "first_task". */
jonathonfletcher 0:5f46ebd8588e 263 U32 i;
jonathonfletcher 0:5f46ebd8588e 264
jonathonfletcher 0:5f46ebd8588e 265 DBG_INIT();
jonathonfletcher 0:5f46ebd8588e 266
jonathonfletcher 0:5f46ebd8588e 267 /* Initialize dynamic memory and task TCB pointers to NULL. */
jonathonfletcher 0:5f46ebd8588e 268 for (i = 0; i < os_maxtaskrun; i++) {
jonathonfletcher 0:5f46ebd8588e 269 os_active_TCB[i] = NULL;
jonathonfletcher 0:5f46ebd8588e 270 }
jonathonfletcher 0:5f46ebd8588e 271
jonathonfletcher 0:5f46ebd8588e 272 /* Set up TCB of idle demon */
jonathonfletcher 0:5f46ebd8588e 273 os_idle_TCB.task_id = 255;
jonathonfletcher 0:5f46ebd8588e 274 os_idle_TCB.priv_stack = idle_task_stack_size;
jonathonfletcher 0:5f46ebd8588e 275 os_idle_TCB.stack = idle_task_stack;
jonathonfletcher 0:5f46ebd8588e 276 rt_init_context (&os_idle_TCB, 0, os_idle_demon);
jonathonfletcher 0:5f46ebd8588e 277
jonathonfletcher 0:5f46ebd8588e 278 /* Set up ready list: initially empty */
jonathonfletcher 0:5f46ebd8588e 279 os_rdy.cb_type = HCB;
jonathonfletcher 0:5f46ebd8588e 280 os_rdy.p_lnk = NULL;
jonathonfletcher 0:5f46ebd8588e 281 /* Set up delay list: initially empty */
jonathonfletcher 0:5f46ebd8588e 282 os_dly.cb_type = HCB;
jonathonfletcher 0:5f46ebd8588e 283 os_dly.p_dlnk = NULL;
jonathonfletcher 0:5f46ebd8588e 284 os_dly.p_blnk = NULL;
jonathonfletcher 0:5f46ebd8588e 285 os_dly.delta_time = 0;
jonathonfletcher 0:5f46ebd8588e 286
jonathonfletcher 0:5f46ebd8588e 287 /* Fix SP and systemvariables to assume idle task is running */
jonathonfletcher 0:5f46ebd8588e 288 /* Transform main program into idle task by assuming idle TCB */
jonathonfletcher 0:5f46ebd8588e 289 os_tsk.tsk_run = &os_idle_TCB;
jonathonfletcher 0:5f46ebd8588e 290 os_tsk.tsk_run->state = RUNNING;
jonathonfletcher 0:5f46ebd8588e 291
jonathonfletcher 0:5f46ebd8588e 292 /* Initialize ps queue */
jonathonfletcher 0:5f46ebd8588e 293 os_psq->first = 0;
jonathonfletcher 0:5f46ebd8588e 294 os_psq->last = 0;
jonathonfletcher 0:5f46ebd8588e 295 os_psq->size = os_fifo_size;
jonathonfletcher 0:5f46ebd8588e 296
jonathonfletcher 0:5f46ebd8588e 297 rt_init_robin ();
jonathonfletcher 0:5f46ebd8588e 298
jonathonfletcher 0:5f46ebd8588e 299 /* Intitialize SVC and PendSV */
jonathonfletcher 0:5f46ebd8588e 300 rt_svc_init ();
jonathonfletcher 0:5f46ebd8588e 301 }
jonathonfletcher 0:5f46ebd8588e 302
jonathonfletcher 0:5f46ebd8588e 303
jonathonfletcher 0:5f46ebd8588e 304 /*--------------------------- rt_sys_start ----------------------------------*/
jonathonfletcher 0:5f46ebd8588e 305 void rt_sys_start (void) {
jonathonfletcher 0:5f46ebd8588e 306 /* Start system */
jonathonfletcher 0:5f46ebd8588e 307
jonathonfletcher 0:5f46ebd8588e 308 /* Intitialize and start system clock timer */
jonathonfletcher 0:5f46ebd8588e 309 os_tick_irqn = os_tick_init ();
jonathonfletcher 0:5f46ebd8588e 310 if (os_tick_irqn >= 0) {
jonathonfletcher 0:5f46ebd8588e 311 OS_X_INIT(os_tick_irqn);
jonathonfletcher 0:5f46ebd8588e 312 }
jonathonfletcher 0:5f46ebd8588e 313 }
jonathonfletcher 0:5f46ebd8588e 314
jonathonfletcher 0:5f46ebd8588e 315 /*----------------------------------------------------------------------------
jonathonfletcher 0:5f46ebd8588e 316 * end of file
jonathonfletcher 0:5f46ebd8588e 317 *---------------------------------------------------------------------------*/