2016-07-15 06:51:11 -04:00
|
|
|
//
|
2016-09-25 20:05:56 -04:00
|
|
|
// DiskController.hpp
|
2016-07-15 06:51:11 -04:00
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 14/07/2016.
|
|
|
|
// Copyright © 2016 Thomas Harte. All rights reserved.
|
|
|
|
//
|
|
|
|
|
2016-09-25 20:05:56 -04:00
|
|
|
#ifndef Storage_Disk_Controller_hpp
|
|
|
|
#define Storage_Disk_Controller_hpp
|
2016-07-15 06:51:11 -04:00
|
|
|
|
2016-09-25 21:24:16 -04:00
|
|
|
#include "Drive.hpp"
|
2016-07-15 08:28:34 -04:00
|
|
|
#include "DigitalPhaseLockedLoop.hpp"
|
2016-12-24 13:07:23 -05:00
|
|
|
#include "PCMSegment.hpp"
|
2016-12-24 22:51:26 -05:00
|
|
|
#include "PCMPatchedTrack.hpp"
|
2016-07-29 07:31:02 -04:00
|
|
|
#include "../TimedEventLoop.hpp"
|
2016-07-15 06:51:11 -04:00
|
|
|
|
|
|
|
namespace Storage {
|
2016-08-27 17:15:09 -04:00
|
|
|
namespace Disk {
|
2016-07-15 06:51:11 -04:00
|
|
|
|
2016-08-01 06:04:55 -04:00
|
|
|
/*!
|
2016-09-25 21:24:16 -04:00
|
|
|
Provides the shell for emulating a disk controller — something that is connected to a disk drive and uses a
|
|
|
|
phase locked loop ('PLL') to decode a bit stream from the surface of the disk.
|
2016-08-01 06:04:55 -04:00
|
|
|
|
|
|
|
Partly abstract; it is expected that subclasses will provide methods to deal with receiving a newly-recognised
|
|
|
|
bit from the PLL and with crossing the index hole.
|
|
|
|
|
2016-09-25 21:24:16 -04:00
|
|
|
TODO: communication of head size and permissible stepping extents, appropriate simulation of gain.
|
2016-08-01 06:04:55 -04:00
|
|
|
*/
|
2016-09-25 20:05:56 -04:00
|
|
|
class Controller: public DigitalPhaseLockedLoop::Delegate, public TimedEventLoop {
|
2016-09-25 21:24:16 -04:00
|
|
|
protected:
|
2016-08-01 06:04:55 -04:00
|
|
|
/*!
|
|
|
|
Constructs a @c DiskDrive that will be run at @c clock_rate and runs its PLL at @c clock_rate*clock_rate_multiplier,
|
|
|
|
spinning inserted disks at @c revolutions_per_minute.
|
|
|
|
*/
|
2016-09-25 20:05:56 -04:00
|
|
|
Controller(unsigned int clock_rate, unsigned int clock_rate_multiplier, unsigned int revolutions_per_minute);
|
2016-07-15 08:28:34 -04:00
|
|
|
|
2016-08-01 06:04:55 -04:00
|
|
|
/*!
|
2016-09-18 22:03:06 -04:00
|
|
|
Communicates to the PLL the expected length of a bit as a fraction of a second.
|
2016-08-01 06:04:55 -04:00
|
|
|
*/
|
2016-07-15 08:28:34 -04:00
|
|
|
void set_expected_bit_length(Time bit_length);
|
2016-07-15 06:51:11 -04:00
|
|
|
|
2016-08-01 06:04:55 -04:00
|
|
|
/*!
|
|
|
|
Advances the drive by @c number_of_cycles cycles.
|
|
|
|
*/
|
2016-07-29 11:03:09 -04:00
|
|
|
void run_for_cycles(int number_of_cycles);
|
2016-07-15 06:51:11 -04:00
|
|
|
|
2016-08-01 06:04:55 -04:00
|
|
|
/*!
|
2016-09-25 21:24:16 -04:00
|
|
|
Sets the current drive.
|
2016-08-01 06:04:55 -04:00
|
|
|
*/
|
2016-09-25 21:24:16 -04:00
|
|
|
void set_drive(std::shared_ptr<Drive> drive);
|
2016-12-25 21:06:58 -05:00
|
|
|
|
|
|
|
/*!
|
|
|
|
Announces that the track the drive sees is about to change for a reason unknownt to the controller.
|
|
|
|
*/
|
2016-09-25 21:24:16 -04:00
|
|
|
void invalidate_track();
|
2016-08-01 06:04:55 -04:00
|
|
|
|
|
|
|
/*!
|
|
|
|
Enables or disables the disk motor.
|
|
|
|
*/
|
2016-07-15 06:51:11 -04:00
|
|
|
void set_motor_on(bool motor_on);
|
|
|
|
|
2016-11-30 22:26:02 -05:00
|
|
|
/*!
|
|
|
|
@returns @c true if the motor is on; @c false otherwise.
|
|
|
|
*/
|
|
|
|
bool get_motor_on();
|
|
|
|
|
2016-12-07 22:19:20 -05:00
|
|
|
/*!
|
2016-12-25 09:19:18 -05:00
|
|
|
Begins write mode, initiating a PCM sampled region of data. Bits should be written via
|
|
|
|
@c write_bit. They will be written with the length set via @c set_expected_bit_length.
|
|
|
|
It is acceptable to supply a backlog of bits. Flux transition events will not be reported
|
|
|
|
while writing.
|
2016-12-07 22:19:20 -05:00
|
|
|
*/
|
|
|
|
void begin_writing();
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Writes the bit @c value as the next in the PCM stream initiated by @c begin_writing.
|
|
|
|
*/
|
|
|
|
void write_bit(bool value);
|
|
|
|
|
|
|
|
/*!
|
2016-12-25 09:19:18 -05:00
|
|
|
Ends write mode, switching back to read mode. The drive will stop overwriting events.
|
2016-12-07 22:19:20 -05:00
|
|
|
*/
|
|
|
|
void end_writing();
|
|
|
|
|
2016-08-01 06:04:55 -04:00
|
|
|
/*!
|
|
|
|
Should be implemented by subclasses; communicates each bit that the PLL recognises, also specifying
|
|
|
|
the amount of time since the index hole was last seen.
|
|
|
|
*/
|
2016-07-15 08:28:34 -04:00
|
|
|
virtual void process_input_bit(int value, unsigned int cycles_since_index_hole) = 0;
|
2016-08-01 06:04:55 -04:00
|
|
|
|
|
|
|
/*!
|
2016-12-25 12:31:38 -05:00
|
|
|
Should be implemented by subclasses; communicates that the index hole has been reached.
|
2016-08-01 06:04:55 -04:00
|
|
|
*/
|
2016-07-15 08:28:34 -04:00
|
|
|
virtual void process_index_hole() = 0;
|
|
|
|
|
2016-12-25 12:31:38 -05:00
|
|
|
/*!
|
|
|
|
Should be implemented by subclasses if they implement writing; communicates that
|
|
|
|
all bits supplied to write_bit have now been written.
|
|
|
|
*/
|
|
|
|
virtual void process_write_completed();
|
|
|
|
|
2016-07-29 07:31:02 -04:00
|
|
|
// for TimedEventLoop
|
|
|
|
virtual void process_next_event();
|
|
|
|
|
2016-09-25 21:24:16 -04:00
|
|
|
// to satisfy DigitalPhaseLockedLoop::Delegate
|
|
|
|
void digital_phase_locked_loop_output_bit(int value);
|
|
|
|
|
|
|
|
bool get_is_track_zero();
|
|
|
|
void step(int direction);
|
2016-12-01 21:13:16 -05:00
|
|
|
virtual bool get_drive_is_ready();
|
2016-12-25 09:46:12 -05:00
|
|
|
bool get_drive_is_read_only();
|
2016-09-25 21:24:16 -04:00
|
|
|
|
2016-07-15 08:28:34 -04:00
|
|
|
private:
|
2016-12-03 11:59:28 -05:00
|
|
|
Time bit_length_;
|
|
|
|
unsigned int clock_rate_;
|
|
|
|
unsigned int clock_rate_multiplier_;
|
|
|
|
Time rotational_multiplier_;
|
2016-07-29 05:19:01 -04:00
|
|
|
|
2016-12-03 11:59:28 -05:00
|
|
|
std::shared_ptr<DigitalPhaseLockedLoop> pll_;
|
|
|
|
std::shared_ptr<Drive> drive_;
|
|
|
|
std::shared_ptr<Track> track_;
|
2016-12-24 21:47:57 -05:00
|
|
|
unsigned int cycles_since_index_hole_;
|
2016-07-29 05:19:01 -04:00
|
|
|
|
2016-12-24 20:54:27 -05:00
|
|
|
inline void get_next_event(const Time &duration_already_passed);
|
2016-12-03 11:59:28 -05:00
|
|
|
Track::Event current_event_;
|
|
|
|
bool motor_is_on_;
|
2016-09-25 21:24:16 -04:00
|
|
|
|
2016-12-24 13:07:23 -05:00
|
|
|
bool is_reading_;
|
2016-12-24 22:51:26 -05:00
|
|
|
std::shared_ptr<PCMPatchedTrack> patched_track_;
|
2016-12-24 13:07:23 -05:00
|
|
|
PCMSegment write_segment_;
|
|
|
|
Time write_start_time_;
|
|
|
|
|
2016-12-25 12:31:38 -05:00
|
|
|
Time cycles_until_bits_written_;
|
|
|
|
Time cycles_per_bit_;
|
|
|
|
|
2016-09-25 21:24:16 -04:00
|
|
|
void setup_track();
|
2016-12-26 14:24:33 -05:00
|
|
|
Time get_time_into_track();
|
2016-07-15 06:51:11 -04:00
|
|
|
};
|
|
|
|
|
2016-08-27 17:15:09 -04:00
|
|
|
}
|
2016-07-15 06:51:11 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* DiskDrive_hpp */
|