2009-07-03 07:18:14 +08:00
|
|
|
/*
|
2021-03-27 17:51:56 +08:00
|
|
|
* Copyright (c) 2006-2021, RT-Thread Development Team
|
2009-07-03 07:18:14 +08:00
|
|
|
*
|
2018-10-15 01:35:07 +08:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2009-07-03 07:18:14 +08:00
|
|
|
*
|
|
|
|
* Change Logs:
|
|
|
|
* Date Author Notes
|
|
|
|
* 2006-09-06 XuXinming first version
|
|
|
|
* 2006-09-20 Bernard clean code according code style
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <rtthread.h>
|
|
|
|
#include <rthw.h>
|
|
|
|
|
|
|
|
#include "s3c44b0.h"
|
|
|
|
|
|
|
|
void rt_serial_init(void);
|
|
|
|
void rt_console_puts(const char* str);
|
|
|
|
void rt_serial_putc(const char c);
|
|
|
|
|
2021-03-27 17:51:56 +08:00
|
|
|
#define USTAT_RCV_READY 0x01 /* receive data ready */
|
|
|
|
#define USTAT_TXB_EMPTY 0x02 /* tx buffer empty */
|
2009-07-03 07:18:14 +08:00
|
|
|
|
|
|
|
rt_inline void serial_flush_input(void)
|
|
|
|
{
|
2021-03-27 17:51:56 +08:00
|
|
|
volatile unsigned int tmp;
|
2009-07-03 07:18:14 +08:00
|
|
|
|
2021-03-27 17:51:56 +08:00
|
|
|
/* keep on reading as long as the receiver is not empty */
|
|
|
|
while(UTRSTAT0 & USTAT_RCV_READY) tmp = URXH0;
|
2009-07-03 07:18:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
rt_inline void serial_flush_output(void)
|
|
|
|
{
|
2021-03-27 17:51:56 +08:00
|
|
|
/* wait until the transmitter is no longer busy */
|
|
|
|
while(!(UTRSTAT0 & USTAT_TXB_EMPTY)) ;
|
2009-07-03 07:18:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @addtogroup S3C44B0
|
|
|
|
*/
|
|
|
|
/*@{*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This function is used to display a string on console, normally, it's
|
|
|
|
* invoked by rt_kprintf
|
|
|
|
*
|
|
|
|
* @param str the displayed string
|
|
|
|
*/
|
|
|
|
void rt_console_puts(const char* str)
|
|
|
|
{
|
2021-03-27 17:51:56 +08:00
|
|
|
while (*str)
|
|
|
|
{
|
|
|
|
rt_serial_putc (*str++);
|
|
|
|
}
|
2009-07-03 07:18:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This function initializes serial
|
|
|
|
*/
|
|
|
|
void rt_serial_init()
|
|
|
|
{
|
2021-03-27 17:51:56 +08:00
|
|
|
rt_uint32_t divisor = 0;
|
2009-07-03 07:18:14 +08:00
|
|
|
|
2021-03-27 17:51:56 +08:00
|
|
|
divisor = 0x20;
|
2009-07-03 07:18:14 +08:00
|
|
|
|
2021-03-27 17:51:56 +08:00
|
|
|
serial_flush_output();
|
|
|
|
serial_flush_input();
|
2009-07-03 07:18:14 +08:00
|
|
|
|
2021-03-27 17:51:56 +08:00
|
|
|
/* UART interrupt off */
|
|
|
|
UCON0 = 0;
|
|
|
|
/* FIFO disable */
|
|
|
|
UFCON0 =0x0;
|
|
|
|
UMCON0 =0x0;
|
|
|
|
/* set baudrate */
|
|
|
|
UBRDIV0 = divisor;
|
2009-07-03 07:18:14 +08:00
|
|
|
|
2021-03-27 17:51:56 +08:00
|
|
|
/* word length=8bit, stop bit = 1, no parity, use external clock */
|
2023-04-29 05:58:59 +08:00
|
|
|
ULCON0 = 0x03;
|
2009-07-03 07:18:14 +08:00
|
|
|
|
2021-03-27 17:51:56 +08:00
|
|
|
UCON0 = 0x5;
|
2009-07-03 07:18:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This function read a character from serial without interrupt enable mode
|
|
|
|
*
|
|
|
|
* @return the read char
|
|
|
|
*/
|
|
|
|
char rt_serial_getc()
|
|
|
|
{
|
2021-03-27 17:51:56 +08:00
|
|
|
while ((UTRSTAT0 & USTAT_RCV_READY) == 0);
|
2009-07-03 07:18:14 +08:00
|
|
|
|
2021-03-27 17:51:56 +08:00
|
|
|
return URXH0;
|
2009-07-03 07:18:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This function will write a character to serial without interrupt enable mode
|
|
|
|
*
|
|
|
|
* @param c the char to write
|
|
|
|
*/
|
|
|
|
void rt_serial_putc(const char c)
|
|
|
|
{
|
2021-03-27 17:51:56 +08:00
|
|
|
/*
|
|
|
|
to be polite with serial console add a line feed
|
|
|
|
to the carriage return character
|
|
|
|
*/
|
|
|
|
if (c=='\n')rt_serial_putc('\r');
|
2009-07-03 07:18:14 +08:00
|
|
|
|
2021-03-27 17:51:56 +08:00
|
|
|
/* wait for room in the transmit FIFO */
|
|
|
|
while(!(UTRSTAT0 & USTAT_TXB_EMPTY));
|
2009-07-03 07:18:14 +08:00
|
|
|
|
2021-03-27 17:51:56 +08:00
|
|
|
UTXH0 = (rt_uint8_t)c;
|
2009-07-03 07:18:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*@}*/
|