/[gxemul]/trunk/src/devices/dev_ns16550.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/src/devices/dev_ns16550.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 24 by dpavlin, Mon Oct 8 16:19:56 2007 UTC revision 42 by dpavlin, Mon Oct 8 16:22:32 2007 UTC
# Line 1  Line 1 
1  /*  /*
2   *  Copyright (C) 2003-2006  Anders Gavare.  All rights reserved.   *  Copyright (C) 2003-2007  Anders Gavare.  All rights reserved.
3   *   *
4   *  Redistribution and use in source and binary forms, with or without   *  Redistribution and use in source and binary forms, with or without
5   *  modification, are permitted provided that the following conditions are met:   *  modification, are permitted provided that the following conditions are met:
# Line 25  Line 25 
25   *  SUCH DAMAGE.   *  SUCH DAMAGE.
26   *     *  
27   *   *
28   *  $Id: dev_ns16550.c,v 1.54 2006/04/06 18:08:42 debug Exp $   *  $Id: dev_ns16550.c,v 1.62 2007/06/15 19:57:33 debug Exp $
29   *     *  
30   *  NS16550 serial controller.   *  COMMENT: NS16550 serial controller
  *  
31   *   *
32   *  TODO: Implement the FIFO.   *  TODO: Implement the FIFO.
33   */   */
# Line 40  Line 39 
39  #include "console.h"  #include "console.h"
40  #include "cpu.h"  #include "cpu.h"
41  #include "device.h"  #include "device.h"
42    #include "interrupt.h"
43  #include "machine.h"  #include "machine.h"
44  #include "memory.h"  #include "memory.h"
45  #include "misc.h"  #include "misc.h"
# Line 55  Line 55 
55  struct ns_data {  struct ns_data {
56          int             addrmult;          int             addrmult;
57          int             in_use;          int             in_use;
         int             irqnr;  
58          char            *name;          char            *name;
59          int             console_handle;          int             console_handle;
60          int             enable_fifo;          int             enable_fifo;
61    
62            struct interrupt irq;
63    
64          unsigned char   reg[DEV_NS16550_LENGTH];          unsigned char   reg[DEV_NS16550_LENGTH];
65          unsigned char   fcr;            /*  FIFO control register  */          unsigned char   fcr;            /*  FIFO control register  */
66          int             int_asserted;          int             int_asserted;
# Line 72  struct ns_data { Line 73  struct ns_data {
73  };  };
74    
75    
76  /*  DEVICE_TICK(ns16550)
  *  dev_ns16550_tick():  
  *  
  *  This function is called at regular intervals. An interrupt is caused to the  
  *  CPU if there is a character available for reading, or if the transmitter  
  *  slot is empty (i.e. the ns16550 is ready to transmit).  
  */  
 void dev_ns16550_tick(struct cpu *cpu, void *extra)  
77  {  {
78            /*
79             *  This function is called at regular intervals. An interrupt is
80             *  asserted if there is a character available for reading, or if the
81             *  transmitter slot is empty (i.e. the ns16550 is ready to transmit).
82             */
83          struct ns_data *d = extra;          struct ns_data *d = extra;
84    
85          d->reg[com_iir] &= ~IIR_RXRDY;          d->reg[com_iir] &= ~IIR_RXRDY;
# Line 96  void dev_ns16550_tick(struct cpu *cpu, v Line 95  void dev_ns16550_tick(struct cpu *cpu, v
95              ((d->reg[com_ier] & IER_ERXRDY) && (d->reg[com_iir] & IIR_RXRDY))) {              ((d->reg[com_ier] & IER_ERXRDY) && (d->reg[com_iir] & IIR_RXRDY))) {
96                  d->reg[com_iir] &= ~IIR_NOPEND;                  d->reg[com_iir] &= ~IIR_NOPEND;
97                  if (d->reg[com_mcr] & MCR_IENABLE) {                  if (d->reg[com_mcr] & MCR_IENABLE) {
98                          cpu_interrupt(cpu, d->irqnr);                          INTERRUPT_ASSERT(d->irq);
99                          d->int_asserted = 1;                          d->int_asserted = 1;
100                  }                  }
101          } else {          } else {
102                  d->reg[com_iir] |= IIR_NOPEND;                  d->reg[com_iir] |= IIR_NOPEND;
103                  if (d->int_asserted)                  if (d->int_asserted)
104                          cpu_interrupt_ack(cpu, d->irqnr);                          INTERRUPT_DEASSERT(d->irq);
105                  d->int_asserted = 0;                  d->int_asserted = 0;
106          }          }
107  }  }
108    
109    
 /*  
  *  dev_ns16550_access():  
  */  
