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

Subversion Repositories zap

[/] [zap/] [trunk/] [src/] [ts/] [uart/] [uart.c] - Blame information for rev 43

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 43 Revanth
#include "uart.h"
2
 
3
/* Sets up rate as 1 baud = 16 CPU clocks. Also resets TX and RX logic */
4
void UARTInit()
5
{
6
        // Set up frequency of operation. 1 bit time = 16 CPU clocks.
7
        *UART0_LCR        = (*UART0_LCR) | (1 << 7);
8
        *UART0_DLAB1      = 1;
9
        *UART0_DLAB2      = 0;
10
        *UART0_LCR        = (*UART0_LCR) & ~(1 << 7);
11
 
12
        // Enable TX and RX.
13
        UARTEnableTX();
14
        UARTEnableRX();
15
}
16
 
17
/* Write a string to the UART device. This is an open loop function. */
18
void UARTWrite(char* s)
19
{
20
        int len;
21
        int i;
22
 
23
        len = strlen(s);
24
 
25
        for(i=0;i<len;i++)        {
26
                UARTWriteByte(s[i]);
27
        }
28
}
29
 
30
/* Write a byte to the UART. This is an open loop function. */
31
void UARTWriteByte(char c)
32
{
33
        *UART0_THR = c;
34
}
35
 
36
/* Length of a string */
37
int strlen(char* s)
38
{
39
        int i;
40
        i = 0;
41
 
42
        while(s[i] != '\0')
43
                i++;
44
 
45
        return i;
46
}
47
 
48
/* UART Enable RX interrupt */
49
void UARTEnableRXInterrupt (void) {
50
        *UART0_IER = *UART0_IER | 1;
51
}
52
 
53
/* Enable TX */
54
void UARTEnableTX (void) {
55
        *UART0_FCR = *UART0_FCR | 4;
56
}
57
 
58
/* Enablt RX */
59
void UARTEnableRX (void) {
60
        *UART0_FCR = *UART0_FCR | 1;
61
}
62
 
63
/* Check if transmit is empty */
64
int UARTTransmitEmpty (void) {
65
        char x = *UART0_LSR;
66
 
67
        if ( x & (1 << 6) )
68
                return 1;
69
        else
70
                return 0;
71
}
72
 
73
/* Get a character from uart */
74
char UARTGetChar (void) {
75
        return *UART0_RBR;
76
}

powered by: WebSVN 2.1.0

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