source: UsbWattMeter/trunk/asp_dcre/kernel/sys_manage.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: 9.6 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-2008 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: sys_manage.c 164 2016-03-07 11:33:50Z coas-nagasima $
45 */
46
47/*
48 * ƒVƒXƒeƒ€ó‘ÔŠÇ—‹@”\
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_ROT_RDQ_ENTER
59#define LOG_ROT_RDQ_ENTER(tskpri)
60#endif /* LOG_ROT_RDQ_ENTER */
61
62#ifndef LOG_ROT_RDQ_LEAVE
63#define LOG_ROT_RDQ_LEAVE(ercd)
64#endif /* LOG_ROT_RDQ_LEAVE */
65
66#ifndef LOG_IROT_RDQ_ENTER
67#define LOG_IROT_RDQ_ENTER(tskpri)
68#endif /* LOG_IROT_RDQ_ENTER */
69
70#ifndef LOG_IROT_RDQ_LEAVE
71#define LOG_IROT_RDQ_LEAVE(ercd)
72#endif /* LOG_IROT_RDQ_LEAVE */
73
74#ifndef LOG_GET_TID_ENTER
75#define LOG_GET_TID_ENTER(p_tskid)
76#endif /* LOG_GET_TID_ENTER */
77
78#ifndef LOG_GET_TID_LEAVE
79#define LOG_GET_TID_LEAVE(ercd, tskid)
80#endif /* LOG_GET_TID_LEAVE */
81
82#ifndef LOG_IGET_TID_ENTER
83#define LOG_IGET_TID_ENTER(p_tskid)
84#endif /* LOG_IGET_TID_ENTER */
85
86#ifndef LOG_IGET_TID_LEAVE
87#define LOG_IGET_TID_LEAVE(ercd, tskid)
88#endif /* LOG_IGET_TID_LEAVE */
89
90#ifndef LOG_LOC_CPU_ENTER
91#define LOG_LOC_CPU_ENTER()
92#endif /* LOG_LOC_CPU_ENTER */
93
94#ifndef LOG_LOC_CPU_LEAVE
95#define LOG_LOC_CPU_LEAVE(ercd)
96#endif /* LOG_LOC_CPU_LEAVE */
97
98#ifndef LOG_ILOC_CPU_ENTER
99#define LOG_ILOC_CPU_ENTER()
100#endif /* LOG_ILOC_CPU_ENTER */
101
102#ifndef LOG_ILOC_CPU_LEAVE
103#define LOG_ILOC_CPU_LEAVE(ercd)
104#endif /* LOG_ILOC_CPU_LEAVE */
105
106#ifndef LOG_UNL_CPU_ENTER
107#define LOG_UNL_CPU_ENTER()
108#endif /* LOG_UNL_CPU_ENTER */
109
110#ifndef LOG_UNL_CPU_LEAVE
111#define LOG_UNL_CPU_LEAVE(ercd)
112#endif /* LOG_UNL_CPU_LEAVE */
113
114#ifndef LOG_IUNL_CPU_ENTER
115#define LOG_IUNL_CPU_ENTER()
116#endif /* LOG_IUNL_CPU_ENTER */
117
118#ifndef LOG_IUNL_CPU_LEAVE
119#define LOG_IUNL_CPU_LEAVE(ercd)
120#endif /* LOG_IUNL_CPU_LEAVE */
121
122#ifndef LOG_DIS_DSP_ENTER
123#define LOG_DIS_DSP_ENTER()
124#endif /* LOG_DIS_DSP_ENTER */
125
126#ifndef LOG_DIS_DSP_LEAVE
127#define LOG_DIS_DSP_LEAVE(ercd)
128#endif /* LOG_DIS_DSP_LEAVE */
129
130#ifndef LOG_ENA_DSP_ENTER
131#define LOG_ENA_DSP_ENTER()
132#endif /* LOG_ENA_DSP_ENTER */
133
134#ifndef LOG_ENA_DSP_LEAVE
135#define LOG_ENA_DSP_LEAVE(ercd)
136#endif /* LOG_ENA_DSP_LEAVE */
137
138#ifndef LOG_SNS_CTX_ENTER
139#define LOG_SNS_CTX_ENTER()
140#endif /* LOG_SNS_CTX_ENTER */
141
142#ifndef LOG_SNS_CTX_LEAVE
143#define LOG_SNS_CTX_LEAVE(state)
144#endif /* LOG_SNS_CTX_LEAVE */
145
146#ifndef LOG_SNS_LOC_ENTER
147#define LOG_SNS_LOC_ENTER()
148#endif /* LOG_SNS_LOC_ENTER */
149
150#ifndef LOG_SNS_LOC_LEAVE
151#define LOG_SNS_LOC_LEAVE(state)
152#endif /* LOG_SNS_LOC_LEAVE */
153
154#ifndef LOG_SNS_DSP_ENTER
155#define LOG_SNS_DSP_ENTER()
156#endif /* LOG_SNS_DSP_ENTER */
157
158#ifndef LOG_SNS_DSP_LEAVE
159#define LOG_SNS_DSP_LEAVE(state)
160#endif /* LOG_SNS_DSP_LEAVE */
161
162#ifndef LOG_SNS_DPN_ENTER
163#define LOG_SNS_DPN_ENTER()
164#endif /* LOG_SNS_DPN_ENTER */
165
166#ifndef LOG_SNS_DPN_LEAVE
167#define LOG_SNS_DPN_LEAVE(state)
168#endif /* LOG_SNS_DPN_LEAVE */
169
170#ifndef LOG_SNS_KER_ENTER
171#define LOG_SNS_KER_ENTER()
172#endif /* LOG_SNS_KER_ENTER */
173
174#ifndef LOG_SNS_KER_LEAVE
175#define LOG_SNS_KER_LEAVE(state)
176#endif /* LOG_SNS_KER_LEAVE */
177
178/*
179 * ƒ^ƒXƒN‚Ì—Dæ‡ˆÊ‚̉ñ“]
180 */
181#ifdef TOPPERS_rot_rdq
182
183ER
184rot_rdq(PRI tskpri)
185{
186 uint_t pri;
187 ER ercd;
188
189 LOG_ROT_RDQ_ENTER(tskpri);
190 CHECK_TSKCTX_UNL();
191 CHECK_TPRI_SELF(tskpri);
192
193 t_lock_cpu();
194 pri = (tskpri == TPRI_SELF) ? p_runtsk->priority : INT_PRIORITY(tskpri);
195 if (rotate_ready_queue(pri)) {
196 dispatch();
197 }
198 ercd = E_OK;
199 t_unlock_cpu();
200
201 error_exit:
202 LOG_ROT_RDQ_LEAVE(ercd);
203 return(ercd);
204}
205
206#endif /* TOPPERS_rot_rdq */
207
208/*
209 * ƒ^ƒXƒN‚Ì—Dæ‡ˆÊ‚̉ñ“]i”ñƒ^ƒXƒNƒRƒ“ƒeƒLƒXƒg—pj
210 */
211#ifdef TOPPERS_irot_rdq
212
213ER
214irot_rdq(PRI tskpri)
215{
216 ER ercd;
217
218 LOG_IROT_RDQ_ENTER(tskpri);
219 CHECK_INTCTX_UNL();
220 CHECK_TPRI(tskpri);
221
222 i_lock_cpu();
223 if (rotate_ready_queue(INT_PRIORITY(tskpri))) {
224 reqflg = true;
225 }
226 ercd = E_OK;
227 i_unlock_cpu();
228
229 error_exit:
230 LOG_IROT_RDQ_LEAVE(ercd);
231 return(ercd);
232}
233
234#endif /* TOPPERS_irot_rdq */
235
236/*
237 * ŽÀsó‘Ԃ̃^ƒXƒNID‚ÌŽQÆ
238 */
239#ifdef TOPPERS_get_tid
240
241ER
242get_tid(ID *p_tskid)
243{
244 ER ercd;
245
246 LOG_GET_TID_ENTER(p_tskid);
247 CHECK_TSKCTX_UNL();
248
249 t_lock_cpu();
250 *p_tskid = TSKID(p_runtsk);
251 ercd = E_OK;
252 t_unlock_cpu();
253
254 error_exit:
255 LOG_GET_TID_LEAVE(ercd, *p_tskid);
256 return(ercd);
257}
258
259#endif /* TOPPERS_get_tid */
260
261/*
262 * ŽÀsó‘Ԃ̃^ƒXƒNID‚ÌŽQÆi”ñƒ^ƒXƒNƒRƒ“ƒeƒLƒXƒg—pj
263 */
264#ifdef TOPPERS_iget_tid
265
266ER
267iget_tid(ID *p_tskid)
268{
269 ER ercd;
270
271 LOG_IGET_TID_ENTER(p_tskid);
272 CHECK_INTCTX_UNL();
273
274 i_lock_cpu();
275 *p_tskid = (p_runtsk == NULL) ? TSK_NONE : TSKID(p_runtsk);
276 ercd = E_OK;
277 i_unlock_cpu();
278
279 error_exit:
280 LOG_IGET_TID_LEAVE(ercd, *p_tskid);
281 return(ercd);
282}
283
284#endif /* TOPPERS_iget_tid */
285
286/*
287 * CPUƒƒbƒNó‘Ԃւ̈ڍs
288 */
289#ifdef TOPPERS_loc_cpu
290
291ER
292loc_cpu(void)
293{
294 ER ercd;
295
296 LOG_LOC_CPU_ENTER();
297 CHECK_TSKCTX();
298
299 if (!t_sense_lock()) {
300 t_lock_cpu();
301 }
302 ercd = E_OK;
303
304 error_exit:
305 LOG_LOC_CPU_LEAVE(ercd);
306 return(ercd);
307}
308
309#endif /* TOPPERS_loc_cpu */
310
311/*
312 * CPUƒƒbƒNó‘Ԃւ̈ڍsi”ñƒ^ƒXƒNƒRƒ“ƒeƒLƒXƒg—pj
313 */
314#ifdef TOPPERS_iloc_cpu
315
316ER
317iloc_cpu(void)
318{
319 ER ercd;
320
321 LOG_ILOC_CPU_ENTER();
322 CHECK_INTCTX();
323
324 if (!i_sense_lock()) {
325 i_lock_cpu();
326 }
327 ercd = E_OK;
328
329 error_exit:
330 LOG_ILOC_CPU_LEAVE(ercd);
331 return(ercd);
332}
333
334#endif /* TOPPERS_iloc_cpu */
335
336/*
337 * CPUƒƒbƒNó‘Ԃ̉ðœ
338 *
339 * CPUƒƒbƒN’†‚́CƒfƒBƒXƒpƒbƒ`‚ª•K—v‚Æ‚È‚éƒT[ƒrƒXƒR[ƒ‹‚ðŒÄ‚яo‚·‚±
340 * ‚Æ‚Í‚Å‚«‚È‚¢‚½‚߁CCPUƒƒbƒNó‘Ô‚Ì‰ðœŽž‚ɃfƒBƒXƒpƒbƒ`ƒƒ‚ð‹N“®‚·‚é
341 * •K—v‚Í‚È‚¢D
342 */
343#ifdef TOPPERS_unl_cpu
344
345ER
346unl_cpu(void)
347{
348 ER ercd;
349
350 LOG_UNL_CPU_ENTER();
351 CHECK_TSKCTX();
352
353 if (t_sense_lock()) {
354 t_unlock_cpu();
355 }
356 ercd = E_OK;
357
358 error_exit:
359 LOG_UNL_CPU_LEAVE(ercd);
360 return(ercd);
361}
362
363#endif /* TOPPERS_unl_cpu */
364
365/*
366 * CPUƒƒbƒNó‘Ô‚Ì‰ðœi”ñƒ^ƒXƒNƒRƒ“ƒeƒLƒXƒg—pj
367 *
368 * CPUƒƒbƒN’†‚́CƒfƒBƒXƒpƒbƒ`‚ª•K—v‚Æ‚È‚éƒT[ƒrƒXƒR[ƒ‹‚ðŒÄ‚яo‚·‚±
369 * ‚Æ‚Í‚Å‚«‚È‚¢‚½‚߁CCPUƒƒbƒNó‘Ô‚Ì‰ðœŽž‚ɃfƒBƒXƒpƒbƒ`ƒƒ‚Ì‹N“®‚ð—v
370 * ‹‚·‚é•K—v‚Í‚È‚¢D
371 */
372#ifdef TOPPERS_iunl_cpu
373
374ER
375iunl_cpu(void)
376{
377 ER ercd;
378
379 LOG_IUNL_CPU_ENTER();
380 CHECK_INTCTX();
381
382 if (i_sense_lock()) {
383 i_unlock_cpu();
384 }
385 ercd = E_OK;
386
387 error_exit:
388 LOG_IUNL_CPU_LEAVE(ercd);
389 return(ercd);
390}
391
392#endif /* TOPPERS_iunl_cpu */
393
394/*
395 * ƒfƒBƒXƒpƒbƒ`‚Ì‹ÖŽ~
396 */
397#ifdef TOPPERS_dis_dsp
398
399ER
400dis_dsp(void)
401{
402 ER ercd;
403
404 LOG_DIS_DSP_ENTER();
405 CHECK_TSKCTX_UNL();
406
407 t_lock_cpu();
408 disdsp = true;
409 dspflg = false;
410 ercd = E_OK;
411 t_unlock_cpu();
412
413 error_exit:
414 LOG_DIS_DSP_LEAVE(ercd);
415 return(ercd);
416}
417
418#endif /* TOPPERS_dis_dsp */
419
420/*
421 * ƒfƒBƒXƒpƒbƒ`‚Ì‹–‰Â
422 */
423#ifdef TOPPERS_ena_dsp
424
425ER
426ena_dsp(void)
427{
428 ER ercd;
429
430 LOG_ENA_DSP_ENTER();
431 CHECK_TSKCTX_UNL();
432
433 t_lock_cpu();
434 disdsp = false;
435 if (ipmflg) {
436 dspflg = true;
437 if (p_runtsk != p_schedtsk) {
438 dispatch();
439 }
440 }
441 ercd = E_OK;
442 t_unlock_cpu();
443
444 error_exit:
445 LOG_ENA_DSP_LEAVE(ercd);
446 return(ercd);
447}
448
449#endif /* TOPPERS_ena_dsp */
450
451/*
452 * ƒRƒ“ƒeƒLƒXƒg‚ÌŽQÆ
453 */
454#ifdef TOPPERS_sns_ctx
455
456bool_t
457sns_ctx(void)
458{
459 bool_t state;
460
461 LOG_SNS_CTX_ENTER();
462 state = sense_context() ? true : false;
463 LOG_SNS_CTX_LEAVE(state);
464 return(state);
465}
466
467#endif /* TOPPERS_sns_ctx */
468
469/*
470 * CPUƒƒbƒNó‘Ô‚ÌŽQÆ
471 */
472#ifdef TOPPERS_sns_loc
473
474bool_t
475sns_loc(void)
476{
477 bool_t state;
478
479 LOG_SNS_LOC_ENTER();
480 state = x_sense_lock() ? true : false;
481 LOG_SNS_LOC_LEAVE(state);
482 return(state);
483}
484
485#endif /* TOPPERS_sns_loc */
486
487/*
488 * ƒfƒBƒXƒpƒbƒ`‹ÖŽ~ó‘Ô‚ÌŽQÆ
489 */
490#ifdef TOPPERS_sns_dsp
491
492bool_t
493sns_dsp(void)
494{
495 bool_t state;
496
497 LOG_SNS_DSP_ENTER();
498 state = disdsp;
499 LOG_SNS_DSP_LEAVE(state);
500 return(state);
501}
502
503#endif /* TOPPERS_sns_dsp */
504
505/*
506 * ƒfƒBƒXƒpƒbƒ`•Û—¯ó‘Ô‚ÌŽQÆ
507 */
508#ifdef TOPPERS_sns_dpn
509
510bool_t
511sns_dpn(void)
512{
513 bool_t state;
514
515 LOG_SNS_DPN_ENTER();
516 state = (sense_context() || t_sense_lock() || !dspflg) ? true : false;
517 LOG_SNS_DPN_LEAVE(state);
518 return(state);
519}
520
521#endif /* TOPPERS_sns_dpn */
522
523/*
524 * ƒJ[ƒlƒ‹”ñ“®ìó‘Ô‚ÌŽQÆ
525 */
526#ifdef TOPPERS_sns_ker
527
528bool_t
529sns_ker(void)
530{
531 bool_t state;
532
533 LOG_SNS_KER_ENTER();
534 state = kerflg ? false : true;
535 LOG_SNS_KER_LEAVE(state);
536 return(state);
537}
538
539#endif /* TOPPERS_sns_ker */
Note: See TracBrowser for help on using the repository browser.