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

Subversion Repositories test_project

[/] [test_project/] [trunk/] [sw/] [uart/] [uart.c] - Diff between revs 25 and 52

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

Rev 25 Rev 52
Line 1... Line 1...
#include "../support/support.h"
#include "../support/support.h"
#include "../support/board.h"
#include "../support/board.h"
#include "uart.h"
#include "../support/uart.h"
 
 
 
void uart_print_str(char *);
 
void uart_print_long(unsigned long);
 
 
#define BOTH_EMPTY (UART_LSR_TEMT | UART_LSR_THRE)
// Dummy or32 except vectors
 
void buserr_except(){}
 
void dpf_except(){}
 
void ipf_except(){}
 
void lpint_except(){}
 
void align_except(){}
 
void illegal_except(){}
 
void hpint_except(){}
 
void dtlbmiss_except(){}
 
void itlbmiss_except(){}
 
void range_except(){}
 
void syscall_except(){}
 
void res1_except(){}
 
void trap_except(){}
 
void res2_except(){}
 
 
#define WAIT_FOR_XMITR \
 
        do { \
 
                lsr = REG8(UART_BASE + UART_LSR); \
 
        } while ((lsr & BOTH_EMPTY) != BOTH_EMPTY)
 
 
 
#define WAIT_FOR_THRE \
 
        do { \
 
                lsr = REG8(UART_BASE + UART_LSR); \
 
        } while ((lsr & UART_LSR_THRE) != UART_LSR_THRE)
 
 
 
#define CHECK_FOR_CHAR (REG8(UART_BASE + UART_LSR) & UART_LSR_DR)
 
 
 
#define WAIT_FOR_CHAR \
 
         do { \
 
                lsr = REG8(UART_BASE + UART_LSR); \
 
         } while ((lsr & UART_LSR_DR) != UART_LSR_DR)
 
 
 
#define UART_TX_BUFF_LEN 32
 
#define UART_TX_BUFF_MASK (UART_TX_BUFF_LEN -1)
 
 
 
char tx_buff[UART_TX_BUFF_LEN];
 
volatile int tx_level, rx_level;
 
 
 
void uart_init(void)
 
{
 
        int devisor;
 
 
 
        /* Reset receiver and transmiter */
 
        REG8(UART_BASE + UART_FCR) = UART_FCR_ENABLE_FIFO | UART_FCR_CLEAR_RCVR | UART_FCR_CLEAR_XMIT | UART_FCR_TRIGGER_14;
 
 
 
        /* Disable all interrupts */
 
        REG8(UART_BASE + UART_IER) = 0x00;
 
 
 
        /* Set 8 bit char, 1 stop bit, no parity */
 
        REG8(UART_BASE + UART_LCR) = UART_LCR_WLEN8 & ~(UART_LCR_STOP | UART_LCR_PARITY);
 
 
 
        /* Set baud rate */
 
        devisor = IN_CLK/(16 * UART_BAUD_RATE);
 
        REG8(UART_BASE + UART_LCR) |= UART_LCR_DLAB;
 
        REG8(UART_BASE + UART_DLL) = devisor & 0x000000ff;
 
        REG8(UART_BASE + UART_DLM) = (devisor >> 8) & 0x000000ff;
 
        REG8(UART_BASE + UART_LCR) &= ~(UART_LCR_DLAB);
 
 
 
        return;
 
}
 
 
 
void uart_putc(char c)
 
{
 
        unsigned char lsr;
 
 
 
        WAIT_FOR_THRE;
 
        REG8(UART_BASE + UART_TX) = c;
 
        if(c == '\n') {
 
          WAIT_FOR_THRE;
 
          REG8(UART_BASE + UART_TX) = '\r';
 
        }
 
        WAIT_FOR_XMITR;
 
}
 
 
 
void uart_print_str(char *p)
void uart_print_str(char *p)
{
{
        while(*p != 0) {
        while(*p != 0) {
                uart_putc(*p);
                uart_putc(*p);
                p++;
                p++;
        }
        }
}
}
 
 
 
 
void uart_print_long(unsigned long ul)
void uart_print_long(unsigned long ul)
{
{
  int i;
  int i;
  char c;
  char c;
 
 
Line 90... Line 47...
  uart_putc(c);
  uart_putc(c);
  }
  }
 
 
}
}
 
 
 
 
void uart_print_short(unsigned long ul)
void uart_print_short(unsigned long ul)
{
{
  int i;
  int i;
  char c;
  char c;
  char flag=0;
  char flag=0;
Line 116... Line 72...
 
 
}
}
 
 
 
 
 
 
char uart_getc()
 
{
 
        unsigned char lsr;
 
        char c;
 
 
 
        WAIT_FOR_CHAR;
 
        c = REG8(UART_BASE + UART_RX);
 
        return c;
 
}
 
 
 
 
 
int main()
int main()
{
{
        uart_init();
        uart_init();
 
 
        /* We can't use printf because in this simple example
        /* We can't use printf because in this simple example
           we don't link C library. */
           we don't link C library. */
        uart_print_str("Hello World.\n\r");
        uart_print_str("Hello World.\n\r");
 
 
        report(0xdeaddead);
        report(0xdeaddead);
        exit(0);
        or32_exit(0);
}
}
 
 
 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.