Official mbed Real Time Operating System based on the RTX implementation of the CMSIS-RTOS API open standard.

Dependents:   LoRaWAN-lmic-app LoRaWAN-lmic-app LoRaWAN-test-10secs testes ... more

Committer:
mbed_official
Date:
Thu Nov 06 11:00:33 2014 +0000
Revision:
48:e9a2c7cb57a4
Synchronized with git revision 8724eb616b6e07a3bd111d3022652eb5bbefe9b7

Full URL: https://github.com/mbedmicro/mbed/commit/8724eb616b6e07a3bd111d3022652eb5bbefe9b7/

[RZ/A1H] mbed-RZ first release

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 48:e9a2c7cb57a4 1 /*----------------------------------------------------------------------------
mbed_official 48:e9a2c7cb57a4 2 * RL-ARM - RTX
mbed_official 48:e9a2c7cb57a4 3 *----------------------------------------------------------------------------
mbed_official 48:e9a2c7cb57a4 4 * Name: RT_TASK.C
mbed_official 48:e9a2c7cb57a4 5 * Purpose: Task functions and system start up.
mbed_official 48:e9a2c7cb57a4 6 * Rev.: V4.60
mbed_official 48:e9a2c7cb57a4 7 *----------------------------------------------------------------------------
mbed_official 48:e9a2c7cb57a4 8 *
mbed_official 48:e9a2c7cb57a4 9 * Copyright (c) 1999-2009 KEIL, 2009-2012 ARM Germany GmbH
mbed_official 48:e9a2c7cb57a4 10 * All rights reserved.
mbed_official 48:e9a2c7cb57a4 11 * Redistribution and use in source and binary forms, with or without
mbed_official 48:e9a2c7cb57a4 12 * modification, are permitted provided that the following conditions are met:
mbed_official 48:e9a2c7cb57a4 13 * - Redistributions of source code must retain the above copyright
mbed_official 48:e9a2c7cb57a4 14 * notice, this list of conditions and the following disclaimer.
mbed_official 48:e9a2c7cb57a4 15 * - Redistributions in binary form must reproduce the above copyright
mbed_official 48:e9a2c7cb57a4 16 * notice, this list of conditions and the following disclaimer in the
mbed_official 48:e9a2c7cb57a4 17 * documentation and/or other materials provided with the distribution.
mbed_official 48:e9a2c7cb57a4 18 * - Neither the name of ARM nor the names of its contributors may be used
mbed_official 48:e9a2c7cb57a4 19 * to endorse or promote products derived from this software without
mbed_official 48:e9a2c7cb57a4 20 * specific prior written permission.
mbed_official 48:e9a2c7cb57a4 21 *
mbed_official 48:e9a2c7cb57a4 22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
mbed_official 48:e9a2c7cb57a4 23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
mbed_official 48:e9a2c7cb57a4 24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
mbed_official 48:e9a2c7cb57a4 25 * ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE
mbed_official 48:e9a2c7cb57a4 26 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
mbed_official 48:e9a2c7cb57a4 27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
mbed_official 48:e9a2c7cb57a4 28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
mbed_official 48:e9a2c7cb57a4 29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
mbed_official 48:e9a2c7cb57a4 30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
mbed_official 48:e9a2c7cb57a4 31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
mbed_official 48:e9a2c7cb57a4 32 * POSSIBILITY OF SUCH DAMAGE.
mbed_official 48:e9a2c7cb57a4 33 *---------------------------------------------------------------------------*/
mbed_official 48:e9a2c7cb57a4 34
mbed_official 48:e9a2c7cb57a4 35 #include "rt_TypeDef.h"
mbed_official 48:e9a2c7cb57a4 36 #include "RTX_Config.h"
mbed_official 48:e9a2c7cb57a4 37 #include "rt_System.h"
mbed_official 48:e9a2c7cb57a4 38 #include "rt_Task.h"
mbed_official 48:e9a2c7cb57a4 39 #include "rt_List.h"
mbed_official 48:e9a2c7cb57a4 40 #include "rt_MemBox.h"
mbed_official 48:e9a2c7cb57a4 41 #include "rt_Robin.h"
mbed_official 48:e9a2c7cb57a4 42 #ifdef __CORTEX_A9
mbed_official 48:e9a2c7cb57a4 43 #include "rt_HAL_CA.h"
mbed_official 48:e9a2c7cb57a4 44 #else
mbed_official 48:e9a2c7cb57a4 45 #include "rt_HAL_CM.h"
mbed_official 48:e9a2c7cb57a4 46 #endif
mbed_official 48:e9a2c7cb57a4 47
mbed_official 48:e9a2c7cb57a4 48 /*----------------------------------------------------------------------------
mbed_official 48:e9a2c7cb57a4 49 * Global Variables
mbed_official 48:e9a2c7cb57a4 50 *---------------------------------------------------------------------------*/
mbed_official 48:e9a2c7cb57a4 51
mbed_official 48:e9a2c7cb57a4 52 /* Running and next task info. */
mbed_official 48:e9a2c7cb57a4 53 struct OS_TSK os_tsk;
mbed_official 48:e9a2c7cb57a4 54
mbed_official 48:e9a2c7cb57a4 55 /* Task Control Blocks of idle demon */
mbed_official 48:e9a2c7cb57a4 56 struct OS_TCB os_idle_TCB;
mbed_official 48:e9a2c7cb57a4 57
mbed_official 48:e9a2c7cb57a4 58
mbed_official 48:e9a2c7cb57a4 59 /*----------------------------------------------------------------------------
mbed_official 48:e9a2c7cb57a4 60 * Local Functions
mbed_official 48:e9a2c7cb57a4 61 *---------------------------------------------------------------------------*/
mbed_official 48:e9a2c7cb57a4 62
mbed_official 48:e9a2c7cb57a4 63 static OS_TID rt_get_TID (void) {
mbed_official 48:e9a2c7cb57a4 64 U32 tid;
mbed_official 48:e9a2c7cb57a4 65
mbed_official 48:e9a2c7cb57a4 66 for (tid = 1; tid <= os_maxtaskrun; tid++) {
mbed_official 48:e9a2c7cb57a4 67 if (os_active_TCB[tid-1] == NULL) {
mbed_official 48:e9a2c7cb57a4 68 return ((OS_TID)tid);
mbed_official 48:e9a2c7cb57a4 69 }
mbed_official 48:e9a2c7cb57a4 70 }
mbed_official 48:e9a2c7cb57a4 71 return (0);
mbed_official 48:e9a2c7cb57a4 72 }
mbed_official 48:e9a2c7cb57a4 73
mbed_official 48:e9a2c7cb57a4 74
mbed_official 48:e9a2c7cb57a4 75 /*--------------------------- rt_init_context -------------------------------*/
mbed_official 48:e9a2c7cb57a4 76
mbed_official 48:e9a2c7cb57a4 77 static void rt_init_context (P_TCB p_TCB, U8 priority, FUNCP task_body) {
mbed_official 48:e9a2c7cb57a4 78 /* Initialize general part of the Task Control Block. */
mbed_official 48:e9a2c7cb57a4 79 p_TCB->cb_type = TCB;
mbed_official 48:e9a2c7cb57a4 80 p_TCB->state = READY;
mbed_official 48:e9a2c7cb57a4 81 p_TCB->prio = priority;
mbed_official 48:e9a2c7cb57a4 82 p_TCB->p_lnk = NULL;
mbed_official 48:e9a2c7cb57a4 83 p_TCB->p_rlnk = NULL;
mbed_official 48:e9a2c7cb57a4 84 p_TCB->p_dlnk = NULL;
mbed_official 48:e9a2c7cb57a4 85 p_TCB->p_blnk = NULL;
mbed_official 48:e9a2c7cb57a4 86 p_TCB->delta_time = 0;
mbed_official 48:e9a2c7cb57a4 87 p_TCB->interval_time = 0;
mbed_official 48:e9a2c7cb57a4 88 p_TCB->events = 0;
mbed_official 48:e9a2c7cb57a4 89 p_TCB->waits = 0;
mbed_official 48:e9a2c7cb57a4 90 p_TCB->stack_frame = 0;
mbed_official 48:e9a2c7cb57a4 91
mbed_official 48:e9a2c7cb57a4 92 if (p_TCB->priv_stack == 0) {
mbed_official 48:e9a2c7cb57a4 93 /* Allocate the memory space for the stack. */
mbed_official 48:e9a2c7cb57a4 94 p_TCB->stack = rt_alloc_box (mp_stk);
mbed_official 48:e9a2c7cb57a4 95 }
mbed_official 48:e9a2c7cb57a4 96 rt_init_stack (p_TCB, task_body);
mbed_official 48:e9a2c7cb57a4 97 }
mbed_official 48:e9a2c7cb57a4 98
mbed_official 48:e9a2c7cb57a4 99
mbed_official 48:e9a2c7cb57a4 100 /*--------------------------- rt_switch_req ---------------------------------*/
mbed_official 48:e9a2c7cb57a4 101
mbed_official 48:e9a2c7cb57a4 102 void rt_switch_req (P_TCB p_new) {
mbed_official 48:e9a2c7cb57a4 103 /* Switch to next task (identified by "p_new"). */
mbed_official 48:e9a2c7cb57a4 104 os_tsk.new = p_new;
mbed_official 48:e9a2c7cb57a4 105 p_new->state = RUNNING;
mbed_official 48:e9a2c7cb57a4 106 DBG_TASK_SWITCH(p_new->task_id);
mbed_official 48:e9a2c7cb57a4 107 }
mbed_official 48:e9a2c7cb57a4 108
mbed_official 48:e9a2c7cb57a4 109
mbed_official 48:e9a2c7cb57a4 110 /*--------------------------- rt_dispatch -----------------------------------*/
mbed_official 48:e9a2c7cb57a4 111
mbed_official 48:e9a2c7cb57a4 112 void rt_dispatch (P_TCB next_TCB) {
mbed_official 48:e9a2c7cb57a4 113 /* Dispatch next task if any identified or dispatch highest ready task */
mbed_official 48:e9a2c7cb57a4 114 /* "next_TCB" identifies a task to run or has value NULL (=no next task) */
mbed_official 48:e9a2c7cb57a4 115 if (next_TCB == NULL) {
mbed_official 48:e9a2c7cb57a4 116 /* Running task was blocked: continue with highest ready task */
mbed_official 48:e9a2c7cb57a4 117 next_TCB = rt_get_first (&os_rdy);
mbed_official 48:e9a2c7cb57a4 118 rt_switch_req (next_TCB);
mbed_official 48:e9a2c7cb57a4 119 }
mbed_official 48:e9a2c7cb57a4 120 else {
mbed_official 48:e9a2c7cb57a4 121 /* Check which task continues */
mbed_official 48:e9a2c7cb57a4 122 if (next_TCB->prio > os_tsk.run->prio) {
mbed_official 48:e9a2c7cb57a4 123 /* preempt running task */
mbed_official 48:e9a2c7cb57a4 124 rt_put_rdy_first (os_tsk.run);
mbed_official 48:e9a2c7cb57a4 125 os_tsk.run->state = READY;
mbed_official 48:e9a2c7cb57a4 126 rt_switch_req (next_TCB);
mbed_official 48:e9a2c7cb57a4 127 }
mbed_official 48:e9a2c7cb57a4 128 else {
mbed_official 48:e9a2c7cb57a4 129 /* put next task into ready list, no task switch takes place */
mbed_official 48:e9a2c7cb57a4 130 next_TCB->state = READY;
mbed_official 48:e9a2c7cb57a4 131 rt_put_prio (&os_rdy, next_TCB);
mbed_official 48:e9a2c7cb57a4 132 }
mbed_official 48:e9a2c7cb57a4 133 }
mbed_official 48:e9a2c7cb57a4 134 }
mbed_official 48:e9a2c7cb57a4 135
mbed_official 48:e9a2c7cb57a4 136
mbed_official 48:e9a2c7cb57a4 137 /*--------------------------- rt_block --------------------------------------*/
mbed_official 48:e9a2c7cb57a4 138
mbed_official 48:e9a2c7cb57a4 139 void rt_block (U16 timeout, U8 block_state) {
mbed_official 48:e9a2c7cb57a4 140 /* Block running task and choose next ready task. */
mbed_official 48:e9a2c7cb57a4 141 /* "timeout" sets a time-out value or is 0xffff (=no time-out). */
mbed_official 48:e9a2c7cb57a4 142 /* "block_state" defines the appropriate task state */
mbed_official 48:e9a2c7cb57a4 143 P_TCB next_TCB;
mbed_official 48:e9a2c7cb57a4 144
mbed_official 48:e9a2c7cb57a4 145 if (timeout) {
mbed_official 48:e9a2c7cb57a4 146 if (timeout < 0xffff) {
mbed_official 48:e9a2c7cb57a4 147 rt_put_dly (os_tsk.run, timeout);
mbed_official 48:e9a2c7cb57a4 148 }
mbed_official 48:e9a2c7cb57a4 149 os_tsk.run->state = block_state;
mbed_official 48:e9a2c7cb57a4 150 next_TCB = rt_get_first (&os_rdy);
mbed_official 48:e9a2c7cb57a4 151 rt_switch_req (next_TCB);
mbed_official 48:e9a2c7cb57a4 152 }
mbed_official 48:e9a2c7cb57a4 153 }
mbed_official 48:e9a2c7cb57a4 154
mbed_official 48:e9a2c7cb57a4 155
mbed_official 48:e9a2c7cb57a4 156 /*--------------------------- rt_tsk_pass -----------------------------------*/
mbed_official 48:e9a2c7cb57a4 157
mbed_official 48:e9a2c7cb57a4 158 void rt_tsk_pass (void) {
mbed_official 48:e9a2c7cb57a4 159 /* Allow tasks of same priority level to run cooperatively.*/
mbed_official 48:e9a2c7cb57a4 160 P_TCB p_new;
mbed_official 48:e9a2c7cb57a4 161
mbed_official 48:e9a2c7cb57a4 162 p_new = rt_get_same_rdy_prio();
mbed_official 48:e9a2c7cb57a4 163 if (p_new != NULL) {
mbed_official 48:e9a2c7cb57a4 164 rt_put_prio ((P_XCB)&os_rdy, os_tsk.run);
mbed_official 48:e9a2c7cb57a4 165 os_tsk.run->state = READY;
mbed_official 48:e9a2c7cb57a4 166 rt_switch_req (p_new);
mbed_official 48:e9a2c7cb57a4 167 }
mbed_official 48:e9a2c7cb57a4 168 }
mbed_official 48:e9a2c7cb57a4 169
mbed_official 48:e9a2c7cb57a4 170
mbed_official 48:e9a2c7cb57a4 171 /*--------------------------- rt_tsk_self -----------------------------------*/
mbed_official 48:e9a2c7cb57a4 172
mbed_official 48:e9a2c7cb57a4 173 OS_TID rt_tsk_self (void) {
mbed_official 48:e9a2c7cb57a4 174 /* Return own task identifier value. */
mbed_official 48:e9a2c7cb57a4 175 if (os_tsk.run == NULL) {
mbed_official 48:e9a2c7cb57a4 176 return (0);
mbed_official 48:e9a2c7cb57a4 177 }
mbed_official 48:e9a2c7cb57a4 178 return (os_tsk.run->task_id);
mbed_official 48:e9a2c7cb57a4 179 }
mbed_official 48:e9a2c7cb57a4 180
mbed_official 48:e9a2c7cb57a4 181
mbed_official 48:e9a2c7cb57a4 182 /*--------------------------- rt_tsk_prio -----------------------------------*/
mbed_official 48:e9a2c7cb57a4 183
mbed_official 48:e9a2c7cb57a4 184 OS_RESULT rt_tsk_prio (OS_TID task_id, U8 new_prio) {
mbed_official 48:e9a2c7cb57a4 185 /* Change execution priority of a task to "new_prio". */
mbed_official 48:e9a2c7cb57a4 186 P_TCB p_task;
mbed_official 48:e9a2c7cb57a4 187
mbed_official 48:e9a2c7cb57a4 188 if (task_id == 0) {
mbed_official 48:e9a2c7cb57a4 189 /* Change execution priority of calling task. */
mbed_official 48:e9a2c7cb57a4 190 os_tsk.run->prio = new_prio;
mbed_official 48:e9a2c7cb57a4 191 run:if (rt_rdy_prio() > new_prio) {
mbed_official 48:e9a2c7cb57a4 192 rt_put_prio (&os_rdy, os_tsk.run);
mbed_official 48:e9a2c7cb57a4 193 os_tsk.run->state = READY;
mbed_official 48:e9a2c7cb57a4 194 rt_dispatch (NULL);
mbed_official 48:e9a2c7cb57a4 195 }
mbed_official 48:e9a2c7cb57a4 196 return (OS_R_OK);
mbed_official 48:e9a2c7cb57a4 197 }
mbed_official 48:e9a2c7cb57a4 198
mbed_official 48:e9a2c7cb57a4 199 /* Find the task in the "os_active_TCB" array. */
mbed_official 48:e9a2c7cb57a4 200 if (task_id > os_maxtaskrun || os_active_TCB[task_id-1] == NULL) {
mbed_official 48:e9a2c7cb57a4 201 /* Task with "task_id" not found or not started. */
mbed_official 48:e9a2c7cb57a4 202 return (OS_R_NOK);
mbed_official 48:e9a2c7cb57a4 203 }
mbed_official 48:e9a2c7cb57a4 204 p_task = os_active_TCB[task_id-1];
mbed_official 48:e9a2c7cb57a4 205 p_task->prio = new_prio;
mbed_official 48:e9a2c7cb57a4 206 if (p_task == os_tsk.run) {
mbed_official 48:e9a2c7cb57a4 207 goto run;
mbed_official 48:e9a2c7cb57a4 208 }
mbed_official 48:e9a2c7cb57a4 209 rt_resort_prio (p_task);
mbed_official 48:e9a2c7cb57a4 210 if (p_task->state == READY) {
mbed_official 48:e9a2c7cb57a4 211 /* Task enqueued in a ready list. */
mbed_official 48:e9a2c7cb57a4 212 p_task = rt_get_first (&os_rdy);
mbed_official 48:e9a2c7cb57a4 213 rt_dispatch (p_task);
mbed_official 48:e9a2c7cb57a4 214 }
mbed_official 48:e9a2c7cb57a4 215 return (OS_R_OK);
mbed_official 48:e9a2c7cb57a4 216 }
mbed_official 48:e9a2c7cb57a4 217
mbed_official 48:e9a2c7cb57a4 218
mbed_official 48:e9a2c7cb57a4 219 /*--------------------------- rt_tsk_create ---------------------------------*/
mbed_official 48:e9a2c7cb57a4 220
mbed_official 48:e9a2c7cb57a4 221 OS_TID rt_tsk_create (FUNCP task, U32 prio_stksz, void *stk, void *argv) {
mbed_official 48:e9a2c7cb57a4 222 /* Start a new task declared with "task". */
mbed_official 48:e9a2c7cb57a4 223 P_TCB task_context;
mbed_official 48:e9a2c7cb57a4 224 U32 i;
mbed_official 48:e9a2c7cb57a4 225
mbed_official 48:e9a2c7cb57a4 226 /* Priority 0 is reserved for idle task! */
mbed_official 48:e9a2c7cb57a4 227 if ((prio_stksz & 0xFF) == 0) {
mbed_official 48:e9a2c7cb57a4 228 prio_stksz += 1;
mbed_official 48:e9a2c7cb57a4 229 }
mbed_official 48:e9a2c7cb57a4 230 task_context = rt_alloc_box (mp_tcb);
mbed_official 48:e9a2c7cb57a4 231 if (task_context == NULL) {
mbed_official 48:e9a2c7cb57a4 232 return (0);
mbed_official 48:e9a2c7cb57a4 233 }
mbed_official 48:e9a2c7cb57a4 234 /* If "size != 0" use a private user provided stack. */
mbed_official 48:e9a2c7cb57a4 235 task_context->stack = stk;
mbed_official 48:e9a2c7cb57a4 236 task_context->priv_stack = prio_stksz >> 8;
mbed_official 48:e9a2c7cb57a4 237 /* Pass parameter 'argv' to 'rt_init_context' */
mbed_official 48:e9a2c7cb57a4 238 task_context->msg = argv;
mbed_official 48:e9a2c7cb57a4 239 /* For 'size == 0' system allocates the user stack from the memory pool. */
mbed_official 48:e9a2c7cb57a4 240 rt_init_context (task_context, prio_stksz & 0xFF, task);
mbed_official 48:e9a2c7cb57a4 241
mbed_official 48:e9a2c7cb57a4 242 /* Find a free entry in 'os_active_TCB' table. */
mbed_official 48:e9a2c7cb57a4 243 i = rt_get_TID ();
mbed_official 48:e9a2c7cb57a4 244 os_active_TCB[i-1] = task_context;
mbed_official 48:e9a2c7cb57a4 245 task_context->task_id = i;
mbed_official 48:e9a2c7cb57a4 246 DBG_TASK_NOTIFY(task_context, __TRUE);
mbed_official 48:e9a2c7cb57a4 247 rt_dispatch (task_context);
mbed_official 48:e9a2c7cb57a4 248 return ((OS_TID)i);
mbed_official 48:e9a2c7cb57a4 249 }
mbed_official 48:e9a2c7cb57a4 250
mbed_official 48:e9a2c7cb57a4 251
mbed_official 48:e9a2c7cb57a4 252 /*--------------------------- rt_tsk_delete ---------------------------------*/
mbed_official 48:e9a2c7cb57a4 253
mbed_official 48:e9a2c7cb57a4 254 OS_RESULT rt_tsk_delete (OS_TID task_id) {
mbed_official 48:e9a2c7cb57a4 255 /* Terminate the task identified with "task_id". */
mbed_official 48:e9a2c7cb57a4 256 P_TCB task_context;
mbed_official 48:e9a2c7cb57a4 257
mbed_official 48:e9a2c7cb57a4 258 if (task_id == 0 || task_id == os_tsk.run->task_id) {
mbed_official 48:e9a2c7cb57a4 259 /* Terminate itself. */
mbed_official 48:e9a2c7cb57a4 260 os_tsk.run->state = INACTIVE;
mbed_official 48:e9a2c7cb57a4 261 os_tsk.run->tsk_stack = rt_get_PSP ();
mbed_official 48:e9a2c7cb57a4 262 rt_stk_check ();
mbed_official 48:e9a2c7cb57a4 263 os_active_TCB[os_tsk.run->task_id-1] = NULL;
mbed_official 48:e9a2c7cb57a4 264 rt_free_box (mp_stk, os_tsk.run->stack);
mbed_official 48:e9a2c7cb57a4 265 os_tsk.run->stack = NULL;
mbed_official 48:e9a2c7cb57a4 266 DBG_TASK_NOTIFY(os_tsk.run, __FALSE);
mbed_official 48:e9a2c7cb57a4 267 rt_free_box (mp_tcb, os_tsk.run);
mbed_official 48:e9a2c7cb57a4 268 os_tsk.run = NULL;
mbed_official 48:e9a2c7cb57a4 269 rt_dispatch (NULL);
mbed_official 48:e9a2c7cb57a4 270 /* The program should never come to this point. */
mbed_official 48:e9a2c7cb57a4 271 }
mbed_official 48:e9a2c7cb57a4 272 else {
mbed_official 48:e9a2c7cb57a4 273 /* Find the task in the "os_active_TCB" array. */
mbed_official 48:e9a2c7cb57a4 274 if (task_id > os_maxtaskrun || os_active_TCB[task_id-1] == NULL) {
mbed_official 48:e9a2c7cb57a4 275 /* Task with "task_id" not found or not started. */
mbed_official 48:e9a2c7cb57a4 276 return (OS_R_NOK);
mbed_official 48:e9a2c7cb57a4 277 }
mbed_official 48:e9a2c7cb57a4 278 task_context = os_active_TCB[task_id-1];
mbed_official 48:e9a2c7cb57a4 279 rt_rmv_list (task_context);
mbed_official 48:e9a2c7cb57a4 280 rt_rmv_dly (task_context);
mbed_official 48:e9a2c7cb57a4 281 os_active_TCB[task_id-1] = NULL;
mbed_official 48:e9a2c7cb57a4 282 rt_free_box (mp_stk, task_context->stack);
mbed_official 48:e9a2c7cb57a4 283 task_context->stack = NULL;
mbed_official 48:e9a2c7cb57a4 284 DBG_TASK_NOTIFY(task_context, __FALSE);
mbed_official 48:e9a2c7cb57a4 285 rt_free_box (mp_tcb, task_context);
mbed_official 48:e9a2c7cb57a4 286 }
mbed_official 48:e9a2c7cb57a4 287 return (OS_R_OK);
mbed_official 48:e9a2c7cb57a4 288 }
mbed_official 48:e9a2c7cb57a4 289
mbed_official 48:e9a2c7cb57a4 290
mbed_official 48:e9a2c7cb57a4 291 /*--------------------------- rt_sys_init -----------------------------------*/
mbed_official 48:e9a2c7cb57a4 292
mbed_official 48:e9a2c7cb57a4 293 #ifdef __CMSIS_RTOS
mbed_official 48:e9a2c7cb57a4 294 void rt_sys_init (void) {
mbed_official 48:e9a2c7cb57a4 295 #else
mbed_official 48:e9a2c7cb57a4 296 void rt_sys_init (FUNCP first_task, U32 prio_stksz, void *stk) {
mbed_official 48:e9a2c7cb57a4 297 #endif
mbed_official 48:e9a2c7cb57a4 298 /* Initialize system and start up task declared with "first_task". */
mbed_official 48:e9a2c7cb57a4 299 U32 i;
mbed_official 48:e9a2c7cb57a4 300
mbed_official 48:e9a2c7cb57a4 301 DBG_INIT();
mbed_official 48:e9a2c7cb57a4 302
mbed_official 48:e9a2c7cb57a4 303 /* Initialize dynamic memory and task TCB pointers to NULL. */
mbed_official 48:e9a2c7cb57a4 304 for (i = 0; i < os_maxtaskrun; i++) {
mbed_official 48:e9a2c7cb57a4 305 os_active_TCB[i] = NULL;
mbed_official 48:e9a2c7cb57a4 306 }
mbed_official 48:e9a2c7cb57a4 307 rt_init_box (&mp_tcb, mp_tcb_size, sizeof(struct OS_TCB));
mbed_official 48:e9a2c7cb57a4 308 rt_init_box (&mp_stk, mp_stk_size, BOX_ALIGN_8 | (U16)(os_stackinfo));
mbed_official 48:e9a2c7cb57a4 309 rt_init_box ((U32 *)m_tmr, mp_tmr_size, sizeof(struct OS_TMR));
mbed_official 48:e9a2c7cb57a4 310
mbed_official 48:e9a2c7cb57a4 311 /* Set up TCB of idle demon */
mbed_official 48:e9a2c7cb57a4 312 os_idle_TCB.task_id = 255;
mbed_official 48:e9a2c7cb57a4 313 os_idle_TCB.priv_stack = 0;
mbed_official 48:e9a2c7cb57a4 314 rt_init_context (&os_idle_TCB, 0, os_idle_demon);
mbed_official 48:e9a2c7cb57a4 315
mbed_official 48:e9a2c7cb57a4 316 /* Set up ready list: initially empty */
mbed_official 48:e9a2c7cb57a4 317 os_rdy.cb_type = HCB;
mbed_official 48:e9a2c7cb57a4 318 os_rdy.p_lnk = NULL;
mbed_official 48:e9a2c7cb57a4 319 /* Set up delay list: initially empty */
mbed_official 48:e9a2c7cb57a4 320 os_dly.cb_type = HCB;
mbed_official 48:e9a2c7cb57a4 321 os_dly.p_dlnk = NULL;
mbed_official 48:e9a2c7cb57a4 322 os_dly.p_blnk = NULL;
mbed_official 48:e9a2c7cb57a4 323 os_dly.delta_time = 0;
mbed_official 48:e9a2c7cb57a4 324
mbed_official 48:e9a2c7cb57a4 325 /* Fix SP and system variables to assume idle task is running */
mbed_official 48:e9a2c7cb57a4 326 /* Transform main program into idle task by assuming idle TCB */
mbed_official 48:e9a2c7cb57a4 327 #ifndef __CMSIS_RTOS
mbed_official 48:e9a2c7cb57a4 328 rt_set_PSP (os_idle_TCB.tsk_stack+32);
mbed_official 48:e9a2c7cb57a4 329 #endif
mbed_official 48:e9a2c7cb57a4 330 os_tsk.run = &os_idle_TCB;
mbed_official 48:e9a2c7cb57a4 331 os_tsk.run->state = RUNNING;
mbed_official 48:e9a2c7cb57a4 332
mbed_official 48:e9a2c7cb57a4 333 /* Initialize ps queue */
mbed_official 48:e9a2c7cb57a4 334 os_psq->first = 0;
mbed_official 48:e9a2c7cb57a4 335 os_psq->last = 0;
mbed_official 48:e9a2c7cb57a4 336 os_psq->size = os_fifo_size;
mbed_official 48:e9a2c7cb57a4 337
mbed_official 48:e9a2c7cb57a4 338 rt_init_robin ();
mbed_official 48:e9a2c7cb57a4 339
mbed_official 48:e9a2c7cb57a4 340 /* Initialize SVC and PendSV */
mbed_official 48:e9a2c7cb57a4 341 rt_svc_init ();
mbed_official 48:e9a2c7cb57a4 342
mbed_official 48:e9a2c7cb57a4 343 #ifndef __CMSIS_RTOS
mbed_official 48:e9a2c7cb57a4 344 /* Initialize and start system clock timer */
mbed_official 48:e9a2c7cb57a4 345 os_tick_irqn = os_tick_init ();
mbed_official 48:e9a2c7cb57a4 346 if (os_tick_irqn >= 0) {
mbed_official 48:e9a2c7cb57a4 347 OS_X_INIT(os_tick_irqn);
mbed_official 48:e9a2c7cb57a4 348 }
mbed_official 48:e9a2c7cb57a4 349
mbed_official 48:e9a2c7cb57a4 350 /* Start up first user task before entering the endless loop */
mbed_official 48:e9a2c7cb57a4 351 rt_tsk_create (first_task, prio_stksz, stk, NULL);
mbed_official 48:e9a2c7cb57a4 352 #endif
mbed_official 48:e9a2c7cb57a4 353 }
mbed_official 48:e9a2c7cb57a4 354
mbed_official 48:e9a2c7cb57a4 355
mbed_official 48:e9a2c7cb57a4 356 /*--------------------------- rt_sys_start ----------------------------------*/
mbed_official 48:e9a2c7cb57a4 357
mbed_official 48:e9a2c7cb57a4 358 #ifdef __CMSIS_RTOS
mbed_official 48:e9a2c7cb57a4 359 void rt_sys_start (void) {
mbed_official 48:e9a2c7cb57a4 360 /* Start system */
mbed_official 48:e9a2c7cb57a4 361
mbed_official 48:e9a2c7cb57a4 362 /* Initialize and start system clock timer */
mbed_official 48:e9a2c7cb57a4 363 os_tick_irqn = os_tick_init ();
mbed_official 48:e9a2c7cb57a4 364 if (os_tick_irqn >= 0) {
mbed_official 48:e9a2c7cb57a4 365 OS_X_INIT(os_tick_irqn);
mbed_official 48:e9a2c7cb57a4 366 }
mbed_official 48:e9a2c7cb57a4 367 }
mbed_official 48:e9a2c7cb57a4 368 #endif
mbed_official 48:e9a2c7cb57a4 369
mbed_official 48:e9a2c7cb57a4 370 /*----------------------------------------------------------------------------
mbed_official 48:e9a2c7cb57a4 371 * end of file
mbed_official 48:e9a2c7cb57a4 372 *---------------------------------------------------------------------------*/