2013-07-17 13:37:31 +08:00
|
|
|
/*
|
2021-04-09 10:52:34 +08:00
|
|
|
* Copyright (c) 2006-2021, RT-Thread Development Team
|
2013-07-17 13:37:31 +08:00
|
|
|
*
|
2021-04-09 10:52:34 +08:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2013-07-17 13:37:31 +08:00
|
|
|
*
|
|
|
|
* Change Logs:
|
|
|
|
* Date Author Notes
|
|
|
|
* 2013-7-14 Peng Fan sep6200 implementation
|
|
|
|
*/
|
|
|
|
|
2013-07-17 18:42:19 +08:00
|
|
|
/**
|
|
|
|
* @addtogroup sep6200
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*@{*/
|
2013-07-17 13:37:31 +08:00
|
|
|
#include <rthw.h>
|
|
|
|
#include <rtthread.h>
|
|
|
|
|
2024-09-14 05:40:40 +08:00
|
|
|
#include <drivers/dev_serial.h>
|
2013-07-17 13:37:31 +08:00
|
|
|
|
|
|
|
#include <sep6200.h>
|
|
|
|
|
|
|
|
void rt_hw_serial_putc(const char c);
|
|
|
|
|
2021-04-09 10:52:34 +08:00
|
|
|
#define UART0 ((struct uartport *)SEP6200_UART0_BASE)
|
2013-07-17 13:37:31 +08:00
|
|
|
|
|
|
|
struct rt_device uart0_device;
|
|
|
|
struct serial_int_rx uart0_int_rx;
|
|
|
|
struct serial_device uart0 =
|
|
|
|
{
|
2021-04-09 10:52:34 +08:00
|
|
|
UART0,
|
|
|
|
&uart0_int_rx,
|
2013-07-17 13:37:31 +08:00
|
|
|
RT_NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This function will handle rtos timer
|
|
|
|
*/
|
|
|
|
void rt_timer_handler(int vector, void *param)
|
|
|
|
{
|
2021-04-09 10:52:34 +08:00
|
|
|
rt_uint32_t clear_int;
|
2013-07-17 13:37:31 +08:00
|
|
|
|
2021-04-09 10:52:34 +08:00
|
|
|
/* clear timer interrupt */
|
|
|
|
if (read_reg(SEP6200_TIMER_T2IMSR) & 0x1)
|
|
|
|
clear_int = read_reg(SEP6200_TIMER_T2ISCR);
|
2013-07-17 13:37:31 +08:00
|
|
|
|
2021-04-09 10:52:34 +08:00
|
|
|
rt_tick_increase();
|
2013-07-17 13:37:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This function will handle serial interrupt
|
|
|
|
*/
|
|
|
|
void rt_serial_handler(int vector, void *param)
|
|
|
|
{
|
2021-04-09 10:52:34 +08:00
|
|
|
rt_uint32_t num;
|
|
|
|
switch (vector) {
|
|
|
|
case INTSRC_UART0:
|
2013-07-17 13:37:31 +08:00
|
|
|
|
|
|
|
/*No interrupt*/
|
2021-04-09 10:52:34 +08:00
|
|
|
if ((*(RP)SEP6200_UART0_IIR & 0x1))
|
|
|
|
return;
|
2013-07-17 13:37:31 +08:00
|
|
|
|
|
|
|
/*Get the serial interrupt num*/
|
2021-04-09 10:52:34 +08:00
|
|
|
num = (*(RP)SEP6200_UART0_IIR >> 1) & 0x7;
|
2013-07-17 13:37:31 +08:00
|
|
|
|
|
|
|
/*Receive or timeout*/
|
|
|
|
if ((num == 6) || (num == 2))
|
2021-04-09 10:52:34 +08:00
|
|
|
rt_hw_serial_isr(&uart0_device);
|
|
|
|
break;
|
|
|
|
/*1,2,3 not implemented now, do in future*/
|
|
|
|
case INTSRC_UART1:
|
|
|
|
break;
|
|
|
|
case INTSRC_UART2:
|
|
|
|
break;
|
|
|
|
case INTSRC_UART3:
|
|
|
|
break;
|
|
|
|
}
|
2013-07-17 13:37:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This function will init timer2 for system ticks
|
|
|
|
*/
|
2021-04-09 10:52:34 +08:00
|
|
|
#define BUS4_FREQ 320000000UL
|
|
|
|
#define TIMER_CLK BUS4_FREQ
|
2013-07-17 13:37:31 +08:00
|
|
|
#define HZ 100
|
|
|
|
void rt_hw_timer_init(void)
|
|
|
|
{
|
2021-04-09 10:52:34 +08:00
|
|
|
*(RP)SEP6200_TIMER_T2LCR = (TIMER_CLK + HZ / 2) / HZ;
|
|
|
|
*(RP)SEP6200_TIMER_T2CR = 0x6;
|
2013-07-17 13:37:31 +08:00
|
|
|
|
2021-04-09 10:52:34 +08:00
|
|
|
rt_hw_interrupt_install(INTSRC_TIMER1, rt_timer_handler, RT_NULL, "timer");
|
|
|
|
rt_hw_interrupt_umask(INTSRC_TIMER1);
|
2013-07-17 13:37:31 +08:00
|
|
|
|
2021-04-09 10:52:34 +08:00
|
|
|
/* start the timer */
|
|
|
|
*(RP)SEP6200_TIMER_T2CR |= 0x1;
|
2013-07-17 13:37:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This function will init uart
|
|
|
|
*/
|
|
|
|
#define UART_CLK 60000000UL
|
|
|
|
void rt_hw_uart_init(void)
|
|
|
|
{
|
2021-04-09 10:52:34 +08:00
|
|
|
const rt_uint32_t uartclk = UART_CLK;
|
2013-07-17 13:37:31 +08:00
|
|
|
|
2021-04-09 10:52:34 +08:00
|
|
|
*(RP)(SEP6200_UART0_LCR) = 0x83;
|
|
|
|
*(RP)(SEP6200_UART0_DLBH) = (uartclk/16/115200) >> 8;
|
|
|
|
*(RP)(SEP6200_UART0_DLBL) = (uartclk/16/115200) & 0xff;
|
|
|
|
*(RP)(SEP6200_UART0_LCR) = 0x83 & (~(0x1 << 7));
|
2013-07-17 13:37:31 +08:00
|
|
|
|
2021-04-09 10:52:34 +08:00
|
|
|
*(RP)(SEP6200_UART0_FCR) = 0x0;
|
|
|
|
*(RP)(SEP6200_UART0_MCR) = 0x0;
|
2013-07-17 13:37:31 +08:00
|
|
|
|
2021-04-09 10:52:34 +08:00
|
|
|
*(RP)(SEP6200_UART0_IER) = 0x0;
|
|
|
|
/* Enable rx interrupt*/
|
|
|
|
*(RP)(SEP6200_UART0_IER) |= 0x1;
|
|
|
|
/* Disable tx interrupt*/
|
|
|
|
*(RP)(SEP6200_UART0_IER) &= ~(0x1 << 1);
|
2013-07-17 13:37:31 +08:00
|
|
|
|
2021-04-09 10:52:34 +08:00
|
|
|
rt_hw_interrupt_install(INTSRC_UART0, rt_serial_handler, RT_NULL, "uart0");
|
|
|
|
rt_hw_interrupt_umask(INTSRC_UART0);
|
2013-07-17 13:37:31 +08:00
|
|
|
|
2021-04-09 10:52:34 +08:00
|
|
|
rt_hw_serial_register(&uart0_device, "uart0",
|
|
|
|
RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX | RT_DEVICE_FLAG_STREAM,
|
|
|
|
&uart0);
|
2013-07-17 13:37:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void rt_hw_board_init(void)
|
|
|
|
{
|
|
|
|
int i = 0;
|
2021-04-09 10:52:34 +08:00
|
|
|
rt_hw_uart_init();
|
|
|
|
rt_hw_timer_init();
|
2013-07-17 13:37:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Write one char to serial, must not trigger interrupt
|
|
|
|
*/
|
|
|
|
void rt_hw_serial_putc(const char c)
|
|
|
|
{
|
2021-04-09 10:52:34 +08:00
|
|
|
if (c == '\n')
|
|
|
|
rt_hw_serial_putc('\r');
|
2013-07-17 13:37:31 +08:00
|
|
|
|
2021-04-09 10:52:34 +08:00
|
|
|
while (!((*(RP)SEP6200_UART0_LSR) & 0x40));
|
2013-07-17 13:37:31 +08:00
|
|
|
|
2021-04-09 10:52:34 +08:00
|
|
|
*(RP)(SEP6200_UART0_TXFIFO) = c;
|
2013-07-17 13:37:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This function is used by rt_kprintf to display a string on console.
|
|
|
|
*
|
|
|
|
* @param str the displayed string^M
|
|
|
|
*/
|
|
|
|
void rt_hw_console_output(const char *str)
|
|
|
|
{
|
|
|
|
while (*str) {
|
|
|
|
rt_hw_serial_putc(*str++);
|
|
|
|
}
|
|
|
|
}
|
2013-07-17 18:42:19 +08:00
|
|
|
|
|
|
|
/*@}*/
|