Obsolete unused backup project such as OK6410
guowenxue
2018-02-04 00cb813bffdc9876ae03ff0b967be3b1912f2454
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/********************************************************************************************
 *        File:  serial.c
 *     Version:  1.0.0
 *   Copyright:  2013 (c) Guo Wenxue <guowenxue@gmail.com>
 * Description:  The UART on board drivers/functions.
 *   ChangeLog:  1, Release initial version on "Mon Feb 25 22:58:49 CST 2013"
 *
 *******************************************************************************************/
 
#include "s3c6410.h"
 
/*
 * Initialise the serial port with the given baudrate. The settings
 * are always 8 data bits, no parity, 1 stop bit, no start bits.
 */
int serial_init(int baudrate)
{
    unsigned int     regv;
 
    s3c64xx_uart *const uart = s3c64xx_get_base_uart(S3C64XX_UART0);
 
    /* UART I/O port initialize: GPA0->RXD0, GPA1->TXD0) */
    regv = s3c_readl(GPACON);
    regv = (regv & ~(0xff<<0)) | (0x22<<0);    
    s3c_writel(regv, GPACON);
 
    /* RXD0: Pull-down, TXD0: pull up/down disable */
    regv = s3c_readl(GPAPUD);
    regv = (regv & ~(0xf<<0)) | (0x1<<0);    
    s3c_writel(regv, GPAPUD);
 
    /* Normal Mode, No Parity, 1 Stop Bit, 8 Bit Data */
    uart->ULCON = 3;
 
    /* PCLK divide, Polling Mode */
    uart->UCON = (0x2<<10) | (1<<9) | (1<<8) | (1<<2) | (1<<0);
    uart->UFCON = 0;  /* Disable FIFO */
    uart->UMCON = 0;  /* Disable Auto Flow Control */
 
    /* Baudrate, DIV=PCLK/(bps*16)-1=66000000/(115200*16)-1 = 34; */
    s3c_writel(34, UBRDIV0);
 
    for (regv=0; regv<0x100; regv++)  ;
 
    uart->UDIVSLOT = 0x80;
 
    return 0;
}
 
/*
 * Read a single byte from the serial port. Returns 1 on success, 0
 * otherwise. When the function is succesfull, the character read is
 * written into its argument c.
 */
int serial_getc(void)
{
    s3c64xx_uart *const uart = s3c64xx_get_base_uart(S3C64XX_UART0);
 
    /* wait for character to arrive */
    while (!(uart->UTRSTAT & 0x1)) ; 
 
    return uart->URXH & 0xff;
}
 
/*
 * Output a single byte to the serial port.
 */
void serial_putc(const char c)
{
    s3c64xx_uart *const uart = s3c64xx_get_base_uart(S3C64XX_UART0);
 
    /*  wait for room in the tx FIFO */
    while (!(uart->UTRSTAT & 0x2));
            
    uart->UTXH = c;
    if (c == '\n') serial_putc('\r');   /*  If \n, also do \r */
}
 
/*
 * Test whether a character is in the RX buffer
 */
int serial_tstc(void)
{
    s3c64xx_uart *const uart = s3c64xx_get_base_uart(S3C64XX_UART0); 
    return uart->UTRSTAT & 0x1;
}
 
 
void serial_puts(const char *s)
{
    while (*s)
        serial_putc(*s++);
}