From 5150e19d4b901db5b3f596b17e6aef857c4e424d Mon Sep 17 00:00:00 2001 From: weety Date: Fri, 20 Oct 2017 11:19:03 +0800 Subject: [PATCH] [bsp][dm365] Support rt_hw_console_output function; Adjust the initialization sequence; Cleanup code. [drv][mmcsd] Undo Changes. --- bsp/dm365/applications/application.c | 30 ++--- bsp/dm365/applications/board.c | 106 +++++++++++++++--- bsp/dm365/drivers/spi-davinci.c | 1 + bsp/dm365/platform/dm365.c | 3 +- bsp/dm365/platform/system_clock.c | 3 +- .../drivers/include/drivers/mmcsd_core.h | 4 +- components/drivers/sdio/block_dev.c | 5 +- components/drivers/sdio/mmcsd_core.c | 7 +- 8 files changed, 117 insertions(+), 42 deletions(-) diff --git a/bsp/dm365/applications/application.c b/bsp/dm365/applications/application.c index 507e1d9592..375a96935f 100644 --- a/bsp/dm365/applications/application.c +++ b/bsp/dm365/applications/application.c @@ -39,14 +39,10 @@ #include #endif -#ifdef RT_USING_SPI -#include -#endif - int main(void) { - platform_init(); - + int timeout = 0; + /* Filesystem Initialization */ #ifdef RT_USING_DFS { @@ -70,15 +66,17 @@ int main(void) } #endif -#ifdef RT_USING_SPI - { - rt_hw_spi_init(); - } -#endif - #ifdef RT_USING_SDIO + rt_mmcsd_core_init(); + rt_mmcsd_blk_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 */ if (dfs_mount("sd0", "/", "elm", 0, 0) == 0) @@ -87,7 +85,11 @@ int main(void) } else rt_kprintf("File System initialzation failed!%d\n", rt_get_errno()); - } + } + else + { + rt_kprintf("No SD card found.\n"); + } #endif } #endif diff --git a/bsp/dm365/applications/board.c b/bsp/dm365/applications/board.c index cd66ae0588..0ed0b6ff64 100644 --- a/bsp/dm365/applications/board.c +++ b/bsp/dm365/applications/board.c @@ -75,6 +75,9 @@ void rt_timer_handler(int vector, void *param) 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); + /*disable timer*/ 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 */ void rt_hw_board_init() { - psc_change_state(DAVINCI_DM365_LPSC_TIMER0, 3); - psc_change_state(DAVINCI_DM365_LPSC_TIMER1, 3); + /* initialize console */ + 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 */ - //rt_hw_clock_init(); - davinci_clk_init(); + rt_hw_clock_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 */ #ifdef RT_USING_COMPONENTS_INIT @@ -120,16 +208,6 @@ void rt_hw_board_init() rt_console_set_device(RT_CONSOLE_DEVICE_NAME); #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 */ rt_hw_timer_init(); diff --git a/bsp/dm365/drivers/spi-davinci.c b/bsp/dm365/drivers/spi-davinci.c index 443da606d5..fb5d9729d4 100644 --- a/bsp/dm365/drivers/spi-davinci.c +++ b/bsp/dm365/drivers/spi-davinci.c @@ -963,4 +963,5 @@ int rt_hw_spi_init(void) return 0; } +INIT_DEVICE_EXPORT(rt_hw_spi_init); diff --git a/bsp/dm365/platform/dm365.c b/bsp/dm365/platform/dm365.c index 42af671382..010e2a030e 100644 --- a/bsp/dm365/platform/dm365.c +++ b/bsp/dm365/platform/dm365.c @@ -316,11 +316,12 @@ int davinci_clk_init(void) return davinci_register_clks(clk_list, num_clks); } -void platform_init(void) +int platform_init(void) { edma_init(dm365_edma_info); } +INIT_BOARD_EXPORT(platform_init); /* Reset board using the watchdog timer */ void reset_system(void) diff --git a/bsp/dm365/platform/system_clock.c b/bsp/dm365/platform/system_clock.c index 6fd2a8d991..b4e81e98a2 100644 --- a/bsp/dm365/platform/system_clock.c +++ b/bsp/dm365/platform/system_clock.c @@ -26,12 +26,13 @@ #include #include "dm36x.h" +extern int davinci_clk_init(void); /** * @brief System Clock Configuration */ void rt_hw_clock_init(void) { - + davinci_clk_init(); } diff --git a/components/drivers/include/drivers/mmcsd_core.h b/components/drivers/include/drivers/mmcsd_core.h index 36d71efeb2..e474fa28a8 100644 --- a/components/drivers/include/drivers/mmcsd_core.h +++ b/components/drivers/include/drivers/mmcsd_core.h @@ -247,9 +247,9 @@ void mmcsd_change(struct rt_mmcsd_host *host); void mmcsd_detect(void *param); struct rt_mmcsd_host *mmcsd_alloc_host(void); 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); void rt_mmcsd_blk_remove(struct rt_mmcsd_card *card); diff --git a/components/drivers/sdio/block_dev.c b/components/drivers/sdio/block_dev.c index e6998f4fe3..c986556879 100644 --- a/components/drivers/sdio/block_dev.c +++ b/components/drivers/sdio/block_dev.c @@ -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 * in the system initialization. */ -int rt_mmcsd_blk_init(void) +void rt_mmcsd_blk_init(void) { /* nothing */ - return 0; } -INIT_PREV_EXPORT(rt_mmcsd_blk_init); - diff --git a/components/drivers/sdio/mmcsd_core.c b/components/drivers/sdio/mmcsd_core.c index 3e98444b71..02063efdd2 100644 --- a/components/drivers/sdio/mmcsd_core.c +++ b/components/drivers/sdio/mmcsd_core.c @@ -655,7 +655,6 @@ void mmcsd_detect(void *param) if (init_sd(host, ocr)) mmcsd_power_off(host); mmcsd_host_unlock(host); - rt_mb_send(&mmcsd_hotpluge_mb, (rt_uint32_t)host); continue; } @@ -727,7 +726,7 @@ void mmcsd_free_host(struct rt_mmcsd_host *host) rt_free(host); } -int rt_mmcsd_core_init(void) +void rt_mmcsd_core_init(void) { rt_err_t ret; @@ -750,9 +749,5 @@ int rt_mmcsd_core_init(void) } rt_sdio_init(); - - return 0; } -INIT_PREV_EXPORT(rt_mmcsd_core_init); -