110  DEVICE_ACCESS(ns16550)  DEVICE_ACCESS(ns16550)
111  {  {
112          uint64_t idata = 0, odata=0;          uint64_t idata = 0, odata=0;
# Line 325  DEVICE_ACCESS(ns16550) Line 321  DEVICE_ACCESS(ns16550)
321    
322  DEVINIT(ns16550)  DEVINIT(ns16550)
323  {  {
324          struct ns_data *d = malloc(sizeof(struct ns_data));          struct ns_data *d;
325          size_t nlen;          size_t nlen;
326          char *name;          char *name;
327    
328          if (d == NULL) {          CHECK_ALLOCATION(d = malloc(sizeof(struct ns_data)));
                 fprintf(stderr, "out of memory\n");  
                 exit(1);  
         }  
329          memset(d, 0, sizeof(struct ns_data));          memset(d, 0, sizeof(struct ns_data));
330          d->irqnr        = devinit->irq_nr;  
331          d->addrmult     = devinit->addr_mult;          d->addrmult     = devinit->addr_mult;
332          d->in_use       = devinit->in_use;          d->in_use       = devinit->in_use;
333          d->enable_fifo  = 1;          d->enable_fifo  = 1;
# Line 348  DEVINIT(ns16550) Line 341  DEVINIT(ns16550)
341              console_start_slave(devinit->machine, devinit->name2 != NULL?              console_start_slave(devinit->machine, devinit->name2 != NULL?
342              devinit->name2 : devinit->name, d->in_use);              devinit->name2 : devinit->name, d->in_use);
343    
344            INTERRUPT_CONNECT(devinit->interrupt_path, d->irq);
345    
346          nlen = strlen(devinit->name) + 10;          nlen = strlen(devinit->name) + 10;
347          if (devinit->name2 != NULL)          if (devinit->name2 != NULL)
348                  nlen += strlen(devinit->name2);                  nlen += strlen(devinit->name2);
349          name = malloc(nlen);          CHECK_ALLOCATION(name = malloc(nlen));
         if (name == NULL) {  
                 fprintf(stderr, "out of memory\n");  
                 exit(1);  
         }  
350          if (devinit->name2 != NULL && devinit->name2[0])          if (devinit->name2 != NULL && devinit->name2[0])
351                  snprintf(name, nlen, "%s [%s]", devinit->name, devinit->name2);                  snprintf(name, nlen, "%s [%s]", devinit->name, devinit->name2);
352          else          else
# Line 365  DEVINIT(ns16550) Line 356  DEVINIT(ns16550)
356              DEV_NS16550_LENGTH * d->addrmult, dev_ns16550_access, d,              DEV_NS16550_LENGTH * d->addrmult, dev_ns16550_access, d,
357              DM_DEFAULT, NULL);              DM_DEFAULT, NULL);
358          machine_add_tickfunction(devinit->machine,          machine_add_tickfunction(devinit->machine,
359              dev_ns16550_tick, d, TICK_SHIFT, 0.0);              dev_ns16550_tick, d, TICK_SHIFT);
360    
361          /*          /*
362           *  NOTE:  Ugly cast into a pointer, because this is a convenient way           *  NOTE:  Ugly cast into a pointer, because this is a convenient way
363           *         to return the console handle to code in src/machine.c.           *         to return the console handle to code in src/machines/.
364           */           */
365          devinit->return_ptr = (void *)(size_t)d->console_handle;          devinit->return_ptr = (void *)(size_t)d->console_handle;
366    

Legend:
Removed from v.24  
changed lines
  Added in v.42

  ViewVC Help
Powered by ViewVC 1.1.26