コード例 #1
0
 def _generate_com_access(self):
     if self.com_config is not None:
         for element_name in self.partition.data_elements:
             if element_name in self.com_config.send:
                 data_element = self.partition.data_elements[element_name][
                     'element']
                 isPointer = True if data_element.dataType.isComplexType else False
                 self.com_access['send'][element_name] = C.function(
                     "%s_Send_%s" % (self.com_config.prefix, element_name),
                     'Std_ReturnType',
                     args=[
                         C.variable('value',
                                    data_element.dataType.name,
                                    pointer=isPointer)
                     ])
             elif element_name in self.com_config.receive:
                 data_element = self.partition.data_elements[element_name][
                     'element']
                 isPointer = True if data_element.dataType.isComplexType else False
                 self.com_access['receive'][element_name] = C.function(
                     "%s_Receive_%s" %
                     (self.com_config.prefix, element_name),
                     'Std_ReturnType',
                     args=[
                         C.variable('value',
                                    data_element.dataType.name,
                                    pointer=isPointer)
                     ])
             else:
                 self.local_elements.push(element_name)
コード例 #2
0
ファイル: partition.py プロジェクト: krsreenatha/autosar-1
 def _createDefaultFunction(self, component, port, operation):
     ws = component.swc.rootWS()
     assert (ws is not None)
     func_name = '_'.join([
         self.prefix, 'Call', component.swc.name, port.name, operation.name
     ])
     func = C.function(func_name, 'Std_ReturnType')
     portInterface = ws.find(port.portInterfaceRef)
     if portInterface is None:
         raise ValueError("Error: invalid port interface reference: " +
                          port.portInterfaceRef)
     for argument in operation.arguments:
         dataType = ws.find(argument.typeRef)
         if dataType is None:
             raise ValueError('Error: Invalid type reference: ' +
                              argument.typeRef)
         self.types.processType(ws, dataType)
         isPointer = False
         if dataType.isComplexType or (argument.direction
                                       == 'OUT') or (argument.direction
                                                     == 'INOUT'):
             isPointer = True
         func.add_arg(
             C.variable(argument.name, dataType.name, pointer=isPointer))
     return func
コード例 #3
0
ファイル: base.py プロジェクト: cogu/autosar
 def create_data_access_api(self, ws, rte_data_element):
    if rte_data_element.isQueued:
       call_type='Send'
    else:
       call_type='Write'
    data_type = rte_data_element.dataType
    pointer=True if data_type.isComplexType else False
    fname='_'.join([self.parent.rte_prefix, call_type, self.parent.name, self.name, rte_data_element.name])
    shortname='_'.join([self.parent.rte_prefix, call_type, self.name, rte_data_element.name])
    type_arg=type2arg(data_type,pointer)
    func=C.function(fname, 'Std_ReturnType')
    func.add_arg(type_arg)
    if shortname not in self.portAPI:
       rte_port_func = None
       initValue = None
       ar_port = self.ar_port
       if len(ar_port.comspec)>0:
          for comspec in ar_port.comspec:
             if (comspec.name == rte_data_element.name) and (comspec.initValueRef is not None):
                initValue = ws.find(comspec.initValueRef)
       if call_type == 'Send':
          rte_port_func = SendPortFunction(shortname, func, rte_data_element)
       else:
          rte_port_func = WritePortFunction(shortname, func, rte_data_element)
       self.portAPI[shortname] = rte_port_func
コード例 #4
0
ファイル: base.py プロジェクト: ncs1/autosar-1
 def __init__(self, event):      
    self.body = C.block(innerIndent = innerIndentDefault)
    self.calls = {}
    self.typename = 'Rte_ModeType_'+event.mode
    self.proto = C.function('Rte_SetMode_'+event.mode, 'void', args = [C.variable('newMode', self.typename)])
    self.static_var = C.variable('m_'+event.mode, self.typename, static=True)
    self._init_body(event)
