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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_66/] [or1ksim/] [peripheral/] [16450.c] - Diff between revs 238 and 252

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

Rev 238 Rev 252
/* 16450.c -- Simulation of 8250/16450 serial UART
/* 16450.c -- Simulation of 8250/16450 serial UART
   Copyright (C) 1999 Damjan Lampret, lampret@opencores.org
   Copyright (C) 1999 Damjan Lampret, lampret@opencores.org
 
 
This file is part of OpenRISC 1000 Architectural Simulator.
This file is part of OpenRISC 1000 Architectural Simulator.
 
 
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., 675 Mass Ave, Cambridge, MA 02139, USA. */
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
 
 
/* This is functional simulation of 8250/16450 UARTs. Since we RX/TX data
/* This is functional simulation of 8250/16450 UARTs. Since we RX/TX data
   via file streams, we can't simulate modem control lines coming from the
   via file streams, we can't simulate modem control lines coming from the
   DCE and similar details of communication with the DCE.
   DCE and similar details of communication with the DCE.
 
 
   This simulated UART device is intended for basic UART device driver
   This simulated UART device is intended for basic UART device driver
   verification. From device driver perspective this device looks like a
   verification. From device driver perspective this device looks like a
   regular UART but never reports and modem control lines changes (the
   regular UART but never reports and modem control lines changes (the
   only DCE responses are incoming characters from the file stream).
   only DCE responses are incoming characters from the file stream).
*/
*/
 
 
#include <stdlib.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdio.h>
#include <string.h>
#include <string.h>
 
 
#include "abstract.h"
#include "abstract.h"
#include "16450.h"
#include "16450.h"
#include "sim-config.h"
#include "sim-config.h"
#include "pic.h"
#include "pic.h"
 
 
static struct dev_16450 uarts[NR_UARTS];
static struct dev_16450 uarts[NR_UARTS];
static int thre_int;
static int thre_int;
 
 
/* Number of clock cycles (one clock cycle is one call to the uart_clock())
/* Number of clock cycles (one clock cycle is one call to the uart_clock())
   before a single character is transmitted or received. */
   before a single character is transmitted or received. */
