Browse Source

Merge pull request #886 from weety/rtt3_0_dm365

[BSP] use main() in dm365 bsp.
Bernard Xiong 7 years ago
parent
commit
fbe3a4d1db

+ 16 - 128
bsp/dm365/applications/application.c

@@ -29,63 +29,25 @@
 /*@{*/
 
 #include <rtthread.h>
-//#include <rtdevice.h>
 
 #ifdef RT_USING_DFS
-/* dfs filesystem:ELM FatFs filesystem init */
-#include <dfs_elm.h>
 /* dfs Filesystem APIs */
 #include <dfs_fs.h>
-#ifdef RT_USING_DFS_UFFS
-/* dfs filesystem:UFFS filesystem init */
-#include <dfs_uffs.h>
-#endif
-#endif
-
-#if defined(RT_USING_DFS_DEVFS)
-#include <devfs.h>
 #endif
 
 #ifdef RT_USING_SDIO
 #include <drivers/mmcsd_core.h>
-
-#endif
-
-#ifdef RT_USING_LWIP
-#include <netif/ethernetif.h>
-#endif
-
-#ifdef RT_USING_SPI
-#include <spi-davinci.h>
-#endif
-
-#ifdef RT_USING_LED
-#include "led.h"
 #endif
 
-#define RT_INIT_THREAD_STACK_SIZE (2*1024)
-
-#ifdef RT_USING_DFS_ROMFS
-#include <dfs_romfs.h>
-#endif
-
-void rt_init_thread_entry(void* parameter)
+int main(void)
 {
-	platform_init();
-	
+	int timeout = 0;
+
 /* Filesystem Initialization */
 #ifdef RT_USING_DFS
 	{
-		/* init the device filesystem */
-		dfs_init();
-
-#if defined(RT_USING_DFS_ELMFAT)
-		/* init the elm chan FatFs filesystam*/
-		elm_init();
-#endif
 
 #if defined(RT_USING_DFS_ROMFS)
-		dfs_romfs_init();
 		if (dfs_mount(RT_NULL, "/rom", "rom", 0, &romfs_root) == 0)
 		{
 			rt_kprintf("ROM File System initialized!\n");
@@ -94,24 +56,8 @@ void rt_init_thread_entry(void* parameter)
 			rt_kprintf("ROM File System initialzation failed!\n");
 #endif
 
-#if defined(RT_USING_DFS_DEVFS)
-		devfs_init();
-		if (dfs_mount(RT_NULL, "/dev", "devfs", 0, 0) == 0)
-			rt_kprintf("Device File System initialized!\n");
-		else
-			rt_kprintf("Device File System initialzation failed!\n");
-
-		#ifdef RT_USING_NEWLIB
-		/* init libc */
-		libc_system_init(RT_CONSOLE_DEVICE_NAME);
-		#endif
-#endif
-
 #if defined(RT_USING_DFS_UFFS)
 	{
-		/* init the uffs filesystem */
-		dfs_uffs_init();
-
 		/* mount flash device as flash directory */
 		if(dfs_mount("nand0", "/nand0", "uffs", 0, 0) == 0)
 			rt_kprintf("UFFS File System initialized!\n");
@@ -120,97 +66,39 @@ void rt_init_thread_entry(void* parameter)
 	}
 #endif
 
-#ifdef RT_USING_I2C
-	{
-		rt_i2c_core_init();
-		davinci_i2c_init("I2C1");
-	}
-#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();
-	rt_thread_delay(RT_TICK_PER_SECOND*2);
-	/* mount sd card fat partition 1 as root directory */
+	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)
 		{
 			rt_kprintf("File System initialized!\n");
 		}
 		else
 			rt_kprintf("File System initialzation failed!%d\n", rt_get_errno());
-#endif
 	}
-#endif
-
-#ifdef RT_USING_LWIP
+	else
 	{
-		/* register ethernetif device */
-		eth_system_device_init();
-		rt_hw_davinci_emac_init();
-		/* init lwip system */
-		lwip_system_init();
+		rt_kprintf("No SD card found.\n");
 	}
 #endif
-
-}
-
-
-void rt_led_thread_entry(void* parameter)
-{
-	while(1)
-	{
-		/* light on leds for one second */
-		rt_thread_delay(100);
-
-		/* light off leds for one second */
-		rt_thread_delay(100);
 	}
-}
-
-int rt_application_init()
-{
-	rt_thread_t init_thread;
-#ifdef RT_USING_LED
-	rt_thread_t led_thread;
 #endif
 
-#if (RT_THREAD_PRIORITY_MAX == 32)
-	init_thread = rt_thread_create("init",
-								rt_init_thread_entry, RT_NULL,
-								RT_INIT_THREAD_STACK_SIZE, 8, 20);
-#ifdef RT_USING_LED
-	led_thread = rt_thread_create("led",
-								rt_led_thread_entry, RT_NULL,
-								512, 20, 20);
-#endif
-#else
-	init_thread = rt_thread_create("init",
-								rt_init_thread_entry, RT_NULL,
-								RT_INIT_THREAD_STACK_SIZE, 80, 20);
-#ifdef RT_USING_LED
-	led_thread = rt_thread_create("led",
-								rt_led_thread_entry, RT_NULL,
-								512, 200, 20);
-#endif
-#endif
+	/* put user application code here */
 
-	if (init_thread != RT_NULL)
-		rt_thread_startup(init_thread);
-#ifdef RT_USING_LED
-	if(led_thread != RT_NULL)
-		rt_thread_startup(led_thread);
-#endif
-
-	return 0;
 }
 