コード例 #5
0
ファイル: base.py プロジェクト: ncs1/autosar-1
 def create_data_access_api(self, ws, rte_data_element):
    if rte_data_element.isQueued:
       call_type='Receive'
    else:
       call_type='Read'
    pointer=True
    fname='_'.join([self.parent.rte_prefix, call_type, self.parent.name, self.name, rte_data_element.name])
    shortname='_'.join([self.parent.rte_prefix, call_type, self.name, rte_data_element.name])
    data_type = rte_data_element.dataType
    type_arg=type2arg(data_type,pointer)
    func=C.function(fname, 'Std_ReturnType')
    func.add_arg(type_arg)
    if shortname not in self.portAPI:
       rte_port_func = None
       initValue = None
       queueLength = None
       ar_port = self.ar_port
       if len(ar_port.comspec)>0:
          for comspec in ar_port.comspec:
             if (comspec.name == rte_data_element.name) and (comspec.initValueRef is not None):
                initValue = ws.find(comspec.initValueRef)
                queueLength = comspec.queueLength
       if call_type == 'Read':
          rte_port_func = ReadPortFunction(shortname, func, rte_data_element)
       else:
          rte_port_func = ReceivePortFunction(shortname, func, rte_data_element)
       self.portAPI[shortname] = rte_port_func
コード例 #6
0
    def _write_public_funcs(self, fp):
        fp.write('\n'.join(_genCommentHeader('Public Functions')) + '\n')
        func = C.function(self.prefix + '_Start', 'void')
        body = C.block(innerIndent=3)
        #for name in sorted(self.partition.vars.keys()):

        # rtevar = self.partition.vars[name]
        # if isinstance(rtevar, autosar.rte.IntegerVariable):
        #    body.code.append(C.statement('%s = %s'%(rtevar.name, rtevar.initValue)))
        fp.write(str(func) + '\n')
        fp.write('\n'.join(body.lines()) + '\n\n')
        if len(self.partition.serverAPI.read) > 0:
            self._genRead(
                fp,
                sorted(self.partition.serverAPI.final['read'],
                       key=lambda x: x.shortname))
        if len(self.partition.serverAPI.write) > 0:
            self._genWrite(
                fp,
                sorted(self.partition.serverAPI.final['write'],
                       key=lambda x: x.shortname))
        if len(self.partition.serverAPI.receive) > 0:
            self._genReceive(
                fp,
                sorted(self.partition.serverAPI.final['receive'],
                       key=lambda x: x.shortname))
        if len(self.partition.serverAPI.send) > 0:
            self._genSend(
                fp,
                sorted(self.partition.serverAPI.final['send'],
                       key=lambda x: x.shortname))
コード例 #7
0
 def _resolveParameters(self, component):
     ws = component.swc.rootWS()
     assert (ws is not None)
     for elem in component.parameters:
         (componentRef, portRef, dataElemRef) = elem
         swc = ws.find(componentRef)
         port = ws.find(portRef)
         dataElement = ws.find(dataElemRef)
         if dataElement is None:
             raise ValueError(dataElemRef)
         typeObj = ws.find(dataElement.typeRef)
         if typeObj is None:
             raise ValueError('invalid reference: %s' % dataElement.typeRef)
         self.types.processType(ws, typeObj)
         ftype = 'Calprm'
         if self.mode == 'single':
             fname = '%s_%s_%s_%s_%s' % (self.prefix, ftype, swc_name,
                                         port.name, dataElement.name)
         elif self.mode == 'full':
             fname = '%s_%s_%s_%s' % (self.prefix, ftype, port.name,
                                      dataElement.name)
         else:
             raise ValueError(
                 'invalid mode value. Valid modes are "full" and "single"')
         shortname = 'Rte_%s_%s_%s' % (ftype, port.name, dataElement.name)
         func = C.function(fname, typeObj.name)
         if shortname in component.clientAPI.__dict__[ftype.lower()]:
             raise ValueError('error: %s already defined' % shortname)
         component.clientAPI.__dict__[
             ftype.lower()][shortname] = CalPrmPortFunction(
                 shortname, func)
コード例 #8
0
 def OperationInvokedRunnable(cls, name, symbol, ws, port, operation):
     assert (ws is not None)
     returnType = 'void'
     if len(operation.errorRefs) > 0:
         returnType = 'Std_ReturnType'
     prototype = C.function(symbol, returnType)
     for argument in operation.arguments:
         dataType = ws.find(argument.typeRef)
         if dataType is None:
             raise ValueError('invalid type reference: ' + argument.typeRef)
         isPointer = False
         if isinstance(dataType,
                       autosar.datatype.RecordDataType) or isinstance(
                           dataType,
                           autosar.datatype.ArrayDataType) or isinstance(
                               dataType, autosar.datatype.ArrayDataType):
             isPointer = True
         if (isPointer == False) and (argument.direction == 'OUT') or (
                 argument.direction == 'INOUT'):
             isPointer = True
         prototype.add_arg(
             C.variable(argument.name, dataType.name, pointer=isPointer))
     self = cls(name, symbol, prototype)
     self.isServerRunnable = True
     self.serverPortInterface = ws.find(port.portInterfaceRef)
     self.serverOperation = operation
     return self
