BOOL CPCIDisk::Init( HKEY hActiveKey ) { BOOL bRet = FALSE; m_f16Bit = TRUE; // PCI is 16-bit // configure port if (!ConfigPort()) { DEBUGMSG(ZONE_INIT, (_T( "Atapi!CPCIDisk::Init> Failed to configure port; device(%u)\r\n" ), m_dwDeviceId)); goto exit; } // assign the appropriate folder name m_szDiskName = (IsCDRomDevice() ? g_szPCICDRomDisk : g_szPCIHardDisk); // reserve memory for DMA buffers m_pStartMemory = (LPBYTE)VirtualAlloc(NULL, 0x10000, MEM_RESERVE, PAGE_READWRITE); if (!m_pStartMemory) { bRet = FALSE; } // finish intialization; i.e., initialize device bRet = CDisk::Init(hActiveKey); if (!bRet) { goto exit; } exit:; return bRet; }
BOOL CRomiDisk::WakeUp( ) { ConfigPort(); return CDisk::Init(NULL); }
void main(void){ WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer P1DIR |= 0X01; P1OUT = 0x01; ConfigClock(); ConfigPort(); PWM_Details(Duty_Cycle,Periodo); ConfigTimer(); __bis_SR_register(LPM0_bits); // Enter LPM0 w/ interrupts }
int ConnPort::OpenPort(TCHAR *szPort,int iBaudrate,int iParity,int iDataBits,int iStopBits) { DWORD dwThreadID=0; g_iExitFlag=0; m_hPort=NULL; m_hPort=CreateFile(szPort, GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL); if(!m_hPort) { m_hPort=NULL; wprintf(TEXT("open port failed!!!\r\n")); return FALSE; } //指定端口检测的事件集 SetCommMask(m_hPort,EV_RXCHAR); //设置缓冲区,内部输入、输出缓冲区大小 SetupComm(m_hPort,1024,1024); //刷新缓冲区信息->输入、输出缓冲区 PurgeComm(m_hPort,PURGE_TXCLEAR|PURGE_RXCLEAR); if(!ConfigPort(iBaudrate,iParity,iDataBits,iStopBits)) return FALSE; if(!CommTimeouts())return FALSE; //创建读写线程 m_hThreadRead = CreateThread(0,0,(LPTHREAD_START_ROUTINE)ReadThreadProc, (void*)this,0,&dwThreadID); m_hThreadWrite = CreateThread(0,0,(LPTHREAD_START_ROUTINE)WriteThreadProc, (void*)this,0,&dwThreadID); m_hDataParse = CreateThread(0,0,(LPTHREAD_START_ROUTINE)PareDataProc, (void*)this,0,&dwThreadID); m_bIsConnect=TRUE; return TRUE; }
BOOL CRomiDisk::InitializePort( ) { BOOL RetValue=TRUE; PHYSICAL_ADDRESS ioPhysicalBase = {0,0}; m_pATAReg = (PBYTE)m_pPort->m_dwRegBase; m_pATARegAlt = (PBYTE)m_pPort->m_dwRegAlt; m_pBMCommand = (PBYTE)m_pPort->m_dwBMR; m_dwIndirectMode = m_pPort->m_pDskReg[m_dwDeviceId]->dwIndirectMode; // Map it if it is Memeory Mapped IO. ioPhysicalBase.LowPart = S3C6410_BASE_REG_PA_GPIO; m_vpIOPORTRegs = (S3C6410_GPIO_REG *)MmMapIoSpace(ioPhysicalBase , sizeof(S3C6410_GPIO_REG),FALSE); if (m_vpIOPORTRegs == NULL) { DEBUGMSG(ZONE_INIT|ZONE_ERROR,(TEXT("For m_vpIOPORTRegs: MmMapIoSpace() failed IOPORT!\r\n"))); RetValue = FALSE; goto init_done; } ioPhysicalBase.LowPart = S3C6410_BASE_REG_PA_SYSCON; m_vpSYSCONRegs = (S3C6410_SYSCON_REG *)MmMapIoSpace(ioPhysicalBase, sizeof(S3C6410_SYSCON_REG), FALSE); if (m_vpSYSCONRegs == NULL) { DEBUGMSG(ZONE_INIT|ZONE_ERROR,(TEXT("For m_vpSYSCONRegs: MmMapIoSpace() failed SYSCON!\r\n"))); RetValue = FALSE; goto init_done; } ConfigPort(); if (m_pPort->m_pDskReg[m_dwDeviceId]->dwInterruptDriven || m_pPort->m_pDskReg[m_dwDeviceId]->dwEnableUDMA) { if (m_pPort->m_hIRQEvent) { m_dwDeviceFlags |= DFLAGS_DEVICE_INITIALIZED; DEBUGMSG(ZONE_INIT|ZONE_ERROR, (_T("atapiRomi already initialized\n"))); return TRUE; } // create interrupt event if (NULL == (m_pPort->m_hIRQEvent = CreateEvent(NULL, FALSE, FALSE, NULL))) { DEBUGMSG(ZONE_INIT|ZONE_ERROR, (_T( "Atapi!CRomiDisk::ConfigPort> Failed to create interrupt event for device(%d)\r\n" ), m_dwDeviceId)); return FALSE; } } init_done: if ( RetValue != TRUE ) { if ( m_vpSYSCONRegs) { MmUnmapIoSpace((PVOID)m_vpSYSCONRegs, sizeof(S3C6410_SYSCON_REG)); m_vpSYSCONRegs= NULL; } if ( m_vpIOPORTRegs) { MmUnmapIoSpace((PVOID)m_vpIOPORTRegs, sizeof(S3C6410_GPIO_REG)); m_vpIOPORTRegs= NULL; } } return RetValue; //WriteDriveHeadReg(0x40); }