+
 /* NFSv3 Initialization */
 #if defined(RT_USING_DFS) && defined(RT_USING_LWIP) && defined(RT_USING_DFS_NFS)
 #include <dfs_nfs.h>

+ 109 - 9
bsp/dm365/applications/board.c

@@ -32,6 +32,19 @@
  * @addtogroup dm365
  */
 /*@{*/
+#if defined(__CC_ARM)
+	extern int Image$$ER_ZI$$ZI$$Base;
+	extern int Image$$ER_ZI$$ZI$$Length;
+	extern int Image$$ER_ZI$$ZI$$Limit;
+#elif (defined (__GNUC__))
+	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];
+	rt_uint8_t _svc_stack_start[1024] SECTION(".nobss");
+	extern unsigned char __bss_start;
+	extern unsigned char __bss_end;
+#endif
 
 extern void rt_hw_clock_init(void);
 extern void rt_hw_uart_init(void);
@@ -62,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);
 
@@ -88,26 +104,110 @@ 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 uart */
-	rt_hw_uart_init();
+	/* initialize early device */
+#ifdef RT_USING_COMPONENTS_INIT
+	rt_components_board_init();
+#endif
 #ifdef RT_USING_CONSOLE
 	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 timer0 */
 	rt_hw_timer_init();
 

+ 0 - 148
bsp/dm365/applications/startup.c

@@ -1,148 +0,0 @@
-/*
- * File      : startup.c
- * This file is part of RT-Thread RTOS
- * COPYRIGHT (C) 2006, 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
- * 2011-01-13     weety		first version
- */
-
-#include <rthw.h>
-#include <rtthread.h>
-
-#include <dm36x.h>
-#ifdef RT_USING_FINSH
-#include <finsh.h>
-#endif
-
-extern void rt_hw_interrupt_init(void);
-extern void rt_hw_board_init(void);
-extern void rt_serial_init(void);
-extern void rt_system_timer_init(void);
-extern void rt_system_scheduler_init(void);
-extern void rt_thread_idle_init(void);
-extern void rt_hw_cpu_icache_enable(void);
-extern void rt_show_version(void);
-extern void rt_system_heap_init(void*, void*);
-extern void rt_hw_finsh_init(void);
-extern void rt_application_init(void);
-
-/**
- * @addtogroup dm365
- */
-
-/*@{*/
-#if defined(__CC_ARM)
-	extern int Image$$ER_ZI$$ZI$$Base;
-	extern int Image$$ER_ZI$$ZI$$Length;
-	extern int Image$$ER_ZI$$ZI$$Limit;
-#elif (defined (__GNUC__))
-	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];
-	rt_uint8_t _svc_stack_start[1024] SECTION(".nobss");
-	extern unsigned char __bss_start;
-	extern unsigned char __bss_end;
-#endif
-
-#ifdef RT_USING_FINSH
-extern int finsh_system_init(void);
-#endif
-
-
-/**
- * This function will startup RT-Thread RTOS.
- */
-void rtthread_startup(void)
-{
-	/* enable cpu cache */
-	//rt_hw_cpu_icache_enable();
-	//rt_hw_cpu_dcache_enable();
-
-	/* initialize hardware interrupt */
-	rt_hw_interrupt_init();
-
-	/* initialize board */
-	rt_hw_board_init();
-
-	/* show version */
-	rt_show_version();
-	
-	/* initialize tick */
-	rt_system_tick_init();
-
-	/* initialize kernel object */
-	rt_system_object_init();
-
-	/* initialize timer system */
-	rt_system_timer_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
-
-#ifdef RT_USING_MODULE
-	/* initialize module system*/
-	rt_system_module_init();
-#endif
-
-	/* initialize scheduler system */
-	rt_system_scheduler_init();
-
-	/* initialize application */
-	rt_application_init();
-
-#ifdef RT_USING_FINSH
-	/* initialize finsh */
-	finsh_system_init();
-#ifdef RT_USING_DEVICE
-	finsh_set_device(RT_CONSOLE_DEVICE_NAME);
-#endif
-#endif
-
-	/* initialize system timer thread */
-	rt_system_timer_thread_init();
-
-	/* initialize idle thread */
-	rt_thread_idle_init();
-
-	/* start scheduler */
-	rt_system_scheduler_start();
-
-	/* never reach here */
-	return ;
-}
-
-int main(void)
-{
-	rt_uint32_t RT_UNUSED level;
-
-	/* disable interrupt first */
-	level = rt_hw_interrupt_disable();
-
-	/* startup RT-Thread RTOS */
-	rtthread_startup();
-
-	return 0;
-}
-
-/*@}*/

