[bsp][dm365] Support rt_hw_console_output function; Adjust the initialization sequence; Cleanup code.

[drv][mmcsd] Undo Changes.
This commit is contained in:
weety 2017-10-20 11:19:03 +08:00
parent dd5ac17fc8
commit 5150e19d4b
8 changed files with 117 additions and 42 deletions

View File

@ -39,13 +39,9 @@
#include <drivers/mmcsd_core.h> #include <drivers/mmcsd_core.h>
#endif #endif
#ifdef RT_USING_SPI
#include <spi-davinci.h>
#endif
int main(void) int main(void)
{ {
platform_init(); int timeout = 0;
/* Filesystem Initialization */ /* Filesystem Initialization */
#ifdef RT_USING_DFS #ifdef RT_USING_DFS
@ -70,15 +66,17 @@ int main(void)
} }
#endif #endif
#ifdef RT_USING_SPI
{
rt_hw_spi_init();
}
#endif
#ifdef RT_USING_SDIO #ifdef RT_USING_SDIO
rt_mmcsd_core_init();
rt_mmcsd_blk_init();
rt_hw_mmcsd_init(); rt_hw_mmcsd_init();
if (MMCSD_HOST_PLUGED == mmcsd_wait_cd_changed(RT_TICK_PER_SECOND*2)) timeout = 0;
while ((rt_device_find("sd0") == RT_NULL) && (timeout++ < RT_TICK_PER_SECOND*2))
{
rt_thread_delay(1);
}
if (timeout < RT_TICK_PER_SECOND*2)
{ {
/* mount sd card fat partition 1 as root directory */ /* mount sd card fat partition 1 as root directory */
if (dfs_mount("sd0", "/", "elm", 0, 0) == 0) if (dfs_mount("sd0", "/", "elm", 0, 0) == 0)
@ -88,6 +86,10 @@ int main(void)
else else
rt_kprintf("File System initialzation failed!%d\n", rt_get_errno()); rt_kprintf("File System initialzation failed!%d\n", rt_get_errno());
} }
else
{
rt_kprintf("No SD card found.\n");
}
#endif #endif
} }
#endif #endif

View File

@ -75,6 +75,9 @@ void rt_timer_handler(int vector, void *param)
volatile timer_regs_t *regs = volatile timer_regs_t *regs =
(volatile timer_regs_t*)DAVINCI_TIMER1_BASE;//DAVINCI_TIMER0_BASE; (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);
/*disable timer*/ /*disable timer*/
regs->tcr &= ~(0x3UL << 6); regs->tcr &= ~(0x3UL << 6);
@ -101,16 +104,101 @@ void rt_timer_handler(int vector, void *param)
} }
#define LSR_DR 0x01 /* Data ready */
#define LSR_THRE 0x20 /* Xmit holding register empty */
#define BPS 115200 /* serial baudrate */
typedef struct uartport
{
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;
}uartport;
#define thr rbr
#define iir fcr
#define UART0 ((struct uartport *)DAVINCI_UART0_BASE)
static void davinci_uart_putc(char c)
{
while (!(UART0->lsr & LSR_THRE));
UART0->thr = c;
}
/**
* 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)
{
while (*str)
{
if (*str=='\n')
{
davinci_uart_putc('\r');
}
davinci_uart_putc(*str++);
}
}
static void rt_hw_console_init(void)
{
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;
}
/** /**
* This function will init dm365 board * This function will init dm365 board
*/ */
void rt_hw_board_init() void rt_hw_board_init()
{ {
psc_change_state(DAVINCI_DM365_LPSC_TIMER0, 3); /* initialize console */
psc_change_state(DAVINCI_DM365_LPSC_TIMER1, 3); rt_hw_console_init();
/* initialize mmu */
rt_hw_mmu_init(dm365_mem_desc, sizeof(dm365_mem_desc)/sizeof(dm365_mem_desc[0]));
/* initialize hardware interrupt */
rt_hw_interrupt_init();
/* initialize the system clock */ /* initialize the system clock */
//rt_hw_clock_init(); rt_hw_clock_init();
davinci_clk_init();
/* initialize heap memory system */
#ifdef __CC_ARM
rt_system_heap_init((void*)&Image$$ER_ZI$$ZI$$Limit, (void*)0x88000000);
#else
rt_system_heap_init((void*)&__bss_end, (void*)0x88000000);
#endif
/* initialize early device */ /* initialize early device */
#ifdef RT_USING_COMPONENTS_INIT #ifdef RT_USING_COMPONENTS_INIT
@ -120,16 +208,6 @@ void rt_hw_board_init()
rt_console_set_device(RT_CONSOLE_DEVICE_NAME); rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
#endif #endif
/* initialize mmu */
rt_hw_mmu_init(dm365_mem_desc, sizeof(dm365_mem_desc)/sizeof(dm365_mem_desc[0]));
/* initialize heap memory system */
#ifdef __CC_ARM
rt_system_heap_init((void*)&Image$$ER_ZI$$ZI$$Limit, (void*)0x88000000);
#else
rt_system_heap_init((void*)&__bss_end, (void*)0x88000000);
#endif
/* initialize timer0 */ /* initialize timer0 */
rt_hw_timer_init(); rt_hw_timer_init();

View File

@ -963,4 +963,5 @@ int rt_hw_spi_init(void)
return 0; return 0;
} }
INIT_DEVICE_EXPORT(rt_hw_spi_init);

