Example #1
0
DMPAPI(void *) CreateUART(int com)
{
	SerialPort *port;
	
	if (io_Init() == false)
	{
		err_print((char*)"%s: Init IO lib error!!\n", __FUNCTION__);
		return NULL;
	}
	
	if ((port = (SerialPort *)ker_Malloc(sizeof(SerialPort))) == NULL)
	{
		io_Close();
		return NULL;
	}

	port->com  = com;
	port->addr = vx86_uart_GetBaseAddr(com);
	port->nIRQ = vx86_uart_GetIRQ(com);
	
	if (port->addr == 0x00 || port->nIRQ == 0)
	{
		err_print((char*)"%s: COM%d is null. [Base address: 0x%04x, IRQ: %d]\n", __FUNCTION__, com+1, port->addr, port->nIRQ);
		ker_Mfree((void*)port);
		io_Close();
		return NULL;
	}
	
	port->nBuad        = 115200L;
	port->nData        = BYTESIZE8;
	port->nStop        = STOPBIT1;
	port->nParity      = NOPARITY;
	port->control      = NO_CONTROL;
	
	port->InUse        = 0;
	port->INT_InUse    = 0;
	
	port->rts          = 0;
	port->cts          = CTS_OFF;
	
	port->xonxoff_rcvd = XOFF_RCVD;
	port->xonxoff_xmit = XOFF_XMIT;
	port->xon          = 0;
	port->xoff         = 0;
																			 
	port->old_lsb      = port->lsb      = 0;
	port->old_msb      = port->msb      = 0;
	port->old_ier      = port->ier      = 0;
	port->old_lcr      = port->lcr      = 0;
	port->old_mcr      = port->mcr      = 0;
	port->old_TimeOut  = port->TimeOut  = UART_NO_TIMEOUT;
	port->fcr = 0;
	
	port->RFIFO_Size   = 0;
	port->WFIFO_Size   = 0;
	
	if ((port->rcvd = CreateQueue(RX_QUEUE_SIZE)) == NULL) goto CREATE_RX_QUEUE_FAIL;
	if ((port->xmit = CreateQueue(TX_QUEUE_SIZE)) == NULL) goto CREATE_TX_QUEUE_FAIL;
	
	port->msr_handler = NULL;
	port->lsr_handler = NULL;
	
	port->TXDB  = port->addr + 0;
	port->RXDB  = port->addr + 0;
	port->DLLSB = port->addr + 0;
	port->DLMSB = port->addr + 1;
	port->IER   = port->addr + 1;
	port->IIR   = port->addr + 2;
	port->FCR   = port->addr + 2;
	port->LCR   = port->addr + 3;
	port->MCR   = port->addr + 4;
	port->LSR   = port->addr + 5;
	port->MSR   = port->addr + 6;
	port->SCR   = port->addr + 7;
	
	return (void *)port;
	
CREATE_TX_QUEUE_FAIL:
	DestoryQueue(port->rcvd);
CREATE_RX_QUEUE_FAIL:
	ker_Mfree((void*)port);
	io_Close();
	return NULL;
}
Example #2
0
DMPAPI(void *) CreateUSBDevice(void)
{
	USB_Device *usb = NULL;
	
	if ((usb = (USB_Device *)ker_Malloc(sizeof(USB_Device))) == NULL) return NULL;
	
	if (io_Init() == false) {
		err_print((char*)"%s: Init IO lib error!!\n", __FUNCTION__);
		ker_Mfree((void *)usb);
		return NULL;
	}

	usb->addr = vx86_GetUSBDevAddr();
	usb->nIRQ = vx86_GetUSBDevIRQ();
	if (usb->addr == 0x0000 || usb->nIRQ == 0)
	{ 
		io_Close();
		ker_Mfree((void *)usb);
		return NULL;
	}
	
	usb->DevAddr                 = 0x00;
	usb->ReadySetAddr            = false;
	
	usb->state					 = USB_DEV_NOT_ATTACHED;
	usb->stall					 = false;
	
	usb->InUse                   = 0;
	usb->IsSet                   = 0;
	usb->setup_in_handled        = false;
	usb->setup_out_handled       = false;
	usb->bulk_in_transmitting 	 = false;
	
	usb->TimeOut		         = USB_NO_TIMEOUT;
	
	usb->InDataPtr               = NULL;
	usb->OutDataPtr              = NULL;
	usb->InDataSize              = 0;
	usb->OutDataSize             = 0;

	if ((usb->rcvd = CreateQueue(RX_QUEUE_SIZE)) == NULL) goto CREATE_RX_QUEUE_FAIL;
	if ((usb->xmit = CreateQueue(TX_QUEUE_SIZE)) == NULL) goto CREATE_TX_QUEUE_FAIL;
	
	usb->Setup.bmRequestType     = 0;
	usb->Setup.bRequest          = 0;
	usb->Setup.wValue.Value      = 0;
	usb->Setup.wIndex.Value      = 0;
	usb->Setup.wLength           = 0;
	
	usb->ling_coding.dwDTERate   = 0;
	usb->ling_coding.bCharFormat = 0;
	usb->ling_coding.bParityType = 0;
	usb->ling_coding.bDataBits   = 0;
	
	usb->control_line_state      = 0;
	usb->serial_state            = 0;
	
	usb->DAR = usb->addr + 0x00;
	usb->CFR = usb->addr + 0x02;
	usb->FNR = usb->addr + 0x06;
	usb->IER = usb->addr + 0x08;
	usb->ISR = usb->addr + 0x0C;
	usb->TMR = usb->addr + 0x68;
	
	memset((Endpoint *)usb->EP, 0, sizeof(usb->EP));
	usb->EP[0].CtrlTR   = usb->addr + 0x10;
	usb->EP[1].OutTR    = usb->addr + 0x12;
	usb->EP[1].InTR     = usb->addr + 0x14;
	usb->EP[2].OutTR    = usb->addr + 0x16;
	usb->EP[2].InTR     = usb->addr + 0x18;
	usb->EP[3].OutTR    = usb->addr + 0x1A;
	usb->EP[3].InTR     = usb->addr + 0x1C;
	usb->EP[0].SetupDLR = usb->addr + 0x20;
	usb->EP[0].OutDLR   = usb->addr + 0x24;
	usb->EP[0].InDLR    = usb->addr + 0x28;
	usb->EP[1].OutDLR   = usb->addr + 0x2C;
	usb->EP[1].InDLR    = usb->addr + 0x30;
	usb->EP[2].OutDLR   = usb->addr + 0x34;
	usb->EP[2].InDLR    = usb->addr + 0x38;
	usb->EP[3].OutDLR   = usb->addr + 0x3C;
	usb->EP[3].InDLR    = usb->addr + 0x40;
	usb->EP[0].SetupDSR = usb->addr + 0x44;
	usb->EP[0].OutDSR   = usb->addr + 0x48;
	usb->EP[0].InDSR    = usb->addr + 0x4C;
	usb->EP[1].OutDSR   = usb->addr + 0x50;
	usb->EP[1].InDSR    = usb->addr + 0x54;
	usb->EP[2].OutDSR   = usb->addr + 0x58;
	usb->EP[2].InDSR    = usb->addr + 0x5C;
	usb->EP[3].OutDSR   = usb->addr + 0x60;
	usb->EP[3].InDSR    = usb->addr + 0x64;	

#ifdef DMP_86DUINO_MODE
	set_gpio_config_addr(GPIO_CONFIG_ADDR); // for 86duino
	set_tx_led(7, 2);
	set_rx_led(7, 3);
	TX_LED_OFF();
	RX_LED_OFF();
#endif
	return (void *)usb;
	
CREATE_TX_QUEUE_FAIL:
	DestoryQueue(usb->rcvd);
CREATE_RX_QUEUE_FAIL:
	io_Close();
	ker_Mfree((void *)usb);
	return NULL;
}
Example #3
0
DMPAPI(bool) usb_Init(void *vusb)
{
	#if defined DMP_DOS_DJGPP
	static bool locked = false;
	int size_temp;
	#endif
	USB_Device *usb = (USB_Device *)vusb;
	
	if (usb->InUse == 1) return true;
	
	// if (USB_IsAttached() == false) return false;
	USB_Connect();
	
	if (irq_Init() == false) {
        err_print((char*)"%s: IRQ init fail.\n", __FUNCTION__);
		io_Close();
        return false;
    }
	
	#if defined DMP_DOS_DJGPP
	if (locked == false)
	{
		int i, str_size;
		DPMI_LOCK_FUNC(SetEPnDLR);
		DPMI_LOCK_FUNC(Set_Address);
		DPMI_LOCK_FUNC(Get_Descriptor);
		DPMI_LOCK_FUNC(Set_Descriptor);
		DPMI_LOCK_FUNC(Get_Configuration);
		DPMI_LOCK_FUNC(Set_Configuration);
		DPMI_LOCK_FUNC(Get_Interface);
		DPMI_LOCK_FUNC(Set_Interface);
		DPMI_LOCK_FUNC(Synch_Frame);
		DPMI_LOCK_FUNC(USB_Standard_Request);
		DPMI_LOCK_FUNC(Set_Line_Coding);
		DPMI_LOCK_FUNC(Get_Line_Coding);
		DPMI_LOCK_FUNC(Set_Control_Line_State);
		DPMI_LOCK_FUNC(Send_Break);
		DPMI_LOCK_FUNC(USB_CDC_Request);
		DPMI_LOCK_FUNC(EP0_SetupHandler);
		DPMI_LOCK_FUNC(EP0_InHandler);
		DPMI_LOCK_FUNC(EP0_OutHandler);
		DPMI_LOCK_FUNC(EP1_InHandler);
		DPMI_LOCK_FUNC(EP2_InHandler);
		DPMI_LOCK_FUNC(EP2_OutHandler);
		DPMI_LOCK_FUNC(usb_Reset);
		DPMI_LOCK_FUNC(USB_ISR);
		DPMI_LOCK_VAR(desc_Device);
		DPMI_LOCK_VAR(desc_Config_Set);
		DPMI_LOCK_VAR(StringDescTable[0]);
		DPMI_LOCK_VAR(StringDescTable[1]);
		DPMI_LOCK_VAR(StringDescTable[2]);
		DPMI_LOCK_VAR(StringDescTable[3]);
		DPMI_LOCK_VAR(StringDescTable[4]);
		DPMI_LOCK_VAR(StringDescTable[5]);
		DPMI_LOCK_VAR(StringDescTable[6]);
		locked = true;
	}
	#endif

	io_outpb(usb->CFR, 0x02); // Soft reset
	while (io_inpb(usb->CFR) & 0x02);
	
	if ((usb->EP[0].SetupBuf = (BYTE *)ker_Malloc(sizeof(BYTE)*EP0_MAX_PACKET_SIZE)) == NULL) 	  goto EP0_SETUP_FAIL;
	if ((usb->EP[0].InBuf    = (BYTE *)ker_Malloc(sizeof(BYTE)*EP0_MAX_PACKET_SIZE)) == NULL) 	  goto EP0_IN_FAIL;
	if ((usb->EP[0].OutBuf   = (BYTE *)ker_Malloc(sizeof(BYTE)*EP0_MAX_PACKET_SIZE)) == NULL) 	  goto EP0_OUT_FAIL;
	if ((usb->EP[1].InBuf    = (BYTE *)ker_Malloc(sizeof(BYTE)*EP1_MAX_PACKET_SIZE_IN)) == NULL)  goto EP1_IN_FAIL;
	if ((usb->EP[2].InBuf    = (BYTE *)ker_Malloc(sizeof(BYTE)*EP2_MAX_PACKET_SIZE_IN)) == NULL)  goto EP2_IN_FAIL;
	if ((usb->EP[2].OutBuf   = (BYTE *)ker_Malloc(sizeof(BYTE)*EP2_MAX_PACKET_SIZE_OUT)) == NULL) goto EP2_OUT_FAIL;
	
	#if defined DMP_DOS_DJGPP
	if ((dma_handle = dma_Alloc(EP0_MAX_PACKET_SIZE    +
	                            EP0_MAX_PACKET_SIZE    +
						        EP0_MAX_PACKET_SIZE    +
						        EP1_MAX_PACKET_SIZE_IN +
						        EP2_MAX_PACKET_SIZE_IN +
						        EP2_MAX_PACKET_SIZE_OUT, &dma_addr)) == DMA_FAIL) goto EP2_OUT_FAIL;
	size_temp = 0;
	usb->EP[0].SetupPhysical = dma_addr;
	usb->EP[0].InPhysical    = dma_addr + (size_temp += EP0_MAX_PACKET_SIZE);
	usb->EP[0].OutPhysical   = dma_addr + (size_temp += EP0_MAX_PACKET_SIZE);
	usb->EP[1].InPhysical    = dma_addr + (size_temp += EP0_MAX_PACKET_SIZE);
	usb->EP[2].InPhysical    = dma_addr + (size_temp += EP1_MAX_PACKET_SIZE_IN);
	usb->EP[2].OutPhysical   = dma_addr + (size_temp += EP2_MAX_PACKET_SIZE_IN);
	
	#else
	usb->EP[0].SetupPhysical = GrabPhysicalMEM((void *)usb->EP[0].SetupBuf);
	usb->EP[0].InPhysical    = GrabPhysicalMEM((void *)usb->EP[0].InBuf);
	usb->EP[0].OutPhysical   = GrabPhysicalMEM((void *)usb->EP[0].OutBuf);
	usb->EP[1].InPhysical    = GrabPhysicalMEM((void *)usb->EP[1].InBuf);
	usb->EP[2].InPhysical    = GrabPhysicalMEM((void *)usb->EP[2].InBuf);
	usb->EP[2].OutPhysical   = GrabPhysicalMEM((void *)usb->EP[2].OutBuf);
	#endif
	
	// usb->DevAddr = 0x00;
	// usb->ReadySetAddr = false;
	// io_outpb(usb->DAR, 0x00); // enable USB device
	
	io_outpdw(usb->EP[0].SetupDSR, usb->EP[0].SetupPhysical);
	io_outpdw(usb->EP[0].InDSR   , usb->EP[0].InPhysical);
	io_outpdw(usb->EP[0].OutDSR  , usb->EP[0].OutPhysical);
	io_outpdw(usb->EP[1].InDSR   , usb->EP[1].InPhysical);
	io_outpdw(usb->EP[2].InDSR   , usb->EP[2].InPhysical);
	io_outpdw(usb->EP[2].OutDSR  , usb->EP[2].OutPhysical);
	
	io_outpw(usb->EP[0].CtrlTR   , 0x2000 | EP0_MAX_PACKET_SIZE);
	io_outpw(usb->EP[1].InTR     , 0x3800 | EP1_MAX_PACKET_SIZE_IN);
	io_outpw(usb->EP[2].InTR     , 0x3000 | EP2_MAX_PACKET_SIZE_IN);
	io_outpw(usb->EP[2].OutTR    , 0x3000 | EP2_MAX_PACKET_SIZE_OUT);
	
	SetEPnDLR(usb, EP0, SETUP, ENABLE);
	
	// io_outpb(usb->DAR, 0x80); // enable USB device
	// while (!(io_inpb(usb->DAR) & 0x80));
	
	// ClearQueue(usb->rcvd);
	// ClearQueue(usb->xmit);
	
	// io_DisableINT();
	// {
		// io_outpb(usb->CFR, io_inpb(usb->CFR) & 0xFE);
		// io_outpdw(usb->IER, ISOF + IBRST + ISUSP + IRESM + SYSERR + 
		                    // IEP0SETUP + IEP0RX + IEP0TX + IEP1TX + IEP2RX + IEP2TX);
		// io_outpb(usb->CFR, io_inpb(usb->CFR) | 0x01);
	// }
	// io_RestoreINT();
	
	// usb->state = USB_DEV_DEFAULT;
	
	io_outpb(usb->DAR, 0x80); // enable USB device
	while (!(io_inpb(usb->DAR) & 0x80));
	
	io_outpdw(usb->ISR, 0xFFFFFFFFL);

	io_DisableINT();
	{
		io_outpb(usb->CFR, io_inpb(usb->CFR) & 0xFE);
		irq_Setting(usb->nIRQ, IRQ_LEVEL_TRIGGER);
		irq_InstallISR(usb->nIRQ, USB_ISR, (void *)usb);
		io_outpdw(usb->IER, ISOF + IBRST + ISUSP + IRESM + SYSERR + 
		                    IEP0SETUP + IEP0RX + IEP0TX + IEP1TX + IEP2RX + IEP2TX);
		io_outpb(usb->CFR, io_inpb(usb->CFR) | 0x01);
	}
	io_RestoreINT();
	
	usb->state  = USB_DEV_POWERED;
	usb->InUse = 1;
	
	return true;
	
EP2_OUT_FAIL:
	ker_Mfree(usb->EP[2].InBuf);
EP2_IN_FAIL:
	ker_Mfree(usb->EP[1].InBuf);
EP1_IN_FAIL:	
	ker_Mfree(usb->EP[0].OutBuf);
EP0_OUT_FAIL:
	ker_Mfree(usb->EP[0].InBuf);
EP0_IN_FAIL:
	ker_Mfree(usb->EP[0].SetupBuf);
EP0_SETUP_FAIL:
	err_print((char*)"%s: Alloc endpoint buffers error!!\n", __FUNCTION__);
	irq_Close();
	io_Close();
	return false;
}
Example #4
0
DMPAPI(COMPort *) CreateCOMPort(int com)
{
	COMPort *port;
	
	if (com >= SIZE_OF_COM || com < 0) return NULL;
	if (InUse[com] != 0) return NULL;
	
	if ((port = (COMPort *)ker_Malloc(sizeof(COMPort))) == NULL) return NULL;
	
	port->com                = com;
	port->func               = NULL;
	port->Close              = NULL;
	port->SetTimeOut         = NULL;
	port->Read               = NULL;
	port->Receive            = NULL;
	port->QueryRxQueue       = NULL;
	port->RxQueueFull        = NULL;
	port->RxQueueEmpty       = NULL;
	port->FlushRxQueue       = NULL;
	port->Write              = NULL;
	port->Send               = NULL;
	port->QueryTxQueue       = NULL;
	port->TxQueueFull        = NULL;
	port->TxQueueEmpty       = NULL;
	port->FlushTxQueue       = NULL;
	port->TxReady            = NULL;
	port->FlushWFIFO         = NULL;
	port->SetBPS             = NULL;
	port->SetFormat          = NULL;
	port->SetFlowControl     = NULL;
	port->EnableFIFO         = NULL;
	port->SetWFIFOSize       = NULL;
	port->ClearRFIFO         = NULL;
	port->ClearWFIFO         = NULL;
	port->SetLSRHandler      = NULL;
	port->SetMSRHandler      = NULL;
	port->GetLSR             = NULL;
	port->GetMSR             = NULL;
	port->Ready              = NULL;
	port->GetLineCoding      = NULL;
	port->SetSerialState     = NULL;
	port->GetControlLineState= NULL;
	port->Reset              = NULL;
	port->AddIDFilter        = NULL;
	port->GetIDFilter        = NULL;
	port->DelIDFilter        = NULL;
	port->ClearIDList        = NULL;
	port->EnableBypass       = NULL;
	port->DisableBypass      = NULL;
	port->SetEWLimit         = NULL;
	port->GetEWLimit         = NULL;
	port->GetTxErrorCount    = NULL;
	port->GetRxErrorCount    = NULL;
	port->GetNowState        = NULL;
	port->EnableStoreError   = NULL;
	port->DisableStoreError  = NULL;
	port->SetCANBusOffHandler= NULL;
	port->PopError           = NULL;
	port->GetLastError       = NULL;
	port->ReadCAN            = NULL;
	port->WriteCAN           = NULL;
	port->EnableHalfDuplex   = NULL;
	port->EnableFullDuplex   = NULL;
	port->EnableDebugMode    = NULL;
	port->DisableDebugMode   = NULL;
	
	return port;
}