Sort out a whole bunch of other things, including cleaning up the way the

verification source is handled.
This commit is contained in:
dg
2023-05-12 23:28:25 +00:00
parent 1d77ba6429
commit dcfcc6271c
56 changed files with 2189 additions and 923 deletions

View File

@@ -4,7 +4,7 @@
#define GREASEWEAZLE_VID 0x1209
#define GREASEWEAZLE_PID 0x4d69
#define GREASEWEAZLE_ID ((GREASEWEAZLE_VID<<16) | GREASEWEAZLE_PID)
#define GREASEWEAZLE_ID ((GREASEWEAZLE_VID << 16) | GREASEWEAZLE_PID)
#define EP_OUT 0x02
#define EP_IN 0x83
@@ -13,10 +13,12 @@ extern Bytes fluxEngineToGreaseWeazle(const Bytes& fldata, nanoseconds_t clock);
extern Bytes greaseWeazleToFluxEngine(const Bytes& gwdata, nanoseconds_t clock);
extern Bytes stripPartialRotation(const Bytes& fldata);
/* Copied from https://github.com/keirf/Greaseweazle/blob/master/inc/cdc_acm_protocol.h.
/* Copied from
* https://github.com/keirf/Greaseweazle/blob/master/inc/cdc_acm_protocol.h.
*
* WANING: these headers were originally defined with 'packed', which is a gccism so it's
* been dummied out. Don't use them expecting wire protocol structures. */
* WANING: these headers were originally defined with 'packed', which is a
* gccism so it's been dummied out. Don't use them expecting wire protocol
* structures. */
#define packed /* */
@@ -25,90 +27,87 @@ extern Bytes stripPartialRotation(const Bytes& fldata);
*/
/* CMD_GET_INFO, length=3, idx. Returns 32 bytes after ACK. */
#define CMD_GET_INFO 0
/* [BOOTLOADER] CMD_UPDATE, length=6, <update_len>.
#define CMD_GET_INFO 0
/* [BOOTLOADER] CMD_UPDATE, length=6, <update_len>.
* Host follows with <update_len> bytes.
* Bootloader finally returns a status byte, 0 on success. */
/* [MAIN FIRMWARE] CMD_UPDATE, length=10, <update_len>, 0xdeafbee3.
* Host follows with <update_len> bytes.
* Main firmware finally returns a status byte, 0 on success. */
#define CMD_UPDATE 1
#define CMD_UPDATE 1
/* CMD_SEEK, length=3, cyl#. Seek to cyl# on selected drive. */
#define CMD_SEEK 2
#define CMD_SEEK 2
/* CMD_HEAD, length=3, head# (0=bottom) */
#define CMD_HEAD 3
#define CMD_HEAD 3
/* CMD_SET_PARAMS, length=3+nr, idx, <nr bytes> */
#define CMD_SET_PARAMS 4
#define CMD_SET_PARAMS 4
/* CMD_GET_PARAMS, length=4, idx, nr_bytes. Returns nr_bytes after ACK. */
#define CMD_GET_PARAMS 5
#define CMD_GET_PARAMS 5
/* CMD_MOTOR, length=4, drive#, on/off. Turn on/off a drive motor. */
#define CMD_MOTOR 6
#define CMD_MOTOR 6
/* CMD_READ_FLUX, length=2-8. Argument is gw_read_flux.
* Returns flux readings until EOStream. */
#define CMD_READ_FLUX 7
#define CMD_READ_FLUX 7
/* CMD_WRITE_FLUX, length=2-4. Argument is gw_write_flux.
* Host follows with flux readings until EOStream. */
#define CMD_WRITE_FLUX 8
#define CMD_WRITE_FLUX 8
/* CMD_GET_FLUX_STATUS, length=2. Last read/write status returned in ACK. */
#define CMD_GET_FLUX_STATUS 9
/* CMD_SWITCH_FW_MODE, length=3, <mode> */
#define CMD_SWITCH_FW_MODE 11
/* CMD_SELECT, length=3, drive#. Select drive# as current unit. */
#define CMD_SELECT 12
#define CMD_SELECT 12
/* CMD_DESELECT, length=2. Deselect current unit (if any). */
#define CMD_DESELECT 13
#define CMD_DESELECT 13
/* CMD_SET_BUS_TYPE, length=3, bus_type. Set the bus type. */
#define CMD_SET_BUS_TYPE 14
#define CMD_SET_BUS_TYPE 14
/* CMD_SET_PIN, length=4, pin#, level. */
#define CMD_SET_PIN 15
#define CMD_SET_PIN 15
/* CMD_RESET, length=2. Reset all state to initial (power on) values. */
#define CMD_RESET 16
#define CMD_RESET 16
/* CMD_ERASE_FLUX, length=6. Argument is gw_erase_flux. */
#define CMD_ERASE_FLUX 17
#define CMD_ERASE_FLUX 17
/* CMD_SOURCE_BYTES, length=6. Argument is gw_sink_source_bytes. */
#define CMD_SOURCE_BYTES 18
#define CMD_SOURCE_BYTES 18
/* CMD_SINK_BYTES, length=6. Argument is gw_sink_source_bytes. */
#define CMD_SINK_BYTES 19
#define CMD_MAX 19
#define CMD_SINK_BYTES 19
#define CMD_MAX 19
/*
* CMD_SET_BUS CODES
*/
#define BUS_NONE 0
#define BUS_IBMPC 1
#define BUS_SHUGART 2
#define BUS_APPLE2 3
#define BUS_NONE 0
#define BUS_IBMPC 1
#define BUS_SHUGART 2
#define BUS_APPLE2 3
/*
* ACK RETURN CODES
*/
#define ACK_OKAY 0
#define ACK_BAD_COMMAND 1
#define ACK_NO_INDEX 2
#define ACK_NO_TRK0 3
#define ACK_FLUX_OVERFLOW 4
#define ACK_FLUX_UNDERFLOW 5
#define ACK_WRPROT 6
#define ACK_NO_UNIT 7
#define ACK_NO_BUS 8
#define ACK_BAD_UNIT 9
#define ACK_BAD_PIN 10
#define ACK_BAD_CYLINDER 11
#define ACK_OKAY 0
#define ACK_BAD_COMMAND 1
#define ACK_NO_INDEX 2
#define ACK_NO_TRK0 3
#define ACK_FLUX_OVERFLOW 4
#define ACK_FLUX_UNDERFLOW 5
#define ACK_WRPROT 6
#define ACK_NO_UNIT 7
#define ACK_NO_BUS 8
#define ACK_BAD_UNIT 9
#define ACK_BAD_PIN 10
#define ACK_BAD_CYLINDER 11
/*
* CONTROL-CHANNEL COMMAND SET:
* We abuse SET_LINE_CODING requests over endpoint 0, stashing a command
* in the baud-rate field.
*/
#define BAUD_NORMAL 9600
#define BAUD_CLEAR_COMMS 10000
#define BAUD_NORMAL 9600
#define BAUD_CLEAR_COMMS 10000
/*
* Flux stream opcodes. Preceded by 0xFF byte.
*
*
* Argument types:
* N28: 28-bit non-negative integer N, encoded as 4 bytes b0,b1,b2,b3:
* b0 = (uint8_t)(1 | (N << 1))
@@ -120,19 +119,18 @@ extern Bytes stripPartialRotation(const Bytes& fldata);
* Args:
* +4 [N28]: ticks to index, relative to sample cursor.
* Signals an index pulse in the read stream. Sample cursor is unaffected. */
#define FLUXOP_INDEX 1
#define FLUXOP_INDEX 1
/* FLUXOP_SPACE [CMD_READ_FLUX, CMD_WRITE_FLUX]
* Args:
* +4 [N28]: ticks to increment the sample cursor.
* Increments the sample cursor with no intervening flux transitions. */
#define FLUXOP_SPACE 2
#define FLUXOP_SPACE 2
/* FLUXOP_ASTABLE [CMD_WRITE_FLUX]
* Args:
* +4 [N28]: astable period.
* Generate regular flux transitions at specified astable period.
* Generate regular flux transitions at specified astable period.
* Duration is specified by immediately preceding FLUXOP_SPACE opcode(s). */
#define FLUXOP_ASTABLE 3
#define FLUXOP_ASTABLE 3
/*
* COMMAND PACKETS
@@ -140,7 +138,8 @@ extern Bytes stripPartialRotation(const Bytes& fldata);
/* CMD_GET_INFO, index 0 */
#define GETINFO_FIRMWARE 0
struct packed gw_info {
struct packed gw_info
{
uint8_t fw_major;
uint8_t fw_minor;
uint8_t is_main_firmware; /* == 0 -> update bootloader */
@@ -153,15 +152,18 @@ extern struct gw_info gw_info;
/* CMD_GET_INFO, index 1 */
#define GETINFO_BW_STATS 1
struct packed gw_bw_stats {
struct packed {
struct packed gw_bw_stats
{
struct packed
{
uint32_t bytes;
uint32_t usecs;
} min_bw, max_bw;
};
/* CMD_READ_FLUX */
struct packed gw_read_flux {
struct packed gw_read_flux
{
/* Maximum ticks to read for (or 0, for no limit). */
uint32_t ticks;
/* Maximum index pulses to read (or 0, for no limit). */
@@ -169,7 +171,8 @@ struct packed gw_read_flux {
};
/* CMD_WRITE_FLUX */
struct packed gw_write_flux {
struct packed gw_write_flux
{
/* If non-zero, start the write at the index pulse. */
uint8_t cue_at_index;
/* If non-zero, terminate the write at the next index pulse. */
@@ -177,18 +180,21 @@ struct packed gw_write_flux {
};
/* CMD_ERASE_FLUX */
struct packed gw_erase_flux {
struct packed gw_erase_flux
{
uint32_t ticks;
};
/* CMD_SINK_SOURCE_BYTES */
struct packed gw_sink_source_bytes {
struct packed gw_sink_source_bytes
{
uint32_t nr_bytes;
};
/* CMD_{GET,SET}_PARAMS, index 0 */
#define PARAMS_DELAYS 0
struct packed gw_delay {
struct packed gw_delay
{
uint16_t select_delay; /* usec */
uint16_t step_delay; /* usec */
uint16_t seek_settle; /* msec */
@@ -198,7 +204,6 @@ struct packed gw_delay {
/* CMD_SWITCH_FW_MODE */
#define FW_MODE_BOOTLOADER 0
#define FW_MODE_NORMAL 1
#define FW_MODE_NORMAL 1
#endif

View File

@@ -4,18 +4,18 @@
class SerialPort
{
public:
static std::unique_ptr<SerialPort> openSerialPort(const std::string& path);
static std::unique_ptr<SerialPort> openSerialPort(const std::string& path);
public:
virtual ~SerialPort();
virtual ssize_t readImpl(uint8_t* buffer, size_t len) = 0;
virtual ssize_t write(const uint8_t* buffer, size_t len) = 0;
virtual ~SerialPort();
virtual ssize_t readImpl(uint8_t* buffer, size_t len) = 0;
virtual ssize_t write(const uint8_t* buffer, size_t len) = 0;
void read(uint8_t* buffer, size_t len);
void read(Bytes& bytes);
Bytes readBytes(size_t count);
uint8_t readByte();
void write(const Bytes& bytes);
void read(uint8_t* buffer, size_t len);
void read(Bytes& bytes);
Bytes readBytes(size_t count);
uint8_t readByte();
void write(const Bytes& bytes);
private:
uint8_t _readbuffer[4096];
@@ -24,4 +24,3 @@ private:
};
#endif

View File

@@ -6,60 +6,95 @@
class Fluxmap;
class GreaseWeazleProto;
namespace libusbp { class device; }
namespace libusbp
{
class device;
}
class USB
{
public:
virtual ~USB();
virtual ~USB();
virtual int getVersion() = 0;
virtual void recalibrate() = 0;
virtual void seek(int track) = 0;
virtual nanoseconds_t getRotationalPeriod(int hardSectorCount) = 0;
virtual void testBulkWrite() = 0;
virtual void testBulkRead() = 0;
virtual Bytes read(int side, bool synced, nanoseconds_t readTime,
nanoseconds_t hardSectorThreshold) = 0;
virtual void write(int side, const Bytes& bytes,
nanoseconds_t hardSectorThreshold) = 0;
virtual void erase(int side, nanoseconds_t hardSectorThreshold) = 0;
virtual void setDrive(int drive, bool high_density, int index_mode) = 0;
virtual void measureVoltages(struct voltages_frame* voltages) = 0;
virtual int getVersion() = 0;
virtual void recalibrate() = 0;
virtual void seek(int track) = 0;
virtual nanoseconds_t getRotationalPeriod(int hardSectorCount) = 0;
virtual void testBulkWrite() = 0;
virtual void testBulkRead() = 0;
virtual Bytes read(int side,
bool synced,
nanoseconds_t readTime,
nanoseconds_t hardSectorThreshold) = 0;
virtual void write(
int side, const Bytes& bytes, nanoseconds_t hardSectorThreshold) = 0;
virtual void erase(int side, nanoseconds_t hardSectorThreshold) = 0;
virtual void setDrive(int drive, bool high_density, int index_mode) = 0;
virtual void measureVoltages(struct voltages_frame* voltages) = 0;
protected:
std::string usberror(int i);
std::string usberror(int i);
};
extern USB& getUsb();
extern USB* createFluxengineUsb(libusbp::device& device);
extern USB* createGreaseWeazleUsb(const std::string& serialPort, const GreaseWeazleProto& config);
extern USB* createGreaseWeazleUsb(
const std::string& serialPort, const GreaseWeazleProto& config);
static inline int usbGetVersion() { return getUsb().getVersion(); }
static inline void usbRecalibrate() { getUsb().recalibrate(); }
static inline void usbSeek(int track) { getUsb().seek(track); }
static inline void usbTestBulkWrite() { getUsb().testBulkWrite(); }
static inline void usbTestBulkRead() { getUsb().testBulkRead(); }
static inline int usbGetVersion()
{
return getUsb().getVersion();
}
static inline void usbRecalibrate()
{
getUsb().recalibrate();
}
static inline void usbSeek(int track)
{
getUsb().seek(track);
}
static inline void usbTestBulkWrite()
{
getUsb().testBulkWrite();
}
static inline void usbTestBulkRead()
{
getUsb().testBulkRead();
}
static inline void usbErase(int side, nanoseconds_t hardSectorThreshold)
{ getUsb().erase(side, hardSectorThreshold); }
{
getUsb().erase(side, hardSectorThreshold);
}
static inline nanoseconds_t usbGetRotationalPeriod(int hardSectorCount)
{ return getUsb().getRotationalPeriod(hardSectorCount); }
{
return getUsb().getRotationalPeriod(hardSectorCount);
}
static inline Bytes usbRead(int side, bool synced, nanoseconds_t readTime,
nanoseconds_t hardSectorThreshold)
{ return getUsb().read(side, synced, readTime, hardSectorThreshold); }
static inline Bytes usbRead(int side,
bool synced,
nanoseconds_t readTime,
nanoseconds_t hardSectorThreshold)
{
return getUsb().read(side, synced, readTime, hardSectorThreshold);
}
static inline void usbWrite(int side, const Bytes& bytes,
nanoseconds_t hardSectorThreshold)
{ getUsb().write(side, bytes, hardSectorThreshold); }
static inline void usbWrite(
int side, const Bytes& bytes, nanoseconds_t hardSectorThreshold)
{
getUsb().write(side, bytes, hardSectorThreshold);
}
static inline void usbSetDrive(int drive, bool high_density, int index_mode)
{ getUsb().setDrive(drive, high_density, index_mode); }
{
getUsb().setDrive(drive, high_density, index_mode);
}
static inline void usbMeasureVoltages(struct voltages_frame* voltages)
{ getUsb().measureVoltages(voltages); }
{
getUsb().measureVoltages(voltages);
}
#endif

View File

@@ -6,22 +6,21 @@
enum DeviceType
{
DEVICE_FLUXENGINE,
DEVICE_GREASEWEAZLE
DEVICE_FLUXENGINE,
DEVICE_GREASEWEAZLE
};
extern std::string getDeviceName(DeviceType type);
struct CandidateDevice
{
DeviceType type;
libusbp::device device;
uint32_t id;
std::string serial;
std::string serialPort;
DeviceType type;
libusbp::device device;
uint32_t id;
std::string serial;
std::string serialPort;
};
extern std::vector<std::shared_ptr<CandidateDevice>> findUsbDevices();
#endif