コード例 #9
0
 def create_data_send_point(self, ws, port, data_element, data_type):
     if data_element.isQueued:
         call_type = 'Send'
     else:
         call_type = 'Write'
     pointer = True if data_type.isComplexType else False
     fname = '%s_%s_%s_%s_%s' % (self.rte_prefix, call_type, self.swc.name,
                                 port.name, data_element.name)
     shortname = '%s_%s_%s_%s' % (self.rte_prefix, call_type, port.name,
                                  data_element.name)
     type_arg = _type2arg(data_type, pointer)
     func = C.function(fname, 'Std_ReturnType')
     func.add_arg(type_arg)
     if shortname not in self.clientAPI.__dict__[call_type.lower()]:
         rte_port_func = None
         rte_data_element = None
         if len(port.comspec) > 0 and (port.comspec[0].initValueRef
                                       is not None):
             initValue = ws.find(port.comspec[0].initValueRef)
         rte_data_element = DataElement(port.name, data_type, initValue)
         if call_type == 'Send':
             rte_port_func = SendPortFunction(shortname, func,
                                              rte_data_element)
         else:
             rte_port_func = WritePortFunction(shortname, func,
                                               rte_data_element)
         self.clientAPI.__dict__[
             call_type.lower()][shortname] = rte_port_func
コード例 #10
0
ファイル: generator.py プロジェクト: hello-yaowq/autosar-1
    def _create_operation_setter(self, component, port, operation,
                                 port_access):
        func_name = '%s_SetCallHandler_%s_%s_%s' % (
            self.prefix, component.name, port.name, operation.name)
        short_name = '%s_SetCallHandler_%s_%s' % (self.prefix, port.name,
                                                  operation.name)

        type_name = '%s_%s_ServerCallHandler_t' % (port.name, operation.name)
        var_name = 'm_ServerCallHandler_%s_%s_%s' % (component.name, port.name,
                                                     operation.name)
        port_func = port.portAPI['Rte_Call_%s_%s' %
                                 (port.name, operation.name)]
        tmp_proto = C.fptr.from_func(port_func.proto, type_name)

        self.typedefs[type_name] = 'typedef %s' % str(tmp_proto)
        proto = C.function(
            func_name,
            'void',
            args=[C.variable('handler_func', type_name, pointer=True)])
        func = autosar.rte.base.SetCallHandlerFunction(short_name, proto,
                                                       operation, var_name)
        self.extra_public_functions[short_name] = func
        static_var = C.variable(var_name, type_name, static=True, pointer=True)
        self.extra_static_vars[var_name] = static_var
        self.extra_rte_start.append(
            C.statement('%s = (%s*) 0' % (var_name, type_name)))
        body = self._createMockServerCallFunction(port_func.proto, var_name)
        self.extra_public_functions[
            port_func.proto.name] = autosar.rte.base.ServerCallFunction(
                port_func.proto, body)
コード例 #11
0
ファイル: base.py プロジェクト: ncs1/as
 def create_data_access_api(self, ws, rte_data_element):
     if rte_data_element.isQueued:
         call_type = 'Send'
     else:
         call_type = 'Write'
     data_type = rte_data_element.dataType
     pointer = True if data_type.isComplexType else False
     fname = '_'.join([
         self.parent.rte_prefix, call_type, self.parent.name, self.name,
         rte_data_element.name
     ])
     shortname = '_'.join([
         self.parent.rte_prefix, call_type, self.name, rte_data_element.name
     ])
     type_arg = type2arg(data_type, pointer)
     func = C.function(fname, 'Std_ReturnType')
     func.add_arg(type_arg)
     if shortname not in self.portAPI:
         rte_port_func = None
         initValue = None
         ar_port = self.ar_port
         if len(ar_port.comspec) > 0:
             for comspec in ar_port.comspec:
                 if (comspec.name
                         == rte_data_element.name) and (comspec.initValueRef
                                                        is not None):
                     initValue = ws.find(comspec.initValueRef)
         if call_type == 'Send':
             rte_port_func = SendPortFunction(shortname, func,
                                              rte_data_element)
         else:
             rte_port_func = WritePortFunction(shortname, func,
                                               rte_data_element)
         self.portAPI[shortname] = rte_port_func