static void set_char_clks(int uartchip)
static void set_char_clks(int uartchip)
{
{
        int bauds_per_char = 0;
        int bauds_per_char = 0;
 
 
        uarts[uartchip].char_clks = (uarts[uartchip].regs.dlh << 8)
        uarts[uartchip].char_clks = (uarts[uartchip].regs.dlh << 8)
                                        + uarts[uartchip].regs.dll;
                                        + uarts[uartchip].regs.dll;
 
 
        if (uarts[uartchip].regs.lcr & UART_LCR_PARITY)
        if (uarts[uartchip].regs.lcr & UART_LCR_PARITY)
                bauds_per_char++;
                bauds_per_char++;
 
 
        if (uarts[uartchip].regs.lcr & UART_LCR_STOP)
        if (uarts[uartchip].regs.lcr & UART_LCR_STOP)
                bauds_per_char += 2;
                bauds_per_char += 2;
        else
        else
                bauds_per_char++;
                bauds_per_char++;
 
 
        bauds_per_char += (5 + (uarts[uartchip].regs.lcr & 0x2));
        bauds_per_char += (5 + (uarts[uartchip].regs.lcr & 0x2));
 
 
        uarts[uartchip].char_clks *= bauds_per_char;
        uarts[uartchip].char_clks *= bauds_per_char;
}
}
 
 
/* Set a specific UART register with value. */
/* Set a specific UART register with value. */
void uart_write_byte(unsigned long addr, unsigned long value)
void uart_write_byte(unsigned long addr, unsigned long value)
{
{
        int chipsel;
        int chipsel;
 
 
        debug("uart_write_byte(%x,%02x)\n", addr, (unsigned)value);
        debug("uart_write_byte(%x,%02x)\n", addr, (unsigned)value);
 
 
        for(chipsel = 0; chipsel < NR_UARTS; chipsel++)
        for(chipsel = 0; chipsel < NR_UARTS; chipsel++)
                if ((addr & ~(UART_ADDR_SPACE-1)) == uarts[chipsel].baseaddr)
                if ((addr & ~(UART_ADDR_SPACE-1)) == uarts[chipsel].baseaddr)
                        break;
                        break;
                else if (chipsel == NR_UARTS)
                else if (chipsel == NR_UARTS)
                        return;
                        return;
 
 
        if (uarts[chipsel].regs.lcr & UART_LCR_DLAB) {
        if (uarts[chipsel].regs.lcr & UART_LCR_DLAB) {
                switch (addr % UART_ADDR_SPACE) {
                switch (addr % UART_ADDR_SPACE) {
                        case UART_DLL:
                        case UART_DLL:
                                uarts[chipsel].regs.dll = value;
                                uarts[chipsel].regs.dll = value;
                                break;
                                break;
                        case UART_DLH:
                        case UART_DLH:
                                uarts[chipsel].regs.dlh = value;
                                uarts[chipsel].regs.dlh = value;
                                break;
                                break;
                        case UART_LCR:
                        case UART_LCR:
                                uarts[chipsel].regs.lcr = value & UART_VALID_LCR;
                                uarts[chipsel].regs.lcr = value & UART_VALID_LCR;
                                break;
                                break;
                        default:
                        default:
                                debug("write out of range (addr %x, DLAB=1)\n", addr);
                                debug("write out of range (addr %x, DLAB=1)\n", addr);
                }
                }
                set_char_clks(chipsel);
                set_char_clks(chipsel);
                return;
                return;
        }
        }
 
 
        switch (addr % UART_ADDR_SPACE) {
        switch (addr % UART_ADDR_SPACE) {
                case UART_TXBUF:
                case UART_TXBUF:
                        uarts[chipsel].regs.txbuf = value;
                        uarts[chipsel].regs.txbuf = value;
                        uarts[chipsel].istat.txbuf = FULL;
                        uarts[chipsel].istat.txbuf = FULL;
                        uarts[chipsel].regs.lsr &= ~UART_LSR_TXBUFE;
                        uarts[chipsel].regs.lsr &= ~UART_LSR_TXBUFE;
                        uarts[chipsel].regs.lsr &= ~UART_LSR_TXSERE;
                        uarts[chipsel].regs.lsr &= ~UART_LSR_TXSERE;
                        uarts[chipsel].istat.thre_int = 0;
                        uarts[chipsel].istat.thre_int = 0;
                        break;
                        break;
                case UART_IER:
                case UART_IER:
                        uarts[chipsel].regs.ier = value & UART_VALID_IER;
                        uarts[chipsel].regs.ier = value & UART_VALID_IER;
                        break;
                        break;
                case UART_LCR:
                case UART_LCR:
                        uarts[chipsel].regs.lcr = value & UART_VALID_LCR;
                        uarts[chipsel].regs.lcr = value & UART_VALID_LCR;
                        break;
                        break;
                case UART_MCR:
                case UART_MCR:
                        uarts[chipsel].regs.mcr = value & UART_VALID_MCR;
                        uarts[chipsel].regs.mcr = value & UART_VALID_MCR;
                        break;
                        break;
                case UART_SCR:
                case UART_SCR:
                        uarts[chipsel].regs.scr = value;
                        uarts[chipsel].regs.scr = value;
                        break;
                        break;
                default:
                default:
                        debug("write out of range (addr %x)\n", addr);
                        debug("write out of range (addr %x)\n", addr);
        }
        }
        set_char_clks(chipsel);
        set_char_clks(chipsel);
        return;
        return;
}
}
 
 
/* Read a specific UART register. */
/* Read a specific UART register. */
unsigned long uart_read_byte(unsigned long addr)
unsigned long uart_read_byte(unsigned long addr)
{
{
        unsigned char value = 0;
        unsigned char value = 0;
        int chipsel;
        int chipsel;
 
 
        debug("uart_read_byte(%x)\n", addr);
        debug("uart_read_byte(%x)\n", addr);
 
 
        for(chipsel = 0; chipsel < NR_UARTS; chipsel++)
        for(chipsel = 0; chipsel < NR_UARTS; chipsel++)
                if ((addr & ~(UART_ADDR_SPACE-1)) == uarts[chipsel].baseaddr)
                if ((addr & ~(UART_ADDR_SPACE-1)) == uarts[chipsel].baseaddr)
                        break;
                        break;
                else if (chipsel == NR_UARTS)
                else if (chipsel == NR_UARTS)
                        return 0;
                        return 0;
 
 
        if (uarts[chipsel].regs.lcr & UART_LCR_DLAB) {
        if (uarts[chipsel].regs.lcr & UART_LCR_DLAB) {
                switch (addr % UART_ADDR_SPACE) {
                switch (addr % UART_ADDR_SPACE) {
                        case UART_DLL:
                        case UART_DLL:
                                value = uarts[chipsel].regs.dll;
                                value = uarts[chipsel].regs.dll;
                                break;
                                break;
                        case UART_DLH:
                        case UART_DLH:
                                value = uarts[chipsel].regs.dlh;
                                value = uarts[chipsel].regs.dlh;
                                break;
                                break;
                        default:
                        default:
                                debug("read out of range (addr %x, DLAB=1)\n", addr);
                                debug("read out of range (addr %x, DLAB=1)\n", addr);
                }
                }
                return value;
                return value;
        }
        }
 
 
        switch (addr % UART_ADDR_SPACE) {
        switch (addr % UART_ADDR_SPACE) {
                case UART_RXBUF:
                case UART_RXBUF:
                        value = uarts[chipsel].regs.rxbuf;
                        value = uarts[chipsel].regs.rxbuf;
                        uarts[chipsel].istat.rxbuf = EMPTY;
                        uarts[chipsel].istat.rxbuf = EMPTY;
                        uarts[chipsel].regs.lsr &= ~UART_LSR_RDRDY;
                        uarts[chipsel].regs.lsr &= ~UART_LSR_RDRDY;
                        break;
                        break;
                case UART_IER:
                case UART_IER:
                        value = uarts[chipsel].regs.ier & UART_VALID_IER;
                        value = uarts[chipsel].regs.ier & UART_VALID_IER;
                        break;
                        break;
                case UART_IIR:
                case UART_IIR:
                        value = uarts[chipsel].regs.iir & UART_VALID_IIR;
                        value = uarts[chipsel].regs.iir & UART_VALID_IIR;
                        uarts[chipsel].istat.thre_int = 0;
                        uarts[chipsel].istat.thre_int = 0;
                        break;
                        break;
                case UART_LCR:
                case UART_LCR:
                        value = uarts[chipsel].regs.lcr & UART_VALID_LCR;
                        value = uarts[chipsel].regs.lcr & UART_VALID_LCR;
                        break;
                        break;
                case UART_MCR:
                case UART_MCR:
                        value = uarts[chipsel].regs.mcr & UART_VALID_MCR;
                        value = uarts[chipsel].regs.mcr & UART_VALID_MCR;
                        break;
                        break;
                case UART_LSR:
                case UART_LSR:
                        value = uarts[chipsel].regs.lsr & UART_VALID_LSR;
                        value = uarts[chipsel].regs.lsr & UART_VALID_LSR;
                        uarts[chipsel].regs.lsr &=
                        uarts[chipsel].regs.lsr &=
                                ~(UART_LSR_OVRRUN | UART_LSR_PARITY
                                ~(UART_LSR_OVRRUN | UART_LSR_PARITY
                                 | UART_LSR_FRAME | UART_LSR_BREAK);
                                 | UART_LSR_FRAME | UART_LSR_BREAK);
                        break;
                        break;
                case UART_MSR:
                case UART_MSR:
                        value = uarts[chipsel].regs.msr & UART_VALID_MSR;
                        value = uarts[chipsel].regs.msr & UART_VALID_MSR;
                        uarts[chipsel].regs.msr = 0;
                        uarts[chipsel].regs.msr = 0;
                        break;
                        break;
                case UART_SCR:
                case UART_SCR:
                        value = uarts[chipsel].regs.scr;
                        value = uarts[chipsel].regs.scr;
                        break;
                        break;
                default:
                default:
                        debug("read out of range (addr %x)\n", addr);
                        debug("read out of range (addr %x)\n", addr);
        }
        }
        return value;
        return value;
}
}
 
 
/* Reset. It initializes all registers of all UART devices to zero values,
/* Reset. It initializes all registers of all UART devices to zero values,
   (re)opens all RX/TX file streams and places devices in memory address
   (re)opens all RX/TX file streams and places devices in memory address
   space. */
   space. */
