def activate_runtime(): RuntimeModel.set_change_handler_regex('PORTIO', 'portio\.[^.]*\.enable\..*' , onPortRoutePropertyChange) RuntimeModel.set_change_handler_regex('PORTIO', 'portio\.[^.]*\.location\..*', onPortRoutePropertyChange) RuntimeModel.set_change_handler_regex('P[A-Z][0-9][0-5]?', PORT_PINS.ports_settings_custompinname.S, onPortPinPropertyChange) RuntimeModel.set_change_handler_regex('P[A-Z][0-9][0-5]?', PORT_PINS.ports_settings_halpinname.S, onPortPinPropertyChange) RuntimeModel.set_change_handler_regex('P[A-Z][0-9][0-5]?', PORT_PINS.ports_settings_reserve.S, onPortPinPropertyChange)
def validateAllModuleRouteEnablesAndModes(portio): ''' Check that the routes used by modules are enabled on the portio :type portio: Studio._private.StudioClasses.com_silabs_ide_halconf_core_client_accessors_IPortIOAccessor ''' if SNIPPET_PROFILE: start = time.time() # ensure that this is always in a known mapping group RuntimeModel.new_problem_group(None, portio, 'validateAllModuleRouteEnablesAndModes') for signal in portio.signals: signalNameComponents = signal.name.split('|') if len(signalNameComponents) == 3: module = signalNameComponents[0] route = signalNameComponents[1] signalType = signalNameComponents[2] if signalType == 'EN': # If the validation enable signal is True, validate the route enable property if signal.get() == True: validateModuleRouteEnable(portio, module, route) if SNIPPET_PROFILE: stop = time.time() print("validateAllModuleRouteEnablesAndModes() completed in {:.3f} ms".format((stop - start) * 1000))
def validateModuleRouteEnable(portio, module_name, route_name): selector_route = findRoute(portio, module_name, route_name) if not selector_route: return # Add an error if the route is not enabled if selector_route[1].enablePropertyReference.enumIndex == 0: RuntimeModel.new_warning(selector_route[1].enablePropertyReference, '{0}_{1} pin is in use and must be enabled'.format(module_name, route_name))
def __setOverrideLabel(self, label): ''' Sets the given label as custom label on the pin. :param label: Label to assign to the pin :return: void ''' RuntimeModel.set_property_value(self.pin.ref( PORT_PINS.ports_settings_custompinname.S), label, module=self.pin)
def onLoad(state): # Prevent changed properties from enabling parent peripheral try: hal.registerDeviceOverride(hal.OVERRIDE_PERIPHERAL_AUTO_ENABLE, True) except: # Fall back to misspelled version of the function argument try: hal.registerDeviceOverride(hal.OVERRIDE_PERIPHRAL_AUTO_ENABLE, True) except: pass available_modules = Metadata.get_available_modules_for_family() if PROFILE: start = time.time() familyobj = dep.Family(state.device.name) modules = [] module_instance = ACMP_behavior.ACMP('ACMP0') module_instance.load_halconfig_model(available_modules, familyobj) state.set_module_object('ACMP0', module_instance) modules.append(module_instance) module_instance = ACMP_behavior.ACMP('ACMP1') module_instance.load_halconfig_model(available_modules, familyobj) state.set_module_object('ACMP1', module_instance) modules.append(module_instance) module_instance = ADC_behavior.ADC('ADC0') module_instance.load_halconfig_model(available_modules, familyobj) state.set_module_object('ADC0', module_instance) modules.append(module_instance) module_instance = ANTDIV_behavior.ANTDIV('ANTDIV') module_instance.load_halconfig_model(available_modules, familyobj) state.set_module_object('ANTDIV', module_instance) modules.append(module_instance) module_instance = BATTERYMON_behavior.BATTERYMON('BATTERYMON') module_instance.load_halconfig_model(available_modules, familyobj) state.set_module_object('BATTERYMON', module_instance) modules.append(module_instance) module_instance = BTL_BUTTON_behavior.BTL_BUTTON('BTL_BUTTON') module_instance.load_halconfig_model(available_modules, familyobj) state.set_module_object('BTL_BUTTON', module_instance) modules.append(module_instance) module_instance = BULBPWM_behavior.BULBPWM('BULBPWM') module_instance.load_halconfig_model(available_modules, familyobj) state.set_module_object('BULBPWM', module_instance) modules.append(module_instance) module_instance = BULBPWM_COLOR_behavior.BULBPWM_COLOR('BULBPWM_COLOR') module_instance.load_halconfig_model(available_modules, familyobj) state.set_module_object('BULBPWM_COLOR', module_instance) modules.append(module_instance) module_instance = BUTTON_behavior.BUTTON('BUTTON') module_instance.load_halconfig_model(available_modules, familyobj) state.set_module_object('BUTTON', module_instance) modules.append(module_instance) module_instance = CMU_behavior.CMU('CMU') module_instance.load_halconfig_model(available_modules, familyobj) state.set_module_object('CMU', module_instance) modules.append(module_instance) module_instance = COEX_behavior.COEX('COEX') module_instance.load_halconfig_model(available_modules, familyobj) state.set_module_object('COEX', module_instance) modules.append(module_instance) module_instance = CS5463_behavior.CS5463('CS5463') module_instance.load_halconfig_model(available_modules, familyobj) state.set_module_object('CS5463', module_instance) modules.append(module_instance) module_instance = DCDC_behavior.DCDC('DCDC') module_instance.load_halconfig_model(available_modules, familyobj) state.set_module_object('DCDC', module_instance) modules.append(module_instance) module_instance = EMU_behavior.EMU('EMU') module_instance.load_halconfig_model(available_modules, familyobj) state.set_module_object('EMU', module_instance) modules.append(module_instance) module_instance = EXTFLASH_behavior.EXTFLASH('EXTFLASH') module_instance.load_halconfig_model(available_modules, familyobj) state.set_module_object('EXTFLASH', module_instance) modules.append(module_instance) module_instance = EZRADIOPRO_behavior.EZRADIOPRO('EZRADIOPRO') module_instance.load_halconfig_model(available_modules, familyobj) state.set_module_object('EZRADIOPRO', module_instance) modules.append(module_instance) module_instance = FEM_behavior.FEM('FEM') module_instance.load_halconfig_model(available_modules, familyobj) state.set_module_object('FEM', module_instance) modules.append(module_instance) module_instance = GPIO_behavior.GPIO('GPIO') module_instance.load_halconfig_model(available_modules, familyobj) state.set_module_object('GPIO', module_instance) modules.append(module_instance) module_instance = I2C_behavior.I2C('I2C0') module_instance.load_halconfig_model(available_modules, familyobj) state.set_module_object('I2C0', module_instance) modules.append(module_instance) module_instance = I2CSENSOR_behavior.I2CSENSOR('I2CSENSOR') module_instance.load_halconfig_model(available_modules, familyobj) state.set_module_object('I2CSENSOR', module_instance) modules.append(module_instance) module_instance = IDAC_behavior.IDAC('IDAC0') module_instance.load_halconfig_model(available_modules, familyobj) state.set_module_object('IDAC0', module_instance) modules.append(module_instance) module_instance = IOEXP_behavior.IOEXP('IOEXP') module_instance.load_halconfig_model(available_modules, familyobj) state.set_module_object('IOEXP', module_instance) modules.append(module_instance) module_instance = LED_behavior.LED('LED') module_instance.load_halconfig_model(available_modules, familyobj) state.set_module_object('LED', module_instance) modules.append(module_instance) module_instance = LEUART_behavior.LEUART('LEUART0') module_instance.load_halconfig_model(available_modules, familyobj) state.set_module_object('LEUART0', module_instance) modules.append(module_instance) module_instance = MODEM_behavior.MODEM('MODEM') module_instance.load_halconfig_model(available_modules, familyobj) state.set_module_object('MODEM', module_instance) modules.append(module_instance) module_instance = PA_behavior.PA('PA') module_instance.load_halconfig_model(available_modules, familyobj) state.set_module_object('PA', module_instance) modules.append(module_instance) module_instance = PRS_behavior.PRS('PRS') module_instance.load_halconfig_model(available_modules, familyobj) state.set_module_object('PRS', module_instance) modules.append(module_instance) module_instance = PTI_behavior.PTI('PTI') module_instance.load_halconfig_model(available_modules, familyobj) state.set_module_object('PTI', module_instance) modules.append(module_instance) module_instance = PYD1698_behavior.PYD1698('PYD1698') module_instance.load_halconfig_model(available_modules, familyobj) state.set_module_object('PYD1698', module_instance) modules.append(module_instance) module_instance = SERIAL_behavior.SERIAL('SERIAL') module_instance.load_halconfig_model(available_modules, familyobj) state.set_module_object('SERIAL', module_instance) modules.append(module_instance) module_instance = SPIDISPLAY_behavior.SPIDISPLAY('SPIDISPLAY') module_instance.load_halconfig_model(available_modules, familyobj) state.set_module_object('SPIDISPLAY', module_instance) modules.append(module_instance) module_instance = SPINCP_behavior.SPINCP('SPINCP') module_instance.load_halconfig_model(available_modules, familyobj) state.set_module_object('SPINCP', module_instance) modules.append(module_instance) module_instance = TIMER_behavior.TIMER('TIMER0') module_instance.load_halconfig_model(available_modules, familyobj) state.set_module_object('TIMER0', module_instance) modules.append(module_instance) module_instance = TIMER_behavior.TIMER('TIMER1') module_instance.load_halconfig_model(available_modules, familyobj) state.set_module_object('TIMER1', module_instance) modules.append(module_instance) module_instance = UARTNCP_behavior.UARTNCP('UARTNCP') module_instance.load_halconfig_model(available_modules, familyobj) state.set_module_object('UARTNCP', module_instance) modules.append(module_instance) module_instance = USART_behavior.USART('USART0') module_instance.load_halconfig_model(available_modules, familyobj) state.set_module_object('USART0', module_instance) modules.append(module_instance) module_instance = USART_behavior.USART('USART1') module_instance.load_halconfig_model(available_modules, familyobj) state.set_module_object('USART1', module_instance) modules.append(module_instance) module_instance = VCOM_behavior.VCOM('VCOM') module_instance.load_halconfig_model(available_modules, familyobj) state.set_module_object('VCOM', module_instance) modules.append(module_instance) module_instance = VUART_behavior.VUART('VUART') module_instance.load_halconfig_model(available_modules, familyobj) state.set_module_object('VUART', module_instance) modules.append(module_instance) module_instance = WDOG_behavior.WDOG('WDOG') module_instance.load_halconfig_model(available_modules, familyobj) state.set_module_object('WDOG', module_instance) modules.append(module_instance) if PROFILE: stop = time.time() print(" construction of all modules completed in {:.3f} ms".format( (stop - start) * 1000)) start = time.time() # Do the hook installing after all modules have initialized PIN_Snippets.activate_runtime() PORTIO_Snippets.activate_runtime() for module_instance in modules: module_instance.activate_runtime(state) force_enable_module = RuntimeModel.get_property_value( module_instance.get_property('forceenable'), RuntimeModel.get_studio_module_by_name(module_instance.name, state.mode), False) if force_enable_module == '1': RuntimeModel.set_module_checked( RuntimeModel.get_studio_module_by_name(module_instance.name, state.mode), True, state, readonly=True) PORTIO_Snippets.onLoad(state) if PROFILE: stop = time.time() print(" activate_runtime() for all modules completed in {:.3f} ms". format((stop - start) * 1000))
def validateRouting(portio, state): ''' :type portio: Studio._private.StudioClasses.com_silabs_ide_halconf_core_client_accessors_IPortIOAccessor ''' if SNIPPET_PROFILE: start = time.time() # ensure that this is always in a known mapping group RuntimeModel.new_problem_group(None, portio, state, 'validateRouting') """ A map that stores the pin assignment(s) for each physical pin: { pin ID : PinRoutes } """ pinAssignments = collections.OrderedDict() """ Generate a PinLabelsRoutes structures for each pin. Add the pin accessor and create an empty label list to track the assigned pin labels """ for portbank in portio.portBanks: for pin in portbank.pins: pinAssignments[pin.id] = PinRoutes(pin, []) for route in activePinRoutes(portio): pinAssignments[route.getPinId()].pin = route.getPin() pinAssignments[route.getPinId()].routes.append(route) signalSettings = [] # for module in portio.mode.getPeripherals(): # if 'APORT' in module.name: # for attribute in dir(APORT_EFR.SIGNALS): # if 'STAT' in attribute: # print(attribute + " : " + str(module.signal(getattr(APORT_EFR.SIGNALS, attribute)).get())) for pinRoute in pinAssignments.values(): label = pinRoute.getLabel() color = pinRoute.getColor() # This is the place to override pin labels for APORT labels = label.split(' / ') newlabels = [] for partiallabel in labels: newlabel = partiallabel # if 'APORT' in partiallabel: # # get reference to aport through mode # modules = portio.mode.getPeripherals() # # for module in modules: # if 'APORT' in module.name: # chan = partiallabel.replace('APORT_', '').replace("P", "X").replace("N", "Y") # newlabel = str(module.signal(getattr(APORT_EFR.SIGNALS, chan + "_STAT")).get()) # print(chan + " : " + newlabel) # # newlabels.append(newlabel) # else: newlabels.append(newlabel) label = ' / '.join(newlabels) # Set pin signal assignment signalSettings.append((pinRoute.getPin().assignmentSignal, [label, color])) for (prop, msg) in pinRoute.errors(): RuntimeModel.new_warning(prop, msg, state) # Filtering out non-aport pinRoutes aportPinAssignments = {} for pinID in pinAssignments.keys(): if pinAssignments[pinID].isAportConnected(): aportPinAssignments[pinID] = pinAssignments[pinID] for route in pinAssignments[pinID].getRoutes(): if not route.getAportName(): aportPinAssignments[pinID].getRoutes().remove(route) # Generating warnings and infos for (prop, msg) in aportWarnings(aportPinAssignments): RuntimeModel.new_warning(prop, msg, state) for (prop, msg) in aportInfos(aportPinAssignments): RuntimeModel.new_info(prop, msg, state) # Only apply a signal setting if it isn't the same as the previous value for (signal, setting) in signalSettings: if not inLastSignalSettings(portio.mode.name, (signal, setting)): RuntimeModel.set_signal_value(signal, setting, state) # Keep track of settings for next time LastSignalSettings[portio.mode.name] = signalSettings # Validate that all module routes in use are enabled on the portio # validateAllModuleRouteEnablesAndModes(portio) if SNIPPET_PROFILE: stop = time.time() print("validateRouting() completed in {:.3f} ms".format((stop - start) * 1000))