Control a robot over the internet using UDP and a Wifly module (WiFi).

Dependencies:   Motor TextLCD WiflyInterface mbed-rtos mbed

Committer:
apatel336
Date:
Thu Oct 17 13:27:56 2013 +0000
Revision:
0:c0dc3a76f3d4
Initial Release

Who changed what in which revision?

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