static void setupHardware(void) { // TODO: Put hardware configuration and initialisation in here SystemInit(); resetGPIO(); setInput_P2(); ADCInit(ADC_CLK); //resetto il termometro pinMode(OUTPUT); digitalWrite(HIGH); Initial_Hardware(); //init lcd hardware Initial_GLCD_Hor(); //init lcd "software" bg_color(BLACK); int sto_premendo = 0; eMBErrorCode eStatus; eStatus = eMBInit( MB_RTU, 0x0A, 0, 38400, MB_PAR_NONE ); /* Initialize the holding register values before starting the * Modbus stack */ int i; for( i = 0; i < REG_HOLDING_NREGS; i++ ) { usRegHoldingBuf[i] = 0; } sensors.distance1 = 1; sensors.distance2 = 2; sensors.lumino = 3; sensors.mic = 4; sensors.vibro = 5; actual_DHT11.humidity = 666; actual_DHT11.temperature = 666; //associo ai registri holding il valore dei sensori *(usRegHoldingBuf ) = (USHORT *) &sensors.distance1; *(usRegHoldingBuf + 1 ) = (USHORT *) &sensors.distance2; *(usRegHoldingBuf + 2 ) = (USHORT *) &sensors.lumino; *(usRegHoldingBuf + 3 ) = (USHORT *) &sensors.mic; *(usRegHoldingBuf + 4 ) = (USHORT *) &sensors.vibro; *(usRegHoldingBuf + 5 ) = (USHORT *) &actual_DHT11.humidity; *(usRegHoldingBuf + 6 ) = (USHORT *) &actual_DHT11.temperature; /* Enable the Modbus Protocol Stack. */ eStatus = eMBEnable( ); // Warning: If you do not initialize the hardware clock, the timings will be inaccurate }
void ProgramSenoko::runTest() { QProcess stm32flash; int tries; if (prepGPIO()) { testError("Unable to set up reset GPIO"); return; } testInfo("Please hold the \"Reflash\" button on Senoko"); /* Wait for the flashing process to start */ while (1) { bool foundBanner = false; /* This string is the last thing to appear before programming starts */ const char *searchString = "Serial Config: 115200 8E1"; testDebug("Trying to initiate upload..."); resetGPIO(); stm32flash.terminate(); stm32flash.setProcessChannelMode(QProcess::MergedChannels); stm32flash.start("/factory/stm32flash", QStringList() << "-b" << "115200" << "-w" << firmware << "/dev/ttymxc3"); stm32flash.waitForStarted(); tries = 0; while (!foundBanner && (tries++ < 10)) { if (!stm32flash.waitForReadyRead(1000)) { testDebug("Process wasn't ready for read in 1 second"); break; } QByteArray output = stm32flash.readLine(); testDebug(QString("Output string: ") + output); if (stm32flash.state() != QProcess::Running) { testDebug("Process no longer running"); break; } if (output.startsWith(searchString)) { testDebug("Found search string"); foundBanner = true; } else { testDebug(QString("Line doesn't contain string %1: %2").arg(searchString).arg((const char *)output)); } } if (!foundBanner) { testDebug("Didn't find banner"); continue; } if (!stm32flash.waitForReadyRead(1000)) { testDebug("Didn't find data after 1 second"); continue; } break; } testInfo("Upload started, release the \"Reflash\" button"); if (!stm32flash.waitForFinished(60000)) { testError("Flashing process took too long"); testError(stm32flash.readAllStandardOutput()); return; } testInfo("Senoko reflashed successfully"); resetGPIO(); testInfo("Attempting to rescan device bus"); QFile autoprobeFile("/sys/bus/platform/drivers_autoprobe"); if (!autoprobeFile.open(QIODevice::WriteOnly)) { testError(QString() + "Unable to open platform/drivers_autoprobe file: " + autoprobeFile.errorString()); return; } autoprobeFile.write("1\n"); autoprobeFile.close(); sleep(1); }