📄 ide.c
字号:
// a running system, therefore we must install // a INT handler and some other parts :-) // // // Clear CF_INT_SENS_MASK. // EICR &= ~CF_INT_SENS_MASK; // // Check the status of the compact flash. // bValue = (PINE & BV(CF_IRQ)); if (bValue == CF_AVAILABLE) { gbCFMountStatus = CF_AVAILABLE; // // The rising edge between two samples // of INTX generates an interrupt request. // EICR |= CF_INT_RISING_EDGE; } else { gbCFMountStatus = CF_NOT_AVAILABLE; // // The falling edge between two samples // of INTX generates an interrupt request. // EICR |= CF_INT_FALLING_EDGE; } nError = NutRegisterIrqHandler(&sig_INTERRUPT6, CFInterrupt, NULL); if (nError == FALSE) { NutThreadCreate("cfchange", CFChange, NULL, 640); sbi(EIMSK, CF_IRQ); } break; } } NutExitCritical(); HardwareReset(&sDrive[0]); nError = IDE_OK; return (nError);}/************************************************************//* IDEMountDevice *//************************************************************/int IDEMountDevice(BYTE bDevice, BYTE * pSectorBuffer){ int nError; LPDRIVE pDrive; pDrive = NULL; IDELock(); if (bDevice >= IDE_MAX_SUPPORTED_DEVICE) { nError = IDE_ERROR; } else { pDrive = &sDrive[bDevice]; pDrive->wFlags = 0;#if (IDE_SUPPORT_CHS == 1) // // CHS values // pDrive->wCylinders = 0; pDrive->wHeads = 0; pDrive->wSectorsPerTrack = 0;#endif // // LBA value // pDrive->dwTotalSectors = 0; nError = DeviceDiag(pDrive); if (pDrive->wFlags & IDE_SUPPORT_PACKET) {#if (IDE_SUPPORT_ATAPI == 1) pDrive->wSectorSize = ATAPI_SECTOR_SIZE; nError = GetDeviceInfoPacket(pDrive, pSectorBuffer); if (pDrive->wFlags & IDE_READY) { nError = IDE_OK; }#endif } else { if (nError != IDE_OK) { // // Try it again // nError = DeviceDiag(pDrive); } if (nError == IDE_OK) { pDrive->wSectorSize = IDE_SECTOR_SIZE; nError = GetDeviceInfo(pDrive, pSectorBuffer); if (pDrive->wFlags & IDE_READY) { nError = IDE_OK; } } } } /* (bDevice >= IDE_MAX_SUPPORTED_DEVICE) */ IDEFree(); return (nError);}/************************************************************//* IDEGetSectorSize *//************************************************************/int IDEGetSectorSize(BYTE bDevice){ int nSectorSize; LPDRIVE pDrive; nSectorSize = 0; IDELock(); if (bDevice >= IDE_MAX_SUPPORTED_DEVICE) { nSectorSize = 0; } else { pDrive = &sDrive[bDevice]; nSectorSize = pDrive->wSectorSize; } IDEFree(); return (nSectorSize);}/************************************************************//* IDEIsCDROMDevice *//************************************************************/int IDEIsCDROMDevice(BYTE bDevice){ int nIsCDROM; LPDRIVE pDrive; nIsCDROM = FALSE; IDELock(); if (bDevice >= IDE_MAX_SUPPORTED_DEVICE) { nIsCDROM = FALSE; } else { pDrive = &sDrive[bDevice]; if ((pDrive->wFlags & IDE_READY) && (pDrive->wFlags & IDE_CDROM_DEVICE)) { nIsCDROM = TRUE; } } IDEFree(); return (nIsCDROM);}/************************************************************//* IDEIsZIPDevice *//************************************************************/int IDEIsZIPDevice(BYTE bDevice){ int nIsZIP; LPDRIVE pDrive; nIsZIP = FALSE; IDELock(); if (bDevice >= IDE_MAX_SUPPORTED_DEVICE) { nIsZIP = FALSE; } else { pDrive = &sDrive[bDevice]; if ((pDrive->wFlags & IDE_READY) && (pDrive->wFlags & IDE_ZIP_DEVICE)) { nIsZIP = TRUE; } } IDEFree(); return (nIsZIP);}/************************************************************//* IDEUnMountDevice *//************************************************************/int IDEUnMountDevice(BYTE bDevice){ int nError = 0; LPDRIVE pDrive; pDrive = NULL; IDELock(); if (bDevice >= IDE_MAX_SUPPORTED_DEVICE) { nError = IDE_ERROR; } else { pDrive = &sDrive[bDevice]; pDrive->wFlags = 0; } IDEFree(); return (nError);}/************************************************************//* IDEGetTotalSectors *//************************************************************/DWORD IDEGetTotalSectors(BYTE bDevice){ DWORD dwTotalSectors; LPDRIVE pDrive; dwTotalSectors = 0; IDELock(); if (bDevice >= IDE_MAX_SUPPORTED_DEVICE) { dwTotalSectors = 0; } else { pDrive = &sDrive[bDevice]; dwTotalSectors = pDrive->dwTotalSectors; dwTotalSectors -= 64; } IDEFree(); return (dwTotalSectors);}/************************************************************//* IDEReadSectors *//************************************************************/int IDEReadSectors(BYTE bDevice, void *pData, DWORD dwStartSector, WORD wSectorCount){ WORD i; int nError; WORD wReadCount; LPDRIVE pDrive = 0; BYTE *pByte; nError = IDE_OK; IDELock(); if (bDevice >= IDE_MAX_SUPPORTED_DEVICE) { nError = IDE_DRIVE_NOT_FOUND; } else { pDrive = &sDrive[bDevice]; if ((pDrive->wFlags & IDE_READY) == 0) { nError = IDE_DRIVE_NOT_FOUND; } else { if ((dwStartSector + wSectorCount) > pDrive->dwTotalSectors) { nError = IDE_PARAM_ERROR; } } } if ((pDrive->wFlags & IDE_SUPPORT_PACKET) && ((wSectorCount > 1))) { // // Sorry, in this version we support // only 1 sector for PACKET devices. // nError = IDE_PARAM_ERROR; } if ((pDrive->wFlags & IDE_SUPPORT_PACKET) && (nError == IDE_OK)) {#if (IDE_SUPPORT_ATAPI == 1) // // ATAPI // ATAPI_CMD(ATAPI_CMD_READ12); i = 5; while (dwStartSector) { aATAPICmd[i--] = (BYTE) dwStartSector; dwStartSector >>= 8; } // // Reading one sector only // aATAPICmd[9] = 1; nError = ATAPISendCommand(pDrive, pData, &i); if ((nError != IDE_OK) || (i != pDrive->wSectorSize)) { nError = IDE_ERROR; }#else nError = IDE_ERROR;#endif } else { if (nError == IDE_OK) { pByte = (BYTE *) pData; while (wSectorCount > 0) { if (wSectorCount < 256) { wReadCount = wSectorCount; } else { wReadCount = 256; } nError = ReadSectors(bDevice, pByte, dwStartSector, wReadCount); if (nError != IDE_OK) { break; } dwStartSector += wReadCount; wSectorCount -= wReadCount; pByte += (wReadCount * pDrive->wSectorSize); } } } IDEFree(); return (nError);}#if (IDE_SUPPORT_WRITE == 1)/************************************************************//* IDEWriteSectors *//************************************************************/int IDEWriteSectors(BYTE bDevice, void *pData, DWORD dwStartSector, WORD wSectorCount){ int nError; WORD wWriteCount; LPDRIVE pDrive; BYTE *pByte; nError = IDE_OK; pDrive = NULL; IDELock(); if (bDevice >= IDE_MAX_SUPPORTED_DEVICE) { nError = IDE_DRIVE_NOT_FOUND; } else { pDrive = &sDrive[bDevice]; if ((dwStartSector + wSectorCount) > pDrive->dwTotalSectors) { nError = IDE_PARAM_ERROR; } if ((pDrive->wFlags & IDE_READY) == 0) { nError = IDE_DRIVE_NOT_FOUND; } if (pDrive->wFlags & IDE_READ_ONLY) { nError = IDE_NOT_SUPPORTED; } } if (nError == IDE_OK) { pByte = (BYTE *) pData; while (wSectorCount > 0) { if (wSectorCount < 256) { wWriteCount = wSectorCount; } else { wWriteCount = 256; } nError = WriteSectors(bDevice, pByte, dwStartSector, wWriteCount); if (nError != IDE_OK) { break; } dwStartSector += wWriteCount; wSectorCount -= wWriteCount; pByte += (wWriteCount * IDE_SECTOR_SIZE); } } IDEFree(); return (nError);}#endif#if (IDE_SUPPORT_ATAPI == 1)/************************************************************//* IDEATAPISetCDSpeed *//************************************************************/int IDEATAPISetCDSpeed(BYTE bDevice, WORD wSpeed){ WORD i; int nError; LPDRIVE pDrive; nError = IDE_OK; pDrive = NULL; if (bDevice >= IDE_MAX_SUPPORTED_DEVICE) { nError = IDE_DRIVE_NOT_FOUND; } else { pDrive = &sDrive[bDevice]; if ((pDrive->wFlags & IDE_READY) == 0) { nError = IDE_DRIVE_NOT_FOUND; } if ((pDrive->wFlags & IDE_SUPPORT_PACKET) == 0) { nError = IDE_NOT_SUPPORTED; } } if (nError == IDE_OK) { ATAPI_CMD(0xBB); aATAPICmd[2] = (BYTE) ((wSpeed >> 8) & 0x00FF); aATAPICmd[3] = (BYTE) (wSpeed & 0x00FF); nError = ATAPISendCommand(pDrive, NULL, &i); } return (nError);}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -