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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-stable/] [gdb-7.2/] [sim/] [ppc/] [hw_com.c] - Diff between revs 835 and 841

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 835 Rev 841
/*  This file is part of the program psim.
/*  This file is part of the program psim.
 
 
    Copyright (C) 1994-1996, Andrew Cagney <cagney@highland.com.au>
    Copyright (C) 1994-1996, Andrew Cagney <cagney@highland.com.au>
 
 
    This program is free software; you can redistribute it and/or modify
    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
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.
    (at your option) any later version.
 
 
    This program is distributed in the hope that it will be useful,
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
    GNU General Public License for more details.
 
 
    You should have received a copy of the GNU General Public License
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
 
    */
    */
 
 
 
 
#ifndef _HW_COM_C_
#ifndef _HW_COM_C_
#define _HW_COM_C_
#define _HW_COM_C_
 
 
#ifndef STATIC_INLINE_HW_COM
#ifndef STATIC_INLINE_HW_COM
#define STATIC_INLINE_HW_COM STATIC_INLINE
#define STATIC_INLINE_HW_COM STATIC_INLINE
#endif
#endif
 
 
#include "device_table.h"
#include "device_table.h"
 
 
#ifdef HAVE_STRING_H
#ifdef HAVE_STRING_H
#include <string.h>
#include <string.h>
#else
#else
#ifdef HAVE_STRINGS_H
#ifdef HAVE_STRINGS_H
#include <strings.h>
#include <strings.h>
#endif
#endif
#endif
#endif
 
 
#ifdef HAVE_UNISTD_H
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#include <unistd.h>
#endif
#endif
#ifdef HAVE_STDLIB_H
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#include <stdlib.h>
#endif
#endif
 
 
/* DEVICE
/* DEVICE
 
 
 
 
   com - '550 compatible serial device
   com - '550 compatible serial device
 
 
 
 
   DESCRIPTION
   DESCRIPTION
 
 
 
 
   Models the basics of the 8 register '550 serial device.  The model
   Models the basics of the 8 register '550 serial device.  The model
   includes an interrupt line, input and output fifos, and status
   includes an interrupt line, input and output fifos, and status
   information.
   information.
 
 
   Independent configuration of the devices input and output streams is
   Independent configuration of the devices input and output streams is
   allowed: use either the console or a file (buffered or unbuffered) as
   allowed: use either the console or a file (buffered or unbuffered) as
   the data source/sink; specify the real-time delay between each character
   the data source/sink; specify the real-time delay between each character
   transfer.
   transfer.
 
 
   When the devices input stream is being taken from a file, the end of
   When the devices input stream is being taken from a file, the end of
   file is signaled by a loss of carrier (the loss of carrier may be
   file is signaled by a loss of carrier (the loss of carrier may be
   incorrectly proceeded by a single null character).
   incorrectly proceeded by a single null character).
 
 
 
 
   PROPERTIES
   PROPERTIES
 
 
 
 
   reg = <address> <size> ... (optional - note 1)
   reg = <address> <size> ... (optional - note 1)
 
 
   List of <address> <size> pairs.  Each pair specifies an address for
   List of <address> <size> pairs.  Each pair specifies an address for
   the devices 8 registers.  The address should be 8 byte aligned.
   the devices 8 registers.  The address should be 8 byte aligned.
 
 
 
 
   alternate-reg = <address> <size> ... (optional - note 1)
   alternate-reg = <address> <size> ... (optional - note 1)
 
 
   Alternative addreses for the registers.
   Alternative addreses for the registers.
 
 
 
 
   assigned-addresses = <address> <size> ... (optional - note 1)
   assigned-addresses = <address> <size> ... (optional - note 1)
 
 
   On a PCI bus, this property specifies the addresses assigned to the
   On a PCI bus, this property specifies the addresses assigned to the
   device.  The values reflect the devices configuration base registers.
   device.  The values reflect the devices configuration base registers.
 
 
   Note 1: At least one of "assigned-addresses", "reg" or "alternative-reg"
   Note 1: At least one of "assigned-addresses", "reg" or "alternative-reg"
   must be specified.  If "assigned-addresses" is specified the other
   must be specified.  If "assigned-addresses" is specified the other
   address specifications are ignored.
   address specifications are ignored.
 
 
 
 
   input-file = <file-name> (optional)
   input-file = <file-name> (optional)
 
 
   File to take all serial port input from (instead of the simulation
   File to take all serial port input from (instead of the simulation
   console).
   console).
 
 
 
 
   output-file = <file-name> (optional)
   output-file = <file-name> (optional)
 
 
   File to send all output to (instead of the simulation console).
   File to send all output to (instead of the simulation console).
 
 
 
 
   input-buffering = "unbuffered" (optional)
   input-buffering = "unbuffered" (optional)
 
 
   Specifying "unbuffered" buffering disables buffering on the serial
   Specifying "unbuffered" buffering disables buffering on the serial
   devices input stream (all data is immediatly read).  In the future,
   devices input stream (all data is immediatly read).  In the future,
   this option may be used to provide input buffering alternatives.
   this option may be used to provide input buffering alternatives.
 
 
 
 
   output-buffering = "unbuffered" (optional)
   output-buffering = "unbuffered" (optional)
 
 
   Specifying "unbuffered" buffering disables buffering on the serial
   Specifying "unbuffered" buffering disables buffering on the serial
   devices output stream (all data is immediatly written).  In the future,
   devices output stream (all data is immediatly written).  In the future,
   this option may be extended to include other buffering alternatives.
   this option may be extended to include other buffering alternatives.
 
 
 
 
   input-delay = <integer-delay> (optional)
   input-delay = <integer-delay> (optional)
 
 
   Specify the number of ticks after the current character has been
   Specify the number of ticks after the current character has been
   read from the serial port that the next character becomes
   read from the serial port that the next character becomes
   available.
   available.
 
 
 
 
   output-delay = <integer-delay> (optional)
   output-delay = <integer-delay> (optional)
 
 
   Specify the number of ticks after a character has been written to
   Specify the number of ticks after a character has been written to
   the empty output fifo that the fifo finishes draining.  Any
   the empty output fifo that the fifo finishes draining.  Any
   characters written to the output fifo before it has drained will
   characters written to the output fifo before it has drained will
   not be lost and will still be displayed.
   not be lost and will still be displayed.
 
 
 
 
   EXAMPLES
   EXAMPLES
 
 
 
 
   |  /iobus@0xf0000000/com@0x3000/reg 0x3000 8
   |  /iobus@0xf0000000/com@0x3000/reg 0x3000 8
 
 
   Create a simple console device at address <<0x3000>> within
   Create a simple console device at address <<0x3000>> within
   <<iobus>>.  Since iobus starts at address <<0xf0000000>> the
   <<iobus>>.  Since iobus starts at address <<0xf0000000>> the
   absolute address of the serial port will be <<0xf0003000>>.
   absolute address of the serial port will be <<0xf0003000>>.
 
 
   The device will always be ready for I/O (no delay properties specified)
   The device will always be ready for I/O (no delay properties specified)
   and both the input and output streams will use the simulation console
   and both the input and output streams will use the simulation console
   (no file properties).
   (no file properties).
 
 
 
 
   |  $ psim \
   |  $ psim \
   |    -o '/cpus/cpu@0' \
   |    -o '/cpus/cpu@0' \
   |    -o '/iobus@0xf0000000/com@0x4000/reg 0x4000 8' \
   |    -o '/iobus@0xf0000000/com@0x4000/reg 0x4000 8' \
   |    -o '/iobus@0xf0000000/com@0x4000/input-file /etc/passwd' \
   |    -o '/iobus@0xf0000000/com@0x4000/input-file /etc/passwd' \
   |    -o '/iobus@0xf0000000/com@0x4000/input-delay 1000' \
   |    -o '/iobus@0xf0000000/com@0x4000/input-delay 1000' \
   |    -o '/iobus@0xf0000000/com@0x4000 > 0 int /cpus/cpu@0x0' \
   |    -o '/iobus@0xf0000000/com@0x4000 > 0 int /cpus/cpu@0x0' \
   |    psim-test/hw-com/cat.be 0xf0004000
   |    psim-test/hw-com/cat.be 0xf0004000
 
 
   The serial port (at address <<0xf0004000>> is configured so that it
   The serial port (at address <<0xf0004000>> is configured so that it
   takes its input from the file <</etc/passwd>> while its output is
   takes its input from the file <</etc/passwd>> while its output is
   allowed to appear on the simulation console.
   allowed to appear on the simulation console.
 
 
   The node <</cpus/cpu@0>> was explicitly specified to ensure that it had
   The node <</cpus/cpu@0>> was explicitly specified to ensure that it had
   been created before any interrupts were attached to it.
   been created before any interrupts were attached to it.
 
 
   The program <<psim-test/hw-com/cat>> copies any characters on the serial
   The program <<psim-test/hw-com/cat>> copies any characters on the serial
   port's input (<</etc/passwd>>) to its output (the console).
   port's input (<</etc/passwd>>) to its output (the console).
   Consequently, the aove program will display the contents of the file
   Consequently, the aove program will display the contents of the file
   <</etc/passwd>> on the screen.
   <</etc/passwd>> on the screen.
 
 
 
 
   BUGS
   BUGS
 
 
 
 
   IEEE 1275 requires that a device on a PCI bus have, as its first reg
   IEEE 1275 requires that a device on a PCI bus have, as its first reg
   entry, the address of its configuration space registers.  Currently,
   entry, the address of its configuration space registers.  Currently,
   this device does not even implement configuration registers.
   this device does not even implement configuration registers.
 
 
   This model does not attempt to model the '550's input and output fifos.
   This model does not attempt to model the '550's input and output fifos.
   Instead, the input fifo is limited to a single character at a time,
   Instead, the input fifo is limited to a single character at a time,
   while the output fifo is effectivly infinite.  Consequently, unlike the
   while the output fifo is effectivly infinite.  Consequently, unlike the
   '550, this device will not discard output characters once a stream of 16
   '550, this device will not discard output characters once a stream of 16
   have been written to the data output register.
   have been written to the data output register.
 
 
   The input and output can only be taken from a file (or the current
   The input and output can only be taken from a file (or the current
   terminal device).  In the future, the <<com>> device should allow the
   terminal device).  In the future, the <<com>> device should allow the
   specification of other data streams (such as an xterm or TK window).
   specification of other data streams (such as an xterm or TK window).
 
 
   The input blocks if no data is available.
   The input blocks if no data is available.
 
 
   Interrupts have not been tested.
   Interrupts have not been tested.
 
 
   */
   */
 
 