コード例 #12
0
ファイル: base.py プロジェクト: ncs1/as
 def create_server_call_api(self, operation):
     shortname = '_'.join(
         [self.parent.rte_prefix, 'Call', self.name, operation.name])
     if len(self.connectors) == 0:
         func_name = '_'.join([
             self.parent.rte_prefix, 'Call', self.parent.name, self.name,
             operation.name
         ])
     elif len(self.connectors) == 1:
         server_port = self.connectors[0]
         for event in server_port.parent.events:
             if isinstance(event,
                           OperationInvokedEvent) and (event.operation.name
                                                       == operation.name):
                 func_name = event.runnable.name
                 break
         else:
             raise ValueError('No event found to service operation %s/%s' %
                              (self.parent.name, self.name))
     else:
         raise ValueError(
             'Error: Operation %s/%s seems to have multiple servers' %
             (self.parent.name, self.name))
     return_type = 'Std_ReturnType' if len(
         operation.inner.errorRefs) > 0 else 'void'
     proto = C.function(func_name, return_type)
     for argument in operation.arguments:
         proto.add_arg(argument)
     port_func = CallPortFunction(shortname, proto, operation)
     self.portAPI[shortname] = port_func
     return port_func
コード例 #13
0
ファイル: base.py プロジェクト: ncs1/as
 def __init__(self, prefix, component, port, data_element, var_name):
     data_type = data_element.dataType
     func_name = '%s_SetReadData_%s_%s_%s' % (prefix, component.name,
                                              port.name, data_element.name)
     shortname = '%s_SetReadData_%s_%s' % (prefix, port.name,
                                           data_element.name)
     proto = C.function(func_name, 'void')
     proto.add_arg(
         C.variable('data', data_type.name,
                    pointer=data_type.isComplexType))
     self.shortname = shortname
     self.data_element = data_element
     self.proto = proto
     body = C.block(innerIndent=innerIndentDefault)
     if isinstance(data_type, autosar.datatype.ArrayDataType):
         body.append(
             C.statement('memcpy(&%s[0], %s, sizeof(%s)' %
                         (var_name, proto.args[0].name, var_name)))
     elif isinstance(data_type, autosar.datatype.RecordDataType):
         body.append(
             C.statement('memcpy(&%s, %s, sizeof(%s)' %
                         (var_name, proto.args[0].name, var_name)))
     else:
         body.append(C.statement('%s = %s' %
                                 (var_name, proto.args[0].name)))
     self.body = body
コード例 #14
0
ファイル: generator.py プロジェクト: hello-yaowq/autosar-1
 def _write_rte_start(self, fp):
     func = C.function(self.prefix + '_Start', 'void')
     body = C.block(innerIndent=innerIndentDefault)
     self._write_init_values(body)
     if len(self.extra_rte_start) > 0:
         body.extend(self.extra_rte_start)
     fp.write(str(func) + '\n')
     fp.write('\n'.join(body.lines()) + '\n\n')
コード例 #15
0
ファイル: base.py プロジェクト: ncs1/as
 def __init__(self, ar_event, runnable, port, operation):
     super().__init__(ar_event, runnable)
     self.port = port
     self.operation = operation
     return_type = 'Std_ReturnType' if len(
         operation.inner.errorRefs) > 0 else 'void'
     self.runnable.prototype = C.function(runnable.symbol,
                                          return_type,
                                          args=operation.arguments)
コード例 #16
0
ファイル: generator.py プロジェクト: hello-yaowq/autosar-1
 def _write_header_public_func(self, code):
     code.append('')
     code.extend(_genCommentHeader2("PUBLIC FUNCTION PROTOTYPES"))
     code.append(C.statement(C.function('Rte_Start', 'void')))
     if self.mode_switch_enable and len(
             self.partition.mode_switch_functions) > 0:
         for func in [
                 self.partition.mode_switch_functions[key] for key in
                 sorted(self.partition.mode_switch_functions.keys())
         ]:
             code.append(C.statement(func.proto))
コード例 #17
0
 def __init__(self, name, symbol, prototype=None):
     self.name = name
     self.symbol = symbol
     self.isServerRunnable = False
     self.serverPortInterface = None
     self.serverOperation = None
     self.events = []  #rte events
     if prototype is None:
         self.prototype = C.function(self.symbol, 'void')
     else:
         self.prototype = prototype
