source: ssp_qb_r5f100le_cs/trunk/target/qb_r5f100le_cs/ssp_rl78/sample1/src/sample1.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.4 KB
Line 
1/*
2 * TOPPERS/SSP Kernel
3 * Smallest Set Profile Kernel
4 *
5 *
6 * Copyright (C) 2008 by Embedded and Real-Time Systems Laboratory
7 * Graduate School of Information Science, Nagoya Univ., JAPAN
8 * Copyright (C) 2010-2012 by Meika Sugimoto
9 * Copyright (C) 2014,2015 by Naoki Saito
10 * Nagoya Municipal Industrial Research Institute, JAPAN
11 *
12 * ã‹L’˜ìŒ ŽÒ‚́CˆÈ‰º‚Ì(1)`(4)‚ÌðŒ‚ð–ž‚½‚·ê‡‚ÉŒÀ‚èC–{ƒ\ƒtƒgƒEƒF
13 * ƒAi–{ƒ\ƒtƒgƒEƒFƒA‚ð‰ü•Ï‚µ‚½‚à‚Ì‚ðŠÜ‚ށDˆÈ‰º“¯‚¶j‚ðŽg—pE•¡»E‰ü
14 * •ÏEÄ”z•ziˆÈ‰ºC—˜—p‚ƌĂԁj‚·‚邱‚Ƃ𖳏ž‚Å‹–‘ø‚·‚éD
15 * (1) –{ƒ\ƒtƒgƒEƒFƒA‚ðƒ\[ƒXƒR[ƒh‚ÌŒ`‚Å—˜—p‚·‚éê‡‚ɂ́Cã‹L‚Ì’˜ì
16 * Œ •\Ž¦C‚±‚Ì—˜—pðŒ‚¨‚æ‚щº‹L‚Ì–³•ÛØ‹K’肪C‚»‚Ì‚Ü‚Ü‚ÌŒ`‚Ń\[
17 * ƒXƒR[ƒh’†‚ÉŠÜ‚Ü‚ê‚Ä‚¢‚邱‚ƁD
18 * (2) –{ƒ\ƒtƒgƒEƒFƒA‚ðCƒ‰ƒCƒuƒ‰ƒŠŒ`Ž®‚ȂǁC‘¼‚̃\ƒtƒgƒEƒFƒAŠJ”­‚ÉŽg
19 * —p‚Å‚«‚éŒ`‚ōĔz•z‚·‚éê‡‚ɂ́CÄ”z•z‚É”º‚¤ƒhƒLƒ…
20ƒƒ“ƒgi—˜—p
21 * ŽÒƒ}ƒjƒ…
22ƒAƒ‹‚Ȃǁj‚ɁCã‹L‚Ì’˜ìŒ •\Ž¦C‚±‚Ì—˜—pðŒ‚¨‚æ‚щº‹L
23 * ‚Ì–³•ÛØ‹K’è‚ðŒfÚ‚·‚邱‚ƁD
24 * (3) –{ƒ\ƒtƒgƒEƒFƒA‚ðC‹@Ší‚É‘g‚ݍž‚ނȂǁC‘¼‚̃\ƒtƒgƒEƒFƒAŠJ”­‚ÉŽg
25 * —p‚Å‚«‚È‚¢Œ`‚ōĔz•z‚·‚éê‡‚ɂ́CŽŸ‚Ì‚¢‚¸‚ê‚©‚ÌðŒ‚ð–ž‚½‚·‚±
26 * ‚Ɓ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‚ɐ¶‚¶‚é‚¢‚©‚Ȃ鑹
34 * ŠQ‚©‚ç‚àCã‹L’˜ìŒ ŽÒ‚¨‚æ‚ÑTOPPERSƒvƒƒWƒFƒNƒg‚ð–Ɛӂ·‚邱‚ƁD
35 * ‚Ü‚½C–{ƒ\ƒtƒgƒEƒFƒA‚̃†[ƒU‚Ü‚½‚̓Gƒ“ƒhƒ†[ƒU‚©‚ç‚Ì‚¢‚©‚Ȃ闝
36 * —R‚ÉŠî‚­¿‹‚©‚ç‚àCã‹L’˜ìŒ ŽÒ‚¨‚æ‚ÑTOPPERSƒvƒƒWƒFƒNƒg‚ð
37 * –Ɛӂ·‚邱‚ƁD
38 *
39 * –{ƒ\ƒtƒgƒEƒFƒA‚́C–³•ÛØ‚Å’ñ‹Ÿ‚³‚ê‚Ä‚¢‚é‚à‚Ì‚Å‚ ‚éDã‹L’˜ìŒ ŽÒ‚¨
40 * ‚æ‚ÑTOPPERSƒvƒƒWƒFƒNƒg‚́C–{ƒ\ƒtƒgƒEƒFƒA‚ÉŠÖ‚µ‚āC“Á’è‚ÌŽg—p–Ú“I
41 * ‚ɑ΂·‚é“K‡«‚àŠÜ‚߂āC‚¢‚©‚È‚é•ÛØ‚às‚í‚È‚¢D‚Ü‚½C–{ƒ\ƒtƒgƒEƒF
42 * ƒA‚Ì—˜—p‚É‚æ‚è’¼Ú“I‚Ü‚½‚͊ԐړI‚ɐ¶‚¶‚½‚¢‚©‚Ȃ鑹ŠQ‚ÉŠÖ‚µ‚Ä‚àC‚»
43 * ‚̐ӔC‚𕉂í‚È‚¢D
44 *
45 */
46
47/*
48 * TOPPERS/SSP‚̃Tƒ“ƒvƒ‹ƒvƒƒOƒ‰ƒ€
49 *
50 * SSPƒJ[ƒlƒ‹‚ÌŠî–{“I‚È“®ì‚ðŠm”F‚·‚邽‚߂̃Tƒ“ƒvƒ‹ƒvƒƒOƒ‰ƒ€D
51 *
52 * ƒvƒƒOƒ‰ƒ€‚ÌŠT—v:
53 *
54 * ƒ†[ƒUƒCƒ“ƒ^ƒtƒF[ƒX‚ðŽó‚¯Ž‚ƒƒCƒ“ƒ^ƒXƒN‚ƁC3‚‚̕ÀsŽÀs‚³‚ê‚é
55 * ƒ^ƒXƒN‚Ƃō\¬‚³‚ê‚éDƒ^ƒXƒNID‚¨‚æ‚Ñ—Dæ“xÝ’è‚͈ȉº‚Ì’Ê‚èD
56 * (ƒ^ƒXƒNID) (‹N“®Žž—Dæ“x) (ŽÀsŽž—Dæ“x)
57 * MAIN_TASK MAIN_PRIORITY (¶‚É“¯‚¶)
58 * TASK1 TASK1_PRIORITY (¶‚É“¯‚¶)
59 * TASK2 TASK2_PRIORITY (¶‚É“¯‚¶)
60 * TASK3 TASK3_PRIORITY TASK3_EXEPRIORITY
61 *
62 * ‚Ü‚½C‹N“®ŽüŠú‚ª2•b‚ÌŽüŠúƒnƒ“ƒhƒ‰iŽüŠúƒnƒ“ƒhƒ‰ID: CYC1j‚¨‚æ‚Ñ
63 * ƒƒCƒ“ƒ^ƒXƒN‹N“®—p‚ÌŽüŠúƒnƒ“ƒhƒ‰(ŽüŠúƒnƒ“ƒhƒ‰ID: MAIN_CYC)‚ð—p‚¢‚éD
64 *
65 * •ÀsŽÀs‚³‚ê‚éƒ^ƒXƒN‚́Ctask_loop‰ñ‹óƒ‹[ƒv‚ðŽÀs‚·‚é“x‚ɁCƒ^ƒXƒN‚ª
66 * ŽÀs’†‚Å‚ ‚邱‚Æ‚ð‚ ‚ç‚í‚·ƒƒbƒZ[ƒW‚ð•\Ž¦‚·‚éD‹óƒ‹[ƒv‚ðŽÀs‚·‚é
67 * ‚̂́C‹óƒ‹[ƒv‚È‚µ‚сƒbƒZ[ƒW‚ðo—Í‚·‚é‚ƁC‘½—ʂ̃ƒbƒZ[ƒW‚ªo—Í
68 * ‚³‚êCƒvƒƒOƒ‰ƒ€‚Ì“®ì‚ªŠm”F‚µ‚¸‚ç‚­‚Ȃ邽‚ß‚Å‚ ‚éD‚Ü‚½C’ᑬ‚ȃV
69 * ƒŠƒAƒ‹ƒ|[ƒg‚ð—p‚¢‚ăƒbƒZ[ƒW‚ðo—Í‚·‚éê‡‚ɁC‚·‚ׂẴƒbƒZ[ƒW
70 * ‚ªo—Í‚Å‚«‚é‚悤‚ɁCƒƒbƒZ[ƒW‚̗ʂ𐧌À‚·‚é‚Æ‚¢‚¤——R‚à‚ ‚éD
71 *
72 * ŽüŠúƒnƒ“ƒhƒ‰(CYC1)‚́C‹N“®‚µ‚½‚±‚Æ‚ðŽ¦‚·ƒƒbƒZ[ƒW‚ð•\Ž¦‚·‚éD
73 * ƒvƒƒOƒ‰ƒ€‚Ì‹N“®’¼Œã‚́CŽüŠúƒnƒ“ƒhƒ‰(CYC1)‚Í’âŽ~ó‘Ô‚É‚È‚Á‚Ä‚¢‚éD
74 *
75 * ƒƒCƒ“ƒ^ƒXƒN‚́CŽüŠúƒnƒ“ƒhƒ‰(MAIN_CYC)‚©‚ç100ƒ~ƒŠ•b‚²‚Æ‚É‹N“®‚³‚êC
76 * ƒVƒŠƒAƒ‹I/Oƒ|[ƒg‚©‚ç‚Ì•¶Žš“ü—Í‚ðs‚¢C“ü—Í‚³‚ꂽ
77 * •¶Žš‚ɑΉž‚µ‚½ˆ—‚ðŽÀs‚·‚éD“ü—Í‚³‚ꂽ•¶Žš‚Əˆ—‚ÌŠÖŒW‚ÍŽŸ‚Ì’Ê‚èD
78 * 'Q'‚ª“ü—Í‚³‚ê‚é‚ƁCƒvƒƒOƒ‰ƒ€‚ðI—¹‚·‚éD
79 *
80 * '1' : ‘Ώۃ^ƒXƒN‚ðTASK1‚ɐ؂芷‚¦‚éi‰ŠúÝ’èjD
81 * '2' : ‘Ώۃ^ƒXƒN‚ðTASK2‚ɐ؂芷‚¦‚éD
82 * '3' : ‘Ώۃ^ƒXƒN‚ðTASK3‚ɐ؂芷‚¦‚éD
83 * 'a' : ‘Ώۃ^ƒXƒN‚ðact_tsk‚É‚æ‚è‹N“®‚·‚éD
84 * 'e' : ‘Ώۃ^ƒXƒN‚ðŠÖ”‚̃Šƒ^[ƒ“‚É‚æ‚èI—¹‚³‚¹‚éD
85 * 'c' : ŽüŠúƒnƒ“ƒhƒ‰‚𓮍ìŠJŽn‚³‚¹‚éD
86 * 'C' : ŽüŠúƒnƒ“ƒhƒ‰‚𓮍ì’âŽ~‚³‚¹‚éD
87 * 'b' : ƒAƒ‰[ƒ€ƒnƒ“ƒhƒ‰‚ð5•bŒã‚É‹N“®‚·‚é‚悤“®ìŠJŽn‚³‚¹‚éD
88 * 'B' : ƒAƒ‰[ƒ€ƒnƒ“ƒhƒ‰‚𓮍ì’âŽ~‚³‚¹‚éD
89 * 'z' : ‘Ώۃ^ƒXƒN‚ÉCPU—áŠO‚𔭐¶‚³‚¹‚éiƒ^ƒXƒN‚ðI—¹‚³‚¹‚éjD
90 * 's' : ƒCƒxƒ“ƒgƒtƒ‰ƒO(ID:FLG1)‚É“–ŠYƒ^ƒXƒN‚ÉŠÖ˜A‚·‚éƒrƒbƒg‚ðƒZƒbƒg‚·‚éD
91 * 'l' : ‚·‚ׂẴ^ƒXƒNŠÖ˜A‚·‚éƒCƒxƒ“ƒgƒtƒ‰ƒO(ID:FLG1)‚̃rƒbƒg‚ðƒNƒŠƒA‚·‚éD
92 * 'p' : ƒ|[ƒŠƒ“ƒO‚ŃCƒxƒ“ƒgƒtƒ‰ƒO(FLG1)‚ð‘҂D
93 * 'd' : ƒ|[ƒŠƒ“ƒO‚Ńf[ƒ^ƒLƒ…
94[(ID:DTQ1)‚Öƒf[ƒ^‚𑗐M‚·‚éD
95 * 'r' : ƒ|[ƒŠƒ“ƒO‚Ńf[ƒ^ƒLƒ…
96[(ID:DTQ1)‚©‚çƒf[ƒ^‚ðŽóM‚·‚éD
97 */
98
99#include <kernel.h>
100#include <sil.h>
101#include <t_syslog.h>
102#include "kernel_cfg.h"
103#include "syssvc/serial.h"
104#include "syssvc/logtask.h"
105
106#include "sample1.h"
107
108
109/*
110 * ƒVƒXƒeƒ€ƒT[ƒrƒX‚̃Gƒ‰[ƒnƒ“ƒhƒŠƒ“ƒO
111 */
112#define SVC(expression) \
113 if((expression) < 0) \
114 { \
115 syslog(LOG_NOTICE , "Error at %s : %d caused by %s." , \
116 __FILE__ , __LINE__ , #expression); \
117 }
118
119/*
120 * •À—ñŽÀs‚³‚ê‚éƒ^ƒXƒN‚ւ̃ƒbƒZ[ƒW—̈æ
121 */
122char message[3];
123
124/*
125 * ƒ‹[ƒv‰ñ”
126 */
127ulong_t task_loop; /* ƒ^ƒXƒN“à‚ł̃‹[ƒv‰ñ” */
128
129void init_task(intptr_t exinf)
130{
131#ifndef TASK_LOOP
132 volatile ulong_t i;
133 SYSTIM stime1, stime2;
134#endif /* TASK_LOOP */
135
136 /* ƒVƒŠƒAƒ‹ƒ|[ƒg‚̃I[ƒvƒ“ */
137 SVC(serial_opn_por(TASK_PORTID));
138 SVC(serial_ctl_por(TASK_PORTID , IOCTL_CRLF));
139
140 /* ƒƒOƒ^ƒXƒN‚̏‰Šú‰» */
141 logtask_initialize(LOGTASK_PORTID);
142
143 /* ‹N“®ƒƒbƒZ[ƒW‚̏o—Í */
144 syslog(LOG_INFO , "Sample program starts.");
145
146 /* ŽüŠúƒnƒ“ƒhƒ‰‚Ì‹N“® */
147 SVC(sta_cyc(MAIN_CYC));
148
149 /*
150 * ƒ‹[ƒv‰ñ”‚̐ݒè
151 *
152 * TASK_LOOP‚ªƒ}ƒNƒ’è‹`‚³‚ê‚Ä‚¢‚éê‡C‘ª’肹‚¸‚ɁCTASK_LOOP‚É’è
153 * ‹`‚³‚ꂽ’l‚ðCƒ^ƒXƒN“à‚ł̃‹[ƒv‰ñ”‚Æ‚·‚éD
154 *
155 * MEASURE_TWICE‚ªƒ}ƒNƒ’è‹`‚³‚ê‚Ä‚¢‚éê‡C1‰ñ–Ú‚Ì‘ª’茋‰Ê‚ðŽÌ‚Ä
156 * ‚āC2‰ñ–Ú‚Ì‘ª’茋‰Ê‚ðŽg‚¤D1‰ñ–Ú‚Ì‘ª’è‚Í’·‚ß‚ÌŽžŠÔ‚ªo‚邽‚߁D
157 */
158#ifdef TASK_LOOP
159 task_loop = TASK_LOOP;
160#else /* TASK_LOOP */
161
162 task_loop = LOOP_REF;
163 SVC(get_tim(&stime1));
164 for (i = 0; i < task_loop; i++) {
165 /* ŽžŠÔ‚©‚¹‚¬‚Ì‚½‚߂̃‹[ƒv‚Å‚ ‚èC‚±‚±‚ł͉½‚à‚µ‚È‚¢ */
166 }
167 SVC(get_tim(&stime2));
168 task_loop = LOOP_REF * 400UL / (stime2 - stime1);
169
170#endif /* TASK_LOOP */
171
172}
173
174
175void main_task(intptr_t exinf)
176{
177 static ID tskid = TASK1;
178 static uint_t tskno = 1;
179 char c;
180
181
182 /* ƒVƒŠƒAƒ‹ƒ|[ƒg‚©‚ç‚Ì•¶ŽšŽóM */
183 if(serial_rea_dat(TASK_PORTID , &c , 1) > 0)
184 {
185 switch(c)
186 {
187 case 'e':
188 case 's':
189 case 'l':
190 case 'p':
191 case 'd':
192 case 'r':
193 case 'z':
194 message[tskno-1] = c;
195 break;
196 case '1':
197 tskid = TASK1;
198 tskno = 1;
199 break;
200 case '2':
201 tskid = TASK2;
202 tskno = 2;
203 break;
204 case '3':
205 tskid = TASK3;
206 tskno = 3;
207 break;
208 case 'a':
209 syslog(LOG_INFO, "#act_tsk(%d)", tskno);
210 SVC(act_tsk(tskid));
211 break;
212 case 'b':
213 syslog(LOG_INFO, "#sta_alm(1, 5000)");
214 SVC(sta_alm(ALM1 , 5000));
215 break;
216 case 'B':
217 syslog(LOG_INFO, "#stp_alm(1)");
218 SVC(stp_alm(ALM1));
219 break;
220 case 'c':
221 syslog(LOG_INFO, "sta_cyc(1)");
222 SVC(sta_cyc(CYC1));
223 break;
224 case 'C':
225 syslog(LOG_INFO, "stp_cyc(1)");
226 SVC(stp_cyc(CYC1));
227 break;
228 case 'Q':
229 syslog(LOG_NOTICE, "Sample program ends.");
230 SVC(ext_ker());
231 break;
232 default:
233 /* ƒGƒ‰[•\Ž¦ */
234 syslog(LOG_INFO , "Unknown command.");
235 break;
236 }
237 }
238}
239
240
241void task(intptr_t exinf)
242{
243 /* exinf‚̓^ƒXƒN”ԍ† */
244 uint_t tskno = (uint_t)exinf;
245 int_t n = 0;
246 char command;
247 volatile ulong_t i;
248 const char *graph[] = { "|", " +", " *" };
249 bool_t cont = true;
250 FLGPTN pattern;
251 const FLGPTN flgptn[] = { 0x00000001U, 0x00000002U, 0x00000004U };
252 const FLGPTN allptn = 0x00000007U;
253 intptr_t dtqdata;
254
255 do
256 {
257 for (i = 0; i < task_loop; i++) {
258 /* ŽžŠÔ‚©‚¹‚¬‚Ì‚½‚߂̃‹[ƒv‚Å‚ ‚èC‚±‚±‚ł͉½‚à‚µ‚È‚¢ */
259 }
260
261 /* ƒ^ƒXƒN”ԍ†‚Ì•\Ž¦ */
262 syslog(LOG_NOTICE, "task%d is running (%03d). %s",
263 tskno, ++n, graph[tskno-1]);
264
265 /* ƒRƒ}ƒ“ƒhŽæ“¾CƒƒbƒZ[ƒW—̈æ‚ðƒNƒŠƒA */
266 command = message[tskno - 1];
267 message[tskno - 1] = 0;
268
269 switch(command)
270 {
271 case 'e':
272 cont = false;
273 syslog(LOG_INFO, "#%d#terminate task", tskno);
274 break;
275 case 's':
276 SVC(set_flg(FLG1 , flgptn[tskno - 1]));
277 syslog(LOG_INFO, "#%d#set_flg(flgid=%d , mask=%d)",
278 tskno , FLG1 , flgptn[tskno - 1]);
279 break;
280 case 'l':
281 SVC(clr_flg(FLG1 , ~allptn));
282 syslog(LOG_INFO, "#%d#clr_flg(flgid=%d)", tskno , FLG1);
283 break;
284 case 'p':
285 SVC(pol_flg(FLG1 , allptn , TWF_ORW , &pattern));
286 syslog(LOG_INFO, "#%d#pol_flg(flgid=%d , value=%u)", tskno , FLG1 , pattern);
287 break;
288 case 'd':
289 SVC(psnd_dtq(DTQ1 , (intptr_t)tskno));
290 syslog(LOG_INFO, "#%d#snd_dtq(dtqid=%d , value=%u)", tskno , DTQ1 , tskno);
291 break;
292 case 'r':
293 SVC(prcv_dtq(DTQ1 , (intptr_t *)(&dtqdata)));
294 syslog(LOG_INFO, "#%d#rcv_dtq(dtqid=%d , value=%u)", tskno , DTQ1 , dtqdata);
295 break;
296#ifdef CPUEXC1
297 case 'z':
298 syslog(LOG_NOTICE, "#%d#raise CPU exception", tskno);
299 RAISE_CPU_EXCEPTION;
300 break;
301#endif /* CPUEXC1 */
302 default:
303 break;
304 }
305 }while(cont == true);
306}
307
308
309void alarm_handler(intptr_t exinf)
310{
311 ID tskid = (ID)exinf;
312
313 syslog(LOG_INFO , "Alarm handler is raised.");
314 SVC(iact_tsk(tskid));
315}
316
317void main_task_cychdr(intptr_t exinf)
318{
319 ID tskid = (ID)exinf;
320
321 (void)iact_tsk(tskid);
322}
323
324void cyclic_handler(intptr_t exinf)
325{
326 syslog(LOG_INFO , "Cyclic handler is raised.");
327}
328
329#ifdef CPUEXC1
330void exc_handler(void *p_excinf)
331{
332 syslog(LOG_INFO , "CPU exception handler.");
333 syslog(LOG_INFO , "Kernel exit.");
334
335 (void)ext_ker();
336}
337#endif /* CPUEXC1 */
338
Note: See TracBrowser for help on using the repository browser.