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