HRESULT CLoopbackDevice::FinalConstruct() {
  // Perform tasks which may fail when the class CLoopbackDevice
  // is finally constructed. This involves creating the USB device 
  // object and initializing the device so that it is recognized
  // as a valid USB device by the controller
  HRESULT hr = S_OK;

  hr = CreateUSBDevice();
  IfFailHrGo(hr);

  hr = ConfigureDevice();
  IfFailHrGo(hr);

Exit:
    return hr;
}
コード例 #2
0
ファイル: wiring.cpp プロジェクト: jack23912/86Duino
bool init() {
	int i;
	if(io_Init() == false) return false;

	//set corssbar Base Address
	sb_Write16(0x64,0x0A01);
	//printf("SB C0~C3 REG: 0x%08X\n", sb_Read(0xc0));
	sb_Write(0xc0, sb_Read(0xc0) | 0x8000C000L);
	//printf("SB C0~C3 REG: 0x%08X\n", sb_Read(0xc0));
	//set GPIO Base Address
	sb_Write16(0x62,0xf101);
	// GPIO enable
	io_outpdw(0xf100,0x00ff);
	//set GPIO P0~9 dircetion & data Address
	//io_outpdw(0xf100,0x03ff);
	for(i=0;i<8;i++) {
		io_outpdw(0xf100 + (i+1)*4,((0xf202 + i*4)<<16) + 0xf200 + i*4);
		//io_outpb((sb_Read16(0x64)&0xfffe)+i,0x00);
	}
	  
	//setADC Base Address
	sb_Write(0xbc, sb_Read(0xbc) & (~(1L<<28)));  // active adc
	sb1_Write16(0xde, sb1_Read16(0xde) | 0x02);   // not Available for 8051A Access ADC
	sb1_Write(0xe0, 0x0010fe00L); // baseaddr = 0xfe00, disable irq
	
	
	//CDC
	USBDEV = CreateUSBDevice();
    if(USBDEV == NULL)
    {
        printf("init error\n");
        return false;
    }
    usb_SetUSBPins(USBDEV, 7, 0, 7, 1);
    if(usb_Init(USBDEV) == false)
    {
        printf("init2 error\n");
        return false;
    }
	
	//io_Close();
	return true;
}
コード例 #3
0
ファイル: wiring.cpp プロジェクト: pichitpr/86Duino
bool init() {
	int i, crossbarBase, gpioBase;
	if(io_Init() == false) return false;
    timer_NowTime(); // initialize timer
    CLOCKS_PER_MICROSEC = vx86_CpuCLK();
    VORTEX86EX_CLOCKS_PER_MS = CLOCKS_PER_MICROSEC*1000UL;
    
    // Set IRQ4 as level-trigger
    io_outpb(0x4D0, io_inpb(0x4D0) | 0x10);
    
	//set corssbar Base Address
	crossbarBase = sb_Read16(SB_CROSSBASE) & 0xfffe;
	if(crossbarBase == 0 || crossbarBase == 0xfffe)
		sb_Write16(SB_CROSSBASE, CROSSBARBASE | 0x01);
	
	// Force set HIGH speed ISA on SB
	sb_Write(SB_FCREG, sb_Read(SB_FCREG) | 0x8000C000L);
	
	//set SB GPIO Base Address
	gpioBase = sb_Read16(SB_GPIOBASE) & 0xfffe;
	if(gpioBase == 0 || gpioBase == 0xfffe)
	{
		sb_Write16(SB_GPIOBASE, GPIOCTRLBASE | 0x01);
		gpioBase = GPIOCTRLBASE;
	}
	
	// Enable GPIO 0 ~ 7 
	io_outpdw(gpioBase, 0x00ff);
	
	// set GPIO Port 0~7 dircetion & data Address
	for(i=0;i<8;i++)
		io_outpdw(gpioBase + (i+1)*4,((GPIODIRBASE + i*4)<<16) + GPIODATABASE + i*4);
	  
	// set ADC Base Address
	sb_Write(0xbc, sb_Read(0xbc) & (~(1L<<28)));  // active adc
	sb1_Write16(0xde, sb1_Read16(0xde) | 0x02);   // not Available for 8051A Access ADC
	sb1_Write(0xe0, 0x0050fe00L); // baseaddr = 0xfe00, disable irq
	
	// set MCM Base Address
	set_MMIO();
	mc_setbaseaddr();
	for(i=0; i<4; i++)
		mc_SetMode(i, MCMODE_PWM_SIFB);
	
	if(Global_irq_Init == false)
	{
		// set MCM IRQ
		if(irq_Init() == false) 
	    {
	        printf("MCM IRQ init fail\n"); return false;
	    }
	    
	    if(irq_Setting(GetMCIRQ(), IRQ_LEVEL_TRIGGER + IRQ_DISABLE_INTR) == false)
	    {
	        printf("MCM IRQ Setting fail\n"); return false;
	    }
	    Set_MCIRQ(GetMCIRQ());
	    Global_irq_Init = true;
	}
    
	//CDC
	USBDEV = CreateUSBDevice();
	if(USBDEV == NULL)
	{
		printf("init error\n");
		return false;
	}
    
	usb_SetUSBPins(USBDEV, 7, 0, 7, 1);
	usb_SetTimeOut(USBDEV, 0L, 500L); // USB RX timerout is 0ms and TX timeout is 500ms
	if(usb_Init(USBDEV) == false)
	{
		printf("init2 error\n");
		return false;
	}
    
	//io_Close();
	return true;
}
コード例 #4
0
ファイル: com.cpp プロジェクト: aquashift/86Duino_DuinOS
DMPAPI(COMPort *) com_Init(int com)
{
	COMPort *port;

	if ((port = (COMPort *)CreateCOMPort(com)) == NULL) return NULL;

	switch (com)
	{
		case COM1: case COM2: case COM3: case COM4: case COM5:
		case COM6: case COM7: case COM8: case COM9: case COM10:
		{
			if ((port->func = (void *)CreateUART(com)) == NULL) goto FAIL;
			if (uart_Init(port->func) == false)
			{
				uart_Close(port->func);
				goto FAIL;
			}
			
			port->Close              = uart_Close;
			port->SetTimeOut         = uart_SetTimeOut;
			port->Read               = uart_Read;
			port->Receive            = uart_Receive;
			port->QueryRxQueue       = uart_QueryRxQueue;
			port->RxQueueFull        = uart_RxQueueFull;
			port->RxQueueEmpty       = uart_RxQueueEmpty;
			port->FlushRxQueue       = uart_FlushRxQueue;
			port->Write              = uart_Write;
			port->Send               = uart_Send;
			port->QueryTxQueue       = uart_QueryTxQueue;
			port->TxQueueFull        = uart_TxQueueFull;
			port->TxQueueEmpty       = uart_TxQueueEmpty;
			port->FlushTxQueue       = uart_FlushTxQueue;
			port->TxReady            = uart_TxReady;
			port->FlushWFIFO         = uart_FlushWFIFO;
			port->SetBPS             = uart_SetBaud;
			port->SetFormat          = uart_SetFormat;
			port->SetFlowControl     = uart_SetFlowControl;
			port->EnableFIFO         = uart_SetHWFIFO;
			port->SetWFIFOSize       = uart_SetWFIFOSize;
			port->ClearRFIFO         = uart_ClearRFIFO;
			port->ClearWFIFO         = uart_ClearWFIFO;
			port->SetLSRHandler      = uart_SetLSRHandler;
			port->SetMSRHandler      = uart_SetMSRHandler;
			port->GetLSR             = uart_GetLSR;
			port->GetMSR             = uart_GetMSR;
			port->EnableHalfDuplex   = uart_EnableHalfDuplex;
			port->EnableFullDuplex   = uart_EnableFullDuplex;
			port->EnableDebugMode    = uart_EnableDebugMode;
			port->DisableDebugMode   = uart_DisableDebugMode;
			
			return port;
		}
		
		case USB_COM:
		{
			if ((port->func = (void *)CreateUSBDevice()) == NULL) goto FAIL;
			if (set_usb_pins == false)
			{
				err_print((char*)"%s: no set USB-Device pins.\n", __FUNCTION__);
				usb_Close(port->func);
				goto FAIL;
			}
			if (usb_SetUSBPins(port->func, usb_detect_port, usb_detect_pin, usb_on_off_port, usb_on_off_pin) == false)
			{
				usb_Close(port->func);
				goto FAIL;
			}
			if (usb_Init(port->func) == false)
			{
				usb_Close(port->func);
				goto FAIL;
			}
			
			port->Close              = usb_Close;
			port->SetTimeOut         = usb_SetTimeOut;
			port->Read               = usb_Read;
			port->Receive            = usb_Receive;
			port->QueryRxQueue       = usb_QueryRxQueue;
			port->RxQueueFull        = usb_RxQueueFull;
			port->RxQueueEmpty       = usb_RxQueueEmpty;
			port->FlushRxQueue       = usb_FlushRxQueue;
			port->Write              = usb_Write;
			port->Send               = usb_Send;
			port->QueryTxQueue       = usb_QueryTxQueue;
			port->TxQueueFull        = usb_TxQueueFull;
			port->TxQueueEmpty       = usb_TxQueueEmpty;
			port->FlushTxQueue       = usb_FlushTxQueue;
			port->TxReady            = usb_TxReady;
			port->FlushWFIFO         = usb_FlushWFIFO;
			port->Ready              = usb_Ready;
			port->GetLineCoding      = usb_GetLineCoding;
			port->SetSerialState     = usb_SetSerialState;
			port->GetControlLineState= usb_GetControlLineState;
			
			return port;
		}
		
		case CAN_BUS:
		{
			if ((port->func = (void *)CreateCANBus(IO_PORT)) == NULL) goto FAIL;
			if (can_Init(port->func) == false)
			{
				can_Close(port->func);
				goto FAIL;
			}
			
			port->Close              = can_Close;
			port->SetTimeOut         = can_SetTimeOut;
			port->QueryRxQueue       = can_QueryRxQueue;
			port->RxQueueFull        = can_RxQueueFull;
			port->RxQueueEmpty       = can_RxQueueEmpty;
			port->FlushRxQueue       = can_FlushRxQueue;
			port->QueryTxQueue       = can_QueryTxQueue;
			port->TxQueueFull        = can_TxQueueFull;
			port->TxQueueEmpty       = can_TxQueueEmpty;
			port->FlushTxQueue       = can_FlushTxQueue;
			port->TxReady            = can_TxReady;
			port->FlushWFIFO         = can_FlushWFIFO;
			port->SetBPS             = can_SetBPS;
			port->Reset              = can_Reset;
			port->AddIDFilter        = can_AddIDFilter;
			port->GetIDFilter        = can_GetIDFilter;
			port->DelIDFilter        = can_DelIDFilter;
			port->ClearIDList        = can_ClearIDList;
			port->EnableBypass       = can_EnableBypass;
			port->DisableBypass      = can_DisableBypass;
			port->SetEWLimit         = can_SetEWLimit;
			port->GetEWLimit         = can_GetEWLimit;
			port->GetTxErrorCount    = can_GetTxErrorCount;
			port->GetRxErrorCount    = can_GetRxErrorCount;
			port->GetNowState        = can_GetNowState;
			port->EnableStoreError   = can_EnableStoreError;
			port->DisableStoreError  = can_DisableStoreError;
			port->SetCANBusOffHandler= can_SetCANBusOffHandler;
			port->PopError           = can_PopError;
			port->GetLastError       = can_GetLastError;
			port->ReadCAN            = can_Read;
			port->WriteCAN           = can_Write;
			
			return port;
		}
		
		default: break;
	};
	
FAIL:
	ker_Mfree(port);
	return NULL;
}