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