瀏覽代碼

[bsp][dm365] Using component initial;
[drv][mmcsd] Add component initial.

weety 7 年之前
父節點
當前提交
dd5ac17fc8

+ 6 - 120
bsp/dm365/applications/application.c

@@ -29,63 +29,29 @@
 /*@{*/
 
 #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();
 	
 /* 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 +60,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,13 +70,6 @@ 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();
@@ -134,82 +77,25 @@ void rt_init_thread_entry(void* parameter)
 #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 */
+	if (MMCSD_HOST_PLUGED == mmcsd_wait_cd_changed(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
-	{
-		/* register ethernetif device */
-		eth_system_device_init();
-		rt_hw_davinci_emac_init();
-		/* init lwip system */
-		lwip_system_init();
-	}
-#endif
-
-}
+	/* put user application code here */
 
-
-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
-
-	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)

+ 24 - 2
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);
@@ -99,8 +112,10 @@ void rt_hw_board_init()
 	//rt_hw_clock_init();
 	davinci_clk_init();
 
-	/* 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
@@ -108,6 +123,13 @@ void rt_hw_board_init()
 	/* 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();
 

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

+ 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

+ 2 - 2
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);
-void rt_mmcsd_core_init(void);
+int rt_mmcsd_core_init(void);
 
-void rt_mmcsd_blk_init(void);
+int 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);
 

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

@@ -479,7 +479,11 @@ 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.
  */
-void rt_mmcsd_blk_init(void)
+int rt_mmcsd_blk_init(void)
 {
 	/* nothing */
+	return 0;
 }
+
+INIT_PREV_EXPORT(rt_mmcsd_blk_init);
+

+ 6 - 1
components/drivers/sdio/mmcsd_core.c

@@ -655,6 +655,7 @@ 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;
                 }
                 
@@ -726,7 +727,7 @@ void mmcsd_free_host(struct rt_mmcsd_host *host)
     rt_free(host);
 }
 
-void rt_mmcsd_core_init(void)
+int rt_mmcsd_core_init(void)
 {
     rt_err_t ret;
 
@@ -749,5 +750,9 @@ void rt_mmcsd_core_init(void)
     }
 
     rt_sdio_init();
+
+	return 0;
 }
 
+INIT_PREV_EXPORT(rt_mmcsd_core_init);
+

+ 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);
+
 }