enum {
enum {
  max_hw_com_registers = 8,
  max_hw_com_registers = 8,
};
};
 
 
typedef struct _com_port {
typedef struct _com_port {
  int ready;
  int ready;
  int delay;
  int delay;
  int interrupting;
  int interrupting;
  FILE *file;
  FILE *file;
} com_port;
} com_port;
 
 
typedef struct _com_modem {
typedef struct _com_modem {
  int carrier;
  int carrier;
  int carrier_changed;
  int carrier_changed;
  int interrupting;
  int interrupting;
} com_modem;
} com_modem;
 
 
typedef struct _hw_com_device {
typedef struct _hw_com_device {
  com_port input;
  com_port input;
  com_port output;
  com_port output;
  com_modem modem;
  com_modem modem;
  char dlab[2];
  char dlab[2];
  char reg[max_hw_com_registers];
  char reg[max_hw_com_registers];
  int interrupting;
  int interrupting;
} hw_com_device;
} hw_com_device;
 
 
 
 
static void
static void
hw_com_device_init_data(device *me)
hw_com_device_init_data(device *me)
{
{
  hw_com_device *com = (hw_com_device*)device_data(me);
  hw_com_device *com = (hw_com_device*)device_data(me);
  /* clean up */
  /* clean up */
  if (com->output.file != NULL)
  if (com->output.file != NULL)
    fclose(com->output.file);
    fclose(com->output.file);
  if (com->input.file != NULL)
  if (com->input.file != NULL)
    fclose(com->input.file);
    fclose(com->input.file);
  memset(com, 0, sizeof(hw_com_device));
  memset(com, 0, sizeof(hw_com_device));
 
 
  /* the fifo speed */
  /* the fifo speed */
  com->output.delay = (device_find_property(me, "output-delay") != NULL
  com->output.delay = (device_find_property(me, "output-delay") != NULL
                       ? device_find_integer_property(me, "output-delay")
                       ? device_find_integer_property(me, "output-delay")
                       : 0);
                       : 0);
  com->input.delay = (device_find_property(me, "input-delay") != NULL
  com->input.delay = (device_find_property(me, "input-delay") != NULL
                      ? device_find_integer_property(me, "input-delay")
                      ? device_find_integer_property(me, "input-delay")
                      : 0);
                      : 0);
 
 
  /* the data source/sink */
  /* the data source/sink */
  if (device_find_property(me, "input-file") != NULL) {
  if (device_find_property(me, "input-file") != NULL) {
    const char *input_file = device_find_string_property(me, "input-file");
    const char *input_file = device_find_string_property(me, "input-file");
    com->input.file = fopen(input_file, "r");
    com->input.file = fopen(input_file, "r");
    if (com->input.file == NULL)
    if (com->input.file == NULL)
      device_error(me, "Problem opening input file %s\n", input_file);
      device_error(me, "Problem opening input file %s\n", input_file);
    if (device_find_property(me, "input-buffering") != NULL) {
    if (device_find_property(me, "input-buffering") != NULL) {
      const char *buffering = device_find_string_property(me, "input-buffering");
      const char *buffering = device_find_string_property(me, "input-buffering");
      if (strcmp(buffering, "unbuffered") == 0)
      if (strcmp(buffering, "unbuffered") == 0)
        setbuf(com->input.file, NULL);
        setbuf(com->input.file, NULL);
    }
    }
  }
  }
  if (device_find_property(me, "output-file") != NULL) {
  if (device_find_property(me, "output-file") != NULL) {
    const char *output_file = device_find_string_property(me, "output-file");
    const char *output_file = device_find_string_property(me, "output-file");
    com->output.file = fopen(output_file, "w");
    com->output.file = fopen(output_file, "w");
    if (com->output.file == NULL)
    if (com->output.file == NULL)
      device_error(me, "Problem opening output file %s\n", output_file);
      device_error(me, "Problem opening output file %s\n", output_file);
    if (device_find_property(me, "output-buffering") != NULL) {
    if (device_find_property(me, "output-buffering") != NULL) {
      const char *buffering = device_find_string_property(me, "output-buffering");
      const char *buffering = device_find_string_property(me, "output-buffering");
      if (strcmp(buffering, "unbuffered") == 0)
      if (strcmp(buffering, "unbuffered") == 0)
        setbuf(com->output.file, NULL);
        setbuf(com->output.file, NULL);
    }
    }
  }
  }
 
 
  /* ready from the start */
  /* ready from the start */
  com->input.ready = 1;
  com->input.ready = 1;
  com->modem.carrier = 1;
  com->modem.carrier = 1;
  com->output.ready = 1;
  com->output.ready = 1;
}
}
 
 
 
 
static void
static void
update_com_interrupts(device *me,
update_com_interrupts(device *me,
                      hw_com_device *com)
                      hw_com_device *com)
{
{
  int interrupting;
  int interrupting;
  com->modem.interrupting = (com->modem.carrier_changed && (com->reg[1] & 0x80));
  com->modem.interrupting = (com->modem.carrier_changed && (com->reg[1] & 0x80));
  com->input.interrupting = (com->input.ready && (com->reg[1] & 0x1));
  com->input.interrupting = (com->input.ready && (com->reg[1] & 0x1));
  com->output.interrupting = (com->output.ready && (com->reg[1] & 0x2));
  com->output.interrupting = (com->output.ready && (com->reg[1] & 0x2));
  interrupting = (com->input.interrupting
  interrupting = (com->input.interrupting
                  || com->output.interrupting
                  || com->output.interrupting
                  || com->modem.interrupting);
                  || com->modem.interrupting);
 
 
  if (interrupting) {
  if (interrupting) {
    if (!com->interrupting) {
    if (!com->interrupting) {
      device_interrupt_event(me, 0 /*port*/, 1 /*value*/, NULL, 0);
      device_interrupt_event(me, 0 /*port*/, 1 /*value*/, NULL, 0);
    }
    }
  }
  }
  else /*!interrupting*/ {
  else /*!interrupting*/ {
    if (com->interrupting)
    if (com->interrupting)
      device_interrupt_event(me, 0 /*port*/, 0 /*value*/, NULL, 0);
      device_interrupt_event(me, 0 /*port*/, 0 /*value*/, NULL, 0);
  }
  }
  com->interrupting = interrupting;
  com->interrupting = interrupting;
}
}
 
 
 
 
static void
static void
make_read_ready(void *data)
make_read_ready(void *data)
{
{
  device *me = (device*)data;
  device *me = (device*)data;
  hw_com_device *com = (hw_com_device*)device_data(me);
  hw_com_device *com = (hw_com_device*)device_data(me);
  com->input.ready = 1;
  com->input.ready = 1;
  update_com_interrupts(me, com);
  update_com_interrupts(me, com);
}
}
 
 
static void
static void
read_com(device *me,
read_com(device *me,
         hw_com_device *com,
         hw_com_device *com,
         unsigned_word a,
         unsigned_word a,
         char val[1])
         char val[1])
{
{
  unsigned_word addr = a % 8;
  unsigned_word addr = a % 8;
 
 
  /* the divisor latch is special */
  /* the divisor latch is special */
  if (com->reg[3] & 0x8 && addr < 2) {
  if (com->reg[3] & 0x8 && addr < 2) {
    *val = com->dlab[addr];
    *val = com->dlab[addr];
    return;
    return;
  }
  }
 
 
  switch (addr) {
  switch (addr) {
 
 
  case 0:
  case 0:
    /* fifo */
    /* fifo */
    if (!com->modem.carrier)
    if (!com->modem.carrier)
      *val = '\0';
      *val = '\0';
    if (com->input.ready) {
    if (com->input.ready) {
      /* read the char in */
      /* read the char in */
      if (com->input.file == NULL) {
      if (com->input.file == NULL) {
        if (sim_io_read_stdin(val, 1) < 0)
        if (sim_io_read_stdin(val, 1) < 0)
          com->modem.carrier_changed = 1;
          com->modem.carrier_changed = 1;
      }
      }
      else {
      else {
        if (fread(val, 1, 1, com->input.file) == 0)
        if (fread(val, 1, 1, com->input.file) == 0)
          com->modem.carrier_changed = 1;
          com->modem.carrier_changed = 1;
      }
      }
      /* setup for next read */
      /* setup for next read */
      if (com->modem.carrier_changed) {
      if (com->modem.carrier_changed) {
        /* once lost carrier, never ready */
        /* once lost carrier, never ready */
        com->modem.carrier = 0;
        com->modem.carrier = 0;
        com->input.ready = 0;
        com->input.ready = 0;
        *val = '\0';
        *val = '\0';
      }
      }
      else if (com->input.delay > 0) {
      else if (com->input.delay > 0) {
        com->input.ready = 0;
        com->input.ready = 0;
        device_event_queue_schedule(me, com->input.delay, make_read_ready, me);
        device_event_queue_schedule(me, com->input.delay, make_read_ready, me);
      }
      }
    }
    }
    else {
    else {
      /* discard it? */
      /* discard it? */
      /* overflow input fifo? */
      /* overflow input fifo? */
      *val = '\0';
      *val = '\0';
    }
    }
    break;
    break;
 
 
  case 2:
  case 2:
    /* interrupt ident */
    /* interrupt ident */
    if (com->interrupting) {
    if (com->interrupting) {
      if (com->input.interrupting)
      if (com->input.interrupting)
        *val = 0x4;
        *val = 0x4;
      else if (com->output.interrupting)
      else if (com->output.interrupting)
        *val = 0x2;
        *val = 0x2;
      else if (com->modem.interrupting == 0)
      else if (com->modem.interrupting == 0)
        *val = 0;
        *val = 0;
      else
      else
        device_error(me, "bad elif for interrupts\n");
        device_error(me, "bad elif for interrupts\n");
    }
    }
    else
    else
      *val = 0x1;
      *val = 0x1;
    break;
    break;
 
 
  case 5:
  case 5:
    /* line status */
    /* line status */
    *val = ((com->input.ready ? 0x1 : 0)
    *val = ((com->input.ready ? 0x1 : 0)
            | (com->output.ready ? 0x60 : 0)
            | (com->output.ready ? 0x60 : 0)
            );
            );
    break;
    break;
 
 
  case 6:
  case 6:
    /* modem status */
    /* modem status */
    *val = ((com->modem.carrier_changed ? 0x08 : 0)
    *val = ((com->modem.carrier_changed ? 0x08 : 0)
            | (com->modem.carrier ? 0x80 : 0)
            | (com->modem.carrier ? 0x80 : 0)
            );
            );
    com->modem.carrier_changed = 0;
    com->modem.carrier_changed = 0;
    break;
    break;
 
 
  default:
  default:
    *val = com->reg[addr];
    *val = com->reg[addr];
    break;
    break;
 
 
  }
  }
  update_com_interrupts(me, com);
  update_com_interrupts(me, com);
}
}
 
 
static unsigned
static unsigned
hw_com_io_read_buffer_callback(device *me,
hw_com_io_read_buffer_callback(device *me,
                               void *dest,
                               void *dest,
                               int space,
                               int space,
                               unsigned_word addr,
                               unsigned_word addr,
                               unsigned nr_bytes,
                               unsigned nr_bytes,
                               cpu *processor,
                               cpu *processor,
                               unsigned_word cia)
                               unsigned_word cia)
{
{
  hw_com_device *com = device_data(me);
  hw_com_device *com = device_data(me);
  int i;
  int i;
  for (i = 0; i < nr_bytes; i++) {
  for (i = 0; i < nr_bytes; i++) {
    read_com(me, com, addr + i, &((char*)dest)[i]);
    read_com(me, com, addr + i, &((char*)dest)[i]);
  }
  }
  return nr_bytes;
  return nr_bytes;
}
}
 
 
 
 
static void
static void
make_write_ready(void *data)
make_write_ready(void *data)
{
{
  device *me = (device*)data;
  device *me = (device*)data;
  hw_com_device *com = (hw_com_device*)device_data(me);
  hw_com_device *com = (hw_com_device*)device_data(me);
  com->output.ready = 1;
  com->output.ready = 1;
  update_com_interrupts(me, com);
  update_com_interrupts(me, com);
}
}
 
 
static void
static void
write_com(device *me,
write_com(device *me,
          hw_com_device *com,
          hw_com_device *com,
          unsigned_word a,
          unsigned_word a,
          char val)
          char val)
{
{
  unsigned_word addr = a % 8;
  unsigned_word addr = a % 8;
 
 
  /* the divisor latch is special */
  /* the divisor latch is special */
  if (com->reg[3] & 0x8 && addr < 2) {
  if (com->reg[3] & 0x8 && addr < 2) {
    com->dlab[addr] = val;
    com->dlab[addr] = val;
    return;
    return;
  }
  }
 
 
  switch (addr) {
  switch (addr) {
 
 
  case 0:
  case 0:
    /* fifo */
    /* fifo */
    if (com->output.file == NULL) {
    if (com->output.file == NULL) {
      sim_io_write_stdout(&val, 1);
      sim_io_write_stdout(&val, 1);
    }
    }
    else {
    else {
      fwrite(&val, 1, 1, com->output.file);
      fwrite(&val, 1, 1, com->output.file);
    }
    }
    /* setup for next write */
    /* setup for next write */
    if (com->output.ready && com->output.delay > 0) {
    if (com->output.ready && com->output.delay > 0) {
      com->output.ready = 0;
      com->output.ready = 0;
      device_event_queue_schedule(me, com->output.delay, make_write_ready, me);
      device_event_queue_schedule(me, com->output.delay, make_write_ready, me);
    }
    }
    break;
    break;
 
 
  default:
  default:
    com->reg[addr] = val;
    com->reg[addr] = val;
    break;
    break;
 
 
  }
  }
  update_com_interrupts(me, com);
  update_com_interrupts(me, com);
}
}
 
 
static unsigned
static unsigned
hw_com_io_write_buffer_callback(device *me,
hw_com_io_write_buffer_callback(device *me,
                                const void *source,
                                const void *source,
                                int space,
                                int space,
                                unsigned_word addr,
                                unsigned_word addr,
                                unsigned nr_bytes,
                                unsigned nr_bytes,
                                cpu *processor,
                                cpu *processor,
                                unsigned_word cia)
                                unsigned_word cia)
{
{
  hw_com_device *com = device_data(me);
  hw_com_device *com = device_data(me);
  int i;
  int i;
  for (i = 0; i < nr_bytes; i++) {
  for (i = 0; i < nr_bytes; i++) {
    write_com(me, com, addr + i, ((char*)source)[i]);
    write_com(me, com, addr + i, ((char*)source)[i]);
  }
  }
  return nr_bytes;
  return nr_bytes;
}
}
 
 
 
 
/* instances of the hw_com device */
/* instances of the hw_com device */
 
 
static void
static void
hw_com_instance_delete(device_instance *instance)
hw_com_instance_delete(device_instance *instance)
{
{
  /* nothing to delete, the hw_com is attached to the device */
  /* nothing to delete, the hw_com is attached to the device */
  return;
  return;
}
}
 
 
static int
static int
hw_com_instance_read(device_instance *instance,
hw_com_instance_read(device_instance *instance,
                     void *buf,
                     void *buf,
                     unsigned_word len)
                     unsigned_word len)
{
{
  device *me = device_instance_device(instance);
  device *me = device_instance_device(instance);
  hw_com_device *com = device_data(me);
  hw_com_device *com = device_data(me);
  if (com->input.file == NULL)
  if (com->input.file == NULL)
    return sim_io_read_stdin(buf, len);
    return sim_io_read_stdin(buf, len);
  else {
  else {
    return fread(buf, 1, len, com->input.file);
    return fread(buf, 1, len, com->input.file);
  }
  }
}
}
 
 
static int
static int
hw_com_instance_write(device_instance *instance,
hw_com_instance_write(device_instance *instance,
                      const void *buf,
                      const void *buf,
                      unsigned_word len)
                      unsigned_word len)
{
{
  device *me = device_instance_device(instance);
  device *me = device_instance_device(instance);
  hw_com_device *com = device_data(me);
  hw_com_device *com = device_data(me);
  if (com->output.file == NULL)
  if (com->output.file == NULL)
    return sim_io_write_stdout(buf, len);
    return sim_io_write_stdout(buf, len);
  else {
  else {
    return fwrite(buf, 1, len, com->output.file);
    return fwrite(buf, 1, len, com->output.file);
  }
  }
}
}
 
 
static const device_instance_callbacks hw_com_instance_callbacks = {
static const device_instance_callbacks hw_com_instance_callbacks = {
  hw_com_instance_delete,
  hw_com_instance_delete,
  hw_com_instance_read,
  hw_com_instance_read,
  hw_com_instance_write,
  hw_com_instance_write,
};
};
 
 
static device_instance *
static device_instance *
hw_com_create_instance(device *me,
hw_com_create_instance(device *me,
                       const char *path,
                       const char *path,
                       const char *args)
                       const char *args)
{
{
  /* point an instance directly at the device */
  /* point an instance directly at the device */
  return device_create_instance_from(me, NULL,
  return device_create_instance_from(me, NULL,
                                     device_data(me),
                                     device_data(me),
                                     path, args,
                                     path, args,
                                     &hw_com_instance_callbacks);
                                     &hw_com_instance_callbacks);
}
}
 
 
 
 
static device_callbacks const hw_com_callbacks = {
static device_callbacks const hw_com_callbacks = {
  { generic_device_init_address,
  { generic_device_init_address,
    hw_com_device_init_data },
    hw_com_device_init_data },
  { NULL, }, /* address */
  { NULL, }, /* address */
  { hw_com_io_read_buffer_callback,
  { hw_com_io_read_buffer_callback,
      hw_com_io_write_buffer_callback, },
      hw_com_io_write_buffer_callback, },
  { NULL, }, /* DMA */
  { NULL, }, /* DMA */
  { NULL, }, /* interrupt */
  { NULL, }, /* interrupt */
  { NULL, }, /* unit */
  { NULL, }, /* unit */
  hw_com_create_instance,
  hw_com_create_instance,
};
};
 
 
 
 
static void *
static void *
hw_com_create(const char *name,
hw_com_create(const char *name,
              const device_unit *unit_address,
              const device_unit *unit_address,
              const char *args)
              const char *args)
{
{
  /* create the descriptor */
  /* create the descriptor */
  hw_com_device *hw_com = ZALLOC(hw_com_device);
  hw_com_device *hw_com = ZALLOC(hw_com_device);
  return hw_com;
  return hw_com;
}
}
 
 
 
 
const device_descriptor hw_com_device_descriptor[] = {
const device_descriptor hw_com_device_descriptor[] = {
  { "com", hw_com_create, &hw_com_callbacks },
  { "com", hw_com_create, &hw_com_callbacks },
  { NULL },
  { NULL },
};
};
 
 
#endif /* _HW_COM_C_ */
#endif /* _HW_COM_C_ */
 
 

powered by: WebSVN 2.1.0

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