Final 350 project

Dependencies:   uzair Camera_LS_Y201 F7_Ethernet LCD_DISCO_F746NG NetworkAPI SDFileSystem mbed

Committer:
shoaib_ahmed
Date:
Mon Jul 31 09:16:35 2017 +0000
Revision:
0:791a779d6220
final project;

Who changed what in which revision?

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