コード例 #18
0
ファイル: partition.py プロジェクト: ncs1/as
 def _generate_com_access(self):
     for component in self.components:
         if isinstance(component.inner, autosar.bsw.com.ComComponent):
             for port in component.requirePorts:
                 for remote_port in port.connectors:
                     for data_element in remote_port.data_elements:
                         isPointer = True if data_element.dataType.isComplexType else False
                         proto = C.function(
                             "%s_Send_%s_%s" %
                             (component.inner.name, remote_port.name,
                              data_element.name),
                             'Std_ReturnType',
                             args=[
                                 C.variable('value',
                                            data_element.dataType.name,
                                            pointer=isPointer)
                             ])
                         data_element.com_access['Send'] = proto
                         component.inner.addSendInterface(
                             proto, port, data_element)
             for port in component.providePorts:
                 for data_element in port.data_elements:
                     isPointer = True
                     proto = C.function(
                         "%s_Receive_%s_%s" %
                         (component.inner.name, remote_port.name,
                          data_element.name),
                         'Std_ReturnType',
                         args=[
                             C.variable('value',
                                        data_element.dataType.name,
                                        pointer=isPointer)
                         ])
                     data_element.com_access['Receive'] = proto
                     component.inner.addReceiveInterface(
                         proto, port, data_element)
                     #remove from internal RTE variables
                     symbol = data_element.symbol
                     data_element.symbol = None
                     if symbol in self.data_element_map:
                         del self.data_element_map[symbol]
コード例 #19
0
def _rand():
    print("Generate rand function...")
    body = C.block(innerIndent=3)
    body.append(
        C.statement(f"{C.variable('var0', 'int')} = {C.fcall('rand')}"))
    body.append(C.statement('return var0'))
    head = C.function('f_rand', 'int')
    func = C.sequence()
    func.append(head)
    func.append(body)
    print(str(func))
    return func
コード例 #20
0
ファイル: generator.py プロジェクト: cogu/autosar
 def _generate_mode_switch_func(self, callback_name, events):
    code = C.sequence()
    generated=set()
    code.append(C.function(callback_name, 'void'))
    block = C.block(innerIndent = innerIndentDefault)
    for event in events:
       task = self.cfg.find_os_task_by_runnable(event.runnable)
       if task is not None:
          if (task.name, event.name) not in generated:               
             block.append(C.statement(C.fcall('os_task_setEvent', params=['&m_os_task_%s'%task.name, 'EVENT_MASK_%s_%s'%(task.name, event.name)])))
             generated.add((task.name, event.name))
    code.append(block)
    return code
コード例 #21
0
def _main():
    print("Generate main function...")
    func = C.sequence()
    head = C.function(
        'main',
        'int',
    )
    body = C.block(innerIndent=3)
    body.append(C.statement('return 0'))
    func.append(head)
    func.append(body)
    print(str(func))
    return func
コード例 #22
0
def _printf():
    print("Generate printf function...")
    body = C.block(innerIndent=3)
    body.append(C.statement(C.fcall('printf').add_arg('\"%d\"').add_arg('p0')))
    head = C.function(
        'f_printf',
        'void',
    ).add_param(C.variable('p0', 'int'))
    func = C.sequence()
    func.append(head)
    func.append(body)
    print(str(func))
    return func
コード例 #23
0
ファイル: base.py プロジェクト: ncs1/autosar-1
 def __init__(self, prefix, component, port, data_element):
    func_name='%s_SetReadResult_%s_%s_%s'%(prefix, component.name, port.name, data_element.name)
    shortname='%s_SetReadResult_%s_%s'%(prefix, port.name, data_element.name)
    proto=C.function(func_name, 'void')
    
    proto.add_arg(C.variable('value', 'Std_ReturnType'))
    self.shortname = shortname
    self.proto=proto
    self.data_element = data_element
    data_element.result_var = C.variable('m_ReadResult_%s_%s_%s'%(component.name, port.name, data_element.name), 'Std_ReturnType', static=True)
    self.static_var = data_element.result_var
    body = C.block(innerIndent=innerIndentDefault)
    body.append(C.statement('%s = %s'%(self.static_var.name, proto.args[0].name)))
    self.body=body
コード例 #24
0
def _scanf_no_pointer():
    print("Generate scanf function...")
    body = C.block(innerIndent=3)
    body.append(C.statement(C.variable('var0', 'int')))
    body.append(
        C.statement(C.fcall('scanf').add_arg('\"%d\"').add_arg('&var0')))
    body.append(C.statement("return var0"))
    head = C.function(
        'f_scanf_nop',
        'int',
    )
    func = C.sequence()
    func.append(head)
    func.append(body)
    print(str(func))
    return func
