luckfox-pico-sdk/sysdrv/source/mcu/rt-thread/libcpu/arm/s3c44b0/serial.c
luckfox-eng29 8f34c2760d project:build.sh: Added fastboot support; custom modifications to U-Boot and kernel implemented using patches.
project:cfg:BoardConfig_IPC: Added fastboot BoardConfig file and firmware post-scripts, distinguishing between
the BoardConfigs for Luckfox Pico Pro and Luckfox Pico Max. project:app: Added fastboot_client and rk_smart_door
for quick boot applications; updated rkipc app to adapt to the latest media library. media:samples: Added more
usage examples. media:rockit: Fixed bugs; removed support for retrieving data frames from VPSS. media:isp:
Updated rkaiq library and related tools to support connection to RKISP_Tuner. sysdrv:Makefile: Added support for
compiling drv_ko on Luckfox Pico Ultra W using Ubuntu; added support for custom root filesystem.
sysdrv:tools:board: Updated Buildroot optional mirror sources, updated some software versions, and stored device
tree files and configuration files that undergo multiple modifications for U-Boot and kernel separately.
sysdrv:source:mcu: Used RISC-V MCU SDK with RT-Thread system, mainly for initializing camera AE during quick
boot. sysdrv:source:uboot: Added support for fastboot; added high baud rate DDR bin for serial firmware upgrades.
sysdrv:source:kernel: Upgraded to version 5.10.160; increased NPU frequency for RV1106G3; added support for
fastboot.

Signed-off-by: luckfox-eng29 <eng29@luckfox.com>
2024-10-14 09:47:04 +08:00

115 lines
2.1 KiB
C

/*
* Copyright (c) 2006-2018, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* 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);
#define USTAT_RCV_READY 0x01 /* receive data ready */
#define USTAT_TXB_EMPTY 0x02 /* tx buffer empty */
rt_inline void serial_flush_input(void)
{
volatile unsigned int tmp;
/* keep on reading as long as the receiver is not empty */
while(UTRSTAT0 & USTAT_RCV_READY) tmp = URXH0;
}
rt_inline void serial_flush_output(void)
{
/* wait until the transmitter is no longer busy */
while(!(UTRSTAT0 & USTAT_TXB_EMPTY)) ;
}
/**
* @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)
{
while (*str)
{
rt_serial_putc (*str++);
}
}
/**
* This function initializes serial
*/
void rt_serial_init()
{
rt_uint32_t divisor = 0;
divisor = 0x20;
serial_flush_output();
serial_flush_input();
/* UART interrupt off */
UCON0 = 0;
/* FIFO disable */
UFCON0 =0x0;
UMCON0 =0x0;
/* set baudrate */
UBRDIV0 = divisor;
/* word length=8bit, stop bit = 1, no parity, use external clock */
ULCON0 = 0x03|0x00|0x00;
UCON0 = 0x5;
}
/**
* This function read a character from serial without interrupt enable mode
*
* @return the read char
*/
char rt_serial_getc()
{
while ((UTRSTAT0 & USTAT_RCV_READY) == 0);
return URXH0;
}
/**
* 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)
{
/*
to be polite with serial console add a line feed
to the carriage return character
*/
if (c=='\n')rt_serial_putc('\r');
/* wait for room in the transmit FIFO */
while(!(UTRSTAT0 & USTAT_TXB_EMPTY));
UTXH0 = (rt_uint8_t)c;
}
/*@}*/