source: uKadecot/trunk/ssp/extension/alarm.c@ 101

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

TOPPERS/uKadecotのソースコードを追加

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/plain
File size: 6.0 KB
Line 
1/*
2 * TOPPERS/SSP Kernel
3 * Smallest Set Profile Kernel
4 *
5 * Copyright (C) 2011 by Meika Sugimoto
6 * Copyright (C) 2015 by Naoki Saito
7 * Nagoya Municipal Industrial Research Institute, 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‰ü•ÏE
11 * Ä”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‚»‚Ì‚Ü‚Ü‚ÌŒ`‚Ń\[ƒX
14 * ƒR[ƒh’†‚ÉŠÜ‚Ü‚ê‚Ä‚¢‚邱‚ƁD
15 * (2) –{ƒ\ƒtƒgƒEƒFƒA‚ðCƒ‰ƒCƒuƒ‰ƒŠŒ`Ž®‚ȂǁC‘¼‚̃\ƒtƒgƒEƒFƒAŠJ”­‚ÉŽg—p
16 * ‚Å‚«‚éŒ`‚ōĔ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—p
22 * ‚Å‚«‚È‚¢Œ`‚ōĔz•z‚·‚éê‡‚ɂ́CŽŸ‚Ì‚¢‚¸‚ê‚©‚ÌðŒ‚ð–ž‚½‚·‚±‚ƁD
23 * (a) Ä”z•z‚É”º‚¤ƒhƒLƒ…
24ƒƒ“ƒgi—˜—pŽÒƒ}ƒjƒ…
25ƒAƒ‹‚Ȃǁj‚ɁCã‹L‚Ì’˜ì
26 * Œ •\Ž¦C‚±‚Ì—˜—pðŒ‚¨‚æ‚щº‹L‚Ì–³•ÛØ‹K’è‚ðŒfÚ‚·‚邱‚ƁD
27 * (b) Ä”z•z‚ÌŒ`‘Ô‚ðC•Ê‚É’è‚ß‚é•û–@‚É‚æ‚Á‚āCTOPPERSƒvƒƒWƒFƒNƒg‚É•ñ
28 * ‚·‚邱‚ƁD
29 * (4) –{ƒ\ƒtƒgƒEƒFƒA‚Ì—˜—p‚É‚æ‚è’¼Ú“I‚Ü‚½‚͊ԐړI‚ɐ¶‚¶‚é‚¢‚©‚Ȃ鑹ŠQ
30 * ‚©‚ç‚àCã‹L’˜ìŒ ŽÒ‚¨‚æ‚ÑTOPPERSƒvƒƒWƒFƒNƒg‚ð–Ɛӂ·‚邱‚ƁD‚Ü‚½C
31 * –{ƒ\ƒtƒgƒEƒFƒA‚̃†[ƒU‚Ü‚½‚̓Gƒ“ƒhƒ†[ƒU‚©‚ç‚Ì‚¢‚©‚Ȃ闝—R‚ÉŠî‚Ã
32 * ‚­¿‹‚©‚ç‚àCã‹L’˜ìŒ ŽÒ‚¨‚æ‚ÑTOPPERSƒvƒƒWƒFƒNƒg‚ð–Ɛӂ·‚邱‚ƁD
33 *
34 * –{ƒ\ƒtƒgƒEƒFƒA‚́C–³•ÛØ‚Å’ñ‹Ÿ‚³‚ê‚Ä‚¢‚é‚à‚Ì‚Å‚ ‚éDã‹L’˜ìŒ ŽÒ‚¨‚æ
35 * ‚ÑTOPPERSƒvƒƒWƒFƒNƒg‚́C–{ƒ\ƒtƒgƒEƒFƒA‚ÉŠÖ‚µ‚āC“Á’è‚ÌŽg—p–Ú“I‚ɑ΂·
36 * ‚é“K‡«‚àŠÜ‚߂āC‚¢‚©‚È‚é•ÛØ‚às‚í‚È‚¢D‚Ü‚½C–{ƒ\ƒtƒgƒEƒFƒA‚Ì—˜—p
37 * ‚É‚æ‚è’¼Ú“I‚Ü‚½‚͊ԐړI‚ɐ¶‚¶‚½‚¢‚©‚Ȃ鑹ŠQ‚ÉŠÖ‚µ‚Ä‚àC‚»‚̐ӔC‚ð•‰
38 * ‚í‚È‚¢D
39 *
40 */
41
42/*
43 * ƒAƒ‰[ƒ€ƒnƒ“ƒhƒ‰‹@”\
44 */
45
46#include "alarm.h"
47#include "check.h"
48#include "time_event.h"
49
50/*
51 * ƒgƒŒ[ƒXƒƒOƒ}ƒNƒ‚̃fƒtƒHƒ‹ƒg’è‹`
52 */
53
54#ifndef LOG_ALM_ENTER
55#define LOG_ALM_ENTER(almidx)
56#endif /* LOG_ALM_ENTER */
57
58#ifndef LOG_ALM_LEAVE
59#define LOG_ALM_LEAVE(almidx)
60#endif /* LOG_ALM_LEAVE */
61
62#ifndef LOG_STA_ALM_ENTER
63#define LOG_STA_ALM_ENTER(almid, almtim)
64#endif /* LOG_STA_ALM_ENTER */
65
66#ifndef LOG_STA_ALM_LEAVE
67#define LOG_STA_ALM_LEAVE(ercd)
68#endif /* LOG_STA_ALM_LEAVE */
69
70#ifndef LOG_ISTA_ALM_ENTER
71#define LOG_ISTA_ALM_ENTER(almid, almtim)
72#endif /* LOG_ISTA_ALM_ENTER */
73
74#ifndef LOG_ISTA_ALM_LEAVE
75#define LOG_ISTA_ALM_LEAVE(ercd)
76#endif /* LOG_ISTA_ALM_LEAVE */
77
78#ifndef LOG_STP_ALM_ENTER
79#define LOG_STP_ALM_ENTER(almid)
80#endif /* LOG_STP_ALM_ENTER */
81
82#ifndef LOG_STP_ALM_LEAVE
83#define LOG_STP_ALM_LEAVE(ercd)
84#endif /* LOG_STP_ALM_LEAVE */
85
86#ifndef LOG_ISTP_ALM_ENTER
87#define LOG_ISTP_ALM_ENTER(almid)
88#endif /* LOG_ISTP_ALM_ENTER */
89
90#ifndef LOG_ISTP_ALM_LEAVE
91#define LOG_ISTP_ALM_LEAVE(ercd)
92#endif /* LOG_ISTP_ALM_LEAVE */
93
94
95/* ŽüŠúƒnƒ“ƒhƒ‰ID‚ðƒ^ƒCƒ€ƒCƒxƒ“ƒgID‚É•ÏŠ· */
96#define ALM_EVTID(almid) ((ID)(INDEX_ALM(almid) + almevtid_offset))
97#define INDEX_ALM(almid) ((uint_t)((almid) - TMIN_ALMID))
98
99/* ƒAƒ‰[ƒ€ƒnƒ“ƒhƒ‰‚̌” */
100#define tnum_alm ((uint_t)(tmax_almid - TMIN_ALMID + 1))
101
102/* ƒAƒ‰[ƒ€‚Ì“®ìó‘Ô‚ð•\‚·ƒrƒbƒgƒ}ƒbƒv */
103#define ALMACT_BIT(index) (1U << (index))
104
105
106/* ƒAƒ‰[ƒ€ƒnƒ“ƒhƒ‰ŽÀsƒ^ƒCƒ€ƒCƒxƒ“ƒg */
107void call_almhdr(uintptr_t almidx);
108
109
110/*
111 * ƒAƒ‰[ƒ€ƒnƒ“ƒhƒ‰‹@”\‚̏‰Šú‰»
112 */
113
114#ifdef TOPPERS_almcal
115
116void
117initialize_alarm(void)
118{
119 /* ‘S‚ẴAƒ‰[ƒ€‚ð’âŽ~ó‘Ô‚É‚·‚é */
120 almcb_almact = 0U;
121}
122
123#endif /* TOPPERS_almcal */
124
125/*
126 * ƒAƒ‰[ƒ€‚ÌŠJŽn
127 */
128
129#ifdef TOPPERS_sta_alm
130
131ER
132sta_alm(ID almid , RELTIM almtim)
133{
134 ER ercd;
135 uint_t index = INDEX_ALM(almid);
136
137 LOG_STA_ALM_ENTER(almid, almtim);
138 CHECK_TSKCTX_UNL();
139 CHECK_ALMID(almid);
140
141 t_lock_cpu();
142
143 if((almcb_almact & ALMACT_BIT(index)) != 0U) {
144 time_event_dequeue(ALM_EVTID(almid));
145 }
146 else {
147 almcb_almact |= ALMACT_BIT(index);
148 }
149
150 time_event_enqueue(ALM_EVTID(almid) ,
151 current_time + (EVTTIM)almtim , (CBACK)call_almhdr , index);
152
153 ercd = E_OK;
154 t_unlock_cpu();
155
156 error_exit:
157 LOG_STA_ALM_LEAVE(ercd);
158 return ercd;
159}
160
161#endif /* TOPPERS_sta_alm */
162
163/*
164 * ƒAƒ‰[ƒ€‚ÌŠJŽn(”ñƒ^ƒXƒNƒRƒ“ƒeƒLƒXƒg—p)
165 */
166
167#ifdef TOPPERS_ista_alm
168
169ER
170ista_alm(ID almid , RELTIM almtim)
171{
172 ER ercd;
173 uint_t index = INDEX_ALM(almid);
174
175 LOG_ISTA_ALM_ENTER(almid, almtim);
176 CHECK_INTCTX_UNL();
177 CHECK_ALMID(almid);
178
179 i_lock_cpu();
180
181 if((almcb_almact & ALMACT_BIT(index)) != 0U) {
182 time_event_dequeue(ALM_EVTID(almid));
183 }
184 else {
185 almcb_almact |= ALMACT_BIT(index);
186 }
187
188 time_event_enqueue(ALM_EVTID(almid) ,
189 current_time + (EVTTIM)almtim , (CBACK)call_almhdr , index);
190
191 ercd = E_OK;
192 i_unlock_cpu();
193
194 error_exit:
195 LOG_ISTA_ALM_LEAVE(ercd);
196 return ercd;
197}
198
199#endif /* TOPPERS_ista_alm */
200
201/*
202 * ƒAƒ‰[ƒ€‚Ì’âŽ~
203 */
204
205#ifdef TOPPERS_stp_alm
206
207ER
208stp_alm(ID almid)
209{
210 ER ercd;
211 uint_t index = INDEX_ALM(almid);
212
213 LOG_STP_ALM_ENTER(almid);
214 CHECK_TSKCTX_UNL();
215 CHECK_ALMID(almid);
216
217 t_lock_cpu();
218
219 if((almcb_almact & ALMACT_BIT(index)) != 0U) {
220 almcb_almact &= ~ALMACT_BIT(index);
221 time_event_dequeue(ALM_EVTID(almid));
222 }
223 ercd = E_OK;
224 t_unlock_cpu();
225
226 error_exit:
227 LOG_STP_ALM_LEAVE(ercd);
228 return ercd;
229}
230
231#endif /* TOPPERS_stp_alm */
232
233/*
234 * ƒAƒ‰[ƒ€‚Ì’âŽ~(”ñƒ^ƒXƒNƒRƒ“ƒeƒLƒXƒg—p)
235 */
236
237#ifdef TOPPERS_istp_alm
238
239ER
240istp_alm(ID almid)
241{
242 ER ercd;
243 uint_t index = INDEX_ALM(almid);
244
245 LOG_ISTP_ALM_ENTER(almid);
246 CHECK_INTCTX_UNL();
247 CHECK_ALMID(almid);
248
249 i_lock_cpu();
250
251 if((almcb_almact & ALMACT_BIT(index)) != 0U) {
252 almcb_almact &= ~ALMACT_BIT(index);
253 time_event_dequeue(ALM_EVTID(almid));
254 }
255 ercd = E_OK;
256 i_unlock_cpu();
257
258 error_exit:
259 LOG_ISTP_ALM_LEAVE(ercd);
260 return ercd;
261}
262
263#endif /* TOPPERS_istp_alm */
264
265/*
266 * ƒAƒ‰[ƒ€ƒnƒ“ƒhƒ‰‹N“®ƒ‹[ƒ`ƒ“
267 */
268
269#ifdef TOPPERS_almcal
270
271void
272call_almhdr(uintptr_t almidx)
273{
274 /* ƒAƒ‰[ƒ€ƒnƒ“ƒhƒ‰‚ð’âŽ~ó‘Ô‚É‚·‚é */
275 almcb_almact &= ~ALMACT_BIT(almidx);
276
277 i_unlock_cpu();
278
279 /* ƒAƒ‰[ƒ€ƒnƒ“ƒhƒ‰‚ÌŽÀs */
280 LOG_ALM_ENTER(almidx);
281 (*alminib_almhdr[almidx])(alminib_exinf[almidx]);
282 LOG_ALM_LEAVE(almidx);
283
284 if (!i_sense_lock()) {
285 i_lock_cpu();
286 }
287}
288
289#endif /* TOPPERS_almcal */
290
Note: See TracBrowser for help on using the repository browser.