source: ssp_qb_r5f100le_cs/trunk/arch/rl78_ca78k0r/prc_config.c@ 93

Last change on this file since 93 was 93, checked in by nmir-saito, 8 years ago

add Combined package of SSP kernel for QB-R5F100LE-TB(RL78 processor)

File size: 9.5 KB
Line 
1/*
2 * TOPPERS/SSP Kernel
3 * Smallest Set Profile Kernel
4 *
5 * Copyright (C) 2000-2003 by Embedded and Real-Time Systems Laboratory
6 * Toyohashi Univ. of Technology, JAPAN
7 * Copyright (C) 2005,2006 by Embedded and Real-Time Systems Laboratory
8 * Graduate School of Information Science, Nagoya Univ., JAPAN
9 * Copyright (C) 2008 by Witz Corporation, JAPAN
10 * Copyright (C) 2010-2014 by Naoki Saito
11 * Nagoya Municipal Industrial Research Institute, JAPAN
12 *
13 * ã‹L’˜ìŒ ŽÒ‚́CˆÈ‰º‚Ì (1)`(4) ‚ÌðŒ‚ð–ž‚½‚·ê‡‚ÉŒÀ‚èC–{ƒ\ƒtƒgƒEƒF
14 * ƒAi–{ƒ\ƒtƒgƒEƒFƒA‚ð‰ü•Ï‚µ‚½‚à‚Ì‚ðŠÜ‚ށDˆÈ‰º“¯‚¶j‚ðŽg—pE•¡»E‰ü•ÏE
15 * Ä”z•ziˆÈ‰ºC—˜—p‚ƌĂԁj‚·‚邱‚Ƃ𖳏ž‚Å‹–‘ø‚·‚éD
16 * (1) –{ƒ\ƒtƒgƒEƒFƒA‚ðƒ\[ƒXƒR[ƒh‚ÌŒ`‚Å—˜—p‚·‚éê‡‚ɂ́Cã‹L‚Ì’˜ìŒ 
17 * •\Ž¦C‚±‚Ì—˜—pðŒ‚¨‚æ‚щº‹L‚Ì–³•ÛØ‹K’肪C‚»‚Ì‚Ü‚Ü‚ÌŒ`‚Ń\[ƒX
18 * ƒR[ƒh’†‚ÉŠÜ‚Ü‚ê‚Ä‚¢‚邱‚ƁD
19 * (2) –{ƒ\ƒtƒgƒEƒFƒA‚ðCƒ‰ƒCƒuƒ‰ƒŠŒ`Ž®‚ȂǁC‘¼‚̃\ƒtƒgƒEƒFƒAŠJ”­‚ÉŽg—p
20 * ‚Å‚«‚éŒ`‚ōĔz•z‚·‚éê‡‚ɂ́CÄ”z•z‚É”º‚¤ƒhƒLƒ…
21ƒƒ“ƒgi—˜—pŽÒƒ}
22 * ƒjƒ…
23ƒAƒ‹‚Ȃǁj‚ɁCã‹L‚Ì’˜ìŒ •\Ž¦C‚±‚Ì—˜—pðŒ‚¨‚æ‚щº‹L‚Ì–³•Û
24 * Ø‹K’è‚ðŒfÚ‚·‚邱‚ƁD
25 * (3) –{ƒ\ƒtƒgƒEƒFƒA‚ðC‹@Ší‚É‘g‚ݍž‚ނȂǁC‘¼‚̃\ƒtƒgƒEƒFƒAŠJ”­‚ÉŽg—p
26 * ‚Å‚«‚È‚¢Œ`‚ōĔz•z‚·‚éê‡‚ɂ́CŽŸ‚Ì‚¢‚¸‚ê‚©‚ÌðŒ‚ð–ž‚½‚·‚±‚ƁD
27 * (a) Ä”z•z‚É”º‚¤ƒhƒLƒ…
28ƒƒ“ƒgi—˜—pŽÒƒ}ƒjƒ…
29ƒAƒ‹‚Ȃǁj‚ɁCã‹L‚Ì’˜ì
30 * Œ •\Ž¦C‚±‚Ì—˜—pðŒ‚¨‚æ‚щº‹L‚Ì–³•ÛØ‹K’è‚ðŒfÚ‚·‚邱‚ƁD
31 * (b) Ä”z•z‚ÌŒ`‘Ô‚ðC•Ê‚É’è‚ß‚é•û–@‚É‚æ‚Á‚āCTOPPERSƒvƒƒWƒFƒNƒg‚É•ñ
32 * ‚·‚邱‚ƁD
33 * (4) –{ƒ\ƒtƒgƒEƒFƒA‚Ì—˜—p‚É‚æ‚è’¼Ú“I‚Ü‚½‚͊ԐړI‚ɐ¶‚¶‚é‚¢‚©‚Ȃ鑹ŠQ
34 * ‚©‚ç‚àCã‹L’˜ìŒ ŽÒ‚¨‚æ‚ÑTOPPERSƒvƒƒWƒFƒNƒg‚ð–Ɛӂ·‚邱‚ƁD‚Ü‚½C
35 * –{ƒ\ƒtƒgƒEƒFƒA‚̃†[ƒU‚Ü‚½‚̓Gƒ“ƒhƒ†[ƒU‚©‚ç‚Ì‚¢‚©‚Ȃ闝—R‚ÉŠî‚Ã
36 * ‚­¿‹‚©‚ç‚àCã‹L’˜ìŒ ŽÒ‚¨‚æ‚ÑTOPPERSƒvƒƒWƒFƒNƒg‚ð–Ɛӂ·‚邱‚Ɓ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ƒA‚Ì—˜—p
41 * ‚É‚æ‚è’¼Ú“I‚Ü‚½‚͊ԐړI‚ɐ¶‚¶‚½‚¢‚©‚Ȃ鑹ŠQ‚ÉŠÖ‚µ‚Ä‚àC‚»‚̐ӔC‚ð•‰
42 * ‚í‚È‚¢D
43 *
44 */
45
46/*
47 * ƒvƒƒZƒbƒTˆË‘¶ƒ‚ƒWƒ…
48[ƒ‹iRL78j
49 */
50#pragma EI
51#pragma DI
52#include <kernel_impl.h>
53
54/*
55 * Š„ž‚Ý”­¶‰ñ”‚ð•Û‘¶‚·‚é•Ï”
56 */
57uint8_t intnest;
58
59
60/*
61 * (1) ƒRƒ“ƒeƒLƒXƒg‚ÉŠÖ‚·‚é’è‹`
62 */
63
64
65/*
66 * ƒRƒ“ƒeƒLƒXƒg‚ÌŽQÆ
67 */
68bool_t
69sense_context(void)
70{
71 /* ƒlƒXƒgƒJƒEƒ“ƒ^0‚æ‚è‘å‚È‚ç”ñƒ^ƒXƒNƒRƒ“ƒeƒLƒXƒg */
72 return (intnest > 0);
73}
74
75
76/*
77 * (2) ƒVƒXƒeƒ€ó‘Ô‚ÉŠÖ‚·‚é’è‹`
78 */
79
80/*
81 * CPUƒƒbƒNƒtƒ‰ƒOŽÀŒ»‚Ì‚½‚߂̕ϐ”
82 */
83bool_t lock_flag; /* CPUƒƒbƒNƒtƒ‰ƒO‚Ì’l‚ð•ÛŽ‚·‚é•Ï” */
84#if TMIN_INTPRI != -4
85uint8_t saved_psw; /* Š„ž‚Ý—Dæ“xƒŒƒxƒ‹‚ð•Û‘¶‚·‚é•Ï” */
86#endif
87
88/*
89 * CPU ƒƒbƒNó‘Ԃւ̈ڍs
90 * ‚±‚̊֐”‚́CCPU ƒƒbƒNó‘Ô‚Ì‚Æ‚«‚ɌĂт¾‚³‚ê‚È‚¢‚±‚Æ‚ð‘O’ñ‚Æ‚·‚éD
91 */
92void
93t_lock_cpu(void)
94{
95#if TMIN_INTPRI == -4
96 DI();
97#else
98 /* ƒ^ƒXƒN‚Å‚ÍŠ„ž‚Ý—Dæ“xƒ}ƒXƒN‚Ì’l‚Í 0 ‚Ì‚Í‚¸‚È‚Ì‚Å•Û‘¶‚·‚é•K—v‚ª‚È‚¢ */
99 set_psw(PSW_SET_ISP(get_psw(), ISP_LOCK));
100#endif
101 lock_flag = true;
102}
103
104void
105i_lock_cpu(void)
106{
107#if TMIN_INTPRI == -4
108 DI();
109#else
110 uint8_t psw;
111
112 /*
113 * get_psw() ‚Ì•Ô‚è’l‚ð’¼Ú saved_isp ‚É•Û‘¶‚¹‚¸CˆêŽž•Ï”
114 * psw ‚Ö•Û‘¶‚·‚é‚̂́Cget_psw() ‚̌Ăт¾‚µ’¼Œã‚ÉŠ„ž‚Ý‚ª”­¶‚µC
115 * ‹N“®‚³‚ꂽŠ„ž‚ݏˆ—‚Å saved_isp ‚ª•ÏX‚³‚ê‚é‰Â”\«‚ª‚ ‚邽‚߁D
116 */
117 psw = get_psw();
118 if (TIPM_LOCK < ISP2IPM(PSW2ISP(psw))) {
119 set_psw(PSW_SET_ISP(psw, ISP_LOCK));
120 }
121 saved_psw = psw;
122#endif
123 lock_flag = true;
124}
125
126/*
127 * CPUƒƒbƒNó‘Ԃ̉ðœ
128 * ‚±‚̊֐”‚́CCPU ƒƒbƒNó‘Ô‚Ì‚Æ‚«‚ɂ̂݌Ăт¾‚³‚ê‚邱‚Æ‚ð‘O’ñ‚Æ‚·‚éD
129 */
130void
131t_unlock_cpu(void)
132{
133 lock_flag = false;
134#if TMIN_INTPRI == -4
135 EI();
136#else
137 /* ƒ^ƒXƒNŽÀsŽž‚ÍŠ„ž‚݃}ƒXƒN‘S‰ðœó‘Ô‚Ì‚Í‚¸‚Ȃ̂ŁC‘S‰ðœ‚É‚µ‚Ä‚¨‚­ */
138 set_psw(PSW_SET_ISP(get_psw(), ISP_ENAALL));
139#endif
140}
141
142void
143i_unlock_cpu(void)
144{
145 lock_flag = false;
146#if TMIN_INTPRI == -4
147 EI();
148#else
149 set_psw(PSW_SET_ISP(get_psw(), PSW2ISP(saved_psw)));
150#endif
151}
152
153/*
154 * CPUƒƒbƒNó‘Ô‚ÌŽQÆ
155 */
156bool_t
157x_sense_lock(void)
158{
159 return lock_flag;
160}
161
162/*
163 * Š„ž‚Ý—Dæ“xƒ}ƒXƒN(IPM) ‚̐ݒè
164 * Žw’肵‚½Š„ž‚Ý—Dæ“x(-1, -2, ..., TMIN_INTPRI) ‚ðŒ³‚É
165 * ƒvƒƒZƒbƒT‚ÌŠ„ž‚Ý—Dæ“xƒŒƒxƒ‹ (IPL) ‚ðÝ’è‚·‚éD
166 */
167void
168x_set_ipm(PRI intpri)
169{
170 set_psw(PSW_SET_ISP(get_psw(), IPM2ISP(intpri)));
171}
172
173PRI
174x_get_ipm(void)
175{
176 return (ISP2IPM(PSW2ISP(get_psw())));
177}
178
179
180
181/*
182 * (7) dispacher ‚Å‚ÌŠ„ž‚Ý‘Ò‚¿
183 */
184void
185idle_loop(void)
186{
187 t_unlock_cpu();
188 t_lock_cpu();
189}
190
191
192/*
193 * ƒvƒƒZƒbƒTˆË‘¶‚̏‰Šú‰»
194 */
195void
196prc_initialize(void)
197{
198}
199
200/*
201 * ƒvƒƒZƒbƒTˆË‘¶‚̏I—¹ˆ—
202 */
203void
204prc_terminate(void)
205{
206 /* “Á‚É•K—v‚ȏˆ—‚Í‚È‚¢ */
207}
208
209/*
210 * Š„ž‚Ý—v‹‹ÖŽ~ƒtƒ‰ƒO‚̃Zƒbƒg
211 */
212bool_t
213x_disable_int(INTNO intno)
214{
215 volatile uint8_t *reg_addr;
216
217 /* ƒŒƒxƒ‹’è‹`‚ª0‚Å‚ ‚éê‡‚ÍCFG_INT‚³‚ê‚Ä‚¢‚È‚¢ */
218 if(intpri_table[intno] == 0U)
219 {
220 return (false);
221 }
222 // Š„ž‚݃}ƒXƒNEƒtƒ‰ƒOEƒŒƒWƒXƒ^‚ÌŠY“–ƒrƒbƒg‚ð1‚ɃZƒbƒg
223 if(intno < 32) {
224 reg_addr = (volatile uint8_t *)TADR_MK0L;
225 reg_addr += (intno/8);
226 }
227 else {
228 reg_addr = (volatile uint8_t *)TADR_MK2L;
229 reg_addr += ((intno-32) / 8);
230 }
231 *reg_addr |= (uint8_t)(1 << (intno % 8));
232
233 return(true);
234}
235
236/*
237 * Š„ž‚Ý—v‹‹ÖŽ~ƒtƒ‰ƒO‚̃NƒŠƒA
238 */
239bool_t
240x_enable_int(INTNO intno)
241{
242 volatile uint8_t *reg_addr;
243
244 /* ƒŒƒxƒ‹’è‹`‚ª0‚Å‚ ‚éê‡‚ÍCFG_INT‚³‚ê‚Ä‚¢‚È‚¢ */
245 if(intpri_table[intno] == 0u)
246 {
247 return (false);
248 }
249 // Š„ž‚݃}ƒXƒNEƒtƒ‰ƒOEƒŒƒWƒXƒ^‚ÌŠY“–ƒrƒbƒg‚ð0‚ɃZƒbƒg
250 if(intno < 32) {
251 reg_addr = (volatile uint8_t *)TADR_MK0L;
252 reg_addr += (intno/8);
253 }
254 else {
255 reg_addr = (volatile uint8_t *)TADR_MK2L;
256 reg_addr += ((intno-32) / 8);
257 }
258 *reg_addr &= (uint8_t)~(1 << (intno % 8));
259
260 return(true);
261}
262
263/*
264 * Š„ž‚Ý—v‹‚̃NƒŠƒA
265 */
266void
267x_clear_int(INTNO intno)
268{
269 volatile uint8_t *reg_addr;
270
271 // Š„ž‚Ý—v‹ƒtƒ‰ƒOEƒŒƒWƒXƒ^‚ÌŠY“–ƒrƒbƒg‚ð0‚ɃZƒbƒg
272 if(intno < 32) {
273 reg_addr = (volatile uint8_t *)TADR_IF0L;
274 reg_addr += (intno/8);
275 }
276 else {
277 reg_addr = (volatile uint8_t *)TADR_IF2L;
278 reg_addr += ((intno-32) / 8);
279 }
280 *reg_addr &= (uint8_t)~(1 << (intno % 8));
281}
282
283/*
284 * Š„ž‚Ý—v‹‚̃`ƒFƒbƒN
285 */
286bool_t
287x_probe_int(INTNO intno)
288{
289 volatile uint8_t *reg_addr;
290
291 // Š„ž‚Ý—v‹ƒtƒ‰ƒOEƒŒƒWƒXƒ^‚ÌŠY“–ƒrƒbƒg‚ª 1 ‚È‚ç true
292 if(intno < 32) {
293 reg_addr = (volatile uint8_t *)TADR_IF0L;
294 reg_addr += (intno/8);
295 }
296 else {
297 reg_addr = (volatile uint8_t *)TADR_IF2L;
298 reg_addr += ((intno-32) / 8);
299 }
300
301 return((*reg_addr & (uint8_t)(1 << (intno % 8))) != 0);
302}
303
304/*
305 * Š„ž‚Ý—v‹ƒ‰ƒCƒ“‚Ì‘®«‚̐ݒè
306 */
307void
308x_config_int(INTNO intno, ATR intatr, PRI intpri)
309{
310 volatile uint8_t *reg_addr;
311 uint8_t portno;
312
313 assert(VALID_INTNO_CFGINT(intno));
314 assert(TMIN_INTPRI <= intpri && intpri <= TMAX_INTPRI);
315
316 /*
317 * Š„ž‚݂̃}ƒXƒN
318 *
319 * Š„ž‚Ý‚ðŽó‚¯•t‚¯‚½‚܂܁CƒŒƒxƒ‹ƒgƒŠƒK^ƒGƒbƒWƒgƒŠƒK‚̐ݒè‚âCŠ„
320 * ž‚Ý—Dæ“x‚̐ݒè‚ðs‚¤‚̂͊댯‚È‚½‚߁CŠ„ž‚Ý‘®«‚É‚©‚©‚í‚炸C
321 * ˆê’Uƒ}ƒXƒN‚·‚éD
322 */
323 (void) x_disable_int(intno);
324
325 /*
326 * —Dæ“x‚̐ݒè
327 */
328 // —Dæ‡ˆÊŽw’èƒtƒ‰ƒOEƒŒƒWƒXƒ^‚ÌŠY“–ƒrƒbƒg‚É’l‚ðƒZƒbƒg
329 if(intno < 32) {
330 reg_addr = (volatile uint8_t *)TADR_PR00L;
331 reg_addr += (intno/8);
332 }
333 else {
334 reg_addr = (volatile uint8_t *)TADR_PR02L;
335 reg_addr += ((intno-32) / 8);
336 }
337 // —Dæ‡ˆÊƒŒƒxƒ‹‚̐ݒè(’áˆÊƒrƒbƒg)
338 if((IPM2ILVL(intpri) & 0x01) != 0) {
339 *reg_addr |= (uint8_t)(1 << (intno % 8));
340 }
341 else {
342 *reg_addr &= (uint8_t)~(1 << (intno % 8));
343 }
344 // —Dæ‡ˆÊƒŒƒxƒ‹‚̐ݒè(‚ˆÊƒrƒbƒg)
345 if((IPM2ILVL(intpri) & 0x02) != 0) {
346 *(reg_addr+4) |= (uint8_t)(1 << (intno % 8));
347 }
348 else {
349 *(reg_addr+4) &= (uint8_t)~(1 << (intno % 8));
350 }
351
352 /*
353 * ƒgƒŠƒK‚̐ݒè
354 */
355 if(intno <= 7) {
356 reg_addr = (volatile uint8_t *)TADR_EGP0; // EGP0
357 portno = (uint8_t)(intno - 2);
358 }
359 else {
360 reg_addr = (volatile uint8_t *)TADR_EGP1; // EGP1
361 portno = (uint8_t)(intno - 29);
362 }
363
364 /* INT’[Žq‚̏ꍇ‚ÍŠ„ž‚ÝŒŸ’m•û–@‚ðÝ’è‚·‚é */
365 if((intatr & TA_POSEDGE) != 0U)
366 {
367 // ŠO•”Š„ž‚Ý—§‚¿ã‚ª‚èƒGƒbƒW‹–‰ÂƒŒƒWƒXƒ^‚ÌŠY“–ƒrƒbƒg‚ð1‚ɃZƒbƒg
368 *reg_addr |= (uint8_t)(1 << (portno % 8));
369 // ŠO•”Š„ž‚Ý—§‚¿‰º‚ª‚èƒGƒbƒW‹–‰ÂƒŒƒWƒXƒ^‚ÌŠY“–ƒrƒbƒg‚ð0‚ɃZƒbƒg
370 *(reg_addr+1) &= (uint8_t)~(1 << (portno % 8));
371 }
372 else if((intatr & TA_NEGEDGE) != 0U)
373 {
374 // ŠO•”Š„ž‚Ý—§‚¿ã‚ª‚èƒGƒbƒW‹–‰ÂƒŒƒWƒXƒ^‚ÌŠY“–ƒrƒbƒg‚ð0‚ɃZƒbƒg
375 *reg_addr &= (uint8_t)~(1 << (portno % 8));
376 // ŠO•”Š„ž‚Ý—§‚¿‰º‚ª‚èƒGƒbƒW‹–‰ÂƒŒƒWƒXƒ^‚ÌŠY“–ƒrƒbƒg‚ð1‚ɃZƒbƒg
377 *(reg_addr+1) |= (uint8_t)(1 << (portno % 8));
378 }
379 else if((intatr & TA_BOTHEDGE) != 0U)
380 {
381 // ŠO•”Š„ž‚Ý—§‚¿ã‚ª‚èƒGƒbƒW‹–‰ÂƒŒƒWƒXƒ^‚ÌŠY“–ƒrƒbƒg‚ð1‚ɃZƒbƒg
382 *reg_addr |= (uint8_t)(1 << (portno % 8));
383 // ŠO•”Š„ž‚Ý—§‚¿‰º‚ª‚èƒGƒbƒW‹–‰ÂƒŒƒWƒXƒ^‚ÌŠY“–ƒrƒbƒg‚ð1‚ɃZƒbƒg
384 *(reg_addr+1) |= (uint8_t)(1 << (portno % 8));
385 }
386 else { // ‚Ç‚¿‚ç‚Å‚à‚È‚¢ê‡‚̓GƒbƒWŒŸo‚ð‹ÖŽ~
387 // ŠO•”Š„ž‚Ý—§‚¿ã‚ª‚èƒGƒbƒW‹–‰ÂƒŒƒWƒXƒ^‚ÌŠY“–ƒrƒbƒg‚ð0‚ɃZƒbƒg
388 *reg_addr &= (uint8_t)~(1 << (portno % 8));
389 // ŠO•”Š„ž‚Ý—§‚¿‰º‚ª‚èƒGƒbƒW‹–‰ÂƒŒƒWƒXƒ^‚ÌŠY“–ƒrƒbƒg‚ð0‚ɃZƒbƒg
390 *(reg_addr+1) &= (uint8_t)~(1 << (portno % 8));
391 }
392
393 /*
394 * Š„ž‚݂̃}ƒXƒN‰ðœ(—Dæ“xÝ’è)
395 */
396 if ((intatr & TA_ENAINT) != 0U) {
397 (void) x_enable_int(intno);
398 }
399}
400
401/*
402 * NMI‚ðœ‚­‚·‚ׂĂ̊„ž‚Ý‚Ì‹ÖŽ~
403 */
404uint8_t
405TOPPERS_disint(void)
406{
407 volatile uint8_t TOPPERS_psw;
408
409 TOPPERS_psw = get_psw();
410 DI();
411 return(TOPPERS_psw);
412}
413
414/*
415 * Š„ž‚Ý—Dæ“xƒ}ƒXƒNi“à•”•\Œ»j‚ÌŒ»Ý’l‚̐ݒè
416 */
417void
418TOPPERS_enaint(uint8_t TOPPERS_psw)
419{
420 if(TOPPERS_psw & PSW_IE_MASK)
421 {
422 EI();
423 }
424}
425
426
Note: See TracBrowser for help on using the repository browser.