/*
* JR-IDE Project
* - (c) 2017 Alan Hightower
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#ifndef __NETPI_H__
#define __NETPI_H__
#define _LARGEFILE_SOURCE 1
#define _LARGEFILE64_SOURCE 1
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "rpc.h"
extern int verbose;
extern int serial_no;
extern int fw_ver_major, fw_ver_minor;
#define SERVER_VER_MAJOR 1
#define SERVER_VER_MINOR 2
#define LOGDBG(fmt, args...) { if (verbose > 0) printf(fmt, ## args); }
#define LOGDB2(fmt, args...) { if (verbose > 1) printf(fmt, ## args); }
#define LOGDB3(fmt, args...) { if (verbose > 2) printf(fmt, ## args); }
#define LOGERR(fmt, args...) fprintf(stderr, "\nERROR: " fmt "\n\n", ## args)
#define I2C_EFB_ADDR 0x40 // 7-bit
#define I2C_EFB_DEVICE "/dev/i2c-1"
// 3.9, 7.8, 15.6, 31.2, 62.5, or 125 MHz
#define SPI_BITRATE 16000000UL
/*
* This structure is shifted in/out during IDE register refresh
* and updates. It basically represents the standard ATA register
* file plus data transfer FIFO levels. During updates, the FIFO
* levels are atomic adjustment to the level based on PI read/write
* activity
*/
typedef struct _st_ide_regs
{
uint8_t spi_cmd;
uint8_t spi_arg0;
uint8_t spi_arg1;
uint8_t spi_arg2;
uint8_t SLAVE : 1; // [I] Slave device
uint8_t LBAM : 1; // [I] LBA mode
uint8_t EMUX : 1; // [O] Error reg mux control
uint8_t DRQ : 2; // [O] STS: Data request mode
uint8_t DSC : 1; // [O] STS: Drive seek complete
uint8_t DF : 1; // [O] STS: Drive fault
uint8_t DRDY : 1; // [O] STS: Drive ready
uint8_t BSY : 1; // [O] STS: Busy
uint8_t ABRT : 1; // [O] ERR: Aborted command
uint8_t IDNF : 1; // [O] ERR: Sector not found
uint8_t SRSTP : 1; // [I] Reset pending
uint8_t IRQPIn : 1; // [O] IRQ output to RPi
uint8_t IRQACT : 1; // [O] IRQ output active to host
uint8_t IENn : 1; // [I] IRQ enabled by host
uint8_t SRST : 1; // [I] Soft-reset request
#define DRQ_MODE_OFF 0 // STS:DRQ bit always value 0
#define DRQ_MODE_ON 1 // STS:DRQ bit always value 1
#define DRQ_MODE_READSEC 2 // STS:DRQ bit 1 if read FIFO not empty
#define DRQ_MODE_WRITESEC 3 // STS:DRQ bit 1 if write FIFO not empty
uint8_t cmd; // IDE command register
uint8_t feat; // IDE feature register
uint8_t secr; // Payload count high-byte
uint8_t secz; // Sector count or payload count low-byte
uint32_t lba; // Logical block address (or CHS)
uint16_t ififo_cnt; // PIO-IN FIFO level (read) / adjustment (write)
uint16_t ofifo_cnt; // PIO-OUT FIFO level (read) / adjustment (write)
uint8_t dummy;
} __attribute__((packed)) ide_regs_t;
extern ide_regs_t ide;
/*
* Quick and dirty context for tracking information associated
* with a disk file used to emulate an IDE drive.
*/
typedef struct _st_drive
{
char *path;
char *label;
int fd;
int cyls;
int heads;
int spt;
int readonly;
uint32_t sectors;
// Statistic members (in # of words)
uint32_t read_diff;
uint32_t write_diff;
uint32_t read_total;
uint32_t write_total;
} drive_t;
extern void data_in_setup (uint8_t cmd, uint8_t sub, int words);
extern void *data_out_setup (int words);
extern void data_out_commit (int words);
// server.c : DOS Redirector Service (Int 2F:11xx)
extern int init_redirector (void);
extern void _handle_redirect_command (void);
extern void _handle_redirect_complete (uint8_t sub, void *data, int len);
// config.c : Config file management
extern int config_load (const char *path);
extern void config_free (void);
extern drive_t *config_drive_init (int master);
extern void config_drive_term (drive_t *drive);
extern const char *config_i2c_path (void);
// spi.c : SPI interface for Pi
extern int spi_init (int cs, uint32_t rate);
extern int spi_xfer (void *buf, int len);
extern void spi_term (void);
#endif