2015-09-04 12:30:20 +08:00
|
|
|
/*
|
2021-04-09 10:52:34 +08:00
|
|
|
* Copyright (c) 2006-2021, RT-Thread Development Team
|
2015-09-04 12:30:20 +08:00
|
|
|
*
|
2021-04-09 10:52:34 +08:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2015-09-04 12:30:20 +08:00
|
|
|
*
|
|
|
|
* Change Logs:
|
2021-04-09 10:52:34 +08:00
|
|
|
* Date Author Notes
|
|
|
|
* 2010-11-13 weety first version
|
2015-09-04 12:30:20 +08:00
|
|
|
*/
|
|
|
|
|
2015-09-04 21:58:08 +08:00
|
|
|
|
2015-09-04 12:30:20 +08:00
|
|
|
#include <rtthread.h>
|
|
|
|
#include <rthw.h>
|
|
|
|
#include <mmu.h>
|
|
|
|
#include "board.h"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @addtogroup dm365
|
|
|
|
*/
|
|
|
|
/*@{*/
|
2017-10-19 19:14:06 +08:00
|
|
|
#if defined(__CC_ARM)
|
2021-04-09 10:52:34 +08:00
|
|
|
extern int Image$$ER_ZI$$ZI$$Base;
|
|
|
|
extern int Image$$ER_ZI$$ZI$$Length;
|
|
|
|
extern int Image$$ER_ZI$$ZI$$Limit;
|
2017-10-19 19:14:06 +08:00
|
|
|
#elif (defined (__GNUC__))
|
2021-04-09 10:52:34 +08:00
|
|
|
rt_uint8_t _irq_stack_start[1024];
|
|
|
|
rt_uint8_t _fiq_stack_start[1024];
|
|
|
|
rt_uint8_t _undefined_stack_start[512];
|
|
|
|
rt_uint8_t _abort_stack_start[512];
|
2022-12-12 02:12:03 +08:00
|
|
|
rt_uint8_t _svc_stack_start[1024] rt_section(".nobss");
|
2021-04-09 10:52:34 +08:00
|
|
|
extern unsigned char __bss_start;
|
|
|
|
extern unsigned char __bss_end;
|
2017-10-19 19:14:06 +08:00
|
|
|
#endif
|
2015-09-04 12:30:20 +08:00
|
|
|
|
|
|
|
extern void rt_hw_clock_init(void);
|
|
|
|
extern void rt_hw_uart_init(void);
|
|
|
|
|
|
|
|
static struct mem_desc dm365_mem_desc[] = {
|
2021-04-09 10:52:34 +08:00
|
|
|
{ 0x80000000, 0x88000000-1, 0x80000000, SECT_RW_CB, 0, SECT_MAPPED }, /* 128M cached SDRAM memory */
|
|
|
|
{ 0xA0000000, 0xA8000000-1, 0x80000000, SECT_RW_NCNB, 0, SECT_MAPPED }, /* 128M No cached SDRAM memory */
|
|
|
|
{ 0xFFFF0000, 0xFFFF1000-1, 0x80000000, SECT_TO_PAGE, PAGE_RO_CB, PAGE_MAPPED }, /* isr vector table */
|
|
|
|
{ 0x01C00000, 0x02000000-1, 0x01C00000, SECT_RW_NCNB, 0, SECT_MAPPED }, /* CFG BUS peripherals */
|
|
|
|
{ 0x02000000, 0x0A000000-1, 0x02000000, SECT_RW_NCNB, 0, SECT_MAPPED }, /* AEMIF */
|
2015-09-04 12:30:20 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This function will handle rtos timer
|
|
|
|
*/
|
|
|
|
void rt_timer_handler(int vector, void *param)
|
|
|
|
{
|
2021-04-09 10:52:34 +08:00
|
|
|
rt_tick_increase();
|
2015-09-04 12:30:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This function will init timer0 for system ticks
|
|
|
|
*/
|
|
|
|
void rt_hw_timer_init()
|
|
|
|
{
|
2021-04-09 10:52:34 +08:00
|
|
|
/* timer0, input clocks 24MHz */
|
|
|
|
volatile timer_regs_t *regs =
|
|
|
|
(volatile timer_regs_t*)DAVINCI_TIMER1_BASE;//DAVINCI_TIMER0_BASE;
|
|
|
|
|
|
|
|
psc_change_state(DAVINCI_DM365_LPSC_TIMER0, 3);
|
|
|
|
psc_change_state(DAVINCI_DM365_LPSC_TIMER1, 3);
|
2015-09-04 12:30:20 +08:00
|
|
|
|
2021-04-09 10:52:34 +08:00
|
|
|
/*disable timer*/
|
|
|
|
regs->tcr &= ~(0x3UL << 6);
|
2017-10-20 11:19:03 +08:00
|
|
|
|
2021-04-09 10:52:34 +08:00
|
|
|
//TIMMODE 32BIT UNCHAINED MODE
|
|
|
|
regs->tgcr |=(0x1UL << 2);
|
2015-09-04 12:30:20 +08:00
|
|
|
|
2021-04-09 10:52:34 +08:00
|
|
|
/*not in reset timer */
|
|
|
|
regs->tgcr |= (0x1UL << 0);
|
2015-09-04 12:30:20 +08:00
|
|
|
|
2021-04-09 10:52:34 +08:00
|
|
|
//regs->tgcr &= ~(0x1UL << 1);
|
2015-09-04 12:30:20 +08:00
|
|
|
|
2021-04-09 10:52:34 +08:00
|
|
|
/* set Period Registers */
|
|
|
|
regs->prd12 = 24000000/RT_TICK_PER_SECOND;
|
|
|
|
regs->tim12 = 0;
|
2015-09-04 12:30:20 +08:00
|
|
|
|
2021-04-09 10:52:34 +08:00
|
|
|
/* Set enable mode */
|
|
|
|
regs->tcr |= (0x2UL << 6); //period mode
|
2015-09-04 12:30:20 +08:00
|
|
|
|
|
|
|
|
2021-04-09 10:52:34 +08:00
|
|
|
/* install interrupt handler */
|
|
|
|
rt_hw_interrupt_install(IRQ_DM365_TINT2, rt_timer_handler,
|
|
|
|
RT_NULL, "timer1_12");//IRQ_DM365_TINT0_TINT12
|
|
|
|
rt_hw_interrupt_umask(IRQ_DM365_TINT2);//IRQ_DM365_TINT2
|
2015-09-04 12:30:20 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-04-09 10:52:34 +08:00
|
|
|
#define LSR_DR 0x01 /* Data ready */
|
|
|
|
#define LSR_THRE 0x20 /* Xmit holding register empty */
|
|
|
|
#define BPS 115200 /* serial baudrate */
|
2017-10-20 11:19:03 +08:00
|
|
|
|
|
|
|
typedef struct uartport
|
|
|
|
{
|
2021-04-09 10:52:34 +08:00
|
|
|
volatile rt_uint32_t rbr;
|
|
|
|
volatile rt_uint32_t ier;
|
|
|
|
volatile rt_uint32_t fcr;
|
|
|
|
volatile rt_uint32_t lcr;
|
|
|
|
volatile rt_uint32_t mcr;
|
|
|
|
volatile rt_uint32_t lsr;
|
|
|
|
volatile rt_uint32_t msr;
|
|
|
|
volatile rt_uint32_t scr;
|
|
|
|
volatile rt_uint32_t dll;
|
|
|
|
volatile rt_uint32_t dlh;
|
|
|
|
|
|
|
|
volatile rt_uint32_t res[2];
|
|
|
|
volatile rt_uint32_t pwremu_mgmt;
|
|
|
|
volatile rt_uint32_t mdr;
|
2017-10-20 11:19:03 +08:00
|
|
|
}uartport;
|
|
|
|
|
|
|
|
#define thr rbr
|
|
|
|
#define iir fcr
|
|
|
|
|
2021-04-09 10:52:34 +08:00
|
|
|
#define UART0 ((struct uartport *)DAVINCI_UART0_BASE)
|
2017-10-20 11:19:03 +08:00
|
|
|
|
|
|
|
static void davinci_uart_putc(char c)
|
|
|
|
{
|
|
|
|
while (!(UART0->lsr & LSR_THRE));
|
2021-04-09 10:52:34 +08:00
|
|
|
UART0->thr = c;
|
2017-10-20 11:19:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This function is used to display a string on console, normally, it's
|
|
|
|
* invoked by rt_kprintf
|
|
|
|
*
|
|
|
|
* @param str the displayed string
|
|
|
|
*/
|
|
|
|
void rt_hw_console_output(const char* str)
|
|
|
|
{
|
2021-04-09 10:52:34 +08:00
|
|
|
while (*str)
|
|
|
|
{
|
|
|
|
if (*str=='\n')
|
|
|
|
{
|
|
|
|
davinci_uart_putc('\r');
|
|
|
|
}
|
|
|
|
|
|
|
|
davinci_uart_putc(*str++);
|
|
|
|
}
|
2017-10-20 11:19:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void rt_hw_console_init(void)
|
|
|
|
{
|
2021-04-09 10:52:34 +08:00
|
|
|
rt_uint32_t divisor;
|
|
|
|
|
|
|
|
divisor = (24000000 + (BPS * (16 / 2))) / (16 * BPS);
|
|
|
|
UART0->ier = 0;
|
|
|
|
UART0->lcr = 0x83; //8N1
|
|
|
|
UART0->dll = 0;
|
|
|
|
UART0->dlh = 0;
|
|
|
|
UART0->lcr = 0x03;
|
|
|
|
UART0->mcr = 0x03; //RTS,CTS
|
|
|
|
UART0->fcr = 0x07; //FIFO
|
|
|
|
UART0->lcr = 0x83;
|
|
|
|
UART0->dll = divisor & 0xff;
|
|
|
|
UART0->dlh = (divisor >> 8) & 0xff;
|
|
|
|
UART0->lcr = 0x03;
|
|
|
|
UART0->mdr = 0; //16x over-sampling
|
|
|
|
UART0->pwremu_mgmt = 0x6000;
|
2017-10-20 11:19:03 +08:00
|
|
|
}
|
|
|
|
|
2015-09-04 12:30:20 +08:00
|
|
|
/**
|
|
|
|
* This function will init dm365 board
|
|
|
|
*/
|
|
|
|
void rt_hw_board_init()
|
|
|
|
{
|
2021-04-09 10:52:34 +08:00
|
|
|
/* initialize console */
|
|
|
|
rt_hw_console_init();
|
2017-10-20 11:19:03 +08:00
|
|
|
|
2021-04-09 10:52:34 +08:00
|
|
|
/* initialize mmu */
|
|
|
|
rt_hw_mmu_init(dm365_mem_desc, sizeof(dm365_mem_desc)/sizeof(dm365_mem_desc[0]));
|
2017-10-20 11:19:03 +08:00
|
|
|
|
2021-04-09 10:52:34 +08:00
|
|
|
/* initialize hardware interrupt */
|
|
|
|
rt_hw_interrupt_init();
|
2017-10-20 11:19:03 +08:00
|
|
|
|
2021-04-09 10:52:34 +08:00
|
|
|
/* initialize the system clock */
|
|
|
|
rt_hw_clock_init();
|
2017-10-20 11:19:03 +08:00
|
|
|
|
2021-04-09 10:52:34 +08:00
|
|
|
/* initialize heap memory system */
|
2017-10-20 11:19:03 +08:00
|
|
|
#ifdef __CC_ARM
|
2021-04-09 10:52:34 +08:00
|
|
|
rt_system_heap_init((void*)&Image$$ER_ZI$$ZI$$Limit, (void*)0x88000000);
|
2017-10-20 11:19:03 +08:00
|
|
|
#else
|
2021-04-09 10:52:34 +08:00
|
|
|
rt_system_heap_init((void*)&__bss_end, (void*)0x88000000);
|
2017-10-20 11:19:03 +08:00
|
|
|
#endif
|
2015-09-04 12:30:20 +08:00
|
|
|
|
2021-04-09 10:52:34 +08:00
|
|
|
/* initialize early device */
|
2017-10-19 19:14:06 +08:00
|
|
|
#ifdef RT_USING_COMPONENTS_INIT
|
2021-04-09 10:52:34 +08:00
|
|
|
rt_components_board_init();
|
2017-10-19 19:14:06 +08:00
|
|
|
#endif
|
2022-01-08 23:29:41 +08:00
|
|
|
#if defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE)
|
2021-04-09 10:52:34 +08:00
|
|
|
rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
|
2015-09-04 12:30:20 +08:00
|
|
|
#endif
|
|
|
|
|
2021-04-09 10:52:34 +08:00
|
|
|
/* initialize timer0 */
|
|
|
|
rt_hw_timer_init();
|
2015-09-04 12:30:20 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*@}*/
|