OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [or1ksim/] [peripheral/] [atadevice.c] - Diff between revs 1557 and 1693

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 1557 Rev 1693
Line 70... Line 70...
 prohibited commands:
 prohibited commands:
 - device reset
 - device reset
*/
*/
 
 
 
 
/*
/* Use a file to simulate a hard-disk                                 */
  D E V I C E S _ I N I T
static FILE *open_file(uint32_t *size, const char *filename)
*/
 
void ata_devices_init(ata_devices *devices)
 
{
{
  ata_device_init(&devices->device0, 0);
   FILE *fp;
 
   unsigned long  n;
 
 
  if (devices->device0.type)
   // TODO:
    ata_device_init(&devices->device1, ATA_DHR_DEV);
 
  else
   /* check if a file with name 'filename' already exists             */
    ata_device_init(&devices->device1,           0);
   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);
 
 
void ata_device_init(ata_device *device, int dev)
   /* 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;
 
}
 
 
 
 
 
/* 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                                                     */
  /* set DeviceID                                                     */
  device->internals.dev = dev;
  device->internals.dev = dev;
 
 
  /* generate stream for hd_simulation                                */
  /* generate stream for hd_simulation                                */
Line 114... Line 144...
      device->stream = NULL;
      device->stream = NULL;
      break;
      break;
  }
  }
}
}
 
 
/* 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;
  ata_device_init(&devices->device0, 0);
   unsigned long  n;
 
 
 
   // TODO:
 
 
 
   /* check if a file with name 'filename' already exists             */
  if(devices->device0.type)
   if ( !(fp = fopen(filename, "rb+")) )
    ata_device_init(&devices->device1, ATA_DHR_DEV);
     if ( !(fp = fopen(filename, "wb+")) )
 
     {
 
       ERR( "ata_open_file, cannot open hd-file %s\n", filename );
 
       return NULL;
 
     }
 
     else
     else
     {
    ata_device_init(&devices->device1,           0);
       /* 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                                    */
 
 
   TRACE("requested filesize was: %ld (MBytes).\n", *size);
      /* set sectors_per_track & heads_per_cylinders                */
 
      device->internals.sectors_per_track = SECTORS;
 
      device->internals.heads_per_cylinder = HEADS;
 
 
   /* get the size of the file. This is also the size of the harddisk*/
      /* set device1 input signals                                  */
   fseek(fp, 0, SEEK_END);
      device->sigs.pdiagi = pdiagi;
   *size = ftell(fp);
      device->sigs.daspi  = daspi;
 
 
   TRACE("actual filesize is: %ld (MBytes).\n", *size >> 20);
      ata_execute_device_diagnostics_cmd(device);
 
 
   return fp;
      /* 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;
 
 
/* Use a the local filesystem as a hard-disk                          */
      /* set new state                                              */
FILE *open_local(void)
      device->internals.state = ATA_STATE_IDLE;
{
 
 // TODO:
 
 FIXME("Device type LOCAL is not yet supported. Defaulting to device type NO_CONNECT.");
 
 return NULL;
 
}
}
 
  } 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;
 
 
 
    /* 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                                        */
/* power-on and hardware reset                                        */
void ata_devices_hw_reset(ata_devices *devices, int reset_signal)
void ata_devices_hw_reset(ata_devices *devices, int reset_signal)
{
{
  /* display debug information                                        */
  /* display debug information                                        */
  TRACE("ata_devices_hw_reset.\n");
  TRACE("ata_devices_hw_reset.\n");
Line 214... Line 252...
    /* no devices connected                                           */
    /* no devices connected                                           */
    TRACE("ata_device_hw_reset, no devices connected.\n");
    TRACE("ata_device_hw_reset, no devices connected.\n");
  }
  }
}
}
 
 
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
  D E V I C E S _ D O _ C O N T R O L _ R E G I S T E R
 
 
  Handles - software reset
  Handles - software reset
Line 457... Line 443...
 
 
 
 
/*
/*
  D E V I C E S _ W R I T E
  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                                           */
/* 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) {
    switch (adr) {
        case ATA_CR  :
        case ATA_CR  :
            /*display debug information                               */
            /*display debug information                               */
            TRACE("command register written, value = 0x%02X\n", value);
            TRACE("command register written, value = 0x%02X\n", value);
Line 550... Line 518...
            break;
            break;
 
 
    } //endcase
    } //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);
 
  }
 
}
 
 
 
 
 No newline at end of file
 No newline at end of file

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.