DMPAPI(bool) uart_Init(void *vport) { SerialPort *port = (SerialPort *)vport; if (vx86_uart_Init(port->com) == false) { err_print((char*)"%s: Vertex86 COM%d init fail!!\n", __FUNCTION__, port->com + 1); goto VX86_UART_INIT_FAIL; } if (uart_IsOK(port) == false) { err_print((char*)"%s: COM%d doesn't exist.\n", __FUNCTION__, port->com + 1); goto CHECK_EXIST_FAIL; } if (irq_Init() == false) { err_print((char*)"%s: IRQ init fail.\n", __FUNCTION__); goto IRQ_INIT_FAIL; } // save old UART config port->old_lsb = port->lsb = _16550_DLAB_In(port, port->DLLSB); port->old_msb = port->msb = _16550_DLAB_In(port, port->DLMSB); port->old_ier = port->ier = io_inpb(port->IER); port->old_lcr = port->lcr = io_inpb(port->LCR); port->old_mcr = port->mcr = io_inpb(port->MCR); port->old_TimeOut = port->TimeOut = UART_NO_TIMEOUT; // UART initial uart_SetBaud(vport, UARTBAUD_115200BPS); uart_SetFormat(vport, BYTESIZE8 + STOPBIT1 + NOPARITY); uart_SetTimeOut(vport, UART_NO_TIMEOUT); // flush rx & tx queue uart_FlushRxQueue(vport); uart_FlushTxQueue(vport); // clear Hardware RX & TX FIFO uart_ClearRFIFO(vport); uart_ClearWFIFO(vport); // enable FIFO mode uart_SetHWFIFO(vport, ENABLE_HW_FIFO_16); // enable receive data interrupt uart_IntEnable(vport, IERALL); // set flow control uart_SetFlowControl(vport, NO_CONTROL); port->InUse = 1; return true; IRQ_INIT_FAIL: CHECK_EXIST_FAIL: vx86_uart_Close(port->com); VX86_UART_INIT_FAIL: if (io_Close() == false) err_print((char*)"Close IO lib error!!\n"); return false; }
static bool interrupt_init(void) { if(used_irq != 0xff) return true; if(irq_Init() == false) { printf("irq_init fail\n"); return false; } if(irq_Setting(GetMCIRQ(), IRQ_LEVEL_TRIGGER + IRQ_DISABLE_INTR) == false) { printf("%s\n", __FUNCTION__); return false; } if(irq_InstallISR(GetMCIRQ(), user_int, (void*)name) == false) { printf("irq_install fail\n"); return false; } //printf("BaseAddr = %08lxh irq = %d\n\n", mc_setbaseaddr(), GetMCIRQ()); //Master_DX2(); used_irq = GetMCIRQ(); Set_MCIRQ(used_irq); return true; }
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; }
void sys_Init() { //创建系统守护定时(1S) #if OS_TYPE rt_timer_init(&timer_daemon, "daemon", sys_Daemon, NULL, 100 / OS_TICK_MS, RT_TIMER_FLAG_PERIODIC); rt_timer_start(&timer_daemon); #endif #if OS_TYPE buf_Init(); #endif #if OS_QUEUE_QTY os_que_Init(); #endif #if IRQ_ENABLE irq_Init(); #endif #if BATTERY_ENABLE bat_On(); #endif //------------------------------------------------------------------------- //GPIO Functions //------------------------------------------------------------------------- #if PULSE_COL_ENABLE pulse_Init(); #endif #if HT1621_ENABLE ht1621_Init(); #endif //------------------------------------------------------------------------- //External Parallel Interface Functions //------------------------------------------------------------------------- #if NANDFLASH_ENABLE nand_Init(); #endif //------------------------------------------------------------------------- //I2C Interface Functions //------------------------------------------------------------------------- #if PCA955X_ENABLE pca955x_Init(); #endif //------------------------------------------------------------------------- //SPI Interface Functions //------------------------------------------------------------------------- #if SC16IS7X_ENABLE sc16is7x_Init(); #endif #if ATT7022_ENABLE att7022_Init(); #endif #if NRSEC3000_ENABLE nrsec3000_Init(); #endif #if VOICE_ENABLE wtv_Init(); #endif #if MIFARE_ENABLE mf_InitGpio(); #endif //------------------------------------------------------------------------- //UART Interface Functions //------------------------------------------------------------------------- #if VK321X_ENABLE vk321x_Init(); #endif #if TDK6515_ENABLE tdk6515_Init(); #endif #if MODEM_ENABLE modem_Init(); #endif //------------------------------------------------------------------------- //Real Time Clock Functions //------------------------------------------------------------------------- #if RTC_ENABLE rtc_Init(); #endif //------------------------------------------------------------------------- //Backup Functions //------------------------------------------------------------------------- #if BKP_ENABLE bkp_Init(); #endif //------------------------------------------------------------------------- //Flash System Functions //------------------------------------------------------------------------- #if INTFLASH_ENABLE intf_Init(); #endif #if NORFLASH_ENABLE norf_Init(); #endif #if SPIFLASH_ENABLE spif_Init(); #endif #if FLASH_ENABLE flash_Init(); #endif //------------------------------------------------------------------------- //File System Functions //------------------------------------------------------------------------- #if FS_ENABLE fs_init(); #endif //------------------------------------------------------------------------- //USB Interface Functions //------------------------------------------------------------------------- #if USB_ENABLE usb_Init(); #endif //------------------------------------------------------------------------- //Register Subsystem Functions //------------------------------------------------------------------------- #if REGISTER_ENABLE reg_Init(); #endif //------------------------------------------------------------------------- //Network Subsystem Functions //------------------------------------------------------------------------- #if TCPPS_ENABLE net_Init(); #endif //------------------------------------------------------------------------- //In Application Programming Functions //------------------------------------------------------------------------- #if GDFTS_ENABLE gdfts_Init(); #endif #if GUI_ENABLE gui_Init(); #endif #if OS_TYPE //创建系统IO处理线程 #if SYS_TIMER_ENABLE rt_timer_init(&timer_IOHandle, "sysio", sys_IOHandle, NULL, 1, RT_TIMER_FLAG_PERIODIC); rt_timer_start(&timer_IOHandle); #else os_thd_Create(SysIo, 240); #endif //创建应用层线程 app_Entry(); //系统维护线程 sys_Maintain(); #endif }
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; }