[388] | 1 | # -*- coding: utf-8 -*-
|
---|
| 2 | #
|
---|
| 3 | # TECS Generator
|
---|
| 4 | # Generator for TOPPERS Embedded Component System
|
---|
| 5 | #
|
---|
| 6 | # Copyright (C) 2008-2014 by TOPPERS Project
|
---|
| 7 | #--
|
---|
| 8 | # ä¸è¨èä½æ¨©è
|
---|
| 9 | ã¯ï¼ä»¥ä¸ã®(1)ï½(4)ã®æ¡ä»¶ãæºããå ´åã«éãï¼æ¬ã½ããã¦ã§
|
---|
| 10 | # ã¢ï¼æ¬ã½ããã¦ã§ã¢ãæ¹å¤ãããã®ãå«ãï¼ä»¥ä¸åãï¼ã使ç¨ã»è¤è£½ã»æ¹
|
---|
| 11 | # å¤ã»åé
|
---|
| 12 | å¸ï¼ä»¥ä¸ï¼å©ç¨ã¨å¼ã¶ï¼ãããã¨ãç¡åã§è¨±è«¾ããï¼
|
---|
| 13 | # (1) æ¬ã½ããã¦ã§ã¢ãã½ã¼ã¹ã³ã¼ãã®å½¢ã§å©ç¨ããå ´åã«ã¯ï¼ä¸è¨ã®èä½
|
---|
| 14 | # 権表示ï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãï¼ãã®ã¾ã¾ã®å½¢ã§ã½ã¼
|
---|
| 15 | # ã¹ã³ã¼ãä¸ã«å«ã¾ãã¦ãããã¨ï¼
|
---|
| 16 | # (2) æ¬ã½ããã¦ã§ã¢ãï¼ã©ã¤ãã©ãªå½¢å¼ãªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
| 17 | # ç¨ã§ããå½¢ã§åé
|
---|
| 18 | å¸ããå ´åã«ã¯ï¼åé
|
---|
| 19 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨
|
---|
| 20 | # è
|
---|
| 21 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®èä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨
|
---|
| 22 | # ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
| 23 | # (3) æ¬ã½ããã¦ã§ã¢ãï¼æ©å¨ã«çµã¿è¾¼ããªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
| 24 | # ç¨ã§ããªãå½¢ã§åé
|
---|
| 25 | å¸ããå ´åã«ã¯ï¼æ¬¡ã®ããããã®æ¡ä»¶ãæºããã
|
---|
| 26 | # ã¨ï¼
|
---|
| 27 | # (a) åé
|
---|
| 28 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨è
|
---|
| 29 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®è
|
---|
| 30 | # ä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
| 31 | # (b) åé
|
---|
| 32 | å¸ã®å½¢æ
|
---|
| 33 | ãï¼å¥ã«å®ããæ¹æ³ã«ãã£ã¦ï¼TOPPERSããã¸ã§ã¯ãã«
|
---|
| 34 | # å ±åãããã¨ï¼
|
---|
| 35 | # (4) æ¬ã½ããã¦ã§ã¢ã®å©ç¨ã«ããç´æ¥çã¾ãã¯éæ¥çã«çãããããªãæ
|
---|
| 36 | # 害ãããï¼ä¸è¨èä½æ¨©è
|
---|
| 37 | ããã³TOPPERSããã¸ã§ã¯ããå
|
---|
| 38 | 責ãããã¨ï¼
|
---|
| 39 | # ã¾ãï¼æ¬ã½ããã¦ã§ã¢ã®ã¦ã¼ã¶ã¾ãã¯ã¨ã³ãã¦ã¼ã¶ããã®ãããªãç
|
---|
| 40 | # ç±ã«åºã¥ãè«æ±ãããï¼ä¸è¨èä½æ¨©è
|
---|
| 41 | ããã³TOPPERSããã¸ã§ã¯ãã
|
---|
| 42 | # å
|
---|
| 43 | 責ãããã¨ï¼
|
---|
| 44 | #
|
---|
| 45 | # æ¬ã½ããã¦ã§ã¢ã¯ï¼ç¡ä¿è¨¼ã§æä¾ããã¦ãããã®ã§ããï¼ä¸è¨èä½æ¨©è
|
---|
| 46 | ã
|
---|
| 47 | # ãã³TOPPERSããã¸ã§ã¯ãã¯ï¼æ¬ã½ããã¦ã§ã¢ã«é¢ãã¦ï¼ç¹å®ã®ä½¿ç¨ç®ç
|
---|
| 48 | # ã«å¯¾ããé©åæ§ãå«ãã¦ï¼ãããªãä¿è¨¼ãè¡ããªãï¼ã¾ãï¼æ¬ã½ããã¦ã§
|
---|
| 49 | # ã¢ã®å©ç¨ã«ããç´æ¥çã¾ãã¯éæ¥çã«çãããããªãæ害ã«é¢ãã¦ãï¼ã
|
---|
| 50 | # ã®è²¬ä»»ãè² ããªãï¼
|
---|
| 51 | #
|
---|
| 52 | # $Id$
|
---|
| 53 | #++
|
---|
| 54 |
|
---|
| 55 | require_tecsgen_lib "lib/GenHRP2Marshaler.rb"
|
---|
| 56 |
|
---|
| 57 | # require_tecsgen_lib "GenParamCopy.rb"
|
---|
| 58 |
|
---|
| 59 | #= Transparent RPC ãã©ã°ã¤ã³
|
---|
| 60 | # Transparent RPC ãã£ã³ãã«ãçæãã
|
---|
| 61 | # ãã©ã°ã¤ã³å¼æ°ã¯ä»¥ä¸ã® RPCPluginArgProc ãåç
|
---|
| 62 | §
|
---|
| 63 |
|
---|
| 64 | # mikan through plugin: namespace ãèæ
|
---|
| 65 | ®ããã¦ããªã
|
---|
| 66 | # ãããå©ç¨ããå ´åã以ä¸ã®ããã« toppers_jsp.cdl sChannel.cdl ãæå®ããå¿
|
---|
| 67 | è¦ããã
|
---|
| 68 | # tecsgen toppers_jsp.cdl sChannel.cdl your_description.cdl
|
---|
| 69 |
|
---|
| 70 | # 以ä¸ãä»®å®ï¼å¶éäºé
|
---|
| 71 | ï¼
|
---|
| 72 | # å¼ã³å
|
---|
| 73 | ãå¼ã³å
|
---|
| 74 | ã®ã¨ã³ãã£ã¢ã³ãchar, short, int_t, long_t, intptr_t ã®ãµã¤ãºãåã
|
---|
| 75 | # æ符å·ãç¡ç¬¦å·ã§ãµã¤ãºãåã
|
---|
| 76 |
|
---|
| 77 | #
|
---|
| 78 | # RPCãç¨ãããã¡ã¤ã³ééä¿¡ã®
|
---|
| 79 | # throughãã©ã°ã¤ã³
|
---|
| 80 | # HRP2ãã¡ã¤ã³ãã©ã°ã¤ã³ã«ãã£ã¦æ¿å
|
---|
| 81 | ¥ããã
|
---|
| 82 | #
|
---|
| 83 | class HRP2RPCPlugin < ThroughPlugin
|
---|
| 84 |
|
---|
| 85 | include GenTransparentMarshaler
|
---|
| 86 | # include GenParamCopy
|
---|
| 87 |
|
---|
| 88 | # RPCPlugin å°ç¨ã®ãªãã·ã§ã³
|
---|
| 89 | TransparentRPCPluginArgProc = RPCPluginArgProc.dup # è¤è£½ãä½ã£ã¦å
|
---|
| 90 | ãå¤æ´ããªãããã«ãã
|
---|
| 91 | TransparentRPCPluginArgProc[ "noClientSemaphore" ] = Proc.new { |obj,rhs| obj.set_noClientSemaphore rhs }
|
---|
| 92 | TransparentRPCPluginArgProc[ "semaphoreCelltype" ] = Proc.new { |obj,rhs| obj.set_semaphoreCelltype rhs }
|
---|
| 93 |
|
---|
| 94 | #=== RPCPlugin ã® initialize
|
---|
| 95 | # 説æ㯠ThroughPlugin (plugin.rb) ãåç
|
---|
| 96 | §
|
---|
| 97 | def initialize( cell_name, plugin_arg, next_cell, next_cell_port_name, next_cell_port_subscript, signature, celltype, caller_cell )
|
---|
| 98 | super
|
---|
| 99 | @b_noClientSemaphore = false
|
---|
| 100 | @semaphoreCelltype = "tSemaphore"
|
---|
| 101 | initialize_transparent_marshaler cell_name
|
---|
| 102 |
|
---|
| 103 | # ãªãã·ã§ã³ï¼GenTransparentMarshaler åç
|
---|
| 104 | §
|
---|
| 105 | @plugin_arg_check_proc_tab = TransparentRPCPluginArgProc
|
---|
| 106 | parse_plugin_arg
|
---|
| 107 |
|
---|
| 108 | @rpc_channel_celltype_name = "tRPCPlugin_#{@TDRCelltype}_#{@channelCelltype}_#{@signature.get_name}"
|
---|
| 109 | @rpc_channel_celltype_file_name = "#{$gen}/#{@rpc_channel_celltype_name}.cdl"
|
---|
| 110 |
|
---|
| 111 | if @signature.need_PPAllocator? then
|
---|
| 112 | if @PPAllocatorSize == nil then
|
---|
| 113 | cdl_error( "PPAllocatorSize must be speicified for oneway [in] array" )
|
---|
| 114 | # @PPAllocatorSize = 0 # 仮㫠0 ã¨ãã¦ãã (cdl ã®æ§æã¨ã©ã¼ãé¿ãããã)
|
---|
| 115 | end
|
---|
| 116 | end
|
---|
| 117 |
|
---|
| 118 | # @signature.each_param{ |func_decl, param_decl|
|
---|
| 119 | # if func_decl.get_type.is_oneway? then
|
---|
| 120 | # if ( param_decl.get_size || param_decl.get_count ) && param_decl.get_string then
|
---|
| 121 | # cdl_error( "array of string not supported for oneway function in Transparent RPC" ) # mikan æååã®é
|
---|
| 122 | å
|
---|
| 123 | # elsif param_decl.get_string == -1 then
|
---|
| 124 | # cdl_error( "length unspecified string is not permited for oneway function in Transparent RPC" ) # mikan é·ãæªæå®æåå
|
---|
| 125 | # end
|
---|
| 126 | # end
|
---|
| 127 | # }
|
---|
| 128 | end
|
---|
| 129 |
|
---|
| 130 | #=== plugin ã®å®£è¨ã³ã¼ã (celltype ã®å®ç¾©) çæ
|
---|
| 131 | def gen_plugin_decl_code( file )
|
---|
| 132 |
|
---|
| 133 | ct_name = "#{@ct_name}_#{@channelCelltype}"
|
---|
| 134 |
|
---|
| 135 | # ãã®ã»ã«ã¿ã¤ãï¼åãã·ã°ããã£ï¼ã¯æ¢ã«çæããã¦ãããï¼
|
---|
| 136 | if @@generated_celltype[ ct_name ] == nil then
|
---|
| 137 | @@generated_celltype[ ct_name ] = [ self ]
|
---|
| 138 | else
|
---|
| 139 | @@generated_celltype[ ct_name ] << self
|
---|
| 140 | return
|
---|
| 141 | end
|
---|
| 142 |
|
---|
| 143 | gen_marshaler_celltype
|
---|
| 144 |
|
---|
| 145 | if @PPAllocatorSize then
|
---|
| 146 | alloc_cell = " cell tPPAllocator PPAllocator {\n heapSize = #{@PPAllocatorSize};\n };\n"
|
---|
| 147 | alloc_call_port_join = " cPPAllocator = PPAllocator.ePPAllocator;\n"
|
---|
| 148 | else
|
---|
| 149 | alloc_cell = ""
|
---|
| 150 | alloc_call_port_join = ""
|
---|
| 151 | end
|
---|
| 152 |
|
---|
| 153 | if @b_noClientSemaphore == false then
|
---|
| 154 | semaphore1 = <<EOT
|
---|
| 155 | // Semaphore for Multi-task use ("specify noClientSemaphore" option to delete this)
|
---|
| 156 | cell #{@semaphoreCelltype} Semaphore {
|
---|
| 157 | count = 1;
|
---|
| 158 | attribute = C_EXP( "TA_NULL" );
|
---|
| 159 | };
|
---|
| 160 | EOT
|
---|
| 161 | semaphore2 = " cLockChannel = Semaphore.eSemaphore;\n"
|
---|
| 162 | else
|
---|
| 163 | semaphore1 = ""
|
---|
| 164 | semaphore2 = ""
|
---|
| 165 | end
|
---|
| 166 |
|
---|
| 167 | f = CFile.open( @rpc_channel_celltype_file_name, "w" )
|
---|
| 168 | # åãå
|
---|
| 169 | 容ãäºåº¦æ¸ãå¯è½æ§ãã (AppFile ã¯ä¸å¯)
|
---|
| 170 |
|
---|
| 171 | f.print <<EOT
|
---|
| 172 | import( "#{@marshaler_celltype_file_name}" );
|
---|
| 173 |
|
---|
| 174 | composite #{@rpc_channel_celltype_name}Client {
|
---|
| 175 | /* Interface */
|
---|
| 176 | entry #{@signature.get_name} eThroughEntry;
|
---|
| 177 | //call sTDR cTDR;
|
---|
| 178 | call sEventflag cEventflag;
|
---|
| 179 | call sSemaphore cSemaphore;
|
---|
| 180 | call sMessageBuffer cMessageBuffer;
|
---|
| 181 |
|
---|
| 182 | /* Implementation */
|
---|
| 183 | #{semaphore1}
|
---|
| 184 | cell #{@marshaler_celltype_name} #{@signature.get_name}_marshaler{
|
---|
| 185 | //cTDR => composite.cTDR;
|
---|
| 186 | cEventflag => composite.cEventflag;
|
---|
| 187 | cSemaphore => composite.cSemaphore;
|
---|
| 188 | cMessageBuffer => composite.cMessageBuffer;
|
---|
| 189 | #{semaphore2} };
|
---|
| 190 | composite.eThroughEntry => #{@signature.get_name}_marshaler.eClientEntry;
|
---|
| 191 | };
|
---|
| 192 |
|
---|
| 193 | [active]
|
---|
| 194 | composite #{@rpc_channel_celltype_name}Server {
|
---|
| 195 | /* Interface */
|
---|
| 196 | attr {
|
---|
| 197 | PRI taskPriority;
|
---|
| 198 | };
|
---|
| 199 | call #{@signature.get_name} #{@call_port_name};
|
---|
| 200 | //call sTDR cTDR;
|
---|
| 201 | call sEventflag cEventflag;
|
---|
| 202 | call sSemaphore cSemaphore;
|
---|
| 203 | call sMessageBuffer cMessageBuffer;
|
---|
| 204 |
|
---|
| 205 | /* Implementation */
|
---|
| 206 | #{alloc_cell} cell #{@unmarshaler_celltype_name} #{@signature.get_name}_unmarshaler{
|
---|
| 207 | //cTDR => composite.cTDR;
|
---|
| 208 | cEventflag => composite.cEventflag;
|
---|
| 209 | cSemaphore => composite.cSemaphore;
|
---|
| 210 | cMessageBuffer => composite.cMessageBuffer;
|
---|
| 211 | cServerCall => composite.#{@call_port_name};
|
---|
| 212 | #{alloc_call_port_join} };
|
---|
| 213 | cell tRPCDedicatedTaskMain RPCTaskMain{
|
---|
| 214 | cMain = #{@signature.get_name}_unmarshaler.eUnmarshalAndCallFunction;
|
---|
| 215 | };
|
---|
| 216 | cell tTask Task {
|
---|
| 217 | cBody = RPCTaskMain.eMain;
|
---|
| 218 | priority = taskPriority;
|
---|
| 219 | taskAttribute = C_EXP( "TA_ACT" ); /* mikan : marshaler starts at the beginning */
|
---|
| 220 | //stackSize = 4096;
|
---|
| 221 | userStackSize = 4096;
|
---|
| 222 | };
|
---|
| 223 | };
|
---|
| 224 | EOT
|
---|
| 225 | # mikan stackSize option & ææ° tecs_package 対å¿
|
---|
| 226 |
|
---|
| 227 | f.close
|
---|
| 228 | end
|
---|
| 229 |
|
---|
| 230 | #=== through cell ã³ã¼ããçæ
|
---|
| 231 | #
|
---|
| 232 | #
|
---|
| 233 | def gen_through_cell_code( file )
|
---|
| 234 |
|
---|
| 235 | gen_plugin_decl_code( file )
|
---|
| 236 |
|
---|
| 237 | # ã»ã«ãæ¢ã
|
---|
| 238 | # path =["::",@next_cell.get_name]
|
---|
| 239 | # cell = Namespace.find( path )
|
---|
| 240 | cell = Namespace.find( @next_cell.get_namespace_path )
|
---|
| 241 |
|
---|
| 242 | file.print <<EOT
|
---|
| 243 | import( "#{@rpc_channel_celltype_file_name}" );
|
---|
| 244 | EOT
|
---|
| 245 |
|
---|
| 246 | #nest = @end_region.gen_region_str_pre file
|
---|
| 247 | indent_str = ""
|
---|
| 248 |
|
---|
| 249 | file.print <<EOT
|
---|
| 250 | #{indent_str}// one way channel cell
|
---|
| 251 | #{indent_str}cell #{@channelCelltype} #{@channelCellName} {
|
---|
| 252 | #{indent_str}};
|
---|
| 253 |
|
---|
| 254 | #{indent_str}// RPC channel cell
|
---|
| 255 | EOT
|
---|
| 256 |
|
---|
| 257 | nest = @start_region.gen_region_str_pre file
|
---|
| 258 | indent_str = " " * nest
|
---|
| 259 |
|
---|
| 260 | # #473 ã解決ãããå ´åãcomposite ãªã¬ã¼ã¢ãã±ã¼ã¿ã«å¤æ´ãã¹ã
|
---|
| 261 | # ã¢ãã±ã¼ã¿ã®æå®ããããï¼
|
---|
| 262 | if cell.get_allocator_list.length > 0 then
|
---|
| 263 |
|
---|
| 264 | dbgPrint "make allocator\n"
|
---|
| 265 | file.print "#{indent_str}[allocator("
|
---|
| 266 |
|
---|
| 267 | delim = ""
|
---|
| 268 | cell.get_allocator_list.each do |type, eport, subsc, func, buf, alloc|
|
---|
| 269 |
|
---|
| 270 | file.print delim
|
---|
| 271 | delim = ",\n#{indent_str} " # æçµè¡ã«ã¯åºããªã
|
---|
| 272 |
|
---|
| 273 | if subsc then # é
|
---|
| 274 | åæ·»æ°
|
---|
| 275 | subsc_str = '[#{subsc}]'
|
---|
| 276 | else
|
---|
| 277 | subsc_str = ""
|
---|
| 278 | end
|
---|
| 279 |
|
---|
| 280 | eport = "eThroughEntry" #RPCã®åãå£åã«å¤æ´
|
---|
| 281 | file.print "#{eport}#{subsc_str}.#{func}.#{buf} = #{alloc}"
|
---|
| 282 | end
|
---|
| 283 |
|
---|
| 284 | file.puts ")]"
|
---|
| 285 | end
|
---|
| 286 |
|
---|
| 287 | file.print <<EOT
|
---|
| 288 | #{indent_str}cell #{@rpc_channel_celltype_name}Client #{@cell_name} {
|
---|
| 289 | #{indent_str} //cTDR = #{@channelCellName}.eTDR;
|
---|
| 290 | #{indent_str} cEventflag = #{@channelCellName}.eEventflag;
|
---|
| 291 | #{indent_str} cSemaphore = #{@channelCellName}.eSemaphore;
|
---|
| 292 | #{indent_str} cMessageBuffer = #{@channelCellName}.eMessageBuffer;
|
---|
| 293 | #{indent_str}};
|
---|
| 294 | EOT
|
---|
| 295 |
|
---|
| 296 | @start_region.gen_region_str_post file
|
---|
| 297 |
|
---|
| 298 | nest = @end_region.gen_region_str_pre file
|
---|
| 299 | indent_str = " " * nest
|
---|
| 300 | nest_str = " " * nest
|
---|
| 301 | if @next_cell_port_subscript then
|
---|
| 302 | subscript = '[' + @next_cell_port_subscript.to_s + ']'
|
---|
| 303 | else
|
---|
| 304 | subscript = ""
|
---|
| 305 | end
|
---|
| 306 |
|
---|
| 307 | file.print <<EOT
|
---|
| 308 | #{indent_str}cell #{@rpc_channel_celltype_name}Server #{@cell_name}Body {
|
---|
| 309 | #{indent_str} #{@call_port_name} = #{@next_cell.get_namespace_path.get_path_str}.#{@next_cell_port_name}#{subscript};
|
---|
| 310 | //#{indent_str} #{@call_port_name} = #{@next_cell.get_name}.#{@next_cell_port_name};
|
---|
| 311 | #{indent_str} //cTDR = #{@channelCellName}.eTDR;
|
---|
| 312 | #{indent_str} cEventflag = #{@channelCellName}.eEventflag;
|
---|
| 313 | #{indent_str} cSemaphore = #{@channelCellName}.eSemaphore;
|
---|
| 314 | #{indent_str} cMessageBuffer = #{@channelCellName}.eMessageBuffer;
|
---|
| 315 | #{indent_str} taskPriority = #{@task_priority};
|
---|
| 316 | #{indent_str}};
|
---|
| 317 | EOT
|
---|
| 318 |
|
---|
| 319 | @end_region.gen_region_str_post file
|
---|
| 320 | end
|
---|
| 321 |
|
---|
| 322 |
|
---|
| 323 | #=== ãã©ã°ã¤ã³å¼æ° noClientSemaphore ã®ãã§ãã¯
|
---|
| 324 | def set_noClientSemaphore rhs
|
---|
| 325 | rhs = rhs.to_sym
|
---|
| 326 | if rhs == :true then
|
---|
| 327 | @b_noClientSemaphore = true
|
---|
| 328 | elsif rhs == :false then
|
---|
| 329 | @b_noClientSemaphore = false
|
---|
| 330 | else
|
---|
| 331 | cdl_error( "RPCPlugin: specify true or false for noClientSemaphore" )
|
---|
| 332 | end
|
---|
| 333 | end
|
---|
| 334 |
|
---|
| 335 | #=== ãã©ã°ã¤ã³å¼æ° semaphoreCelltype ã®ãã§ãã¯
|
---|
| 336 | def set_semaphoreCelltype rhs
|
---|
| 337 | @semaphoreCelltype = rhs.to_sym
|
---|
| 338 | nsp = NamespacePath.analyze( @semaphoreCelltype.to_s )
|
---|
| 339 | obj = Namespace.find( nsp )
|
---|
| 340 | if ! obj.instance_of?( Celltype ) && ! obj.instance_of?( CompositeCelltype ) then
|
---|
| 341 | cdl_error( "RPCPlugin: semaphoreCelltype '#{rhs}' not celltype or not defined" )
|
---|
| 342 | end
|
---|
| 343 | end
|
---|
| 344 |
|
---|
| 345 | #=== NamespacePath ãå¾ã
|
---|
| 346 | # çæããã»ã«ã® namespace path ãçæãã
|
---|
| 347 | def get_cell_namespace_path
|
---|
| 348 | # nsp = @region.get_namespace.get_namespace_path
|
---|
| 349 | nsp = @start_region.get_namespace_path
|
---|
| 350 | return nsp.append( @cell_name )
|
---|
| 351 | end
|
---|
| 352 |
|
---|
| 353 | end
|
---|
| 354 |
|
---|
| 355 |
|
---|