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