コード例 #25
0
ファイル: generator.py プロジェクト: hello-yaowq/autosar-1
 def _create_data_element_getter(self, component, port, data_element):
     data_type = data_element.dataType
     func_name = '%s_GetWriteData_%s_%s_%s' % (self.prefix, component.name,
                                               port.name, data_element.name)
     short_name = '%s_GetWriteData_%s_%s' % (self.prefix, port.name,
                                             data_element.name)
     suffix = '*' if data_type.isComplexType else ''
     proto = C.function(func_name, data_type.name + suffix)
     rte_func = autosar.rte.base.DataElementFunction(
         proto, port, data_element)
     #self._createPortVariable(component, port, data_element)
     var_name = self._createDataElementVariable(component, port,
                                                data_element)
     self.partition.upperLayerAPI.get[
         short_name] = autosar.rte.base.GetPortFunction(
             short_name, proto, data_element)
コード例 #26
0
ファイル: base.py プロジェクト: cogu/autosar
 def __init__(self, prefix, component, port, data_element, var_name):
    data_type = data_element.dataType
    func_name='%s_SetReadData_%s_%s_%s'%(prefix, component.name, port.name, data_element.name)
    shortname='%s_SetReadData_%s_%s'%(prefix, port.name, data_element.name)
    proto=C.function(func_name, 'void')
    proto.add_arg(C.variable('data', data_type.name, pointer=data_type.isComplexType))
    self.shortname = shortname
    self.data_element = data_element
    self.proto=proto
    body = C.block(innerIndent=innerIndentDefault)
    if isinstance(data_type, autosar.datatype.ArrayDataType):               
       body.append(C.statement('memcpy(&%s[0], %s, sizeof(%s)'%(var_name, proto.args[0].name, var_name)))
    elif isinstance(data_type, autosar.datatype.RecordDataType):               
       body.append(C.statement('memcpy(&%s, %s, sizeof(%s)'%(var_name, proto.args[0].name, var_name)))
    else:
       body.append(C.statement('%s = %s'%(var_name, proto.args[0].name)))
    self.body=body
コード例 #27
0
ファイル: generator.py プロジェクト: ncs1/as
 def _generate_mode_switch_func(self, callback_name, events):
     code = C.sequence()
     generated = set()
     code.append(C.function(callback_name, 'void'))
     block = C.block(innerIndent=innerIndentDefault)
     for event in events:
         task = self.cfg.find_os_task_by_runnable(event.runnable)
         if task is not None:
             if (task.name, event.name) not in generated:
                 block.append(
                     C.statement(
                         C.fcall('os_task_setEvent',
                                 params=[
                                     '&m_os_task_%s' % task.name,
                                     'EVENT_MASK_%s_%s' %
                                     (task.name, event.name)
                                 ])))
                 generated.add((task.name, event.name))
     code.append(block)
     return code
コード例 #28
0
 def _process_runnables(self, component, ws, swc, runnables=None):
     for autosar_runnable in swc.behavior.runnables:
         for dataPoint in autosar_runnable.dataReceivePoints + autosar_runnable.dataSendPoints:
             port = ws.find(dataPoint.portRef)
             if port is None:
                 raise ValueError('Error: Invalid port reference: ' +
                                  dataPoint.dataPoint.portRef)
             data_element = ws.find(dataPoint.dataElemRef)
             if data_element is None:
                 raise ValueError(
                     'Error: Invalid data element reference: ' +
                     dataPoint.dataElemRef)
             data_type = ws.find(data_element.typeRef)
             if data_type is None:
                 raise ValueError('Error: Invalid data type reference: %s' %
                                  data_element.typeRef)
             self.types.processType(ws, data_type)
             if isinstance(dataPoint, autosar.behavior.DataReceivePoint):
                 component.create_data_receive_point(
                     ws, port, data_element, data_type)
             elif isinstance(dataPoint, autosar.behavior.DataSendPoint):
                 component.create_data_send_point(ws, port, data_element,
                                                  data_type)
             else:
                 raise ValueError('unknown type: ' + str(type(dataPoint)))
         for callPoint in autosar_runnable.serverCallPoints:
             for instanceRef in callPoint.operationInstanceRefs:
                 port = ws.find(instanceRef.portRef)
                 if port is None:
                     raise ValueError('Error: Invalid port reference: ' +
                                      instanceRef.portRef)
                 operation = ws.find(instanceRef.operationRef)
                 if port is None:
                     raise ValueError(
                         'Error: Invalid operation reference: ' +
                         instanceRef.operationRef)
                 component.create_server_call_point(ws, port, operation)
         if autosar_runnable.symbol not in component.rte_runnables:
             prototype = C.function(autosar_runnable.symbol, 'void')
             component.rte_runnables[autosar_runnable.name] = Runnable(
                 autosar_runnable.name, autosar_runnable.symbol, prototype)
