1 | # -*- coding: utf-8 -*-
|
---|
2 | #
|
---|
3 | # TECS Generator Cell-type plugin
|
---|
4 | # for TOPPERS Embedded Component System
|
---|
5 | #
|
---|
6 | # Copyright (C) 2008-2014 by TOPPERS Project TECS-WG
|
---|
7 | #--
|
---|
8 | # 上記著作権者は,以下の(1)~(4)の条件を満たす場合に限り,本ソフトウェ
|
---|
9 | # ア(本ソフトウェアを改変したものを含む.以下同じ)を使用・複製・改
|
---|
10 | # 変・再配布(以下,利用と呼ぶ)することを無償で許諾する.
|
---|
11 | # (1) 本ソフトウェアをソースコードの形で利用する場合には,上記の著作
|
---|
12 | # 権表示,この利用条件および下記の無保証規定が,そのままの形でソー
|
---|
13 | # スコード中に含まれていること.
|
---|
14 | # (2) 本ソフトウェアを,ライブラリ形式など,他のソフトウェア開発に使
|
---|
15 | # 用できる形で再配布する場合には,再配布に伴うドキュメント(利用
|
---|
16 | # 者マニュアルなど)に,上記の著作権表示,この利用条件および下記
|
---|
17 | # の無保証規定を掲載すること.
|
---|
18 | # (3) 本ソフトウェアを,機器に組み込むなど,他のソフトウェア開発に使
|
---|
19 | # 用できない形で再配布する場合には,次のいずれかの条件を満たすこ
|
---|
20 | # と.
|
---|
21 | # (a) 再配布に伴うドキュメント(利用者マニュアルなど)に,上記の著
|
---|
22 | # 作権表示,この利用条件および下記の無保証規定を掲載すること.
|
---|
23 | # (b) 再配布の形態を,別に定める方法によって,TOPPERSプロジェクトに
|
---|
24 | # 報告すること.
|
---|
25 | # (4) 本ソフトウェアの利用により直接的または間接的に生じるいかなる損
|
---|
26 | # 害からも,上記著作権者およびTOPPERSプロジェクトを免責すること.
|
---|
27 | # また,本ソフトウェアのユーザまたはエンドユーザからのいかなる理
|
---|
28 | # 由に基づく請求からも,上記著作権者およびTOPPERSプロジェクトを
|
---|
29 | # 免責すること.
|
---|
30 | #
|
---|
31 | # 本ソフトウェアは,無保証で提供されているものである.上記著作権者お
|
---|
32 | # よびTOPPERSプロジェクトは,本ソフトウェアに関して,特定の使用目的
|
---|
33 | # に対する適合性も含めて,いかなる保証も行わない.また,本ソフトウェ
|
---|
34 | # アの利用により直接的または間接的に生じたいかなる損害に関しても,そ
|
---|
35 | # の責任を負わない.
|
---|
36 | #
|
---|
37 | # $Id
|
---|
38 | #++
|
---|
39 |
|
---|
40 | #== celltype プラグインの共通の親クラス
|
---|
41 | class ATK1TaskPlugin < CelltypePlugin
|
---|
42 | #@celltype:: Celltype
|
---|
43 | #@option:: String :オプション文字列
|
---|
44 |
|
---|
45 | #signature:: Celltype シグニチャ(インスタンス)
|
---|
46 | def initialize( celltype, option )
|
---|
47 | super
|
---|
48 | end
|
---|
49 |
|
---|
50 | #=== CDL ファイルの生成
|
---|
51 | # typedef, signature, celltype, cell のコードを生成
|
---|
52 | # 重複して生成してはならない
|
---|
53 | # すでに生成されている場合は出力しないこと。
|
---|
54 | # もしくは同名の import により、重複を避けること。
|
---|
55 | #file:: FILE 生成するファイル
|
---|
56 | # def gen_cdl_file file
|
---|
57 | # end
|
---|
58 |
|
---|
59 | def new_cell cell
|
---|
60 | # join_list = cell.get_join_list
|
---|
61 | # a = join_list.get_item( :resource )
|
---|
62 | # if a == nil
|
---|
63 | # Generator.error( "resource: must be initialized")
|
---|
64 | # elsif ! a.get_rhs.instance_of? Array
|
---|
65 | # Generator.error( "resource: initializer must be in format of '{val1, val2 ...}'")
|
---|
66 | # end
|
---|
67 | end
|
---|
68 |
|
---|
69 | #=== 受け口関数の本体(C言語)を生成する
|
---|
70 | # このメソッドが未定義の場合、ジェネレータは受け口関数のテンプレートを生成する
|
---|
71 | # このメソッドが定義済みの場合、(テンプレートではなく、変更する必要のない)セルタイプコードを生成する
|
---|
72 | #file:: FILE 出力先ファイル
|
---|
73 | #b_singleton:: bool true if singleton
|
---|
74 | #ct_name:: Symbol
|
---|
75 | #global_ct_name:: string
|
---|
76 | #sig_name:: string
|
---|
77 | #ep_name:: string
|
---|
78 | #func_name:: string
|
---|
79 | #func_global_name:: string
|
---|
80 | #func_type:: class derived from Type
|
---|
81 | # def gen_ep_func_body( file, b_singleton, ct_name, global_ct_name, sig_name, ep_name, func_name, func_global_name, func_type, params )
|
---|
82 | # end
|
---|
83 |
|
---|
84 | def gen_factory file
|
---|
85 |
|
---|
86 | file2 = CFile.open( "#{$gen}/TASK_tecsgen.oil", "w" )
|
---|
87 |
|
---|
88 | extended_task_count = 1
|
---|
89 |
|
---|
90 | # TASK
|
---|
91 | @celltype.get_cell_list.each { |cell|
|
---|
92 |
|
---|
93 | if cell.is_generate?
|
---|
94 |
|
---|
95 | file2.print "\tTASK #{cell.get_name} {\n"
|
---|
96 |
|
---|
97 | # AUTOSTART
|
---|
98 | join = cell.get_join_list.get_item( :autoStart )
|
---|
99 | if join then
|
---|
100 | str = join.get_rhs.to_s
|
---|
101 |
|
---|
102 | if str == "TRUE" then
|
---|
103 | join2 = cell.get_join_list.get_item( :appMode )
|
---|
104 | if join2 then
|
---|
105 | file2.print "\t\tAUTOSTART = TRUE {\n"
|
---|
106 | delim = ""
|
---|
107 | join2.get_rhs.each { |mode|
|
---|
108 | str = mode.to_s.gsub(/^"(.*)"$/, '\1')
|
---|
109 | file2.print "\t\t\tAPPMODE = #{str};\n"
|
---|
110 | delim = ";"
|
---|
111 | }
|
---|
112 | file2.print "\t\t};\n"
|
---|
113 | else
|
---|
114 | file2.print "\t\tAUTOSTART = TRUE;\n"
|
---|
115 | end
|
---|
116 | elsif str == "FALSE" then
|
---|
117 | file2.print "\t\tAUTOSTART = FALSE;\n"
|
---|
118 | else
|
---|
119 | end
|
---|
120 | end
|
---|
121 |
|
---|
122 | # PRIORITY
|
---|
123 | join = cell.get_join_list.get_item( :priority )
|
---|
124 | if join then
|
---|
125 | file2.print "\t\tPRIORITY = #{join.get_rhs.to_s};\n"
|
---|
126 | end
|
---|
127 |
|
---|
128 | # ACTIVATION
|
---|
129 | join = cell.get_join_list.get_item( :activation )
|
---|
130 | if join then
|
---|
131 | file2.print "\t\tACTIVATION = #{join.get_rhs.to_s};\n"
|
---|
132 | end
|
---|
133 |
|
---|
134 | # SCHEDULE
|
---|
135 | join = cell.get_join_list.get_item( :schedule )
|
---|
136 | if join then
|
---|
137 | str = join.get_rhs.to_s.gsub(/^"(.*)"$/, '\1')
|
---|
138 | file2.print "\t\tSCHEDULE = #{str};\n"
|
---|
139 | end
|
---|
140 |
|
---|
141 | # EVENT
|
---|
142 | join = cell.get_join_list.get_item( :event )
|
---|
143 | delim = ""
|
---|
144 | if join then
|
---|
145 | join.get_rhs.each { |evt|
|
---|
146 | str = evt.to_s.gsub(/^"(.*)"$/, '\1')
|
---|
147 | if !(str == "OMISSIBLE")
|
---|
148 | file2.print "\t\tEVENT = #{str};\n"
|
---|
149 | end
|
---|
150 | delim = ";"
|
---|
151 | }
|
---|
152 | join.get_rhs.each { |evt|
|
---|
153 | str = evt.to_s.gsub(/^"(.*)"$/, '\1')
|
---|
154 | if !(str == "OMISSIBLE")
|
---|
155 | cell.set_specified_id( extended_task_count );
|
---|
156 | ++extended_task_count;
|
---|
157 | break
|
---|
158 | end
|
---|
159 | }
|
---|
160 | end
|
---|
161 |
|
---|
162 | # RESOURCE
|
---|
163 | join = cell.get_join_list.get_item( :resource )
|
---|
164 | delim = ""
|
---|
165 | if join then
|
---|
166 | join.get_rhs.each { |res|
|
---|
167 | str = res.to_s.gsub(/^"(.*)"$/, '\1')
|
---|
168 | if !(str == "OMISSIBLE")
|
---|
169 | file2.print "\t\tRESOURCE = #{str};\n"
|
---|
170 | end
|
---|
171 | delim = ";"
|
---|
172 | }
|
---|
173 | end
|
---|
174 |
|
---|
175 | # MESSAGE
|
---|
176 | join = cell.get_join_list.get_item( :message )
|
---|
177 | delim = ""
|
---|
178 | if join then
|
---|
179 | join.get_rhs.each { |msg|
|
---|
180 | str = msg.to_s.gsub(/^"(.*)"$/, '\1')
|
---|
181 | if !(str == "OMISSIBLE")
|
---|
182 | file2.print "\t\tMESSAGE = #{str};\n"
|
---|
183 | end
|
---|
184 | delim = ";"
|
---|
185 | }
|
---|
186 | end
|
---|
187 |
|
---|
188 | # STACKSIZE
|
---|
189 | join = cell.get_join_list.get_item( :stackSize )
|
---|
190 | if join then
|
---|
191 | file2.print "\t\tSTACKSIZE = #{join.get_rhs.to_s};\n"
|
---|
192 | end
|
---|
193 |
|
---|
194 | file2.print "\t};\n"
|
---|
195 | file2.print "\n"
|
---|
196 |
|
---|
197 | end
|
---|
198 | }
|
---|
199 |
|
---|
200 | file2.close
|
---|
201 |
|
---|
202 | # 追記するために AppFile を使う(文字コード変換されない)
|
---|
203 | file = AppFile.open( "#{$gen}/tTask_tecsgen.#{$c_suffix}" )
|
---|
204 | file.print "\n/* Generated by ATK1TaskPlugin */\n"
|
---|
205 | @celltype.get_cell_list.each { |cell|
|
---|
206 | if cell.is_generate?
|
---|
207 | name_array = @celltype.get_name_array( cell )
|
---|
208 | file.print <<EOT
|
---|
209 | TASK(#{cell.get_name})
|
---|
210 | {
|
---|
211 | CELLCB *p_cellcb = #{name_array[8]};
|
---|
212 | cBody_main();
|
---|
213 | terminate();
|
---|
214 | }
|
---|
215 |
|
---|
216 | EOT
|
---|
217 | end
|
---|
218 | }
|
---|
219 |
|
---|
220 | file.close
|
---|
221 |
|
---|
222 | end
|
---|
223 |
|
---|
224 | end
|
---|
225 |
|
---|