source: UsbWattMeter/trunk/asp_dcre/utils/gentest

Last change on this file was 164, checked in by coas-nagasima, 6 years ago

TOPPERS/ECNLサンプルアプリ「USB充電器電力計」を追加

File size: 8.9 KB
Line 
1#! /usr/bin/perl
2#
3# TOPPERS Software
4# Toyohashi Open Platform for Embedded Real-Time Systems
5#
6# Copyright (C) 2007-2012 by Embedded and Real-Time Systems Laboratory
7# Graduate School of Information Science, Nagoya Univ., 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‰ü
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: gentest 2417 2012-09-07 08:16:42Z ertl-hiro $
43#
44
45#
46# ƒeƒXƒgƒvƒƒOƒ‰ƒ€¶¬ƒc[ƒ‹
47#
48
49$infile = $ARGV[0];
50
51%parampos = (
52 "get_pri" => 2,
53 "get_inf" => 1,
54 "ref_tsk" => 2,
55 "ref_tex" => 2,
56 "ref_sem" => 2,
57 "ref_flg" => 2,
58 "ref_dtq" => 2,
59 "ref_pdq" => 2,
60 "ref_mbx" => 2,
61 "ref_mtx" => 2,
62 "ref_mpf" => 2,
63 "get_tim" => 1,
64 "get_utm" => 1,
65 "ref_cyc" => 2,
66 "ref_alm" => 2,
67 "get_tid" => 1,
68 "iget_tid" => 1,
69 "get_ipm" => 1,
70);
71
72%paramtype = (
73 "get_pri" => "PRI",
74 "get_inf" => "intptr_t",
75 "ref_tsk" => "T_RTSK",
76 "ref_tex" => "T_RTEX",
77 "ref_sem" => "T_RSEM",
78 "ref_flg" => "T_RFLG",
79 "ref_dtq" => "T_RDTQ",
80 "ref_pdq" => "T_RPDQ",
81 "ref_mbx" => "T_RMBX",
82 "ref_mtx" => "T_RMTX",
83 "ref_mpf" => "T_RMPF",
84 "get_tim" => "SYSTIM",
85 "get_utm" => "SYSUTM",
86 "ref_cyc" => "T_RCYC",
87 "ref_alm" => "T_RALM",
88 "get_tid" => "ID",
89 "iget_tid" => "ID",
90 "get_ipm" => "PRI",
91);
92
93sub gen_var_def {
94 local($svc_call) = @_;
95 local($svcname, @params);
96 local($typename, $varname);
97
98 if ($svc_call =~ /^([a-z_]+)\((.*)\)$/) {
99 $svcname = $1;
100 @params = split(/\s*,\s*/, $2);
101
102 if ($parampos{$svcname}) {
103 $varname = $params[@parampos{$svcname} - 1];
104 $varname =~ s/^\&//;
105 $typename = $paramtype{$svcname};
106 ${$TASKVAR{$tskid}}{$typename} = ${varname};
107 }
108 }
109}
110
111sub gen_svc_call {
112 local($svc_call, $error_code_string) = @_;
113 local($error_code);
114
115 $TASKCODE{$tskid} .= $indentstr;
116 $TASKCODE{$tskid} .= sprintf("ercd = %s;\n", $svc_call);
117 gen_var_def($svc_call);
118
119 if ($error_code_string eq "") {
120 $TASKCODE{$tskid} .= $indentstr;
121 $TASKCODE{$tskid} .= sprintf("check_ercd(ercd, E_OK);\n");
122 }
123 elsif ($error_code_string =~ /^\-\>\s*noreturn$/) {
124 # do nothing.
125 }
126 else {
127 $error_code = $error_code_string;
128 $error_code =~ s/^\-\>\s*([A-Z_]*)$/$1/;
129 $TASKCODE{$tskid} .= $indentstr;
130 $TASKCODE{$tskid} .= sprintf("check_ercd(ercd, %s);\n", $error_code);
131 }
132}
133
134sub parse_line {
135 local($line) = @_;
136
137 while ($line =~ s/\\$//) {
138 $line1 = <INFILE>;
139 chomp $line1;
140 $line1 =~ s/^\s*\*\s*//;
141 $line1 =~ s/\s*\/\/.*$//;
142 $line1 =~ s/\s*\.\.\..*$//;
143 $line .= $line1;
144 }
145
146 if ($line =~ /^\.\./) {
147 # do nothing.
148 }
149 elsif ($line =~ /^==\s*((TASK|ALM|CPUEXC|EXTSVC)[0-9]*)(.*)$/) {
150 $startflag = 1;
151 $tskid = $1;
152 $line2 = $3;
153 if ($line2 =~ /^\-TEX(.*)$/) {
154 $tskid = $tskid."-TEX";
155 $line2 = $1;
156 }
157 if ($line2 =~ /^\-([0-9]+)(.*)$/) {
158 $tskcount = $1;
159 $line3 = $2;
160 $indentstr = "\t\t";
161 if (!$TASKCOUNT{$tskid}) {
162 $TASKCOUNT{$tskid} = 0;
163 if ($tskid =~ /^TASK([0-9]*)$/) {
164 $countvar = "task$1_count";
165 }
166 elsif ($tskid =~ /^TASK([0-9]*)-TEX$/) {
167 $countvar = "tex_task$1_count";
168 }
169 elsif ($tskid =~ /^ALM([0-9]*)$/) {
170 $countvar = "alarm$1_count";
171 }
172 elsif ($tskid =~ /^CPUEXC([0-9]*)$/) {
173 $countvar = "cpuexc$1_count";
174 }
175 elsif ($tskid =~ /^EXTSVC([0-9]*)$/) {
176 $countvar = "extsvc$1_count";
177 }
178 $TASKCOUNTVAR{$tskid} = $countvar;
179 }
180 if ($tskcount == $TASKCOUNT{$tskid} + 1) {
181 if ($tskcount > 1) {
182 $TASKCODE{$tskid} .= "\n".$indentstr;
183 $TASKCODE{$tskid} .= sprintf("check_point(0);\n\n");
184 }
185 $TASKCOUNT{$tskid} = $tskcount;
186 $TASKCODE{$tskid} .= sprintf("\tcase %d:", $tskcount);
187 }
188 elsif ($tskcount != $TASKCOUNT{$tskid} && $line3 !~ /^-/) {
189 printf STDERR "Subtask count error: %s-%s\n",$tskid,$tskcount;
190 }
191 }
192 else {
193 $tskcount = "";
194 $indentstr = "\t";
195 }
196 }
197 elsif (!$startflag) {
198 # do nothing.
199 }
200 elsif ($line =~ /^([0-9]+)\:\s*END$/) {
201 $check_no = $1;
202 $TASKCODE{$tskid} .= "\n".$indentstr;
203 $TASKCODE{$tskid} .= sprintf("check_finish(%d);\n", $check_no);
204 $endflag = 1;
205 }
206 else {
207 if ($line =~ /^([0-9]+)\:\s*(.*)/) {
208 $check_no = $1;
209 $line = $2;
210 $TASKCODE{$tskid} .= "\n".$indentstr;
211 $TASKCODE{$tskid} .= sprintf("check_point(%d);\n", $check_no);
212 }
213 if ($line =~ /^(assert\(.*\))$/) {
214 $assert_string = $1;
215 $TASKCODE{$tskid} .= $indentstr;
216 $TASKCODE{$tskid} .= sprintf("check_%s;\n", $assert_string);
217 }
218 elsif ($line =~ /^(state(_i)?\(.*\))$/) {
219 $state_string = $1;
220 $TASKCODE{$tskid} .= $indentstr;
221 $TASKCODE{$tskid} .= sprintf("check_%s;\n", $state_string);
222 }
223 elsif ($line =~ /^call\((.*)\)$/ || $line =~ /^DO\((.*)\)$/) {
224 $call_string = $1;
225 $TASKCODE{$tskid} .= "\n".$indentstr;
226 $TASKCODE{$tskid} .= sprintf("%s;\n", $call_string);
227 }
228 elsif ($line =~ /^MISSING$/) {
229 # do nothing.
230 }
231 elsif ($line =~ /^RETURN((\(.*\))?)$/) {
232 $return_string = $1;
233 $TASKCODE{$tskid} .= "\n".$indentstr;
234 $TASKCODE{$tskid} .= "return".$return_string.";\n";
235 }
236 elsif ($line =~ /^GOTO\((.*)\)$/) {
237 $goto_string = $1;
238 $TASKCODE{$tskid} .= "\n".$indentstr;
239 $TASKCODE{$tskid} .= sprintf("goto %s;\n", $goto_string);
240 }
241 elsif ($line =~ /^LABEL\((.*)\)$/) {
242 $label_string = $1;
243 $indent_string = $indentstr;
244 $indent_string =~ s/\t$//;
245 $TASKCODE{$tskid} .= "\n".$indent_string;
246 $TASKCODE{$tskid} .= sprintf("%s:", $label_string);
247 }
248 elsif ($line =~ /^([a-z_]+\(.*\))\s*(\-\>\s*[A-Za-z_]*)?\s*$/) {
249 $svc_call = $1;
250 $error_code_string = $2;
251 $TASKCODE{$tskid} .= "\n";
252 gen_svc_call($svc_call, $error_code_string);
253 }
254 else {
255 print STDERR "Error: ",$line,"\n";
256 }
257 }
258}
259
260#
261# ƒXƒNƒŠƒvƒgƒtƒ@ƒCƒ‹“Ǎž‚ݏˆ—
262#
263$startflag = 0;
264$endflag = 0;
265open(INFILE, $infile) || die "Cannot open $infile";
266while (($line = <INFILE>) && !$endflag) {
267 chomp $line;
268 $line =~ s/^\s*\*\s*//;
269 $line =~ s/\s*\/\/.*$//;
270 $line =~ s/\s*\.\.\..*$//;
271 next unless($line);
272 parse_line($line);
273}
274close(INFILE);
275
276#
277# ƒ^ƒXƒNƒR[ƒh‚̏o—Í
278#
279sub output_task {
280 if ($TASKCOUNT{$tskid}) {
281 printf "\nstatic uint_t\t%s = 0;\n", $TASKCOUNTVAR{$tskid};
282 }
283 if ($tskid =~ /^TASK([0-9]*)$/) {
284 print "\nvoid\n";
285 print "task$1(intptr_t exinf)\n";
286 }
287 elsif ($tskid =~ /^TASK([0-9]*)-TEX$/) {
288 print "\nvoid\n";
289 print "tex_task$1(TEXPTN texptn, intptr_t exinf)\n";
290 }
291 elsif ($tskid =~ /^ALM([0-9]*)$/) {
292 print "\nvoid\n";
293 print "alarm$1_handler(intptr_t exinf)\n";
294 }
295 elsif ($tskid =~ /^CPUEXC([0-9]*)$/) {
296 print "\nvoid\n";
297 print "cpuexc$1_handler(void *p_excinf)\n";
298 }
299 elsif ($tskid =~ /^EXTSVC([0-9]*)$/) {
300 print "\nER_UINT\n";
301 print "extsvc$1_routine(intptr_t par1, intptr_t par2, intptr_t par3,\n";
302 print "\t\t\t\t\t\t\t\tintptr_t par4, intptr_t par5, ID cdmid)\n";
303 }
304 print "{\n";
305 print "\tER\t\tercd;\n";
306 foreach $typename (keys(%{$TASKVAR{$tskid}})) {
307 print "\t",$typename, (length($typename) < 4 ? "\t\t" : "\t"),
308 ${$TASKVAR{$tskid}}{$typename},";\n";
309 }
310 if ($TASKCOUNT{$tskid}) {
311 printf "\n\tswitch (++%s) {\n", $TASKCOUNTVAR{$tskid};
312 }
313 print $TASKCODE{$tskid};
314 if ($TASKCOUNT{$tskid}) {
315 printf "\n\t\tcheck_point(0);\n";
316 printf "\t}\n";
317 }
318 else {
319 print "\n";
320 }
321 print "\tcheck_point(0);\n";
322 if ($tskid =~ /^EXTSVC([0-9]*)$/) {
323 print "\treturn(E_SYS);\n";
324 }
325 print "}\n";
326}
327
328#
329# ƒeƒXƒgƒvƒƒOƒ‰ƒ€o—͏ˆ—
330#
331foreach $tskid (sort(keys(%TASKCODE))) {
332 output_task();
333}
Note: See TracBrowser for help on using the repository browser.