+ 8 - 0
bsp/dm365/dm365_ram.ld

@@ -28,6 +28,14 @@ SECTIONS
 		__rtmsymtab_start = .;
 		KEEP(*(RTMSymTab))
 		__rtmsymtab_end = .;
+		. = ALIGN(4);
+
+		 /* section information for initial. */
+		. = ALIGN(4);
+		__rt_init_start = .;
+		KEEP(*(SORT(.rti_fn*)))
+		__rt_init_end = .;
+		. = ALIGN(4);
 	}
 
 	. = ALIGN(4);

+ 2 - 0
bsp/dm365/drivers/davinci_emac.c

@@ -1698,6 +1698,8 @@ void rt_hw_davinci_emac_init()
 	
 }
 
+INIT_DEVICE_EXPORT(rt_hw_davinci_emac_init);
+
 
 #ifdef RT_USING_FINSH
 #include <finsh.h>

+ 4 - 1
bsp/dm365/drivers/davinci_serial.c

@@ -223,7 +223,7 @@ void davinci_uart1_init(void)
 /**
  * This function will handle init uart
  */
-void rt_hw_uart_init(void)
+int rt_hw_uart_init(void)
 {
 	davinci_serial_dev0.ops = &davinci_uart_ops;
     //davinci_serial_dev0.config = RT_SERIAL_CONFIG_DEFAULT;
@@ -257,5 +257,8 @@ void rt_hw_uart_init(void)
                           UART1);
 	davinci_uart1_init();
 
+	return 0;
 }
 
+INIT_BOARD_EXPORT(rt_hw_uart_init);
+

+ 6 - 0
bsp/dm365/drivers/i2c-davinci.c

@@ -647,4 +647,10 @@ err:
 	return r;
 }
 
+int rt_hw_iic_init(void)
+{
+	davinci_i2c_init("I2C1");
+}
+
+INIT_DEVICE_EXPORT(rt_hw_iic_init);
 

+ 1 - 0
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);
 

+ 2 - 1
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)

+ 2 - 1
bsp/dm365/platform/system_clock.c

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

+ 3 - 0
bsp/dm365/rtconfig.h

@@ -267,4 +267,7 @@
  * #define RT_DFS_ELM_MAX_LFN	128
  */
 
+#define RT_USING_COMPONENTS_INIT
+#define RT_USING_USER_MAIN
+
 #endif

+ 1 - 0
components/drivers/sdio/block_dev.c

@@ -483,3 +483,4 @@ void rt_mmcsd_blk_init(void)
 {
 	/* nothing */
 }
+

+ 3 - 4
components/drivers/sdio/sdio.c

@@ -33,8 +33,8 @@
 #define RT_SDIO_THREAD_PRIORITY  0x40
 #endif
 
-static rt_list_t sdio_cards;
-static rt_list_t sdio_drivers;
+static rt_list_t sdio_cards = RT_LIST_OBJECT_INIT(sdio_cards);
+static rt_list_t sdio_drivers = RT_LIST_OBJECT_INIT(sdio_drivers);
 
 struct sdio_card
 {
@@ -1397,7 +1397,6 @@ rt_int32_t sdio_unregister_driver(struct rt_sdio_driver *driver)
 
 void rt_sdio_init(void)
 {
-    rt_list_init(&sdio_cards);
-    rt_list_init(&sdio_drivers);
+
 }