def _generate_task_cfg_source(self, dest_dir, header_file, file_name = 'os_task_cfg.c'): source = C.cfile(os.path.join(dest_dir, file_name)) code = source.code code.extend(_genCommentHeader('INCLUDES')) code.append(C.include(header_file)) code.append(C.include('os_event_cfg.h')) code.append('') code.extend(_genCommentHeader('PRIVATE VARIABLES')) for static_var in sorted(self.static_vars.values(), key=lambda x: x.name): code.append(C.statement(static_var)) code.append('') for alarm_var in self.alarm_vars: code.append(C.line(str(alarm_var.decl)+' =')) code.append(C.statement(alarm_var.body)) code.append(C.line(str(self.os_task_var.decl)+' =')) code.append(C.statement(self.os_task_var.body)) code.append('') code.extend(_genCommentHeader('PUBLIC VARIABLES')) code.append(C.line('os_cfg_t g_os_cfg =')) body = C.block(innerIndent = innerIndentDefault) body.append(C.line('&os_task_cfg[0],')) body.append(C.line('OS_NUM_TASKS,')) body.append(C.line('0,')) body.append(C.line('0')) code.append(C.statement(body)) code.append('') code.extend(_genCommentHeader('PUBLIC FUNCTIONS')) for elem in self.cfg.partition.mode_switch_functions.values(): for callback_name in sorted(elem.calls.keys()): code.extend(self._generate_mode_switch_func(callback_name, elem.calls[callback_name])) code.append('') with io.open(source.path, 'w', newline='\n') as fp: for line in source.lines(): fp.write(line+'\n')
def _genComponentHeader(self, fp, component): ws = component.swc.rootWS() assert(ws is not None) hfile=C.hfile(None, guard='RTE_%s_H'%(component.swc.name.upper())) hfile.code.append(C.include('Rte.h')) hfile.code.append(C.include('Rte_Type.h')) lines = self._genInitValues(ws, component.swc.requirePorts+component.swc.providePorts) if len(lines)>0: hfile.code.extend([C.line(x) for x in _genCommentHeader('Init Values')]) hfile.code.extend(lines) #Write API hfile.code.append(C.blank()) hfile.code.extend([C.line(x) for x in _genCommentHeader('API Prototypes')]) for proto in component.clientAPI.get_all(): hfile.code.append(C.statement(proto.func)) if len(component.clientAPI.final['read'])>0: hfile.code.append(C.blank()) hfile.code.extend([C.line(x) for x in _genCommentHeader('Rte_Read_<p>_<d>')]) hfile.code.extend([C.define(proto.shortname, proto.func.name) for proto in component.clientAPI.final['read']]) if len(component.clientAPI.final['write'])>0: hfile.code.append(C.blank()) hfile.code.extend([C.line(x) for x in _genCommentHeader('Rte_Write_<p>_<d>')]) hfile.code.extend([C.define(proto.shortname, proto.func.name) for proto in component.clientAPI.final['write']]) if len(component.clientAPI.final['receive'])>0: hfile.code.append(C.blank()) hfile.code.extend([C.line(x) for x in _genCommentHeader('Rte_Receive_<p>_<d>')]) hfile.code.extend([C.define(proto.shortname, proto.func.name) for proto in component.clientAPI.final['receive']]) if len(component.clientAPI.final['send'])>0: hfile.code.append(C.blank()) hfile.code.extend([C.line(x) for x in _genCommentHeader('Rte_Send_<p>_<d>')]) hfile.code.extend([C.define(proto.shortname, proto.func.name) for proto in component.clientAPI.final['send']]) if len(component.clientAPI.final['mode'])>0: hfile.code.append(C.blank()) hfile.code.extend([C.line(x) for x in _genCommentHeader('Rte_Mode_<p>_<d>')]) hfile.code.extend([C.define(proto.shortname, proto.func.name) for proto in component.clientAPI.final['mode']]) if len(component.clientAPI.final['mode'])>0: hfile.code.append(C.blank()) hfile.code.extend([C.line(x) for x in _genCommentHeader('Rte_Mode_<mode>')]) hfile.code.extend([C.define(proto.shortname, proto.func.name) for proto in component.clientAPI.final['mode']]) if len(component.clientAPI.final['calprm'])>0: hfile.code.append(C.blank()) hfile.code.extend([C.line(x) for x in _genCommentHeader('Rte_Calprm_<name>')]) hfile.code.extend([C.define(proto.shortname, proto.func.name) for proto in component.clientAPI.final['calprm']]) if len(component.clientAPI.final['call'])>0: hfile.code.append(C.blank()) hfile.code.extend([C.line(x) for x in _genCommentHeader('Rte_Call_<p>_<o> ')]) hfile.code.extend([C.define(proto.shortname, proto.func.name) for proto in component.clientAPI.final['call']]) if len(component.rte_runnables)>0: for name in sorted(component.rte_runnables): runnable = component.rte_runnables[name] tmp = self._writeRunnableProto(runnable) hfile.code.extend(tmp) fp.write('\n'.join(hfile.lines())) fp.write('\n')
def _write_includes(self, fp): lines = _genCommentHeader('Includes') fp.write('\n'.join(lines) + '\n') code = C.sequence() for include in self.includes: code.append(C.include(*include)) if self.com_component is not None: code.append(C.include(self.com_component.name + '.h')) if self.os_enable: code.append(C.include('os.h')) fp.write('\n'.join(code.lines()) + '\n\n')
def _write_includes(self, fp): lines = _genCommentHeader('Includes') fp.write('\n'.join(lines)+'\n') code = C.sequence() for include in self.includes: code.append(C.include(*include)) fp.write('\n'.join(code.lines())+'\n\n')
def _write_source_includes(self): code = C.sequence() code.extend(_genCommentHeader2('INCLUDES')) code.append(C.blank()) for include in self.includes: code.append(C.include(*include)) code.append(C.blank()) return code
def _generate_task_cfg_source(self, dest_dir, header_file, file_name='os_task_cfg.c'): source = C.cfile(os.path.join(dest_dir, file_name)) code = source.code code.extend(_genCommentHeader('INCLUDES')) code.append(C.include(header_file)) code.append(C.include('os_event_cfg.h')) code.append('') code.extend(_genCommentHeader('PRIVATE VARIABLES')) for static_var in sorted(self.static_vars.values(), key=lambda x: x.name): code.append(C.statement(static_var)) code.append('') for alarm_var in self.alarm_vars: code.append(C.line(str(alarm_var.decl) + ' =')) code.append(C.statement(alarm_var.body)) code.append(C.line(str(self.os_task_var.decl) + ' =')) code.append(C.statement(self.os_task_var.body)) code.append('') code.extend(_genCommentHeader('PUBLIC VARIABLES')) code.append(C.line('os_cfg_t g_os_cfg =')) body = C.block(innerIndent=innerIndentDefault) body.append(C.line('&os_task_cfg[0],')) body.append(C.line('OS_NUM_TASKS,')) body.append(C.line('0,')) body.append(C.line('0')) code.append(C.statement(body)) code.append('') code.extend(_genCommentHeader('PUBLIC FUNCTIONS')) for elem in self.cfg.partition.mode_switch_functions.values(): for callback_name in sorted(elem.calls.keys()): code.extend( self._generate_mode_switch_func(callback_name, elem.calls[callback_name])) code.append('') with io.open(source.path, 'w', newline='\n') as fp: for line in source.lines(): fp.write(line + '\n')
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
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
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()
def _generate_event_cfg_header(self, dest_dir, file_name='os_event_cfg.h'): header = C.hfile(os.path.join(dest_dir, file_name)) code = header.code code.extend(_genCommentHeader('INCLUDES')) code.append(C.include('PlatForm_Types.h')) code.append('') code.extend(_genCommentHeader('PUBLIC CONSTANTS AND DATA TYPES')) for os_task in self.cfg.tasks: for event_mask in os_task.event_masks: code.append(event_mask) code.append(C.define('OS_NUM_ALARMS_%s'%os_task.name, str(len(os_task.timer_events)))) code.append(C.blank()) with io.open(header.path, 'w', newline='\n') as fp: for line in header.lines(): fp.write(line+'\n')
def _generate_event_cfg_header(self, dest_dir, file_name='os_event_cfg.h'): header = C.hfile(os.path.join(dest_dir, file_name)) code = header.code code.extend(_genCommentHeader('INCLUDES')) code.append(C.include('PlatForm_Types.h')) code.append('') code.extend(_genCommentHeader('PUBLIC CONSTANTS AND DATA TYPES')) for os_task in self.cfg.tasks: for event_mask in os_task.event_masks: code.append(event_mask) code.append( C.define('OS_NUM_ALARMS_%s' % os_task.name, str(len(os_task.timer_events)))) code.append(C.blank()) with io.open(header.path, 'w', newline='\n') as fp: for line in header.lines(): fp.write(line + '\n')
def _write_header_includes(self, code): code.extend(_genCommentHeader2("INCLUDES")) code.append(C.include('Rte_Type.h')) code.append(C.include('Rte.h'))
def generate(self, dest_dir='.', file_name='Rte_Type.h'): """ Generates Rte_Type.h Note: The last argument has been deprecated and is no longer in use """ if self.partition.isFinalized == False: self.partition.finalize() file_path = os.path.join(dest_dir, file_name) with io.open(file_path, 'w', newline='\n') as fp: hfile = C.hfile(file_name) hfile.code.extend( [C.line(x) for x in _genCommentHeader('Includes')]) hfile.code.append(C.include("Std_Types.h")) hfile.code.append(C.blank()) (basicTypes, complexTypes, modeTypes) = self.partition.types.getTypes() hfile.code.extend([ C.line(x) for x in _genCommentHeader('Data Type Definitions') ]) hfile.code.append(C.blank()) ws = self.partition.ws unusedDefaultTypes = self._findUnusedDefaultTypes(ws, basicTypes) first = True for ref in sorted(basicTypes) + sorted(complexTypes): dataType = ws.find(ref) if dataType is not None: typedef = None if first: first = False else: hfile.code.append(C.blank()) hfile.code.append('#define Rte_TypeDef_%s' % dataType.name) if isinstance(dataType, autosar.datatype.BooleanDataType): typedef = C.typedef('boolean', dataType.name) hfile.code.append(C.statement(typedef)) elif isinstance(dataType, autosar.datatype.IntegerDataType): valrange = dataType.maxVal - dataType.minVal bitcount = valrange.bit_length() typename = dataType.name basetype = self._typename(bitcount, dataType.minVal) typedef = C.typedef(basetype, typename) hfile.code.append(C.statement(typedef)) isUnsigned = True if basetype in ('uint8', 'uint16', 'uint32') else False if isUnsigned: minval = str(dataType.minVal) + 'u' maxval = str(dataType.maxVal) + 'u' else: minval = str(dataType.minVal) maxval = str(dataType.maxVal) hfile.code.append('#define %s_LowerLimit ((%s)%s)' % (typename, typename, minval)) hfile.code.append('#define %s_UpperLimit ((%s)%s)' % (typename, typename, maxval)) if dataType.compuMethodRef is not None: compuMethod = ws.find(dataType.compuMethodRef) if compuMethod is not None: lines1 = [] lines2 = [] if isinstance( compuMethod, autosar.datatype.CompuMethodConst): for elem in compuMethod.elements: if isUnsigned: value = str(elem.upperLimit) + 'u' else: value = str(elem.upperLimit) lines1.append( '#define RTE_CONST_%s (%s)' % (elem.textValue, value)) lines2.append( '#define %s ((%s)%s)' % (elem.textValue, typename, value)) if len(lines2) > 0: tmp = lines1 + [C.blank()] + lines2 else: tmp = lines1 for line in tmp: hfile.code.append(line) else: raise ValueError(dataType.compuMethodRef) elif isinstance(dataType, autosar.datatype.RecordDataType): body = C.block(innerIndent=innerIndentDefault) for elem in dataType.elements: childType = ws.find(elem.typeRef, role='DataType') body.append( C.statement( C.variable(elem.name, childType.name))) struct = C.struct(None, body, typedef=dataType.name) hfile.code.append(C.statement(struct)) elif isinstance(dataType, autosar.datatype.StringDataType): hfile.code.append('typedef uint8 %s[%d];' % (dataType.name, dataType.length + 1)) elif isinstance(dataType, autosar.datatype.ArrayDataType): childType = ws.find(dataType.typeRef, role='DataType') if childType is None: raise ValueError('invalid type reference: ' + dataType.typeRef) hfile.code.append( 'typedef %s %s[%d];' % (childType.name, dataType.name, dataType.length)) elif isinstance(dataType, autosar.datatype.RealDataType): if dataType.encoding == 'DOUBLE': platform_typename = 'float64' else: platform_typename = 'float32' hfile.code.append('typedef %s %s;' % (platform_typename, dataType.name)) else: raise NotImplementedError(type(dataType)) #sys.stderr.write('not implemented: %s\n'%str(type(dataType))) else: raise ValueError(ref) if len(modeTypes) > 0: lines = _genCommentHeader('Mode Types') tmp = [] hfile.code.extend(lines) first = True for ref in modeTypes: if first: first = False else: tmp.append(C.blank()) modeType = ws.find(ref) hfile.code.append( C.statement( C.typedef('uint8', 'Rte_ModeType_' + modeType.name))) for i, elem in enumerate(modeType.modeDeclarations): # define RTE_MODE_EcuM_Mode_POST_RUN ((Rte_ModeType_EcuM_Mode)0) tmp.append( C.define( 'RTE_MODE_%s_%s' % (modeType.name, elem.name), '((Rte_ModeType_EcuM_Mode)%d)' % i)) hfile.code.append(C.blank()) hfile.code.extend(tmp) if len(unusedDefaultTypes) > 0: hfile.code.append(C.blank(2)) hfile.code.append( C.line('#ifndef RTE_SUPPRESS_UNUSED_DATATYPES')) for name in sorted(unusedDefaultTypes): hfile.code.append(C.blank()) hfile.code.extend(self.defaultTypes[name]) hfile.code.append(C.blank()) hfile.code.append(C.line('#endif')) fp.write('\n'.join(hfile.lines())) fp.write('\n')