コード例 #29
0
ファイル: base.py プロジェクト: cogu/autosar
 def create_server_call_api(self, operation):      
    shortname='_'.join([self.parent.rte_prefix, 'Call', self.name, operation.name])
    if len(self.connectors)==0:
       func_name='_'.join([self.parent.rte_prefix, 'Call', self.parent.name, self.name, operation.name])
    elif len(self.connectors)==1:         
       server_port = self.connectors[0]
       for event in server_port.parent.events:
          if isinstance(event, OperationInvokedEvent) and (event.operation.name == operation.name):
             func_name=event.runnable.name
             break
       else:
          raise ValueError('No event found to service operation %s/%s'%(self.parent.name, self.name))
    else:
       raise ValueError('Error: Operation %s/%s seems to have multiple servers'%(self.parent.name, self.name))
    return_type = 'Std_ReturnType' if len(operation.inner.errorRefs)>0 else 'void'
    proto = C.function(func_name, return_type)
    for argument in operation.arguments:
       proto.add_arg(argument)
    port_func = CallPortFunction(shortname, proto, operation)
    self.portAPI[shortname] = port_func
    return port_func
コード例 #30
0
def _func(funcname):
    print(f"Generate {funcname}...")
    para_count = random.randint(0, 3)
    local_count = 3
    local_const = 2
    body = C.block(innerIndent=3)
    for i in range(local_count):
        body.append(
            C.statement(
                f"{C.variable(f'var{i}', 'int')} = {C.fcall(random.choice(['f_rand', 'f_scanf_nop']))}"
            ))
    for i in range(local_const):
        body.append(
            C.statement(
                f"{C.variable(f'var{i+local_count}', 'int')} = {random.randint(-1000, 1000)}"
            ))

    all_vars = [f'var{i}' for i in range(local_const + local_count)
                ] + [f'p{i}' for i in range(para_count)]
    op_seq = ['+', '-', '*', '/', '<<', '>>']
    # print(all_vars)
    max_iter = 5
    targets = []
    for i in range(4):
        trg = random.choice(all_vars)
        expr = _expression(all_vars, op_seq, trg)
        body.append(C.statement(f"{trg} = {expr}"))
        targets.append(trg)
    ret_var = random.choice(all_vars)
    ret_expr = _expression(targets, op_seq, ret_var)
    body.append(C.statement(f"{ret_var} = {ret_expr}"))
    body.append(C.statement(f'return {ret_var}'))
    head = C.function(funcname, 'int')
    for i in range(para_count):
        head.add_param(C.variable(f'p{i}', 'int'))
    func = C.sequence()
    func.append(head)
    func.append(body)
    print(str(func))
    return func
コード例 #31
0
ファイル: generator.py プロジェクト: cogu/autosar
 def _generate_task_cfg_header(self, dest_dir, file_name = 'os_task_cfg.h'):
    header = C.hfile(os.path.join(dest_dir, file_name))
    code = header.code
    code.extend(_genCommentHeader('INCLUDES'))
    code.append(C.include('os_types.h'))
    code.append(C.include('os_task.h'))
    code.append('')
    code.extend(_genCommentHeader('PUBLIC CONSTANTS AND DATA TYPES'))
    code.append(C.define('OS_NUM_TASKS',str(len(self.cfg.tasks))+'u'))
    code.append('')
    code.extend(_genCommentHeader('PUBLIC VARIABLES'))
    code.append(C.statement('extern os_cfg_t g_os_cfg'))
    code.append('')
    code.extend(_genCommentHeader('PUBLIC FUNCTION PROTOTYPES'))
    for task in self.cfg.tasks:
       code.append(C.statement('OS_TASK_HANDLER(%s, arg)'%task.name))
    for function_name in self.cfg.mode_switch_calls:
       code.append(C.statement(C.function(function_name, 'void')))
    with io.open(header.path, 'w', newline='\n') as fp:
       for line in header.lines():
          fp.write(line+'\n')
    return file_name