View File

@ -316,11 +316,12 @@ int davinci_clk_init(void)
return davinci_register_clks(clk_list, num_clks); return davinci_register_clks(clk_list, num_clks);
} }
void platform_init(void) int platform_init(void)
{ {
edma_init(dm365_edma_info); edma_init(dm365_edma_info);
} }
INIT_BOARD_EXPORT(platform_init);
/* Reset board using the watchdog timer */ /* Reset board using the watchdog timer */
void reset_system(void) void reset_system(void)

View File

@ -26,12 +26,13 @@
#include <rtthread.h> #include <rtthread.h>
#include "dm36x.h" #include "dm36x.h"
extern int davinci_clk_init(void);
/** /**
* @brief System Clock Configuration * @brief System Clock Configuration
*/ */
void rt_hw_clock_init(void) void rt_hw_clock_init(void)
{ {
davinci_clk_init();
} }

View File

@ -247,9 +247,9 @@ void mmcsd_change(struct rt_mmcsd_host *host);
void mmcsd_detect(void *param); void mmcsd_detect(void *param);
struct rt_mmcsd_host *mmcsd_alloc_host(void); struct rt_mmcsd_host *mmcsd_alloc_host(void);
void mmcsd_free_host(struct rt_mmcsd_host *host); void mmcsd_free_host(struct rt_mmcsd_host *host);
int rt_mmcsd_core_init(void); void rt_mmcsd_core_init(void);
int rt_mmcsd_blk_init(void); void rt_mmcsd_blk_init(void);
rt_int32_t rt_mmcsd_blk_probe(struct rt_mmcsd_card *card); rt_int32_t rt_mmcsd_blk_probe(struct rt_mmcsd_card *card);
void rt_mmcsd_blk_remove(struct rt_mmcsd_card *card); void rt_mmcsd_blk_remove(struct rt_mmcsd_card *card);

View File

@ -479,11 +479,8 @@ void rt_mmcsd_blk_remove(struct rt_mmcsd_card *card)
* @deprecated since 2.1.0, this function does not need to be invoked * @deprecated since 2.1.0, this function does not need to be invoked
* in the system initialization. * in the system initialization.
*/ */
int rt_mmcsd_blk_init(void) void rt_mmcsd_blk_init(void)
{ {
/* nothing */ /* nothing */
return 0;
} }
INIT_PREV_EXPORT(rt_mmcsd_blk_init);

View File

@ -655,7 +655,6 @@ void mmcsd_detect(void *param)
if (init_sd(host, ocr)) if (init_sd(host, ocr))
mmcsd_power_off(host); mmcsd_power_off(host);
mmcsd_host_unlock(host); mmcsd_host_unlock(host);
rt_mb_send(&mmcsd_hotpluge_mb, (rt_uint32_t)host);
continue; continue;
} }
@ -727,7 +726,7 @@ void mmcsd_free_host(struct rt_mmcsd_host *host)
rt_free(host); rt_free(host);
} }
int rt_mmcsd_core_init(void) void rt_mmcsd_core_init(void)
{ {
rt_err_t ret; rt_err_t ret;
@ -750,9 +749,5 @@ int rt_mmcsd_core_init(void)
} }
rt_sdio_init(); rt_sdio_init();
return 0;
} }
INIT_PREV_EXPORT(rt_mmcsd_core_init);