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