status_t device_node::Reprobe() { status_t status = InitDriver(); if (status < B_OK) return status; MethodDeleter<device_node, bool> uninit(this, &device_node::UninitDriver); // If this child has been probed already, probe it again status = _Probe(); if (status != B_OK) return status; NodeList::Iterator iterator = fChildren.GetIterator(); while (iterator.HasNext()) { device_node* child = iterator.Next(); status = child->Reprobe(); if (status != B_OK) return status; } return B_OK; }
status_t device_node::Rescan() { status_t status = InitDriver(); if (status < B_OK) return status; MethodDeleter<device_node, bool> uninit(this, &device_node::UninitDriver); if (DriverModule()->rescan_child_devices != NULL) { status = DriverModule()->rescan_child_devices(DriverData()); if (status != B_OK) return status; } NodeList::Iterator iterator = fChildren.GetIterator(); while (iterator.HasNext()) { device_node* child = iterator.Next(); status = child->Rescan(); if (status != B_OK) return status; } return B_OK; }
void init_graphics2() { memset((void *)(0x90000000), 0, my_lcd_config.virtual_xres * my_lcd_config.virtual_yres * my_lcd_config.pixelsize / 8); lcd_on(); init_gdi_driver(&my_lcd_config); SetLCD_Conf(&my_lcd_config); InitDriver(); setDevice(1); //change gotoXY(0,0); };
//Function to load the driver DWORD TDriver::LoadDriver(LPCTSTR path, BOOL start) { //first initialized it DWORD retCode = InitDriver(path); //then load if(retCode == DRV_SUCCESS) retCode = LoadDriver(start); return retCode; }
int Init (const char * driverPath) { BOOL ret = FALSE; if (InitDriver () == FALSE) { if (strlen (driverPath)) { StartStopService ("r2k",TRUE); RemoveService ("r2k"); eprintf ("Installing driver: %s\n", driverPath); if (InstallService (driverPath, "r2k", "r2k")) { StartStopService ("r2k",FALSE); ret = InitDriver (); } } else { eprintf ("Error initalizating driver, try r2k://pathtodriver\nEx: radare2.exe r2k://c:\\r2k.sys"); } } else { eprintf ("Driver present [OK]\n"); ret = TRUE; } return ret; }
bool AudioDriver::Init() { // Clear all buffers for (int i=0;i<SOUND_BUFFER_COUNT;i++) { pool_[i].buffer_=0 ; pool_[i].size_=0 ; } ; isPlaying_=false; return InitDriver() ; }
//Function to Load the driver. DWORD TDriver::LoadDriver(LPCTSTR name, LPCTSTR path, LPCTSTR dosName, BOOL start) { //first initialized it DWORD retCode = InitDriver(name, path, dosName); //then load if(retCode == DRV_SUCCESS) { retCode = LoadDriver(start); } return(retCode); }
void* CPEEntry(void* para) { InitDriver(); ModCol.LoadModule(); pthread_t thr1; for(int i=0; i<ModCol.MAX_ModuleCollection; i++) { //create thread ModCol[i]->iInterface.Init(0); pthread_create(&thr1, NULL, ModCol[i]->iInterface.CPEThread, NULL); } return 0; }
static int AutoSelectDriver(unsigned int port_base) { int i; for (i=0; drivers[i] != NULL; ++i) { if (InitDriver(drivers[i], port_base)) { return 1; } } C_Printf("OPL_Init: Failed to find a working driver.\n"); return 0; }
OpenSoundDevice::OpenSoundDevice(oss_card_info *cardinfo) : fLocker("OpenSoundDevice") { CALLED(); fInitCheckStatus = B_NO_INIT; memcpy(&fCardInfo, cardinfo, sizeof(oss_card_info)); memset(&fFragments, 0, sizeof(fFragments)); #if 0 strcpy(fDevice_name, name); strcpy(fDevice_path, path); PRINT(("name : %s, path : %s\n", fDevice_name, fDevice_path)); if (InitDriver() != B_OK) return; fInitCheckStatus = B_OK; #endif }
int OPL_Init(unsigned int port_base) { char *driver_name; int i; driver_name = getenv("OPL_DRIVER"); if (driver_name != NULL) { // Search the list until we find the driver with this name. for (i=0; drivers[i] != NULL; ++i) { if (!strcmp(driver_name, drivers[i]->name)) { if (InitDriver(drivers[i], port_base)) { return 1; } else { C_Printf("OPL_Init: Failed to initialize " "driver: '%s'.\n", driver_name); return 0; } } } C_Printf("OPL_Init: unknown driver: '%s'.\n", driver_name); return 0; } else { return AutoSelectDriver(port_base); } }
extern "C" NTSTATUS DriverEntry (IN PDRIVER_OBJECT pDriverObject,IN PUNICODE_STRING /*pRegistryPath*/ ) { KdPrint(("DriverEntry begin\n")); NTSTATUS status; //注册设备卸载例程 pDriverObject->DriverUnload = UnloadDevice; ////注册irp例程 pDriverObject->MajorFunction[IRP_MJ_CREATE] = CreateDispatchRoutine; pDriverObject->MajorFunction[IRP_MJ_CLOSE] = CloseDispatchRoutine; //pDriverObject->MajorFunction[IRP_MJ_WRITE] = DispatchRoutine; //pDriverObject->MajorFunction[IRP_MJ_READ] = DispatchRoutine; pDriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = ControlDispatchRoutine; //创建驱动设备对象 status = CreateDevice(pDriverObject); //初始化自定义代码 InitDriver(); KdPrint(("DriverEntry end\n")); return status; }
//**************************************************************************** // //! Task function implements the Antenna Selection functionality //! //! \param none //! //! This function //! 1. Starts Device in STA Mode //! 2. Scans, Sort and Stores all the AP with Antenna 1 //! 3. Scans, Sort and Stores all the AP with Antenna 2 //! 4. Switch to AP Mode and Wait for AP Configuration from Browser //! 5. Switch to STA Mode and Connect to Configured AP with Selected Antenna //! //! \return None. // //**************************************************************************** void AntennaSelection(void* pTaskParams) { int iDeviceMode = 0; unsigned char ucCountSSID; unsigned char ucCountSSIDAnt2; long lRetVal = -1; InitializeAppVariables(); // // Following function configure the device to default state by cleaning // the persistent settings stored in NVMEM (viz. connection profiles & // policies, power policy etc) // // Applications may choose to skip this step if the developer is sure // that the device is in its default state at start of applicaton // // Note that all profiles and persistent settings that were done on the // device will be lost // lRetVal = ConfigureSimpleLinkToDefaultState(); if(lRetVal < 0) { if (DEVICE_NOT_IN_STATION_MODE == lRetVal) { UART_PRINT("Failed to configure the device in its default state\n\r"); } LOOP_FOREVER(__LINE__); } UART_PRINT("Device is configured in default state \n\r"); // // Assumption is that the device is configured in station mode already // and it is in its default state // lRetVal = sl_Start(0, 0, 0); if (lRetVal < 0 || ROLE_STA != lRetVal) { UART_PRINT("Failed to start the device \n\r"); LOOP_FOREVER(__LINE__); } UART_PRINT("Device started as STATION \n\r"); // // Start the driver // iDeviceMode = InitDriver(); if (iDeviceMode == ROLE_AP) { //Device in AP Mode, Wait for Initialization to Complete while (g_ucIpObtained == 0) { MAP_UtilsDelay(100); } } sl_WlanSetMode(ROLE_STA); if (iDeviceMode == ROLE_AP) DeInitDriverAP(); else DeInitDriver(); g_ucIpObtained = 0; g_ucConnectionStatus = 0; InitDriver(); //Select Antenna 1 AntennaSelect(1); //Get Scan Result ucCountSSID = GetScanResult(&g_netEntries[0]); //Select Antenna 2 AntennaSelect(2); //Get Scan Result ucCountSSIDAnt2 = GetScanResult(&g_netEntriesAnt2[0]); //Sort Scan Result SortByRSSI(&g_netEntries[0],ucCountSSID); SortByRSSI(&g_netEntriesAnt2[0],ucCountSSIDAnt2); while(!g_ucAntSelectDone) { //Switch to AP Mode sl_WlanSetMode(ROLE_AP); DeInitDriver(); g_ucIpObtained = 0; g_ucConnectionStatus = 0; //Initialize the SLHost Driver InitDriver(); //Wait for Ip Acquired Event in AP Mode while (g_ucIpObtained == 0) { MAP_UtilsDelay(100); } // // Wait for AP Configuraiton, Open Browser and Configure AP // while (g_ucProfileAdded && !g_ucAntSelectDone) { MAP_UtilsDelay(100); } g_ucProfileAdded = 1; //Switch to STA Mode sl_WlanSetMode(ROLE_STA); //AP Configured, Restart in STA Mode DeInitDriverAP(); g_ucIpObtained = 0; g_ucConnectionStatus = 0; //MAP_UtilsDelay(10000000); InitDriver(); // // Connect to the Configured Access Point // WlanConnect(); g_ucConnectedToConfAP = g_ucConnectionStatus; sl_WlanDisconnect(); } while (1) { } }
int OpenFile(const char* filename) { InitDriver(); int ret = CreateOcxByFile(filename); if(ret != ENERR) { printf("Open Stream fail\n"); return ret; } int pix = Manager.avParams.pixFormat; int w = Manager.avParams.width; int h = Manager.avParams.height; CallBack callfun = Manager.avParams.callFunc; void *arg = Manager.avParams.arg; memset(&Manager,0,sizeof(AvManager)); SetPlayParams(pix,w,h,callfun,arg); pix = Manager.avParams.pixFormat; w = Manager.avParams.width; h = Manager.avParams.height; printf("pix=%d,w=%d,h=%d\n",pix,w,h); if(Manager.avParams.arg) printf("Have some parameters\n"); if(Manager.avParams.callFunc) printf("Have som function!\n"); InitScaleEngine(); int audio = IsExistAuido(); int video = IsExistVideo(); Manager.playAudio = audio; Manager.playVideo = video; Manager.playerClock = 0; if(audio) { printf("Set Audio Params!\n"); Manager.ap = GetOcxAudioParam(); InitWaveEngine(Manager.ap.m_bAudioFreq,Manager.ap.m_bAudioFormat,Manager.ap.m_bAudioChannel); Manager.audioBasePara = 2*Manager.ap.m_bAudioFreq*Manager.ap.m_bAudioChannel; Manager.audioTimeBase = GetTimeBase(AUDIO); } if(video) { printf("Set video params!\n"); Manager.vp = GetOcxVideoParam(); SetScaleParam(PIX_FMT_YUV420P,Manager.vp.m_bVideoWidth,Manager.vp.m_bVideoHeight,pix,w,h); if(Manager.vp.m_bVideoFrameRate > 0 && Manager.vp.m_bVideoFrameRate <= 100) Manager.delayWithoutAudioTime = (1.0/Manager.vp.m_bVideoFrameRate); else { Manager.vp.m_bVideoFrameRate = 25; Manager.delayWithoutAudioTime = (1.0/25); } Manager.videoTimeBase = GetTimeBase(VIDEO); printf("Delay frame per time = %f,frame/per = %d\n",Manager.delayWithoutAudioTime,Manager.vp.m_bVideoFrameRate); } Manager.duration = GetDuration(); printf("Duration = %f\n",Manager.duration); Manager.avCommand = NONE_CMD; Manager.avState = PLAY; Manager.ManagerOver = FALSE; Manager.autoEnd = FALSE; Manager.avPos = 0; Manager.avSeek = FALSE; Manager.masterClkByAV = NONE; Manager.delay_timer = (double)GetTimeHere()/AV_TIME_BASE; Manager.last_delay = 40e-3; Manager.last_pts = 0; Manager.managerEnd = FALSE; Manager.audioClock = 0; Manager.videoClock = 0; if(Manager.playAudio) { Manager.MediaAudio = InitQueueBuffer(); if(!Manager.MediaAudio) return EALLOC; pthread_create(&Manager.renderAudio,NULL,&RenderAudio,&Manager); if(!Manager.renderAudio) { printf("Can not create render audio thread!\n"); return EALLOC; } } if(Manager.playVideo) { Manager.MediaVideo = InitQueueBuffer(); if(!Manager.MediaVideo) return EALLOC; Manager.MediaPicture = InitQueueBuffer(); if(!Manager.MediaPicture) return EALLOC; pthread_create(&Manager.synProcess,NULL,&SynProcess,&Manager); if(!Manager.synProcess) { printf("Start syn thread error!\n"); return EALLOC; } usSleep(20); pthread_create(&Manager.renderVideo,NULL,&RenderVideo,&Manager); if(!Manager.renderVideo) { printf("Can not create render video thread!\n"); return EALLOC; } } pthread_create(&Manager.readAvEngine,NULL,&ReadAvData,&Manager); if(!Manager.readAvEngine) { printf("Can not create read thread!\n"); return EALLOC; } Manager.already = TRUE; return ENERR; }
/*! Registers this node, and all of its children that have to be registered. Also initializes the driver and keeps it that way on return in case it returns successfully. */ status_t device_node::Register(device_node* parent) { // make it public if (parent != NULL) parent->AddChild(this); else sRootNode = this; status_t status = InitDriver(); if (status != B_OK) return status; if ((fFlags & B_KEEP_DRIVER_LOADED) != 0) { // We keep this driver loaded by having it always initialized InitDriver(); } fFlags |= NODE_FLAG_REGISTER_INITIALIZED; // We don't uninitialize the driver - this is done by the caller // in order to save reinitializing during driver loading. uint32 registeredFixedCount; status = _RegisterFixed(registeredFixedCount); if (status != B_OK) { UninitUnusedDriver(); return status; } // Register the children the driver wants if (DriverModule()->register_child_devices != NULL) { status = DriverModule()->register_child_devices(DriverData()); if (status != B_OK) { UninitUnusedDriver(); return status; } if (!fChildren.IsEmpty()) { fRegistered = true; return B_OK; } } if (registeredFixedCount > 0) { // Nodes with fixed children cannot have any dynamic children, so bail // out here fRegistered = true; return B_OK; } // Register all possible child device nodes status = _RegisterDynamic(); if (status == B_OK) fRegistered = true; else UninitUnusedDriver(); return status; }
status_t device_node::Probe(const char* devicePath, uint32 updateCycle) { if ((fFlags & NODE_FLAG_DEVICE_REMOVED) != 0 || updateCycle == fLastUpdateCycle) return B_OK; status_t status = InitDriver(); if (status < B_OK) return status; MethodDeleter<device_node, bool> uninit(this, &device_node::UninitDriver); if ((fFlags & B_FIND_CHILD_ON_DEMAND) != 0) { bool matches = false; uint16 type = 0; uint16 subType = 0; if (get_attr_uint16(this, B_DEVICE_SUB_TYPE, &subType, false) == B_OK && get_attr_uint16(this, B_DEVICE_TYPE, &type, false) == B_OK) { // Check if this node matches the device path // TODO: maybe make this extendible via settings file? if (!strcmp(devicePath, "disk")) { matches = type == PCI_mass_storage; } else if (!strcmp(devicePath, "audio")) { matches = type == PCI_multimedia && (subType == PCI_audio || subType == PCI_hd_audio); } else if (!strcmp(devicePath, "net")) { matches = type == PCI_network; } else if (!strcmp(devicePath, "graphics")) { matches = type == PCI_display; } else if (!strcmp(devicePath, "video")) { matches = type == PCI_multimedia && subType == PCI_video; } } else { // This driver does not support types, but still wants to its // children explored on demand only. matches = true; sGenericContextPath = devicePath; } if (matches) { fLastUpdateCycle = updateCycle; // This node will be probed in this update cycle status = _Probe(); sGenericContextPath = NULL; return status; } return B_OK; } NodeList::Iterator iterator = fChildren.GetIterator(); while (iterator.HasNext()) { device_node* child = iterator.Next(); status = child->Probe(devicePath, updateCycle); if (status != B_OK) return status; } return B_OK; }
//=============================================================== // Name : StateInit // Purpose : Initialization of the system. //=============================================================== void StateInit(void) { INTDisableInterrupts(); // Disable all interrupts of the system. INIT_PORTS; // INIT_WDT; INIT_TIMER; #ifdef USE_POTENTIOMETER INIT_ADC; #else INIT_INPUT_CAPTURE; #endif INIT_UART; INIT_SPI; INIT_PWM; INIT_I2C; INIT_CAN; INIT_SKADI; START_INTERRUPTS; // Send ID to backplane by CAN protocol SEND_ID_TO_BACKPLANE; Timer.DelayMs(10); // Send the mode of operation to the steering wheel SEND_MODE_TO_STEERING_WHEEL; // Get last known position of the mast ReadMastPosFromEeprom(); if (AbsFloat(mastAngle.currentValue) > 360) // Error { mastAngle.previousValue = 0; mastAngle.currentValue = 0; } #ifdef USE_POTENTIOMETER if (potValues.lastAverage > ADC_TOTAL_BITS) { potValues.lastAverage = ADC_TOTAL_BITS << 1; } if (potValues.zeroInBits > ADC_TOTAL_BITS) { potValues.zeroInBits = ADC_TOTAL_BITS << 1; } if (potValues.potStepValue > POT_TO_MOTOR_RATIO) { potValues.potStepValue = POT_TO_MOTOR_RATIO << 1; } if (potValues.lastBits > (ADC_BITS_PER_REVOLUTION - 1)) { potValues.lastBits = 0; } PotAddFirstSample(&potValues); // potValues.potSamples.lineBuffer.buffer[potValues.potSamples.maxBufSize] = potValues.lastAverage; // potValues.potStepSamples.lineBuffer.buffer[potValues.potStepSamples.maxBufSize] = potValues.potStepValue; #endif // Init registers for the drive InitDriver(); #ifdef USE_POTENTIOMETER potValues.angle = &mastAngle; potValues.speed = &mastSpeed; #endif }
/////////////////////////////////////////////////////////////////////// // main() //--------------------------------------------------------------------- // int main(int argc, char *argv[]) { Vstatus vErr; int end, i; unsigned int u; unsigned int lastRxCount; unsigned int time, lastTime; printf( "CANcount (Built at " __DATE__ " " __TIME__ ")\n" ); // parse the command line for (i=1; i<argc; i++) { int tmpL; if (_stricmp(argv[i], "-h") == 0) { usage(); } else if (_stricmp(argv[i], "-v") == 0) { gHwType = HWTYPE_VIRTUAL; } else if (sscanf(argv[i], "-hw%d", &tmpL) == 1) { gHwType = tmpL; } else if (_stricmp(argv[i], "-2") == 0) { gHwChannel = 1; printf("Using channel 2.\n"); } else if (_stricmp(argv[i], "-l") == 0) { gLogEvents = 1; printf("Logging activated\n"); } else if (sscanf(argv[i], "-b%u", &u) == 1) { if (u>5000 && u<=1000000) gBitRate = u; else usage(); } else if (sscanf(argv[i], "-f%s", &gLogFileName) == 1) { gLogFile = fopen(gLogFileName, "wb"); } else { usage(); } } if (gHwType < 0) usage(); printf("Hardware = %u\n", gHwType); printf("Channel = %u\n", gHwChannel+1); printf("Bitrate = %u BPS\n", gBitRate); if (gLogFile) printf("Logfile = %s\n", gLogFileName); printf("\n"); // initialize the CAN driver vErr = InitDriver(gHwType, gHwChannel); if (vErr) goto error; // create a synchronisation object gEventHandle = CreateEvent(NULL, FALSE, FALSE, NULL); vErr = ncdSetNotification(gPortHandle, (unsigned long*)&gEventHandle, 1); if (vErr) goto ncdError; // create a thread threadHandle = CreateThread(0, 0x1000, thread, 0, 0, &threadId); SetThreadPriority(threadHandle, THREAD_PRIORITY_NORMAL); // channel on bus vErr = ncdActivateChannel(gPortHandle, gChannelMask); if (vErr) goto ncdError; // main loop end = 0; lastTime = GetTickCount(); lastRxCount = 0; while (!end) { Sleep(500); time = GetTickCount(); if (time != lastTime) { printf("RX = %u msg/s, OVERFLOWS = %u \r", ((gRxCount-lastRxCount)*1000)/(time-lastTime), gRxOverflows); lastTime = time; lastRxCount = gRxCount; } // check keyboard if (_kbhit()) { switch (_getch()) { case 27: end = 1; break; default: break; } } } error: // stop thread if (threadHandle) { threadRuning = 0; WaitForSingleObject(threadHandle, 5000); } ncdDeactivateChannel(gPortHandle, gChannelMask); CleanUp(); if (gLogFile) fclose(gLogFile); return 0; ncdError: printf("ERROR: %s\n", ncdGetErrorString(vErr)); goto error; }