source: UsbWattMeter/trunk/asp_dcre/kernel/task_refer.c@ 164

Last change on this file since 164 was 164, checked in by coas-nagasima, 6 years ago

TOPPERS/ECNLサンプルアプリ「USB充電器電力計」を追加

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-csrc
File size: 5.5 KB
Line 
1/*
2 * TOPPERS/ASP Kernel
3 * Toyohashi Open Platform for Embedded Real-Time Systems/
4 * Advanced Standard Profile Kernel
5 *
6 * Copyright (C) 2005-2014 by Embedded and Real-Time Systems Laboratory
7 * Graduate School of Information Science, Nagoya Univ., JAPAN
8 *
9 * ã‹L’˜ìŒ ŽÒ‚́CˆÈ‰º‚Ì(1)`(4)‚ÌðŒ‚ð–ž‚½‚·ê‡‚ÉŒÀ‚èC–{ƒ\ƒtƒgƒEƒF
10 * ƒAi–{ƒ\ƒtƒgƒEƒFƒA‚ð‰ü•Ï‚µ‚½‚à‚Ì‚ðŠÜ‚ށDˆÈ‰º“¯‚¶j‚ðŽg—pE•¡»E‰ü
11 * •ÏEÄ”z•ziˆÈ‰ºC—˜—p‚ƌĂԁj‚·‚邱‚Ƃ𖳏ž‚Å‹–‘ø‚·‚éD
12 * (1) –{ƒ\ƒtƒgƒEƒFƒA‚ðƒ\[ƒXƒR[ƒh‚ÌŒ`‚Å—˜—p‚·‚éê‡‚ɂ́Cã‹L‚Ì’˜ì
13 * Œ •\Ž¦C‚±‚Ì—˜—pðŒ‚¨‚æ‚щº‹L‚Ì–³•ÛØ‹K’肪C‚»‚Ì‚Ü‚Ü‚ÌŒ`‚Ń\[
14 * ƒXƒR[ƒh’†‚ÉŠÜ‚Ü‚ê‚Ä‚¢‚邱‚ƁD
15 * (2) –{ƒ\ƒtƒgƒEƒFƒA‚ðCƒ‰ƒCƒuƒ‰ƒŠŒ`Ž®‚ȂǁC‘¼‚̃\ƒtƒgƒEƒFƒAŠJ”­‚ÉŽg
16 * —p‚Å‚«‚éŒ`‚ōĔz•z‚·‚éê‡‚ɂ́CÄ”z•z‚É”º‚¤ƒhƒLƒ…
17ƒƒ“ƒgi—˜—p
18 * ŽÒƒ}ƒjƒ…
19ƒAƒ‹‚Ȃǁj‚ɁCã‹L‚Ì’˜ìŒ •\Ž¦C‚±‚Ì—˜—pðŒ‚¨‚æ‚щº‹L
20 * ‚Ì–³•ÛØ‹K’è‚ðŒfÚ‚·‚邱‚ƁD
21 * (3) –{ƒ\ƒtƒgƒEƒFƒA‚ðC‹@Ší‚É‘g‚ݍž‚ނȂǁC‘¼‚̃\ƒtƒgƒEƒFƒAŠJ”­‚ÉŽg
22 * —p‚Å‚«‚È‚¢Œ`‚ōĔz•z‚·‚éê‡‚ɂ́CŽŸ‚Ì‚¢‚¸‚ê‚©‚ÌðŒ‚ð–ž‚½‚·‚±
23 * ‚ƁD
24 * (a) Ä”z•z‚É”º‚¤ƒhƒLƒ…
25ƒƒ“ƒgi—˜—pŽÒƒ}ƒjƒ…
26ƒAƒ‹‚Ȃǁj‚ɁCã‹L‚Ì’˜
27 * ìŒ •\Ž¦C‚±‚Ì—˜—pðŒ‚¨‚æ‚щº‹L‚Ì–³•ÛØ‹K’è‚ðŒfÚ‚·‚邱‚ƁD
28 * (b) Ä”z•z‚ÌŒ`‘Ô‚ðC•Ê‚É’è‚ß‚é•û–@‚É‚æ‚Á‚āCTOPPERSƒvƒƒWƒFƒNƒg‚É
29 * •ñ‚·‚邱‚ƁD
30 * (4) –{ƒ\ƒtƒgƒEƒFƒA‚Ì—˜—p‚É‚æ‚è’¼Ú“I‚Ü‚½‚͊ԐړI‚ɐ¶‚¶‚é‚¢‚©‚Ȃ鑹
31 * ŠQ‚©‚ç‚àCã‹L’˜ìŒ ŽÒ‚¨‚æ‚ÑTOPPERSƒvƒƒWƒFƒNƒg‚ð–Ɛӂ·‚邱‚ƁD
32 * ‚Ü‚½C–{ƒ\ƒtƒgƒEƒFƒA‚̃†[ƒU‚Ü‚½‚̓Gƒ“ƒhƒ†[ƒU‚©‚ç‚Ì‚¢‚©‚Ȃ闝
33 * —R‚ÉŠî‚­¿‹‚©‚ç‚àCã‹L’˜ìŒ ŽÒ‚¨‚æ‚ÑTOPPERSƒvƒƒWƒFƒNƒg‚ð
34 * –Ɛӂ·‚邱‚ƁD
35 *
36 * –{ƒ\ƒtƒgƒEƒFƒA‚́C–³•ÛØ‚Å’ñ‹Ÿ‚³‚ê‚Ä‚¢‚é‚à‚Ì‚Å‚ ‚éDã‹L’˜ìŒ ŽÒ‚¨
37 * ‚æ‚ÑTOPPERSƒvƒƒWƒFƒNƒg‚́C–{ƒ\ƒtƒgƒEƒFƒA‚ÉŠÖ‚µ‚āC“Á’è‚ÌŽg—p–Ú“I
38 * ‚ɑ΂·‚é“K‡«‚àŠÜ‚߂āC‚¢‚©‚È‚é•ÛØ‚às‚í‚È‚¢D‚Ü‚½C–{ƒ\ƒtƒgƒEƒF
39 * ƒA‚Ì—˜—p‚É‚æ‚è’¼Ú“I‚Ü‚½‚͊ԐړI‚ɐ¶‚¶‚½‚¢‚©‚Ȃ鑹ŠQ‚ÉŠÖ‚µ‚Ä‚àC‚»
40 * ‚̐ӔC‚𕉂í‚È‚¢D
41 *
42 * @(#) $Id: task_refer.c 164 2016-03-07 11:33:50Z coas-nagasima $
43 */
44
45/*
46 * ƒ^ƒXƒN‚̏ó‘ÔŽQÆ‹@”\
47 */
48
49#include "kernel_impl.h"
50#include "check.h"
51#include "task.h"
52#include "wait.h"
53#include "semaphore.h"
54#include "eventflag.h"
55#include "dataqueue.h"
56#include "pridataq.h"
57#include "mailbox.h"
58#include "mempfix.h"
59#include "time_event.h"
60
61/*
62 * ƒgƒŒ[ƒXƒƒOƒ}ƒNƒ‚̃fƒtƒHƒ‹ƒg’è‹`
63 */
64#ifndef LOG_REF_TSK_ENTER
65#define LOG_REF_TSK_ENTER(tskid, pk_rtsk)
66#endif /* LOG_REF_TSK_ENTER */
67
68#ifndef LOG_REF_TSK_LEAVE
69#define LOG_REF_TSK_LEAVE(ercd, pk_rtsk)
70#endif /* LOG_REF_TSK_LEAVE */
71
72/*
73 * ƒ^ƒXƒN‚̏ó‘ÔŽQÆ
74 */
75#ifdef TOPPERS_ref_tsk
76
77ER
78ref_tsk(ID tskid, T_RTSK *pk_rtsk)
79{
80 TCB *p_tcb;
81 uint_t tstat;
82 ER ercd;
83
84 LOG_REF_TSK_ENTER(tskid, pk_rtsk);
85 CHECK_TSKCTX_UNL();
86 CHECK_TSKID_SELF(tskid);
87 p_tcb = get_tcb_self(tskid);
88
89 t_lock_cpu();
90 if (p_tcb->p_tinib->tskatr == TA_NOEXS) {
91 ercd = E_NOEXS;
92 }
93 else {
94 tstat = p_tcb->tstat;
95 if (TSTAT_DORMANT(tstat)) {
96 /*
97 * ‘Ώۃ^ƒXƒN‚ª‹xŽ~ó‘Ԃ̏ꍇ
98 */
99 pk_rtsk->tskstat = TTS_DMT;
100 }
101 else {
102 /*
103 * ƒ^ƒXƒNó‘Ô‚ÌŽæo‚µ
104 */
105 if (TSTAT_SUSPENDED(tstat)) {
106 if (TSTAT_WAITING(tstat)) {
107 pk_rtsk->tskstat = TTS_WAS;
108 }
109 else {
110 pk_rtsk->tskstat = TTS_SUS;
111 }
112 }
113 else if (TSTAT_WAITING(tstat)) {
114 pk_rtsk->tskstat = TTS_WAI;
115 }
116 else if (p_tcb == p_runtsk) {
117 pk_rtsk->tskstat = TTS_RUN;
118 }
119 else {
120 pk_rtsk->tskstat = TTS_RDY;
121 }
122
123 /*
124 * Œ»Ý—Dæ“x‚ƃx[ƒX—Dæ“x‚ÌŽæo‚µ
125 */
126 pk_rtsk->tskpri = EXT_TSKPRI(p_tcb->priority);
127 pk_rtsk->tskbpri = EXT_TSKPRI(p_tcb->priority);
128
129 if (TSTAT_WAITING(tstat)) {
130 /*
131 * ‘Ò‚¿—vˆö‚Æ‘Ò‚¿‘Ώۂ̃IƒuƒWƒFƒNƒg‚ÌID‚ÌŽæo‚µ
132 */
133 switch (tstat & TS_WAIT_MASK) {
134 case TS_WAIT_SLP:
135 pk_rtsk->tskwait = TTW_SLP;
136 break;
137 case TS_WAIT_DLY:
138 pk_rtsk->tskwait = TTW_DLY;
139 break;
140 case TS_WAIT_SEM:
141 pk_rtsk->tskwait = TTW_SEM;
142 pk_rtsk->wobjid = SEMID(((WINFO_SEM *)(p_tcb->p_winfo))
143 ->p_semcb);
144 break;
145 case TS_WAIT_FLG:
146 pk_rtsk->tskwait = TTW_FLG;
147 pk_rtsk->wobjid = FLGID(((WINFO_FLG *)(p_tcb->p_winfo))
148 ->p_flgcb);
149 break;
150 case TS_WAIT_SDTQ:
151 pk_rtsk->tskwait = TTW_SDTQ;
152 pk_rtsk->wobjid = DTQID(((WINFO_DTQ *)(p_tcb->p_winfo))
153 ->p_dtqcb);
154 break;
155 case TS_WAIT_RDTQ:
156 pk_rtsk->tskwait = TTW_RDTQ;
157 pk_rtsk->wobjid = DTQID(((WINFO_DTQ *)(p_tcb->p_winfo))
158 ->p_dtqcb);
159 break;
160 case TS_WAIT_SPDQ:
161 pk_rtsk->tskwait = TTW_SPDQ;
162 pk_rtsk->wobjid = PDQID(((WINFO_PDQ *)(p_tcb->p_winfo))
163 ->p_pdqcb);
164 break;
165 case TS_WAIT_RPDQ:
166 pk_rtsk->tskwait = TTW_RPDQ;
167 pk_rtsk->wobjid = PDQID(((WINFO_PDQ *)(p_tcb->p_winfo))
168 ->p_pdqcb);
169 break;
170 case TS_WAIT_MBX:
171 pk_rtsk->tskwait = TTW_MBX;
172 pk_rtsk->wobjid = MBXID(((WINFO_MBX *)(p_tcb->p_winfo))
173 ->p_mbxcb);
174 break;
175 case TS_WAIT_MPF:
176 pk_rtsk->tskwait = TTW_MPF;
177 pk_rtsk->wobjid = MPFID(((WINFO_MPF *)(p_tcb->p_winfo))
178 ->p_mpfcb);
179 break;
180 }
181
182 /*
183 * ƒ^ƒCƒ€ƒAƒEƒg‚·‚é‚Ü‚Å‚ÌŽžŠÔ‚ÌŽæo‚µ
184 */
185 if (p_tcb->p_winfo->p_tmevtb != NULL) {
186 pk_rtsk->lefttmo
187 = (TMO) tmevt_lefttim(p_tcb->p_winfo->p_tmevtb);
188 }
189 else {
190 pk_rtsk->lefttmo = TMO_FEVR;
191 }
192 }
193
194 /*
195 * ‹N°—v‹ƒLƒ…
196[ƒCƒ“ƒO”‚ÌŽæo‚µ
197 */
198 pk_rtsk->wupcnt = p_tcb->wupque ? 1U : 0U;
199 }
200
201 /*
202 * ‹N“®—v‹ƒLƒ…
203[ƒCƒ“ƒO”‚ÌŽæo‚µ
204 */
205 pk_rtsk->actcnt = p_tcb->actque ? 1U : 0U;
206 ercd = E_OK;
207 }
208 t_unlock_cpu();
209
210 error_exit:
211 LOG_REF_TSK_LEAVE(ercd, pk_rtsk);
212 return(ercd);
213}
214
215#endif /* TOPPERS_ref_tsk */
Note: See TracBrowser for help on using the repository browser.