mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-10-13 06:55:31 +08:00
[bsp/ls1cdev]
1、uart驱动重写,采用uart驱动框架 2、添加并修改勤为本ls1c_uart 3、开启main为用户程序入口,删除application.c和startup.c,并对初始化部分做相应调整更新。 4、开启dhcp
This commit is contained in:
+40
-2
@@ -57,7 +57,8 @@ CONFIG_RT_CONSOLE_DEVICE_NAME="uart2"
|
||||
# RT-Thread Components
|
||||
#
|
||||
CONFIG_RT_USING_COMPONENTS_INIT=y
|
||||
# CONFIG_RT_USING_USER_MAIN is not set
|
||||
CONFIG_RT_USING_USER_MAIN=y
|
||||
CONFIG_RT_MAIN_THREAD_STACK_SIZE=2048
|
||||
|
||||
#
|
||||
# C++ features
|
||||
@@ -73,6 +74,7 @@ CONFIG_FINSH_USING_HISTORY=y
|
||||
CONFIG_FINSH_HISTORY_LINES=5
|
||||
CONFIG_FINSH_USING_SYMTAB=y
|
||||
CONFIG_FINSH_USING_DESCRIPTION=y
|
||||
# CONFIG_FINSH_ECHO_DISABLE_DEFAULT is not set
|
||||
CONFIG_FINSH_THREAD_PRIORITY=20
|
||||
CONFIG_FINSH_THREAD_STACK_SIZE=4096
|
||||
CONFIG_FINSH_CMD_SIZE=80
|
||||
@@ -168,7 +170,9 @@ CONFIG_RT_LWIP_IGMP=y
|
||||
CONFIG_RT_LWIP_ICMP=y
|
||||
# CONFIG_RT_LWIP_SNMP is not set
|
||||
CONFIG_RT_LWIP_DNS=y
|
||||
# CONFIG_RT_LWIP_DHCP is not set
|
||||
CONFIG_RT_LWIP_DHCP=y
|
||||
CONFIG_IP_SOF_BROADCAST=1
|
||||
CONFIG_IP_SOF_BROADCAST_RECV=1
|
||||
|
||||
#
|
||||
# Static IPv4 Address
|
||||
@@ -227,6 +231,13 @@ CONFIG_LWIP_NETIF_LOOPBACK=0
|
||||
#
|
||||
# system packages
|
||||
#
|
||||
|
||||
#
|
||||
# RT-Thread GUI Engine
|
||||
#
|
||||
# CONFIG_PKG_USING_GUIENGINE is not set
|
||||
# CONFIG_PKG_USING_LVGL is not set
|
||||
# CONFIG_PKG_USING_LWEXT4 is not set
|
||||
# CONFIG_PKG_USING_PARTITION is not set
|
||||
# CONFIG_PKG_USING_SQLITE is not set
|
||||
# CONFIG_PKG_USING_RTI is not set
|
||||
@@ -239,14 +250,34 @@ CONFIG_LWIP_NETIF_LOOPBACK=0
|
||||
# CONFIG_PKG_USING_MONGOOSE is not set
|
||||
# CONFIG_PKG_USING_WEBTERMINAL is not set
|
||||
# CONFIG_PKG_USING_CJSON is not set
|
||||
# CONFIG_PKG_USING_LJSON is not set
|
||||
# CONFIG_PKG_USING_EZXML is not set
|
||||
# CONFIG_PKG_USING_NANOPB is not set
|
||||
# CONFIG_PKG_USING_GAGENT_CLOUD is not set
|
||||
|
||||
#
|
||||
# Wi-Fi
|
||||
#
|
||||
|
||||
#
|
||||
# Marvell WiFi
|
||||
#
|
||||
# CONFIG_PKG_USING_WLANMARVELL is not set
|
||||
|
||||
#
|
||||
# Wiced WiFi
|
||||
#
|
||||
# CONFIG_PKG_USING_WLAN_WICED is not set
|
||||
# CONFIG_PKG_USING_COAP is not set
|
||||
# CONFIG_PKG_USING_NOPOLL is not set
|
||||
# CONFIG_PKG_USING_NETUTILS is not set
|
||||
|
||||
#
|
||||
# security packages
|
||||
#
|
||||
# CONFIG_PKG_USING_MBEDTLS is not set
|
||||
# CONFIG_PKG_USING_libsodium is not set
|
||||
# CONFIG_PKG_USING_TINYCRYPT is not set
|
||||
|
||||
#
|
||||
# language packages
|
||||
@@ -257,19 +288,26 @@ CONFIG_LWIP_NETIF_LOOPBACK=0
|
||||
#
|
||||
# multimedia packages
|
||||
#
|
||||
# CONFIG_PKG_USING_OPENMV is not set
|
||||
|
||||
#
|
||||
# tools packages
|
||||
#
|
||||
# CONFIG_PKG_USING_CMBACKTRACE is not set
|
||||
# CONFIG_PKG_USING_EASYFLASH is not set
|
||||
# CONFIG_PKG_USING_EASYLOGGER is not set
|
||||
# CONFIG_PKG_USING_SYSTEMVIEW is not set
|
||||
# CONFIG_PKG_USING_IPERF is not set
|
||||
|
||||
#
|
||||
# miscellaneous packages
|
||||
#
|
||||
# CONFIG_PKG_USING_FASTLZ is not set
|
||||
# CONFIG_PKG_USING_MINILZO is not set
|
||||
# CONFIG_PKG_USING_QUICKLZ is not set
|
||||
# CONFIG_PKG_USING_MULTIBUTTON is not set
|
||||
# CONFIG_PKG_USING_SAMPLES is not set
|
||||
# CONFIG_PKG_USING_CANFESTIVAL is not set
|
||||
|
||||
#
|
||||
# example package: hello
|
||||
|
||||
@@ -1,61 +0,0 @@
|
||||
/*
|
||||
* File : application.c
|
||||
* This file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2006-2012, RT-Thread Develop Team
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rt-thread.org/license/LICENSE
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2010-06-25 Bernard first version
|
||||
* 2011-08-08 lgnq modified for Loongson LS1B
|
||||
* 2015-07-06 chinesebear modified for Loongson LS1C
|
||||
* 2018-02-08 sundm75 modified for Loongson LS1C SmartLoongV3
|
||||
*/
|
||||
|
||||
#include <rtthread.h>
|
||||
#include "net/synopGMAC.h"
|
||||
#include <lwip/api.h>
|
||||
|
||||
void rt_init_thread_entry(void *parameter)
|
||||
{
|
||||
#ifdef RT_USING_COMPONENTS_INIT
|
||||
/* initialization RT-Thread Components */
|
||||
rt_components_init();
|
||||
#endif
|
||||
#if defined(RT_USING_DFS) && defined(RT_USING_DFS_ELMFAT)
|
||||
/* mount sd card fat partition 1 as root directory */
|
||||
if( dfs_mount("sd0", "/", "elm", 0, 0) == 0)
|
||||
{
|
||||
rt_kprintf("File System initialized!\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_kprintf("File System initialzation failed!\n");
|
||||
}
|
||||
#endif /* RT_USING_DFS && RT_USING_DFS_ELMFAT */
|
||||
|
||||
/*网口EMAC初始化*/
|
||||
rt_hw_eth_init();
|
||||
#if defined(RT_USING_RTGUI)
|
||||
/*触摸屏使用SPI总线SPI1 CS0 初始化*/
|
||||
rtgui_touch_hw_init("spi10");
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
int rt_application_init(void)
|
||||
{
|
||||
rt_thread_t tid;
|
||||
|
||||
/* create initialization thread */
|
||||
tid = rt_thread_create("init",
|
||||
rt_init_thread_entry, RT_NULL,
|
||||
4096, RT_THREAD_PRIORITY_MAX/3, 20);
|
||||
if (tid != RT_NULL)
|
||||
rt_thread_startup(tid);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* File : main.c
|
||||
* This file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2008 - 2017, RT-Thread Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2018-05-10 zhuangwei first version
|
||||
*/
|
||||
|
||||
#include <rtthread.h>
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@@ -1,93 +0,0 @@
|
||||
/*
|
||||
* File : startup.c
|
||||
* This file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2006-2012, RT-Thread Develop Team
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rt-thread.org/license/LICENSE
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2010-06-25 Bernard first version
|
||||
* 2011-08-08 lgnq modified for Loongson LS1B
|
||||
* 2015-07-06 chinesebear modified for Loongson LS1C
|
||||
*/
|
||||
|
||||
#include <rthw.h>
|
||||
#include <rtthread.h>
|
||||
|
||||
#include "board.h"
|
||||
#define A_K0BASE 0x80000000
|
||||
|
||||
/**
|
||||
* @addtogroup Loongson LS1B
|
||||
*/
|
||||
|
||||
/*@{*/
|
||||
|
||||
extern unsigned char __bss_end;
|
||||
|
||||
extern int rt_application_init(void);
|
||||
|
||||
extern void tlb_refill_exception(void);
|
||||
extern void general_exception(void);
|
||||
extern void irq_exception(void);
|
||||
extern void rt_hw_cache_init(void);
|
||||
extern void invalidate_writeback_dcache_all(void);
|
||||
extern void invalidate_icache_all(void);
|
||||
|
||||
/**
|
||||
* This function will startup RT-Thread RTOS.
|
||||
*/
|
||||
void rtthread_startup(void)
|
||||
{
|
||||
/* disable interrupt first */
|
||||
rt_hw_interrupt_disable();
|
||||
|
||||
/* init cache */
|
||||
rt_hw_cache_init();
|
||||
/* init hardware interrupt */
|
||||
rt_hw_interrupt_init();
|
||||
|
||||
/* copy vector */
|
||||
rt_memcpy((void *)A_K0BASE, tlb_refill_exception, 0x80);
|
||||
rt_memcpy((void *)(A_K0BASE + 0x180), general_exception, 0x80);
|
||||
rt_memcpy((void *)(A_K0BASE + 0x200), irq_exception, 0x80);
|
||||
|
||||
invalidate_writeback_dcache_all();
|
||||
invalidate_icache_all();
|
||||
|
||||
/* init board */
|
||||
rt_hw_board_init();
|
||||
|
||||
/* show version */
|
||||
rt_show_version();
|
||||
|
||||
#ifdef RT_USING_HEAP
|
||||
rt_system_heap_init((void*)&__bss_end, (void*)RT_HW_HEAP_END);
|
||||
#endif
|
||||
|
||||
/* init scheduler system */
|
||||
rt_system_scheduler_init();
|
||||
|
||||
/* initialize timer */
|
||||
rt_system_timer_init();
|
||||
|
||||
/* initialize timer thread */
|
||||
rt_system_timer_thread_init();
|
||||
|
||||
/* init idle thread */
|
||||
rt_thread_idle_init();
|
||||
|
||||
/* init application */
|
||||
rt_application_init();
|
||||
|
||||
/* start scheduler */
|
||||
rt_system_scheduler_start();
|
||||
|
||||
/* never reach here */
|
||||
return;
|
||||
}
|
||||
|
||||
/*@}*/
|
||||
+32
-38
@@ -18,9 +18,22 @@
|
||||
#include <rthw.h>
|
||||
|
||||
#include "board.h"
|
||||
#include "uart.h"
|
||||
#include "drv_uart.h"
|
||||
#include "ls1c.h"
|
||||
|
||||
#define A_K0BASE 0x80000000
|
||||
|
||||
extern unsigned char __bss_end;
|
||||
|
||||
|
||||
extern void tlb_refill_exception(void);
|
||||
extern void general_exception(void);
|
||||
extern void irq_exception(void);
|
||||
extern void rt_hw_cache_init(void);
|
||||
extern void invalidate_writeback_dcache_all(void);
|
||||
extern void invalidate_icache_all(void);
|
||||
|
||||
|
||||
/**
|
||||
* @addtogroup Loongson LS1B
|
||||
*/
|
||||
@@ -81,6 +94,24 @@ void rt_hw_fpu_init(void)
|
||||
*/
|
||||
void rt_hw_board_init(void)
|
||||
{
|
||||
/* init cache */
|
||||
rt_hw_cache_init();
|
||||
|
||||
/* init hardware interrupt */
|
||||
rt_hw_interrupt_init();
|
||||
|
||||
/* copy vector */
|
||||
rt_memcpy((void *)A_K0BASE, tlb_refill_exception, 0x80);
|
||||
rt_memcpy((void *)(A_K0BASE + 0x180), general_exception, 0x80);
|
||||
rt_memcpy((void *)(A_K0BASE + 0x200), irq_exception, 0x80);
|
||||
|
||||
invalidate_writeback_dcache_all();
|
||||
invalidate_icache_all();
|
||||
|
||||
#ifdef RT_USING_HEAP
|
||||
rt_system_heap_init((void*)&__bss_end, (void*)RT_HW_HEAP_END);
|
||||
#endif
|
||||
|
||||
#ifdef RT_USING_SERIAL
|
||||
/* init hardware UART device */
|
||||
rt_hw_uart_init();
|
||||
@@ -105,41 +136,4 @@ void rt_hw_board_init(void)
|
||||
rt_kprintf("current sr: 0x%08x\n", read_c0_status());
|
||||
}
|
||||
|
||||
#define __raw_out_put(unr) \
|
||||
while (*ptr) \
|
||||
{ \
|
||||
if (*ptr == '\n') \
|
||||
{ \
|
||||
/* FIFO status, contain valid data */ \
|
||||
while (!(UART_LSR(UART##unr##_BASE) & (UARTLSR_TE | UARTLSR_TFE))); \
|
||||
/* write data */ \
|
||||
UART_DAT(UART##unr##_BASE) = '\r'; \
|
||||
} \
|
||||
/* FIFO status, contain valid data */ \
|
||||
while (!(UART_LSR(UART##unr##_BASE) & (UARTLSR_TE | UARTLSR_TFE))); \
|
||||
/* write data */ \
|
||||
UART_DAT(UART##unr##_BASE) = *ptr; \
|
||||
ptr ++; \
|
||||
}
|
||||
|
||||
/* UART line status register value */
|
||||
#define UARTLSR_ERROR (1 << 7)
|
||||
#define UARTLSR_TE (1 << 6)
|
||||
#define UARTLSR_TFE (1 << 5)
|
||||
#define UARTLSR_BI (1 << 4)
|
||||
#define UARTLSR_FE (1 << 3)
|
||||
#define UARTLSR_PE (1 << 2)
|
||||
#define UARTLSR_OE (1 << 1)
|
||||
#define UARTLSR_DR (1 << 0)
|
||||
void rt_hw_console_output(const char *ptr)
|
||||
{
|
||||
#if defined(RT_USING_UART0)
|
||||
__raw_out_put(0);
|
||||
#elif defined(RT_USING_UART2)
|
||||
__raw_out_put(2);
|
||||
#elif defined(RT_USING_UART3)
|
||||
__raw_out_put(3);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*@}*/
|
||||
|
||||
@@ -0,0 +1,177 @@
|
||||
/*
|
||||
* File : drv_uart.c
|
||||
* This file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2008 - 2016, RT-Thread Development Team
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2018-05-08 zhuangwei the first version
|
||||
*/
|
||||
#include <rtthread.h>
|
||||
#include <rtdevice.h>
|
||||
#include <rthw.h>
|
||||
#include "drv_uart.h"
|
||||
#include "ls1c_pin.h"
|
||||
#include "ls1c_uart.h"
|
||||
|
||||
/* STM32 uart driver */
|
||||
struct rt_uart_ls1c
|
||||
{
|
||||
ls1c_uart_t UARTx;
|
||||
rt_uint32_t IRQ;
|
||||
};
|
||||
|
||||
static rt_err_t ls1c_uart_configure(struct rt_serial_device *serial, struct serial_configure *cfg)
|
||||
{
|
||||
struct rt_uart_ls1c *uart_dev = RT_NULL;
|
||||
ls1c_uart_info_t uart_info = {0};
|
||||
|
||||
RT_ASSERT(serial != RT_NULL);
|
||||
RT_ASSERT(cfg != RT_NULL);
|
||||
|
||||
uart_dev = (struct rt_uart_ls1c *)serial->parent.user_data;
|
||||
|
||||
// 初始化串口
|
||||
uart_info.UARTx = uart_dev->UARTx;
|
||||
uart_info.baudrate = cfg->baud_rate;
|
||||
uart_info.rx_enable= TRUE;
|
||||
uart_init(&uart_info);
|
||||
|
||||
return RT_EOK;
|
||||
|
||||
}
|
||||
|
||||
static rt_err_t ls1c_uart_control(struct rt_serial_device *serial, int cmd, void *arg)
|
||||
{
|
||||
struct rt_uart_ls1c *uart_dev = RT_NULL;
|
||||
|
||||
RT_ASSERT(serial != RT_NULL);
|
||||
uart_dev = (struct rt_uart_ls1c *)serial->parent.user_data;
|
||||
|
||||
switch (cmd)
|
||||
{
|
||||
case RT_DEVICE_CTRL_CLR_INT: /* disable rx irq */
|
||||
rt_hw_interrupt_mask(uart_dev->IRQ);
|
||||
break;
|
||||
|
||||
case RT_DEVICE_CTRL_SET_INT: /* enable rx irq */
|
||||
rt_hw_interrupt_umask(uart_dev->IRQ);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return RT_EOK;
|
||||
|
||||
}
|
||||
|
||||
static int ls1c_uart_putc(struct rt_serial_device *serial, char c)
|
||||
{
|
||||
struct rt_uart_ls1c *uart_dev = RT_NULL;
|
||||
|
||||
RT_ASSERT(serial != RT_NULL);
|
||||
|
||||
uart_dev = (struct rt_uart_ls1c *)serial->parent.user_data;
|
||||
uart_putc(uart_dev->UARTx, c);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int ls1c_uart_getc(struct rt_serial_device *serial)
|
||||
{
|
||||
struct rt_uart_ls1c *uart_dev = RT_NULL;
|
||||
|
||||
RT_ASSERT(serial != RT_NULL);
|
||||
|
||||
uart_dev = (struct rt_uart_ls1c *)serial->parent.user_data;
|
||||
void *uart_base = uart_get_base(uart_dev->UARTx);
|
||||
|
||||
if(LSR_RXRDY & reg_read_8(uart_base + LS1C_UART_LSR_OFFSET))
|
||||
{
|
||||
return reg_read_8(uart_base + LS1C_UART_DAT_OFFSET);
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* UART interrupt handler */
|
||||
static void uart_irq_handler(int vector, void *param)
|
||||
{
|
||||
struct rt_serial_device *serial = (struct rt_serial_device*)param;
|
||||
struct rt_uart_ls1c *uart_dev = RT_NULL;
|
||||
|
||||
RT_ASSERT(serial != RT_NULL);
|
||||
|
||||
uart_dev = (struct rt_uart_ls1c *)serial->parent.user_data;
|
||||
void *uart_base = uart_get_base(uart_dev->UARTx);
|
||||
unsigned char iir = reg_read_8(uart_base + LS1C_UART_IIR_OFFSET);
|
||||
|
||||
// 判断是否为接收超时或接收到有效数据
|
||||
if ((IIR_RXTOUT & iir) || (IIR_RXRDY & iir))
|
||||
{
|
||||
rt_interrupt_enter();
|
||||
rt_hw_serial_isr(serial, RT_SERIAL_EVENT_RX_IND);
|
||||
rt_interrupt_leave();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static const struct rt_uart_ops stm32_uart_ops =
|
||||
{
|
||||
ls1c_uart_configure,
|
||||
ls1c_uart_control,
|
||||
ls1c_uart_putc,
|
||||
ls1c_uart_getc,
|
||||
};
|
||||
|
||||
#if defined(RT_USING_UART2)
|
||||
struct rt_uart_ls1c uart2 =
|
||||
{
|
||||
LS1C_UART2,
|
||||
LS1C_UART2_IRQ,
|
||||
};
|
||||
struct rt_serial_device serial2;
|
||||
#endif /* RT_USING_UART1 */
|
||||
|
||||
void rt_hw_uart_init(void)
|
||||
{
|
||||
struct rt_uart_ls1c *uart;
|
||||
struct serial_configure config = RT_SERIAL_CONFIG_DEFAULT;
|
||||
|
||||
#ifdef RT_USING_UART2
|
||||
uart = &uart2;
|
||||
|
||||
serial2.ops = &stm32_uart_ops;
|
||||
serial2.config = config;
|
||||
|
||||
pin_set_purpose(36, PIN_PURPOSE_OTHER);
|
||||
pin_set_purpose(37, PIN_PURPOSE_OTHER);
|
||||
pin_set_remap(36, PIN_REMAP_SECOND);
|
||||
pin_set_remap(37, PIN_REMAP_SECOND);
|
||||
|
||||
rt_hw_interrupt_install(uart->IRQ, uart_irq_handler, &serial2, "UART2");
|
||||
|
||||
/* register UART1 device */
|
||||
rt_hw_serial_register(&serial2,
|
||||
"uart2",
|
||||
//RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX | RT_DEVICE_FLAG_DMA_RX,
|
||||
RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX,
|
||||
uart);
|
||||
#endif /* RT_USING_UART1 */
|
||||
}
|
||||
|
||||
@@ -1,20 +1,19 @@
|
||||
/*
|
||||
* File : uart.h
|
||||
* File : drv_uart.h
|
||||
* This file is part of RT-Thread RTOS
|
||||
* COPYRIGHT (C) 2006-2012, RT-Thread Develop Team
|
||||
* COPYRIGHT (C) 2009, RT-Thread Development Team
|
||||
*
|
||||
* The license and distribution terms for this file may be
|
||||
* found in the file LICENSE in this distribution or at
|
||||
* http://www.rt-thread.org/license/LICENSE
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2011-08-08 lgnq first version for LS1B
|
||||
* 2015-07-06 chinesebear modified for loongson 1c
|
||||
* Date Author Notes
|
||||
* 2018-05-08 zhuangwei the first version
|
||||
*/
|
||||
|
||||
#ifndef __UART_H__
|
||||
#define __UART_H__
|
||||
#ifndef __DRV_UART_H__
|
||||
#define __DRV_UART_H__
|
||||
|
||||
#include "ls1c.h"
|
||||
|
||||
@@ -100,4 +99,5 @@
|
||||
|
||||
void rt_hw_uart_init(void);
|
||||
|
||||
|
||||
#endif
|
||||
@@ -860,7 +860,7 @@ void eth_rx_irq(int irqno,void *param)
|
||||
return;
|
||||
}
|
||||
|
||||
void rt_hw_eth_init(void)
|
||||
int rt_hw_eth_init(void)
|
||||
{
|
||||
u64 base_addr = Gmac_base;
|
||||
struct synopGMACNetworkAdapter * synopGMACadapter;
|
||||
@@ -925,4 +925,9 @@ void rt_hw_eth_init(void)
|
||||
eth_dev.parent.eth_rx = rt_eth_rx;
|
||||
|
||||
eth_device_init(&(eth_dev.parent), "e0");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
INIT_DEVICE_EXPORT(rt_hw_eth_init);
|
||||
|
||||
|
||||
@@ -32,6 +32,6 @@
|
||||
#include "mii.h"
|
||||
#include "synopGMAC_types.h"
|
||||
|
||||
void rt_hw_eth_init(void);
|
||||
int rt_hw_eth_init(void);
|
||||
|
||||
#endif /*__SYNOPGMAC__H*/
|
||||
|
||||
@@ -117,8 +117,8 @@ typedef int bool;
|
||||
*/
|
||||
|
||||
//sw: nothing to display
|
||||
#define TR0(fmt, args...) rt_kprintf(fmt, ##args)
|
||||
#define TR(fmt, args...) rt_kprintf(fmt, ##args)
|
||||
#define TR0(fmt, args...) //rt_kprintf(fmt, ##args)
|
||||
#define TR(fmt, args...) //rt_kprintf(fmt, ##args)
|
||||
//#define TR rt_kprintf
|
||||
|
||||
//typedef int bool;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
+2
-2
@@ -16,8 +16,8 @@ config $PKGS_DIR
|
||||
option env="PKGS_ROOT"
|
||||
default "packages"
|
||||
|
||||
source "$RTT_DIR/KConfig"
|
||||
source "$PKGS_DIR/KConfig"
|
||||
source "$RTT_DIR/Kconfig"
|
||||
source "$PKGS_DIR/Kconfig"
|
||||
|
||||
if RT_USING_SERIAL
|
||||
config RT_USING_UART2
|
||||
|
||||
@@ -125,9 +125,20 @@
|
||||
|
||||
|
||||
// 串口寄存器
|
||||
#define LS1C_UART0_BASE (0xbfe40000)
|
||||
#define LS1C_UART00_BASE (0xbfe40000)
|
||||
#define LS1C_UART01_BASE (0xbfe41000)
|
||||
#define LS1C_UART1_BASE (0xbfe44000)
|
||||
#define LS1C_UART2_BASE (0xbfe48000)
|
||||
#define LS1C_UART3_BASE (0xbfe4c000)
|
||||
#define LS1C_UART4_BASE (0xbfe4c400)
|
||||
#define LS1C_UART5_BASE (0xbfe4c500)
|
||||
#define LS1C_UART6_BASE (0xbfe4c600)
|
||||
#define LS1C_UART7_BASE (0xbfe4c700)
|
||||
#define LS1C_UART8_BASE (0xbfe4c800)
|
||||
#define LS1C_UART9_BASE (0xbfe4c900)
|
||||
#define LS1C_UART10_BASE (0xbfe4ca00)
|
||||
#define LS1C_UART11_BASE (0xbfe4cb00)
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,180 @@
|
||||
// 串口相关头文件
|
||||
|
||||
|
||||
#ifndef __OPENLOONGSON_UART_H
|
||||
#define __OPENLOONGSON_UART_H
|
||||
|
||||
|
||||
#include "ls1c_public.h"
|
||||
|
||||
|
||||
// 串口各寄存器相对基地址的偏移
|
||||
#define LS1C_UART_DAT_OFFSET (0)
|
||||
#define LS1C_UART_IER_OFFSET (1)
|
||||
#define LS1C_UART_IIR_OFFSET (2)
|
||||
#define LS1C_UART_FCR_OFFSET (2)
|
||||
#define LS1C_UART_LCR_OFFSET (3)
|
||||
#define LS1C_UART_MCR_OFFSET (4)
|
||||
#define LS1C_UART_LSR_OFFSET (5)
|
||||
#define LS1C_UART_MSR_OFFSET (6)
|
||||
|
||||
#define LS1C_UART_LSB_OFFSET (0) // 分频锁存器1
|
||||
#define LS1C_UART_MSB_OFFSET (1) // 分频锁存器2
|
||||
|
||||
/* interrupt enable register */
|
||||
#define IER_IRxE 0x1 /* 接收有效数据中断使能 */
|
||||
#define IER_ITxE 0x2 /* 传输保存寄存器为空中断使能 */
|
||||
#define IER_ILE 0x4 /* 接收器线路状态中断使能 */
|
||||
#define IER_IME 0x8 /* Modem状态中断使能 */
|
||||
|
||||
/* interrupt identification register */
|
||||
#define IIR_IMASK 0xf /* mask */
|
||||
#define IIR_RXTOUT 0xc /* receive timeout */
|
||||
#define IIR_RLS 0x6 /* receive line status */
|
||||
#define IIR_RXRDY 0x4 /* receive ready */
|
||||
#define IIR_TXRDY 0x2 /* transmit ready */
|
||||
#define IIR_NOPEND 0x1 /* nothing */
|
||||
#define IIR_MLSC 0x0 /* modem status */
|
||||
#define IIR_FIFO_MASK 0xc0 /* set if FIFOs are enabled */
|
||||
|
||||
/* fifo control register */
|
||||
#define FIFO_ENABLE 0x01 /* enable fifo */
|
||||
#define FIFO_RCV_RST 0x02 /* reset receive fifo */
|
||||
#define FIFO_XMT_RST 0x04 /* reset transmit fifo */
|
||||
#define FIFO_DMA_MODE 0x08 /* enable dma mode */
|
||||
#define FIFO_TRIGGER_1 0x00 /* trigger at 1 char */
|
||||
#define FIFO_TRIGGER_4 0x40 /* trigger at 4 chars */
|
||||
#define FIFO_TRIGGER_8 0x80 /* trigger at 8 chars */
|
||||
#define FIFO_TRIGGER_14 0xc0 /* trigger at 14 chars */
|
||||
|
||||
// 线路控制寄存器
|
||||
/* character format control register */
|
||||
#define CFCR_DLAB 0x80 /* divisor latch */
|
||||
#define CFCR_SBREAK 0x40 /* send break */
|
||||
#define CFCR_PZERO 0x30 /* zero parity */
|
||||
#define CFCR_PONE 0x20 /* one parity */
|
||||
#define CFCR_PEVEN 0x10 /* even parity */
|
||||
#define CFCR_PODD 0x00 /* odd parity */
|
||||
#define CFCR_PENAB 0x08 /* parity enable */
|
||||
#define CFCR_STOPB 0x04 /* 2 stop bits */
|
||||
#define CFCR_8BITS 0x03 /* 8 data bits */
|
||||
#define CFCR_7BITS 0x02 /* 7 data bits */
|
||||
#define CFCR_6BITS 0x01 /* 6 data bits */
|
||||
#define CFCR_5BITS 0x00 /* 5 data bits */
|
||||
|
||||
/* modem control register */
|
||||
#define MCR_LOOPBACK 0x10 /* loopback */
|
||||
#define MCR_IENABLE 0x08 /* output 2 = int enable */
|
||||
#define MCR_DRS 0x04 /* output 1 = xxx */
|
||||
#define MCR_RTS 0x02 /* enable RTS */
|
||||
#define MCR_DTR 0x01 /* enable DTR */
|
||||
|
||||
/* line status register */
|
||||
#define LSR_RCV_FIFO 0x80 /* error in receive fifo */
|
||||
#define LSR_TSRE 0x40 /* transmitter empty */
|
||||
#define LSR_TXRDY 0x20 /* transmitter ready */
|
||||
#define LSR_BI 0x10 /* break detected */
|
||||
#define LSR_FE 0x08 /* framing error */
|
||||
#define LSR_PE 0x04 /* parity error */
|
||||
#define LSR_OE 0x02 /* overrun error */
|
||||
#define LSR_RXRDY 0x01 /* receiver ready */
|
||||
#define LSR_RCV_MASK 0x1f
|
||||
|
||||
|
||||
// 串口模块编号
|
||||
typedef enum
|
||||
{
|
||||
LS1C_UART00 = 0, // 全功能串口UART0可以分为两个四线串口UART00和UART01
|
||||
LS1C_UART01,
|
||||
LS1C_UART1,
|
||||
LS1C_UART2,
|
||||
LS1C_UART3,
|
||||
LS1C_UART4,
|
||||
LS1C_UART5,
|
||||
LS1C_UART6,
|
||||
LS1C_UART7,
|
||||
LS1C_UART8,
|
||||
LS1C_UART9,
|
||||
LS1C_UART10,
|
||||
LS1C_UART11
|
||||
}ls1c_uart_t;
|
||||
|
||||
|
||||
// 串口信息
|
||||
typedef struct
|
||||
{
|
||||
ls1c_uart_t UARTx; // 串口模块编号
|
||||
unsigned int baudrate; // 波特率
|
||||
BOOL rx_enable; // 是否需要使用串口接收数据(使能接收中断),发送默认使能
|
||||
}ls1c_uart_info_t;
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* 获取指定串口模块的基地址
|
||||
* @UARTx 串口编号
|
||||
* @ret 基地址
|
||||
*/
|
||||
void *uart_get_base(ls1c_uart_t UARTx);
|
||||
|
||||
|
||||
/*
|
||||
* 初始化指定的串口模块
|
||||
* @uart_info_p 串口模块信息
|
||||
*/
|
||||
void uart_init(ls1c_uart_info_t *uart_info_p);
|
||||
|
||||
|
||||
/*
|
||||
* 初始化串口2
|
||||
*/
|
||||
void uart2_init(void);
|
||||
|
||||
|
||||
/*
|
||||
* 在串口2上打印字符串
|
||||
* @str 待打印的字符串
|
||||
*/
|
||||
void uart2_print(const char *str);
|
||||
|
||||
|
||||
/*
|
||||
* 在调试串口打印字符串
|
||||
* @str 待打印的字符串
|
||||
*/
|
||||
void uart_debug_print(const char *str);
|
||||
|
||||
|
||||
/*
|
||||
* 在调试串口打印一个字符
|
||||
* @ch 待打印的字符
|
||||
*/
|
||||
void uart_debug_putc(unsigned char ch);
|
||||
|
||||
|
||||
/*
|
||||
* 把中断号转换为串口号
|
||||
* @IRQn 中断号
|
||||
* @ret 串口号
|
||||
*/
|
||||
ls1c_uart_t uart_irqn_to_uartx(int IRQn);
|
||||
|
||||
|
||||
/*
|
||||
* 发送一个字节
|
||||
* @uartx 串口号
|
||||
* @ch 待发送的字符串
|
||||
*/
|
||||
void uart_putc(ls1c_uart_t uartx, unsigned char ch);
|
||||
|
||||
|
||||
/*
|
||||
* 打印一个字符串到指定串口
|
||||
* @uartx 串口号
|
||||
* @str 待打印的字符串
|
||||
*/
|
||||
void uart_print(ls1c_uart_t uartx, const char *str);
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
+16
-73
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user