source: UsbWattMeter/trunk/asp_dcre/kernel/task_except.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: 7.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) 2000-2003 by Embedded and Real-Time Systems Laboratory
7 * Toyohashi Univ. of Technology, JAPAN
8 * Copyright (C) 2005-2014 by Embedded and Real-Time Systems Laboratory
9 * Graduate School of Information Science, Nagoya Univ., JAPAN
10 *
11 * ã‹L’˜ìŒ ŽÒ‚́CˆÈ‰º‚Ì(1)`(4)‚ÌðŒ‚ð–ž‚½‚·ê‡‚ÉŒÀ‚èC–{ƒ\ƒtƒgƒEƒF
12 * ƒAi–{ƒ\ƒtƒgƒEƒFƒA‚ð‰ü•Ï‚µ‚½‚à‚Ì‚ðŠÜ‚ށDˆÈ‰º“¯‚¶j‚ðŽg—pE•¡»E‰ü
13 * •ÏEÄ”z•ziˆÈ‰ºC—˜—p‚ƌĂԁj‚·‚邱‚Ƃ𖳏ž‚Å‹–‘ø‚·‚éD
14 * (1) –{ƒ\ƒtƒgƒEƒFƒA‚ðƒ\[ƒXƒR[ƒh‚ÌŒ`‚Å—˜—p‚·‚éê‡‚ɂ́Cã‹L‚Ì’˜ì
15 * Œ •\Ž¦C‚±‚Ì—˜—pðŒ‚¨‚æ‚щº‹L‚Ì–³•ÛØ‹K’肪C‚»‚Ì‚Ü‚Ü‚ÌŒ`‚Ń\[
16 * ƒXƒR[ƒh’†‚ÉŠÜ‚Ü‚ê‚Ä‚¢‚邱‚ƁD
17 * (2) –{ƒ\ƒtƒgƒEƒFƒA‚ðCƒ‰ƒCƒuƒ‰ƒŠŒ`Ž®‚ȂǁC‘¼‚̃\ƒtƒgƒEƒFƒAŠJ”­‚ÉŽg
18 * —p‚Å‚«‚éŒ`‚ōĔz•z‚·‚éê‡‚ɂ́CÄ”z•z‚É”º‚¤ƒhƒLƒ…
19ƒƒ“ƒgi—˜—p
20 * ŽÒƒ}ƒjƒ…
21ƒAƒ‹‚Ȃǁj‚ɁCã‹L‚Ì’˜ìŒ •\Ž¦C‚±‚Ì—˜—pðŒ‚¨‚æ‚щº‹L
22 * ‚Ì–³•ÛØ‹K’è‚ðŒfÚ‚·‚邱‚ƁD
23 * (3) –{ƒ\ƒtƒgƒEƒFƒA‚ðC‹@Ší‚É‘g‚ݍž‚ނȂǁC‘¼‚̃\ƒtƒgƒEƒFƒAŠJ”­‚ÉŽg
24 * —p‚Å‚«‚È‚¢Œ`‚ōĔz•z‚·‚éê‡‚ɂ́CŽŸ‚Ì‚¢‚¸‚ê‚©‚ÌðŒ‚ð–ž‚½‚·‚±
25 * ‚ƁD
26 * (a) Ä”z•z‚É”º‚¤ƒhƒLƒ…
27ƒƒ“ƒgi—˜—pŽÒƒ}ƒjƒ…
28ƒAƒ‹‚Ȃǁj‚ɁCã‹L‚Ì’˜
29 * ìŒ •\Ž¦C‚±‚Ì—˜—pðŒ‚¨‚æ‚щº‹L‚Ì–³•ÛØ‹K’è‚ðŒfÚ‚·‚邱‚ƁD
30 * (b) Ä”z•z‚ÌŒ`‘Ô‚ðC•Ê‚É’è‚ß‚é•û–@‚É‚æ‚Á‚āCTOPPERSƒvƒƒWƒFƒNƒg‚É
31 * •ñ‚·‚邱‚ƁD
32 * (4) –{ƒ\ƒtƒgƒEƒFƒA‚Ì—˜—p‚É‚æ‚è’¼Ú“I‚Ü‚½‚͊ԐړI‚ɐ¶‚¶‚é‚¢‚©‚Ȃ鑹
33 * ŠQ‚©‚ç‚àCã‹L’˜ìŒ ŽÒ‚¨‚æ‚ÑTOPPERSƒvƒƒWƒFƒNƒg‚ð–Ɛӂ·‚邱‚ƁD
34 * ‚Ü‚½C–{ƒ\ƒtƒgƒEƒFƒA‚̃†[ƒU‚Ü‚½‚̓Gƒ“ƒhƒ†[ƒU‚©‚ç‚Ì‚¢‚©‚Ȃ闝
35 * —R‚ÉŠî‚­¿‹‚©‚ç‚àCã‹L’˜ìŒ ŽÒ‚¨‚æ‚ÑTOPPERSƒvƒƒWƒFƒNƒg‚ð
36 * –Ɛӂ·‚邱‚ƁD
37 *
38 * –{ƒ\ƒtƒgƒEƒFƒA‚́C–³•ÛØ‚Å’ñ‹Ÿ‚³‚ê‚Ä‚¢‚é‚à‚Ì‚Å‚ ‚éDã‹L’˜ìŒ ŽÒ‚¨
39 * ‚æ‚ÑTOPPERSƒvƒƒWƒFƒNƒg‚́C–{ƒ\ƒtƒgƒEƒFƒA‚ÉŠÖ‚µ‚āC“Á’è‚ÌŽg—p–Ú“I
40 * ‚ɑ΂·‚é“K‡«‚àŠÜ‚߂āC‚¢‚©‚È‚é•ÛØ‚às‚í‚È‚¢D‚Ü‚½C–{ƒ\ƒtƒgƒEƒF
41 * ƒA‚Ì—˜—p‚É‚æ‚è’¼Ú“I‚Ü‚½‚͊ԐړI‚ɐ¶‚¶‚½‚¢‚©‚Ȃ鑹ŠQ‚ÉŠÖ‚µ‚Ä‚àC‚»
42 * ‚̐ӔC‚𕉂í‚È‚¢D
43 *
44 * $Id: task_except.c 164 2016-03-07 11:33:50Z coas-nagasima $
45 */
46
47/*
48 * ƒ^ƒXƒN—áŠOˆ—‹@”\
49 */
50
51#include "kernel_impl.h"
52#include "check.h"
53#include "task.h"
54
55/*
56 * ƒgƒŒ[ƒXƒƒOƒ}ƒNƒ‚̃fƒtƒHƒ‹ƒg’è‹`
57 */
58#ifndef LOG_DEF_TEX_ENTER
59#define LOG_DEF_TEX_ENTER(tskid, pk_dtex)
60#endif /* LOG_DEF_TEX_ENTER */
61
62#ifndef LOG_DEF_TEX_LEAVE
63#define LOG_DEF_TEX_LEAVE(ercd)
64#endif /* LOG_DEF_TEX_LEAVE */
65
66#ifndef LOG_RAS_TEX_ENTER
67#define LOG_RAS_TEX_ENTER(tskid, rasptn)
68#endif /* LOG_RAS_TEX_ENTER */
69
70#ifndef LOG_RAS_TEX_LEAVE
71#define LOG_RAS_TEX_LEAVE(ercd)
72#endif /* LOG_RAS_TEX_LEAVE */
73
74#ifndef LOG_IRAS_TEX_ENTER
75#define LOG_IRAS_TEX_ENTER(tskid, rasptn)
76#endif /* LOG_IRAS_TEX_ENTER */
77
78#ifndef LOG_IRAS_TEX_LEAVE
79#define LOG_IRAS_TEX_LEAVE(ercd)
80#endif /* LOG_IRAS_TEX_LEAVE */
81
82#ifndef LOG_DIS_TEX_ENTER
83#define LOG_DIS_TEX_ENTER()
84#endif /* LOG_DIS_TEX_ENTER */
85
86#ifndef LOG_DIS_TEX_LEAVE
87#define LOG_DIS_TEX_LEAVE(ercd)
88#endif /* LOG_DIS_TEX_LEAVE */
89
90#ifndef LOG_ENA_TEX_ENTER
91#define LOG_ENA_TEX_ENTER()
92#endif /* LOG_ENA_TEX_ENTER */
93
94#ifndef LOG_ENA_TEX_LEAVE
95#define LOG_ENA_TEX_LEAVE(ercd)
96#endif /* LOG_ENA_TEX_LEAVE */
97
98#ifndef LOG_SNS_TEX_ENTER
99#define LOG_SNS_TEX_ENTER()
100#endif /* LOG_SNS_TEX_ENTER */
101
102#ifndef LOG_SNS_TEX_LEAVE
103#define LOG_SNS_TEX_LEAVE(state)
104#endif /* LOG_SNS_TEX_LEAVE */
105
106#ifndef LOG_REF_TEX_ENTER
107#define LOG_REF_TEX_ENTER(tskid, pk_rtex)
108#endif /* LOG_REF_TEX_ENTER */
109
110#ifndef LOG_REF_TEX_LEAVE
111#define LOG_REF_TEX_LEAVE(ercd, pk_rtex)
112#endif /* LOG_REF_TEX_LEAVE */
113
114/*
115 * ƒ^ƒXƒN—áŠOˆ—ƒ‹[ƒ`ƒ“‚Ì’è‹`
116 */
117#ifdef TOPPERS_def_tex
118
119ER_UINT
120def_tex(ID tskid, const T_DTEX *pk_dtex)
121{
122 TCB *p_tcb;
123 TINIB *p_tinib;
124 ER ercd;
125
126 LOG_DEF_TEX_ENTER(tskid, pk_dtex);
127 CHECK_TSKCTX_UNL();
128 CHECK_TSKID_SELF(tskid);
129 CHECK_RSATR(pk_dtex->texatr, TA_NULL);
130 if (pk_dtex->texrtn != NULL) {
131 CHECK_ALIGN_FUNC(pk_dtex->texrtn);
132 CHECK_NONNULL_FUNC(pk_dtex->texrtn);
133 }
134 p_tcb = get_tcb_self(tskid);
135 p_tinib = (TINIB *)(p_tcb->p_tinib);
136
137 t_lock_cpu();
138 if (p_tcb->p_tinib->tskatr == TA_NOEXS) {
139 ercd = E_NOEXS;
140 }
141 else if (TSKID(p_tcb) > tmax_stskid) {
142 if (pk_dtex->texrtn != NULL) {
143 if (p_tinib->texrtn != NULL) {
144 ercd = E_OBJ;
145 }
146 else {
147 p_tinib->texatr = pk_dtex->texatr;
148 p_tinib->texrtn = pk_dtex->texrtn;
149 ercd = E_OK;
150 }
151 }
152 else {
153 if (p_tinib->texrtn != NULL) {
154 p_tinib->texrtn = NULL;
155 p_tcb->enatex = false;
156 p_tcb->texptn = 0U;
157 ercd = E_OK;
158 }
159 else {
160 ercd = E_OBJ;
161 }
162 }
163 }
164 else {
165 ercd = E_OBJ;
166 }
167 t_unlock_cpu();
168
169 error_exit:
170 LOG_DEF_TEX_LEAVE(ercd);
171 return(ercd);
172}
173
174#endif /* TOPPERS_def_tex */
175
176/*
177 * ƒ^ƒXƒN—áŠOˆ—‚Ì—v‹
178 */
179#ifdef TOPPERS_ras_tex
180
181ER
182ras_tex(ID tskid, TEXPTN rasptn)
183{
184 TCB *p_tcb;
185 ER ercd;
186
187 LOG_RAS_TEX_ENTER(tskid, rasptn);
188 CHECK_TSKCTX_UNL();
189 CHECK_TSKID_SELF(tskid);
190 CHECK_PAR(rasptn != 0U);
191 p_tcb = get_tcb_self(tskid);
192
193 t_lock_cpu();
194 if (p_tcb->p_tinib->tskatr == TA_NOEXS) {
195 ercd = E_NOEXS;
196 }
197 else if (TSTAT_DORMANT(p_tcb->tstat) || p_tcb->p_tinib->texrtn == NULL) {
198 ercd = E_OBJ;
199 }
200 else {
201 p_tcb->texptn |= rasptn;
202 if (p_tcb == p_runtsk && p_runtsk->enatex && ipmflg) {
203 call_texrtn();
204 }
205 ercd = E_OK;
206 }
207 t_unlock_cpu();
208
209 error_exit:
210 LOG_RAS_TEX_LEAVE(ercd);
211 return(ercd);
212}
213
214#endif /* TOPPERS_ras_tex */
215
216/*
217 * ƒ^ƒXƒN—áŠOˆ—‚Ì—v‹i”ñƒ^ƒXƒNƒRƒ“ƒeƒLƒXƒg—pj
218 */
219#ifdef TOPPERS_iras_tex
220
221ER
222iras_tex(ID tskid, TEXPTN rasptn)
223{
224 TCB *p_tcb;
225 ER ercd;
226
227 LOG_IRAS_TEX_ENTER(tskid, rasptn);
228 CHECK_INTCTX_UNL();
229 CHECK_TSKID(tskid);
230 CHECK_PAR(rasptn != 0U);
231 p_tcb = get_tcb(tskid);
232
233 i_lock_cpu();
234 if (p_tcb->p_tinib->tskatr == TA_NOEXS) {
235 ercd = E_NOEXS;
236 }
237 else if (TSTAT_DORMANT(p_tcb->tstat) || p_tcb->p_tinib->texrtn == NULL) {
238 ercd = E_OBJ;
239 }
240 else {
241 p_tcb->texptn |= rasptn;
242 if (p_tcb == p_runtsk && p_runtsk->enatex && ipmflg) {
243 reqflg = true;
244 }
245 ercd = E_OK;
246 }
247 i_unlock_cpu();
248
249 error_exit:
250 LOG_IRAS_TEX_LEAVE(ercd);
251 return(ercd);
252}
253
254#endif /* TOPPERS_iras_tex */
255
256/*
257 * ƒ^ƒXƒN—áŠOˆ—‚Ì‹ÖŽ~
258 */
259#ifdef TOPPERS_dis_tex
260
261ER
262dis_tex(void)
263{
264 ER ercd;
265
266 LOG_DIS_TEX_ENTER();
267 CHECK_TSKCTX_UNL();
268
269 t_lock_cpu();
270 if (p_runtsk->p_tinib->texrtn == NULL) {
271 ercd = E_OBJ;
272 }
273 else {
274 p_runtsk->enatex = false;
275 ercd = E_OK;
276 }
277 t_unlock_cpu();
278
279 error_exit:
280 LOG_DIS_TEX_LEAVE(ercd);
281 return(ercd);
282}
283
284#endif /* TOPPERS_dis_tex */
285
286/*
287 * ƒ^ƒXƒN—áŠOˆ—‚Ì‹–‰Â
288 */
289#ifdef TOPPERS_ena_tex
290
291ER
292ena_tex(void)
293{
294 ER ercd;
295
296 LOG_ENA_TEX_ENTER();
297 CHECK_TSKCTX_UNL();
298
299 t_lock_cpu();
300 if (p_runtsk->p_tinib->texrtn == NULL) {
301 ercd = E_OBJ;
302 }
303 else {
304 p_runtsk->enatex = true;
305 if (p_runtsk->texptn != 0U && ipmflg) {
306 call_texrtn();
307 }
308 ercd = E_OK;
309 }
310 t_unlock_cpu();
311
312 error_exit:
313 LOG_ENA_TEX_LEAVE(ercd);
314 return(ercd);
315}
316
317#endif /* TOPPERS_ena_tex */
318
319/*
320 * ƒ^ƒXƒN—áŠOˆ—‹ÖŽ~ó‘Ô‚ÌŽQÆ
321 */
322#ifdef TOPPERS_sns_tex
323
324bool_t
325sns_tex(void)
326{
327 bool_t state;
328
329 LOG_SNS_TEX_ENTER();
330 state = (p_runtsk != NULL && p_runtsk->enatex) ? false : true;
331 LOG_SNS_TEX_LEAVE(state);
332 return(state);
333}
334
335#endif /* TOPPERS_sns_tex */
336
337/*
338 * ƒ^ƒXƒN—áŠOˆ—‚̏ó‘ÔŽQÆ
339 */
340#ifdef TOPPERS_ref_tex
341
342ER
343ref_tex(ID tskid, T_RTEX *pk_rtex)
344{
345 TCB *p_tcb;
346 ER ercd;
347
348 LOG_REF_TEX_ENTER(tskid, pk_rtex);
349 CHECK_TSKCTX_UNL();
350 CHECK_TSKID_SELF(tskid);
351 p_tcb = get_tcb_self(tskid);
352
353 t_lock_cpu();
354 if (p_tcb->p_tinib->tskatr == TA_NOEXS) {
355 ercd = E_NOEXS;
356 }
357 else if (TSTAT_DORMANT(p_tcb->tstat) || p_tcb->p_tinib->texrtn == NULL) {
358 ercd = E_OBJ;
359 }
360 else {
361 pk_rtex->texstat = (p_tcb->enatex) ? TTEX_ENA : TTEX_DIS;
362 pk_rtex->pndptn = p_tcb->texptn;
363 ercd = E_OK;
364 }
365 t_unlock_cpu();
366
367 error_exit:
368 LOG_REF_TEX_LEAVE(ercd, pk_rtex);
369 return(ercd);
370}
371
372#endif /* TOPPERS_ref_tex */
Note: See TracBrowser for help on using the repository browser.