コード例 #32
0
ファイル: generator.py プロジェクト: ncs1/as
 def _generate_task_cfg_header(self, dest_dir, file_name='os_task_cfg.h'):
     header = C.hfile(os.path.join(dest_dir, file_name))
     code = header.code
     code.extend(_genCommentHeader('INCLUDES'))
     code.append(C.include('os_types.h'))
     code.append(C.include('os_task.h'))
     code.append('')
     code.extend(_genCommentHeader('PUBLIC CONSTANTS AND DATA TYPES'))
     code.append(C.define('OS_NUM_TASKS', str(len(self.cfg.tasks)) + 'u'))
     code.append('')
     code.extend(_genCommentHeader('PUBLIC VARIABLES'))
     code.append(C.statement('extern os_cfg_t g_os_cfg'))
     code.append('')
     code.extend(_genCommentHeader('PUBLIC FUNCTION PROTOTYPES'))
     for task in self.cfg.tasks:
         code.append(C.statement('OS_TASK_HANDLER(%s, arg)' % task.name))
     for function_name in self.cfg.mode_switch_calls:
         code.append(C.statement(C.function(function_name, 'void')))
     with io.open(header.path, 'w', newline='\n') as fp:
         for line in header.lines():
             fp.write(line + '\n')
     return file_name
コード例 #33
0
ファイル: generator.py プロジェクト: hello-yaowq/autosar-1
    def _createHeaderLines(self, filepath):
        hfile = C.hfile(filepath)
        code = hfile.code
        code.extend([C.line(x) for x in _genCommentHeader('Includes')])
        code.append(C.include("Std_Types.h"))
        code.append(C.include("Rte_Type.h"))
        code.append(C.include("Rte.h"))
        code.append(C.blank())
        code.extend(_genCommentHeader('Constants and Types'))
        for key in sorted(self.typedefs.keys()):
            code.append(C.statement(self.typedefs[key]))
        code.append(C.blank())
        code.extend([
            C.line(x)
            for x in _genCommentHeader('Public Function Declarations')
        ])
        code.append(C.blank())

        code.append(
            C.statement(C.function('%s_Start' % self.api_prefix, 'void')))
        for func in sorted(self.partition.upperLayerAPI.final['get'],
                           key=lambda x: x.shortname):
            assert func.proto is not None
            hfile.code.append(C.statement(func.proto))
        for func in sorted(self.partition.upperLayerAPI.final['setReadData'],
                           key=lambda x: x.shortname):
            assert func.proto is not None
            hfile.code.append(C.statement(func.proto))
        for func in sorted(self.partition.upperLayerAPI.final['setReadResult'],
                           key=lambda x: x.shortname):
            assert func.proto is not None
            hfile.code.append(C.statement(func.proto))
        for func in sorted(self.extra_public_functions.values(),
                           key=lambda x: x.shortname):
            assert func.proto is not None
            hfile.code.append(C.statement(func.proto))
        hfile.code.append(C.blank())
        return hfile.lines()
コード例 #34
0
    def create_server_call_point(self, ws, port, operation):
        shortname = '_'.join(
            [self.rte_prefix, 'Call', port.name, operation.name])
        func = C.function(shortname, 'Std_ReturnType')
        portInterface = ws.find(port.portInterfaceRef)
        if portInterface is None:
            raise ValueError("Error: invalid port interface reference: " +
                             port.portInterfaceRef)
        for argument in operation.arguments:
            dataType = ws.find(argument.typeRef)
            if dataType is None:
                raise ValueError('Error: Invalid type reference: ' +
                                 argument.typeRef)
            isPointer = False
            if dataType.isComplexType or (argument.direction
                                          == 'OUT') or (argument.direction
                                                        == 'INOUT'):
                isPointer = True
            func.add_arg(
                C.variable(argument.name, dataType.name, pointer=isPointer))

            rte_port_func = CallPortFunction(shortname, func, portInterface,
                                             operation)
            self.clientAPI.call[shortname] = rte_port_func
コード例 #35
0
ファイル: base.py プロジェクト: cogu/autosar
 def __init__(self, ar_event, runnable, port, operation):
    super().__init__(ar_event, runnable)
    self.port = port
    self.operation = operation      
    return_type = 'Std_ReturnType' if len(operation.inner.errorRefs)>0 else 'void'
    self.runnable.prototype=C.function(runnable.symbol, return_type, args=operation.arguments)
コード例 #36
0
ファイル: partition.py プロジェクト: ncs1/as
 def _runnables_finalize(self):
     #operation_invoke_events = [event for event in self.events if isinstance(event, OperationInvokedEvent)]
     for runnable in self.runnables:
         if runnable.prototype is None:
             runnable.prototype = (C.function(runnable.symbol, 'void'))