source: ssp_qb_r5f100le_cs/trunk/arch/arm_m_gcc/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: 7.1 KB
Line 
1/*
2 * TOPPERS/SSP Kernel
3 * Smallest Set Profile Kernel
4 *
5 * Copyright (C) 2008 by Embedded and Real-Time Systems Laboratory
6 * Graduate School of Information Science, Nagoya Univ., JAPAN
7 * Copyright (C) 2010 by Meika Sugimoto
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: prc_config.c 1304 2008-08-27 07:28:36Z ertl-honda $
43 */
44
45/*
46 * ƒvƒƒZƒbƒTˆË‘¶ƒ‚ƒWƒ…
47[ƒ‹iARM-M—pj
48 */
49
50#include "kernel_impl.h"
51#include "check.h"
52#include "task.h"
53
54#include <t_syslog.h>
55
56/*
57 * CPUƒƒbƒNƒtƒ‰ƒOŽÀŒ»‚Ì‚½‚߂̕ϐ”
58 */
59volatile bool_t lock_flag; /* CPUƒƒbƒNƒtƒ‰ƒO‚Ì’l‚ð•ÛŽ‚·‚é•Ï” */
60volatile uint32_t saved_iipm; /* Š„ž‚Ý—Dæ“xƒ}ƒXƒN‚ð•Û‘¶‚·‚é•Ï” */
61
62/* Š„ž‚݃lƒXƒg”‚ÌŠÇ— */
63uint8_t intnest;
64
65/*
66 * ƒxƒNƒ^ƒe[ƒuƒ‹(kernel_cfg.c)
67 */
68extern const FP vector_table[];
69
70/*
71 * ƒVƒXƒeƒ€—áŠOEŠ„ž‚݂́i—áŠO”ԍ† 4`15j
72 * Š„ž‚Ý—Dæ“xÝ’背ƒWƒXƒ^‚ւ̃AƒNƒZƒX‚Ì‚½‚ß‚Ì”z—ñ
73 */
74static const unsigned int nvic_sys_pri_reg[] = {
75 0,
76 NVIC_SYS_PRI1,
77 NVIC_SYS_PRI2,
78 NVIC_SYS_PRI3
79};
80
81/*
82 * —áŠO‚ÆŠ„ž‚Ý‚ÌŠ„ž‚Ý—Dæ“x‚ðƒZƒbƒg
83 *
84 * excno‚ÍARM-M‚Å’è‚ß‚ç‚ê‚Ä‚¢‚é Exception Number ‚ðŽw’èD
85 */
86void
87set_exc_int_priority(uint32_t excno, uint8_t pri){
88 uint32_t tmp, reg;
89
90 /*
91 * Š„ž‚Ý—Dæ“xÝ’背ƒWƒXƒ^‚ÌŒˆ’è
92 */
93 if ((EXCNO_MPU <= excno) && (excno <= IRQNO_SYSTICK)) {
94 /*
95 * Exception Number 4(Memory Management)‚©‚ç
96 * Exception Number 15(SysTick)‚Ü‚Å‚ÌŠ„ž‚Ý—Dæ“x‚̓VƒXƒeƒ€—Dæ“x
97 * ƒŒƒWƒXƒ^‚É‚æ‚èÝ’èD
98 */
99 reg = nvic_sys_pri_reg[excno >> 2];
100 }
101 else if ((TMIN_INTNO < excno) && (excno <= TMAX_INTNO)){
102 /*
103 * IRQŠ„ž‚Ý‚È‚ç
104 */
105 reg = NVIC_PRI0 + (((excno - (TMIN_INTNO + 1)) >> 2) * 4);
106 }
107 else {
108 return ;
109 }
110
111 tmp = sil_rew_mem((void *)reg);
112 tmp &= ~(0xFF << (8 * (excno & 0x03)));
113 tmp |= (pri << (8 - TBITW_IPRI)) << (8 * (excno & 0x03));
114 sil_wrw_mem((void *)reg, tmp);
115}
116
117/*
118 * —áŠO‚Ì‹–‰Â
119 *
120 * Memory Management, Bus Fault, Usage Fault ‚Í‹ÖŽ~E‹–‰Â‚ª”ƒ‚¨‚¤
121 */
122void
123enable_exc(EXCNO excno)
124{
125 uint32_t tmp;
126
127 switch (excno) {
128 case EXCNO_MPU:
129 tmp = sil_rew_mem((void *)NVIC_SYS_HND_CTRL);
130 tmp |= NVIC_SYS_HND_CTRL_MEM;
131 sil_wrw_mem((void *)NVIC_SYS_HND_CTRL, tmp);
132 break;
133 case EXCNO_BUS:
134 tmp = sil_rew_mem((void *)NVIC_SYS_HND_CTRL);
135 tmp |= NVIC_SYS_HND_CTRL_BUS;
136 sil_wrw_mem((void *)NVIC_SYS_HND_CTRL, tmp);
137 break;
138 case EXCNO_USAGE:
139 tmp = sil_rew_mem((void *)NVIC_SYS_HND_CTRL);
140 tmp |= NVIC_SYS_HND_CTRL_USAGE;
141 sil_wrw_mem((void *)NVIC_SYS_HND_CTRL, tmp);
142 break;
143 }
144}
145
146/*
147 * —áŠO‚Ì‹ÖŽ~
148 */
149void
150disable_exc(EXCNO excno)
151{
152 uint32_t tmp;
153
154 switch (excno) {
155 case EXCNO_MPU:
156 tmp = sil_rew_mem((void *)NVIC_SYS_HND_CTRL);
157 tmp &= ~NVIC_SYS_HND_CTRL_MEM;
158 sil_wrw_mem((void *)NVIC_SYS_HND_CTRL, tmp);
159 break;
160 case EXCNO_BUS:
161 tmp = sil_rew_mem((void *)NVIC_SYS_HND_CTRL);
162 tmp &= ~NVIC_SYS_HND_CTRL_BUS;
163 sil_wrw_mem((void *)NVIC_SYS_HND_CTRL, tmp);
164 break;
165 case EXCNO_USAGE:
166 tmp = sil_rew_mem((void *)NVIC_SYS_HND_CTRL);
167 tmp &= ~NVIC_SYS_HND_CTRL_USAGE;
168 sil_wrw_mem((void *)NVIC_SYS_HND_CTRL, tmp);
169 break;
170 }
171}
172
173
174/*
175 * ƒvƒƒZƒbƒTˆË‘¶‚̏‰Šú‰»
176 */
177void
178prc_initialize(void)
179{
180 /*
181 * CPUƒƒbƒNƒtƒ‰ƒOŽÀŒ»‚Ì‚½‚߂̕ϐ”‚̏‰Šú‰»
182 */
183 lock_flag = true;
184 saved_iipm = IIPM_ENAALL;
185
186 /* Š„ž‚݃lƒXƒg”‚̏‰Šú‰» */
187 intnest = 0u;
188
189 /*
190 * ƒxƒNƒ^ƒe[ƒuƒ‹‚ðÝ’è
191 */
192 sil_wrw_mem((void*)NVIC_VECTTBL, (uint32_t)vector_table);
193
194 /*
195 * SVCƒnƒ“ƒhƒ‰‚Ì—Dæ“x‚ðÝ’è
196 */
197 set_exc_int_priority(EXCNO_SVCALL, 0);
198
199 /*
200 * SVCƒnƒ“ƒhƒ‰‚ð—LŒø‚É
201 */
202 x_enable_int(EXCNO_SVCALL);
203}
204
205/*
206 * ƒvƒƒZƒbƒTˆË‘¶‚̏I—¹ˆ—
207 */
208void
209prc_terminate(void)
210{
211 while(1)
212 ;
213}
214
215/*
216 * Š„ž‚Ý—v‹ƒ‰ƒCƒ“‘®«‚̐ݒè
217 */
218void
219x_config_int(INTNO intno, ATR intatr, PRI intpri)
220{
221 //assert(VALID_INTNO_CFGINT(intno));
222 //assert(TMIN_INTPRI <= intpri && intpri <= TMAX_INTPRI);
223
224 /*
225 * ˆê’UŠ„ž‚Ý‚ð‹ÖŽ~‚·‚é
226 */
227 (void)x_disable_int(intno);
228 x_clear_int(intno);
229
230 /*
231 * Š„ž‚Ý—Dæ“x‚ðƒZƒbƒg
232 */
233 set_exc_int_priority(intno, intpri);
234
235 /*
236 * Š„ž‚Ý—v‹ƒ}ƒXƒN‰ðœ(•K—v‚ȏꍇ)
237 * “¯Žž‚ÉŠ„ž‚Ý—Dæ“x‚àƒZƒbƒg‚³‚ê‚é
238 */
239 if ((intatr & TA_ENAINT) != 0U) {
240 (void) x_enable_int(intno);
241 }
242}
243
244
245#ifndef OMIT_DEFAULT_EXC_HANDLER
246/*
247 * TrapaˆÈŠO‚Ì—áŠO‚Å“o˜^‚³‚ê‚Ä‚¢‚È‚¢—áŠO‚ª”­¶‚·‚é‚ƌĂяo‚³‚ê‚é
248 */
249void
250default_exc_handler(void *p_excinf)
251{
252 uint32_t basepri = *(((uint32_t*)p_excinf) + P_EXCINF_OFFSET_BASEPRI);
253 uint32_t pc = *(((uint32_t*)p_excinf) + P_EXCINF_OFFSET_PC);
254 uint32_t xpsr = *(((uint32_t*)p_excinf) + P_EXCINF_OFFSET_XPSR);
255 uint32_t excno = get_ipsr() & IPSR_ISR_NUMBER;
256
257 syslog(LOG_EMERG, "\nUnregistered Exception occurs.");
258 syslog(LOG_EMERG, "Excno = %08x PC = %08x XPSR = %08x basepri = %08X, p_excinf = %08X",
259 excno, pc, xpsr, basepri, p_excinf);
260
261 target_exit();
262}
263#endif /* OMIT_DEFAULT_EXC_HANDLER */
264
265#ifndef OMIT_DEFAULT_INT_HANDLER
266/*
267 * –¢“o˜^‚ÌŠ„ž‚Ý‚ª”­¶‚µ‚½ê‡‚ɌĂяo‚³‚ê‚é
268 */
269void
270default_int_handler(void *p_excinf)
271{
272 uint32_t basepri = *(((uint32_t*)p_excinf) + P_EXCINF_OFFSET_BASEPRI);
273 uint32_t pc = *(((uint32_t*)p_excinf) + P_EXCINF_OFFSET_PC);
274 uint32_t xpsr = *(((uint32_t*)p_excinf) + P_EXCINF_OFFSET_XPSR);
275 uint32_t excno = get_ipsr() & IPSR_ISR_NUMBER;
276
277 syslog(LOG_EMERG, "\nUnregistered Interrupt occurs.");
278 syslog(LOG_EMERG, "Excno = %08x PC = %08x XPSR = %08x basepri = %08X, p_excinf = %08X",
279 excno, pc, xpsr, basepri, p_excinf);
280
281 target_exit();
282}
283#endif /* OMIT_DEFAULT_INT_HANDLER */
Note: See TracBrowser for help on using the repository browser.