bool X86AtaDevice::isAttached() const { softReset(); /* waits until master drive is ready again */ outb(_ioPort + kAtaRegisterDriveSelect, 0xA0 | _slaveBit << 4); outb(_ioPort + kAtaRegisterLbaLow, 0x0); outb(_ioPort + kAtaRegisterLbaMid, 0x0); outb(_ioPort + kAtaRegisterLbaHigh, 0x0); outb(_ioPort + kAtaRegisterCommand, 0xEC); return waitForStatus(-1) != 0; }
void testProGas(void) { /* subscribe events */ TEST(bcm_gas_subscribe_event((void *)0x12345678, eventCallback), "bcm_gas_subscribe_event failed"); /* initialize GAS protocol */ TEST(bcm_gas_initialize(), "bcm_gas_initialize failed"); { uint16 channel = 11; struct ether_addr dst = {{0x00, 0x26, 0x5e, 0x1b, 0x13, 0x5e}}; bcm_gas_t *gas; uint16 status; gas = bcm_gas_create(wl(), 0, channel, &dst); TEST(gas != 0, "bcm_gas_create failed"); TEST(bcm_gas_set_query_request(gas, 10, (uint8 *)"helloworld"), "bcm_gas_set_query_request failed"); TEST(bcm_gas_start(gas), "bcm_gas_start failed"); waitForStatus(gas, 30 * 1000, &status); verifyResponseData(gas, status); TEST(bcm_gas_start(gas), "bcm_gas_start failed"); waitForStatus(gas, 30 * 1000, &status); verifyResponseData(gas, status); TEST(bcm_gas_destroy(gas), "bcm_gas_destroy failed"); } /* deinitialize GAS protocol */ TEST(bcm_gas_deinitialize(), "bcm_gas_deinitialize failed"); /* unsubscribe events */ TEST(bcm_gas_unsubscribe_event(eventCallback), "proGasUnubscribeEvent failed"); }
uint8_t X86AtaDevice::waitUntilReady(bool errorCheck) const { uint8_t status = 0; ioWait(); status = waitForStatus(-1); if (errorCheck) { status = inb(_ioPort + kAtaRegisterStatus); if (status & kAtaStatusBitError) return 1; if (status & kAtaStatusBitDriveFault) return 1; if (!(status & kAtaStatusBitDRQ)) return 1; } return 0; }
bool sendHdCommand(HdCommand *command) { if (waitForStatus(STATUS_BSY, 0, HD_TIMEOUT) == TRUE) { outByte(REG_DEV_CTRL, 0); outByte(REG_FEATURES, command->features); outByte(REG_NSECTOR, command->count); outByte(REG_LBA_LOW, command->lbaLow); outByte(REG_LBA_MID, command->lbaMid); outByte(REG_LBA_HIGH, command->lbaHigh); outByte(REG_DEVICE, command->device); outByte(REG_CMD, command->command); return TRUE; } else { return FALSE; } }
void readHardSector(u32 sector, u8 *buffer, int sectorCount) { command.features = 0; command.count = sectorCount; command.lbaLow = sector & 0xFF; command.lbaMid = (sector >> 8) & 0xFF; command.lbaHigh = (sector >> 16) & 0xFF; command.device = MAKE_DEVICE_REG(1, 0, (sector >> 24) & 0xF); command.command = ATA_READ; isHardDiskReady = FALSE; sendHdCommand(&command); int sectorLeft = command.count; while (sectorLeft>0) { waitForStatus(STATUS_BSY, 0, HD_TIMEOUT); readPort(REG_DATA, buffer, 512); buffer+=512; sectorLeft--; } }
void testProGasIncoming(void) { uint16 status; /* subscribe events */ TEST(bcm_gas_subscribe_event((void *)0x12345678, eventCallback), "bcm_gas_subscribe_event failed"); /* initialize GAS protocol */ TEST(bcm_gas_initialize(), "bcm_gas_initialize failed"); while (1) { waitForStatus(0, 60 * 1000, &status); } /* deinitialize GAS protocol */ TEST(bcm_gas_deinitialize(), "bcm_gas_deinitialize failed"); /* unsubscribe events */ TEST(bcm_gas_unsubscribe_event(eventCallback), "proGasUnubscribeEvent failed"); }