/*! * \brief Constructor * \note This constructor tries to start a new process and launch module. If this fails at firs time, it will try again. * \note This second trial is currently a workaround for QProcess failing to start a module on OSX on the first time. * \note The reason for this remains unclear, possibly an OSX issue with either yarprun or QProcess. * \param[in] pMainWindow - pointer to MainWindow * \param[in] binaryName - name of module executable * \param[in] moduleTitle - title of this module * \param[in] server - server where the module runs * \param[in] instanceID - module identification number * \param[in] tabID - module tab index */ GUI::GUI(MainWindow *pMainWindow, QString binaryName, QString moduleTitle, QString serverName, int instanceID, int tabID) { bool success = startModule(binaryName, serverName, instanceID); if(!success) { module->close(); qCritical(" - %s_gui(%i): trying to relaunch QProcess and connect again", binaryName.toStdString().c_str(), instanceID); success = startModule(binaryName, serverName, instanceID); } if(success) initialise(pMainWindow, binaryName, moduleTitle, serverName, instanceID, tabID); }
/**************************************************************************** * Attach interval timer function * * The callback function is called every 1ms interval * @param[in] fFunction Specify callback function * * @return none * ***************************************************************************/ void attachIntervalTimerHandler(void (*fFunction)(unsigned long u32Milles)) { g_fITInterruptFunc = fFunction; startModule(MstpIdTPU0); // Stop the timer. TPUA.TSTR.BIT.CST5 = 0U; // Set the counter to run at the desired frequency. TPU5.TCR.BIT.TPSC = 0b011; // Set TGRA compare match to clear TCNT. TPU5.TCR.BIT.CCLR = 0b001; // Set the count to occur on rising edge of PCLK. TPU5.TCR.BIT.CKEG = 0b01; // Set Normal. TPU5.TMDR.BIT.MD = 0b0000; // Set the period. TPU5.TGRA = 750 - 1; //1ms setting at PCLK/64(750kHz) // Set the count to occur on rising edge of PCLK. TPU5.TSR.BIT.TGFA = 0U; /* Set TGI6A interrupt priority level to 5*/ IPR(TPU5,TGI5A) = 0x5; /* Enable TGI6A interrupts */ IEN(TPU5,TGI5A) = 0x1; /* Clear TGI6A interrupt flag */ IR(TPU5,TGI5A) = 0x0; // Enable the module interrupt for the ms timer. TPU5.TIER.BIT.TGIEA = 1U; // Start the timer. TPUA.TSTR.BIT.CST5 = 1U; }
int main( void ) { halInit(); moduleInit(); printf("\r\n****************************************************\r\n"); printf("Fragmentation Example - ROUTER - using AFZDO\r\n"); buttonIsr = &handleButtonPress; #define MODULE_START_DELAY_IF_FAIL_MS 5000 /* See basic communications examples for more information about module startup. */ struct moduleConfiguration defaultConfiguration = DEFAULT_MODULE_CONFIGURATION_ROUTER; start: while ((result = startModule(&defaultConfiguration, GENERIC_APPLICATION_CONFIGURATION)) != MODULE_SUCCESS) { printf("Module start unsuccessful. Error Code 0x%02X. Retrying...\r\n", result); delayMs(MODULE_START_DELAY_IF_FAIL_MS); } printf("On Network!\r\n"); setLed(0); /* On network, display info about this network */ #ifdef DISPLAY_NETWORK_INFORMATION //excluded to reduce code size displayNetworkConfigurationParameters(); displayDeviceInformation(); #endif HAL_ENABLE_INTERRUPTS(); /* Now the network is running - send a message to the coordinator every few seconds.*/ #define TEST_CLUSTER 0x77 /* Fill test message buffer with an incrementing counter */ int i = 0; for (i=0; i<MESSAGE_LENGTH; i++) { testMessage[i] = i; } printf("Sending the following message:\r\n"); uint8_t counter = 0; while (1) { printf("Sending Message #%u L%u to Short Address 0x0000 (Coordinator) ", counter++, MESSAGE_LENGTH); /* Send an extended length message to a short address */ moduleResult_t result = afSendDataExtendedShort(DEFAULT_ENDPOINT, DEFAULT_ENDPOINT, 0, TEST_CLUSTER, testMessage, MESSAGE_LENGTH); //a short message - coordinator will receive an AF_INCOMING_MSG_EXT if (result == MODULE_SUCCESS) { printf("Success\r\n"); } else { printf("ERROR %i ", result); #ifdef RESTART_AFTER_ZM_FAILURE printf("\r\nRestarting\r\n"); goto start; #else printf("stopping\r\n"); while(1); #endif } delayMs(2000); } }
bool Win32GLGrDriver2D::startup(){ startModule( "Win32GL" ); startModule( "Win32FontDriver" ); _context=0; _graphics=0; _glContext=0; _font=new Win32Font( BBTMPSTR("courier"),10,0 ); autoRelease( _font ); bbSetGrDriver2D( this ); return true; }
int main( void ) { halInit(); moduleInit(); printf("\r\n****************************************************\r\n"); printf("Secure Communications Example - ROUTER - using AFZDO\r\n"); HAL_ENABLE_INTERRUPTS(); #define MODULE_START_DELAY_IF_FAIL_MS 5000 struct moduleConfiguration defaultConfiguration = DEFAULT_MODULE_CONFIGURATION_ROUTER; defaultConfiguration.securityMode = SECURITY_MODE_PRECONFIGURED_KEYS; defaultConfiguration.securityKey = key; start: while ((result = startModule(&defaultConfiguration, GENERIC_APPLICATION_CONFIGURATION)) != MODULE_SUCCESS) { printf("Module start unsuccessful. Error Code 0x%02X. Retrying...\r\n", result); delayMs(MODULE_START_DELAY_IF_FAIL_MS); } printf("On Network!\r\n"); setLed(0); /* On network, display info about this network */ #ifdef DISPLAY_NETWORK_INFORMATION displayNetworkConfigurationParameters(); displayDeviceInformation(); #endif /* Now the network is running - send a message to the coordinator every few seconds.*/ #define TEST_CLUSTER 0x77 while (1) { printf("Sending Message %u ", counter++); result = afSendData(DEFAULT_ENDPOINT,DEFAULT_ENDPOINT,0, TEST_CLUSTER, testMessage, 5); if (result == MODULE_SUCCESS) { printf("Success\r\n"); } else { printf("ERROR %02X ", result); #ifdef RESTART_AFTER_ZM_FAILURE printf("\r\nRestarting\r\n"); goto start; #else printf("stopping\r\n"); while(1); #endif } toggleLed(1); delayMs(2000); } }
// Start a module by name bool ICQMain::startModule(const char *name) { Module *m = getModule(name); if (m) { logger->log(LOG_WARNING, "module %s already started\n", name); return false; } ConfigParser file(LINQ_CONFIG_DIR"/modules.conf"); Profile *prof = file.getProfile(name); // Shutdown threads first to avoid race condition destroyThreads(); bool ret = startModule(prof); startThreads(); return ret; }
void StartPlasma::Private::startFreeModules() { for (const auto& module: modules->freeModules()) { startModule(module); } // QSet<QString> starting = runOrder[0]; // runOrder[0].clear(); // // qDebug() << "StartPlasma:\t" << "these are the currently running modules:" << running; // qDebug() << "StartPlasma:\t" << "starting the following modules:" << starting; // // // Did we end or we are in a dead-lock // if (starting.size() == 0 && running.size() == 0) { // // splash.reset(); // // int leftCount = 0; // foreach (const QSet<QString> & left, runOrder) { // leftCount += left.size(); // } // // if (leftCount > 0) { // qDebug() << "StartPlasma:\t" << "ERROR:" << leftCount << "modules not started - dead-lock detected"; // printLevels(); // // } else { // qDebug() << "StartPlasma:\t" << "##### Starting finished. We are all live and well (" << time.elapsed() << "ms )"; // } // // } else { // foreach (const QString &module, starting) { // startModule(module); // } // } // }
static void stateMachine() { while (1) { if (zigbeeNetworkStatus == NWK_ONLINE) { if(moduleHasMessageWaiting()) //wait until SRDY goes low indicating a message has been received. displayMessages(); } switch (state) { case STATE_IDLE: { /* process command line commands only if not doing anything else: */ if (command != NO_CHARACTER_RECEIVED) { /* parse the command entered, and go to the required state */ state = processCommand(command); command = NO_CHARACTER_RECEIVED; } /* note: other flags (for different messages or events) can be added here */ break; } case STATE_INIT: { printf("Starting State Machine\r\n"); state = STATE_GET_DEVICE_TYPE; break; } /* A button press during startup will cause the application to prompt for device type */ case STATE_GET_DEVICE_TYPE: { //printf("Current Configured DeviceType: %s\r\n", getDeviceTypeName()); set_type: /* if saving device type to flash memory: printf("Any other key to exit. Timeout in 5 seconds.\r\n"); / long wait = 0; long timeout = TICKS_IN_ONE_MS * 5000l; while ((command == NO_CHARACTER_RECEIVED) && (wait != timeout)) wait++; */ while (command == NO_CHARACTER_RECEIVED) { printf("Setting Device Type: Press C for Coordinator, R for Router, or E for End Device.\r\n"); delayMs(2000); } switch (command) { case 'C': case 'c': printf("Coordinator it is...\r\n"); zigbeeDeviceType = COORDINATOR; break; case 'R': case 'r': printf("Router it is...\r\n"); zigbeeDeviceType = ROUTER; break; case 'E': case 'e': printf("End Device it is...\r\n"); zigbeeDeviceType = END_DEVICE; break; default: command = NO_CHARACTER_RECEIVED; goto set_type; } command = NO_CHARACTER_RECEIVED; state = STATE_MODULE_STARTUP; break; } case STATE_MODULE_STARTUP: { #define MODULE_START_DELAY_IF_FAIL_MS 5000 moduleResult_t result; /* Start with the default module configuration */ struct moduleConfiguration defaultConfiguration = DEFAULT_MODULE_CONFIGURATION_COORDINATOR; /* Make any changes needed here (channel list, PAN ID, etc.) We Configure the Zigbee Device Type (Router, Coordinator, End Device) based on what user selected */ defaultConfiguration.deviceType = zigbeeDeviceType; while ((result = startModule(&defaultConfiguration, GENERIC_APPLICATION_CONFIGURATION)) != MODULE_SUCCESS) { printf("Module start unsuccessful. Error Code 0x%02X. Retrying...\r\n", result); delayMs(MODULE_START_DELAY_IF_FAIL_MS); } printf("Success\r\n"); state = STATE_DISPLAY_NETWORK_INFORMATION; zigbeeNetworkStatus = NWK_ONLINE; break; } case STATE_DISPLAY_NETWORK_INFORMATION: { printf("Module Information:\r\n"); /* On network, display info about this network */ displayNetworkConfigurationParameters(); displayDeviceInformation(); displayCommandLineInterfaceHelp(); state = STATE_IDLE; //startup is done! break; } case STATE_VALID_SHORT_ADDRESS_ENTERED: //command line processor has a valid shortAddressEntered { printf("Valid Short Address Entered\r\n"); state = pendingState; break; } case STATE_VALID_LONG_ADDRESS_ENTERED: { /* flip byte order */ int8_t temp[8]; int i; for (i=0; i<8; i++) temp[7-i] = longAddressEntered[i]; memcpy(longAddressEntered, temp, 8); //Store LSB first since that is how it will be sent: state = pendingState; break; } case STATE_SEND_MESSAGE_VIA_SHORT_ADDRESS: { printf("Send via short address to %04X\r\n", shortAddressEntered); moduleResult_t result = afSendData(DEFAULT_ENDPOINT,DEFAULT_ENDPOINT,shortAddressEntered, TEST_CLUSTER, testMessage, 5); if (result == MODULE_SUCCESS) { printf("Success\r\n"); } else { printf("Could not send to that device (Error Code 0x%02X)\r\n", result); #ifdef RESTART_AFTER_ZM_FAILURE printf("\r\nRestarting\r\n"); state = STATE_MODULE_STARTUP; continue; #endif } state = STATE_IDLE; break; } case STATE_SEND_MESSAGE_VIA_LONG_ADDRESS: { printf("Send via long address to (LSB first)"); printHexBytes(longAddressEntered, 8); moduleResult_t result = afSendDataExtended(DEFAULT_ENDPOINT, DEFAULT_ENDPOINT, longAddressEntered, DESTINATION_ADDRESS_MODE_LONG, TEST_CLUSTER, testMessage, 5); if (result == MODULE_SUCCESS) { printf("Success\r\n"); } else { printf("Could not send to that device (Error Code 0x%02X)\r\n", result); #ifdef RESTART_AFTER_ZM_FAILURE printf("\r\nRestarting\r\n"); state = STATE_MODULE_STARTUP; continue; #endif } state = STATE_IDLE; break; } case STATE_FIND_VIA_SHORT_ADDRESS: { printf("Looking for that device...\r\n"); moduleResult_t result = zdoRequestIeeeAddress(shortAddressEntered, SINGLE_DEVICE_RESPONSE, 0); if (result == MODULE_SUCCESS) { #ifndef ZDO_NWK_ADDR_RSP_HANDLED_BY_APPLICATION displayZdoAddressResponse(zmBuf + SRSP_PAYLOAD_START); #endif } else { printf("Could not locate that device (Error Code 0x%02X)\r\n", result); } state = STATE_IDLE; break; } case STATE_FIND_VIA_LONG_ADDRESS: { printf("Looking for that device...\r\n"); moduleResult_t result = zdoNetworkAddressRequest(longAddressEntered, SINGLE_DEVICE_RESPONSE, 0); if (result == MODULE_SUCCESS) { #ifndef ZDO_NWK_ADDR_RSP_HANDLED_BY_APPLICATION displayZdoAddressResponse(zmBuf + SRSP_PAYLOAD_START); #endif } else { printf("Could not locate that device (Error Code 0x%02X)\r\n", result); } state = STATE_IDLE; break; } default: //should never happen { printf("UNKNOWN STATE (%u)\r\n", state); state = STATE_IDLE; } break; } } }
void stateMachine() { while (1) { if (zigbeeNetworkStatus == NWK_ONLINE) { if(moduleHasMessageWaiting()) //wait until SRDY goes low indicating a message has been received. { getMessage(); displayMessage(); } } switch (state) { case STATE_IDLE: { if (stateFlags & STATE_FLAG_SEND_INFO_MESSAGE) //if there is a pending info message to be sent { state = STATE_SEND_INFO_MESSAGE; //then send the message and clear the flag stateFlags &= ~STATE_FLAG_SEND_INFO_MESSAGE; } /* Other flags (for different messages or events) can be added here */ break; } case STATE_MODULE_STARTUP: { #define MODULE_START_DELAY_IF_FAIL_MS 5000 // Must be greater than MODULE_START_FAIL_LED_ONTIME moduleResult_t result; struct moduleConfiguration defaultConfiguration = DEFAULT_MODULE_CONFIGURATION_END_DEVICE; /* Uncomment below to restrict the device to a specific PANID defaultConfiguration.panId = 0x1234; */ struct applicationConfiguration endDeviceConf; endDeviceConf.endPoint = 1; endDeviceConf.latencyRequested = LATENCY_NORMAL; endDeviceConf.profileId = 0xcc00; // the clock profile is 0xCC00 endDeviceConf.deviceId = 0x8866; endDeviceConf.deviceVersion = 0x01; endDeviceConf.numberOfBindingInputClusters = 4; // number of binding input cluster endDeviceConf.bindingInputClusters[0] = 0x0000; // basic cluster endDeviceConf.bindingInputClusters[1] = 0x0003; // identify cluster endDeviceConf.bindingInputClusters[2] = 0xfc01; // synchronise clock cluster endDeviceConf.bindingInputClusters[3] = 0xfc02; // send string message cluster endDeviceConf.numberOfBindingOutputClusters = 4; // number of binding output cluster endDeviceConf.bindingOutputClusters[0] = 0x0000; endDeviceConf.bindingOutputClusters[1] = 0x0003; endDeviceConf.bindingOutputClusters[2] = 0xfc01; endDeviceConf.bindingOutputClusters[3] = 0xfc02; struct applicationConfiguration ac; ac.endPoint = 1; ac.deviceVersion = 0x10; ac.profileId = 0xfafa; ac.latencyRequested = LATENCY_NORMAL; ac.numberOfBindingInputClusters = 2; ac.bindingInputClusters[0] = 0x0000; ac.bindingInputClusters[1] = 0x0900; ac.numberOfBindingOutputClusters = 2; ac.bindingOutputClusters[0] = 0x0000; ac.bindingOutputClusters[1] = 0x0900; /* Below is an example of how to restrict the device to only one channel: defaultConfiguration.channelMask = CHANNEL_MASK_17; printf("DEMO - USING CUSTOM CHANNEL 17\r\n"); */ //while ((result = startModule(&defaultConfiguration, GENERIC_APPLICATION_CONFIGURATION)) != MODULE_SUCCESS) while ((result = startModule(&defaultConfiguration, &ac)) != MODULE_SUCCESS) { SET_NETWORK_FAILURE_LED_ON(); // Turn on the LED to show failure printf("FAILED. Error Code 0x%02X. Retrying...\r\n", result); delayMs(MODULE_START_DELAY_IF_FAIL_MS/2); SET_NETWORK_FAILURE_LED_OFF(); delayMs(MODULE_START_DELAY_IF_FAIL_MS/2); } INIT_BOOSTER_PACK_LEDS(); SET_NETWORK_LED_ON(); SET_NETWORK_FAILURE_LED_OFF(); printf("Success\r\n"); /* Module is now initialized so store MAC Address */ zbGetDeviceInfo(DIP_MAC_ADDRESS); memcpy(hdr.mac, zmBuf+SRSP_DIP_VALUE_FIELD, 8); #define MESSAGE_PERIOD_SECONDS 4 int16_t timerResult = initTimer(MESSAGE_PERIOD_SECONDS); if (timerResult != 0) { printf("timerResult Error %d, STOPPING\r\n", timerResult); while (1); } state = STATE_DISPLAY_NETWORK_INFORMATION; break; } case STATE_DISPLAY_NETWORK_INFORMATION: { printf("~ni~"); /* On network, display info about this network */ displayNetworkConfigurationParameters(); displayDeviceInformation(); /* Set module GPIOs as output and turn them off */ if ((sysGpio(GPIO_SET_DIRECTION, ALL_GPIO_PINS) != MODULE_SUCCESS) || (sysGpio(GPIO_CLEAR, ALL_GPIO_PINS) != MODULE_SUCCESS)) { printf("ERROR\r\n"); } state = STATE_SEND_INFO_MESSAGE; break; } case STATE_SEND_INFO_MESSAGE: { printf("~im~"); struct infoMessage im; /* See infoMessage.h for description of these info message fields.*/ im.header = hdr; im.deviceType = DEVICETYPE_TESLA_CONTROLS_END_DEVICE_DEMO; im.header.sequence = sequenceNumber++; im.numParameters = getSensorValues(im.kvps); // Does two things: Loads infoMessage with sensor value KVPs and gets the number of them // now, add status message interval im.kvps[im.numParameters].oid = OID_STATUS_MESSAGE_INTERVAL; im.kvps[im.numParameters].value = MESSAGE_PERIOD_SECONDS; im.numParameters++; // add zigbee module information: if (sysVersion() != MODULE_SUCCESS) { printf("ERROR retriving module information\r\n"); } else { displaySysVersion(); // Product ID im.kvps[im.numParameters].oid = OID_MODULE_PRODUCT_ID; im.kvps[im.numParameters].value = zmBuf[SYS_VERSION_RESULT_PRODUCTID_FIELD]; im.numParameters++; // FW - Major im.kvps[im.numParameters].oid = OID_MODULE_FIRMWARE_MAJOR; im.kvps[im.numParameters].value = zmBuf[SYS_VERSION_RESULT_FW_MAJOR_FIELD]; im.numParameters++; // FW - Minor im.kvps[im.numParameters].oid = OID_MODULE_FIRMWARE_MINOR; im.kvps[im.numParameters].value = zmBuf[SYS_VERSION_RESULT_FW_MINOR_FIELD]; im.numParameters++; // FW - Build im.kvps[im.numParameters].oid = OID_MODULE_FIRMWARE_BUILD; im.kvps[im.numParameters].value = zmBuf[SYS_VERSION_RESULT_FW_BUILD_FIELD]; im.numParameters++; } printInfoMessage(&im); #define RESTART_DELAY_IF_MESSAGE_FAIL_MS 5000 uint8_t messageBuffer[MAX_INFO_MESSAGE_SIZE]; serializeInfoMessage(&im, messageBuffer); setLed(SEND_MESSAGE_LED); //indicate that we are sending a message moduleResult_t result = afSendData(DEFAULT_ENDPOINT, DEFAULT_ENDPOINT, 0, INFO_MESSAGE_CLUSTER, messageBuffer, getSizeOfInfoMessage(&im)); // and send it clearLed(SEND_MESSAGE_LED); if (result != MODULE_SUCCESS) { zigbeeNetworkStatus = NWK_OFFLINE; printf("afSendData error %02X; restarting...\r\n", result); delayMs(RESTART_DELAY_IF_MESSAGE_FAIL_MS); //allow enough time for coordinator to fully restart, if that caused our problem state = STATE_MODULE_STARTUP; } else { printf("Success\r\n"); state = STATE_IDLE; } break; } default: //should never happen { printf("UNKNOWN STATE\r\n"); state = STATE_MODULE_STARTUP; } break; } } }
/** The main state machine for the application. Never exits. */ void stateMachine() { // while (1) // { if (zigbeeNetworkStatus == NWK_ONLINE) { if(moduleHasMessageWaiting()) //wait until SRDY goes low indicating a message has been received. stateFlags |= STATE_FLAG_MESSAGE_WAITING; } switch (state) { case STATE_IDLE: { if (stateFlags & STATE_FLAG_MESSAGE_WAITING & coordinator_on) // If there is a message waiting... { parseMessages(); // ... then display it trackingStateMachine(current_router_index); stateFlags &= ~STATE_FLAG_MESSAGE_WAITING; } if (stateFlags & STATE_FLAG_BUTTON_PRESSED) // If ISR set this flag... { if (debounceButton(ANY_BUTTON)) // ...then debounce it { processButtonPress(); // ...and process it } if (debounceButtonHold(ANY_BUTTON)) { processButtonHold(); } stateFlags &= ~STATE_FLAG_BUTTON_PRESSED; } /* Other flags (for different messages or events) can be added here */ break; } case STATE_MODULE_STARTUP: // Start the Zigbee Module on the network { #define MODULE_START_DELAY_IF_FAIL_MS 5000 moduleResult_t result; struct moduleConfiguration defaultConfiguration = DEFAULT_MODULE_CONFIGURATION_COORDINATOR; /* Uncomment below to restrict the device to a specific PANID defaultConfiguration.panId = 0x1234; */ /* Below is an example of how to restrict the device to only one channel: defaultConfiguration.channelMask = CHANNEL_MASK_17; printf("DEMO - USING CUSTOM CHANNEL 17\r\n"); */ while ((result = startModule(&defaultConfiguration, GENERIC_APPLICATION_CONFIGURATION)) != MODULE_SUCCESS) { printf("FAILED. Error Code 0x%02X. Retrying...\r\n", result); delayMs(MODULE_START_DELAY_IF_FAIL_MS); } //printf("Success\r\n"); zigbeeNetworkStatus = NWK_ONLINE; state = STATE_DISPLAY_NETWORK_INFORMATION; break; } case STATE_DISPLAY_NETWORK_INFORMATION: { printf("~ni~"); /* On network, display info about this network */ displayNetworkConfigurationParameters(); displayDeviceInformation(); if (sysGpio(GPIO_SET_DIRECTION, ALL_GPIO_PINS) != MODULE_SUCCESS) //Set module GPIOs as output { printf("ERROR\r\n"); } /* printf("Press button to change which received value is displayed on RGB LED. D6 & D5 will indicate mode:\r\n"); printf(" None = None\r\n"); printf(" Yellow (D9) = IR Temp Sensor\r\n"); printf(" Red (D8) = Color Sensor\r\n"); */ printf("Displaying Messages Received\r\n"); setModuleLeds(RGB_LED_DISPLAY_MODE_NONE); /* Now the network is running - wait for any received messages from the ZM */ #ifdef VERBOSE_MESSAGE_DISPLAY printAfIncomingMsgHeaderNames(); #endif state = STATE_IDLE; break; } default: //should never happen { printf("UNKNOWN STATE\r\n"); state = STATE_MODULE_STARTUP; } break; } // } }
void setPinModeHardwarePWM(int pin, int period, int term, unsigned long length) { if (pin >= 0 && pin < NUM_DIGITAL_PINS) { int port = digitalPinToPort(pin); if (port == NOT_A_PIN) { return; } int bit = digitalPinToBit(pin); int tpsc = 0b10; // PCLK/16 switch (pin) { case PIN_IO1: startModule(MstpIdTPU3); assignPinFunction(pin, 0b00011, 0, 0); BSET(portModeRegister(port), bit); TPUA.TSTR.BIT.CST3 = 0; TPU3.TCR.BIT.TPSC = tpsc; TPU3.TCR.BIT.CCLR = 0b010; TPU3.TCR.BIT.CKEG = 0b01; TPU3.TMDR.BIT.MD = 0b0011; changePinModeHardwarePWM(pin, period, term, length); TPUA.TSTR.BIT.CST3 = 1; break; case PIN_IO0: startModule(MstpIdMTU1); assignPinFunction(pin, 0b00001, 0, 0); BSET(portModeRegister(port), bit); MTU.TSTR.BIT.CST1 = 0; MTU1.TCR.BIT.TPSC = tpsc; MTU1.TCR.BIT.CCLR = 0b001; MTU1.TCR.BIT.CKEG = 0b01; MTU1.TMDR.BIT.MD = 0b0010; changePinModeHardwarePWM(pin, period, term, length); MTU.TSTR.BIT.CST1 = 1; break; case PIN_IO28: startModule(MstpIdTPU3); assignPinFunction(pin, 0b00011, 0, 0); BSET(portModeRegister(port), bit); TPUA.TSTR.BIT.CST3 = 0; TPU3.TCR.BIT.TPSC = tpsc; TPU3.TCR.BIT.CCLR = 0b010; TPU3.TCR.BIT.CKEG = 0b01; TPU3.TMDR.BIT.MD = 0b0011; changePinModeHardwarePWM(pin, period, term, length); TPUA.TSTR.BIT.CST3 = 1; break; case PIN_IO29: startModule(MstpIdTPU3); assignPinFunction(pin, 0b00011, 0, 0); BSET(portModeRegister(port), bit); TPUA.TSTR.BIT.CST3 = 0; TPU3.TCR.BIT.TPSC = tpsc; TPU3.TCR.BIT.CCLR = 0b010; TPU3.TCR.BIT.CKEG = 0b01; TPU3.TMDR.BIT.MD = 0b0011; changePinModeHardwarePWM(pin, period, term, length); TPUA.TSTR.BIT.CST3 = 1; break; case PIN_IO32: startModule(MstpIdMTU4); assignPinFunction(pin, 0b00001, 0, 0); BSET(portModeRegister(port), bit); MTU.TSTR.BIT.CST4 = 0; MTU.TOER.BIT.OE4A = 1; MTU4.TCR.BIT.TPSC = tpsc; MTU4.TCR.BIT.CCLR = 0b001; MTU4.TCR.BIT.CKEG = 0b01; MTU4.TMDR.BIT.MD = 0b0010; changePinModeHardwarePWM(pin, period, term, length); MTU.TSTR.BIT.CST4 = 1; break; case PIN_IO5: //IO5 is connected to IO23(P25), that enables hwPwm. // TIOCA4 startModule(MstpIdTPU4); pin = PIN_IO23; // for multiple connection assignPinFunction(pin, 0b00011, 0, 0); port = digitalPinToPort(pin); // for multiple connection bit = digitalPinToBit(pin); BSET(portModeRegister(port), bit); TPUA.TSTR.BIT.CST4 = 0; TPU4.TCR.BIT.TPSC = tpsc; TPU4.TCR.BIT.CCLR = 0b001; TPU4.TCR.BIT.CKEG = 0b01; TPU4.TMDR.BIT.MD = 0b0010; changePinModeHardwarePWM(pin, period, term, length); TPUA.TSTR.BIT.CST4 = 1; break; case PIN_IO7: startModule(MstpIdTPU0); assignPinFunction(pin, 0b00011, 0, 0); BSET(portModeRegister(port), bit); TPUA.TSTR.BIT.CST0 = 0; TPU0.TCR.BIT.TPSC = tpsc; TPU0.TCR.BIT.CCLR = 0b001; TPU0.TCR.BIT.CKEG = 0b01; TPU0.TMDR.BIT.MD = 0b0011; changePinModeHardwarePWM(pin, period, term, length); TPUA.TSTR.BIT.CST0 = 1; break; case PIN_IO8: startModule(MstpIdTPU0); assignPinFunction(pin, 0b00011, 0, 0); BSET(portModeRegister(port), bit); TPUA.TSTR.BIT.CST0 = 0; TPU0.TCR.BIT.TPSC = tpsc; TPU0.TCR.BIT.CCLR = 0b001; TPU0.TCR.BIT.CKEG = 0b01; TPU0.TMDR.BIT.MD = 0b0011; changePinModeHardwarePWM(pin, period, term, length); TPUA.TSTR.BIT.CST0 = 1; break; case PIN_IO11: startModule(MstpIdMTU3); assignPinFunction(pin, 0b00001, 0, 0); BSET(portModeRegister(port), bit); MTU.TSTR.BIT.CST3 = 0; MTU3.TCR.BIT.TPSC = tpsc; MTU3.TCR.BIT.CCLR = 0b101; MTU3.TCR.BIT.CKEG = 0b01; MTU3.TMDR.BIT.MD = 0b0010; changePinModeHardwarePWM(pin, period, term, length); MTU.TSTR.BIT.CST3 = 1; break; } } }
// Called when a module is found void ICQMain::sectionParsed(Profile *prof) { startModule(prof); }