-
Notifications
You must be signed in to change notification settings - Fork 0
/
act_tsk.c
103 lines (80 loc) · 1.8 KB
/
act_tsk.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/**
act_tsk.c
Copyright (c) 2013-2021 Akihisa ONODA
This software is released under the MIT License.
http://opensource.org/licenses/mit-license.php
*/
#include <defines.h>
#include <itron.h>
#include <kernel.h>
#include <kernel_id.h>
#include <service_call.h>
#include <task.h>
#include <lib.h>
extern T_TCB task_control_blocks[];
ER
act_tsk(ID tskid)
{
U_SPRM prm;
prm.act_tsk.ret = E_OK;
prm.act_tsk.tskid = tskid;
service_call(SCID_ACT_TSK, &prm);
return prm.act_tsk.ret;
}
ER
act_tsk_body(ID tskid)
{
ER ret;
ret = act_tsk_common(tskid, 1);
return ret;
}
ER
iact_tsk(ID tskid)
{
U_SPRM prm;
prm.iact_tsk.ret = E_OK;
prm.iact_tsk.tskid = tskid;
iservice_call(SCID_IACT_TSK, &prm);
return prm.iact_tsk.ret;
}
ER
iact_tsk_body(ID tskid)
{
ER ret;
ret = act_tsk_common(tskid, 1);
return ret;
}
ER
act_tsk_common(ID tskid, UW flg)
{
VP_INT *sp;
int idx = TSKID_IDX(tskid);
ER ret = E_OK;
task_control_blocks[idx].npri = task_control_blocks[idx].bpri;
/* stackの初期化 */
sp = (VP_INT *)task_control_blocks[idx].stk;
*(--sp) = (VP_INT)0x01000000; /* EPSR.T=1 */
*(--sp) = (VP_INT)task_execute; /* R15(PC) */
*(--sp) = (VP_INT)task_terminate; /* R14(LR): タスク終了時の戻り先 */
*(--sp) = 0; /* R12 */
*(--sp) = 0; /* R3 */
*(--sp) = 0; /* R2 */
*(--sp) = 0; /* R1 */
*(--sp) = (VP_INT)&task_control_blocks[idx]; /* R0 */
*(--sp) = 0; /* R7 */
*(--sp) = 0; /* R6 */
*(--sp) = 0; /* R5 */
*(--sp) = 0; /* R4 */
*(--sp) = 0; /* R11 */
*(--sp) = 0; /* R10 */
*(--sp) = 0; /* R9 */
*(--sp) = 0; /* R8 */
task_control_blocks[idx].ctx.sp = (VP_INT)sp;
/* readyqueueに繋ぐ */
ret = task_push_queue(&(task_control_blocks[idx]));
if (flg) {
/* dispatch */
task_reschedule();
}
return ret;
}