void uart_reset()
void uart_reset()
{
{
        int i;
        int i;
 
 
        printf("Resetting %u UART(s).\n", NR_UARTS);
        printf("Resetting %u UART(s).\n", NR_UARTS);
        memset(uarts, 0, sizeof(uarts));
        memset(uarts, 0, sizeof(uarts));
 
 
        for(i = 0; i < NR_UARTS; i++)
        for(i = 0; i < NR_UARTS; i++)
                if (config.uarts[i].txfile) { /* MM: Try to create stream.  */
                if (config.uarts[i].txfile) { /* MM: Try to create stream.  */
                        if (!(uarts[i].rxfs = fopen(config.uarts[i].rxfile, "r"))
                        if (!(uarts[i].rxfs = fopen(config.uarts[i].rxfile, "r"))
                                && !(uarts[i].rxfs = fopen(config.uarts[i].rxfile, "r+"))) {
                                && !(uarts[i].rxfs = fopen(config.uarts[i].rxfile, "r+"))) {
                                printf("UART%d has problems with RX file stream.\n", i);
                                printf("UART%d has problems with RX file stream.\n", i);
                                continue;
                                continue;
                        }
                        }
                        uarts[i].txfs = fopen(config.uarts[i].txfile, "a");
                        uarts[i].txfs = fopen(config.uarts[i].txfile, "a");
                        uarts[i].baseaddr = config.uarts[i].baseaddr;
                        uarts[i].baseaddr = config.uarts[i].baseaddr;
                        if (uarts[i].txfs && uarts[i].txfs) {
                        if (uarts[i].rxfs && uarts[i].txfs) {
                                printf("UART%d at 0x%.8x uses ", i, uarts[i].baseaddr);
                                printf("UART%d at 0x%.8x uses ", i, uarts[i].baseaddr);
                                printf("%s for RX and %s for TX.\n", config.uarts[i].rxfile, config.uarts[i].txfile);
                                printf("%s for RX and %s for TX.\n", config.uarts[i].rxfile, config.uarts[i].txfile);
                        } else
                        } else
                                printf("UART%d has problems with TX file stream.\n", i);
                                printf("UART%d has problems with TX file stream.\n", i);
                        register_memoryarea(uarts[i].baseaddr, UART_ADDR_SPACE, 1, uart_read_byte, uart_write_byte, 0);
                        register_memoryarea(uarts[i].baseaddr, UART_ADDR_SPACE, 1, uart_read_byte, uart_write_byte, 0);
                }
                }
}
}
 
 
/* Simulation hook. Must be called every clock cycle to simulate all UART
/* Simulation hook. Must be called every clock cycle to simulate all UART
   devices. It does internal functional UART simulation. */
   devices. It does internal functional UART simulation. */
