void EScale::run() { bool ret; isRun = true; Dev = new QSerialPort; INIT: if (!isRun) goto EXIT; if (!devInit("COM9")) { msleep(200); goto INIT; } while (isRun) { ReadWeight(); msleep(500); } EXIT: Dev->close(); delete Dev; Dev = NULL; }
void devRestart() { if (is_simulator()) return; /* #ifdef WINDOWSPC static bool first = true; if (!first) { NMEAParser::Reset(); return; } first = false; #endif */ StartupStore(TEXT("RestartCommPorts\n")); mutexComm.Lock(); devShutdown(); NMEAParser::Reset(); devInit(TEXT("")); mutexComm.Unlock(); }
/* AppWarmStart(): * This function is provided to allow the application to partially * restart the monitor. It supports the situation where an application * run but the monitor has not already been initialized. This would be * the case if some type of debugger (JTAG or BDM probably) was attached * to the target and it was used to download and run the application. * If this type of debug connection does not support the ability to run * after the monitor runs, then the application must be able to somehow * get the monitor initialized without having it go through a complete * warmstart. * This will only run through the stack space provided by the application. */ void AppWarmStart(ulong mask) { /* First initialize monitor bss space (skipping over MonStack[]): */ if(mask & WARMSTART_BSSINIT) { umonBssInit(); } StateOfMonitor = INITIALIZE; /* Initialize some of the real fundamental stuff regardless of * the incoming mask. */ init0(); /* Subset of init1(): */ if(mask & WARMSTART_IOINIT) { initCPUio(); InitRemoteIO(); if(ConsoleBaudRate == 0) { ConsoleBaudRate = DEFAULT_BAUD_RATE; } devInit(ConsoleBaudRate); } init2(); _init3(mask); }
void usrIosExtraInit (void) { excShowInit (); /* exception show routines */ jobLibInit (JOB_TASK_STACK_SIZE); /* miscellaneous support task */ excInit (MAX_ISR_JOBS); /* interrupt-level job facility */ logInit (consoleFd, MAX_LOG_MSGS); /* message logging */ nbioLogInit (consoleFd, INIT_NBIO_MSGS); /* non-blocking message logging */ pipeDrv (); /* pipes */ aioPxLibInit (MAX_LIO_CALLS); /* POSIX asynchronous IO */ aioSysInit (MAX_AIO_SYS_TASKS, AIO_TASK_PRIORITY, AIO_TASK_STACK_SIZE); /* provides AIO functionality to non-AIO drivers */ stdioInit (); /* buffered IO library */ fioLibInit (); /* formatting for printf, scanf, etc. */ floatInit (); /* allow printf and others to format floats correctly */ erfLibInit (ERF_MAX_USR_CATEGORIES, ERF_MAX_USR_TYPES); /* Event Reporting Framework */ devInit (DEVICE_MANAGER_MAX_NUM_DEVICES); /* Device Manager */ xbdInit (); /* Extended Block Device */ fsMonitorInit (); /* File System Monitor */ fsEventUtilLibInit (); /* File System Event Utilities */ rawFsInit (NUM_RAWFS_FILES); /* Raw block device file system interface */ ptyDrv (); /* Allows communication between processes */ usrRomfsConfig (); /* Read-only memory based file system */ xbdRamDiskDevCreate (RAM_DISK_BLK_SIZE, RAM_DISK_SIZE, FALSE, RAM_DISK_DEV_NAME); /* Create an XBD based RAM disk */ usrBootLineParse (BOOT_LINE_ADRS); /* parse some boot device configuration info */ usrPassFsInit (PASSFS_CACHE); /* direct access to host filesystem */ virtualDiskInit (); /* VxSim virtual disk to emulate a VxWorks disk driver. */ }
BOOLEAN BASE_init(void) { devInit(); rwibase_handlers = CreateHandlerList(BASE_NUMBER_EVENTS); if(InitDevice()) { InitBase(); BASE_Halt(); // BASE_TranslateVelocity(init_trans_speed); // BASE_RotateVelocity(init_rot_speed); BASE_reset(); BASE_EnableStopWhenBump(); return TRUE; } else return FALSE; }
/* init1(): * This is the first level of initialization (aside from the most fundamental * stuff that must be done in reset.s) that is done after the system resets. */ void init1(void) { initCPUio(); /* Configure all chip-selects, parallel IO * direction registers, etc... This may have * been done already in reset.s */ vinit(); /* Initialize the CPU's vector table. */ InitRemoteIO(); /* Initialize all application-settable IO functions */ if(ConsoleBaudRate == 0) { ConsoleBaudRate = DEFAULT_BAUD_RATE; } devInit(ConsoleBaudRate); }
/*------------------------------------------------------------------- main(): This main is for device including the audio/hid/dfu -------------------------------------------------------------------*/ void main() { INIT_GPIO(); TxPoweredUp = FALSE; FePoweredUp = FALSE; #ifdef _DEBUG_RESET_ FalseReset = 0; #endif // Give the XRAM time to powered up as the MCU of the emulator is faster #ifdef _EMULATOR_ delay(80); GLOBCTL = GLOBCTL_INIT; delay(100); #else GLOBCTL = GLOBCTL_INIT; #endif // ROM code using PDATA starting at 0xFA00 P2 = 0xFA; RomRecord.state = ROM_APP_RUNNING; devInit(); // using ROM DFU handler devRomFunction(ROM_INIT_DFU_STATE); // using ROM USB engine USBENGINE_EP0_SIZE = DEV_MAX_EP0_PKT; devRomFunction(ROM_ENG_USB_INIT); // wait till codec inited (USB Host must select device configuration) while (AppDevice.configSetting == 0 && asq_delayed < 20000) { devCheckReset(); asq_delayed++; } //#define NO_ANALOG #ifdef NO_ANALOG if(asq_delayed == 20000) AppDeviceAnalogMode=TRUE; #else while (AppDevice.configSetting == 0) devCheckReset(); #endif usb_pc_answered: asq_delayed=0; // Take Codec (Si471x) out of reset si47xxReset(); // Turn on status LED //USBLed = LED_ON; /* start transmitter, if eeprom says yes */ if(configCheckStartupNeeded()) { if(!si47xxPowerUp() || !si47xxFMTX_hardware_cfg() || !configSetStartupConfig()) { si47xxReset(); } else { /* if we started stand-alone (out-of PC), just loop here infinetily */ while(AppDeviceAnalogMode) { READ_ASQ_STATUS(); if(AppDevice.configSetting == 0) { devCheckReset(); } else { //we have answer from PC (usb devce connected...) AppDeviceAnalogMode=FALSE; goto usb_pc_answered; } } } } AppResetFlag = FALSE; AppSuspendFlag = FALSE; SpkEnOut = 0; while(1) { // For DFU mode if (RomRecord.state == ROM_DFU_MODE) { // Setup for reenumeration // as device in DFU mode USBCTL = 0; USBFADR = 0; PARAMS_DFU_SETUP(DFU_TARGET_EEPROM, 0); // this is for testing DFU_TARGET_OTHER // DevTestDfuDataPtr = (unsigned char xdata *)0x6000; devRomFunction(ROM_RUN_DFU_MODE); } devCheckReset(); devUpdateCodec(); #if 1 // Handle SUSPENSE/RESUME if ((AppSuspendFlag == TRUE) && (AppResetFlag == FALSE)) { devSleepModeOn(); #ifndef _EMULATOR_ PCON = 0x09; #endif while (AppSuspendFlag == TRUE); devSleepModeOff(); // Delay a bit (approx. 5 ms) to account for button debounce // if it was used to do a remote wake up. delay(20); } else { HID_ACCESS(); //get HID report from PC & write to SI4711 READ_ASQ_STATUS(); } #else HID_ACCESS(); //get HID report from PC & write to SI4711 #endif } return; // Just a dummy code to force the compiler to keep // DevFunctionEntryParser() in the final codes DevFunctionEntryParser(0, 0); }
void devStartup(LPTSTR lpCmdLine) { StartupStore(TEXT("Register serial devices\n")); devInit(lpCmdLine); }
BOOL devInit(LPTSTR CommandLine){ int i; TCHAR DeviceName[DEVNAMESIZE+1]; PDeviceDescriptor_t pDevNmeaOut = NULL; static bool doinit=true; for (i=0; i<NUMDEV; i++){ DeviceList[i].Port = -1; DeviceList[i].fhLogFile = NULL; DeviceList[i].Name[0] = '\0'; DeviceList[i].ParseNMEA = NULL; DeviceList[i].PutMacCready = NULL; DeviceList[i].DirectLink = NULL; DeviceList[i].PutBugs = NULL; DeviceList[i].PutBallast = NULL; DeviceList[i].Open = NULL; DeviceList[i].Close = NULL; DeviceList[i].Init = NULL; DeviceList[i].LinkTimeout = NULL; DeviceList[i].Declare = NULL; DeviceList[i].IsLogger = devIsFalseReturn; DeviceList[i].IsGPSSource = devIsFalseReturn; DeviceList[i].IsBaroSource = devIsFalseReturn; DeviceList[i].IsRadio = devIsFalseReturn; DeviceList[i].PutVoice = (int (*)(struct DeviceDescriptor_t *,TCHAR *))devIsFalseReturn; DeviceList[i].PortNumber = i; DeviceList[i].PutQNH = NULL; DeviceList[i].OnSysTicker = NULL; DeviceList[i].pDevPipeTo = NULL; DeviceList[i].PutVolume = NULL; DeviceList[i].PutFreqActive = NULL; DeviceList[i].PutFreqStandby = NULL; DeviceList[i].IsCondor = devIsFalseReturn; DeviceList[i].Disabled = true; ComPortStatus[i]=CPS_UNUSED; // 100210 ComPortHB[i]=0; // counter if (doinit) { ComPortRx[i]=0; ComPortTx[i]=0; ComPortErrTx[i]=0; ComPortErrRx[i]=0; ComPortErrors[i]=0; doinit=false; } } pDevPrimaryBaroSource = NULL; pDevSecondaryBaroSource=NULL; ReadDeviceSettings(0, DeviceName); #ifdef DEBUG_DEVSETTING StartupStore(_T(".......... ReadDeviceSetting 0, DeviceName=<%s>\n"),DeviceName); #endif PortIndex1 = 0; SpeedIndex1 = 2; Bit1Index=(BitIndex_t)bit8N1; ReadPort1Settings(&PortIndex1,&SpeedIndex1,&Bit1Index); //if (_tcslen(DeviceName)>0) // removed 110530 if (wcscmp(DeviceName,_T(DEV_DISABLED_NAME))!=0) { DeviceList[0].Disabled=false; StartupStore(_T(". Device A is <%s> Port=%s%s"),DeviceName,COMMPort[PortIndex1],NEWLINE); } else { DeviceList[0].Disabled=true; StartupStore(_T(". Device A is DISABLED.%s"),NEWLINE); } for (i=DeviceRegisterCount-1; i>=0; i--) { if (DeviceList[0].Disabled) break; if ((_tcscmp(DeviceRegister[i].Name, DeviceName) == 0)) { ComPort *Com = new ComPort(0); // remember: Port1 is the port used by device A, port1 may be Com3 or Com1 etc // this is port 1, so index 0 for us. if (!Com->Initialize(COMMPort[PortIndex1], dwSpeed[SpeedIndex1],Bit1Index,0)) { delete Com; ComPortStatus[0]=CPS_OPENKO; break; } ComPortStatus[0]=CPS_OPENOK; DeviceRegister[i].Installer(devA()); if ((pDevNmeaOut == NULL) && (DeviceRegister[i].Flags & (1l << dfNmeaOut))){ pDevNmeaOut = devA(); } devA()->Com = Com; devInit(devA()); devOpen(devA(), 0); if (devIsBaroSource(devA())) { if (pDevPrimaryBaroSource == NULL){ pDevPrimaryBaroSource = devA(); } else if (pDevSecondaryBaroSource == NULL){ pDevSecondaryBaroSource = devA(); } } break; } } ReadDeviceSettings(1, DeviceName); #ifdef DEBUG_DEVSETTING StartupStore(_T(".......... ReadDeviceSetting 1, DeviceName=<%s>\n"),DeviceName); #endif PortIndex2 = 0; SpeedIndex2 = 2, Bit2Index=(BitIndex_t)bit8N1; ReadPort2Settings(&PortIndex2,&SpeedIndex2, &Bit2Index); //if (_tcslen(DeviceName)>0) // removed 110530 if (wcscmp(DeviceName,_T(DEV_DISABLED_NAME))!=0) { DeviceList[1].Disabled=false; StartupStore(_T(". Device B is <%s> Port=%s%s"),DeviceName,COMMPort[PortIndex2],NEWLINE); } else { DeviceList[1].Disabled=true; StartupStore(_T(". Device B is DISABLED.%s"),NEWLINE); } for (i=DeviceRegisterCount-1; i>=0; i--) { if (PortIndex1 == PortIndex2) break; if (DeviceList[1].Disabled) break; if ((_tcscmp(DeviceRegister[i].Name, DeviceName) == 0)) { ComPort *Com = new ComPort(1); // this is port 2, so index 1 for us if (!Com->Initialize(COMMPort[PortIndex2], dwSpeed[SpeedIndex2],Bit2Index,1)) { // 100210 delete Com; ComPortStatus[1]=CPS_OPENKO; break; } ComPortStatus[1]=CPS_OPENOK; DeviceRegister[i].Installer(devB()); if ((pDevNmeaOut == NULL) && (DeviceRegister[i].Flags & (1l << dfNmeaOut))){ pDevNmeaOut = devB(); } devB()->Com = Com; devInit(devB()); devOpen(devB(), 1); if (devIsBaroSource(devB())) { if (pDevPrimaryBaroSource == NULL){ pDevPrimaryBaroSource = devB(); } else if (pDevSecondaryBaroSource == NULL){ pDevSecondaryBaroSource = devB(); } } break; } } if (pDevNmeaOut != NULL){ if (pDevNmeaOut == devA()){ devB()->pDevPipeTo = devA(); } if (pDevNmeaOut == devB()){ devA()->pDevPipeTo = devB(); } } return(TRUE); }
BOOL devInit(LPCTSTR CommandLine) { TCHAR DeviceName[DEVNAMESIZE + 1]; PDeviceDescriptor_t pDevNmeaOut = NULL; TCHAR Port[MAX_PATH] = {_T('\0')}; DWORD SpeedIndex = 2; DWORD BitIndex = (BitIndex_t) bit8N1; static bool doinit = true; pDevPrimaryBaroSource = NULL; pDevSecondaryBaroSource = NULL; std::set<std::wstring> UsedPort; // list of already used port for (unsigned i = 0; i < NUMDEV; i++) { DeviceList[i].InitStruct(i); ComPortStatus[i] = CPS_UNUSED; // 100210 ComPortHB[i] = 0; // counter if (doinit) { ComPortRx[i] = 0; ComPortTx[i] = 0; ComPortErrTx[i] = 0; ComPortErrRx[i] = 0; ComPortErrors[i] = 0; doinit = false; } if (SIMMODE){ continue; } ReadDeviceSettings(i, DeviceName); DeviceList[i].Disabled = (wcscmp(DeviceName, _T(DEV_DISABLED_NAME)) == 0); if (DeviceList[i].Disabled) { StartupStore(_T(". Device %c is DISABLED.%s"), (_T('A') + i), NEWLINE); continue; } DeviceRegister_t* pDev = std::find_if(&DeviceRegister[0], &DeviceRegister[DeviceRegisterCount], devNameCompare(DeviceName)); if (pDev == &DeviceRegister[DeviceRegisterCount]) { DeviceList[i].Disabled = true; StartupStore(_T(". Device %c : invalide drivers name <%s>%s"), (_T('A') + i), DeviceName, NEWLINE); continue; } if(_tcscmp(pDev->Name,TEXT("Internal")) == 0) { _tcscpy(Port, _T("GPSID")); } else { Port[0] = _T('\0'); SpeedIndex = 2; BitIndex = (BitIndex_t) bit8N1; ReadPortSettings(i, Port, &SpeedIndex, &BitIndex); } // remember: Port1 is the port used by device A, port1 may be Com3 or Com1 etc if(std::find(UsedPort.begin(), UsedPort.end(), Port) != UsedPort.end()) { StartupStore(_T(". Port <%s> Already used, Device %c Disabled ! %s"), Port, (_T('A') + i), NEWLINE); continue; } UsedPort.insert(Port); // remember: Port1 is the port used by device A, port1 may be Com3 or Com1 etc StartupStore(_T(". Device %c is <%s> Port=%s%s"), (_T('A') + i), DeviceName, Port, NEWLINE); ComPort *Com = NULL; if (_tcsncmp(Port, _T("BT:"), 3) == 0) { CBtHandler* pBtHandler = CBtHandler::Get(); StartupStore(_T(".. Initialise Bluetooth Device %s%s"), Port, NEWLINE); if (pBtHandler && pBtHandler->IsOk()) { if (pBtHandler->StartHW()) { Com = new BthPort(i, &Port[3]); } } } else if (_tcscmp(Port, _T("GPSID")) == 0) { Com = new GpsIdPort(i, Port); } else { Com = new SerialPort(i, Port, dwSpeed[SpeedIndex], (BitIndex_t)BitIndex, PollingMode); } if (Com && Com->Initialize()) { ComPortStatus[i] = CPS_OPENOK; pDev->Installer(&DeviceList[i]); if ((pDevNmeaOut == NULL) && (pDev->Flags & (1l << dfNmeaOut))) { pDevNmeaOut = &DeviceList[i]; } DeviceList[i].Com = Com; devInit(&DeviceList[i]); devOpen(&DeviceList[i], i); if (devIsBaroSource(&DeviceList[i])) { if (pDevPrimaryBaroSource == NULL) { pDevPrimaryBaroSource = &DeviceList[i]; } else if (pDevSecondaryBaroSource == NULL) { pDevSecondaryBaroSource = &DeviceList[i]; } } } else { delete Com; ComPortStatus[i] = CPS_OPENKO; } } if (pDevNmeaOut != NULL) { if (pDevNmeaOut == devA()) { devB()->pDevPipeTo = devA(); } if (pDevNmeaOut == devB()) { devA()->pDevPipeTo = devB(); } } return (TRUE); }