/** Detect whether the disk in the drive is changed or not. @param[in] FdcDev A pointer to FDC_BLK_IO_DEV @retval EFI_SUCCESS No disk media change @retval EFI_DEVICE_ERROR Fail to do the recalibrate or seek operation @retval EFI_NO_MEDIA No disk in the drive @retval EFI_MEDIA_CHANGED There is a new disk in the drive **/ EFI_STATUS DisketChanged ( IN FDC_BLK_IO_DEV *FdcDev ) { EFI_STATUS Status; UINT8 Data; // // Check change line // Data = FdcReadPort (FdcDev, FDC_REGISTER_DIR); // // Io delay // MicroSecondDelay (50); if ((Data & DIR_DCL) == 0x80) { // // disk change line is active // if (FdcDev->PresentCylinderNumber != 0) { Status = Recalibrate (FdcDev); } else { Status = Seek (FdcDev, 0x30); } if (EFI_ERROR (Status)) { FdcDev->ControllerState->NeedRecalibrate = TRUE; return EFI_DEVICE_ERROR; // // Fail to do the seek or recalibrate operation // } Data = FdcReadPort (FdcDev, FDC_REGISTER_DIR); // // Io delay // MicroSecondDelay (50); if ((Data & DIR_DCL) == 0x80) { return EFI_NO_MEDIA; } return EFI_MEDIA_CHANGED; } return EFI_SUCCESS; }
/// Performs a pseudo re-calibration on the data, returning a copy of the newly calibrated data /// The original data are left unmodified. OIDataList Recalibrate(const OIDataList & data, OICalibratorPtr old_cal, OICalibratorPtr new_cal) { // Make a deep copy of the data OIDataList tmp = copy(data); COIV2Row * v2_row; COIT3Row * t3_row; // Now recalibrate. Use RTTI to decide which function we should call. for(OIDataRowPtr row: tmp) { v2_row = dynamic_cast<COIV2Row*>(row.get()); if(v2_row != NULL) Recalibrate(v2_row, old_cal, new_cal); t3_row = dynamic_cast<COIT3Row*>(row.get()); if(t3_row != NULL) Recalibrate(t3_row, old_cal, new_cal); // else if(row->GetType() == COIDataRow::OI_T3) // Recalibrate_T3(row, old_cal, new_cal); } return tmp; }
MainDisplay::MainDisplay(UserInterface& ui) : ui(ui), inventory(ui, ui.character), pause_indicators(ui), mini_menu(ui) { // Set the positions and sizes of UI elements _width = get_natural_width(); message_bar = {0, 0, _width, 30}; map_window = {0, message_bar.height, _width, ui.tile_height * map_height}; status_bar = {0, message_bar.height + map_window.height, _width, 30}; _height = get_natural_height(); Reset(); Recalibrate(); ui.RegisterCallback_KeyInput(boost::bind(&MainDisplay::InputKey, this, _1, _2)); widget_order.push_front(&inventory); widget_order.push_front(&pause_indicators); widget_order.push_front(&mini_menu); }
void MainDisplay::Draw() { if (ui.this_zone == nullptr) { al_clear_to_color(ui.Colour("gray")); ui.Print("no vision", _width/2, _height/2); return; } // check if recalibration is required. (note: this is a bit of a hack. I'll probably remove it later.) if (_width != ui.get_display_width() || _height != ui.get_display_height() || b_inventory_open != (inventory.get_width() != 0)) { Recalibrate(); } al_clear_to_color(ui.Colour(0.35, 0.40, 0.2)); DrawMap(); if (b_inventory_open) { inventory.SetAction(next_action.act); //inventory.Draw(); } DrawMessageBar(); DrawStatusBar(); //DrawPauseIndicators(); //pause_indicators.Draw(); ui.Print((boost::format("fps:%d") % ui.get_fps()).str(), _width - 50, _height - 20); // draw widgets in reverse order, so that front items are drawn on top. for (auto it = widget_order.rbegin(); it != widget_order.rend(); ++it) { (*it)->Draw(); } }
static NTSTATUS NTAPI InitController(PCONTROLLER_INFO ControllerInfo) /* * FUNCTION: Initialize a newly-found controller * ARGUMENTS: * ControllerInfo: pointer to the controller to be initialized * RETURNS: * STATUS_SUCCESS if the controller is successfully initialized * STATUS_IO_DEVICE_ERROR otherwise */ { int i; UCHAR HeadLoadTime; UCHAR HeadUnloadTime; UCHAR StepRateTime; PAGED_CODE(); ASSERT(ControllerInfo); TRACE_(FLOPPY, "InitController called with Controller 0x%p\n", ControllerInfo); KeClearEvent(&ControllerInfo->SynchEvent); INFO_(FLOPPY, "InitController: resetting the controller\n"); /* Reset the controller */ if(HwReset(ControllerInfo) != STATUS_SUCCESS) { WARN_(FLOPPY, "InitController: unable to reset controller\n"); return STATUS_IO_DEVICE_ERROR; } /* All controllers should support this so * if we get something strange back then we * know that this isn't a floppy controller */ if (HwGetVersion(ControllerInfo) <= 0) { WARN_(FLOPPY, "InitController: unable to contact controller\n"); return STATUS_NO_SUCH_DEVICE; } /* Reset the controller to avoid interrupt garbage on certain controllers */ if(HwReset(ControllerInfo) != STATUS_SUCCESS) { WARN_(FLOPPY, "InitController: unable to reset controller #2\n"); return STATUS_IO_DEVICE_ERROR; } INFO_(FLOPPY, "InitController: setting data rate\n"); /* Set data rate */ if(HwSetDataRate(ControllerInfo, DRSR_DSEL_500KBPS) != STATUS_SUCCESS) { WARN_(FLOPPY, "InitController: unable to set data rate\n"); return STATUS_IO_DEVICE_ERROR; } INFO_(FLOPPY, "InitController: waiting for initial interrupt\n"); /* Wait for an interrupt */ WaitForControllerInterrupt(ControllerInfo); /* Reset means you have to clear each of the four interrupts (one per drive) */ for(i = 0; i < MAX_DRIVES_PER_CONTROLLER; i++) { INFO_(FLOPPY, "InitController: Sensing interrupt %d\n", i); if(HwSenseInterruptStatus(ControllerInfo) != STATUS_SUCCESS) { WARN_(FLOPPY, "InitController: Unable to clear interrupt 0x%x\n", i); return STATUS_IO_DEVICE_ERROR; } } INFO_(FLOPPY, "InitController: done sensing interrupts\n"); /* Next, see if we have the right version to do implied seek */ if(HwGetVersion(ControllerInfo) == VERSION_ENHANCED) { /* If so, set that up -- all defaults below except first TRUE for EIS */ if(HwConfigure(ControllerInfo, TRUE, TRUE, FALSE, 0, 0) != STATUS_SUCCESS) { WARN_(FLOPPY, "InitController: unable to set up implied seek\n"); ControllerInfo->ImpliedSeeks = FALSE; } else { INFO_(FLOPPY, "InitController: implied seeks set!\n"); ControllerInfo->ImpliedSeeks = TRUE; } /* * FIXME: Figure out the answer to the below * * I must admit that I'm really confused about the Model 30 issue. At least one * important bit (the disk change bit in the DIR) is flipped if this is a Model 30 * controller. However, at least one other floppy driver believes that there are only * two computers that are guaranteed to have a Model 30 controller: * - IBM Thinkpad 750 * - IBM PS2e * * ...and another driver only lists a config option for "thinkpad", that flips * the change line. A third driver doesn't mention the Model 30 issue at all. * * What I can't tell is whether or not the average, run-of-the-mill computer now has * a Model 30 controller. For the time being, I'm going to wire this to FALSE, * and just not support the computers mentioned above, while I try to figure out * how ubiquitous these newfangled 30 thingies are. */ //ControllerInfo->Model30 = TRUE; ControllerInfo->Model30 = FALSE; } else { INFO_(FLOPPY, "InitController: enhanced version not supported; disabling implied seeks\n"); ControllerInfo->ImpliedSeeks = FALSE; ControllerInfo->Model30 = FALSE; } /* Specify */ WARN_(FLOPPY, "FIXME: Figure out speed\n"); HeadLoadTime = SPECIFY_HLT_500K; HeadUnloadTime = SPECIFY_HUT_500K; StepRateTime = SPECIFY_SRT_500K; INFO_(FLOPPY, "InitController: issuing specify command to controller\n"); /* Don't disable DMA --> enable dma (dumb & confusing) */ if(HwSpecify(ControllerInfo, HeadLoadTime, HeadUnloadTime, StepRateTime, FALSE) != STATUS_SUCCESS) { WARN_(FLOPPY, "InitController: unable to specify options\n"); return STATUS_IO_DEVICE_ERROR; } /* Init the stop stuff */ KeInitializeDpc(&ControllerInfo->MotorStopDpc, MotorStopDpcFunc, ControllerInfo); KeInitializeTimer(&ControllerInfo->MotorTimer); KeInitializeEvent(&ControllerInfo->MotorStoppedEvent, NotificationEvent, FALSE); ControllerInfo->StopDpcQueued = FALSE; /* * Recalibrate each drive on the controller (depends on StartMotor, which depends on the timer stuff above) * We don't even know if there is a disk in the drive, so this may not work, but that's OK. */ for(i = 0; i < ControllerInfo->NumberOfDrives; i++) { INFO_(FLOPPY, "InitController: recalibrating drive 0x%x on controller 0x%p\n", i, ControllerInfo); Recalibrate(&ControllerInfo->DriveInfo[i]); } INFO_(FLOPPY, "InitController: done initializing; returning STATUS_SUCCESS\n"); return STATUS_SUCCESS; }
NTSTATUS NTAPI ResetChangeFlag(PDRIVE_INFO DriveInfo) /* * FUNCTION: Reset the drive's change flag (as reflected in the DIR) * ARGUMENTS: * DriveInfo: the drive to reset * RETURNS: * STATUS_SUCCESS if the changeline is cleared * STATUS_NO_MEDIA_IN_DEVICE if the changeline cannot be cleared * STATUS_IO_DEVICE_ERROR if the controller cannot be communicated with * NOTES: * - Change reset procedure: recalibrate, seek 1, seek 0 * - If the line is still set after that, there's clearly no disk in the * drive, so we return STATUS_NO_MEDIA_IN_DEVICE * - PAGED_CODE because we wait */ { BOOLEAN DiskChanged; PAGED_CODE(); ASSERT(DriveInfo); TRACE_(FLOPPY, "ResetChangeFlag called\n"); /* Try to recalibrate. We don't care if it works. */ Recalibrate(DriveInfo); /* clear spurious interrupts in prep for seeks */ KeClearEvent(&DriveInfo->ControllerInfo->SynchEvent); /* must re-start the drive because Recalibrate() stops it */ StartMotor(DriveInfo); /* Seek to 1 */ if(HwSeek(DriveInfo, 1) != STATUS_SUCCESS) { WARN_(FLOPPY, "ResetChangeFlag(): HwSeek failed; returning STATUS_IO_DEVICE_ERROR\n"); StopMotor(DriveInfo->ControllerInfo); return STATUS_IO_DEVICE_ERROR; } WaitForControllerInterrupt(DriveInfo->ControllerInfo); if(HwSenseInterruptStatus(DriveInfo->ControllerInfo) != STATUS_SUCCESS) { WARN_(FLOPPY, "ResetChangeFlag(): HwSenseInterruptStatus failed; bailing out\n"); StopMotor(DriveInfo->ControllerInfo); return STATUS_IO_DEVICE_ERROR; } /* Seek back to 0 */ if(HwSeek(DriveInfo, 0) != STATUS_SUCCESS) { WARN_(FLOPPY, "ResetChangeFlag(): HwSeek failed; returning STATUS_IO_DEVICE_ERROR\n"); StopMotor(DriveInfo->ControllerInfo); return STATUS_IO_DEVICE_ERROR; } WaitForControllerInterrupt(DriveInfo->ControllerInfo); if(HwSenseInterruptStatus(DriveInfo->ControllerInfo) != STATUS_SUCCESS) { WARN_(FLOPPY, "ResetChangeFlag(): HwSenseInterruptStatus #2 failed; bailing\n"); StopMotor(DriveInfo->ControllerInfo); return STATUS_IO_DEVICE_ERROR; } /* Check the change bit */ if(HwDiskChanged(DriveInfo, &DiskChanged) != STATUS_SUCCESS) { WARN_(FLOPPY, "ResetChangeFlag(): HwDiskChanged failed; returning STATUS_IO_DEVICE_ERROR\n"); StopMotor(DriveInfo->ControllerInfo); return STATUS_IO_DEVICE_ERROR; } StopMotor(DriveInfo->ControllerInfo); /* if the change flag is still set, there's probably no media in the drive. */ if(DiskChanged) return STATUS_NO_MEDIA_IN_DEVICE; /* else we're done! */ return STATUS_SUCCESS; }
/** Do recalibrate and check if the drive is present or not and set the media parameters if the driver is present. @param[in] FdcDev A pointer to the FDC_BLK_IO_DEV @retval EFI_SUCCESS The floppy disk drive is present @retval EFI_DEVICE_ERROR The floppy disk drive is not present **/ EFI_STATUS FddIdentify ( IN FDC_BLK_IO_DEV *FdcDev ) { EFI_STATUS Status; // // Set Floppy Disk Controller's motor on // Status = MotorOn (FdcDev); if (EFI_ERROR (Status)) { return EFI_DEVICE_ERROR; } Status = Recalibrate (FdcDev); if (EFI_ERROR (Status)) { MotorOff (FdcDev); FdcDev->ControllerState->NeedRecalibrate = TRUE; return EFI_DEVICE_ERROR; } // // Set Media Parameter // FdcDev->BlkIo.Media->RemovableMedia = TRUE; FdcDev->BlkIo.Media->MediaPresent = TRUE; FdcDev->BlkIo.Media->MediaId = 0; // // Check Media // Status = DisketChanged (FdcDev); if (Status == EFI_NO_MEDIA) { FdcDev->BlkIo.Media->MediaPresent = FALSE; } else if ((Status != EFI_MEDIA_CHANGED) && (Status != EFI_SUCCESS)) { MotorOff (FdcDev); return Status; } // // Check Disk Write Protected // Status = SenseDrvStatus (FdcDev, 0); if (Status == EFI_WRITE_PROTECTED) { FdcDev->BlkIo.Media->ReadOnly = TRUE; } else if (Status == EFI_SUCCESS) { FdcDev->BlkIo.Media->ReadOnly = FALSE; } else { return EFI_DEVICE_ERROR; } MotorOff (FdcDev); // // Set Media Default Type // FdcDev->BlkIo.Media->BlockSize = DISK_1440K_BYTEPERSECTOR; FdcDev->BlkIo.Media->LastBlock = DISK_1440K_EOT * 2 * (DISK_1440K_MAXTRACKNUM + 1) - 1; return EFI_SUCCESS; }
/** Set the head of floppy drive to the new cylinder. @param FdcDev FDC_BLK_IO_DEV *: A pointer to FDC_BLK_IO_DEV @param Lba EFI_LBA : The logic block address want to seek @retval EFI_SUCCESS: Execute the Seek operation successfully @retval EFI_DEVICE_ERROR: Fail to execute the Seek operation **/ EFI_STATUS Seek ( IN FDC_BLK_IO_DEV *FdcDev, IN EFI_LBA Lba ) { FDD_SEEK_CMD Command; UINT8 EndOfTrack; UINT8 Head; UINT8 Cylinder; UINT8 StatusRegister0; UINT8 *CommandPointer; UINT8 PresentCylinderNumber; UINTN Index; UINT8 DelayTime; if (FdcDev->ControllerState->NeedRecalibrate) { if (EFI_ERROR (Recalibrate (FdcDev))) { FdcDev->ControllerState->NeedRecalibrate = TRUE; return EFI_DEVICE_ERROR; } } EndOfTrack = DISK_1440K_EOT; // // Calculate cylinder based on Lba and EOT // Cylinder = (UINT8) ((UINTN) Lba / EndOfTrack / 2); // // if the destination cylinder is the present cylinder, unnecessary to do the // seek operation // if (FdcDev->PresentCylinderNumber == Cylinder) { return EFI_SUCCESS; } // // Calculate the head : 0 or 1 // Head = (UINT8) ((UINTN) Lba / EndOfTrack % 2); ZeroMem (&Command, sizeof (FDD_SEEK_CMD)); Command.CommandCode = SEEK_CMD; if (FdcDev->Disk == FdcDisk0) { Command.DiskHeadSel = 0; // // 0 // } else { Command.DiskHeadSel = 1; // // 1 // } Command.DiskHeadSel = (UINT8) (Command.DiskHeadSel | (Head << 2)); Command.NewCylinder = Cylinder; CommandPointer = (UINT8 *) (&Command); for (Index = 0; Index < sizeof (FDD_SEEK_CMD); Index++) { if (EFI_ERROR (DataOutByte (FdcDev, CommandPointer++))) { return EFI_DEVICE_ERROR; } } // // Io delay // MicroSecondDelay (100); // // Calculate waiting time // if (FdcDev->PresentCylinderNumber > Cylinder) { DelayTime = (UINT8) (FdcDev->PresentCylinderNumber - Cylinder); } else { DelayTime = (UINT8) (Cylinder - FdcDev->PresentCylinderNumber); } MicroSecondDelay ((DelayTime + 1) * 4000); if (EFI_ERROR (SenseIntStatus (FdcDev, &StatusRegister0, &PresentCylinderNumber))) { return EFI_DEVICE_ERROR; } if ((StatusRegister0 & 0xf0) == 0x20) { FdcDev->PresentCylinderNumber = Command.NewCylinder; return EFI_SUCCESS; } else { FdcDev->ControllerState->NeedRecalibrate = TRUE; return EFI_DEVICE_ERROR; } }
void MeasuringReceiver::ProcessThread() { IQCapture capture; double center, power, relative, offset; std::list<double> average; std::vector<complex_f> full; while(running) { // Reinitialize to start tuned level measurements over if(reinitialize) { ampGroup->button(0)->setChecked(true); // Select high power emit updateRangeEnabled(rangeLevelNone); power = 0.0; offset = 0.0; relative = 0.0; reinitialize = false; recalibrate = true; } // Recalibrates to a new range // Range must be chosen before entering this block if(recalibrate) { offset += (power - relative); Recalibrate(center, power, capture); relative = power; full.resize(descriptor.returnLen * 3); average.clear(); } device->GetIQFlush(&capture, true); simdCopy_32fc(&capture.capture[0], &full[0], descriptor.returnLen); for(int i = 1; i < 3; i++) { device->GetIQ(&capture); simdCopy_32fc(&capture.capture[0], &full[i * descriptor.returnLen], descriptor.returnLen); } getPeakCorrelation(&full[0], descriptor.returnLen*3, center, center, power, descriptor.sampleRate); std::cout << "Post center " << center << " " << power << "\n"; if(device->ADCOverflow()) { emit updateRangeLevelText("IF Overload", rangeColorRed); } else { if(GetCurrentRange() == MeasRcvrRangeHigh) { if(power > -25.0) { emit updateRangeLevelText("", rangeColorBlack); emit updateRangeEnabled(rangeLevelNone); } else if(power < -40.0) { emit updateRangeLevelText(MeasRcvrRangeMid, "Passed Mid-Range", rangeColorRed); emit updateRangeEnabled(rangeLevelNone); } else { emit updateRangeLevelText(MeasRcvrRangeMid, "Recal at new range", rangeColorOrange); emit updateRangeEnabled(MeasRcvrRangeMid); } } else if(GetCurrentRange() == MeasRcvrRangeMid) { if(power > -50.0) { emit updateRangeLevelText("", rangeColorBlack); emit updateRangeEnabled(rangeLevelNone); } else if(power < -65.0) { emit updateRangeLevelText(MeasRcvrRangeLow, "Passed Low-Range", rangeColorRed); emit updateRangeEnabled(rangeLevelNone); } else { emit updateRangeLevelText(MeasRcvrRangeLow, "Recal at new range", rangeColorOrange); emit updateRangeEnabled(MeasRcvrRangeLow); } } else { emit updateRangeLevelText("", rangeColorBlack); emit updateRangeEnabled(rangeLevelNone); } } // Lets update our text double diff = (power - relative) + offset; average.push_front(diff); while(average.size() > 20) average.pop_back(); double avgPower = 0.0; for(double d : average) avgPower += d; avgPower /= average.size(); QString centerStr, powerStr, relativeStr, averageStr; centerStr = Frequency(freqEntry->GetFrequency() + center * descriptor.sampleRate/*312500.0*/).GetFreqString(); powerStr.sprintf("%.3f dBm", power); relativeStr.sprintf("%.3f dB", diff); averageStr.sprintf("%.3f dB", avgPower); emit updateLabels(centerStr, powerStr, relativeStr, averageStr); } device->Abort(); }