void uart_clock()
void uart_clock()
{
{
        int i, retval;
        int i, retval;
 
 
        for(i = 0; i < NR_UARTS; i++) {
        for(i = 0; i < NR_UARTS; i++) {
                if (!uarts[i].txfs) {
                if (!uarts[i].txfs) {
                        continue;
                        continue;
                }
                }
 
 
                /* Transmit */
                /* Transmit */
                if (uarts[i].istat.txser == EMPTY) {
                if (uarts[i].istat.txser == EMPTY) {
                        uarts[i].regs.lsr |= UART_LSR_TXBUFE;
                        uarts[i].regs.lsr |= UART_LSR_TXBUFE;
                        if (uarts[i].istat.txbuf == FULL) {
                        if (uarts[i].istat.txbuf == FULL) {
                                uarts[i].iregs.txser = uarts[i].regs.txbuf;
                                uarts[i].iregs.txser = uarts[i].regs.txbuf;
                                uarts[i].istat.txser = FULL;
                                uarts[i].istat.txser = FULL;
                                uarts[i].istat.txbuf = EMPTY;
                                uarts[i].istat.txbuf = EMPTY;
                                uarts[i].regs.lsr &= ~UART_LSR_TXSERE;
                                uarts[i].regs.lsr &= ~UART_LSR_TXSERE;
                                uarts[i].istat.thre_int = 1;
                                uarts[i].istat.thre_int = 1;
                        } else
                        } else
                                uarts[i].regs.lsr |= UART_LSR_TXSERE;
                                uarts[i].regs.lsr |= UART_LSR_TXSERE;
                } else if (uarts[i].char_clks == uarts[i].istat.txser_clks++) {
                } else if (uarts[i].char_clks == uarts[i].istat.txser_clks++) {
                        debug("TX \'%c\' via UART%d...\n", uarts[i].iregs.txser, i);
                        debug("TX \'%c\' via UART%d...\n", uarts[i].iregs.txser, i);
                        if (uarts[i].regs.mcr & UART_MCR_LOOP)
                        if (uarts[i].regs.mcr & UART_MCR_LOOP)
                                uarts[i].iregs.loopback = uarts[i].iregs.txser;
                                uarts[i].iregs.loopback = uarts[i].iregs.txser;
                        else {
                        else {
                                fputc((int)uarts[i].iregs.txser, uarts[i].txfs);
                                fputc((int)uarts[i].iregs.txser, uarts[i].txfs);
                                fflush(uarts[i].txfs);
                                fflush(uarts[i].txfs);
                        }
                        }
                        uarts[i].istat.txser = EMPTY;
                        uarts[i].istat.txser = EMPTY;
                        uarts[i].istat.txser_clks = 0;
                        uarts[i].istat.txser_clks = 0;
                }
                }
 
 
                /* Receive */
                /* Receive */
                if (uarts[i].istat.rxser == EMPTY)
                if (uarts[i].istat.rxser == EMPTY)
                        uarts[i].istat.rxser = FULL;
                        uarts[i].istat.rxser = FULL;
                else if (uarts[i].char_clks == uarts[i].istat.rxser_clks++) {
                else if (uarts[i].char_clks == uarts[i].istat.rxser_clks++) {
                        debug("Receiving via UART%d...\n", i);
                        debug("Receiving via UART%d...\n", i);
                        if (uarts[i].regs.mcr & UART_MCR_LOOP)
                        if (uarts[i].regs.mcr & UART_MCR_LOOP)
                                uarts[i].iregs.rxser = uarts[i].iregs.loopback;
                                uarts[i].iregs.rxser = uarts[i].iregs.loopback;
                        else if((retval = fgetc(uarts[i].rxfs)) != EOF) {
                        else if((retval = fgetc(uarts[i].rxfs)) != EOF) {
                                uarts[i].iregs.rxser = (char)retval;
                                uarts[i].iregs.rxser = (char)retval;
                                if (uarts[i].istat.rxbuf == FULL)
                                if (uarts[i].istat.rxbuf == FULL)
                                        uarts[i].regs.lsr |= UART_LSR_OVRRUN;
                                        uarts[i].regs.lsr |= UART_LSR_OVRRUN;
                                uarts[i].regs.lsr |= UART_LSR_RDRDY;
                                uarts[i].regs.lsr |= UART_LSR_RDRDY;
                                uarts[i].regs.rxbuf = uarts[i].iregs.rxser;
                                uarts[i].regs.rxbuf = uarts[i].iregs.rxser;
                                uarts[i].istat.rxbuf = FULL;
                                uarts[i].istat.rxbuf = FULL;
                        }
                        }
                        uarts[i].istat.rxser = EMPTY;
                        uarts[i].istat.rxser = EMPTY;
                        uarts[i].istat.rxser_clks = 0;
                        uarts[i].istat.rxser_clks = 0;
                }
                }
 
 
                /* Loopback */
                /* Loopback */
                if (uarts[i].regs.mcr & UART_MCR_LOOP) {
                if (uarts[i].regs.mcr & UART_MCR_LOOP) {
                        debug("uart_clock: Loopback\n");
                        debug("uart_clock: Loopback\n");
                        if ((uarts[i].regs.mcr & UART_MCR_AUX2) !=
                        if ((uarts[i].regs.mcr & UART_MCR_AUX2) !=
                            ((uarts[i].regs.msr & UART_MSR_DCD) >> 4))
                            ((uarts[i].regs.msr & UART_MSR_DCD) >> 4))
                                uarts[i].regs.msr |= UART_MSR_DDCD;
                                uarts[i].regs.msr |= UART_MSR_DDCD;
                        if ((uarts[i].regs.mcr & UART_MCR_AUX1) <
                        if ((uarts[i].regs.mcr & UART_MCR_AUX1) <
                            ((uarts[i].regs.msr & UART_MSR_RI) >> 4))
                            ((uarts[i].regs.msr & UART_MSR_RI) >> 4))
                                uarts[i].regs.msr |= UART_MSR_TERI;
                                uarts[i].regs.msr |= UART_MSR_TERI;
                        if ((uarts[i].regs.mcr & UART_MCR_RTS) !=
                        if ((uarts[i].regs.mcr & UART_MCR_RTS) !=
                            ((uarts[i].regs.msr & UART_MSR_CTS) >> 3))
                            ((uarts[i].regs.msr & UART_MSR_CTS) >> 3))
                                uarts[i].regs.msr |= UART_MSR_DCTS;
                                uarts[i].regs.msr |= UART_MSR_DCTS;
                        if ((uarts[i].regs.mcr & UART_MCR_DTR) !=
                        if ((uarts[i].regs.mcr & UART_MCR_DTR) !=
                            ((uarts[i].regs.msr & UART_MSR_DSR) >> 5))
                            ((uarts[i].regs.msr & UART_MSR_DSR) >> 5))
                                uarts[i].regs.msr |= UART_MSR_DDSR;
                                uarts[i].regs.msr |= UART_MSR_DDSR;
                        uarts[i].regs.msr &= ~(UART_MSR_DCD | UART_MSR_RI
                        uarts[i].regs.msr &= ~(UART_MSR_DCD | UART_MSR_RI
                                              | UART_MSR_DSR | UART_MSR_CTS);
                                              | UART_MSR_DSR | UART_MSR_CTS);
                        uarts[i].regs.msr |= ((uarts[i].regs.mcr & UART_MCR_AUX2) << 4);
                        uarts[i].regs.msr |= ((uarts[i].regs.mcr & UART_MCR_AUX2) << 4);
                        uarts[i].regs.msr |= ((uarts[i].regs.mcr & UART_MCR_AUX1) << 4);
                        uarts[i].regs.msr |= ((uarts[i].regs.mcr & UART_MCR_AUX1) << 4);
                        uarts[i].regs.msr |= ((uarts[i].regs.mcr & UART_MCR_RTS) << 3);
                        uarts[i].regs.msr |= ((uarts[i].regs.mcr & UART_MCR_RTS) << 3);
                        uarts[i].regs.msr |= ((uarts[i].regs.mcr & UART_MCR_DTR) << 5);
                        uarts[i].regs.msr |= ((uarts[i].regs.mcr & UART_MCR_DTR) << 5);
                }
                }
 
 
                /* Interrupt detection in proper priority order. */
                /* Interrupt detection in proper priority order. */
                uarts[i].regs.iir = UART_IIR_NO_INT;
                uarts[i].regs.iir = UART_IIR_NO_INT;
                if (uarts[i].regs.ier & UART_IER_RLSI &&
                if (uarts[i].regs.ier & UART_IER_RLSI &&
                    uarts[i].regs.lsr & (UART_LSR_OVRRUN | UART_LSR_PARITY
                    uarts[i].regs.lsr & (UART_LSR_OVRRUN | UART_LSR_PARITY
                                        | UART_LSR_FRAME | UART_LSR_BREAK)) {
                                        | UART_LSR_FRAME | UART_LSR_BREAK)) {
                        uarts[i].regs.iir = UART_IIR_RLSI;
                        uarts[i].regs.iir = UART_IIR_RLSI;
                }
                }
                else if (uarts[i].regs.ier & UART_IER_RDI &&
                else if (uarts[i].regs.ier & UART_IER_RDI &&
                    uarts[i].regs.lsr & UART_LSR_RDRDY) {
                    uarts[i].regs.lsr & UART_LSR_RDRDY) {
                        uarts[i].regs.iir = UART_IIR_RDI;
                        uarts[i].regs.iir = UART_IIR_RDI;
                }
                }
                else if (uarts[i].regs.ier & UART_IER_THRI &&
                else if (uarts[i].regs.ier & UART_IER_THRI &&
                    uarts[i].regs.lsr & UART_LSR_TXBUFE &&
                    uarts[i].regs.lsr & UART_LSR_TXBUFE &&
                    uarts[i].istat.thre_int == 1) {
                    uarts[i].istat.thre_int == 1) {
                        uarts[i].regs.iir = UART_IIR_THRI;
                        uarts[i].regs.iir = UART_IIR_THRI;
                }
                }
                else if (uarts[i].regs.ier & UART_IER_MSI &&
                else if (uarts[i].regs.ier & UART_IER_MSI &&
                    uarts[i].regs.msr & (UART_MSR_DCTS | UART_MSR_DDSR
                    uarts[i].regs.msr & (UART_MSR_DCTS | UART_MSR_DDSR
                                        | UART_MSR_TERI | UART_MSR_DDCD)) {
                                        | UART_MSR_TERI | UART_MSR_DDCD)) {
                        uarts[i].regs.iir = UART_IIR_MSI;
                        uarts[i].regs.iir = UART_IIR_MSI;
                }
                }
                if (!(uarts[i].regs.iir & UART_IIR_NO_INT))
                if (!(uarts[i].regs.iir & UART_IIR_NO_INT))
                        report_interrupt(INT_UART);
                        report_interrupt(INT_UART);
        }
        }
}
}
 
 
/* Print register values on stdout. */
/* Print register values on stdout. */
void uart_status()
void uart_status()
{
{
        int i;
        int i;
 
 
        for(i = 0; i < NR_UARTS; i++) {
        for(i = 0; i < NR_UARTS; i++) {
                if ( !uarts[i].baseaddr )
                if ( !uarts[i].baseaddr )
                        continue;
                        continue;
                printf("\nUART%d visible registers at 0x%.8x:\n", i, uarts[i].baseaddr);
                printf("\nUART%d visible registers at 0x%.8x:\n", i, uarts[i].baseaddr);
                printf("RXBUF: %.2x  TXBUF: %.2x\n", uarts[i].regs.rxbuf, uarts[i].regs.txbuf);
                printf("RXBUF: %.2x  TXBUF: %.2x\n", uarts[i].regs.rxbuf, uarts[i].regs.txbuf);
                printf("DLL  : %.2x  DLH  : %.2x\n", uarts[i].regs.dll, uarts[i].regs.dlh);
                printf("DLL  : %.2x  DLH  : %.2x\n", uarts[i].regs.dll, uarts[i].regs.dlh);
                printf("IER  : %.2x  IIR  : %.2x\n", uarts[i].regs.ier, uarts[i].regs.iir);
                printf("IER  : %.2x  IIR  : %.2x\n", uarts[i].regs.ier, uarts[i].regs.iir);
                printf("LCR  : %.2x  MCR  : %.2x\n", uarts[i].regs.lcr, uarts[i].regs.mcr);
                printf("LCR  : %.2x  MCR  : %.2x\n", uarts[i].regs.lcr, uarts[i].regs.mcr);
                printf("LSR  : %.2x  MSR  : %.2x\n", uarts[i].regs.lsr, uarts[i].regs.msr);
                printf("LSR  : %.2x  MSR  : %.2x\n", uarts[i].regs.lsr, uarts[i].regs.msr);
                printf("SCR  : %.2x\n", uarts[i].regs.scr);
                printf("SCR  : %.2x\n", uarts[i].regs.scr);
 
 
                printf("\nInternal registers (sim debug):\n");
                printf("\nInternal registers (sim debug):\n");
                printf("RXSER: %.2x  TXSER: %.2x\n", uarts[i].iregs.rxser, uarts[i].iregs.txser);
                printf("RXSER: %.2x  TXSER: %.2x\n", uarts[i].iregs.rxser, uarts[i].iregs.txser);
 
 
                printf("\nInternal status (sim debug):\n");
                printf("\nInternal status (sim debug):\n");
                printf("char_clks: %d\n", uarts[i].char_clks);
                printf("char_clks: %d\n", uarts[i].char_clks);
                printf("rxser_clks: %d  txser_clks: %d\n", uarts[i].istat.rxser_clks, uarts[i].istat.txser_clks);
                printf("rxser_clks: %d  txser_clks: %d\n", uarts[i].istat.rxser_clks, uarts[i].istat.txser_clks);
                printf("rxser: %d  txser: %d\n", uarts[i].istat.rxser, uarts[i].istat.txser);
                printf("rxser: %d  txser: %d\n", uarts[i].istat.rxser, uarts[i].istat.txser);
                printf("rxbuf: %d  txbuf: %d\n", uarts[i].istat.rxbuf, uarts[i].istat.txbuf);
                printf("rxbuf: %d  txbuf: %d\n", uarts[i].istat.rxbuf, uarts[i].istat.txbuf);
 
 
                printf("RX fs: %p  TX fs: %p\n\n", uarts[i].rxfs, uarts[i].txfs);
                printf("RX fs: %p  TX fs: %p\n\n", uarts[i].rxfs, uarts[i].txfs);
        }
        }
}
}
 
 

powered by: WebSVN 2.1.0

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