Repostiory containing DAPLink source code with Reset Pin workaround for HANI_IOT board.
Upstream: https://github.com/ARMmbed/DAPLink
source/rtos/rt_Task.c@0:01f31e923fe2, 2020-04-07 (annotated)
- Committer:
- Pawel Zarembski
- Date:
- Tue Apr 07 12:55:42 2020 +0200
- Revision:
- 0:01f31e923fe2
hani: DAPLink with reset workaround
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Pawel Zarembski |
0:01f31e923fe2 | 1 | /** |
Pawel Zarembski |
0:01f31e923fe2 | 2 | * @file rt_Task.c |
Pawel Zarembski |
0:01f31e923fe2 | 3 | * @brief |
Pawel Zarembski |
0:01f31e923fe2 | 4 | * |
Pawel Zarembski |
0:01f31e923fe2 | 5 | * DAPLink Interface Firmware |
Pawel Zarembski |
0:01f31e923fe2 | 6 | * Copyright (c) 2009-2016, ARM Limited, All Rights Reserved |
Pawel Zarembski |
0:01f31e923fe2 | 7 | * SPDX-License-Identifier: Apache-2.0 |
Pawel Zarembski |
0:01f31e923fe2 | 8 | * |
Pawel Zarembski |
0:01f31e923fe2 | 9 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
Pawel Zarembski |
0:01f31e923fe2 | 10 | * not use this file except in compliance with the License. |
Pawel Zarembski |
0:01f31e923fe2 | 11 | * You may obtain a copy of the License at |
Pawel Zarembski |
0:01f31e923fe2 | 12 | * |
Pawel Zarembski |
0:01f31e923fe2 | 13 | * http://www.apache.org/licenses/LICENSE-2.0 |
Pawel Zarembski |
0:01f31e923fe2 | 14 | * |
Pawel Zarembski |
0:01f31e923fe2 | 15 | * Unless required by applicable law or agreed to in writing, software |
Pawel Zarembski |
0:01f31e923fe2 | 16 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
Pawel Zarembski |
0:01f31e923fe2 | 17 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
Pawel Zarembski |
0:01f31e923fe2 | 18 | * See the License for the specific language governing permissions and |
Pawel Zarembski |
0:01f31e923fe2 | 19 | * limitations under the License. |
Pawel Zarembski |
0:01f31e923fe2 | 20 | */ |
Pawel Zarembski |
0:01f31e923fe2 | 21 | |
Pawel Zarembski |
0:01f31e923fe2 | 22 | #include "rt_TypeDef.h" |
Pawel Zarembski |
0:01f31e923fe2 | 23 | #include "RTX_Config.h" |
Pawel Zarembski |
0:01f31e923fe2 | 24 | #include "rt_System.h" |
Pawel Zarembski |
0:01f31e923fe2 | 25 | #include "rt_Task.h" |
Pawel Zarembski |
0:01f31e923fe2 | 26 | #include "rt_List.h" |
Pawel Zarembski |
0:01f31e923fe2 | 27 | #include "rt_MemBox.h" |
Pawel Zarembski |
0:01f31e923fe2 | 28 | #include "rt_Robin.h" |
Pawel Zarembski |
0:01f31e923fe2 | 29 | #include "rt_HAL_CM.h" |
Pawel Zarembski |
0:01f31e923fe2 | 30 | |
Pawel Zarembski |
0:01f31e923fe2 | 31 | /*---------------------------------------------------------------------------- |
Pawel Zarembski |
0:01f31e923fe2 | 32 | * Global Variables |
Pawel Zarembski |
0:01f31e923fe2 | 33 | *---------------------------------------------------------------------------*/ |
Pawel Zarembski |
0:01f31e923fe2 | 34 | |
Pawel Zarembski |
0:01f31e923fe2 | 35 | /* Running and next task info. */ |
Pawel Zarembski |
0:01f31e923fe2 | 36 | struct OS_TSK os_tsk; |
Pawel Zarembski |
0:01f31e923fe2 | 37 | |
Pawel Zarembski |
0:01f31e923fe2 | 38 | /* Task Control Blocks of idle demon */ |
Pawel Zarembski |
0:01f31e923fe2 | 39 | struct OS_TCB os_idle_TCB; |
Pawel Zarembski |
0:01f31e923fe2 | 40 | |
Pawel Zarembski |
0:01f31e923fe2 | 41 | |
Pawel Zarembski |
0:01f31e923fe2 | 42 | /*---------------------------------------------------------------------------- |
Pawel Zarembski |
0:01f31e923fe2 | 43 | * Local Functions |
Pawel Zarembski |
0:01f31e923fe2 | 44 | *---------------------------------------------------------------------------*/ |
Pawel Zarembski |
0:01f31e923fe2 | 45 | |
Pawel Zarembski |
0:01f31e923fe2 | 46 | static OS_TID rt_get_TID (void) { |
Pawel Zarembski |
0:01f31e923fe2 | 47 | U32 tid; |
Pawel Zarembski |
0:01f31e923fe2 | 48 | |
Pawel Zarembski |
0:01f31e923fe2 | 49 | for (tid = 1; tid <= os_maxtaskrun; tid++) { |
Pawel Zarembski |
0:01f31e923fe2 | 50 | if (os_active_TCB[tid-1] == NULL) { |
Pawel Zarembski |
0:01f31e923fe2 | 51 | return ((OS_TID)tid); |
Pawel Zarembski |
0:01f31e923fe2 | 52 | } |
Pawel Zarembski |
0:01f31e923fe2 | 53 | } |
Pawel Zarembski |
0:01f31e923fe2 | 54 | return (0); |
Pawel Zarembski |
0:01f31e923fe2 | 55 | } |
Pawel Zarembski |
0:01f31e923fe2 | 56 | |
Pawel Zarembski |
0:01f31e923fe2 | 57 | |
Pawel Zarembski |
0:01f31e923fe2 | 58 | /*--------------------------- rt_init_context -------------------------------*/ |
Pawel Zarembski |
0:01f31e923fe2 | 59 | |
Pawel Zarembski |
0:01f31e923fe2 | 60 | static void rt_init_context (P_TCB p_TCB, U8 priority, FUNCP task_body) { |
Pawel Zarembski |
0:01f31e923fe2 | 61 | /* Initialize general part of the Task Control Block. */ |
Pawel Zarembski |
0:01f31e923fe2 | 62 | p_TCB->cb_type = TCB; |
Pawel Zarembski |
0:01f31e923fe2 | 63 | p_TCB->state = READY; |
Pawel Zarembski |
0:01f31e923fe2 | 64 | p_TCB->prio = priority; |
Pawel Zarembski |
0:01f31e923fe2 | 65 | p_TCB->p_lnk = NULL; |
Pawel Zarembski |
0:01f31e923fe2 | 66 | p_TCB->p_rlnk = NULL; |
Pawel Zarembski |
0:01f31e923fe2 | 67 | p_TCB->p_dlnk = NULL; |
Pawel Zarembski |
0:01f31e923fe2 | 68 | p_TCB->p_blnk = NULL; |
Pawel Zarembski |
0:01f31e923fe2 | 69 | p_TCB->delta_time = 0; |
Pawel Zarembski |
0:01f31e923fe2 | 70 | p_TCB->interval_time = 0; |
Pawel Zarembski |
0:01f31e923fe2 | 71 | p_TCB->events = 0; |
Pawel Zarembski |
0:01f31e923fe2 | 72 | p_TCB->waits = 0; |
Pawel Zarembski |
0:01f31e923fe2 | 73 | p_TCB->ret_val = OS_R_OK; |
Pawel Zarembski |
0:01f31e923fe2 | 74 | p_TCB->ret_upd = 0; |
Pawel Zarembski |
0:01f31e923fe2 | 75 | |
Pawel Zarembski |
0:01f31e923fe2 | 76 | if (p_TCB->priv_stack == 0) { |
Pawel Zarembski |
0:01f31e923fe2 | 77 | /* Allocate the memory space for the stack. */ |
Pawel Zarembski |
0:01f31e923fe2 | 78 | p_TCB->stack = rt_alloc_box (mp_stk); |
Pawel Zarembski |
0:01f31e923fe2 | 79 | } |
Pawel Zarembski |
0:01f31e923fe2 | 80 | rt_init_stack (p_TCB, task_body); |
Pawel Zarembski |
0:01f31e923fe2 | 81 | } |
Pawel Zarembski |
0:01f31e923fe2 | 82 | |
Pawel Zarembski |
0:01f31e923fe2 | 83 | |
Pawel Zarembski |
0:01f31e923fe2 | 84 | /*--------------------------- rt_switch_req ---------------------------------*/ |
Pawel Zarembski |
0:01f31e923fe2 | 85 | |
Pawel Zarembski |
0:01f31e923fe2 | 86 | void rt_switch_req (P_TCB p_new) { |
Pawel Zarembski |
0:01f31e923fe2 | 87 | /* Switch to next task (identified by "p_new"). */ |
Pawel Zarembski |
0:01f31e923fe2 | 88 | os_tsk.new = p_new; |
Pawel Zarembski |
0:01f31e923fe2 | 89 | p_new->state = RUNNING; |
Pawel Zarembski |
0:01f31e923fe2 | 90 | DBG_TASK_SWITCH(p_new->task_id); |
Pawel Zarembski |
0:01f31e923fe2 | 91 | } |
Pawel Zarembski |
0:01f31e923fe2 | 92 | |
Pawel Zarembski |
0:01f31e923fe2 | 93 | |
Pawel Zarembski |
0:01f31e923fe2 | 94 | /*--------------------------- rt_dispatch -----------------------------------*/ |
Pawel Zarembski |
0:01f31e923fe2 | 95 | |
Pawel Zarembski |
0:01f31e923fe2 | 96 | void rt_dispatch (P_TCB next_TCB) { |
Pawel Zarembski |
0:01f31e923fe2 | 97 | /* Dispatch next task if any identified or dispatch highest ready task */ |
Pawel Zarembski |
0:01f31e923fe2 | 98 | /* "next_TCB" identifies a task to run or has value NULL (=no next task) */ |
Pawel Zarembski |
0:01f31e923fe2 | 99 | if (next_TCB == NULL) { |
Pawel Zarembski |
0:01f31e923fe2 | 100 | /* Running task was blocked: continue with highest ready task */ |
Pawel Zarembski |
0:01f31e923fe2 | 101 | next_TCB = rt_get_first (&os_rdy); |
Pawel Zarembski |
0:01f31e923fe2 | 102 | rt_switch_req (next_TCB); |
Pawel Zarembski |
0:01f31e923fe2 | 103 | } |
Pawel Zarembski |
0:01f31e923fe2 | 104 | else { |
Pawel Zarembski |
0:01f31e923fe2 | 105 | /* Check which task continues */ |
Pawel Zarembski |
0:01f31e923fe2 | 106 | if (next_TCB->prio > os_tsk.run->prio) { |
Pawel Zarembski |
0:01f31e923fe2 | 107 | /* preempt running task */ |
Pawel Zarembski |
0:01f31e923fe2 | 108 | rt_put_rdy_first (os_tsk.run); |
Pawel Zarembski |
0:01f31e923fe2 | 109 | os_tsk.run->state = READY; |
Pawel Zarembski |
0:01f31e923fe2 | 110 | rt_switch_req (next_TCB); |
Pawel Zarembski |
0:01f31e923fe2 | 111 | } |
Pawel Zarembski |
0:01f31e923fe2 | 112 | else { |
Pawel Zarembski |
0:01f31e923fe2 | 113 | /* put next task into ready list, no task switch takes place */ |
Pawel Zarembski |
0:01f31e923fe2 | 114 | next_TCB->state = READY; |
Pawel Zarembski |
0:01f31e923fe2 | 115 | rt_put_prio (&os_rdy, next_TCB); |
Pawel Zarembski |
0:01f31e923fe2 | 116 | } |
Pawel Zarembski |
0:01f31e923fe2 | 117 | } |
Pawel Zarembski |
0:01f31e923fe2 | 118 | } |
Pawel Zarembski |
0:01f31e923fe2 | 119 | |
Pawel Zarembski |
0:01f31e923fe2 | 120 | |
Pawel Zarembski |
0:01f31e923fe2 | 121 | /*--------------------------- rt_block --------------------------------------*/ |
Pawel Zarembski |
0:01f31e923fe2 | 122 | |
Pawel Zarembski |
0:01f31e923fe2 | 123 | void rt_block (U16 timeout, U8 block_state) { |
Pawel Zarembski |
0:01f31e923fe2 | 124 | /* Block running task and choose next ready task. */ |
Pawel Zarembski |
0:01f31e923fe2 | 125 | /* "timeout" sets a time-out value or is 0xffff (=no time-out). */ |
Pawel Zarembski |
0:01f31e923fe2 | 126 | /* "block_state" defines the appropriate task state */ |
Pawel Zarembski |
0:01f31e923fe2 | 127 | P_TCB next_TCB; |
Pawel Zarembski |
0:01f31e923fe2 | 128 | |
Pawel Zarembski |
0:01f31e923fe2 | 129 | if (timeout) { |
Pawel Zarembski |
0:01f31e923fe2 | 130 | if (timeout < 0xffff) { |
Pawel Zarembski |
0:01f31e923fe2 | 131 | rt_put_dly (os_tsk.run, timeout); |
Pawel Zarembski |
0:01f31e923fe2 | 132 | } |
Pawel Zarembski |
0:01f31e923fe2 | 133 | os_tsk.run->state = block_state; |
Pawel Zarembski |
0:01f31e923fe2 | 134 | next_TCB = rt_get_first (&os_rdy); |
Pawel Zarembski |
0:01f31e923fe2 | 135 | rt_switch_req (next_TCB); |
Pawel Zarembski |
0:01f31e923fe2 | 136 | } |
Pawel Zarembski |
0:01f31e923fe2 | 137 | } |
Pawel Zarembski |
0:01f31e923fe2 | 138 | |
Pawel Zarembski |
0:01f31e923fe2 | 139 | |
Pawel Zarembski |
0:01f31e923fe2 | 140 | /*--------------------------- rt_tsk_pass -----------------------------------*/ |
Pawel Zarembski |
0:01f31e923fe2 | 141 | |
Pawel Zarembski |
0:01f31e923fe2 | 142 | void rt_tsk_pass (void) { |
Pawel Zarembski |
0:01f31e923fe2 | 143 | /* Allow tasks of same priority level to run cooperatively.*/ |
Pawel Zarembski |
0:01f31e923fe2 | 144 | P_TCB p_new; |
Pawel Zarembski |
0:01f31e923fe2 | 145 | |
Pawel Zarembski |
0:01f31e923fe2 | 146 | p_new = rt_get_same_rdy_prio(); |
Pawel Zarembski |
0:01f31e923fe2 | 147 | if (p_new != NULL) { |
Pawel Zarembski |
0:01f31e923fe2 | 148 | rt_put_prio ((P_XCB)&os_rdy, os_tsk.run); |
Pawel Zarembski |
0:01f31e923fe2 | 149 | os_tsk.run->state = READY; |
Pawel Zarembski |
0:01f31e923fe2 | 150 | rt_switch_req (p_new); |
Pawel Zarembski |
0:01f31e923fe2 | 151 | } |
Pawel Zarembski |
0:01f31e923fe2 | 152 | } |
Pawel Zarembski |
0:01f31e923fe2 | 153 | |
Pawel Zarembski |
0:01f31e923fe2 | 154 | |
Pawel Zarembski |
0:01f31e923fe2 | 155 | /*--------------------------- rt_tsk_self -----------------------------------*/ |
Pawel Zarembski |
0:01f31e923fe2 | 156 | |
Pawel Zarembski |
0:01f31e923fe2 | 157 | OS_TID rt_tsk_self (void) { |
Pawel Zarembski |
0:01f31e923fe2 | 158 | /* Return own task identifier value. */ |
Pawel Zarembski |
0:01f31e923fe2 | 159 | if (os_tsk.run == NULL) { |
Pawel Zarembski |
0:01f31e923fe2 | 160 | return (0); |
Pawel Zarembski |
0:01f31e923fe2 | 161 | } |
Pawel Zarembski |
0:01f31e923fe2 | 162 | return (os_tsk.run->task_id); |
Pawel Zarembski |
0:01f31e923fe2 | 163 | } |
Pawel Zarembski |
0:01f31e923fe2 | 164 | |
Pawel Zarembski |
0:01f31e923fe2 | 165 | |
Pawel Zarembski |
0:01f31e923fe2 | 166 | /*--------------------------- rt_tsk_prio -----------------------------------*/ |
Pawel Zarembski |
0:01f31e923fe2 | 167 | |
Pawel Zarembski |
0:01f31e923fe2 | 168 | OS_RESULT rt_tsk_prio (OS_TID task_id, U8 new_prio) { |
Pawel Zarembski |
0:01f31e923fe2 | 169 | /* Change execution priority of a task to "new_prio". */ |
Pawel Zarembski |
0:01f31e923fe2 | 170 | P_TCB p_task; |
Pawel Zarembski |
0:01f31e923fe2 | 171 | |
Pawel Zarembski |
0:01f31e923fe2 | 172 | if (task_id == 0) { |
Pawel Zarembski |
0:01f31e923fe2 | 173 | /* Change execution priority of calling task. */ |
Pawel Zarembski |
0:01f31e923fe2 | 174 | os_tsk.run->prio = new_prio; |
Pawel Zarembski |
0:01f31e923fe2 | 175 | run:if (rt_rdy_prio() > new_prio) { |
Pawel Zarembski |
0:01f31e923fe2 | 176 | rt_put_prio (&os_rdy, os_tsk.run); |
Pawel Zarembski |
0:01f31e923fe2 | 177 | os_tsk.run->state = READY; |
Pawel Zarembski |
0:01f31e923fe2 | 178 | os_tsk.run->ret_val = OS_R_OK; |
Pawel Zarembski |
0:01f31e923fe2 | 179 | rt_dispatch (NULL); |
Pawel Zarembski |
0:01f31e923fe2 | 180 | } |
Pawel Zarembski |
0:01f31e923fe2 | 181 | return (OS_R_OK); |
Pawel Zarembski |
0:01f31e923fe2 | 182 | } |
Pawel Zarembski |
0:01f31e923fe2 | 183 | |
Pawel Zarembski |
0:01f31e923fe2 | 184 | /* Find the task in the "os_active_TCB" array. */ |
Pawel Zarembski |
0:01f31e923fe2 | 185 | if (task_id > os_maxtaskrun || os_active_TCB[task_id-1] == NULL) { |
Pawel Zarembski |
0:01f31e923fe2 | 186 | /* Task with "task_id" not found or not started. */ |
Pawel Zarembski |
0:01f31e923fe2 | 187 | return (OS_R_NOK); |
Pawel Zarembski |
0:01f31e923fe2 | 188 | } |
Pawel Zarembski |
0:01f31e923fe2 | 189 | p_task = os_active_TCB[task_id-1]; |
Pawel Zarembski |
0:01f31e923fe2 | 190 | p_task->prio = new_prio; |
Pawel Zarembski |
0:01f31e923fe2 | 191 | if (p_task == os_tsk.run) { |
Pawel Zarembski |
0:01f31e923fe2 | 192 | goto run; |
Pawel Zarembski |
0:01f31e923fe2 | 193 | } |
Pawel Zarembski |
0:01f31e923fe2 | 194 | rt_resort_prio (p_task); |
Pawel Zarembski |
0:01f31e923fe2 | 195 | if (p_task->state == READY) { |
Pawel Zarembski |
0:01f31e923fe2 | 196 | /* Task enqueued in a ready list. */ |
Pawel Zarembski |
0:01f31e923fe2 | 197 | p_task = rt_get_first (&os_rdy); |
Pawel Zarembski |
0:01f31e923fe2 | 198 | os_tsk.run->ret_val = OS_R_OK; |
Pawel Zarembski |
0:01f31e923fe2 | 199 | rt_dispatch (p_task); |
Pawel Zarembski |
0:01f31e923fe2 | 200 | } |
Pawel Zarembski |
0:01f31e923fe2 | 201 | return (OS_R_OK); |
Pawel Zarembski |
0:01f31e923fe2 | 202 | } |
Pawel Zarembski |
0:01f31e923fe2 | 203 | |
Pawel Zarembski |
0:01f31e923fe2 | 204 | |
Pawel Zarembski |
0:01f31e923fe2 | 205 | /*--------------------------- rt_tsk_create ---------------------------------*/ |
Pawel Zarembski |
0:01f31e923fe2 | 206 | |
Pawel Zarembski |
0:01f31e923fe2 | 207 | OS_TID rt_tsk_create (FUNCP task, U32 prio_stksz, void *stk, void *argv) { |
Pawel Zarembski |
0:01f31e923fe2 | 208 | /* Start a new task declared with "task". */ |
Pawel Zarembski |
0:01f31e923fe2 | 209 | P_TCB task_context; |
Pawel Zarembski |
0:01f31e923fe2 | 210 | U32 i; |
Pawel Zarembski |
0:01f31e923fe2 | 211 | |
Pawel Zarembski |
0:01f31e923fe2 | 212 | /* Priority 0 is reserved for idle task! */ |
Pawel Zarembski |
0:01f31e923fe2 | 213 | if ((prio_stksz & 0xFF) == 0) { |
Pawel Zarembski |
0:01f31e923fe2 | 214 | prio_stksz += 1; |
Pawel Zarembski |
0:01f31e923fe2 | 215 | } |
Pawel Zarembski |
0:01f31e923fe2 | 216 | task_context = rt_alloc_box (mp_tcb); |
Pawel Zarembski |
0:01f31e923fe2 | 217 | if (task_context == NULL) { |
Pawel Zarembski |
0:01f31e923fe2 | 218 | return (0); |
Pawel Zarembski |
0:01f31e923fe2 | 219 | } |
Pawel Zarembski |
0:01f31e923fe2 | 220 | /* If "size != 0" use a private user provided stack. */ |
Pawel Zarembski |
0:01f31e923fe2 | 221 | task_context->stack = stk; |
Pawel Zarembski |
0:01f31e923fe2 | 222 | task_context->priv_stack = prio_stksz >> 8; |
Pawel Zarembski |
0:01f31e923fe2 | 223 | /* Pass parameter 'argv' to 'rt_init_context' */ |
Pawel Zarembski |
0:01f31e923fe2 | 224 | task_context->msg = argv; |
Pawel Zarembski |
0:01f31e923fe2 | 225 | /* For 'size == 0' system allocates the user stack from the memory pool. */ |
Pawel Zarembski |
0:01f31e923fe2 | 226 | rt_init_context (task_context, prio_stksz & 0xFF, task); |
Pawel Zarembski |
0:01f31e923fe2 | 227 | |
Pawel Zarembski |
0:01f31e923fe2 | 228 | /* Find a free entry in 'os_active_TCB' table. */ |
Pawel Zarembski |
0:01f31e923fe2 | 229 | i = rt_get_TID (); |
Pawel Zarembski |
0:01f31e923fe2 | 230 | os_active_TCB[i-1] = task_context; |
Pawel Zarembski |
0:01f31e923fe2 | 231 | task_context->task_id = i; |
Pawel Zarembski |
0:01f31e923fe2 | 232 | DBG_TASK_NOTIFY(task_context, __TRUE); |
Pawel Zarembski |
0:01f31e923fe2 | 233 | rt_dispatch (task_context); |
Pawel Zarembski |
0:01f31e923fe2 | 234 | os_tsk.run->ret_val = i; |
Pawel Zarembski |
0:01f31e923fe2 | 235 | return ((OS_TID)i); |
Pawel Zarembski |
0:01f31e923fe2 | 236 | } |
Pawel Zarembski |
0:01f31e923fe2 | 237 | |
Pawel Zarembski |
0:01f31e923fe2 | 238 | |
Pawel Zarembski |
0:01f31e923fe2 | 239 | /*--------------------------- rt_tsk_delete ---------------------------------*/ |
Pawel Zarembski |
0:01f31e923fe2 | 240 | |
Pawel Zarembski |
0:01f31e923fe2 | 241 | OS_RESULT rt_tsk_delete (OS_TID task_id) { |
Pawel Zarembski |
0:01f31e923fe2 | 242 | /* Terminate the task identified with "task_id". */ |
Pawel Zarembski |
0:01f31e923fe2 | 243 | P_TCB task_context; |
Pawel Zarembski |
0:01f31e923fe2 | 244 | |
Pawel Zarembski |
0:01f31e923fe2 | 245 | if (task_id == 0 || task_id == os_tsk.run->task_id) { |
Pawel Zarembski |
0:01f31e923fe2 | 246 | /* Terminate itself. */ |
Pawel Zarembski |
0:01f31e923fe2 | 247 | os_tsk.run->state = INACTIVE; |
Pawel Zarembski |
0:01f31e923fe2 | 248 | os_tsk.run->tsk_stack = rt_get_PSP (); |
Pawel Zarembski |
0:01f31e923fe2 | 249 | rt_stk_check (); |
Pawel Zarembski |
0:01f31e923fe2 | 250 | os_active_TCB[os_tsk.run->task_id-1] = NULL; |
Pawel Zarembski |
0:01f31e923fe2 | 251 | rt_free_box (mp_stk, os_tsk.run->stack); |
Pawel Zarembski |
0:01f31e923fe2 | 252 | os_tsk.run->stack = NULL; |
Pawel Zarembski |
0:01f31e923fe2 | 253 | DBG_TASK_NOTIFY(os_tsk.run, __FALSE); |
Pawel Zarembski |
0:01f31e923fe2 | 254 | rt_free_box (mp_tcb, os_tsk.run); |
Pawel Zarembski |
0:01f31e923fe2 | 255 | os_tsk.run = NULL; |
Pawel Zarembski |
0:01f31e923fe2 | 256 | rt_dispatch (NULL); |
Pawel Zarembski |
0:01f31e923fe2 | 257 | /* The program should never come to this point. */ |
Pawel Zarembski |
0:01f31e923fe2 | 258 | } |
Pawel Zarembski |
0:01f31e923fe2 | 259 | else { |
Pawel Zarembski |
0:01f31e923fe2 | 260 | /* Find the task in the "os_active_TCB" array. */ |
Pawel Zarembski |
0:01f31e923fe2 | 261 | if (task_id > os_maxtaskrun || os_active_TCB[task_id-1] == NULL) { |
Pawel Zarembski |
0:01f31e923fe2 | 262 | /* Task with "task_id" not found or not started. */ |
Pawel Zarembski |
0:01f31e923fe2 | 263 | return (OS_R_NOK); |
Pawel Zarembski |
0:01f31e923fe2 | 264 | } |
Pawel Zarembski |
0:01f31e923fe2 | 265 | task_context = os_active_TCB[task_id-1]; |
Pawel Zarembski |
0:01f31e923fe2 | 266 | rt_rmv_list (task_context); |
Pawel Zarembski |
0:01f31e923fe2 | 267 | rt_rmv_dly (task_context); |
Pawel Zarembski |
0:01f31e923fe2 | 268 | os_active_TCB[task_id-1] = NULL; |
Pawel Zarembski |
0:01f31e923fe2 | 269 | rt_free_box (mp_stk, task_context->stack); |
Pawel Zarembski |
0:01f31e923fe2 | 270 | task_context->stack = NULL; |
Pawel Zarembski |
0:01f31e923fe2 | 271 | DBG_TASK_NOTIFY(task_context, __FALSE); |
Pawel Zarembski |
0:01f31e923fe2 | 272 | rt_free_box (mp_tcb, task_context); |
Pawel Zarembski |
0:01f31e923fe2 | 273 | } |
Pawel Zarembski |
0:01f31e923fe2 | 274 | return (OS_R_OK); |
Pawel Zarembski |
0:01f31e923fe2 | 275 | } |
Pawel Zarembski |
0:01f31e923fe2 | 276 | |
Pawel Zarembski |
0:01f31e923fe2 | 277 | |
Pawel Zarembski |
0:01f31e923fe2 | 278 | /*--------------------------- rt_sys_init -----------------------------------*/ |
Pawel Zarembski |
0:01f31e923fe2 | 279 | |
Pawel Zarembski |
0:01f31e923fe2 | 280 | void rt_sys_init (FUNCP first_task, U32 prio_stksz, void *stk) { |
Pawel Zarembski |
0:01f31e923fe2 | 281 | /* Initialize system and start up task declared with "first_task". */ |
Pawel Zarembski |
0:01f31e923fe2 | 282 | U32 i; |
Pawel Zarembski |
0:01f31e923fe2 | 283 | |
Pawel Zarembski |
0:01f31e923fe2 | 284 | DBG_INIT(); |
Pawel Zarembski |
0:01f31e923fe2 | 285 | |
Pawel Zarembski |
0:01f31e923fe2 | 286 | /* Initialize dynamic memory and task TCB pointers to NULL. */ |
Pawel Zarembski |
0:01f31e923fe2 | 287 | for (i = 0; i < os_maxtaskrun; i++) { |
Pawel Zarembski |
0:01f31e923fe2 | 288 | os_active_TCB[i] = NULL; |
Pawel Zarembski |
0:01f31e923fe2 | 289 | } |
Pawel Zarembski |
0:01f31e923fe2 | 290 | rt_init_box (&mp_tcb, mp_tcb_size, sizeof(struct OS_TCB)); |
Pawel Zarembski |
0:01f31e923fe2 | 291 | rt_init_box (&mp_stk, mp_stk_size, BOX_ALIGN_8 | (U16)(os_stackinfo)); |
Pawel Zarembski |
0:01f31e923fe2 | 292 | rt_init_box ((U32 *)m_tmr, mp_tmr_size, sizeof(struct OS_TMR)); |
Pawel Zarembski |
0:01f31e923fe2 | 293 | |
Pawel Zarembski |
0:01f31e923fe2 | 294 | /* Set up TCB of idle demon */ |
Pawel Zarembski |
0:01f31e923fe2 | 295 | os_idle_TCB.task_id = 255; |
Pawel Zarembski |
0:01f31e923fe2 | 296 | os_idle_TCB.priv_stack = 0; |
Pawel Zarembski |
0:01f31e923fe2 | 297 | rt_init_context (&os_idle_TCB, 0, os_idle_demon); |
Pawel Zarembski |
0:01f31e923fe2 | 298 | |
Pawel Zarembski |
0:01f31e923fe2 | 299 | /* Set up ready list: initially empty */ |
Pawel Zarembski |
0:01f31e923fe2 | 300 | os_rdy.cb_type = HCB; |
Pawel Zarembski |
0:01f31e923fe2 | 301 | os_rdy.p_lnk = NULL; |
Pawel Zarembski |
0:01f31e923fe2 | 302 | /* Set up delay list: initially empty */ |
Pawel Zarembski |
0:01f31e923fe2 | 303 | os_dly.cb_type = HCB; |
Pawel Zarembski |
0:01f31e923fe2 | 304 | os_dly.p_dlnk = NULL; |
Pawel Zarembski |
0:01f31e923fe2 | 305 | os_dly.p_blnk = NULL; |
Pawel Zarembski |
0:01f31e923fe2 | 306 | os_dly.delta_time = 0; |
Pawel Zarembski |
0:01f31e923fe2 | 307 | |
Pawel Zarembski |
0:01f31e923fe2 | 308 | /* Fix SP and systemvariables to assume idle task is running */ |
Pawel Zarembski |
0:01f31e923fe2 | 309 | /* Transform main program into idle task by assuming idle TCB */ |
Pawel Zarembski |
0:01f31e923fe2 | 310 | rt_set_PSP (os_idle_TCB.tsk_stack+32); |
Pawel Zarembski |
0:01f31e923fe2 | 311 | os_tsk.run = &os_idle_TCB; |
Pawel Zarembski |
0:01f31e923fe2 | 312 | os_tsk.run->state = RUNNING; |
Pawel Zarembski |
0:01f31e923fe2 | 313 | |
Pawel Zarembski |
0:01f31e923fe2 | 314 | /* Initialize ps queue */ |
Pawel Zarembski |
0:01f31e923fe2 | 315 | os_psq->first = 0; |
Pawel Zarembski |
0:01f31e923fe2 | 316 | os_psq->last = 0; |
Pawel Zarembski |
0:01f31e923fe2 | 317 | os_psq->size = os_fifo_size; |
Pawel Zarembski |
0:01f31e923fe2 | 318 | |
Pawel Zarembski |
0:01f31e923fe2 | 319 | rt_init_robin (); |
Pawel Zarembski |
0:01f31e923fe2 | 320 | |
Pawel Zarembski |
0:01f31e923fe2 | 321 | /* Intitialize SVC and PendSV */ |
Pawel Zarembski |
0:01f31e923fe2 | 322 | rt_svc_init (); |
Pawel Zarembski |
0:01f31e923fe2 | 323 | |
Pawel Zarembski |
0:01f31e923fe2 | 324 | /* Intitialize system clock timer */ |
Pawel Zarembski |
0:01f31e923fe2 | 325 | os_tick_irqn = os_tick_init (); |
Pawel Zarembski |
0:01f31e923fe2 | 326 | if (os_tick_irqn >= 0) { |
Pawel Zarembski |
0:01f31e923fe2 | 327 | OS_X_INIT(os_tick_irqn); |
Pawel Zarembski |
0:01f31e923fe2 | 328 | } |
Pawel Zarembski |
0:01f31e923fe2 | 329 | |
Pawel Zarembski |
0:01f31e923fe2 | 330 | /* Start up first user task before entering the endless loop */ |
Pawel Zarembski |
0:01f31e923fe2 | 331 | rt_tsk_create (first_task, prio_stksz, stk, NULL); |
Pawel Zarembski |
0:01f31e923fe2 | 332 | } |
Pawel Zarembski |
0:01f31e923fe2 | 333 | |
Pawel Zarembski |
0:01f31e923fe2 | 334 | /*---------------------------------------------------------------------------- |
Pawel Zarembski |
0:01f31e923fe2 | 335 | * end of file |
Pawel Zarembski |
0:01f31e923fe2 | 336 | *---------------------------------------------------------------------------*/ |