URL
https://opencores.org/ocsvn/or1k/or1k/trunk
Subversion Repositories or1k
Compare Revisions
- This comparison shows the changes necessary to convert path
/
- from Rev 1692 to Rev 1693
- ↔ Reverse comparison
Rev 1692 → Rev 1693
/trunk/or1ksim/peripheral/atadevice.c
72,22 → 72,52
*/ |
|
|
/* |
D E V I C E S _ I N I T |
*/ |
void ata_devices_init(ata_devices *devices) |
/* Use a file to simulate a hard-disk */ |
static FILE *open_file(uint32_t *size, const char *filename) |
{ |
ata_device_init(&devices->device0, 0); |
FILE *fp; |
unsigned long n; |
|
if (devices->device0.type) |
ata_device_init(&devices->device1, ATA_DHR_DEV); |
else |
ata_device_init(&devices->device1, 0); |
// TODO: |
|
/* check if a file with name 'filename' already exists */ |
if(!(fp = fopen(filename, "rb+"))) |
if(!(fp = fopen(filename, "wb+"))) { |
ERR("ata_open_file, cannot open hd-file %s\n", filename); |
return NULL; |
} else { |
/* TODO create a file 'size' large */ |
/* create a file 'size' large */ |
TRACE("ata_device; generating a new hard disk file.\n"); |
TRACE("This may take a while, depending on the requested size.\n"); |
for(n=0; n < *size; n++) |
fputc(0, fp); |
} |
else /* file already exist */ |
fprintf(stderr, "file %s already exists. Using existing file.\n", filename); |
|
TRACE("requested filesize was: %d (MBytes).\n", *size); |
|
/* get the size of the file. This is also the size of the harddisk*/ |
fseek(fp, 0, SEEK_END); |
*size = ftell(fp); |
|
TRACE("actual filesize is: %d (MBytes).\n", *size >> 20); |
|
return fp; |
} |
|
|
void ata_device_init(ata_device *device, int dev) |
/* Use a the local filesystem as a hard-disk */ |
static FILE *open_local(void) |
{ |
// TODO: |
FIXME("Device type LOCAL is not yet supported. Defaulting to device type NO_CONNECT."); |
return NULL; |
} |
|
static void ata_device_init(ata_device *device, int dev) |
{ |
/* set DeviceID */ |
device->internals.dev = dev; |
|
116,60 → 146,68
} |
} |
|
/* Use a file to simulate a hard-disk */ |
FILE *open_file(unsigned long *size, const char *filename) |
/* |
D E V I C E S _ I N I T |
*/ |
void ata_devices_init(ata_devices *devices) |
{ |
FILE *fp; |
unsigned long n; |
ata_device_init(&devices->device0, 0); |
|
// TODO: |
if(devices->device0.type) |
ata_device_init(&devices->device1, ATA_DHR_DEV); |
else |
ata_device_init(&devices->device1, 0); |
} |
|
/* check if a file with name 'filename' already exists */ |
if ( !(fp = fopen(filename, "rb+")) ) |
if ( !(fp = fopen(filename, "wb+")) ) |
{ |
ERR( "ata_open_file, cannot open hd-file %s\n", filename ); |
return NULL; |
} |
else |
{ |
/* TODO create a file 'size' large */ |
/* create a file 'size' large */ |
TRACE("ata_device; generating a new hard disk file.\n"); |
TRACE("This may take a while, depending on the requested size.\n"); |
for (n=0; n < (*size << 20); n++) |
fputc(0, fp); |
} |
else /* file already exist */ |
fprintf(stderr, "file %s already exists. Using existing file.\n", filename); |
/* |
D E V I C E S _ H W _ R E S E T |
*/ |
static void ata_device_hw_reset(ata_device *device, int reset_signal, |
int daspo, int pdiagi, int daspi) |
{ |
/* check ata-device state */ |
if(device->internals.state == ATA_STATE_HW_RST) { |
if(!reset_signal) { |
/* hardware reset finished */ |
|
/* set sectors_per_track & heads_per_cylinders */ |
device->internals.sectors_per_track = SECTORS; |
device->internals.heads_per_cylinder = HEADS; |
|
TRACE("requested filesize was: %ld (MBytes).\n", *size); |
/* set device1 input signals */ |
device->sigs.pdiagi = pdiagi; |
device->sigs.daspi = daspi; |
|
/* get the size of the file. This is also the size of the harddisk*/ |
fseek(fp, 0, SEEK_END); |
*size = ftell(fp); |
ata_execute_device_diagnostics_cmd(device); |
|
TRACE("actual filesize is: %ld (MBytes).\n", *size >> 20); |
/* clear busy bit */ |
device->regs.status &= ~ATA_SR_BSY; |
|
return fp; |
} |
/* set DRDY bit, when not a PACKET device */ |
if(!device->packet) |
device->regs.status |= ATA_SR_DRDY; |
|
/* set new state */ |
device->internals.state = ATA_STATE_IDLE; |
} |
} else if (reset_signal) { |
/* hardware reset signal asserted, stop what we are doing */ |
|
/* Use a the local filesystem as a hard-disk */ |
FILE *open_local(void) |
{ |
// TODO: |
FIXME("Device type LOCAL is not yet supported. Defaulting to device type NO_CONNECT."); |
return NULL; |
} |
/* negate bus signals */ |
device->sigs.iordy = 0; |
device->sigs.intrq = 0; |
device->sigs.dmarq = 0; |
device->sigs.pdiago = 0; |
device->sigs.daspo = daspo; |
|
/* set busy bit */ |
device->regs.status |= ATA_SR_BSY; |
|
/* set new state */ |
device->internals.state = ATA_STATE_HW_RST; |
} |
} |
|
|
/* |
D E V I C E S _ H W _ R E S E T |
*/ |
/* power-on and hardware reset */ |
void ata_devices_hw_reset(ata_devices *devices, int reset_signal) |
{ |
216,59 → 254,7
} |
} |
|
void ata_device_hw_reset(ata_device *device, int reset_signal, |
int daspo, int pdiagi, int daspi) |
{ |
/* check ata-device state */ |
if (device->internals.state == ATA_STATE_HW_RST) |
{ |
if (!reset_signal) |
{ |
/* hardware reset finished */ |
|
/* set sectors_per_track & heads_per_cylinders */ |
device->internals.sectors_per_track = SECTORS; |
device->internals.heads_per_cylinder = HEADS; |
|
/* set device1 input signals */ |
device->sigs.pdiagi = pdiagi; |
device->sigs.daspi = daspi; |
|
ata_execute_device_diagnostics_cmd(device); |
|
/* clear busy bit */ |
device->regs.status &= ~ATA_SR_BSY; |
|
/* set DRDY bit, when not a PACKET device */ |
if (!device->packet) |
device->regs.status |= ATA_SR_DRDY; |
|
/* set new state */ |
device->internals.state = ATA_STATE_IDLE; |
} |
} |
else |
if (reset_signal) |
{ |
/* hardware reset signal asserted, stop what we are doing */ |
|
/* negate bus signals */ |
device->sigs.iordy = 0; |
device->sigs.intrq = 0; |
device->sigs.dmarq = 0; |
device->sigs.pdiago = 0; |
device->sigs.daspo = daspo; |
|
/* set busy bit */ |
device->regs.status |= ATA_SR_BSY; |
PRINTF("setting status register BSY 0x%2X\n", device->regs.status); |
|
/* set new state */ |
device->internals.state = ATA_STATE_HW_RST; |
} |
} |
|
|
/* |
D E V I C E S _ D O _ C O N T R O L _ R E G I S T E R |
|
459,26 → 445,8
/* |
D E V I C E S _ W R I T E |
*/ |
/* Write to devices */ |
void ata_devices_write(ata_devices *devices, char adr, short value) |
{ |
/* check for no connected devices */ |
if (!devices->device0.stream && !devices->device1.stream) |
ERR("ata_devices_write, no ata devices connected.\n"); |
else |
{ |
/* first device */ |
if (devices->device0.stream) |
ata_device_write(&devices->device0, adr, value); |
|
/* second device */ |
if (devices->device1.stream) |
ata_device_write(&devices->device1, adr, value); |
} |
} |
|
/* write to a single device */ |
void ata_device_write(ata_device *device, char adr, short value) |
static void ata_device_write(ata_device *device, char adr, short value) |
{ |
switch (adr) { |
case ATA_CR : |
552,3 → 520,20
} //endcase |
} |
|
/* Write to devices */ |
void ata_devices_write(ata_devices *devices, char adr, short value) |
{ |
/* check for no connected devices */ |
if(!devices->device0.stream && !devices->device1.stream) |
ERR("ata_devices_write, no ata devices connected.\n"); |
else { |
/* first device */ |
if(devices->device0.stream) |
ata_device_write(&devices->device0, adr, value); |
|
/* second device */ |
if(devices->device1.stream) |
ata_device_write(&devices->device1, adr, value); |
} |
} |
|
/trunk/or1ksim/peripheral/atadevice.h
184,16 → 184,6
short ata_devices_read(ata_devices *devices, char adr); |
void ata_devices_write(ata_devices *devices, char adr, short value); |
|
/* single device */ |
void ata_device_init(ata_device *device, int dev); |
void ata_device_hw_reset(ata_device *device, int reset_signal, int daspo, int pdiagi, int daspi); |
void ata_device_do_control_register(ata_device *device); |
void ata_device_do_command_register(ata_device *device); |
void ata_device_write(ata_device *device, char adr, short value); |
|
/* housekeeping routines */ |
FILE *open_file(unsigned long *size, const char *filename); |
FILE *open_local(void); |
|
|
#endif |