From 090153f94f52cc74906dd5f4cfc893493755c0a2 Mon Sep 17 00:00:00 2001 From: ardafu Date: Fri, 25 Sep 2015 15:35:37 +0800 Subject: [PATCH 01/36] [bsp][stm32f746-Disco] Cleanup code 1. Using RT_USING_COMPONENTS_INIT and RT_USING_USER_MAIN 2. Cleanup code --- bsp/stm32f7-disco/applications/application.c | 6 +- bsp/stm32f7-disco/applications/startup.c | 125 ------------------- bsp/stm32f7-disco/drivers/board.c | 25 ++-- bsp/stm32f7-disco/drivers/board.h | 2 +- bsp/stm32f7-disco/drivers/drv_mpu.c | 9 +- bsp/stm32f7-disco/drivers/drv_mpu.h | 4 +- bsp/stm32f7-disco/drivers/drv_sdram.c | 6 + bsp/stm32f7-disco/rtconfig.h | 3 + bsp/stm32f7-disco/rtconfig.py | 2 +- 9 files changed, 37 insertions(+), 145 deletions(-) delete mode 100644 bsp/stm32f7-disco/applications/startup.c diff --git a/bsp/stm32f7-disco/applications/application.c b/bsp/stm32f7-disco/applications/application.c index e1dafdf5b2..2bf527c90b 100644 --- a/bsp/stm32f7-disco/applications/application.c +++ b/bsp/stm32f7-disco/applications/application.c @@ -24,14 +24,14 @@ */ #include -#include void rt_init_thread_entry(void *parameter) { - rt_components_init(); + //rt_components_init(); } -int rt_application_init() +//int rt_application_init() +int main(void) { rt_thread_t tid; diff --git a/bsp/stm32f7-disco/applications/startup.c b/bsp/stm32f7-disco/applications/startup.c deleted file mode 100644 index 628a805042..0000000000 --- a/bsp/stm32f7-disco/applications/startup.c +++ /dev/null @@ -1,125 +0,0 @@ -/* - * File : startup.c - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2015, 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 - * 2006-08-31 Bernard first implementation - * 2015-08-01 xiaonong modify for STM32F7 version - */ - -#include -#include -#include "board.h" - -#ifdef RT_USING_EXT_SDRAM -#include "drv_sdram.h" -#include "sram.h" -#endif - -/** - * @addtogroup STM32 - */ - -/*@{*/ - -extern int rt_application_init(void); - -#ifdef USE_FULL_ASSERT -/** -* @brief assert_failed -* Reports the name of the source file and the source line number -* where the assert_param error has occurred. -* @param File: pointer to the source file name -* @param Line: assert_param error line source number -* @retval None -*/ -void assert_failed(uint8_t* file, uint32_t line) -{ - /* User can add his own implementation to report the file name and line - number,ex: printf("Wrong parameters value: file %s on line %d\r\n", - file, line) */ - rt_kprintf("\n\r Wrong parameter value detected on\r\n"); - rt_kprintf(" file %s\r\n", file); - rt_kprintf(" line %d\r\n", line); - - /* Infinite loop */ - while (1) - {} -} -#endif - -/** - * This function will startup RT-Thread RTOS. - */ -void rtthread_startup(void) -{ - /* init board */ - rt_hw_board_init(); - - /* show version */ - rt_show_version(); - - /* init tick */ - rt_system_tick_init(); - - /* init kernel object */ - rt_system_object_init(); - - /* init timer system */ - rt_system_timer_init(); - -#ifdef RT_USING_EXT_SDRAM - sdram_hw_init(); - rt_system_heap_init((void*)EXT_SDRAM_BEGIN, (void*)EXT_SDRAM_END); - sram_init(); -#else - rt_system_heap_init((void*)HEAP_BEGIN, (void*)HEAP_END); -#endif - - /* init scheduler system */ - rt_system_scheduler_init(); - - /* init application */ - rt_application_init(); - - /* init timer thread */ - rt_system_timer_thread_init(); - - /* init idle thread */ - rt_thread_idle_init(); - - /* start scheduler */ - rt_system_scheduler_start(); - - /* never reach here */ - return ; -} - -int main(void) -{ - /* disable interrupt first */ - rt_hw_interrupt_disable(); - - /* startup RT-Thread RTOS */ - rtthread_startup(); - - return 0; -} - -/*@}*/ diff --git a/bsp/stm32f7-disco/drivers/board.c b/bsp/stm32f7-disco/drivers/board.c index 734ecf2094..0553920a47 100644 --- a/bsp/stm32f7-disco/drivers/board.c +++ b/bsp/stm32f7-disco/drivers/board.c @@ -22,13 +22,10 @@ * 2009-01-05 Bernard first implementation */ -#include #include -#include - #include "board.h" -#include "drv_usart.h" -#include "drv_mpu.h" +#include "sram.h" + /** * @addtogroup STM32 @@ -70,11 +67,11 @@ static void SystemClock_Config(void) RCC_OscInitStruct.PLL.PLLN = 400; RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; RCC_OscInitStruct.PLL.PLLQ = 8; - + ret = HAL_RCC_OscConfig(&RCC_OscInitStruct); if(ret != HAL_OK) { - while(1) { ; } + while (1) { ; } } ret = HAL_PWREx_EnableOverDrive(); @@ -85,7 +82,8 @@ static void SystemClock_Config(void) /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 clocks dividers */ - RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2); + RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK |\ + RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2); RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4; @@ -167,7 +165,7 @@ void HAL_ResumeTick(void) void rt_hw_board_init() { /* Configure the MPU attributes as Write Through */ - mpu_init(); + //mpu_init(); /* Enable the CPU Cache */ CPU_CACHE_Enable(); @@ -186,7 +184,16 @@ void rt_hw_board_init() /* set pend exception priority */ NVIC_SetPriority(PendSV_IRQn, (1 << __NVIC_PRIO_BITS) - 1); +#ifdef RT_USING_COMPONENTS_INIT rt_components_board_init(); +#endif + +#ifdef RT_USING_EXT_SDRAM + rt_system_heap_init((void*)EXT_SDRAM_BEGIN, (void*)EXT_SDRAM_END); + sram_init(); +#else + rt_system_heap_init((void*)HEAP_BEGIN, (void*)HEAP_END); +#endif #ifdef RT_USING_CONSOLE rt_console_set_device(RT_CONSOLE_DEVICE_NAME); diff --git a/bsp/stm32f7-disco/drivers/board.h b/bsp/stm32f7-disco/drivers/board.h index d4aebe06d6..8d1e9f3739 100644 --- a/bsp/stm32f7-disco/drivers/board.h +++ b/bsp/stm32f7-disco/drivers/board.h @@ -31,8 +31,8 @@ // Use external SDRAM memory on the board // Begin Address of External SDRAM #define EXT_SDRAM_BEGIN 0xC0000000 +// Size of External SDRAM #define EXT_SDRAM_SIZE (0x800000) -// End Address of External SDRAM #define EXT_SDRAM_END (EXT_SDRAM_BEGIN + EXT_SDRAM_SIZE) // diff --git a/bsp/stm32f7-disco/drivers/drv_mpu.c b/bsp/stm32f7-disco/drivers/drv_mpu.c index 4cab4d2281..630e48e2d2 100644 --- a/bsp/stm32f7-disco/drivers/drv_mpu.c +++ b/bsp/stm32f7-disco/drivers/drv_mpu.c @@ -23,9 +23,9 @@ */ #include "drv_mpu.h" - - -void mpu_init(void) +#include +#include "stm32f7xx.h" +int mpu_init(void) { MPU_Region_InitTypeDef MPU_InitStruct; @@ -79,5 +79,6 @@ void mpu_init(void) /* Enable the MPU */ HAL_MPU_Enable(MPU_PRIVILEGED_DEFAULT); + return 0; } - +INIT_BOARD_EXPORT(mpu_init); diff --git a/bsp/stm32f7-disco/drivers/drv_mpu.h b/bsp/stm32f7-disco/drivers/drv_mpu.h index 707adfc2ef..9baf74b0d7 100644 --- a/bsp/stm32f7-disco/drivers/drv_mpu.h +++ b/bsp/stm32f7-disco/drivers/drv_mpu.h @@ -1,9 +1,9 @@ #ifndef __DRV_MPU_H #define __DRV_MPU_H -#include "stm32f7xx.h" + /* Initialize Cortex M MPU */ -void mpu_init(void); +int mpu_init(void); #endif diff --git a/bsp/stm32f7-disco/drivers/drv_sdram.c b/bsp/stm32f7-disco/drivers/drv_sdram.c index 4b58e21d01..303bd3b928 100644 --- a/bsp/stm32f7-disco/drivers/drv_sdram.c +++ b/bsp/stm32f7-disco/drivers/drv_sdram.c @@ -362,3 +362,9 @@ void SDRAM_DMA_IRQHandler(void) { HAL_DMA_IRQHandler(sdramHandle.hdma); } + +static int rt_sdram_hw_init(void) +{ + return (int)sdram_hw_init(); +} +INIT_BOARD_EXPORT(rt_sdram_hw_init); diff --git a/bsp/stm32f7-disco/rtconfig.h b/bsp/stm32f7-disco/rtconfig.h index bd0aaed397..f599858171 100644 --- a/bsp/stm32f7-disco/rtconfig.h +++ b/bsp/stm32f7-disco/rtconfig.h @@ -227,4 +227,7 @@ /* enable SDRAM */ #define RT_USING_EXT_SDRAM +#define RT_USING_COMPONENTS_INIT +#define RT_USING_USER_MAIN + #endif diff --git a/bsp/stm32f7-disco/rtconfig.py b/bsp/stm32f7-disco/rtconfig.py index 91ef8db8b3..8fd7dd9094 100644 --- a/bsp/stm32f7-disco/rtconfig.py +++ b/bsp/stm32f7-disco/rtconfig.py @@ -45,7 +45,7 @@ if PLATFORM == 'gcc': STRIP = PREFIX + 'strip' DEVICE = ' -mcpu=cortex-m7 -mthumb -mfpu=fpv4-sp-d16 -mfloat-abi=softfp -ffunction-sections -fdata-sections' - CFLAGS = DEVICE + ' -g -Wall -DSTM32F756xx -DUSE_HAL_DRIVER -D__ASSEMBLY__ -D__FPU_USED' + CFLAGS = DEVICE + ' -g -Wall -DSTM32F756xx -DUSE_HAL_DRIVER -D__ASSEMBLY__ -D__FPU_USED -eentry' AFLAGS = ' -c' + DEVICE + ' -x assembler-with-cpp -Wa,-mimplicit-it=thumb ' LFLAGS = DEVICE + ' -lm -lgcc -lc' + ' -nostartfiles -Wl,--gc-sections,-Map=rtthread_stm32f7xx.map,-cref,-u,Reset_Handler -T rtthread-stm32f7xx.ld' From 3164e33de1dc7dd6e88dd99f8e7354f5dd5fb09e Mon Sep 17 00:00:00 2001 From: Bernard Xiong Date: Sat, 26 Sep 2015 11:37:11 +0800 Subject: [PATCH 02/36] Update and rename application.c to main.c --- .../applications/{application.c => main.c} | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) rename bsp/stm32f7-disco/applications/{application.c => main.c} (74%) diff --git a/bsp/stm32f7-disco/applications/application.c b/bsp/stm32f7-disco/applications/main.c similarity index 74% rename from bsp/stm32f7-disco/applications/application.c rename to bsp/stm32f7-disco/applications/main.c index 2bf527c90b..a0b14aee41 100644 --- a/bsp/stm32f7-disco/applications/application.c +++ b/bsp/stm32f7-disco/applications/main.c @@ -1,5 +1,5 @@ /* - * File : application.c + * File : main.c * This file is part of RT-Thread RTOS * COPYRIGHT (C) 2015, RT-Thread Development Team * @@ -25,20 +25,9 @@ #include -void rt_init_thread_entry(void *parameter) -{ - //rt_components_init(); -} - -//int rt_application_init() int main(void) { - rt_thread_t tid; - - tid = rt_thread_create("init", - rt_init_thread_entry, RT_NULL, - 2048, RT_THREAD_PRIORITY_MAX / 3, 20); - if (tid != RT_NULL) rt_thread_startup(tid); - + /* put user application code here */ return 0; } + From 53c85fb989a60ef015bbbe3a2541b9ff1020ef15 Mon Sep 17 00:00:00 2001 From: Arda Date: Sat, 26 Sep 2015 23:39:04 +0800 Subject: [PATCH 03/36] [libc][dlib] Add missing definition of mode_t For using pthread with IAR tool chain --- components/libc/dlib/sys/types.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/components/libc/dlib/sys/types.h b/components/libc/dlib/sys/types.h index b01d8283d4..3074bd69d0 100644 --- a/components/libc/dlib/sys/types.h +++ b/components/libc/dlib/sys/types.h @@ -9,4 +9,6 @@ typedef rt_int32_t key_t; /* Used for interprocess communication. */ typedef rt_int32_t pid_t; /* Used for process IDs and process group IDs. */ typedef signed long ssize_t; /* Used for a count of bytes or an error indication. */ +typedef int mode_t; + #endif From 5ed2d0ea3bf0fd5cfb83b22548d55db6754453be Mon Sep 17 00:00:00 2001 From: FlyM Date: Tue, 29 Sep 2015 06:53:44 +0800 Subject: [PATCH 04/36] [bsp]add stm32f4xx bsp rtc driver --- bsp/stm32f40x/drivers/stm32f4_rtc.c | 247 ++++++++++++++++++++++++++++ bsp/stm32f40x/drivers/stm32f4_rtc.h | 23 +++ 2 files changed, 270 insertions(+) create mode 100644 bsp/stm32f40x/drivers/stm32f4_rtc.c create mode 100644 bsp/stm32f40x/drivers/stm32f4_rtc.h diff --git a/bsp/stm32f40x/drivers/stm32f4_rtc.c b/bsp/stm32f40x/drivers/stm32f4_rtc.c new file mode 100644 index 0000000000..b949f4510b --- /dev/null +++ b/bsp/stm32f40x/drivers/stm32f4_rtc.c @@ -0,0 +1,247 @@ +/* + * File : stm32f4_rtc.c + * This file is stm32f4 rtc driver part of RT-Thread RTOS + * COPYRIGHT (C) 2009, RT-Thread Development Team + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rt-thread.org/license/LICENSE + * + * Change Logs: + * Date Author Notes + * 2015-09-29 FlyM the first version. + */ +#include +#include +#include +#include "stm32f4_rtc.h" + +static int get_week(int year, int month, int day) +{ + if (month==1||month==2) + { + year -=1; + month +=12; + } + return (day+1+2*month+3*(month+1)/5+year+(year/4)-year/100+year/400)%7; +} + +static struct rt_device rtc; +static rt_err_t rt_rtc_open(rt_device_t dev, rt_uint16_t oflag) +{ + if (dev->rx_indicate != RT_NULL) + { + /* Open Interrupt */ + } + + return RT_EOK; +} + +static rt_size_t rt_rtc_read(rt_device_t dev, rt_off_t pos, void* buffer, rt_size_t size) +{ + return 0; +} + +static rt_err_t rt_rtc_control(rt_device_t dev, rt_uint8_t cmd, void *args) +{ + rt_time_t *time; + RT_ASSERT(dev != RT_NULL); + + switch (cmd) + { + case RT_DEVICE_CTRL_RTC_GET_TIME: + { + struct tm ct; + RTC_TimeTypeDef t; + RTC_DateTypeDef d; + + rt_memset(&ct,0,sizeof(struct tm)); + time = (rt_time_t *)args; + /* read device */ + RTC_GetDate(RTC_Format_BIN,&d); + RTC_GetTime(RTC_Format_BIN,&t); + + ct.tm_year = d.RTC_Year + 100; + ct.tm_mon = d.RTC_Month - 1; + ct.tm_mday = d.RTC_Date; + ct.tm_wday = d.RTC_WeekDay; + + ct.tm_hour = t.RTC_Hours; + ct.tm_min = t.RTC_Minutes; + ct.tm_sec = t.RTC_Seconds; + + *time = mktime(&ct); + } + break; + + case RT_DEVICE_CTRL_RTC_SET_TIME: + { + struct tm *ct; + struct tm tm_new; + time_t *time; + RTC_TimeTypeDef RTC_TimeStructure; + RTC_InitTypeDef RTC_InitStructure; + RTC_DateTypeDef RTC_DateStructure; + + time = (time_t *)args; + /* lock scheduler. */ + rt_enter_critical(); + /* converts calendar time time into local time. */ + ct = localtime(time); + /* copy the statically located variable */ + rt_memcpy(&tm_new, ct, sizeof(struct tm)); + /* unlock scheduler. */ + rt_exit_critical(); + /* Enable the PWR clock */ + RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); + /* Allow access to RTC */ + PWR_BackupAccessCmd(ENABLE); + /* ck_spre(1Hz) = RTCCLK(LSI) /(uwAsynchPrediv + 1)*(uwSynchPrediv + 1)*/ + //uwSynchPrediv = 0xFF; + //uwAsynchPrediv = 0x7F; + /* Configure the RTC data register and RTC prescaler */ + RTC_InitStructure.RTC_AsynchPrediv = 0x7F; + RTC_InitStructure.RTC_SynchPrediv = 0xFF; + RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24; + RTC_Init(&RTC_InitStructure); + /* Set the date */ + RTC_DateStructure.RTC_Year = tm_new.tm_year - 100; + RTC_DateStructure.RTC_Month = tm_new.tm_mon + 1; + RTC_DateStructure.RTC_Date = tm_new.tm_mday; + RTC_DateStructure.RTC_WeekDay = get_week(tm_new.tm_year+1900,tm_new.tm_mon+1,tm_new.tm_mday); + RTC_SetDate(RTC_Format_BIN, &RTC_DateStructure); + /* Set the time*/ + if (tm_new.tm_hour > 11) + { + RTC_TimeStructure.RTC_H12 = RTC_H12_PM; + } + else + { + RTC_TimeStructure.RTC_H12 = RTC_H12_AM; + } + RTC_TimeStructure.RTC_Hours = tm_new.tm_hour; + RTC_TimeStructure.RTC_Minutes = tm_new.tm_min; + RTC_TimeStructure.RTC_Seconds = tm_new.tm_sec; + + RTC_SetTime(RTC_Format_BIN, &RTC_TimeStructure); + + /* Indicator for the RTC configuration */ + RTC_WriteBackupRegister(RTC_BKP_DR0, 0x32F2); + } + break; + } + + return RT_EOK; +} + +/******************************************************************************* +* Function Name : RTC_Configuration +* Description : Configures the RTC. +* Input : None +* Output : None +* Return : 0 reday,-1 error. +*******************************************************************************/ +int RTC_Configuration(void) +{ + /* Enable the PWR clock */ + RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); + + /* Allow access to RTC */ + PWR_BackupAccessCmd(ENABLE); + +#if defined (RTC_CLOCK_SOURCE_LSI) /* LSI used as RTC source clock*/ + /* The RTC Clock may varies due to LSI frequency dispersion */ + /* Enable the LSI OSC */ + RCC_LSICmd(ENABLE); + + /* Wait till LSI is ready */ + while(RCC_GetFlagStatus(RCC_FLAG_LSIRDY) == RESET) + { + } + + /* Select the RTC Clock Source */ + RCC_RTCCLKConfig(RCC_RTCCLKSource_LSI); + + /* ck_spre(1Hz) = RTCCLK(LSI) /(uwAsynchPrediv + 1)*(uwSynchPrediv + 1)*/ + //uwSynchPrediv = 0xFF; + //uwAsynchPrediv = 0x7F; + +#elif defined (RTC_CLOCK_SOURCE_LSE) /* LSE used as RTC source clock */ + /* Enable the LSE OSC */ + RCC_LSEConfig(RCC_LSE_ON); + + /* Wait till LSE is ready */ + while(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET) + { + } + /* Select the RTC Clock Source */ + RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE); + +#else +#error Please select the RTC Clock source inside the main.c file +#endif /* RTC_CLOCK_SOURCE_LSI */ + + /* Enable the RTC Clock */ + RCC_RTCCLKCmd(ENABLE); + + /* Wait for RTC APB registers synchronisation */ + RTC_WaitForSynchro(); + + return 0; +} + +void rt_hw_rtc_init(void) +{ + rtc.type = RT_Device_Class_RTC; + + if (RTC_ReadBackupRegister(RTC_BKP_DR0) != 0x32F2) + { + rt_kprintf("rtc is not configured\n"); + rt_kprintf("please configure with set_date and set_time\n"); + if ( RTC_Configuration() != 0) + { + rt_kprintf("rtc configure fail...\r\n"); + return ; + } + } + else + { + /* Wait for RTC registers synchronization */ + RTC_WaitForSynchro(); + } + + /* register rtc device */ + rtc.init = RT_NULL; + rtc.open = rt_rtc_open; + rtc.close = RT_NULL; + rtc.read = rt_rtc_read; + rtc.write = RT_NULL; + rtc.control = rt_rtc_control; + + /* no private */ + rtc.user_data = RT_NULL; + + rt_device_register(&rtc, "rtc", RT_DEVICE_FLAG_RDWR); + + return; +} + +#ifdef RT_USING_FINSH +#include "finsh.h" +void show_time(void) +{ + RTC_TimeTypeDef t; + RTC_DateTypeDef d; + /* Get the current Date */ + RTC_GetDate(RTC_Format_BIN,&d); + /* Get the current Time */ + RTC_GetTime(RTC_Format_BIN, &t); + /* Display time Format : hh:mm:ss */ + rt_kprintf("Now Time = 20%02d %02d %02d[%02d]-%0.2d:%0.2d:%0.2d \r\n", \ + d.RTC_Year,d.RTC_Month,d.RTC_Date,d.RTC_WeekDay,t.RTC_Hours, t.RTC_Minutes, t.RTC_Seconds); +} + +FINSH_FUNCTION_EXPORT(show_time, show current time.) +#endif + + diff --git a/bsp/stm32f40x/drivers/stm32f4_rtc.h b/bsp/stm32f40x/drivers/stm32f4_rtc.h new file mode 100644 index 0000000000..42fa4ebed7 --- /dev/null +++ b/bsp/stm32f40x/drivers/stm32f4_rtc.h @@ -0,0 +1,23 @@ +/* + * File : stm32f4_rtc.h + * This file is stm32f4 rtc driver part of RT-Thread RTOS + * COPYRIGHT (C) 2009, RT-Thread Development Team + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rt-thread.org/license/LICENSE + * + * Change Logs: + * Date Author Notes + * 2015-09-29 FlyM the first version + */ + +#ifndef __STM32F4_RTC_H__ +#define __STM32F4_RTC_H__ + +#define RTC_CLOCK_SOURCE_LSE + +void rt_hw_rtc_init(void); + +#endif + From a8828eee89f9311d1dad5a3d0f1cc6822957b979 Mon Sep 17 00:00:00 2001 From: ardafu Date: Tue, 29 Sep 2015 11:53:23 +0800 Subject: [PATCH 05/36] [bsp][stm32f746-disco] Add support of IAR tool chain 1. Add IAR project template and link scripts. Add missing CXX configuration for IAR tool chain in rtconfg.py. 2. Modify all link scripts, Using ITCM interface.(Changing flash start address from 0x0800_0000 to 0x0020_0000). --- bsp/stm32f7-disco/rtconfig.py | 16 +- bsp/stm32f7-disco/rtthread-stm32f7xx.icf | 33 + bsp/stm32f7-disco/rtthread-stm32f7xx.ld | 2 +- bsp/stm32f7-disco/rtthread-stm32f7xx.sct | 4 +- bsp/stm32f7-disco/template.ewp | 1919 ++++++++++++++++++++++ 5 files changed, 1965 insertions(+), 9 deletions(-) create mode 100644 bsp/stm32f7-disco/rtthread-stm32f7xx.icf create mode 100644 bsp/stm32f7-disco/template.ewp diff --git a/bsp/stm32f7-disco/rtconfig.py b/bsp/stm32f7-disco/rtconfig.py index 8fd7dd9094..0741e1931c 100644 --- a/bsp/stm32f7-disco/rtconfig.py +++ b/bsp/stm32f7-disco/rtconfig.py @@ -19,10 +19,8 @@ elif CROSS_TOOL == 'keil': PLATFORM = 'armcc' EXEC_PATH = r'C:/Keil_v5' elif CROSS_TOOL == 'iar': - print '================ERROR============================' - print 'Not support iar yet!' - print '=================================================' - exit(0) + PLATFORM = 'iar' + IAR_PATH = 'C:/Program Files (x86)/IAR Systems/Embedded Workbench 7.2' if os.getenv('RTT_EXEC_PATH'): EXEC_PATH = os.getenv('RTT_EXEC_PATH') @@ -99,6 +97,7 @@ elif PLATFORM == 'armcc': elif PLATFORM == 'iar': # toolchains CC = 'iccarm' + CXX = 'iccarm' AS = 'iasmarm' AR = 'iarchive' LINK = 'ilinkarm' @@ -123,18 +122,23 @@ elif PLATFORM == 'iar': CFLAGS += ' --dlib_config "' + IAR_PATH + '/arm/INC/c/DLib_Config_Normal.h"' CFLAGS += ' -Ol' CFLAGS += ' --use_c++_inline' - + CFLAGS += ' --silent' + AFLAGS = '' AFLAGS += ' -s+' AFLAGS += ' -w+' AFLAGS += ' -r' AFLAGS += ' --cpu Cortex-M7' AFLAGS += ' --fpu None' - + AFLAGS += ' -S' + LFLAGS = ' --config rtthread-stm32f7xx.icf' LFLAGS += ' --redirect _Printf=_PrintfTiny' LFLAGS += ' --redirect _Scanf=_ScanfSmall' LFLAGS += ' --entry __iar_program_start' + LFLAGS += ' --silent' + + CXXFLAGS = CFLAGS EXEC_PATH = IAR_PATH + '/arm/bin/' POST_ACTION = '' diff --git a/bsp/stm32f7-disco/rtthread-stm32f7xx.icf b/bsp/stm32f7-disco/rtthread-stm32f7xx.icf new file mode 100644 index 0000000000..73cbc1c601 --- /dev/null +++ b/bsp/stm32f7-disco/rtthread-stm32f7xx.icf @@ -0,0 +1,33 @@ +/*###ICF### Section handled by ICF editor, don't touch! ****/ +/*-Editor annotation file-*/ +/* IcfEditorFile="$TOOLKIT_DIR$\config\ide\IcfEditor\cortex_v1_0.xml" */ +/*-Specials-*/ +define symbol __ICFEDIT_intvec_start__ = 0x00200000; +/*-Memory Regions-*/ +define symbol __ICFEDIT_region_ROM_start__ = 0x00200000; +define symbol __ICFEDIT_region_ROM_end__ = 0x002FFFFF; +define symbol __ICFEDIT_region_RAM_start__ = 0x20010000; +define symbol __ICFEDIT_region_RAM_end__ = 0x2003FFFF; +/*-Sizes-*/ +define symbol __ICFEDIT_size_cstack__ = 0x400; +define symbol __ICFEDIT_size_heap__ = 0x200; +/**** End of ICF editor section. ###ICF###*/ + + +define memory mem with size = 4G; +define region ROM_region = mem:[from __ICFEDIT_region_ROM_start__ to __ICFEDIT_region_ROM_end__]; +define region RAM_region = mem:[from __ICFEDIT_region_RAM_start__ to __ICFEDIT_region_RAM_end__]; + +define block CSTACK with alignment = 8, size = __ICFEDIT_size_cstack__ { }; +define block HEAP with alignment = 8, size = __ICFEDIT_size_heap__ { }; + +initialize by copy { readwrite }; +do not initialize { section .noinit }; + +place at address mem:__ICFEDIT_intvec_start__ { readonly section .intvec }; + +place in ROM_region { readonly }; +place in RAM_region { readwrite, block CSTACK, block HEAP }; +keep { section FSymTab }; +keep { section VSymTab }; +keep { section .rti_fn* }; diff --git a/bsp/stm32f7-disco/rtthread-stm32f7xx.ld b/bsp/stm32f7-disco/rtthread-stm32f7xx.ld index a841a10714..16f747b83a 100644 --- a/bsp/stm32f7-disco/rtthread-stm32f7xx.ld +++ b/bsp/stm32f7-disco/rtthread-stm32f7xx.ld @@ -6,7 +6,7 @@ /* Program Entry, set to mark it as "used" and avoid gc */ MEMORY { - CODE (rx) : ORIGIN = 0x08000000, LENGTH = 1024k /* 1024KB flash */ + CODE (rx) : ORIGIN = 0x00200000, LENGTH = 1024k /* 1024KB flash */ DATA (rw) : ORIGIN = 0x20010000, LENGTH = 256k /* 256K sram */ } ENTRY(Reset_Handler) diff --git a/bsp/stm32f7-disco/rtthread-stm32f7xx.sct b/bsp/stm32f7-disco/rtthread-stm32f7xx.sct index a084b410ca..f9e5ff5279 100644 --- a/bsp/stm32f7-disco/rtthread-stm32f7xx.sct +++ b/bsp/stm32f7-disco/rtthread-stm32f7xx.sct @@ -2,8 +2,8 @@ ; *** Scatter-Loading Description File generated by uVision *** ; ************************************************************* -LR_IROM1 0x08000000 0x00100000 { ; load region size_region - ER_IROM1 0x08000000 0x00100000 { ; load address = execution address +LR_IROM1 0x00200000 0x00100000 { ; load region size_region + ER_IROM1 0x00200000 0x00100000 { ; load address = execution address *.o (RESET, +First) *(InRoot$$Sections) .ANY (+RO) diff --git a/bsp/stm32f7-disco/template.ewp b/bsp/stm32f7-disco/template.ewp new file mode 100644 index 0000000000..5f300148cc --- /dev/null +++ b/bsp/stm32f7-disco/template.ewp @@ -0,0 +1,1919 @@ + + + + 2 + + Debug + + ARM + + 1 + + General + 3 + + 24 + 1 + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ICCARM + 2 + + 31 + 1 + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + AARM + 2 + + 9 + 1 + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + OBJCOPY + 0 + + 1 + 1 + 1 + + + + + + + + + CUSTOM + 3 + + + + 0 + + + + BICOMP + 0 + + + + BUILDACTION + 1 + + + + + + + ILINK + 0 + + 16 + 1 + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + IARCHIVE + 0 + + 0 + 1 + 1 + + + + + + + BILINK + 0 + + + + + Release + + ARM + + 0 + + General + 3 + + 24 + 1 + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ICCARM + 2 + + 31 + 1 + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + AARM + 2 + + 9 + 1 + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + OBJCOPY + 0 + + 1 + 1 + 0 + + + + + + + + + CUSTOM + 3 + + + + 0 + + + + BICOMP + 0 + + + + BUILDACTION + 1 + + + + + + + ILINK + 0 + + 16 + 1 + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + IARCHIVE + 0 + + 0 + 1 + 0 + + + + + + + BILINK + 0 + + + + + + From 7e45f059dce0a7751beef09e5ac122a83d731c5b Mon Sep 17 00:00:00 2001 From: Bernard Xiong Date: Wed, 30 Sep 2015 16:26:40 +0800 Subject: [PATCH 06/36] [BSP] Update simualtor bsp for Win32/MSVC --- bsp/simulator/.gitignore | 47 ++ bsp/simulator/SConstruct | 4 +- bsp/simulator/applications/application.c | 163 +------ bsp/simulator/applications/init.c | 170 +++++++ bsp/simulator/applications/init.h | 31 ++ bsp/simulator/applications/platform.c | 14 +- bsp/simulator/drivers/board.c | 13 +- bsp/simulator/drivers/module_win32.c | 184 +++++++- bsp/simulator/drivers/serial.c | 218 --------- bsp/simulator/drivers/serial.h | 32 -- .../drivers/{usart_sim.c => uart_console.c} | 179 ++++++-- bsp/simulator/drivers/uart_console.h | 6 + bsp/simulator/rtconfig.h | 416 +++++++++--------- bsp/simulator/rtconfig.py | 4 +- 14 files changed, 799 insertions(+), 682 deletions(-) create mode 100644 bsp/simulator/.gitignore create mode 100644 bsp/simulator/applications/init.c create mode 100644 bsp/simulator/applications/init.h delete mode 100755 bsp/simulator/drivers/serial.c delete mode 100644 bsp/simulator/drivers/serial.h rename bsp/simulator/drivers/{usart_sim.c => uart_console.c} (52%) mode change 100755 => 100644 create mode 100644 bsp/simulator/drivers/uart_console.h diff --git a/bsp/simulator/.gitignore b/bsp/simulator/.gitignore new file mode 100644 index 0000000000..fef6f4cbc8 --- /dev/null +++ b/bsp/simulator/.gitignore @@ -0,0 +1,47 @@ +# Object files +*.o +*.ko +*.mo +*.d +*.crf +*.lst + +# Libraries +*.lib +*.a + +# Shared objects (inc. Windows DLLs) +*.dll +*.so +*.so.* +*.dylib +*.pyc + +# Executables +*.exe +*.out +*.app +*.elf +*.axf +*.bin +*.hex + +# Intermediate file +*.bak +*.swp +*.map +*.dblite +*.dep +*.lnp +*.uvgui.* +*.build_log.* +build + +Debug +_UpgradeReport_Files +*.ncb +*.suo +*.exp +*.XML +*.user +*.def diff --git a/bsp/simulator/SConstruct b/bsp/simulator/SConstruct index 760002d80d..4283082d04 100755 --- a/bsp/simulator/SConstruct +++ b/bsp/simulator/SConstruct @@ -88,7 +88,7 @@ def ObjRemove(objs, remove): # build program -shared if GetDepend('RT_USING_MODULE'): # Remove module.c in $RTT_ROOT/src - ObjRemove(objs, ['module.obj', 'module.o']) + ObjRemove(objs, ['module.obj', 'module.o', 'module.c']) AddOption('--def', dest='def', @@ -99,7 +99,7 @@ if GetDepend('RT_USING_MODULE'): if rtconfig.PLATFORM == 'mingw': env['LINKFLAGS'] = rtconfig.DEFFILE_LFLAGS else: - rtconfig.POST_ACTION = 'createdef.py $TARGET rtthread.def' + rtconfig.POST_ACTION = 'python createdef.py $TARGET rtthread.def' program = env.Program(TARGET, objs) else: diff --git a/bsp/simulator/applications/application.c b/bsp/simulator/applications/application.c index a01e8d91b7..df34aa87c9 100755 --- a/bsp/simulator/applications/application.c +++ b/bsp/simulator/applications/application.c @@ -1,11 +1,21 @@ /* * File : application.c * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2006, RT-Thread Development Team + * COPYRIGHT (C) 2006 - 2015, RT-Thread Development Team * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rt-thread.org/license/LICENSE + * 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 @@ -16,154 +26,15 @@ #include #include -#ifdef RT_USING_FINSH -#include -#include -#endif - -#ifdef RT_USING_LWIP -#include -#include -extern void lwip_system_init(void); -#endif - #ifdef RT_USING_DFS -#include #include -#ifdef RT_USING_DFS_ELMFAT -#include -#endif -#if defined(RT_USING_LWIP) && defined(RT_USING_DFS_NFS) -#include -#endif -#ifdef RT_USING_DFS_ROMFS -#include -#endif -#ifdef RT_USING_DFS_DEVFS -#include -#endif -#ifdef RT_USING_DFS_UFFS -#include -#endif -#ifdef RT_USING_DFS_JFFS2 -#include -#endif -#ifdef RT_USING_DFS_YAFFS2 -#include -#endif -#ifdef RT_USING_DFS_ROMFS -#include -#endif #endif -#ifdef RT_USING_NEWLIB -#include -#endif -#ifdef RT_USING_PTHREADS -#include -#endif - -#ifdef RT_USING_MODULE -#include -#endif - -#ifdef RT_USING_RTGUI -#include -#endif +#include "init.h" void rt_init_thread_entry(void *parameter) { -#ifdef RT_USING_LWIP -#ifdef RT_USING_TAPNETIF - tap_netif_hw_init(); -#else - pcap_netif_hw_init(); -#endif -#endif - - rt_platform_init(); - -#ifdef RT_USING_MODULE - rt_system_module_init(); -#endif - -#ifdef RT_USING_FINSH - /* initialize finsh */ - finsh_system_init(); - finsh_set_device(RT_CONSOLE_DEVICE_NAME); -#endif - -#ifdef RT_USING_LWIP - /* initialize lwip stack */ - /* register ethernetif device */ - eth_system_device_init(); - - /* initialize lwip system */ - lwip_system_init(); - rt_kprintf("TCP/IP initialized!\n"); -#endif - -#ifdef RT_USING_DFS - /* initialize the device file system */ - dfs_init(); - -#ifdef RT_USING_DFS_ELMFAT - /* initialize the elm chan FatFS file system*/ - elm_init(); -#endif - -#if defined(RT_USING_DFS_NFS) && defined(RT_USING_LWIP) - /* initialize NFSv3 client file system */ - nfs_init(); -#endif - -#ifdef RT_USING_DFS_YAFFS2 - dfs_yaffs2_init(); -#endif - -#ifdef RT_USING_DFS_UFFS - dfs_uffs_init(); -#endif - -#ifdef RT_USING_DFS_JFFS2 - dfs_jffs2_init(); -#endif - -#ifdef RT_USING_DFS_ROMFS - dfs_romfs_init(); -#endif - -#ifdef RT_USING_DFS_RAMFS - dfs_ramfs_init(); -#endif - -#ifdef RT_USING_DFS_DEVFS - devfs_init(); -#endif -#endif /* end of RT_USING_DFS */ - -#ifdef RT_USING_NEWLIB - libc_system_init(RT_CONSOLE_DEVICE_NAME); -#else - /* the pthread system initialization will be initiallized in libc */ -#ifdef RT_USING_PTHREADS - pthread_system_init(); -#endif -#endif - -#ifdef RT_USING_RTGUI - rtgui_system_server_init(); -#endif - -#ifdef RT_USING_USB_HOST - rt_usb_host_init(); -#endif - -#ifdef RT_USING_RTGUI - /* start sdl thread to simulate an LCD. SDL may depend on DFS and should be - * called after rt_components_init. */ - rt_hw_sdl_start(); -#endif /* RT_USING_RTGUI */ + components_init(); /* File system Initialization */ #ifdef RT_USING_DFS @@ -228,5 +99,3 @@ int rt_application_init() return 0; } - -/*@}*/ \ No newline at end of file diff --git a/bsp/simulator/applications/init.c b/bsp/simulator/applications/init.c new file mode 100644 index 0000000000..b78deefe71 --- /dev/null +++ b/bsp/simulator/applications/init.c @@ -0,0 +1,170 @@ +/* + * File : init.h + * This file is part of RT-Thread RTOS + * COPYRIGHT (C) 2006 - 2015, 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 + * 2015-09-30 Bernard the first version + */ + +#include + +#include "init.h" + +#ifdef RT_USING_FINSH +#include +#include +#endif + +#ifdef RT_USING_LWIP +#include +#include +extern void lwip_system_init(void); +#endif + +#ifdef RT_USING_DFS +#include +#include +#ifdef RT_USING_DFS_ELMFAT +#include +#endif +#if defined(RT_USING_LWIP) && defined(RT_USING_DFS_NFS) +#include +#endif +#ifdef RT_USING_DFS_ROMFS +#include +#endif +#ifdef RT_USING_DFS_DEVFS +#include +#endif +#ifdef RT_USING_DFS_UFFS +#include +#endif +#ifdef RT_USING_DFS_JFFS2 +#include +#endif +#ifdef RT_USING_DFS_YAFFS2 +#include +#endif +#ifdef RT_USING_DFS_ROMFS +#include +#endif +#endif + +#ifdef RT_USING_NEWLIB +#include +#endif +#ifdef RT_USING_PTHREADS +#include +#endif + +#ifdef RT_USING_MODULE +#include +#endif + +#ifdef RT_USING_RTGUI +#include +#endif + +/* components initialization for simulator */ +void components_init(void) +{ + platform_init(); + +#ifdef RT_USING_MODULE + rt_system_module_init(); +#endif + +#ifdef RT_USING_FINSH + /* initialize finsh */ + finsh_system_init(); + finsh_set_device(RT_CONSOLE_DEVICE_NAME); +#endif + +#ifdef RT_USING_LWIP + /* initialize lwip stack */ + /* register ethernetif device */ + eth_system_device_init(); + + /* initialize lwip system */ + lwip_system_init(); + rt_kprintf("TCP/IP initialized!\n"); +#endif + +#ifdef RT_USING_DFS + /* initialize the device file system */ + dfs_init(); + +#ifdef RT_USING_DFS_ELMFAT + /* initialize the elm chan FatFS file system*/ + elm_init(); +#endif + +#if defined(RT_USING_DFS_NFS) && defined(RT_USING_LWIP) + /* initialize NFSv3 client file system */ + nfs_init(); +#endif + +#ifdef RT_USING_DFS_YAFFS2 + dfs_yaffs2_init(); +#endif + +#ifdef RT_USING_DFS_UFFS + dfs_uffs_init(); +#endif + +#ifdef RT_USING_DFS_JFFS2 + dfs_jffs2_init(); +#endif + +#ifdef RT_USING_DFS_ROMFS + dfs_romfs_init(); +#endif + +#ifdef RT_USING_DFS_RAMFS + dfs_ramfs_init(); +#endif + +#ifdef RT_USING_DFS_DEVFS + devfs_init(); +#endif +#endif /* end of RT_USING_DFS */ + +#ifdef RT_USING_NEWLIB + libc_system_init(RT_CONSOLE_DEVICE_NAME); +#else + /* the pthread system initialization will be initiallized in libc */ +#ifdef RT_USING_PTHREADS + pthread_system_init(); +#endif +#endif + +#ifdef RT_USING_RTGUI + rtgui_system_server_init(); +#endif + +#ifdef RT_USING_USB_HOST + rt_usb_host_init(); +#endif + +#ifdef RT_USING_RTGUI + /* start sdl thread to simulate an LCD. SDL may depend on DFS and should be + * called after rt_components_init. */ + rt_hw_sdl_start(); +#endif /* RT_USING_RTGUI */ +} diff --git a/bsp/simulator/applications/init.h b/bsp/simulator/applications/init.h new file mode 100644 index 0000000000..ae8c838e1e --- /dev/null +++ b/bsp/simulator/applications/init.h @@ -0,0 +1,31 @@ +/* + * File : init.h + * This file is part of RT-Thread RTOS + * COPYRIGHT (C) 2006 - 2015, 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 + * 2015-09-30 Bernard the first version + */ + +#ifndef INIT_H__ +#define INIT_H__ + +void platform_init(void); +void components_init(void); + +#endif diff --git a/bsp/simulator/applications/platform.c b/bsp/simulator/applications/platform.c index fbc1003d2a..229c507c9a 100644 --- a/bsp/simulator/applications/platform.c +++ b/bsp/simulator/applications/platform.c @@ -1,8 +1,16 @@ #include #include "board.h" -void rt_platform_init(void) +void platform_init(void) { +#ifdef RT_USING_LWIP +#ifdef RT_USING_TAPNETIF + tap_netif_hw_init(); +#else + pcap_netif_hw_init(); +#endif +#endif + #ifdef RT_USING_DFS /* initialize sd card */ rt_hw_sdcard_init(); @@ -16,9 +24,5 @@ void rt_platform_init(void) #endif #endif /* RT_USING_DFS */ - -#ifdef _WIN32 - rt_thread_idle_sethook(rt_hw_win32_low_cpu); -#endif } diff --git a/bsp/simulator/drivers/board.c b/bsp/simulator/drivers/board.c index dcb8d9a049..4e498395c9 100755 --- a/bsp/simulator/drivers/board.c +++ b/bsp/simulator/drivers/board.c @@ -14,9 +14,12 @@ #include #include -#include "board.h" + #include +#include "board.h" +#include "uart_console.h" + /** * @addtogroup simulator on win32 */ @@ -93,9 +96,11 @@ void rt_hw_board_init() /* init system memory */ heap = rt_hw_sram_init(); -//#if defined(RT_USING_USART) - rt_hw_usart_init(); -//#endif + uart_console_init(); + +#ifdef _WIN32 + rt_thread_idle_sethook(rt_hw_win32_low_cpu); +#endif #if defined(RT_USING_CONSOLE) rt_console_set_device(RT_CONSOLE_DEVICE_NAME); diff --git a/bsp/simulator/drivers/module_win32.c b/bsp/simulator/drivers/module_win32.c index 3f0a273746..95cb301037 100644 --- a/bsp/simulator/drivers/module_win32.c +++ b/bsp/simulator/drivers/module_win32.c @@ -130,6 +130,7 @@ void rt_module_unload_sethook(void (*hook)(rt_module_t module)) */ int rt_system_module_init(void) { + return 0; } /** @@ -148,6 +149,7 @@ rt_module_t rt_module_self(void) /* return current module */ return (rt_module_t)tid->module_id; } +RTM_EXPORT(rt_module_self); /** * This function will find the specified module. @@ -191,6 +193,7 @@ rt_module_t rt_module_find(const char *name) /* not found */ return RT_NULL; } +RTM_EXPORT(rt_module_find); #ifdef RT_USING_DFS #include @@ -237,10 +240,10 @@ rt_module_t rt_module_open(const char *path) struct dfs_filesystem *fs; appentry_t fptr; HINSTANCE hinstlib; - int len; - char * winpath; - rt_module_t module; - char * name; + rt_module_t module; + + char * winpath = RT_NULL; + char * name = RT_NULL; RT_DEBUG_NOT_IN_INTERRUPT; @@ -256,10 +259,10 @@ rt_module_t rt_module_open(const char *path) } /* change path */ - len = strlen(path+1); + // len = strlen(path+1); if ((winpath = dfs_win32_dirdup((char *)path)) == RT_NULL) { - rt_kprintf("out of memory, exit", path); + rt_kprintf("out of memory, exit"); return RT_NULL; } @@ -282,10 +285,8 @@ rt_module_t rt_module_open(const char *path) name = _module_name(path); /* allocate module */ - module = (struct rt_module *)rt_object_allocate(RT_Object_Class_Module, - name); - if (!module) - return RT_NULL; + module = (struct rt_module *)rt_object_allocate(RT_Object_Class_Module, name); + if (!module) return RT_NULL; module->nref = 0; module->module_entry = fptr; @@ -298,31 +299,21 @@ rt_module_t rt_module_open(const char *path) if (module->module_entry != 0) { - rt_uint32_t *stack_size; - rt_uint8_t *priority; - #ifdef RT_USING_SLAB /* init module memory allocator */ module->mem_list = RT_NULL; /* create page array */ - module->page_array = + module->page_array = (void *)rt_malloc(PAGE_COUNT_MAX * sizeof(struct rt_page_info)); module->page_cnt = 0; #endif - /* get the main thread stack size */ - module->stack_size = 2048; - module->thread_priority = RT_THREAD_PRIORITY_MAX - 2; - /* create module thread */ module->module_thread = rt_thread_create(name, - (void(*)(void *))module->module_entry, - RT_NULL, - module->stack_size, - module->thread_priority, - 10); + (void(*)(void *))module->module_entry, RT_NULL, + 2048, RT_THREAD_PRIORITY_MAX - 2, 10); RT_DEBUG_LOG(RT_DEBUG_MODULE, ("thread entry 0x%x\n", module->module_entry)); @@ -354,12 +345,157 @@ rt_module_t rt_module_open(const char *path) #if defined(RT_USING_FINSH) #include - FINSH_FUNCTION_EXPORT_ALIAS(rt_module_open, exec, exec module from a file); #endif #endif +/** + * This function will do a excutable program with main function and parameters. + * + * @param path the full path of application module + * @param cmd_line the command line of program + * @param size the size of command line of program + * + * @return the module object + */ +rt_module_t rt_module_exec_cmd(const char *path, const char* cmd_line, int line_size) +{ + struct dfs_filesystem *fs; + appentry_t fptr; + HINSTANCE hinstlib; + rt_module_t module; + + char * winpath = RT_NULL; + char * name = RT_NULL; + char *full_path = RT_NULL; + + RT_DEBUG_NOT_IN_INTERRUPT; + + /* check parameters */ + RT_ASSERT(path != RT_NULL); + + if (*path != '/') + { + full_path = dfs_normalize_path(RT_NULL, path); + } + else + { + full_path = (const char*)path; + } + + /* app module should only in DFS_WIN32 */ + fs = dfs_filesystem_lookup(full_path); + if ((fs == RT_NULL) || (strcmp(fs->ops->name,"wdir") != 0)) + { + rt_kprintf("invalid path: %s\n", path); + goto __exit; + } + + /* change path */ + // len = strlen(full_path + 1); + if ((winpath = dfs_win32_dirdup((char *)full_path)) == RT_NULL) + { + rt_kprintf("out of memory, exit", path); + goto __exit; + } + + hinstlib = LoadLibrary(winpath); + if (hinstlib == NULL) + { + rt_kprintf("error: unable to open %s\n", winpath); + goto __exit; + } + + fptr = (appentry_t)GetProcAddress(hinstlib, "main"); + if (fptr == NULL) + { + rt_kprintf("error: unable to find function in %s\n", winpath); + FreeLibrary(hinstlib); + goto __exit; + } + + /* release winpath */ + rt_free(winpath); + + /* get the name of the module */ + name = _module_name(path); + + /* allocate module */ + module = (struct rt_module *)rt_object_allocate(RT_Object_Class_Module, name); + if (!module) + { + goto __exit; + } + + module->nref = 0; + module->module_entry = fptr; + + /* init module object container */ + rt_module_init_object_container(module); + + /* increase module reference count */ + module->nref ++; + + if (module->module_entry != 0) + { + /* set module argument */ + module->module_cmd_line = (rt_uint8_t*)rt_malloc(line_size + 1); + rt_memcpy(module->module_cmd_line, cmd_line, line_size); + module->module_cmd_line[line_size] = '\0'; + module->module_cmd_size = line_size; + +#ifdef RT_USING_SLAB + /* init module memory allocator */ + module->mem_list = RT_NULL; + + /* create page array */ + module->page_array = + (void *)rt_malloc(PAGE_COUNT_MAX * sizeof(struct rt_page_info)); + module->page_cnt = 0; +#endif + + /* create module thread */ + module->module_thread = + rt_thread_create(name, + (void(*)(void *))module->module_entry, RT_NULL, + 2048, RT_THREAD_PRIORITY_MAX - 2, 10); + + RT_DEBUG_LOG(RT_DEBUG_MODULE, ("thread entry 0x%x\n", + module->module_entry)); + + /* set module id */ + module->module_thread->module_id = (void *)module; + module->parent.flag = RT_MODULE_FLAG_WITHENTRY; + + /* startup module thread */ + rt_thread_startup(module->module_thread); + } + else + { + /* without entry point */ + module->parent.flag |= RT_MODULE_FLAG_WITHOUTENTRY; + } + +#ifdef RT_USING_HOOK + if (rt_module_load_hook != RT_NULL) + { + rt_module_load_hook(module); + } +#endif + + rt_free(name); + return module; + +__exit: + if (full_path != path) rt_free(full_path); + if (name != RT_NULL) rt_free(full_path); + if (winpath != RT_NULL)rt_free(winpath); + + return RT_NULL; + /* FreeLibrary(hinstlib); */ +} + rt_err_t rt_module_destroy(rt_module_t module) { return 0; diff --git a/bsp/simulator/drivers/serial.c b/bsp/simulator/drivers/serial.c deleted file mode 100755 index 72cbad3baf..0000000000 --- a/bsp/simulator/drivers/serial.c +++ /dev/null @@ -1,218 +0,0 @@ -/* - * File : serial.c - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2013 RT-Thread Develop Team - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rt-thread.org/license/LICENSE - * - * Change Logs: - * Date Author Notes - * 2009-02-05 Bernard first version - * 2009-10-25 Bernard fix rt_serial_read bug when there is no data - * in the buffer. - * 2010-03-29 Bernard cleanup code. - * 2013-02-7 prife rewrite for simulator - */ - -#include - -#include "serial.h" -#include - -#if 0 -static FILE *fp = RT_NULL; -#endif - -/*@{*/ -int seial_save_byte(unsigned char ch, struct serial_device * serial) -{ - /* save on rx buffer */ - rt_base_t level; - struct rt_device * dev = RT_DEVICE(serial); - /* disable interrupt */ - //暂时关闭中断,因为要操作uart数据结构 - level = rt_hw_interrupt_disable(); - - /* save character */ - serial->serial_rx.rx_buffer[serial->serial_rx.save_index] = ch; - serial->serial_rx.save_index ++; - //下面的代码检查save_index是否已经到到缓冲区尾部,如果是则回转到头部,称为一个环形缓冲区 - if (serial->serial_rx.save_index >= SERIAL_RX_BUFFER_SIZE) - serial->serial_rx.save_index = 0; - - //这种情况表示反转后的save_index追上了read_index,则增大read_index,丢弃一个旧的数据 - /* if the next position is read index, discard this 'read char' */ - if (serial->serial_rx.save_index == serial->serial_rx.read_index) - { - serial->serial_rx.read_index ++; - if (serial->serial_rx.read_index >= SERIAL_RX_BUFFER_SIZE) - serial->serial_rx.read_index = 0; - } - - /* enable interrupt */ - //uart数据结构已经操作完成,重新使能中断 - rt_hw_interrupt_enable(level); - - /* invoke callback */ - if (dev->rx_indicate != RT_NULL) - { - rt_size_t rx_length; - - /* get rx length */ - rx_length = serial->serial_rx.read_index > serial->serial_rx.save_index ? - SERIAL_RX_BUFFER_SIZE - serial->serial_rx.read_index + serial->serial_rx.save_index : - serial->serial_rx.save_index - serial->serial_rx.read_index; - - dev->rx_indicate(dev, rx_length); - } - return 0; -} - -/* RT-Thread Device Interface */ -/** - * This function initializes serial - */ -static rt_err_t rt_serial_init(rt_device_t dev) -{ - struct serial_device * serial = SERIAL_DEVICE(dev); - if (!(dev->flag & RT_DEVICE_FLAG_ACTIVATED)) - { - if (dev->flag & RT_DEVICE_FLAG_INT_RX) - { - rt_memset(serial->serial_rx.rx_buffer, 0, - sizeof(serial->serial_rx.rx_buffer)); - serial->serial_rx.read_index = 0; - serial->serial_rx.save_index = 0; - } - - dev->flag |= RT_DEVICE_FLAG_ACTIVATED; - } - return RT_EOK; -} - -static rt_err_t rt_serial_open(rt_device_t dev, rt_uint16_t oflag) -{ - return RT_EOK; -} - -static rt_err_t rt_serial_close(rt_device_t dev) -{ - return RT_EOK; -} -static rt_size_t rt_serial_read(rt_device_t dev, rt_off_t pos, void *buffer, rt_size_t size) -{ - rt_uint8_t *ptr; - rt_err_t err_code; - struct serial_device * serial = SERIAL_DEVICE(dev); - - ptr = buffer; - err_code = RT_EOK; - - if (dev->flag & RT_DEVICE_FLAG_INT_RX) - { - /* interrupt mode Rx */ - while (size) - { - rt_base_t level; - - /* disable interrupt */ - level = rt_hw_interrupt_disable(); - - if (serial->serial_rx.read_index != serial->serial_rx.save_index) - { - /* read a character */ - *ptr++ = serial->serial_rx.rx_buffer[serial->serial_rx.read_index]; - size--; - - /* move to next position */ - serial->serial_rx.read_index ++; - if (serial->serial_rx.read_index >= SERIAL_RX_BUFFER_SIZE) - serial->serial_rx.read_index = 0; - } - else - { - /* set error code */ - err_code = -RT_EEMPTY; - - /* enable interrupt */ - rt_hw_interrupt_enable(level); - break; - } - - /* enable interrupt */ - rt_hw_interrupt_enable(level); - } - } - - - /* set error code */ - rt_set_errno(err_code); - return (rt_uint32_t)ptr - (rt_uint32_t)buffer; -} - -static rt_size_t rt_serial_write(rt_device_t dev, rt_off_t pos, const void *buffer, rt_size_t size) -{ - int level; -#if 0 - if (fp == NULL) - fp = fopen("log.txt", "wb+"); - - if (fp != NULL) - fwrite(buffer, size, 1, fp); -#endif - - level = rt_hw_interrupt_disable(); - fwrite(buffer, size, 1, stdout); - fflush(stdout); - rt_hw_interrupt_enable(level); - return size; -} - -static rt_err_t rt_serial_control(rt_device_t dev, rt_uint8_t cmd, void *args) -{ - RT_ASSERT(dev != RT_NULL); - - switch (cmd) - { - case RT_DEVICE_CTRL_SUSPEND: - /* suspend device */ - dev->flag |= RT_DEVICE_FLAG_SUSPENDED; - break; - - case RT_DEVICE_CTRL_RESUME: - /* resume device */ - dev->flag &= ~RT_DEVICE_FLAG_SUSPENDED; - break; - } - - return RT_EOK; -} - -/* - * serial register - */ -rt_err_t rt_hw_serial_register(rt_device_t device, const char *name, rt_uint32_t flag) -{ - RT_ASSERT(device != RT_NULL); - device->type = RT_Device_Class_Char; - device->rx_indicate = RT_NULL; - device->tx_complete = RT_NULL; - device->init = rt_serial_init; - device->open = rt_serial_open; - device->close = rt_serial_close; - device->read = rt_serial_read; - device->write = rt_serial_write; - device->control = rt_serial_control; - device->user_data = RT_NULL; - - /* register a character device */ - return rt_device_register(device, name, (rt_uint16_t)(RT_DEVICE_FLAG_RDWR | flag)); -} - -rt_err_t rt_hw_serial_init(struct serial_device * serial, char * name) -{ - return rt_hw_serial_register(RT_DEVICE(serial), name, - RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX | RT_DEVICE_FLAG_STREAM); -} diff --git a/bsp/simulator/drivers/serial.h b/bsp/simulator/drivers/serial.h deleted file mode 100644 index 7c554c3f45..0000000000 --- a/bsp/simulator/drivers/serial.h +++ /dev/null @@ -1,32 +0,0 @@ -/* -********************************************************************************************************* -* MC9S12DP256/DG128 Specific code -* BANKED MEMORY MODEL -* -* File : rthw.c -* By : parai -* email:parai@foxmail.com -*******************************************************************************************************/ - -#ifndef __RT_HW_SERIAL_H__ -#define __RT_HW_SERIAL_H__ - -#include -#define SERIAL_RX_BUFFER_SIZE 80 -struct serial_int_rx -{ - rt_uint8_t rx_buffer[SERIAL_RX_BUFFER_SIZE]; - rt_uint32_t read_index, save_index; -}; - -struct serial_device -{ - struct rt_device dev; - struct serial_int_rx serial_rx; -}; - -#define SERIAL_DEVICE(dev) ((struct serial_device *)(dev)) - -int seial_save_byte(unsigned char ch, struct serial_device * serial); -rt_err_t rt_hw_serial_init(struct serial_device * serial, char * name); -#endif diff --git a/bsp/simulator/drivers/usart_sim.c b/bsp/simulator/drivers/uart_console.c old mode 100755 new mode 100644 similarity index 52% rename from bsp/simulator/drivers/usart_sim.c rename to bsp/simulator/drivers/uart_console.c index 6c8209dcc0..95a9cb11dd --- a/bsp/simulator/drivers/usart_sim.c +++ b/bsp/simulator/drivers/uart_console.c @@ -1,34 +1,29 @@ -/* - * File : serial.c - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2013 RT-Thread Develop Team - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rt-thread.org/license/LICENSE - * - * Change Logs: - * Date Author Notes - * 2012-09-25 prife first implementation - * 2013-01-15 prife support linux - * 2013-02-6 prife rewrite to fit the new serial.c - */ -#include -#include +#include + +#include +#include +#include +#include + +#include + +/* uart driver */ +struct console_uart +{ + int rx_ready; + + struct rt_ringbuffer rb; + rt_uint8_t rx_buffer[256]; +} _console_uart; +static struct rt_serial_device _serial; + +#define SAVEKEY(key) do { char ch = key; rt_ringbuffer_put_force(&(_console_uart.rb), &ch, 1); } while (0) #ifdef _WIN32 #include #include #include -#endif -#include -#include "serial.h" - -struct serial_device serial1; - -#define SAVEKEY(key) seial_save_byte(key, &serial1) -#ifdef _WIN32 /* * Handler for OSKey Thread */ @@ -36,9 +31,8 @@ static HANDLE OSKey_Thread; static DWORD OSKey_ThreadID; static DWORD WINAPI ThreadforKeyGet(LPVOID lpParam); -void rt_hw_usart_init(void) +void console_lowlevel_init(void) { - rt_hw_serial_init(&serial1, RT_CONSOLE_DEVICE_NAME); /* * create serial thread that receive key input from keyboard */ @@ -52,9 +46,9 @@ void rt_hw_usart_init(void) if (OSKey_Thread == NULL) { //Display Error Message - return; } + SetThreadPriority(OSKey_Thread, THREAD_PRIORITY_NORMAL); SetThreadPriorityBoost(OSKey_Thread, @@ -67,6 +61,7 @@ void rt_hw_usart_init(void) ResumeThread(OSKey_Thread); } +static DWORD WINAPI ThreadforKeyGet(LPVOID lpParam) #else /* POSIX version */ #include @@ -78,11 +73,11 @@ void rt_hw_usart_init(void) static void * ThreadforKeyGet(void * lpParam); static pthread_t OSKey_Thread; -void rt_hw_usart_init(void) + +void console_lowlevel_init(void) { int res; - rt_hw_serial_init(&serial1, RT_CONSOLE_DEVICE_NAME); res = pthread_create(&OSKey_Thread, NULL, &ThreadforKeyGet, NULL); if (res) { @@ -90,15 +85,10 @@ void rt_hw_usart_init(void) exit(EXIT_FAILURE); } } -#endif - -#ifdef _WIN32 -static DWORD WINAPI ThreadforKeyGet(LPVOID lpParam) -#else static struct termios oldt, newt; /*simulate windows' getch(), it works!!*/ -void set_stty(void) +static void set_stty(void) { /* get terminal input's attribute */ tcgetattr(STDIN_FILENO, &oldt); @@ -109,22 +99,21 @@ void set_stty(void) tcsetattr(STDIN_FILENO, TCSANOW, &newt); } -void restore_stty(void) +static void restore_stty(void) { /* recover terminal's attribute */ tcsetattr(STDIN_FILENO, TCSANOW, &oldt); } #define getch getchar - static void * ThreadforKeyGet(void * lpParam) #endif /* not _WIN32*/ { /* - * 方向键(←): 0xe04b - * 方向键(↑): 0xe048 - * 方向键(→): 0xe04d - * 方向键(↓): 0xe050 + * left key(←): 0xe04b + * up key(↑): 0xe048 + * right key(→): 0xe04d + * down key(↓): 0xe050 */ unsigned char key; @@ -135,7 +124,9 @@ static void * ThreadforKeyGet(void * lpParam) pthread_sigmask(SIG_BLOCK, &sigmask, &oldmask); set_stty(); #endif + (void)lpParam; //prevent compiler warnings + for (;;) { key = getch(); @@ -173,5 +164,109 @@ static void * ThreadforKeyGet(void * lpParam) } #endif SAVEKEY(key); + + /* Notfiy serial ISR */ + rt_hw_serial_isr(&_serial, RT_SERIAL_EVENT_RX_IND); } } /*** ThreadforKeyGet ***/ + +static rt_err_t console_configure(struct rt_serial_device *serial, struct serial_configure *cfg) +{ + /* no baudrate, nothing */ + + return RT_EOK; +} + +static rt_err_t console_control(struct rt_serial_device *serial, int cmd, void *arg) +{ + struct console_uart* uart; + + RT_ASSERT(serial != RT_NULL); + uart = (struct console_uart *)serial->parent.user_data; + + switch (cmd) + { + case RT_DEVICE_CTRL_CLR_INT: + uart->rx_ready = 0; + break; + case RT_DEVICE_CTRL_SET_INT: + uart->rx_ready = 1; + break; + } + + return RT_EOK; +} + +static int console_putc(struct rt_serial_device *serial, char c) +{ + int level; + struct console_uart* uart; + + RT_ASSERT(serial != RT_NULL); + uart = (struct console_uart *)serial->parent.user_data; + +#if 0 /* Enable it if you want to save the console log */ + { + static FILE* fp = NULL; + + if (fp == NULL) + fp = fopen("log.txt", "wb+"); + + if (fp != NULL) + fwrite(buffer, size, 1, fp); + } +#endif + + level = rt_hw_interrupt_disable(); + fwrite(&c, 1, 1, stdout); + fflush(stdout); + rt_hw_interrupt_enable(level); + return 1; +} + +static int console_getc(struct rt_serial_device *serial) +{ + char ch; + struct console_uart* uart; + + RT_ASSERT(serial != RT_NULL); + uart = (struct console_uart *)serial->parent.user_data; + + if (rt_ringbuffer_getchar(&(uart->rb), &ch)) return ch; + + return -1; +} + +static const struct rt_uart_ops console_uart_ops = +{ + console_configure, + console_control, + console_putc, + console_getc, +}; + +int uart_console_init(void) +{ + struct serial_configure config = RT_SERIAL_CONFIG_DEFAULT; + struct console_uart* uart; + struct rt_serial_device* serial; + + uart = &_console_uart; + serial = &_serial; + + uart->rx_ready = 0; + + serial->ops = &console_uart_ops; + serial->config = config; + /* initialize ring buffer */ + rt_ringbuffer_init(&uart->rb, uart->rx_buffer, sizeof(uart->rx_buffer)); + + /* register UART device */ + rt_hw_serial_register(serial, "console", + RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX, + uart); + + console_lowlevel_init(); + + return 0; +} diff --git a/bsp/simulator/drivers/uart_console.h b/bsp/simulator/drivers/uart_console.h new file mode 100644 index 0000000000..149a7a21f8 --- /dev/null +++ b/bsp/simulator/drivers/uart_console.h @@ -0,0 +1,6 @@ +#ifndef UART_CONSOLE_H__ +#define UART_CONSOLE_H__ + +int uart_console_init(void); + +#endif diff --git a/bsp/simulator/rtconfig.h b/bsp/simulator/rtconfig.h index a1f877de2e..894a5822a1 100755 --- a/bsp/simulator/rtconfig.h +++ b/bsp/simulator/rtconfig.h @@ -1,13 +1,217 @@ /* RT-Thread config file */ + #ifndef __RTTHREAD_CFG_H__ #define __RTTHREAD_CFG_H__ +// + +// +#define RT_NAME_MAX 6 +// +#define RT_ALIGN_SIZE 4 +// +// 8 +// 32 +// 256 +// +#define RT_THREAD_PRIORITY_MAX 32 +// +#define RT_TICK_PER_SECOND 100 +//
+#define RT_DEBUG +// +// #define RT_THREAD_DEBUG +// +#define RT_USING_OVERFLOW_CHECK +//
+ +// +#define RT_USING_HOOK +//
+// #define RT_USING_TIMER_SOFT +// +#define RT_TIMER_THREAD_PRIO 4 +// +#define RT_TIMER_THREAD_STACK_SIZE 512 +//
+ +//
+// +#define RT_USING_SEMAPHORE +// +#define RT_USING_MUTEX +// +#define RT_USING_EVENT +// +#define RT_USING_MAILBOX +// +#define RT_USING_MESSAGEQUEUE +//
+ +//
+// +#define RT_USING_MEMPOOL +// +#define RT_USING_MEMHEAP +// +#define RT_USING_HEAP +// +#define RT_USING_SMALL_MEM +// +// #define RT_USING_SLAB +//
+ +//
+#define RT_USING_DEVICE +// +#define RT_USING_DEVICE_IPC +// +#define RT_USING_SERIAL +// +#define RT_USING_UART0 +//
+ +//
+#define RT_USING_CONSOLE +// +#define RT_CONSOLEBUF_SIZE 128 +// +#define RT_CONSOLE_DEVICE_NAME "console" +//
+ +// +// #define RT_USING_COMPONENTS_INIT +//
+#define RT_USING_FINSH +// +#define FINSH_USING_SYMTAB +// +#define FINSH_USING_DESCRIPTION +// +#define FINSH_THREAD_STACK_SIZE 4096 +//
+ +//
+// +// #define RT_USING_LIBC +// +// #define RT_USING_PTHREADS +//
+ +//
+// #define RT_USING_DFS +// +// #define DFS_USING_WORKDIR +// +#define DFS_FILESYSTEMS_MAX 2 +// +#define DFS_FD_MAX 4 +// +#define RT_USING_DFS_ELMFAT +// +// 1 +// 2 +// 3 +// +#define RT_DFS_ELM_USE_LFN 3 +// +#define RT_DFS_ELM_CODE_PAGE 437 +// +#define RT_DFS_ELM_MAX_LFN 128 +// +// #define RT_USING_DFS_YAFFS2 +// +// #define RT_USING_DFS_UFFS +// +// #define RT_USING_DFS_DEVFS +// +// #define RT_USING_DFS_NFS +// +#define RT_NFS_HOST_EXPORT "192.168.1.5:/" +//
+ +//
+// #define RT_USING_LWIP +// +#define RT_LWIP_ICMP +// +// #define RT_LWIP_IGMP +// +#define RT_LWIP_UDP +// +#define RT_LWIP_TCP +// +#define RT_LWIP_DNS +// +// #define RT_LWIP_SNMP +// +// #define RT_LWIP_DHCP +// +#define RT_LWIP_TCPTHREAD_PRIORITY 12 +// +#define RT_LWIP_TCPTHREAD_MBOX_SIZE 8 +// +#define RT_LWIP_TCPTHREAD_STACKSIZE 4096 +// +#define RT_LWIP_ETHTHREAD_PRIORITY 14 +// +#define RT_LWIP_ETHTHREAD_MBOX_SIZE 8 +// +#define RT_LWIP_ETHTHREAD_STACKSIZE 512 +// +#define RT_LWIP_IPADDR0 192 +#define RT_LWIP_IPADDR1 168 +#define RT_LWIP_IPADDR2 1 +#define RT_LWIP_IPADDR3 30 +// +#define RT_LWIP_GWADDR0 192 +#define RT_LWIP_GWADDR1 168 +#define RT_LWIP_GWADDR2 1 +#define RT_LWIP_GWADDR3 1 +// +#define RT_LWIP_MSKADDR0 255 +#define RT_LWIP_MSKADDR1 255 +#define RT_LWIP_MSKADDR2 255 +#define RT_LWIP_MSKADDR3 0 +//
+ +//
+// #define RT_USING_RTGUI +// +#define RTGUI_NAME_MAX 12 +// +#define RTGUI_USING_SMALL_SIZE +// +#define RTGUI_USING_FONT16 +// +// #define RTGUI_USING_FONT12 +// +#define RTGUI_USING_FONTHZ +// +#define RTGUI_DEFAULT_FONT_SIZE 16 +// +#define RTGUI_USING_DFS_FILERW +// +#define RTGUI_USING_HZ_BMP +// +#define RTGUI_IMAGE_XPM +// +// #define RTGUI_IMAGE_JPEG +// +// #define RTGUI_IMAGE_PNG +// +#define RTGUI_IMAGE_BMP +// + #define RTGUI_USING_HZ_FILE +// +#define RTGUI_USING_MOUSE_CURSOR +//
+ +//
+ #define RT_HEAP_SIZE (1024*1024*2) -#if defined(_MSC_VER) -/* SECTION: port for visual studio */ -#undef RT_USING_NEWLIB -#undef RT_USING_MINILIBC +#if defined(_MSC_VER) #define NORESOURCE //RT_VESRION in winuser.h #define _CRT_ERRNO_DEFINED //errno macro redefinition #define _INC_WTIME_INL//dfs_elm.c time.h conflicts with wtime.inl @@ -26,212 +230,12 @@ #if defined(__MINGW32__) #define _NO_OLDNAMES /* to ignore: mode_t in sys/type.h */ -#endif -#endif +#endif /* end of __MINGW32__ */ -/* SECTION: basic kernel options */ -/* RT_NAME_MAX*/ -#define RT_NAME_MAX 8 - -/* RT_ALIGN_SIZE*/ -#define RT_ALIGN_SIZE 4 - -/* PRIORITY_MAX */ -#define RT_THREAD_PRIORITY_MAX 32 - -/* Tick per Second */ -#define RT_TICK_PER_SECOND 100 - -/* SECTION: RT_DEBUG */ -/* Thread Debug */ -#define RT_DEBUG -//#define RT_DEBUG_SCHEDULER 1 -#define RT_THREAD_DEBUG - -#define RT_USING_OVERFLOW_CHECK - -/* Using Hook */ -#define RT_USING_HOOK - -/* Using Software Timer */ -/* #define RT_USING_TIMER_SOFT */ -#define RT_TIMER_THREAD_PRIO 4 -#define RT_TIMER_THREAD_STACK_SIZE 512 -#define RT_TIMER_TICK_PER_SECOND 10 - -/* SECTION: IPC */ -/* Using Semaphore*/ -#define RT_USING_SEMAPHORE - -/* Using Mutex */ -#define RT_USING_MUTEX - -/* Using Event */ -#define RT_USING_EVENT - -/* Using MailBox */ -#define RT_USING_MAILBOX - -/* Using Message Queue */ -#define RT_USING_MESSAGEQUEUE - -/* SECTION: Memory Management */ -/* Using Memory Pool Management*/ -/* #define RT_USING_MEMPOOL */ - -/* Using Dynamic Heap Management */ -#define RT_USING_HEAP - -/* Using Small MM */ -#define RT_USING_SMALL_MEM -/* #define RT_TINY_SIZE */ - -/* SECTION: Device System */ -/* Using Device System */ -#define RT_USING_DEVICE -#define RT_USING_DEVICE_IPC -/* #define RT_USING_UART1 */ - -/* SECTION: Console options */ -#define RT_USING_CONSOLE -/* the buffer size of console*/ -#define RT_CONSOLEBUF_SIZE 128 -#define RT_CONSOLE_DEVICE_NAME "sci0" - -/* SECTION: APP MODULE */ -/* #define RT_USING_MODULE */ - -/* SECTION: MTD interface options */ -/* using mtd nand flash */ -#define RT_USING_MTD_NAND -/* using mtd nor flash */ -/* #define RT_USING_MTD_NOR */ - -/* SECTION: finsh, a C-Express shell */ -#define RT_USING_FINSH -/* Using symbol table */ -#define FINSH_USING_SYMTAB -#define FINSH_USING_DESCRIPTION - -/* SECTION: device file system */ -#define RT_USING_DFS -#define DFS_FILESYSTEM_TYPES_MAX 8 - -/* DFS: ELM FATFS options */ -#define RT_USING_DFS_ELMFAT -#define RT_DFS_ELM_WORD_ACCESS -/* Reentrancy (thread safe) of the FatFs module. */ -#define RT_DFS_ELM_REENTRANT -/* Number of volumes (logical drives) to be used. */ -#define RT_DFS_ELM_DRIVES 2 -/* #define RT_DFS_ELM_USE_LFN 1 */ -#define RT_DFS_ELM_MAX_LFN 255 -/* Maximum sector size to be handled. */ -#define RT_DFS_ELM_MAX_SECTOR_SIZE 512 - -/* DFS: network file system options */ -/* #define RT_USING_DFS_NFS */ - -/* DFS: UFFS nand file system options */ -#define RT_USING_DFS_UFFS -/* configuration for uffs, more to see dfs_uffs.h and uffs_config.h */ -#define RT_CONFIG_UFFS_ECC_MODE UFFS_ECC_HW_AUTO -/* enable this ,you need provide a mark_badblock/check_block function */ -/* #define RT_UFFS_USE_CHECK_MARK_FUNCITON */ - -/* DFS: JFFS2 nor flash file system options */ -//#define RT_USING_DFS_JFFS2 - -/* DFS: windows share directory mounted to rt-thread/dfs */ -/* only used in bsp/simulator */ #ifdef _WIN32 #define RT_USING_DFS_WINSHAREDIR #endif -/* the max number of mounted file system */ -#define DFS_FILESYSTEMS_MAX 4 -/* the max number of opened files */ -#define DFS_FD_MAX 4 - -/* SECTION: lwip, a lightweight TCP/IP protocol stack */ -/* #define RT_USING_LWIP */ -/* LwIP uses RT-Thread Memory Management */ -#define RT_LWIP_USING_RT_MEM -/* Enable ICMP protocol*/ -#define RT_LWIP_ICMP -/* Enable UDP protocol*/ -#define RT_LWIP_UDP -/* Enable TCP protocol*/ -#define RT_LWIP_TCP -/* Enable DNS */ -#define RT_LWIP_DNS - -/* the number of simultaneously active TCP connections*/ -#define RT_LWIP_TCP_PCB_NUM 5 - -/* Using DHCP */ -/* #define RT_LWIP_DHCP */ - -/* ip address of target*/ -#define RT_LWIP_IPADDR0 192 -#define RT_LWIP_IPADDR1 168 -#define RT_LWIP_IPADDR2 126 -#define RT_LWIP_IPADDR3 30 - -/* gateway address of target*/ -#define RT_LWIP_GWADDR0 192 -#define RT_LWIP_GWADDR1 168 -#define RT_LWIP_GWADDR2 126 -#define RT_LWIP_GWADDR3 1 - -/* mask address of target*/ -#define RT_LWIP_MSKADDR0 255 -#define RT_LWIP_MSKADDR1 255 -#define RT_LWIP_MSKADDR2 255 -#define RT_LWIP_MSKADDR3 0 - -/* tcp thread options */ -#define RT_LWIP_TCPTHREAD_PRIORITY 12 -#define RT_LWIP_TCPTHREAD_MBOX_SIZE 10 -#define RT_LWIP_TCPTHREAD_STACKSIZE 1024 - -/* Ethernet if thread options */ -#define RT_LWIP_ETHTHREAD_PRIORITY 15 -#define RT_LWIP_ETHTHREAD_MBOX_SIZE 10 -#define RT_LWIP_ETHTHREAD_STACKSIZE 512 - -/* TCP sender buffer space */ -#define RT_LWIP_TCP_SND_BUF 8192 -/* TCP receive window. */ -#define RT_LWIP_TCP_WND 8192 - -/* SECTION: RT-Thread/GUI */ -/* #define RT_USING_RTGUI */ - -/* name length of RTGUI object */ -#define RTGUI_NAME_MAX 12 -/* support 16 weight font */ -#define RTGUI_USING_FONT16 -/* support Chinese font */ -#define RTGUI_USING_FONTHZ -/* use DFS as file interface */ -#define RTGUI_USING_DFS_FILERW -/* use font file as Chinese font */ -/* #define RTGUI_USING_HZ_FILE */ -/* use Chinese bitmap font */ -#define RTGUI_USING_HZ_BMP -/* use small size in RTGUI */ -#define RTGUI_USING_SMALL_SIZE -/* use mouse cursor */ -/* #define RTGUI_USING_MOUSE_CURSOR */ -/* default font size in RTGUI */ -#define RTGUI_DEFAULT_FONT_SIZE 16 - -/* image support */ -#define RTGUI_IMAGE_XPM -#define RTGUI_IMAGE_BMP -/* #define RTGUI_IMAGE_JPEG */ -/* #define RTGUI_IMAGE_PNG */ -#define RTGUI_USING_NOTEBOOK_IMAGE +#endif /* end of _MSC_VER */ #endif diff --git a/bsp/simulator/rtconfig.py b/bsp/simulator/rtconfig.py index d3ed2599d5..8ccacadfd6 100755 --- a/bsp/simulator/rtconfig.py +++ b/bsp/simulator/rtconfig.py @@ -114,8 +114,8 @@ elif PLATFORM == 'cl': CFLAGS += ' /MT' LFLAGS += '' - CFLAGS += ' /ZI /Od /W 3 /WL ' - LFLAGS += ' /SUBSYSTEM:CONSOLE /MACHINE:X86 ' + CFLAGS += ' /Zi /Od /W 3 /WL ' + LFLAGS += ' /SUBSYSTEM:CONSOLE /MACHINE:X86 /INCREMENTAL:NO' CPATH = '' LPATH = '' From aa190ed5f6145397d3004726c1704b0d408fe22d Mon Sep 17 00:00:00 2001 From: Bernard Xiong Date: Wed, 30 Sep 2015 17:57:58 +0800 Subject: [PATCH 07/36] [BSP] enable file system feature in simulator BSP --- bsp/simulator/drivers/sd_sim.c | 1 - bsp/simulator/rtconfig.h | 14 ++++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/bsp/simulator/drivers/sd_sim.c b/bsp/simulator/drivers/sd_sim.c index b3b265273d..de0dd7cf30 100755 --- a/bsp/simulator/drivers/sd_sim.c +++ b/bsp/simulator/drivers/sd_sim.c @@ -9,7 +9,6 @@ // #define SD_TRACE rt_kprintf #define SD_TRACE(...) -//#define SDCARD_SIM "F:\\Project\\tools\\SDCARD" #define SDCARD_SIM "sd.bin" #define SDCARD_SIZE (16*1024*1024) //16M diff --git a/bsp/simulator/rtconfig.h b/bsp/simulator/rtconfig.h index 894a5822a1..1fc0ddbb8b 100755 --- a/bsp/simulator/rtconfig.h +++ b/bsp/simulator/rtconfig.h @@ -79,8 +79,6 @@ #define RT_CONSOLE_DEVICE_NAME "console" // -// -// #define RT_USING_COMPONENTS_INIT //
#define RT_USING_FINSH // @@ -89,6 +87,10 @@ #define FINSH_USING_DESCRIPTION // #define FINSH_THREAD_STACK_SIZE 4096 +// +#define FINSH_USING_MSH +// +#define FINSH_USING_MSH_DEFAULT //
//
@@ -99,9 +101,9 @@ //
//
-// #define RT_USING_DFS +#define RT_USING_DFS // -// #define DFS_USING_WORKDIR +#define DFS_USING_WORKDIR // #define DFS_FILESYSTEMS_MAX 2 // @@ -232,10 +234,10 @@ #define _NO_OLDNAMES /* to ignore: mode_t in sys/type.h */ #endif /* end of __MINGW32__ */ +#endif /* end of _MSC_VER */ + #ifdef _WIN32 #define RT_USING_DFS_WINSHAREDIR #endif -#endif /* end of _MSC_VER */ - #endif From cdf4c7e89746519c9a615323e8f9e78bc70f82aa Mon Sep 17 00:00:00 2001 From: Bernard Xiong Date: Wed, 30 Sep 2015 18:06:09 +0800 Subject: [PATCH 08/36] [BSP] Enable module application in simulator BSP --- bsp/simulator/drivers/module_win32.c | 79 ++++++++++++++++++++++++---- bsp/simulator/rtconfig.h | 2 + 2 files changed, 72 insertions(+), 9 deletions(-) diff --git a/bsp/simulator/drivers/module_win32.c b/bsp/simulator/drivers/module_win32.c index 95cb301037..83e9304ff7 100644 --- a/bsp/simulator/drivers/module_win32.c +++ b/bsp/simulator/drivers/module_win32.c @@ -350,8 +350,67 @@ FINSH_FUNCTION_EXPORT_ALIAS(rt_module_open, exec, exec module from a file); #endif +#define RT_MODULE_ARG_MAX 8 +static int _rt_module_split_arg(char* cmd, rt_size_t length, char* argv[]) +{ + int argc = 0; + char *ptr = cmd; + + while ((ptr - cmd) < length) + { + /* strip bank and tab */ + while ((*ptr == ' ' || *ptr == '\t') && (ptr -cmd)< length) + *ptr++ = '\0'; + /* check whether it's the end of line */ + if ((ptr - cmd)>= length) break; + + /* handle string with quote */ + if (*ptr == '"') + { + argv[argc++] = ++ptr; + + /* skip this string */ + while (*ptr != '"' && (ptr-cmd) < length) + if (*ptr ++ == '\\') ptr ++; + if ((ptr - cmd) >= length) break; + + /* skip '"' */ + *ptr ++ = '\0'; + } + else + { + argv[argc++] = ptr; + while ((*ptr != ' ' && *ptr != '\t') && (ptr - cmd) < length) + ptr ++; + } + + if (argc >= RT_MODULE_ARG_MAX) break; + } + + return argc; +} + +/* module main thread entry */ +static void module_main_entry(void* parameter) +{ + int argc; + char *argv[RT_MODULE_ARG_MAX]; + typedef int (*main_func_t)(int argc, char** argv); + + rt_module_t module = (rt_module_t) parameter; + if (module == RT_NULL || module->module_cmd_line == RT_NULL) return; + + rt_memset(argv, 0x00, sizeof(argv)); + argc = _rt_module_split_arg((char*)module->module_cmd_line, module->module_cmd_size, argv); + if (argc == 0) return ; + + /* do the main function */ + ((main_func_t)module->module_entry)(argc, argv); + return; +} + /** - * This function will do a excutable program with main function and parameters. + * This function will do a executable program with main function and parameters. * * @param path the full path of application module * @param cmd_line the command line of program @@ -455,14 +514,10 @@ rt_module_t rt_module_exec_cmd(const char *path, const char* cmd_line, int line_ module->page_cnt = 0; #endif - /* create module thread */ - module->module_thread = - rt_thread_create(name, - (void(*)(void *))module->module_entry, RT_NULL, - 2048, RT_THREAD_PRIORITY_MAX - 2, 10); - - RT_DEBUG_LOG(RT_DEBUG_MODULE, ("thread entry 0x%x\n", - module->module_entry)); + /* create module thread */ + module->module_thread = rt_thread_create(name, + module_main_entry, module, + 2048, RT_THREAD_PRIORITY_MAX - 2, 10); /* set module id */ module->module_thread->module_id = (void *)module; @@ -500,4 +555,10 @@ rt_err_t rt_module_destroy(rt_module_t module) { return 0; } + +rt_err_t rt_module_unload(rt_module_t module) +{ + return 0; +} + #endif diff --git a/bsp/simulator/rtconfig.h b/bsp/simulator/rtconfig.h index 1fc0ddbb8b..2555fc11da 100755 --- a/bsp/simulator/rtconfig.h +++ b/bsp/simulator/rtconfig.h @@ -98,6 +98,8 @@ // #define RT_USING_LIBC // // #define RT_USING_PTHREADS +// +#define RT_USING_MODULE //
//
From 1ac6bc6c889f5f6760893a7aab33873ebe9dfe69 Mon Sep 17 00:00:00 2001 From: Bernard Xiong Date: Wed, 30 Sep 2015 10:21:55 +0000 Subject: [PATCH 09/36] [BSP] fix compiling issue in simulator for Linux --- bsp/simulator/drivers/module_win32.c | 2 +- bsp/simulator/drivers/uart_console.c | 10 ++++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/bsp/simulator/drivers/module_win32.c b/bsp/simulator/drivers/module_win32.c index 83e9304ff7..0c998eed2c 100644 --- a/bsp/simulator/drivers/module_win32.c +++ b/bsp/simulator/drivers/module_win32.c @@ -17,7 +17,7 @@ #include #ifdef RT_USING_MODULE -static void rt_module_init_object_container(struct rt_module *module) +void rt_module_init_object_container(struct rt_module *module) { RT_ASSERT(module != RT_NULL); diff --git a/bsp/simulator/drivers/uart_console.c b/bsp/simulator/drivers/uart_console.c index 95a9cb11dd..283ac83a05 100644 --- a/bsp/simulator/drivers/uart_console.c +++ b/bsp/simulator/drivers/uart_console.c @@ -5,8 +5,6 @@ #include #include -#include - /* uart driver */ struct console_uart { @@ -110,10 +108,10 @@ static void * ThreadforKeyGet(void * lpParam) #endif /* not _WIN32*/ { /* - * left key(←): 0xe04b - * up key(↑): 0xe048 - * right key(→): 0xe04d - * down key(↓): 0xe050 + * left key(锟斤拷)锟斤拷 0xe04b + * up key(锟斤拷)锟斤拷 0xe048 + * right key(锟斤拷)锟斤拷 0xe04d + * down key(锟斤拷)锟斤拷 0xe050 */ unsigned char key; From 5ac0ed740300c812f4a472ac800f3b7ecd8f3f50 Mon Sep 17 00:00:00 2001 From: Bernard Xiong Date: Thu, 1 Oct 2015 11:29:59 +0800 Subject: [PATCH 10/36] [BSP] remove testdll in the simualtor BSP --- bsp/simulator/testdll/SConstruct | 85 ----- bsp/simulator/testdll/basicapp/Sconscript | 7 - bsp/simulator/testdll/basicapp/basicapp.c | 30 -- bsp/simulator/testdll/label/Sconscript | 7 - bsp/simulator/testdll/label/label_demo1.c | 74 ---- bsp/simulator/testdll/rtconfig.py | 51 --- bsp/simulator/testdll/rttapp.def | 3 - bsp/simulator/testdll/snake/SConscript | 7 - bsp/simulator/testdll/snake/snake.c | 271 --------------- bsp/simulator/testdll/snake/snake.h | 68 ---- bsp/simulator/testdll/snake/snake_gui.c | 397 ---------------------- bsp/simulator/testdll/var/Sconscript | 7 - bsp/simulator/testdll/var/var.c | 20 -- 13 files changed, 1027 deletions(-) delete mode 100644 bsp/simulator/testdll/SConstruct delete mode 100644 bsp/simulator/testdll/basicapp/Sconscript delete mode 100644 bsp/simulator/testdll/basicapp/basicapp.c delete mode 100644 bsp/simulator/testdll/label/Sconscript delete mode 100644 bsp/simulator/testdll/label/label_demo1.c delete mode 100644 bsp/simulator/testdll/rtconfig.py delete mode 100644 bsp/simulator/testdll/rttapp.def delete mode 100644 bsp/simulator/testdll/snake/SConscript delete mode 100644 bsp/simulator/testdll/snake/snake.c delete mode 100644 bsp/simulator/testdll/snake/snake.h delete mode 100644 bsp/simulator/testdll/snake/snake_gui.c delete mode 100644 bsp/simulator/testdll/var/Sconscript delete mode 100644 bsp/simulator/testdll/var/var.c diff --git a/bsp/simulator/testdll/SConstruct b/bsp/simulator/testdll/SConstruct deleted file mode 100644 index 690df89ce8..0000000000 --- a/bsp/simulator/testdll/SConstruct +++ /dev/null @@ -1,85 +0,0 @@ -import os -import sys -import SCons.cpp -import rtconfig - -if os.getenv('RTT_ROOT'): - RTT_ROOT = os.getenv('RTT_ROOT') -else: - RTT_ROOT = os.path.normpath(os.getcwd() + '/../..') - -if os.getenv('RTT_RTGUI'): - RTT_RTGUI = os.getenv('RTT_RTGUI') -else: - # set the rtgui root directory by hand - # empty string means use the RTGUI in svn - RTT_RTGUI = os.path.normpath(r'F:\Project\git\rt-gui\components\rtgui') - # RTT_RTGUI ='' - -sys.path = sys.path + [os.path.join(RTT_ROOT, 'tools')] -from building import * - -Export('RTT_ROOT') - -# add target option -AddOption('--app', - dest='app', - nargs=1, type='string', - action='store', - metavar='DIR', - help='installation prefix') - -# add target option -AddOption('--type', - dest='type', - nargs=1, type='string', - action='store', - metavar='DIR', - help='installation prefix') - -app = GetOption('app') -env = Environment(TARGET_ARCH='x86') -CPPPATH = [ - RTT_ROOT + '/include', - RTT_ROOT + '/bsp/' + rtconfig.BSP, - RTT_ROOT + '/components/finsh', - RTT_ROOT + '/components/libdl', - RTT_ROOT + '/components/external/ftk/ftk/src/os/rt-thread', - RTT_ROOT + '/components/external/ftk/ftk/src/demos', - RTT_ROOT + '/components/external/ftk/ftk/apps/common', - RTT_ROOT + '/components/external/ftk/ftk/src', - RTT_ROOT + '/components/dfs', - RTT_ROOT + '/components/dfs/include', - RTT_ROOT + '/components/libc/newlib', - RTT_ROOT + '/components/external/cairo/cairo-1.10.2/src', - RTT_ROOT + '/components/external/cairo/' -] -if RTT_RTGUI: - RTGUI_ROOT = RTT_RTGUI -else: - RTGUI_ROOT = RTT_ROOT + '/components/rtgui' -RTGUI_PATH = [ - RTGUI_ROOT + '/include', - RTGUI_ROOT + '/common', - RTGUI_ROOT + '/server', - RTGUI_ROOT + '/widgets', -] -CPPPATH += RTGUI_PATH - -env.Append(CCFLAGS=rtconfig.CFLAGS) -env.Append(LINKFLAGS=rtconfig.LFLAGS) -env.Append(CPPPATH=CPPPATH) -env.Append(LIBS='rtthread', LIBPATH='../') -env.Append(CPPDEFINES=['RTT_IN_MODULE']) -env.PrependENVPath('PATH', rtconfig.EXEC_PATH) - -PrepareModuleBuilding(env, RTT_ROOT) - -#dir = app + '/build/' + rtconfig.BSP -dir = app + '/build/' -objs = SConscript(app + '/Sconscript', variant_dir=dir, duplicate=0) -TARGET = dir + '/' + app + '.' + rtconfig.TARGET_EXT - -# build program -#env.Program(TARGET, objs) -env.SharedLibrary(TARGET, objs) diff --git a/bsp/simulator/testdll/basicapp/Sconscript b/bsp/simulator/testdll/basicapp/Sconscript deleted file mode 100644 index d8dd99964e..0000000000 --- a/bsp/simulator/testdll/basicapp/Sconscript +++ /dev/null @@ -1,7 +0,0 @@ -import rtconfig -Import('RTT_ROOT') -from building import * - -src = Glob('*.c') -group = DefineGroup('', src, depend = ['']) -Return('group') \ No newline at end of file diff --git a/bsp/simulator/testdll/basicapp/basicapp.c b/bsp/simulator/testdll/basicapp/basicapp.c deleted file mode 100644 index 3a1927277e..0000000000 --- a/bsp/simulator/testdll/basicapp/basicapp.c +++ /dev/null @@ -1,30 +0,0 @@ -#include - -static int a = 0; -static int b = 1000000; -int c = 100; - -static void function(int count1, int count2, int count3) -{ - rt_kprintf("Hello RT-Thread %d %d\n", count1, count2, count3); -} - -int main(void) -{ - int i; - - rt_kprintf("application entry\n"); - rt_kprintf("[addr]a-0x%x,b-0x%x,c-0x%x\n", &a, &b, &c); - rt_kprintf("[value]a-%d,b-%d,c-%d\n", a, b, c); - - for(i=0; i<100; i++) - { - a++; - b--; - c++; - function(a, c, b ); - } - - return 0; -} - diff --git a/bsp/simulator/testdll/label/Sconscript b/bsp/simulator/testdll/label/Sconscript deleted file mode 100644 index d8dd99964e..0000000000 --- a/bsp/simulator/testdll/label/Sconscript +++ /dev/null @@ -1,7 +0,0 @@ -import rtconfig -Import('RTT_ROOT') -from building import * - -src = Glob('*.c') -group = DefineGroup('', src, depend = ['']) -Return('group') \ No newline at end of file diff --git a/bsp/simulator/testdll/label/label_demo1.c b/bsp/simulator/testdll/label/label_demo1.c deleted file mode 100644 index 9a72c31fd2..0000000000 --- a/bsp/simulator/testdll/label/label_demo1.c +++ /dev/null @@ -1,74 +0,0 @@ -#include - -#include -#include -#include -#include -#include - -/* 在LCD上创建一个主窗口,这是第一个窗口 */ -static void win_thread_entry(void *parameter) -{ - struct rtgui_app *app; - struct rtgui_win *win; - struct rtgui_label *label; - struct rtgui_rect rect; - - app = rtgui_app_create(rt_thread_self(), "MyApp"); - RT_ASSERT(app != RT_NULL); - - /* create a full screen window */ - rtgui_graphic_driver_get_rect(rtgui_graphic_driver_get_default(), &rect); - - win = rtgui_win_create(RT_NULL, "MainWin", &rect, - RTGUI_WIN_STYLE_NO_BORDER | RTGUI_WIN_STYLE_NO_TITLE); - if (win == RT_NULL) - { - rtgui_app_destroy(app); - return; - } - - /* 建立一个label,内容为helloworld */ - label = rtgui_label_create("Hello World!"); - - /* 设置label的位置,这里是绝对坐标 */ - rect.x1 = 0; - rect.y1 = 100; - rect.x2 = 240; - rect.y2 = 140; - rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect); - - rt_kprintf("bc: %x\n", RTGUI_WIDGET_BACKGROUND(label)); - rt_kprintf("fc: %x\n", RTGUI_WIDGET_FOREGROUND(label)); -#if 0 - RTGUI_WIDGET_BACKGROUND(label) = 0; - RTGUI_WIDGET_FOREGROUND(label) = RTGUI_RGB(0xFF, 0xFF, 0); -#endif - - /*添加label到主窗口*/ - rtgui_container_add_child(RTGUI_CONTAINER(win), RTGUI_WIDGET(label)); - - /* 显示主窗口 */ - rtgui_win_show(win, RT_FALSE); - - /* 循环 */ - rtgui_app_run(app); - - rtgui_win_destroy(win); - rtgui_app_destroy(app); - rt_kprintf("MyApp Quit.\n"); -} - -int main() -{ - rt_thread_t tid; - - tid = rt_thread_create("win", win_thread_entry, RT_NULL, - 2048, 20, 20); - if (tid != RT_NULL) - { - rt_thread_startup(tid); - } - - return 0; -} diff --git a/bsp/simulator/testdll/rtconfig.py b/bsp/simulator/testdll/rtconfig.py deleted file mode 100644 index a2ea824d75..0000000000 --- a/bsp/simulator/testdll/rtconfig.py +++ /dev/null @@ -1,51 +0,0 @@ -# bsp name -BSP = 'simulator' - -# toolchains -EXEC_PATH = '' -PREFIX = '' -TARGET_EXT = 'dll' -AS = PREFIX + 'cl' -CC = PREFIX + 'cl' -AR = PREFIX + 'cl' -LINK = PREFIX + 'cl' -AFLAGS = '' -CFLAGS = '' -LFLAGS = '' -BUILD = 'debug' - -if BUILD == 'debug': - CFLAGS += ' /MTd' - LFLAGS += ' /DEBUG' -else: - CFLAGS += ' /MT' - LFLAGS += '' - -CFLAGS += ' /ZI /Od /W 3 /WL' -LFLAGS += ' /DEF:rttapp.def /SUBSYSTEM:CONSOLE /MACHINE:X86' -#LFLAGS += ' /DEF:rttapp.def /SUBSYSTEM:WINDOWS /MACHINE:X86' #/ENTRY:mainCRTStartup - -CPATH = '' -LPATH = '' - -''' -EXEC_PATH = 'C:/Program Files/CodeSourcery/Sourcery G++ Lite/bin' -PREFIX = 'arm-none-eabi-' -CC = PREFIX + 'gcc' -CXX = PREFIX + 'g++' -AS = PREFIX + 'gcc' -AR = PREFIX + 'ar' -LINK = PREFIX + 'gcc' -TARGET_EXT = 'so' -SIZE = PREFIX + 'size' -OBJDUMP = PREFIX + 'objdump' -OBJCPY = PREFIX + 'objcopy' - -DEVICE = ' -mcpu=arm920t' -CFLAGS = DEVICE + ' -O0 -fPIC -DFTK_AS_PLUGIN -DRT_THREAD ' -AFLAGS = ' -c' + DEVICE + ' -x assembler-with-cpp' -LFLAGS = DEVICE + ' -Wl,-z,max-page-size=0x4 -shared -fPIC -nostdlib -s' - -CPATH = '' -LPATH = '' -''' diff --git a/bsp/simulator/testdll/rttapp.def b/bsp/simulator/testdll/rttapp.def deleted file mode 100644 index a3a3ca51a8..0000000000 --- a/bsp/simulator/testdll/rttapp.def +++ /dev/null @@ -1,3 +0,0 @@ -LIBRARY app -EXPORTS -main diff --git a/bsp/simulator/testdll/snake/SConscript b/bsp/simulator/testdll/snake/SConscript deleted file mode 100644 index f9808e4fe7..0000000000 --- a/bsp/simulator/testdll/snake/SConscript +++ /dev/null @@ -1,7 +0,0 @@ -import rtconfig -Import('RTT_ROOT') -from building import * - -src = Glob('*.c') -group = DefineGroup('', src, depend = ['']) -Return('group') diff --git a/bsp/simulator/testdll/snake/snake.c b/bsp/simulator/testdll/snake/snake.c deleted file mode 100644 index 87e1c8b36f..0000000000 --- a/bsp/simulator/testdll/snake/snake.c +++ /dev/null @@ -1,271 +0,0 @@ -#include -#include -#include -#include "snake.h" - -#define ASSERT_RET(x, ret) \ - do{ \ - if (x) \ - return ret; \ - }while(0) - -rt_list_t snake_head; -SNAKE_DIR prevdir, newdir; - -static SNAKE_DIR dir_adjust(SNAKE_DIR dir) -{ - if ((SNAKE_DIR_UP == prevdir && SNAKE_DIR_DOWN != dir) - || (SNAKE_DIR_DOWN == prevdir && SNAKE_DIR_UP != dir) - || (SNAKE_DIR_LEFT == prevdir && SNAKE_DIR_RIGHT != dir) - || (SNAKE_DIR_RIGHT == prevdir && SNAKE_DIR_LEFT != dir) - ) - { - newdir = dir; - } - else - { - rt_kprintf("dirction change error\n\r"); - } - - return newdir; -} - -static void across_XY(point_t *node, const map_t *map) -{ - RT_ASSERT(node != RT_NULL && map != RT_NULL); - - // 如果长度超出当前边框则可以穿越墙到对面 - node->x = (node->x + map->width) % map->width; - node->y = (node->y + map->height) % map->height; -} - -static SYS_STE node_update(snake_t *tail, const point_t *node, map_t *map) -{ - SYS_STE ret; - point_t *pos; - - RT_ASSERT(tail != RT_NULL && node != RT_NULL && map != RT_NULL); - - pos = map->snake_flush; - pos[0].x = pos[0].y = -1; - pos[1].x = pos[1].y = -1; - - ret = (SYS_STE)map->range[node->y * map->width + node->x]; - - if (FOOD == map->range[node->y * map->width + node->x]) - { - // 吃一个食物增加一个节点 - snake_t *new = (snake_t *)rt_malloc(sizeof(snake_t)); - if (!new) - return NORMAL; - - pos[0] = *node; - new->body = *node; - rt_list_insert_after(&snake_head, &new->list); - } - else if (NORMAL == map->range[node->y * map->width + node->x]) - { - // 将尾巴修改后拿到头部,其他不变 - rt_list_remove(&tail->list); - map->range[tail->body.y * map->width + tail->body.x] = NORMAL; - - pos[0] = *node; - pos[1] = tail->body; - - tail->body = *node; - rt_list_insert_after(&snake_head, &tail->list); - } - - map->range[node->y * map->width + node->x] = OVER; - - if (ret != OVER) - prevdir = newdir; - - return ret; -} - - -map_t *map_init(rt_uint32_t width, rt_uint32_t heigth) -{ - map_t *map = rt_malloc(sizeof(map_t)); - - if (map != RT_NULL) - { - map->range = rt_malloc(heigth * width); - - if (!map->range) - { - rt_free(map); - map = RT_NULL; - } - else - { - map->width = width; - map->height = heigth; - memset(map->range, NORMAL, heigth * width); - } - } - - return map; -} - -// 构造一条指定长度的蛇在指定点 -rt_bool_t snake_init(const point_t *start, const int length, const SNAKE_DIR dir, map_t *map) -{ - rt_int32_t i; - rt_int32_t inc_x, inc_y; - point_t old = *start; - - ASSERT_RET(!map || !start, RT_FALSE); - - rt_list_init(&snake_head); - - if (dir == SNAKE_DIR_UP || dir == SNAKE_DIR_DOWN) - { - if (map->height <= length) - return RT_FALSE; - - inc_x = 0; - inc_y = dir == SNAKE_DIR_DOWN ? 1 : -1; // 反向延长身子,头部在指定位置 - old.y -= inc_y; - } - else - { - if (map->width <= length) - return RT_FALSE; - - inc_y = 0; - inc_x = dir == SNAKE_DIR_RIGHT ? -1 : 1; - old.x -= inc_x; - } - - for (i = 0; i < length; i++) - { - snake_t *new = (snake_t *)rt_malloc(sizeof(snake_t)); - if (!new) - return RT_FALSE; - - new->body.y = inc_y + old.y; - new->body.x = inc_x + old.x; - - // 如果长度超出当前边框则可以穿越墙到对面 - across_XY(&new->body, map); - - map->range[new->body.y * map->width + new->body.x] = OVER; - - old = new->body; - rt_list_insert_before(&snake_head, &new->list); - } - - prevdir = dir; - - return RT_TRUE; -} - -// 构造出食物 -rt_bool_t food_init(map_t *map, rt_uint32_t max_num) -{ - point_t food; - -#ifndef FOOD_TIMEOUT -#define FOOD_TIMEOUT 10 -#endif - - rt_uint32_t timeout, num; - - ASSERT_RET(!map, RT_FALSE); - - num = 0; - timeout = rt_tick_get(); - srand(rand()); - - map->food_flush[0].x = map->food_flush[0].y = -1; - - do - { - food.x = rand() % map->width; - food.y = rand() % map->height; - - if (map->range[food.y * map->width + food.x] == NORMAL) - { - map->food_flush[0] = food; - map->range[food.y * map->width + food.x] = FOOD; - num++; - } - } - while (num < max_num && rt_tick_get() - timeout < FOOD_TIMEOUT); - - return num; -} - -void map_deinit(map_t *map) -{ - if (map) - { - if (map->range) - { - rt_free(map->range); - map->range = RT_NULL; - } - rt_free(map); - } -} - -void snake_deinit(void) -{ - snake_t *node; - - while (!rt_list_isempty(&snake_head)) - { - node = rt_list_entry(snake_head.prev, snake_t, list); - rt_list_remove(&node->list); - rt_free(node); - } -} - -void food_deinit(void) -{ - -} - -SYS_STE snake_step(SNAKE_DIR dir, map_t *map) -{ - snake_t *tail, *head; - point_t node; - - ASSERT_RET(!map, RT_FALSE); - - dir = dir_adjust(dir); - - // 取出头尾两个节点,其他节点不需要改变 - tail = rt_list_entry(snake_head.prev, snake_t, list); - head = rt_list_entry(snake_head.next, snake_t, list); - - node = head->body; - - // 构造一个新的蛇头坐标 - switch (dir) - { - case SNAKE_DIR_UP: - case SNAKE_DIR_DOWN: - node.y = head->body.y + (dir == SNAKE_DIR_DOWN ? -1 : 1); - break; - case SNAKE_DIR_LEFT: - case SNAKE_DIR_RIGHT: - node.x = head->body.x + (dir == SNAKE_DIR_RIGHT ? 1 : -1); - break; - } - across_XY(&node, map); - - return node_update(tail, &node, map); -} - -rt_bool_t snake_restart(const point_t *start, const int length, const SNAKE_DIR dir, map_t *map) -{ - ASSERT_RET(!map || !start, RT_FALSE); - - snake_deinit(); - memset(map->range, NORMAL, map->width * map->height); - - return snake_init(start, length, dir, map); -} diff --git a/bsp/simulator/testdll/snake/snake.h b/bsp/simulator/testdll/snake/snake.h deleted file mode 100644 index 557d4d9241..0000000000 --- a/bsp/simulator/testdll/snake/snake.h +++ /dev/null @@ -1,68 +0,0 @@ -#ifndef _SNAKE_H_ -#define _SNAKE_H_ - -#include - -#define snake_length_max 20 //最大蛇长 -#define snake_length_init 3 //初始化蛇长 -#define snake_room_size_hight 8 //房子高 0-255 建议>8 -#define snake_room_size_widht 8 //房子宽 0-255 建议>8 - -#define snake_init_pointx 1 -#define snake_init_pointy 2 - -typedef struct -{ - rt_int32_t x, y; -} point_t; - -typedef struct -{ - rt_int32_t width; // max x - rt_int32_t height; // max y - rt_uint8_t *range; // map, map->range[y * map->width + x] - point_t snake_flush[2]; - point_t food_flush[1]; -} map_t; - -typedef enum -{ - SNAKE_DIR_UP, - SNAKE_DIR_DOWN, - SNAKE_DIR_LEFT, - SNAKE_DIR_RIGHT -} SNAKE_DIR; - -typedef enum -{ - FOOD, // 吃到水果 - OVER, // 咬到自身 - NORMAL // 正常行动 -} SYS_STE; - -typedef struct -{ - point_t body; - rt_list_t list; -} snake_t; - -// 构造一个地图 -map_t *map_init(rt_uint32_t width, rt_uint32_t heigth); - -// 构造一条指定长度的蛇在指定点 -rt_bool_t snake_init(const point_t *start, const int length, const SNAKE_DIR dir, map_t *map); - -// 构造出食物 -rt_bool_t food_init(map_t *map, rt_uint32_t max_num); - -void map_deinit(map_t *map); - -void snake_deinit(void); - -void food_deinit(void); - -SYS_STE snake_step(SNAKE_DIR dir, map_t *map); - -rt_bool_t snake_restart(const point_t *start, const int length, const SNAKE_DIR dir, map_t *map); - -#endif diff --git a/bsp/simulator/testdll/snake/snake_gui.c b/bsp/simulator/testdll/snake/snake_gui.c deleted file mode 100644 index 5ad2c8d7c5..0000000000 --- a/bsp/simulator/testdll/snake/snake_gui.c +++ /dev/null @@ -1,397 +0,0 @@ -#include -#include - -#include -#include -#include -#include -#include - -#include "snake.h" - -#define LATTICE_SIZE (20) -#define FOOD_MAX (8) - -#define WALL_COLOR RTGUI_RGB(255, 0, 0) -#define SNAKE_COLOR RTGUI_RGB(0, 100, 200) -#define SNAKE_HEAD_COLOR RTGUI_RGB(180, 70, 130) -#define BACKGROUND_COLOR RTGUI_RGB(153, 153, 0) -#define FOOD_COLOR RTGUI_RGB(128, 0, 0) - -static rtgui_timer_t *timer; -static rt_size_t room_size_x, room_size_y; -static rt_size_t lattice_size_x, lattice_size_y; -static struct rtgui_rect room_rect, lattice_rect; - -map_t *map; -SNAKE_DIR run_state; -rt_int32_t snake_len; -rt_int32_t food_num; -point_t second_node; - -static void snake_fill_lattice(struct rtgui_dc *dc, - rt_uint32_t x, - rt_uint32_t y, - rtgui_color_t color) -{ - struct rtgui_rect rect; - - // coordinate conversion - y = (lattice_size_y - 1) - y; - - RTGUI_DC_BC(dc) = color; - - rect.x1 = lattice_rect.x1 + (LATTICE_SIZE * x); - rect.x2 = rect.x1 + LATTICE_SIZE; - rect.x1 += 2; - - rect.y1 = lattice_rect.y1 + (LATTICE_SIZE * y); - rect.y2 = rect.y1 + LATTICE_SIZE; - rect.y1 += 2; - - rtgui_dc_fill_rect(dc, &rect); -} - -static void snake_draw(struct rtgui_widget *widget) -{ - struct rtgui_dc *dc; - struct rtgui_rect rect; - rt_uint32_t i; - - dc = rtgui_dc_begin_drawing(widget); - if (dc == RT_NULL) - { - rt_kprintf("dc == RT_NULL\r\n"); - return; - } - - /* get room size, run once frist. */ - if ((room_size_x == 0) || (room_size_y == 0)) - { - rt_size_t tmp; - - rtgui_widget_get_rect(widget, &rect); - rt_kprintf("rect => x1:%d x2:%d, y1:%d y2:%d\r\n", rect.x1, rect.x2, rect.y1, rect.y2); - - room_size_x = rect.x2 - rect.x1; - room_size_y = rect.y2 - rect.y1; - memcpy(&room_rect, &rect, sizeof(struct rtgui_rect)); - rt_kprintf("room_rect => x1:%d x2:%d, y1:%d y2:%d\r\n", - room_rect.x1, room_rect.x2, - room_rect.y1, room_rect.y2); - - lattice_size_x = (room_rect.x2 - room_rect.x1) / LATTICE_SIZE; - lattice_size_y = (room_rect.y2 - room_rect.y1) / LATTICE_SIZE; - lattice_size_x -= 2; - lattice_size_y -= 2; - rt_kprintf("lattice_size_x:%d lattice_size_y:%d\r\n", - lattice_size_x, - lattice_size_y); - - tmp = (room_rect.x2 - room_rect.x1) - (LATTICE_SIZE * lattice_size_x); - lattice_rect.x1 = room_rect.x1 + (tmp / 2); - lattice_rect.x2 = lattice_rect.x1 + (LATTICE_SIZE * lattice_size_x); - - tmp = (room_rect.y2 - room_rect.y1) - (LATTICE_SIZE * lattice_size_y); - lattice_rect.y1 = room_rect.y1 + (tmp / 2); - lattice_rect.y2 = lattice_rect.y1 + (LATTICE_SIZE * lattice_size_y); - rt_kprintf("lattice_rect => x1:%d x2:%d, y1:%d y2:%d\r\n", - lattice_rect.x1, lattice_rect.x2, - lattice_rect.y1, lattice_rect.y2); - - /* create snake. */ - { - point_t start; - map = map_init(lattice_size_x, lattice_size_y); - if (map != RT_NULL) - { - start.x = snake_init_pointx; - start.y = snake_init_pointy; - run_state = SNAKE_DIR_DOWN; - - if (snake_init(&start, snake_length_init, run_state, map)) - { - food_num = 1; - food_init(map, food_num); - } - else - { - map_deinit(map); - map = RT_NULL; - } - } - } - } - - RTGUI_DC_BC(dc) = BACKGROUND_COLOR; - rtgui_dc_fill_rect(dc, &room_rect); - - memcpy(&rect, &lattice_rect, sizeof(struct rtgui_rect)); - rect.x2 += 1; - rect.y2 += 1; - RTGUI_DC_FC(dc) = WALL_COLOR; - rtgui_dc_draw_rect(dc, &rect); - - for (i = 1; i < lattice_size_y; i++) - { - memcpy(&rect, &lattice_rect, sizeof(struct rtgui_rect)); - rect.x1 += 1; - rect.x2 -= 1; - rtgui_dc_draw_horizontal_line(dc, rect.x1, rect.x2, - rect.y1 + (LATTICE_SIZE * i)); - } - - for (i = 1; i < lattice_size_x; i++) - { - memcpy(&rect, &lattice_rect, sizeof(struct rtgui_rect)); - rect.y1 += 1; - rect.y2 -= 1; - rtgui_dc_draw_vertical_line(dc, rect.x1 + (LATTICE_SIZE * i), - rect.y1, rect.y2); - } - - /* draw snake. */ - { - rt_int32_t x, y; - rt_bool_t first_node = RT_TRUE; - - for (y = 0; y < map->height; y++) - { - for (x = 0; x < map->width; x++) - { - switch (map->range[y * map->width + x]) - { - case NORMAL: - break; - case FOOD: - snake_fill_lattice(dc, x, y, FOOD_COLOR); - break; - case OVER: - if (first_node) - { - first_node = RT_FALSE; - second_node.x = x; - second_node.y = y; - snake_fill_lattice(dc, x, y, SNAKE_HEAD_COLOR); - } - else - { - snake_fill_lattice(dc, x, y, SNAKE_COLOR); - } - break; - } - } - - } - } - - rtgui_dc_end_drawing(dc); - - return; -} - -static void snake_update(struct rtgui_widget *widget) -{ - struct rtgui_dc *dc; - rt_int32_t x, y; - rt_uint32_t i; - - dc = rtgui_dc_begin_drawing(widget); - if (dc == RT_NULL) - { - rt_kprintf("dc == RT_NULL\r\n"); - return; - } - - snake_fill_lattice(dc, second_node.x, second_node.y, SNAKE_COLOR); - second_node = map->snake_flush[0]; - - for (i = 0; i < 3; i++) - { - if (i < 2) - { - x = map->snake_flush[i].x; - y = map->snake_flush[i].y; - } - else - { - x = map->food_flush[0].x; - y = map->food_flush[0].y; - } - - if ((x >= 0) && (y >= 0)) - { - switch (map->range[(map->width * y) + x]) - { - case NORMAL: - snake_fill_lattice(dc, x, y, BACKGROUND_COLOR); - break; - case FOOD: - snake_fill_lattice(dc, x, y, FOOD_COLOR); - break; - case OVER: - if (0 == i) - snake_fill_lattice(dc, x, y, SNAKE_HEAD_COLOR); - else - snake_fill_lattice(dc, x, y, SNAKE_COLOR); - break; - } - } - } - - rtgui_dc_end_drawing(dc); - return; -} - -static void snake_handler(struct rtgui_widget *widget, rtgui_event_t *event) -{ - struct rtgui_event_kbd *ekbd; - - ekbd = (struct rtgui_event_kbd *) event; - if (ekbd->type == RTGUI_KEYDOWN) - { - switch (ekbd->key) - { - case RTGUIK_UP: - rt_kprintf("RTGUIK_UP\r\n"); - run_state = SNAKE_DIR_UP; - break; - case RTGUIK_DOWN: - rt_kprintf("RTGUIK_DOWN\r\n"); - run_state = SNAKE_DIR_DOWN; - break; - case RTGUIK_LEFT: - rt_kprintf("RTGUIK_LEFT\r\n"); - run_state = SNAKE_DIR_LEFT; - break; - case RTGUIK_RIGHT: - rt_kprintf("RTGUIK_RIGHT\r\n"); - run_state = SNAKE_DIR_RIGHT; - break; - default: - break; - } - } -} - -static rt_bool_t event_handler(struct rtgui_object *object, rtgui_event_t *event) -{ - struct rtgui_widget *widget = RTGUI_WIDGET(object); - - rt_kprintf("event_handler\r\n"); - - if (event->type == RTGUI_EVENT_PAINT) - { - rt_kprintf("RTGUI_EVENT_PAINT\r\n"); - rtgui_win_event_handler((struct rtgui_object *)object, event); - snake_draw(widget); - rtgui_timer_start(timer); - } - else if (event->type == RTGUI_EVENT_SHOW) - { - rt_kprintf("RTGUI_EVENT_SHOW\r\n"); - rtgui_win_event_handler((struct rtgui_object *)object, event); - snake_draw(widget); - rtgui_timer_start(timer); - } - else if (event->type == RTGUI_EVENT_HIDE) - { - rt_kprintf("RTGUI_EVENT_HIDE\r\n"); - rtgui_win_event_handler((struct rtgui_object *)object, event); - rtgui_timer_stop(timer); - } - else if (event->type == RTGUI_EVENT_WIN_DEACTIVATE) - { - rt_kprintf("RTGUI_EVENT_WIN_DEACTIVATE\r\n"); - rtgui_win_event_handler((struct rtgui_object *)object, event); - rtgui_timer_stop(timer); - } - else if (event->type == RTGUI_EVENT_KBD) - { - rtgui_win_event_handler((struct rtgui_object *)object, event); - snake_handler(widget, event); - } - else - { - rt_kprintf("event->type:%d\r\n", event->type); - return rtgui_win_event_handler((struct rtgui_object *)object, event); - } - - return RT_FALSE; -} - -static void timeout(struct rtgui_timer *timer, void *parameter) -{ - struct rtgui_widget *widget; - SYS_STE ret; - - if (!map) - return; - - ret = snake_step(run_state, map); - if (OVER == ret) - return; - - if (FOOD == ret) - { - snake_len++; - if (snake_len >= (map->width * map->height) / 3) - { - point_t start; - - start.x = snake_init_pointx; - start.y = snake_init_pointy; - run_state = SNAKE_DIR_DOWN; - snake_len = snake_length_init; - - if (!snake_restart(&start, snake_len, run_state, map)) - { - map_deinit(map); - snake_deinit(); - map = RT_NULL; - } - } - - food_init(map, 1); - } - - widget = RTGUI_WIDGET(parameter); - snake_update(widget); -} - -void main(void) -{ - struct rtgui_app *application; - struct rtgui_win *win; - rtgui_rect_t rect; - - application = rtgui_app_create("sanke_app"); - if (application != RT_NULL) - { - rtgui_get_screen_rect(&rect); - rtgui_set_mainwin_rect(&rect); - win = rtgui_mainwin_create(RT_NULL, - "sanke_win", - RTGUI_WIN_STYLE_MAINWIN | RTGUI_WIN_STYLE_DESTROY_ON_CLOSE); - if (win == RT_NULL) - { - rt_kprintf("sanke_win create fail!\r\n"); - return; - } - - rtgui_object_set_event_handler(RTGUI_OBJECT(win), event_handler); - - timer = rtgui_timer_create(RT_TICK_PER_SECOND / 2, - RT_TIMER_FLAG_PERIODIC, - timeout, - (void *)win); - - rtgui_win_show(win, RT_TRUE); - - //退出后才返回 - map_deinit(map); - snake_deinit(); - food_deinit(); - rtgui_app_destroy(application); - } -} diff --git a/bsp/simulator/testdll/var/Sconscript b/bsp/simulator/testdll/var/Sconscript deleted file mode 100644 index d8dd99964e..0000000000 --- a/bsp/simulator/testdll/var/Sconscript +++ /dev/null @@ -1,7 +0,0 @@ -import rtconfig -Import('RTT_ROOT') -from building import * - -src = Glob('*.c') -group = DefineGroup('', src, depend = ['']) -Return('group') \ No newline at end of file diff --git a/bsp/simulator/testdll/var/var.c b/bsp/simulator/testdll/var/var.c deleted file mode 100644 index 41eba40f38..0000000000 --- a/bsp/simulator/testdll/var/var.c +++ /dev/null @@ -1,20 +0,0 @@ -#include - -/* rtgui\common\rtgui_object.c */ -_declspec(dllimport) void * _rtgui_object; - -/* rtgui\common\color.c */ -_declspec(dllimport) rt_uint32_t blue; -//extern rt_uint32_t * green; - -int main(void) -{ - int i; - - //rt_kprintf("green = %x, *green", green, *(rt_uint32_t *)green); - rt_kprintf("blue = %x\n", blue); - rt_kprintf("_rtgui_object = %x\n", _rtgui_object); - - return 0; -} - From 1e4bcaca3e99a5006ed6674cde288c91ffa4dd2e Mon Sep 17 00:00:00 2001 From: Bernard Xiong Date: Thu, 1 Oct 2015 11:34:10 +0800 Subject: [PATCH 11/36] [BSP] remove rtgui_demo in the simulator BSP --- bsp/simulator/rtgui_demo/SConscript | 12 - bsp/simulator/rtgui_demo/snake/SConscript | 10 - bsp/simulator/rtgui_demo/snake/snake.c | 271 -------------- bsp/simulator/rtgui_demo/snake/snake.h | 68 ---- bsp/simulator/rtgui_demo/snake/snake_gui.c | 400 --------------------- 5 files changed, 761 deletions(-) delete mode 100644 bsp/simulator/rtgui_demo/SConscript delete mode 100644 bsp/simulator/rtgui_demo/snake/SConscript delete mode 100644 bsp/simulator/rtgui_demo/snake/snake.c delete mode 100644 bsp/simulator/rtgui_demo/snake/snake.h delete mode 100644 bsp/simulator/rtgui_demo/snake/snake_gui.c diff --git a/bsp/simulator/rtgui_demo/SConscript b/bsp/simulator/rtgui_demo/SConscript deleted file mode 100644 index 0992612410..0000000000 --- a/bsp/simulator/rtgui_demo/SConscript +++ /dev/null @@ -1,12 +0,0 @@ -from building import * - -cwd = GetCurrentDir() -objs = [] -list = os.listdir(cwd) - -for d in list: - path = os.path.join(cwd, d) - if os.path.isfile(os.path.join(path, 'SConscript')): - objs = objs + SConscript(os.path.join(d, 'SConscript')) - -Return('objs') diff --git a/bsp/simulator/rtgui_demo/snake/SConscript b/bsp/simulator/rtgui_demo/snake/SConscript deleted file mode 100644 index a5734dc40c..0000000000 --- a/bsp/simulator/rtgui_demo/snake/SConscript +++ /dev/null @@ -1,10 +0,0 @@ -import rtconfig -from building import * - -src = Glob('*.c') + Glob('*.cpp') -cwd = GetCurrentDir() - -CPPPATH = [cwd] -group = DefineGroup('snake', src, depend = ['RT_USING_RTGUI'], CPPPATH=CPPPATH) - -Return('group') diff --git a/bsp/simulator/rtgui_demo/snake/snake.c b/bsp/simulator/rtgui_demo/snake/snake.c deleted file mode 100644 index 87e1c8b36f..0000000000 --- a/bsp/simulator/rtgui_demo/snake/snake.c +++ /dev/null @@ -1,271 +0,0 @@ -#include -#include -#include -#include "snake.h" - -#define ASSERT_RET(x, ret) \ - do{ \ - if (x) \ - return ret; \ - }while(0) - -rt_list_t snake_head; -SNAKE_DIR prevdir, newdir; - -static SNAKE_DIR dir_adjust(SNAKE_DIR dir) -{ - if ((SNAKE_DIR_UP == prevdir && SNAKE_DIR_DOWN != dir) - || (SNAKE_DIR_DOWN == prevdir && SNAKE_DIR_UP != dir) - || (SNAKE_DIR_LEFT == prevdir && SNAKE_DIR_RIGHT != dir) - || (SNAKE_DIR_RIGHT == prevdir && SNAKE_DIR_LEFT != dir) - ) - { - newdir = dir; - } - else - { - rt_kprintf("dirction change error\n\r"); - } - - return newdir; -} - -static void across_XY(point_t *node, const map_t *map) -{ - RT_ASSERT(node != RT_NULL && map != RT_NULL); - - // 如果长度超出当前边框则可以穿越墙到对面 - node->x = (node->x + map->width) % map->width; - node->y = (node->y + map->height) % map->height; -} - -static SYS_STE node_update(snake_t *tail, const point_t *node, map_t *map) -{ - SYS_STE ret; - point_t *pos; - - RT_ASSERT(tail != RT_NULL && node != RT_NULL && map != RT_NULL); - - pos = map->snake_flush; - pos[0].x = pos[0].y = -1; - pos[1].x = pos[1].y = -1; - - ret = (SYS_STE)map->range[node->y * map->width + node->x]; - - if (FOOD == map->range[node->y * map->width + node->x]) - { - // 吃一个食物增加一个节点 - snake_t *new = (snake_t *)rt_malloc(sizeof(snake_t)); - if (!new) - return NORMAL; - - pos[0] = *node; - new->body = *node; - rt_list_insert_after(&snake_head, &new->list); - } - else if (NORMAL == map->range[node->y * map->width + node->x]) - { - // 将尾巴修改后拿到头部,其他不变 - rt_list_remove(&tail->list); - map->range[tail->body.y * map->width + tail->body.x] = NORMAL; - - pos[0] = *node; - pos[1] = tail->body; - - tail->body = *node; - rt_list_insert_after(&snake_head, &tail->list); - } - - map->range[node->y * map->width + node->x] = OVER; - - if (ret != OVER) - prevdir = newdir; - - return ret; -} - - -map_t *map_init(rt_uint32_t width, rt_uint32_t heigth) -{ - map_t *map = rt_malloc(sizeof(map_t)); - - if (map != RT_NULL) - { - map->range = rt_malloc(heigth * width); - - if (!map->range) - { - rt_free(map); - map = RT_NULL; - } - else - { - map->width = width; - map->height = heigth; - memset(map->range, NORMAL, heigth * width); - } - } - - return map; -} - -// 构造一条指定长度的蛇在指定点 -rt_bool_t snake_init(const point_t *start, const int length, const SNAKE_DIR dir, map_t *map) -{ - rt_int32_t i; - rt_int32_t inc_x, inc_y; - point_t old = *start; - - ASSERT_RET(!map || !start, RT_FALSE); - - rt_list_init(&snake_head); - - if (dir == SNAKE_DIR_UP || dir == SNAKE_DIR_DOWN) - { - if (map->height <= length) - return RT_FALSE; - - inc_x = 0; - inc_y = dir == SNAKE_DIR_DOWN ? 1 : -1; // 反向延长身子,头部在指定位置 - old.y -= inc_y; - } - else - { - if (map->width <= length) - return RT_FALSE; - - inc_y = 0; - inc_x = dir == SNAKE_DIR_RIGHT ? -1 : 1; - old.x -= inc_x; - } - - for (i = 0; i < length; i++) - { - snake_t *new = (snake_t *)rt_malloc(sizeof(snake_t)); - if (!new) - return RT_FALSE; - - new->body.y = inc_y + old.y; - new->body.x = inc_x + old.x; - - // 如果长度超出当前边框则可以穿越墙到对面 - across_XY(&new->body, map); - - map->range[new->body.y * map->width + new->body.x] = OVER; - - old = new->body; - rt_list_insert_before(&snake_head, &new->list); - } - - prevdir = dir; - - return RT_TRUE; -} - -// 构造出食物 -rt_bool_t food_init(map_t *map, rt_uint32_t max_num) -{ - point_t food; - -#ifndef FOOD_TIMEOUT -#define FOOD_TIMEOUT 10 -#endif - - rt_uint32_t timeout, num; - - ASSERT_RET(!map, RT_FALSE); - - num = 0; - timeout = rt_tick_get(); - srand(rand()); - - map->food_flush[0].x = map->food_flush[0].y = -1; - - do - { - food.x = rand() % map->width; - food.y = rand() % map->height; - - if (map->range[food.y * map->width + food.x] == NORMAL) - { - map->food_flush[0] = food; - map->range[food.y * map->width + food.x] = FOOD; - num++; - } - } - while (num < max_num && rt_tick_get() - timeout < FOOD_TIMEOUT); - - return num; -} - -void map_deinit(map_t *map) -{ - if (map) - { - if (map->range) - { - rt_free(map->range); - map->range = RT_NULL; - } - rt_free(map); - } -} - -void snake_deinit(void) -{ - snake_t *node; - - while (!rt_list_isempty(&snake_head)) - { - node = rt_list_entry(snake_head.prev, snake_t, list); - rt_list_remove(&node->list); - rt_free(node); - } -} - -void food_deinit(void) -{ - -} - -SYS_STE snake_step(SNAKE_DIR dir, map_t *map) -{ - snake_t *tail, *head; - point_t node; - - ASSERT_RET(!map, RT_FALSE); - - dir = dir_adjust(dir); - - // 取出头尾两个节点,其他节点不需要改变 - tail = rt_list_entry(snake_head.prev, snake_t, list); - head = rt_list_entry(snake_head.next, snake_t, list); - - node = head->body; - - // 构造一个新的蛇头坐标 - switch (dir) - { - case SNAKE_DIR_UP: - case SNAKE_DIR_DOWN: - node.y = head->body.y + (dir == SNAKE_DIR_DOWN ? -1 : 1); - break; - case SNAKE_DIR_LEFT: - case SNAKE_DIR_RIGHT: - node.x = head->body.x + (dir == SNAKE_DIR_RIGHT ? 1 : -1); - break; - } - across_XY(&node, map); - - return node_update(tail, &node, map); -} - -rt_bool_t snake_restart(const point_t *start, const int length, const SNAKE_DIR dir, map_t *map) -{ - ASSERT_RET(!map || !start, RT_FALSE); - - snake_deinit(); - memset(map->range, NORMAL, map->width * map->height); - - return snake_init(start, length, dir, map); -} diff --git a/bsp/simulator/rtgui_demo/snake/snake.h b/bsp/simulator/rtgui_demo/snake/snake.h deleted file mode 100644 index 557d4d9241..0000000000 --- a/bsp/simulator/rtgui_demo/snake/snake.h +++ /dev/null @@ -1,68 +0,0 @@ -#ifndef _SNAKE_H_ -#define _SNAKE_H_ - -#include - -#define snake_length_max 20 //最大蛇长 -#define snake_length_init 3 //初始化蛇长 -#define snake_room_size_hight 8 //房子高 0-255 建议>8 -#define snake_room_size_widht 8 //房子宽 0-255 建议>8 - -#define snake_init_pointx 1 -#define snake_init_pointy 2 - -typedef struct -{ - rt_int32_t x, y; -} point_t; - -typedef struct -{ - rt_int32_t width; // max x - rt_int32_t height; // max y - rt_uint8_t *range; // map, map->range[y * map->width + x] - point_t snake_flush[2]; - point_t food_flush[1]; -} map_t; - -typedef enum -{ - SNAKE_DIR_UP, - SNAKE_DIR_DOWN, - SNAKE_DIR_LEFT, - SNAKE_DIR_RIGHT -} SNAKE_DIR; - -typedef enum -{ - FOOD, // 吃到水果 - OVER, // 咬到自身 - NORMAL // 正常行动 -} SYS_STE; - -typedef struct -{ - point_t body; - rt_list_t list; -} snake_t; - -// 构造一个地图 -map_t *map_init(rt_uint32_t width, rt_uint32_t heigth); - -// 构造一条指定长度的蛇在指定点 -rt_bool_t snake_init(const point_t *start, const int length, const SNAKE_DIR dir, map_t *map); - -// 构造出食物 -rt_bool_t food_init(map_t *map, rt_uint32_t max_num); - -void map_deinit(map_t *map); - -void snake_deinit(void); - -void food_deinit(void); - -SYS_STE snake_step(SNAKE_DIR dir, map_t *map); - -rt_bool_t snake_restart(const point_t *start, const int length, const SNAKE_DIR dir, map_t *map); - -#endif diff --git a/bsp/simulator/rtgui_demo/snake/snake_gui.c b/bsp/simulator/rtgui_demo/snake/snake_gui.c deleted file mode 100644 index 0df1ba7a87..0000000000 --- a/bsp/simulator/rtgui_demo/snake/snake_gui.c +++ /dev/null @@ -1,400 +0,0 @@ -#include -#include - -#include -#include -#include -#include -#include - -#include "snake.h" - -#define LATTICE_SIZE (20) -#define FOOD_MAX (8) - -#define WALL_COLOR RTGUI_RGB(255, 0, 0) -#define SNAKE_COLOR RTGUI_RGB(0, 100, 200) -#define SNAKE_HEAD_COLOR RTGUI_RGB(180, 70, 130) -#define BACKGROUND_COLOR RTGUI_RGB(153, 153, 0) -#define FOOD_COLOR RTGUI_RGB(128, 0, 0) - -static rtgui_timer_t *timer; -static rt_size_t room_size_x, room_size_y; -static rt_size_t lattice_size_x, lattice_size_y; -static struct rtgui_rect room_rect, lattice_rect; - -map_t *map; -SNAKE_DIR run_state; -rt_int32_t snake_len; -rt_int32_t food_num; -point_t second_node; - -static void snake_fill_lattice(struct rtgui_dc *dc, - rt_uint32_t x, - rt_uint32_t y, - rtgui_color_t color) -{ - struct rtgui_rect rect; - - // coordinate conversion - y = (lattice_size_y - 1) - y; - - RTGUI_DC_BC(dc) = color; - - rect.x1 = lattice_rect.x1 + (LATTICE_SIZE * x); - rect.x2 = rect.x1 + LATTICE_SIZE; - rect.x1 += 2; - - rect.y1 = lattice_rect.y1 + (LATTICE_SIZE * y); - rect.y2 = rect.y1 + LATTICE_SIZE; - rect.y1 += 2; - - rtgui_dc_fill_rect(dc, &rect); -} - -static void snake_draw(struct rtgui_widget *widget) -{ - struct rtgui_dc *dc; - struct rtgui_rect rect; - rt_uint32_t i; - - dc = rtgui_dc_begin_drawing(widget); - if (dc == RT_NULL) - { - rt_kprintf("dc == RT_NULL\r\n"); - return; - } - - /* get room size, run once frist. */ - if ((room_size_x == 0) || (room_size_y == 0)) - { - rt_size_t tmp; - - rtgui_widget_get_rect(widget, &rect); - rt_kprintf("rect => x1:%d x2:%d, y1:%d y2:%d\r\n", rect.x1, rect.x2, rect.y1, rect.y2); - - room_size_x = rect.x2 - rect.x1; - room_size_y = rect.y2 - rect.y1; - memcpy(&room_rect, &rect, sizeof(struct rtgui_rect)); - rt_kprintf("room_rect => x1:%d x2:%d, y1:%d y2:%d\r\n", - room_rect.x1, room_rect.x2, - room_rect.y1, room_rect.y2); - - lattice_size_x = (room_rect.x2 - room_rect.x1) / LATTICE_SIZE; - lattice_size_y = (room_rect.y2 - room_rect.y1) / LATTICE_SIZE; - lattice_size_x -= 2; - lattice_size_y -= 2; - rt_kprintf("lattice_size_x:%d lattice_size_y:%d\r\n", - lattice_size_x, - lattice_size_y); - - tmp = (room_rect.x2 - room_rect.x1) - (LATTICE_SIZE * lattice_size_x); - lattice_rect.x1 = room_rect.x1 + (tmp / 2); - lattice_rect.x2 = lattice_rect.x1 + (LATTICE_SIZE * lattice_size_x); - - tmp = (room_rect.y2 - room_rect.y1) - (LATTICE_SIZE * lattice_size_y); - lattice_rect.y1 = room_rect.y1 + (tmp / 2); - lattice_rect.y2 = lattice_rect.y1 + (LATTICE_SIZE * lattice_size_y); - rt_kprintf("lattice_rect => x1:%d x2:%d, y1:%d y2:%d\r\n", - lattice_rect.x1, lattice_rect.x2, - lattice_rect.y1, lattice_rect.y2); - - /* create snake. */ - { - point_t start; - map = map_init(lattice_size_x, lattice_size_y); - if (map != RT_NULL) - { - start.x = snake_init_pointx; - start.y = snake_init_pointy; - run_state = SNAKE_DIR_DOWN; - - if (snake_init(&start, snake_length_init, run_state, map)) - { - food_num = 1; - food_init(map, food_num); - } - else - { - map_deinit(map); - map = RT_NULL; - } - } - } - } - - RTGUI_DC_BC(dc) = BACKGROUND_COLOR; - rtgui_dc_fill_rect(dc, &room_rect); - - memcpy(&rect, &lattice_rect, sizeof(struct rtgui_rect)); - rect.x2 += 1; - rect.y2 += 1; - RTGUI_DC_FC(dc) = WALL_COLOR; - rtgui_dc_draw_rect(dc, &rect); - - for (i = 1; i < lattice_size_y; i++) - { - memcpy(&rect, &lattice_rect, sizeof(struct rtgui_rect)); - rect.x1 += 1; - rect.x2 -= 1; - rtgui_dc_draw_horizontal_line(dc, rect.x1, rect.x2, - rect.y1 + (LATTICE_SIZE * i)); - } - - for (i = 1; i < lattice_size_x; i++) - { - memcpy(&rect, &lattice_rect, sizeof(struct rtgui_rect)); - rect.y1 += 1; - rect.y2 -= 1; - rtgui_dc_draw_vertical_line(dc, rect.x1 + (LATTICE_SIZE * i), - rect.y1, rect.y2); - } - - /* draw snake. */ - { - rt_int32_t x, y; - rt_bool_t first_node = RT_TRUE; - - for (y = 0; y < map->height; y++) - { - for (x = 0; x < map->width; x++) - { - switch (map->range[y * map->width + x]) - { - case NORMAL: - break; - case FOOD: - snake_fill_lattice(dc, x, y, FOOD_COLOR); - break; - case OVER: - if (first_node) - { - first_node = RT_FALSE; - second_node.x = x; - second_node.y = y; - snake_fill_lattice(dc, x, y, SNAKE_HEAD_COLOR); - } - else - { - snake_fill_lattice(dc, x, y, SNAKE_COLOR); - } - break; - } - } - - } - } - - rtgui_dc_end_drawing(dc); - - return; -} - -static void snake_update(struct rtgui_widget *widget) -{ - struct rtgui_dc *dc; - rt_int32_t x, y; - rt_uint32_t i; - - dc = rtgui_dc_begin_drawing(widget); - if (dc == RT_NULL) - { - rt_kprintf("dc == RT_NULL\r\n"); - return; - } - - snake_fill_lattice(dc, second_node.x, second_node.y, SNAKE_COLOR); - second_node = map->snake_flush[0]; - - for (i = 0; i < 3; i++) - { - if (i < 2) - { - x = map->snake_flush[i].x; - y = map->snake_flush[i].y; - } - else - { - x = map->food_flush[0].x; - y = map->food_flush[0].y; - } - - if ((x >= 0) && (y >= 0)) - { - switch (map->range[(map->width * y) + x]) - { - case NORMAL: - snake_fill_lattice(dc, x, y, BACKGROUND_COLOR); - break; - case FOOD: - snake_fill_lattice(dc, x, y, FOOD_COLOR); - break; - case OVER: - if (0 == i) - snake_fill_lattice(dc, x, y, SNAKE_HEAD_COLOR); - else - snake_fill_lattice(dc, x, y, SNAKE_COLOR); - break; - } - } - } - - rtgui_dc_end_drawing(dc); - return; -} - -static void snake_handler(struct rtgui_widget *widget, rtgui_event_t *event) -{ - struct rtgui_event_kbd *ekbd; - - ekbd = (struct rtgui_event_kbd *) event; - if (ekbd->type == RTGUI_KEYDOWN) - { - switch (ekbd->key) - { - case RTGUIK_UP: - rt_kprintf("RTGUIK_UP\r\n"); - run_state = SNAKE_DIR_UP; - break; - case RTGUIK_DOWN: - rt_kprintf("RTGUIK_DOWN\r\n"); - run_state = SNAKE_DIR_DOWN; - break; - case RTGUIK_LEFT: - rt_kprintf("RTGUIK_LEFT\r\n"); - run_state = SNAKE_DIR_LEFT; - break; - case RTGUIK_RIGHT: - rt_kprintf("RTGUIK_RIGHT\r\n"); - run_state = SNAKE_DIR_RIGHT; - break; - default: - break; - } - } -} - -static rt_bool_t event_handler(struct rtgui_object *object, rtgui_event_t *event) -{ - struct rtgui_widget *widget = RTGUI_WIDGET(object); - - rt_kprintf("event_handler\r\n"); - - if (event->type == RTGUI_EVENT_PAINT) - { - rt_kprintf("RTGUI_EVENT_PAINT\r\n"); - rtgui_win_event_handler((struct rtgui_object *)object, event); - snake_draw(widget); - rtgui_timer_start(timer); - } - else if (event->type == RTGUI_EVENT_SHOW) - { - rt_kprintf("RTGUI_EVENT_SHOW\r\n"); - rtgui_win_event_handler((struct rtgui_object *)object, event); - snake_draw(widget); - rtgui_timer_start(timer); - } - else if (event->type == RTGUI_EVENT_HIDE) - { - rt_kprintf("RTGUI_EVENT_HIDE\r\n"); - rtgui_win_event_handler((struct rtgui_object *)object, event); - rtgui_timer_stop(timer); - } - else if (event->type == RTGUI_EVENT_WIN_DEACTIVATE) - { - rt_kprintf("RTGUI_EVENT_WIN_DEACTIVATE\r\n"); - rtgui_win_event_handler((struct rtgui_object *)object, event); - rtgui_timer_stop(timer); - } - else if (event->type == RTGUI_EVENT_KBD) - { - rtgui_win_event_handler((struct rtgui_object *)object, event); - snake_handler(widget, event); - } - else - { - rt_kprintf("event->type:%d\r\n", event->type); - return rtgui_win_event_handler((struct rtgui_object *)object, event); - } - - return RT_FALSE; -} - -static void timeout(struct rtgui_timer *timer, void *parameter) -{ - struct rtgui_widget *widget; - SYS_STE ret; - - if (!map) - return; - - ret = snake_step(run_state, map); - if (OVER == ret) - return; - - if (FOOD == ret) - { - snake_len++; - if (snake_len >= (map->width * map->height) / 3) - { - point_t start; - - start.x = snake_init_pointx; - start.y = snake_init_pointy; - run_state = SNAKE_DIR_DOWN; - snake_len = snake_length_init; - - if (!snake_restart(&start, snake_len, run_state, map)) - { - map_deinit(map); - snake_deinit(); - map = RT_NULL; - } - } - - food_init(map, 1); - } - - widget = RTGUI_WIDGET(parameter); - snake_update(widget); -} - -void snake_main(void) -{ - struct rtgui_app *application; - struct rtgui_win *win; - rtgui_rect_t rect; - - application = rtgui_app_create("sanke_app"); - if (application != RT_NULL) - { - rtgui_get_screen_rect(&rect); - rtgui_set_mainwin_rect(&rect); - win = rtgui_mainwin_create(RT_NULL, - "sanke_win", - RTGUI_WIN_STYLE_MAINWIN | RTGUI_WIN_STYLE_DESTROY_ON_CLOSE); - if (win == RT_NULL) - { - rt_kprintf("sanke_win create fail!\r\n"); - return; - } - - rtgui_object_set_event_handler(RTGUI_OBJECT(win), event_handler); - - timer = rtgui_timer_create(RT_TICK_PER_SECOND / 2, - RT_TIMER_FLAG_PERIODIC, - timeout, - (void *)win); - - rtgui_win_show(win, RT_TRUE); - - //退出后才返回 - map_deinit(map); - snake_deinit(); - food_deinit(); - rtgui_app_destroy(application); - } -} - -#include -FINSH_FUNCTION_EXPORT(snake_main, snake run) From d2ec1f3eaac98e693414e46fe236edf140c5e6f0 Mon Sep 17 00:00:00 2001 From: Bernard Xiong Date: Thu, 1 Oct 2015 06:46:52 +0000 Subject: [PATCH 12/36] [DFS] remove st_blksize in the struct stat --- bsp/efm32/copy_this_file_dfs_elm.c | 1 - bsp/simulator/drivers/dfs_win32.c | 2 -- components/dfs/filesystems/devfs/devfs.c | 6 ++---- components/dfs/filesystems/elmfat/dfs_elm.c | 1 - components/dfs/filesystems/jffs2/dfs_jffs2.c | 3 +-- components/dfs/filesystems/nfs/dfs_nfs.c | 1 - components/dfs/filesystems/ramfs/dfs_ramfs.c | 1 - components/dfs/filesystems/romfs/dfs_romfs.c | 1 - components/dfs/filesystems/uffs/dfs_uffs.c | 3 +-- components/dfs/include/dfs_def.h | 1 - components/dfs/src/dfs_file.c | 1 - components/dfs/src/dfs_posix.c | 1 - components/external/SQLite-3.8.1/src/os_rtthread.c | 2 +- 13 files changed, 5 insertions(+), 19 deletions(-) diff --git a/bsp/efm32/copy_this_file_dfs_elm.c b/bsp/efm32/copy_this_file_dfs_elm.c index eea9ff7e6d..2f648750c9 100644 --- a/bsp/efm32/copy_this_file_dfs_elm.c +++ b/bsp/efm32/copy_this_file_dfs_elm.c @@ -641,7 +641,6 @@ int dfs_elm_stat(struct dfs_filesystem *fs, const char *path, struct stat *st) st->st_size = file_info.fsize; st->st_mtime = file_info.ftime; - st->st_blksize = 512; } #if _USE_LFN diff --git a/bsp/simulator/drivers/dfs_win32.c b/bsp/simulator/drivers/dfs_win32.c index 8d6e7b0305..a0ebcf5e6e 100644 --- a/bsp/simulator/drivers/dfs_win32.c +++ b/bsp/simulator/drivers/dfs_win32.c @@ -505,8 +505,6 @@ static int dfs_win32_stat(struct dfs_filesystem *fs, const char *path, struct st st->st_mtime = time_tmp.QuadPart; } - st->st_blksize = 0; - FindClose(hFind); return 0; diff --git a/components/dfs/filesystems/devfs/devfs.c b/components/dfs/filesystems/devfs/devfs.c index 1f4569558f..fcbb738572 100644 --- a/components/dfs/filesystems/devfs/devfs.c +++ b/components/dfs/filesystems/devfs/devfs.c @@ -213,8 +213,7 @@ int dfs_device_fs_stat(struct dfs_filesystem *fs, const char *path, struct stat st->st_size = 0; st->st_mtime = 0; - st->st_blksize = 512; - + return DFS_STATUS_OK; } else @@ -238,8 +237,7 @@ int dfs_device_fs_stat(struct dfs_filesystem *fs, const char *path, struct stat st->st_size = 0; st->st_mtime = 0; - st->st_blksize = 512; - + return DFS_STATUS_OK; } } diff --git a/components/dfs/filesystems/elmfat/dfs_elm.c b/components/dfs/filesystems/elmfat/dfs_elm.c index 3658a5dc80..ca2c082972 100644 --- a/components/dfs/filesystems/elmfat/dfs_elm.c +++ b/components/dfs/filesystems/elmfat/dfs_elm.c @@ -738,7 +738,6 @@ int dfs_elm_stat(struct dfs_filesystem *fs, const char *path, struct stat *st) st->st_mode &= ~(DFS_S_IWUSR | DFS_S_IWGRP | DFS_S_IWOTH); st->st_size = file_info.fsize; - st->st_blksize = 512; /* get st_mtime. */ { diff --git a/components/dfs/filesystems/jffs2/dfs_jffs2.c b/components/dfs/filesystems/jffs2/dfs_jffs2.c index 6516797544..78c7730136 100644 --- a/components/dfs/filesystems/jffs2/dfs_jffs2.c +++ b/components/dfs/filesystems/jffs2/dfs_jffs2.c @@ -331,7 +331,7 @@ static int dfs_jffs2_open(struct dfs_fd* file) return jffs2_result_to_dfs(result); } - /* save this pointer, it will be used when calling read(),write(), + /* save this pointer, it will be used when calling read()锟斤拷write(), flush(), lessk(), and will be rt_free when calling close()*/ file->data = jffs2_file; file->pos = jffs2_file->f_offset; @@ -686,7 +686,6 @@ static int dfs_jffs2_stat(struct dfs_filesystem* fs, const char *path, struct st st->st_dev = 0; st->st_size = s.st_size; st->st_mtime = s.st_mtime; - st->st_blksize = 1;//fixme: what's this field? return 0; } diff --git a/components/dfs/filesystems/nfs/dfs_nfs.c b/components/dfs/filesystems/nfs/dfs_nfs.c index 7ff5fef5f7..4bf96c2aeb 100644 --- a/components/dfs/filesystems/nfs/dfs_nfs.c +++ b/components/dfs/filesystems/nfs/dfs_nfs.c @@ -850,7 +850,6 @@ int nfs_stat(struct dfs_filesystem *fs, const char *path, struct stat *st) st->st_size = info->size; st->st_mtime = info->mtime.seconds; - st->st_blksize = 512; xdr_free((xdrproc_t)xdr_GETATTR3res, (char *)&res); xdr_free((xdrproc_t)xdr_nfs_fh3, (char *)handle); diff --git a/components/dfs/filesystems/ramfs/dfs_ramfs.c b/components/dfs/filesystems/ramfs/dfs_ramfs.c index fecebe4688..7533b6f192 100644 --- a/components/dfs/filesystems/ramfs/dfs_ramfs.c +++ b/components/dfs/filesystems/ramfs/dfs_ramfs.c @@ -292,7 +292,6 @@ int dfs_ramfs_stat(struct dfs_filesystem *fs, st->st_size = dirent->size; st->st_mtime = 0; - st->st_blksize = 512; return DFS_STATUS_OK; } diff --git a/components/dfs/filesystems/romfs/dfs_romfs.c b/components/dfs/filesystems/romfs/dfs_romfs.c index 65fc331466..1dd41b41eb 100644 --- a/components/dfs/filesystems/romfs/dfs_romfs.c +++ b/components/dfs/filesystems/romfs/dfs_romfs.c @@ -245,7 +245,6 @@ int dfs_romfs_stat(struct dfs_filesystem *fs, const char *path, struct stat *st) st->st_size = dirent->size; st->st_mtime = 0; - st->st_blksize = 512; return DFS_STATUS_OK; } diff --git a/components/dfs/filesystems/uffs/dfs_uffs.c b/components/dfs/filesystems/uffs/dfs_uffs.c index faaee0990e..87517aaaf5 100644 --- a/components/dfs/filesystems/uffs/dfs_uffs.c +++ b/components/dfs/filesystems/uffs/dfs_uffs.c @@ -347,7 +347,7 @@ static int dfs_uffs_open(struct dfs_fd* file) return uffs_result_to_dfs(uffs_get_error()); } - /* save this pointer, it will be used when calling read(),write(), + /* save this pointer, it will be used when calling read()锟斤拷write(), * flush(), seek(), and will be free when calling close()*/ file->data = (void *)fd; @@ -619,7 +619,6 @@ static int dfs_uffs_stat(struct dfs_filesystem* fs, const char *path, struct sta st->st_mtime = s.st_mtime; mtd = RT_MTD_NAND_DEVICE(fs->dev_id); - st->st_blksize = mtd->page_size; return 0; } diff --git a/components/dfs/include/dfs_def.h b/components/dfs/include/dfs_def.h index a73ff4ec8b..e509c4a3da 100644 --- a/components/dfs/include/dfs_def.h +++ b/components/dfs/include/dfs_def.h @@ -261,7 +261,6 @@ struct stat rt_uint16_t st_mode; rt_uint32_t st_size; rt_time_t st_mtime; - rt_uint32_t st_blksize; }; struct statfs diff --git a/components/dfs/src/dfs_file.c b/components/dfs/src/dfs_file.c index aebe2996c6..752933b66f 100644 --- a/components/dfs/src/dfs_file.c +++ b/components/dfs/src/dfs_file.c @@ -392,7 +392,6 @@ int dfs_file_stat(const char *path, struct stat *buf) buf->st_size = 0; buf->st_mtime = 0; - buf->st_blksize = 512; /* release full path */ rt_free(fullpath); diff --git a/components/dfs/src/dfs_posix.c b/components/dfs/src/dfs_posix.c index c379d5c969..52a9139d80 100644 --- a/components/dfs/src/dfs_posix.c +++ b/components/dfs/src/dfs_posix.c @@ -368,7 +368,6 @@ int fstat(int fildes, struct stat *buf) buf->st_size = d->size; buf->st_mtime = 0; - buf->st_blksize = 512; fd_put(d); diff --git a/components/external/SQLite-3.8.1/src/os_rtthread.c b/components/external/SQLite-3.8.1/src/os_rtthread.c index fb51b53685..6d57ed7098 100644 --- a/components/external/SQLite-3.8.1/src/os_rtthread.c +++ b/components/external/SQLite-3.8.1/src/os_rtthread.c @@ -1728,7 +1728,7 @@ static int fcntlSizeHint(rtthreadFile *pFile, i64 nByte){ ** is the same technique used by glibc to implement posix_fallocate() ** on systems that do not have a real fallocate() system call. */ - int nBlk = buf.st_blksize; /* File-system block size */ + int nBlk = 4096; // no blksize in RT-Thread, use 4096. /* File-system block size */ i64 iWrite; /* Next offset to write to */ if( robust_ftruncate(pFile->h, nSize) ){ From a65ee8ac451723e149a5b6d6d43ee1c3ac37549b Mon Sep 17 00:00:00 2001 From: Bernard Xiong Date: Fri, 2 Oct 2015 08:16:15 +0800 Subject: [PATCH 13/36] [BSP] disable module feature under simulator for Linux --- bsp/simulator/drivers/uart_console.c | 2 +- bsp/simulator/rtconfig.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bsp/simulator/drivers/uart_console.c b/bsp/simulator/drivers/uart_console.c index 283ac83a05..913daf2311 100644 --- a/bsp/simulator/drivers/uart_console.c +++ b/bsp/simulator/drivers/uart_console.c @@ -97,7 +97,7 @@ static void set_stty(void) tcsetattr(STDIN_FILENO, TCSANOW, &newt); } -static void restore_stty(void) +void restore_stty(void) { /* recover terminal's attribute */ tcsetattr(STDIN_FILENO, TCSANOW, &oldt); diff --git a/bsp/simulator/rtconfig.h b/bsp/simulator/rtconfig.h index 2555fc11da..aa839f5621 100755 --- a/bsp/simulator/rtconfig.h +++ b/bsp/simulator/rtconfig.h @@ -99,7 +99,7 @@ // // #define RT_USING_PTHREADS // -#define RT_USING_MODULE +// #define RT_USING_MODULE //
//
From 2e2886168e943fd7b6694295e0281abd47c8624c Mon Sep 17 00:00:00 2001 From: Bernard Xiong Date: Sun, 11 Oct 2015 15:34:32 +0800 Subject: [PATCH 14/36] [Tools] Add win32 spawn patch for module building. --- tools/building.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tools/building.py b/tools/building.py index 5ad6d4e9d2..38b7881797 100644 --- a/tools/building.py +++ b/tools/building.py @@ -267,6 +267,12 @@ def PrepareModuleBuilding(env, root_directory, bsp_directory): global Env global Rtt_Root + # patch for win32 spawn + if env['PLATFORM'] == 'win32': + win32_spawn = Win32Spawn() + win32_spawn.env = env + env['SPAWN'] = win32_spawn.spawn + Env = env Rtt_Root = root_directory From 3fb53adc4f4543636ab33e032658971b48ea0785 Mon Sep 17 00:00:00 2001 From: Bernard Xiong Date: Sun, 11 Oct 2015 15:37:12 +0800 Subject: [PATCH 15/36] [Tools] Update Keil MDK project generation. Add C++ files support; Fix the two same group issue if to add a library into an exist group. --- tools/keil.py | 255 +++++++++++++++++--------------------------------- 1 file changed, 85 insertions(+), 170 deletions(-) diff --git a/tools/keil.py b/tools/keil.py index d1aa5562d7..599658d983 100644 --- a/tools/keil.py +++ b/tools/keil.py @@ -34,9 +34,12 @@ from utils import xml_indent fs_encoding = sys.getfilesystemencoding() def _get_filetype(fn): - if fn.rfind('.c') != -1 or fn.rfind('.C') != -1 or fn.rfind('.cpp') != -1: + if fn.rfind('.c') != -1 or fn.rfind('.C') != -1: return 1 + if fn.rfind('.cpp') != -1 or fn.rfined('.cxx') != -1: + return 8 + # assemble file type if fn.rfind('.s') != -1 or fn.rfind('.S') != -1: return 2 @@ -88,6 +91,39 @@ def MDK4AddGroupForFN(ProjectFiles, parent, name, filename, project_path): file_path.text = path.decode(fs_encoding) +def MDK4AddLibToGroup(ProjectFiles, group, name, filename, project_path): + name = os.path.basename(filename) + path = os.path.dirname (filename) + + basename = os.path.basename(path) + path = _make_path_relative(project_path, path) + path = os.path.join(path, name) + files = SubElement(group, 'Files') + file = SubElement(files, 'File') + file_name = SubElement(file, 'FileName') + name = os.path.basename(path) + + if name.find('.cpp') != -1: + obj_name = name.replace('.cpp', '.o') + elif name.find('.c') != -1: + obj_name = name.replace('.c', '.o') + elif name.find('.s') != -1: + obj_name = name.replace('.s', '.o') + elif name.find('.S') != -1: + obj_name = name.replace('.s', '.o') + else: + obj_name = name + + if ProjectFiles.count(obj_name): + name = basename + '_' + name + ProjectFiles.append(obj_name) + file_name.text = name.decode(fs_encoding) + file_type = SubElement(file, 'FileType') + file_type.text = '%d' % _get_filetype(name) + file_path = SubElement(file, 'FilePath') + + file_path.text = path.decode(fs_encoding) + def MDK4AddGroup(ProjectFiles, parent, name, files, project_path): # don't add an empty group if len(files) == 0: @@ -130,16 +166,13 @@ def MDK4AddGroup(ProjectFiles, parent, name, files, project_path): file_path.text = path.decode(fs_encoding) -def MDK4Project(target, script): + return group + +# The common part of making MDK4/5 project +def MDK45Project(tree, target, script): project_path = os.path.dirname(os.path.abspath(target)) - project_uvopt = os.path.abspath(target).replace('uvproj', 'uvopt') - if os.path.isfile(project_uvopt): - os.unlink(project_uvopt) - - tree = etree.parse('template.uvproj') root = tree.getroot() - out = file(target, 'wb') out.write('\n') @@ -155,7 +188,31 @@ def MDK4Project(target, script): groups = SubElement(tree.find('Targets/Target'), 'Groups') groups.clear() # clean old groups for group in script: - group_xml = MDK4AddGroup(ProjectFiles, groups, group['name'], group['src'], project_path) + group_tree = MDK4AddGroup(ProjectFiles, groups, group['name'], group['src'], project_path) + + # for local CPPPATH/CPPDEFINES + if (group_tree != None) and (group.has_key('LOCAL_CPPPATH') or group.has_key('LOCAL_CCFLAGS')): + GroupOption = SubElement(group_tree, 'GroupOption') + GroupArmAds = SubElement(GroupOption, 'GroupArmAds') + Cads = SubElement(GroupArmAds, 'Cads') + VariousControls = SubElement(Cads, 'VariousControls') + MiscControls = SubElement(VariousControls, 'MiscControls') + if group.has_key('LOCAL_CCFLAGS'): + MiscControls.text = group['LOCAL_CCFLAGS'] + else: + MiscControls.text = ' ' + Define = SubElement(VariousControls, 'Define') + if group.has_key('LOCAL_CPPDEFINES'): + Define.text = ', '.join(set(group['LOCAL_CPPDEFINES'])) + else: + Define.text = ' ' + Undefine = SubElement(VariousControls, 'Undefine') + Undefine.text = ' ' + IncludePath = SubElement(VariousControls, 'IncludePath') + if group.has_key('LOCAL_CPPPATH'): + IncludePath.text = ';'.join([_make_path_relative(project_path, os.path.normpath(i)) for i in group['LOCAL_CPPPATH']]) + else: + IncludePath.text = ' ' # get each include path if group.has_key('CPPPATH') and group['CPPPATH']: @@ -187,7 +244,10 @@ def MDK4Project(target, script): lib_path = full_path if lib_path != '': - MDK4AddGroupForFN(ProjectFiles, groups, group['name'], lib_path, project_path) + if (group_tree != None): + MDK4AddLibToGroup(ProjectFiles, group_tree, group['name'], lib_path, project_path) + else: + MDK4AddGroupForFN(ProjectFiles, groups, group['name'], lib_path, project_path) # write include path, definitions and link flags IncludePath = tree.find('Targets/Target/TargetOption/TargetArmAds/Cads/VariousControls/IncludePath') @@ -203,176 +263,31 @@ def MDK4Project(target, script): out.write(etree.tostring(root, encoding='utf-8')) out.close() +def MDK4Project(target, script): + template_tree = etree.parse('template.uvproj') + + MDK45Project(template_tree, target, script) + + # remove project.uvopt file + project_uvopt = os.path.abspath(target).replace('uvproj', 'uvopt') + if os.path.isfile(project_uvopt): + os.unlink(project_uvopt) + # copy uvopt file if os.path.exists('template.uvopt'): import shutil shutil.copy2('template.uvopt', 'project.uvopt') -def MDK5AddGroupForFN(ProjectFiles, parent, name, filename, project_path): - group = SubElement(parent, 'Group') - group_name = SubElement(group, 'GroupName') - group_name.text = name - - name = os.path.basename(filename) - path = os.path.dirname (filename) - - basename = os.path.basename(path) - path = _make_path_relative(project_path, path) - path = os.path.join(path, name) - files = SubElement(group, 'Files') - file = SubElement(files, 'File') - file_name = SubElement(file, 'FileName') - name = os.path.basename(path) - - if name.find('.cpp') != -1: - obj_name = name.replace('.cpp', '.o') - elif name.find('.c') != -1: - obj_name = name.replace('.c', '.o') - elif name.find('.s') != -1: - obj_name = name.replace('.s', '.o') - elif name.find('.S') != -1: - obj_name = name.replace('.s', '.o') - - if ProjectFiles.count(obj_name): - name = basename + '_' + name - ProjectFiles.append(obj_name) - file_name.text = name.decode(fs_encoding) - file_type = SubElement(file, 'FileType') - file_type.text = '%d' % _get_filetype(name) - file_path = SubElement(file, 'FilePath') - - file_path.text = path.decode(fs_encoding) - -def MDK5AddGroup(ProjectFiles, parent, name, files, project_path): - # don't add an empty group - if len(files) == 0: - return - - group = SubElement(parent, 'Group') - group_name = SubElement(group, 'GroupName') - group_name.text = name - - for f in files: - fn = f.rfile() - name = fn.name - path = os.path.dirname(fn.abspath) - - basename = os.path.basename(path) - path = _make_path_relative(project_path, path) - path = os.path.join(path, name) - - files = SubElement(group, 'Files') - file = SubElement(files, 'File') - file_name = SubElement(file, 'FileName') - name = os.path.basename(path) - - if name.find('.cpp') != -1: - obj_name = name.replace('.cpp', '.o') - elif name.find('.c') != -1: - obj_name = name.replace('.c', '.o') - elif name.find('.s') != -1: - obj_name = name.replace('.s', '.o') - elif name.find('.S') != -1: - obj_name = name.replace('.s', '.o') - else: - obj_name = name - - if ProjectFiles.count(obj_name): - name = basename + '_' + name - ProjectFiles.append(obj_name) - file_name.text = name.decode(fs_encoding) - file_type = SubElement(file, 'FileType') - file_type.text = '%d' % _get_filetype(name) - file_path = SubElement(file, 'FilePath') - - file_path.text = path.decode(fs_encoding) - def MDK5Project(target, script): - project_path = os.path.dirname(os.path.abspath(target)) + template_tree = etree.parse('template.uvprojx') + + MDK45Project(template_tree, target, script) + + # remove project.uvopt file project_uvopt = os.path.abspath(target).replace('uvprojx', 'uvoptx') if os.path.isfile(project_uvopt): os.unlink(project_uvopt) - - tree = etree.parse('template.uvprojx') - root = tree.getroot() - - out = file(target, 'wb') - out.write('\n') - - CPPPATH = [] - CPPDEFINES = [] - LINKFLAGS = '' - CCFLAGS = '' - ProjectFiles = [] - - # add group - groups = tree.find('Targets/Target/Groups') - if groups is None: - groups = SubElement(tree.find('Targets/Target'), 'Groups') - groups.clear() # clean old groups - for group in script: - group_xml = MDK4AddGroup(ProjectFiles, groups, group['name'], group['src'], project_path) - - # get each include path - if group.has_key('CPPPATH') and group['CPPPATH']: - if CPPPATH: - CPPPATH += group['CPPPATH'] - else: - CPPPATH += group['CPPPATH'] - - # get each group's definitions - if group.has_key('CPPDEFINES') and group['CPPDEFINES']: - if CPPDEFINES: - CPPDEFINES += group['CPPDEFINES'] - else: - CPPDEFINES += group['CPPDEFINES'] - - # get each group's link flags - if group.has_key('LINKFLAGS') and group['LINKFLAGS']: - if LINKFLAGS: - LINKFLAGS += ' ' + group['LINKFLAGS'] - else: - LINKFLAGS += group['LINKFLAGS'] - - if group.has_key('LIBS') and group['LIBS']: - for item in group['LIBS']: - lib_path = '' - for path_item in group['LIBPATH']: - full_path = os.path.join(path_item, item + '.lib') - if os.path.isfile(full_path): # has this library - lib_path = full_path - - if lib_path != '': - MDK4AddGroupForFN(ProjectFiles, groups, group['name'], lib_path, project_path) - - # remove repeat path - paths = set() - for path in CPPPATH: - inc = _make_path_relative(project_path, os.path.normpath(path)) - paths.add(inc) #.replace('\\', '/') - - paths = [i for i in paths] - paths.sort() - CPPPATH = string.join(paths, ';') - - definitions = [i for i in set(CPPDEFINES)] - CPPDEFINES = string.join(definitions, ', ') - - # write include path, definitions and link flags - IncludePath = tree.find('Targets/Target/TargetOption/TargetArmAds/Cads/VariousControls/IncludePath') - IncludePath.text = CPPPATH - - Define = tree.find('Targets/Target/TargetOption/TargetArmAds/Cads/VariousControls/Define') - Define.text = CPPDEFINES - - Misc = tree.find('Targets/Target/TargetOption/TargetArmAds/LDads/Misc') - Misc.text = LINKFLAGS - - xml_indent(root) - out.write(etree.tostring(root, encoding='utf-8')) - out.close() - # copy uvopt file if os.path.exists('template.uvoptx'): import shutil From 147901c2cbb798caf2e9fb340d9b065b76f2c954 Mon Sep 17 00:00:00 2001 From: Bernard Xiong Date: Sun, 11 Oct 2015 15:37:34 +0800 Subject: [PATCH 16/36] [Libc] Export more symbols for libc. --- components/libc/armlibc/libc_syms.c | 39 ++++++++++++++++++++++++ components/libc/armlibc/mem_std.c | 4 +++ components/libc/newlib/libc_sym.c | 47 +++++++++++++++++++++++++++++ 3 files changed, 90 insertions(+) create mode 100644 components/libc/armlibc/libc_syms.c create mode 100644 components/libc/newlib/libc_sym.c diff --git a/components/libc/armlibc/libc_syms.c b/components/libc/armlibc/libc_syms.c new file mode 100644 index 0000000000..847c48544a --- /dev/null +++ b/components/libc/armlibc/libc_syms.c @@ -0,0 +1,39 @@ +#include +#include +#include +#include +#include + +#include + +/* some export routines for module */ + +RTM_EXPORT(strstr); +RTM_EXPORT(strlen); +RTM_EXPORT(strchr); +RTM_EXPORT(strcpy); +RTM_EXPORT(strncpy); +RTM_EXPORT(strcmp); +RTM_EXPORT(strncmp); +RTM_EXPORT(strcat); +RTM_EXPORT(strtol); + +RTM_EXPORT(memcpy); +RTM_EXPORT(memcmp); +RTM_EXPORT(memmove); +RTM_EXPORT(memset); +RTM_EXPORT(memchr); + +RTM_EXPORT(toupper); +RTM_EXPORT(atoi); + +RTM_EXPORT(localtime); +RTM_EXPORT(time); + +/* import the full stdio for printf */ +#ifdef __MICROLIB +#error "[RT_USING_LIBC] Please use standard libc but not microlib." +#endif + +RTM_EXPORT(puts); +RTM_EXPORT(printf); diff --git a/components/libc/armlibc/mem_std.c b/components/libc/armlibc/mem_std.c index 6faf86555f..56aa525df2 100644 --- a/components/libc/armlibc/mem_std.c +++ b/components/libc/armlibc/mem_std.c @@ -22,18 +22,22 @@ void *malloc(int n) { return rt_malloc(n); } +RTM_EXPORT(malloc); void *realloc(void *rmem, rt_size_t newsize) { return rt_realloc(rmem, newsize); } +RTM_EXPORT(realloc); void *calloc(rt_size_t nelem, rt_size_t elsize) { return rt_calloc(nelem, elsize); } +RTM_EXPORT(calloc); void free(void *rmem) { rt_free(rmem); } +RTM_EXPORT(free); diff --git a/components/libc/newlib/libc_sym.c b/components/libc/newlib/libc_sym.c new file mode 100644 index 0000000000..48e488f5d8 --- /dev/null +++ b/components/libc/newlib/libc_sym.c @@ -0,0 +1,47 @@ +#include +#include + +#include +#include +#include + +RTM_EXPORT(strcpy); +RTM_EXPORT(strncpy); +RTM_EXPORT(strlen); +RTM_EXPORT(strcat); +RTM_EXPORT(strstr); +RTM_EXPORT(strchr); +RTM_EXPORT(strcmp); +RTM_EXPORT(strtol); +RTM_EXPORT(strtoul); +RTM_EXPORT(strncmp); + +RTM_EXPORT(memcpy); +RTM_EXPORT(memcmp); +RTM_EXPORT(memmove); +RTM_EXPORT(memset); +RTM_EXPORT(memchr); + +RTM_EXPORT(putchar); +RTM_EXPORT(puts); +RTM_EXPORT(printf); +RTM_EXPORT(sprintf); +RTM_EXPORT(snprintf); + +RTM_EXPORT(fwrite); + +#include +RTM_EXPORT(localtime); +RTM_EXPORT(time); + +#include +RTM_EXPORT(longjmp); +RTM_EXPORT(setjmp); + +RTM_EXPORT(exit); +RTM_EXPORT(abort); + +RTM_EXPORT(rand); + +#include +RTM_EXPORT(__assert_func); From f4248a95c3e06a2a51e702e61de63870f50536f4 Mon Sep 17 00:00:00 2001 From: Bernard Xiong Date: Sun, 11 Oct 2015 15:38:08 +0800 Subject: [PATCH 17/36] [Finsh] Add script feature for msh. --- components/finsh/SConscript | 3 +- components/finsh/cmd.c | 104 +++++++++++------------ components/finsh/msh.c | 66 +++++++++------ components/finsh/msh.h | 5 +- components/finsh/msh_cmd.c | 154 +++++++++++++++++----------------- components/finsh/msh_file.c | 159 ++++++++++++++++++++++++++++++++++++ 6 files changed, 334 insertions(+), 157 deletions(-) create mode 100644 components/finsh/msh_file.c diff --git a/components/finsh/SConscript b/components/finsh/SConscript index 8d6729e4a7..639cbebd4a 100644 --- a/components/finsh/SConscript +++ b/components/finsh/SConscript @@ -22,8 +22,9 @@ finsh_token.c ''') msh_src = Split(''' -msh_cmd.c msh.c +msh_cmd.c +msh_file.c ''') CPPPATH = [cwd] diff --git a/components/finsh/cmd.c b/components/finsh/cmd.c index c42b412f23..29b22c05c2 100644 --- a/components/finsh/cmd.c +++ b/components/finsh/cmd.c @@ -99,17 +99,17 @@ static long _list_thread(struct rt_list_node *list) else if (thread->stat == RT_THREAD_INIT) rt_kprintf(" init "); else if (thread->stat == RT_THREAD_CLOSE) rt_kprintf(" close "); - ptr = (rt_uint8_t*)thread->stack_addr; + ptr = (rt_uint8_t *)thread->stack_addr; while (*ptr == '#')ptr ++; rt_kprintf(" 0x%08x 0x%08x 0x%08x 0x%08x %03d\n", - thread->stack_size + ((rt_uint32_t)thread->stack_addr - (rt_uint32_t)thread->sp), - thread->stack_size, - thread->stack_size - ((rt_uint32_t) ptr - (rt_uint32_t)thread->stack_addr), - thread->remaining_tick, - thread->error); + thread->stack_size + ((rt_uint32_t)thread->stack_addr - (rt_uint32_t)thread->sp), + thread->stack_size, + thread->stack_size - ((rt_uint32_t) ptr - (rt_uint32_t)thread->stack_addr), + thread->remaining_tick, + thread->error); } - + return 0; } @@ -148,7 +148,7 @@ static long _list_sem(struct rt_list_node *list) sem = (struct rt_semaphore *)(rt_list_entry(node, struct rt_object, list)); if (!rt_list_isempty(&sem->parent.suspend_thread)) { - rt_kprintf("%-8.*s %03d %d:", + rt_kprintf("%-8.*s %03d %d:", RT_NAME_MAX, sem->parent.parent.name, sem->value, @@ -448,7 +448,7 @@ static long _list_device(struct rt_list_node *list) { struct rt_device *device; struct rt_list_node *node; - char * const device_type_str[] = + char *const device_type_str[] = { "Character Device", "Block Device", @@ -464,11 +464,11 @@ static long _list_device(struct rt_list_node *list) "SPI Bus", "SPI Device", "SDIO Bus", - "PM Pseudo Device", + "PM Pseudo Device", "Pipe", "Portal Device", - "Timer Device", - "Miscellaneous Device", + "Timer Device", + "Miscellaneous Device", "Unknown" }; @@ -507,13 +507,13 @@ int list_module(void) list = &rt_object_container[RT_Object_Class_Module].object_list; - rt_kprintf("module name ref\n"); - rt_kprintf("------------ --------\n"); + rt_kprintf("module name ref address \n"); + rt_kprintf("------------ -------- ------------\n"); for (node = list->next; node != list; node = node->next) { module = (struct rt_module *)(rt_list_entry(node, struct rt_object, list)); - rt_kprintf("%-16.*s %-04d\n", - RT_NAME_MAX, module->parent.name, module->nref); + rt_kprintf("%-16.*s %-04d 0x%08x\n", + RT_NAME_MAX, module->parent.name, module->nref, module->module_space); } return 0; @@ -525,13 +525,13 @@ int list_mod_detail(const char *name) { int i; struct rt_module *module; - + /* find module */ if ((module = rt_module_find(name)) != RT_NULL) { /* module has entry point */ if (!(module->parent.flag & RT_MODULE_FLAG_WITHOUTENTRY)) - { + { struct rt_thread *thread; struct rt_list_node *tlist; rt_uint8_t *ptr; @@ -548,15 +548,15 @@ int list_mod_detail(const char *name) else if (thread->stat == RT_THREAD_SUSPEND) rt_kprintf(" suspend"); else if (thread->stat == RT_THREAD_INIT) rt_kprintf(" init "); - ptr = (rt_uint8_t*)thread->stack_addr; + ptr = (rt_uint8_t *)thread->stack_addr; while (*ptr == '#')ptr ++; rt_kprintf(" 0x%08x 0x%08x 0x%08x 0x%08x %03d\n", - thread->stack_size + ((rt_uint32_t)thread->stack_addr - (rt_uint32_t)thread->sp), - thread->stack_size, - thread->stack_size - ((rt_uint32_t) ptr - (rt_uint32_t)thread->stack_addr), - thread->remaining_tick, - thread->error); + thread->stack_size + ((rt_uint32_t)thread->stack_addr - (rt_uint32_t)thread->sp), + thread->stack_size, + thread->stack_size - ((rt_uint32_t) ptr - (rt_uint32_t)thread->stack_addr), + thread->remaining_tick, + thread->error); } /* list sub thread in module */ @@ -607,18 +607,18 @@ int list_mod_detail(const char *name) if (!rt_list_isempty(tlist)) _list_timer(tlist); } - if (module->nsym > 0) - { - rt_kprintf("symbol address \n"); - rt_kprintf("-------- ----------\n"); - - /* list module export symbols */ - for (i=0; insym; i++) - { - rt_kprintf("%s 0x%x\n", - module->symtab[i].name, module->symtab[i].addr); - } - } + if (module->nsym > 0) + { + rt_kprintf("symbol address \n"); + rt_kprintf("-------- ----------\n"); + + /* list module export symbols */ + for (i = 0; i < module->nsym; i++) + { + rt_kprintf("%s 0x%x\n", + module->symtab[i].name, module->symtab[i].addr); + } + } } return 0; @@ -632,16 +632,16 @@ long list(void) struct finsh_syscall_item *syscall_item; struct finsh_sysvar_item *sysvar_item; #endif - + rt_kprintf("--Function List:\n"); { struct finsh_syscall *index; for (index = _syscall_table_begin; - index < _syscall_table_end; - FINSH_NEXT_SYSCALL(index)) + index < _syscall_table_end; + FINSH_NEXT_SYSCALL(index)) { - /* skip the internal command */ - if (strncmp((char*)index->name, "__", 2) == 0) continue; + /* skip the internal command */ + if (strncmp((char *)index->name, "__", 2) == 0) continue; #ifdef FINSH_USING_DESCRIPTION rt_kprintf("%-16s -- %s\n", index->name, index->desc); @@ -664,8 +664,8 @@ long list(void) { struct finsh_sysvar *index; for (index = _sysvar_table_begin; - index < _sysvar_table_end; - FINSH_NEXT_SYSVAR(index)) + index < _sysvar_table_end; + FINSH_NEXT_SYSVAR(index)) { #ifdef FINSH_USING_DESCRIPTION rt_kprintf("%-16s -- %s\n", index->name, index->desc); @@ -682,7 +682,7 @@ long list(void) sysvar_item = sysvar_item->next; } #endif - + return 0; } FINSH_FUNCTION_EXPORT(list, list all symbol in system) @@ -732,12 +732,12 @@ void list_prefix(char *prefix) { struct finsh_syscall *index; for (index = _syscall_table_begin; - index < _syscall_table_end; - FINSH_NEXT_SYSCALL(index)) + index < _syscall_table_end; + FINSH_NEXT_SYSCALL(index)) { - /* skip internal command */ - if (str_is_prefix("__", index->name) == 0) continue; - + /* skip internal command */ + if (str_is_prefix("__", index->name) == 0) continue; + if (str_is_prefix(prefix, index->name) == 0) { if (func_cnt == 0) @@ -807,10 +807,10 @@ void list_prefix(char *prefix) /* checks in system variable */ { - struct finsh_sysvar* index; + struct finsh_sysvar *index; for (index = _sysvar_table_begin; - index < _sysvar_table_end; - FINSH_NEXT_SYSVAR(index)) + index < _sysvar_table_end; + FINSH_NEXT_SYSVAR(index)) { if (str_is_prefix(prefix, index->name) == 0) { diff --git a/components/finsh/msh.c b/components/finsh/msh.c index 6d747b40db..bd4b12d9d5 100644 --- a/components/finsh/msh.c +++ b/components/finsh/msh.c @@ -37,7 +37,7 @@ #endif #define RT_FINSH_ARG_MAX 10 -typedef int (*cmd_function_t)(int argc, char** argv); +typedef int (*cmd_function_t)(int argc, char **argv); #ifdef FINSH_USING_MSH #ifdef FINSH_USING_MSH_ONLY @@ -56,7 +56,7 @@ rt_bool_t msh_is_used(void) return __msh_state; } -static int msh_exit(int argc, char** argv) +static int msh_exit(int argc, char **argv) { /* return to finsh shell mode */ __msh_state = RT_FALSE; @@ -74,15 +74,15 @@ static int msh_enter(void) FINSH_FUNCTION_EXPORT_ALIAS(msh_enter, msh, use module shell); #endif -int msh_help(int argc, char** argv) +int msh_help(int argc, char **argv) { rt_kprintf("RT-Thread shell commands:\n"); { struct finsh_syscall *index; for (index = _syscall_table_begin; - index < _syscall_table_end; - FINSH_NEXT_SYSCALL(index)) + index < _syscall_table_end; + FINSH_NEXT_SYSCALL(index)) { if (strncmp(index->name, "__cmd_", 6) != 0) continue; #if defined(FINSH_USING_DESCRIPTION) && defined(FINSH_USING_SYMTAB) @@ -98,7 +98,7 @@ int msh_help(int argc, char** argv) } FINSH_FUNCTION_EXPORT_ALIAS(msh_help, __cmd_help, RT-Thread shell help.); -static int msh_split(char* cmd, rt_size_t length, char* argv[RT_FINSH_ARG_MAX]) +static int msh_split(char *cmd, rt_size_t length, char *argv[RT_FINSH_ARG_MAX]) { char *ptr; rt_size_t position; @@ -161,13 +161,13 @@ static cmd_function_t msh_get_cmd(char *cmd, int size) cmd_function_t cmd_func = RT_NULL; for (index = _syscall_table_begin; - index < _syscall_table_end; - FINSH_NEXT_SYSCALL(index)) + index < _syscall_table_end; + FINSH_NEXT_SYSCALL(index)) { if (strncmp(index->name, "__cmd_", 6) != 0) continue; - + if (strncmp(&index->name[6], cmd, size) == 0 && - index->name[6 + size] == '\0') + index->name[6 + size] == '\0') { cmd_func = (cmd_function_t)index->func; break; @@ -180,7 +180,7 @@ static cmd_function_t msh_get_cmd(char *cmd, int size) #if defined(RT_USING_MODULE) && defined(RT_USING_DFS) /* Return 0 on module executed. Other value indicate error. */ -int msh_exec_module(const char* cmd_line, int size) +int msh_exec_module(const char *cmd_line, int size) { int ret; int fd = -1; @@ -197,7 +197,7 @@ int msh_exec_module(const char* cmd_line, int size) length = cmd_length + 32; /* allocate program name memory */ - pg_name = (char*) rt_malloc(length); + pg_name = (char *) rt_malloc(length); if (pg_name == RT_NULL) return -RT_ENOMEM; @@ -251,12 +251,21 @@ int msh_exec_module(const char* cmd_line, int size) int system(const char *command) { - return msh_exec_module(command, rt_strlen(command)); + int ret = -RT_ENOMEM; + char *cmd = rt_strdup(command); + + if (cmd) + { + ret = msh_exec(cmd, rt_strlen(cmd)); + rt_free(cmd); + } + + return ret; } RTM_EXPORT(system); #endif -static int _msh_exec_cmd(char* cmd, rt_size_t length, int *retp) +static int _msh_exec_cmd(char *cmd, rt_size_t length, int *retp) { int argc; int cmd0_size = 0; @@ -287,12 +296,12 @@ static int _msh_exec_cmd(char* cmd, rt_size_t length, int *retp) return 0; } -int msh_exec(char* cmd, rt_size_t length) +int msh_exec(char *cmd, rt_size_t length) { int cmd_ret; - /* strim the beginning of command */ - while(*cmd == ' ' || *cmd == '\t') + /* strim the beginning of command */ + while (*cmd == ' ' || *cmd == '\t') { cmd++; length--; @@ -318,7 +327,12 @@ int msh_exec(char* cmd, rt_size_t length) #endif #if defined(RT_USING_DFS) && defined(DFS_USING_WORKDIR) - /* change to this directory */ + if (msh_exec_script(cmd, length) == 0) + { + return 0; + } + + /* change to this directory */ if (chdir(cmd) == 0) { return 0; @@ -329,7 +343,7 @@ int msh_exec(char* cmd, rt_size_t length) { char *tcmd; tcmd = cmd; - while(*tcmd != ' ' && *tcmd != '\0') + while (*tcmd != ' ' && *tcmd != '\0') { tcmd++; } @@ -355,14 +369,14 @@ static int str_common(const char *str1, const char *str2) #ifdef RT_USING_DFS void msh_auto_complete_path(char *path) { - DIR* dir = RT_NULL; + DIR *dir = RT_NULL; struct dirent *dirent = RT_NULL; char *full_path, *ptr, *index; if (!path) return; - full_path = (char*)rt_malloc(256); + full_path = (char *)rt_malloc(256); if (full_path == RT_NULL) return; /* out of memory */ if (*path != '/') @@ -434,9 +448,9 @@ void msh_auto_complete_path(char *path) /* save dirent name */ strcpy(full_path, dirent->d_name); } - + length = str_common(dirent->d_name, full_path); - + if (length < min_length) { min_length = length; @@ -460,7 +474,7 @@ void msh_auto_complete_path(char *path) rt_kprintf("%s\n", dirent->d_name); } } - + length = index - path; memcpy(index, full_path, min_length); path[length + min_length] = '\0'; @@ -481,7 +495,7 @@ void msh_auto_complete(char *prefix) min_length = 0; name_ptr = RT_NULL; - if (*prefix == '\0') + if (*prefix == '\0') { msh_help(0, RT_NULL); return; @@ -522,7 +536,7 @@ void msh_auto_complete(char *prefix) /* skip finsh shell function */ if (strncmp(index->name, "__cmd_", 6) != 0) continue; - cmd_name = (const char*) &index->name[6]; + cmd_name = (const char *) &index->name[6]; if (strncmp(prefix, cmd_name, strlen(prefix)) == 0) { if (min_length == 0) diff --git a/components/finsh/msh.h b/components/finsh/msh.h index 959170da3d..df49732956 100644 --- a/components/finsh/msh.h +++ b/components/finsh/msh.h @@ -33,7 +33,10 @@ #include rt_bool_t msh_is_used(void); -int msh_exec(char* cmd, rt_size_t length); +int msh_exec(char *cmd, rt_size_t length); void msh_auto_complete(char *prefix); +int msh_exec_module(const char *cmd_line, int size); +int msh_exec_script(const char *cmd_line, int size); + #endif diff --git a/components/finsh/msh_cmd.c b/components/finsh/msh_cmd.c index fc6b56cdd1..19eb5e0b72 100644 --- a/components/finsh/msh_cmd.c +++ b/components/finsh/msh_cmd.c @@ -41,7 +41,7 @@ extern char working_directory[]; #endif -int cmd_ls(int argc, char** argv) +int cmd_ls(int argc, char **argv) { extern void ls(const char *pathname); @@ -53,7 +53,7 @@ int cmd_ls(int argc, char** argv) ls("/"); #endif } - else + else { ls(argv[1]); } @@ -62,7 +62,7 @@ int cmd_ls(int argc, char** argv) } FINSH_FUNCTION_EXPORT_ALIAS(cmd_ls, __cmd_ls, List information about the FILEs.); -int cmd_cp(int argc, char** argv) +int cmd_cp(int argc, char **argv) { void copy(const char *src, const char *dst); @@ -80,7 +80,7 @@ int cmd_cp(int argc, char** argv) } FINSH_FUNCTION_EXPORT_ALIAS(cmd_cp, __cmd_cp, Copy SOURCE to DEST.); -int cmd_mv(int argc, char** argv) +int cmd_mv(int argc, char **argv) { if (argc != 3) { @@ -89,66 +89,66 @@ int cmd_mv(int argc, char** argv) } else { - int fd; - char *dest = RT_NULL; + int fd; + char *dest = RT_NULL; rt_kprintf("%s => %s\n", argv[1], argv[2]); - fd = open(argv[2], O_DIRECTORY, 0); - if (fd >= 0) - { - char *src; - - close(fd); + fd = open(argv[2], O_DIRECTORY, 0); + if (fd >= 0) + { + char *src; - /* it's a directory */ - dest = (char*)rt_malloc(DFS_PATH_MAX); - if (dest == RT_NULL) - { - rt_kprintf("out of memory\n"); - return -RT_ENOMEM; - } + close(fd); - src = argv[1] + rt_strlen(argv[1]); - while (src != argv[1]) - { - if (*src == '/') break; - src --; - } + /* it's a directory */ + dest = (char *)rt_malloc(DFS_PATH_MAX); + if (dest == RT_NULL) + { + rt_kprintf("out of memory\n"); + return -RT_ENOMEM; + } - rt_snprintf(dest, DFS_PATH_MAX - 1, "%s/%s", argv[2], src); - } - else - { - fd = open(argv[2], O_RDONLY, 0); - if (fd >= 0) - { - close(fd); - - unlink(argv[2]); - } + src = argv[1] + rt_strlen(argv[1]); + while (src != argv[1]) + { + if (*src == '/') break; + src --; + } - dest = argv[2]; - } + rt_snprintf(dest, DFS_PATH_MAX - 1, "%s/%s", argv[2], src); + } + else + { + fd = open(argv[2], O_RDONLY, 0); + if (fd >= 0) + { + close(fd); - rename(argv[1], dest); - if (dest != RT_NULL && dest != argv[2]) rt_free(dest); + unlink(argv[2]); + } + + dest = argv[2]; + } + + rename(argv[1], dest); + if (dest != RT_NULL && dest != argv[2]) rt_free(dest); } return 0; } FINSH_FUNCTION_EXPORT_ALIAS(cmd_mv, __cmd_mv, Rename SOURCE to DEST.); -int cmd_cat(int argc, char** argv) +int cmd_cat(int argc, char **argv) { int index; - extern void cat(const char* filename); + extern void cat(const char *filename); if (argc == 1) { rt_kprintf("Usage: cat [FILE]...\n"); rt_kprintf("Concatenate FILE(s)\n"); - return 0; + return 0; } for (index = 1; index < argc; index ++) @@ -160,7 +160,7 @@ int cmd_cat(int argc, char** argv) } FINSH_FUNCTION_EXPORT_ALIAS(cmd_cat, __cmd_cat, Concatenate FILE(s)); -int cmd_rm(int argc, char** argv) +int cmd_rm(int argc, char **argv) { int index; @@ -168,7 +168,7 @@ int cmd_rm(int argc, char** argv) { rt_kprintf("Usage: rm FILE...\n"); rt_kprintf("Remove (unlink) the FILE(s).\n"); - return 0; + return 0; } for (index = 1; index < argc; index ++) @@ -178,10 +178,10 @@ int cmd_rm(int argc, char** argv) return 0; } -FINSH_FUNCTION_EXPORT_ALIAS(cmd_rm, __cmd_rm, Remove (unlink) the FILE(s).); +FINSH_FUNCTION_EXPORT_ALIAS(cmd_rm, __cmd_rm, Remove(unlink) the FILE(s).); #ifdef DFS_USING_WORKDIR -int cmd_cd(int argc, char** argv) +int cmd_cd(int argc, char **argv) { if (argc == 1) { @@ -196,34 +196,34 @@ int cmd_cd(int argc, char** argv) } FINSH_FUNCTION_EXPORT_ALIAS(cmd_cd, __cmd_cd, Change the shell working directory.); -int cmd_pwd(int argc, char** argv) +int cmd_pwd(int argc, char **argv) { - rt_kprintf("%s\n", working_directory); - return 0; + rt_kprintf("%s\n", working_directory); + return 0; } FINSH_FUNCTION_EXPORT_ALIAS(cmd_pwd, __cmd_pwd, Print the name of the current working directory.); #endif -int cmd_mkdir(int argc, char** argv) +int cmd_mkdir(int argc, char **argv) { - if (argc == 1) - { - rt_kprintf("Usage: mkdir [OPTION] DIRECTORY\n"); - rt_kprintf("Create the DIRECTORY, if they do not already exist.\n"); - } - else - { - mkdir(argv[1], 0); - } + if (argc == 1) + { + rt_kprintf("Usage: mkdir [OPTION] DIRECTORY\n"); + rt_kprintf("Create the DIRECTORY, if they do not already exist.\n"); + } + else + { + mkdir(argv[1], 0); + } - return 0; + return 0; } FINSH_FUNCTION_EXPORT_ALIAS(cmd_mkdir, __cmd_mkdir, Create the DIRECTORY.); -int cmd_mkfs(int argc, char** argv) +int cmd_mkfs(int argc, char **argv) { int result = 0; - char* type="elm"; /* use the default file system type as 'fatfs' */ + char *type = "elm"; /* use the default file system type as 'fatfs' */ if (argc == 2) { @@ -242,7 +242,7 @@ int cmd_mkfs(int argc, char** argv) rt_kprintf("Usage: mkfs [-t type] device\n"); return 0; } - + if (result != RT_EOK) { rt_kprintf("mkfs failed, result=%d\n", result); @@ -255,17 +255,17 @@ FINSH_FUNCTION_EXPORT_ALIAS(cmd_mkfs, __cmd_mkfs, format disk with file system); #endif #ifdef RT_USING_LWIP -int cmd_ifconfig(int argc, char** argv) +int cmd_ifconfig(int argc, char **argv) { extern void list_if(void); - extern void set_if(char* netif_name, char* ip_addr, char* gw_addr, char* nm_addr); + extern void set_if(char *netif_name, char *ip_addr, char *gw_addr, char *nm_addr); - if(argc == 1) + if (argc == 1) { list_if(); } - else if(argc == 5) + else if (argc == 5) { rt_kprintf("config : %s\n", argv[1]); rt_kprintf("IP addr: %s\n", argv[2]); @@ -283,22 +283,22 @@ int cmd_ifconfig(int argc, char** argv) FINSH_FUNCTION_EXPORT_ALIAS(cmd_ifconfig, __cmd_ifconfig, list the information of network interfaces); #ifdef RT_LWIP_TCP -int cmd_netstat(int argc, char** argv) +int cmd_netstat(int argc, char **argv) { - extern void list_tcps(void); + extern void list_tcps(void); - list_tcps(); - return 0; + list_tcps(); + return 0; } -FINSH_FUNCTION_EXPORT_ALIAS(cmd_netstat, __cmd_netstat, list the information of TCP/IP); +FINSH_FUNCTION_EXPORT_ALIAS(cmd_netstat, __cmd_netstat, list the information of TCP / IP); #endif #endif /* RT_USING_LWIP */ -int cmd_ps(int argc, char** argv) +int cmd_ps(int argc, char **argv) { extern long list_thread(void); extern int list_module(void); - + #ifdef RT_USING_MODULE if ((argc == 2) && (strcmp(argv[1], "-m") == 0)) list_module(); @@ -309,14 +309,14 @@ int cmd_ps(int argc, char** argv) } FINSH_FUNCTION_EXPORT_ALIAS(cmd_ps, __cmd_ps, List threads in the system.); -int cmd_time(int argc, char** argv) +int cmd_time(int argc, char **argv) { return 0; } FINSH_FUNCTION_EXPORT_ALIAS(cmd_time, __cmd_time, Execute command with time.); #ifdef RT_USING_HEAP -int cmd_free(int argc, char** argv) +int cmd_free(int argc, char **argv) { extern void list_mem(void); extern void list_memheap(void); diff --git a/components/finsh/msh_file.c b/components/finsh/msh_file.c new file mode 100644 index 0000000000..80012e9bb8 --- /dev/null +++ b/components/finsh/msh_file.c @@ -0,0 +1,159 @@ +/* + * script for RT-Thread module shell + * + * COPYRIGHT (C) 2013-2015, Shanghai Real-Thread Technology Co., Ltd + * + * This file is part of RT-Thread (http://www.rt-thread.org) + * Maintainer: bernard.xiong + * + * All rights reserved. + * + * 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 + * 2015-09-25 Bernard the first verion for FinSH + */ + +#include +#include + +#include "msh.h" + +#if defined(FINSH_USING_MSH) && defined(RT_USING_DFS) +#include + +static int msh_readline(int fd, char *line_buf, int size) +{ + char ch; + int index = 0; + + do + { + if (read(fd, &ch, 1) != 1) + { + /* nothing in this file */ + return 0; + } + } + while (ch == '\n' || ch == '\r'); + + /* set the first character */ + line_buf[index ++] = ch; + + while (index < size) + { + if (read(fd, &ch, 1) == 1) + { + if (ch == '\n' || ch == '\r') + { + line_buf[index] = '\0'; + break; + } + + line_buf[index++] = ch; + } + else + { + line_buf[index] = '\0'; + break; + } + } + + return index; +} + +int msh_exec_script(const char *cmd_line, int size) +{ + int ret; + int fd = -1; + char *pg_name; + int length, cmd_length = 0; + + if (size == 0) return -RT_ERROR; + + /* get the length of command0 */ + while ((cmd_line[cmd_length] != ' ' && cmd_line[cmd_length] != '\t') && cmd_length < size) + cmd_length ++; + + /* get name length */ + length = cmd_length + 32; + + /* allocate program name memory */ + pg_name = (char *) rt_malloc(length); + if (pg_name == RT_NULL) return -RT_ENOMEM; + + /* copy command0 */ + memcpy(pg_name, cmd_line, cmd_length); + pg_name[cmd_length] = '\0'; + + if (strstr(pg_name, ".sh") != RT_NULL || strstr(pg_name, ".SH") != RT_NULL) + { + /* try to open program */ + fd = open(pg_name, O_RDONLY, 0); + + /* search in /bin path */ + if (fd < 0) + { + rt_snprintf(pg_name, length - 1, "/bin/%.*s", cmd_length, cmd_line); + fd = open(pg_name, O_RDONLY, 0); + } + } + + rt_free(pg_name); + if (fd >= 0) + { + /* found script */ + char *line_buf; + int length; + + line_buf = (char *) rt_malloc(RT_CONSOLEBUF_SIZE); + + /* read line by line and then exec it */ + do + { + length = msh_readline(fd, line_buf, RT_CONSOLEBUF_SIZE); + if (length > 0) + { + char ch = '\0'; + int index; + + for (index = 0; index < length; index ++) + { + ch = line_buf[index]; + if (ch == ' ' || ch == '\t') continue; + else break; + } + + if (ch != '#') /* not a comment */ + msh_exec(line_buf, length); + } + } + while (length > 0); + + close(fd); + rt_free(line_buf); + + ret = 0; + } + else + { + ret = -1; + } + + return ret; +} + +#endif From d859e3e8b8b0798899d5b6898ce6e884978996e5 Mon Sep 17 00:00:00 2001 From: Bernard Xiong Date: Sun, 11 Oct 2015 15:38:35 +0800 Subject: [PATCH 18/36] [DFS] export more symbols for dfs_lwip. --- components/dfs/filesystems/lwip/lwip_netdb.c | 3 + components/dfs/filesystems/lwip/lwip_select.c | 1 + .../dfs/filesystems/lwip/lwip_sockets.c | 155 ++++++++++-------- components/dfs/filesystems/lwip/sys/socket.h | 2 + 4 files changed, 90 insertions(+), 71 deletions(-) diff --git a/components/dfs/filesystems/lwip/lwip_netdb.c b/components/dfs/filesystems/lwip/lwip_netdb.c index 6871474251..1e14dfb093 100644 --- a/components/dfs/filesystems/lwip/lwip_netdb.c +++ b/components/dfs/filesystems/lwip/lwip_netdb.c @@ -29,6 +29,7 @@ struct hostent *gethostbyname(const char *name) { return lwip_gethostbyname(name); } +RTM_EXPORT(gethostbyname); int gethostbyname_r(const char *name, struct hostent *ret, char *buf, size_t buflen, struct hostent **result, int *h_errnop) @@ -40,6 +41,7 @@ void freeaddrinfo(struct addrinfo *ai) { lwip_freeaddrinfo(ai); } +RTM_EXPORT(freeaddrinfo); int getaddrinfo(const char *nodename, const char *servname, @@ -48,3 +50,4 @@ int getaddrinfo(const char *nodename, { return lwip_getaddrinfo(nodename, servname, hints, res); } +RTM_EXPORT(getaddrinfo); diff --git a/components/dfs/filesystems/lwip/lwip_select.c b/components/dfs/filesystems/lwip/lwip_select.c index 3477b6f1d6..31d9190cfc 100644 --- a/components/dfs/filesystems/lwip/lwip_select.c +++ b/components/dfs/filesystems/lwip/lwip_select.c @@ -118,5 +118,6 @@ select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset, return result; } +RTM_EXPORT(select); #endif diff --git a/components/dfs/filesystems/lwip/lwip_sockets.c b/components/dfs/filesystems/lwip/lwip_sockets.c index 346ef7b266..6b68378f7d 100644 --- a/components/dfs/filesystems/lwip/lwip_sockets.c +++ b/components/dfs/filesystems/lwip/lwip_sockets.c @@ -32,154 +32,167 @@ int accept(int s, struct sockaddr *addr, socklen_t *addrlen) { - int new_client = -1; + int new_client = -1; int sock = dfs_lwip_getsocket(s); new_client = lwip_accept(sock, addr, addrlen); - if (new_client != -1) - { - /* this is a new socket, create it in file system fd */ - int fd; - struct dfs_fd *d; - - /* allocate a fd */ - fd = fd_new(); - if (fd < 0) - { - rt_set_errno(-DFS_STATUS_ENOMEM); - lwip_close(sock); + if (new_client != -1) + { + /* this is a new socket, create it in file system fd */ + int fd; + struct dfs_fd *d; - printf("no fd yet!\n"); - return -1; - } - d = fd_get(fd); + /* allocate a fd */ + fd = fd_new(); + if (fd < 0) + { + rt_set_errno(-DFS_STATUS_ENOMEM); + lwip_close(sock); - /* this is a socket fd */ - d->type = FT_SOCKET; - d->path = RT_NULL; - - d->fs = dfs_lwip_get_fs(); - - d->flags = DFS_O_RDWR; /* set flags as read and write */ - d->size = 0; - d->pos = 0; + rt_kprintf("no fd yet!\n"); + return -1; + } + d = fd_get(fd); - /* set socket to the data of dfs_fd */ - d->data = (void*) new_client; + /* this is a socket fd */ + d->type = FT_SOCKET; + d->path = RT_NULL; + + d->fs = dfs_lwip_get_fs(); + + d->flags = DFS_O_RDWR; /* set flags as read and write */ + d->size = 0; + d->pos = 0; + + /* set socket to the data of dfs_fd */ + d->data = (void *) new_client; + + /* release the ref-count of fd */ + fd_put(d); - /* release the ref-count of fd */ - fd_put(d); - return fd; - } + } - return new_client; + return new_client; } +RTM_EXPORT(accept); int bind(int s, const struct sockaddr *name, socklen_t namelen) { int sock = dfs_lwip_getsocket(s); - + return lwip_bind(sock, name, namelen); } +RTM_EXPORT(bind); int shutdown(int s, int how) { int sock; - struct dfs_fd *d; + struct dfs_fd *d; - d = fd_get(s); - if (d == RT_NULL) - { - rt_set_errno(-DFS_STATUS_EBADF); - - return -1; - } - - sock = dfs_lwip_getsocket(s); - if (lwip_shutdown(sock, how) == 0) + d = fd_get(s); + if (d == RT_NULL) { - /* socket has been closed, delete it from file system fd */ - fd_put(d); - fd_put(d); - - return 0; + rt_set_errno(-DFS_STATUS_EBADF); + + return -1; } - return -1; -} + sock = dfs_lwip_getsocket(s); + if (lwip_shutdown(sock, how) == 0) + { + /* socket has been closed, delete it from file system fd */ + fd_put(d); + fd_put(d); -int getpeername (int s, struct sockaddr *name, socklen_t *namelen) + return 0; + } + + return -1; +} +RTM_EXPORT(shutdown); + +int getpeername(int s, struct sockaddr *name, socklen_t *namelen) { int sock = dfs_lwip_getsocket(s); return lwip_getpeername(sock, name, namelen); } +RTM_EXPORT(getpeername); -int getsockname (int s, struct sockaddr *name, socklen_t *namelen) +int getsockname(int s, struct sockaddr *name, socklen_t *namelen) { int sock = dfs_lwip_getsocket(s); - + return lwip_getsockname(sock, name, namelen); } +RTM_EXPORT(getsockname); -int getsockopt (int s, int level, int optname, void *optval, socklen_t *optlen) +int getsockopt(int s, int level, int optname, void *optval, socklen_t *optlen) { int sock = dfs_lwip_getsocket(s); - + return lwip_getsockopt(sock, level, optname, optval, optlen); } +RTM_EXPORT(getsockopt); -int setsockopt (int s, int level, int optname, const void *optval, socklen_t optlen) +int setsockopt(int s, int level, int optname, const void *optval, socklen_t optlen) { int sock = dfs_lwip_getsocket(s); - + return lwip_setsockopt(sock, level, optname, optval, optlen); } +RTM_EXPORT(setsockopt); int connect(int s, const struct sockaddr *name, socklen_t namelen) { int sock = dfs_lwip_getsocket(s); - + return lwip_connect(sock, name, namelen); } +RTM_EXPORT(connect); int listen(int s, int backlog) { int sock = dfs_lwip_getsocket(s); - + return lwip_listen(sock, backlog); } +RTM_EXPORT(listen); int recv(int s, void *mem, size_t len, int flags) { int sock = dfs_lwip_getsocket(s); - + return lwip_recv(sock, mem, len, flags); } +RTM_EXPORT(recv); int recvfrom(int s, void *mem, size_t len, int flags, - struct sockaddr *from, socklen_t *fromlen) + struct sockaddr *from, socklen_t *fromlen) { int sock = dfs_lwip_getsocket(s); - + return lwip_recvfrom(sock, mem, len, flags, from, fromlen); } +RTM_EXPORT(recvfrom); int send(int s, const void *dataptr, size_t size, int flags) { int sock = dfs_lwip_getsocket(s); - + return lwip_send(sock, dataptr, size, flags); } +RTM_EXPORT(send); int sendto(int s, const void *dataptr, size_t size, int flags, - const struct sockaddr *to, socklen_t tolen) + const struct sockaddr *to, socklen_t tolen) { int sock = dfs_lwip_getsocket(s); - + return lwip_sendto(sock, dataptr, size, flags, to, tolen); } +RTM_EXPORT(sendto); int socket(int domain, int type, int protocol) { @@ -207,13 +220,13 @@ int socket(int domain, int type, int protocol) d->path = RT_NULL; d->fs = dfs_lwip_get_fs(); - + d->flags = DFS_O_RDWR; /* set flags as read and write */ d->size = 0; d->pos = 0; - + /* set socket to the data of dfs_fd */ - d->data = (void*) sock; + d->data = (void *) sock; } /* release the ref-count of fd */ @@ -221,4 +234,4 @@ int socket(int domain, int type, int protocol) return fd; } - +RTM_EXPORT(socket); diff --git a/components/dfs/filesystems/lwip/sys/socket.h b/components/dfs/filesystems/lwip/sys/socket.h index 5317e05e4c..b9608d97ed 100644 --- a/components/dfs/filesystems/lwip/sys/socket.h +++ b/components/dfs/filesystems/lwip/sys/socket.h @@ -29,9 +29,11 @@ extern "C" { #endif +#include #include typedef uint16_t sa_family_t; +typedef uint16_t in_port_t; struct sockaddr_storage { From e5edc5b09a6c66321114d3c417143c5bbe84df68 Mon Sep 17 00:00:00 2001 From: Bernard Xiong Date: Sun, 11 Oct 2015 15:39:07 +0800 Subject: [PATCH 19/36] [DFS] Use the win32 stat structure if using MS VC++ compiler. --- components/dfs/include/dfs_def.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/components/dfs/include/dfs_def.h b/components/dfs/include/dfs_def.h index e509c4a3da..0f75a5162b 100644 --- a/components/dfs/include/dfs_def.h +++ b/components/dfs/include/dfs_def.h @@ -255,6 +255,9 @@ #define DFS_S_IWOTH 00002 #define DFS_S_IXOTH 00001 +#ifdef _MSC_VER +#include +#else struct stat { rt_device_t st_dev; @@ -262,6 +265,7 @@ struct stat rt_uint32_t st_size; rt_time_t st_mtime; }; +#endif struct statfs { From c2b5cd1e85b11f25e3707a4e5f0ea3ca93ed48ae Mon Sep 17 00:00:00 2001 From: Bernard Xiong Date: Mon, 12 Oct 2015 10:52:14 +0800 Subject: [PATCH 20/36] [Finsh] fix the '\r' issue in linux telnet. --- components/finsh/shell.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/finsh/shell.c b/components/finsh/shell.c index ce80e4dec2..8962a7333f 100644 --- a/components/finsh/shell.c +++ b/components/finsh/shell.c @@ -425,7 +425,7 @@ void finsh_thread_entry(void *parameter) if (rt_device_read(shell->device, 0, &next, 1) == 1) { - if (next == '\0') ch = 'r'; /* linux telnet will issue '\0' */ + if (next == '\0') ch = '\r'; /* linux telnet will issue '\0' */ else ch = next; } else ch = '\r'; From c7af45b7593f8e1b54e963b65888e0db8a894b0e Mon Sep 17 00:00:00 2001 From: "www220@tom.com" Date: Mon, 12 Oct 2015 15:55:52 +0800 Subject: [PATCH 21/36] =?UTF-8?q?msh=E4=B8=AD=E7=9A=84mkfs=E5=91=BD?= =?UTF-8?q?=E4=BB=A4=E5=86=8D=E6=90=BA=E5=B8=A6=E7=B1=BB=E5=9E=8B=E6=98=AF?= =?UTF-8?q?=EF=BC=8C=E8=A7=A3=E6=9E=90=E5=87=BA=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/finsh/msh_cmd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/finsh/msh_cmd.c b/components/finsh/msh_cmd.c index 19eb5e0b72..a4b865b028 100644 --- a/components/finsh/msh_cmd.c +++ b/components/finsh/msh_cmd.c @@ -234,7 +234,7 @@ int cmd_mkfs(int argc, char **argv) if (strcmp(argv[1], "-t") == 0) { type = argv[2]; - result = dfs_mkfs(type, argv[1]); + result = dfs_mkfs(type, argv[3]); } } else From 1c91512e97b6591c9f6b0ef28e28b6de4f86c826 Mon Sep 17 00:00:00 2001 From: ardafu Date: Tue, 13 Oct 2015 09:49:27 +0800 Subject: [PATCH 22/36] [bsp][stm32f746g-disco] Fix MPU init bug. 1. Fixed the bug that MPU init function was called 2 times. --- bsp/stm32f7-disco/drivers/board.c | 4 ++-- bsp/stm32f7-disco/drivers/drv_mpu.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bsp/stm32f7-disco/drivers/board.c b/bsp/stm32f7-disco/drivers/board.c index 0553920a47..02f0acf2e6 100644 --- a/bsp/stm32f7-disco/drivers/board.c +++ b/bsp/stm32f7-disco/drivers/board.c @@ -25,7 +25,7 @@ #include #include "board.h" #include "sram.h" - +#include "drv_mpu.h" /** * @addtogroup STM32 @@ -165,7 +165,7 @@ void HAL_ResumeTick(void) void rt_hw_board_init() { /* Configure the MPU attributes as Write Through */ - //mpu_init(); + mpu_init(); /* Enable the CPU Cache */ CPU_CACHE_Enable(); diff --git a/bsp/stm32f7-disco/drivers/drv_mpu.c b/bsp/stm32f7-disco/drivers/drv_mpu.c index 630e48e2d2..ecf556203b 100644 --- a/bsp/stm32f7-disco/drivers/drv_mpu.c +++ b/bsp/stm32f7-disco/drivers/drv_mpu.c @@ -81,4 +81,4 @@ int mpu_init(void) HAL_MPU_Enable(MPU_PRIVILEGED_DEFAULT); return 0; } -INIT_BOARD_EXPORT(mpu_init); +//INIT_BOARD_EXPORT(mpu_init); From 78cb445af29bf78a4ea79e372da2554d0fc357a7 Mon Sep 17 00:00:00 2001 From: cedar-renjun <819280802@qq.com> Date: Tue, 13 Oct 2015 11:34:10 +0800 Subject: [PATCH 23/36] Create stm32f40x_flash.icf --- bsp/stm32f40x/stm32f40x_flash.icf | 33 +++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 bsp/stm32f40x/stm32f40x_flash.icf diff --git a/bsp/stm32f40x/stm32f40x_flash.icf b/bsp/stm32f40x/stm32f40x_flash.icf new file mode 100644 index 0000000000..8888d0e081 --- /dev/null +++ b/bsp/stm32f40x/stm32f40x_flash.icf @@ -0,0 +1,33 @@ +/*###ICF### Section handled by ICF editor, don't touch! ****/ +/*-Editor annotation file-*/ +/* IcfEditorFile="$TOOLKIT_DIR$\config\ide\IcfEditor\cortex_v1_0.xml" */ +/*-Specials-*/ +define symbol __ICFEDIT_intvec_start__ = 0x08000000; +/*-Memory Regions-*/ +define symbol __ICFEDIT_region_ROM_start__ = 0x08000000; +define symbol __ICFEDIT_region_ROM_end__ = 0x0807FFFF; +define symbol __ICFEDIT_region_RAM_start__ = 0x20000000; +define symbol __ICFEDIT_region_RAM_end__ = 0x2001FFFF; /*STM32 F446RE*/ +/*-Sizes-*/ +define symbol __ICFEDIT_size_cstack__ = 0x200; +define symbol __ICFEDIT_size_heap__ = 0x000; +/**** End of ICF editor section. ###ICF###*/ + + +define memory mem with size = 4G; +define region ROM_region = mem:[from __ICFEDIT_region_ROM_start__ to __ICFEDIT_region_ROM_end__]; +define region RAM_region = mem:[from __ICFEDIT_region_RAM_start__ to __ICFEDIT_region_RAM_end__]; + +define block CSTACK with alignment = 8, size = __ICFEDIT_size_cstack__ { }; +define block HEAP with alignment = 8, size = __ICFEDIT_size_heap__ { }; + +initialize by copy { readwrite }; +do not initialize { section .noinit }; + +keep { section FSymTab }; +keep { section VSymTab }; +keep { section .rti_fn* }; +place at address mem:__ICFEDIT_intvec_start__ { readonly section .intvec }; + +place in ROM_region { readonly }; +place in RAM_region { readwrite, block CSTACK, last block HEAP}; From 34a220042867dee8ee948e7021c4e7770e19f8fa Mon Sep 17 00:00:00 2001 From: cedar-renjun <819280802@qq.com> Date: Tue, 13 Oct 2015 11:40:59 +0800 Subject: [PATCH 24/36] include iar startup code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fixed bug: 'scons --target=iar -s' output iar project missing startup code, and link file 淇scons鐢熸垚IAR宸ョ▼涓病鏈塻tartup code鍜岄摼鎺ユ枃浠讹紝瀵艰嚧宸ョ▼涓柇寮傚父鍜孎insh鏃犳硶宸ヤ綔 --- bsp/stm32f40x/Libraries/SConscript | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bsp/stm32f40x/Libraries/SConscript b/bsp/stm32f40x/Libraries/SConscript index d23856456a..c83c06b439 100644 --- a/bsp/stm32f40x/Libraries/SConscript +++ b/bsp/stm32f40x/Libraries/SConscript @@ -18,8 +18,8 @@ if rtconfig.CROSS_TOOL == 'gcc': src = src + ['CMSIS/ST/STM32F4xx/Source/Templates/gcc_ride7/startup_stm32f4xx.s'] elif rtconfig.CROSS_TOOL == 'keil': src = src + ['CMSIS/ST/STM32F4xx/Source/Templates/arm/startup_stm32f4xx.s'] -# elif rtconfig.CROSS_TOOL == 'iar': - # src = src + ['CMSIS/CM3/DeviceSupport/ST/STM32F10x/startup/iar/' + startup_scripts[rtconfig.STM32_TYPE]] +elif rtconfig.CROSS_TOOL == 'iar': + src = src + ['CMSIS/ST/STM32F4xx/Source/Templates/iar/startup_stm32f4xx.s'] path = [cwd + '/STM32F4xx_StdPeriph_Driver/inc', cwd + '/CMSIS/ST/STM32F4xx/Include', From 238ebdd045f479c944bae64b312cfe174485b215 Mon Sep 17 00:00:00 2001 From: cedar-renjun <819280802@qq.com> Date: Tue, 13 Oct 2015 11:52:05 +0800 Subject: [PATCH 25/36] Update and rename readme.txt to readme.md --- bsp/stm32f40x/readme.md | 25 +++++++++++++++++++++++++ bsp/stm32f40x/readme.txt | 9 --------- 2 files changed, 25 insertions(+), 9 deletions(-) create mode 100644 bsp/stm32f40x/readme.md delete mode 100644 bsp/stm32f40x/readme.txt diff --git a/bsp/stm32f40x/readme.md b/bsp/stm32f40x/readme.md new file mode 100644 index 0000000000..e1d0e56820 --- /dev/null +++ b/bsp/stm32f40x/readme.md @@ -0,0 +1,25 @@ +board info: +STM32F4 discovery +http://www.st.com/internet/evalboard/product/252419.jsp + +note: +in drivers/stm32f4xx_conf.h + /* Redefine the HSE value; it's equal to 8 MHz on the STM32F4-DISCOVERY Kit */ + #define HSE_VALUE ((uint32_t)8000000) + + + + **================= IAR WARNING =================** + + after use `scons --target=iar -s` cmd to product IAR project, you have to add iar link file by hand + + IAR steps: + 1. Project-->Options-->Linker + 2. Config-->Linker Configuration file + 3. select `Override Default`, then select `bsp/stm32f40x/stm32f40x_flash.icf` + 4. rebuild project + + + **TODO** + auto add *.icf by scons script + diff --git a/bsp/stm32f40x/readme.txt b/bsp/stm32f40x/readme.txt deleted file mode 100644 index 7bebe251c6..0000000000 --- a/bsp/stm32f40x/readme.txt +++ /dev/null @@ -1,9 +0,0 @@ -board info: -STM32F4 discovery -http://www.st.com/internet/evalboard/product/252419.jsp - -note: -in drivers/stm32f4xx_conf.h - /* Redefine the HSE value; it's equal to 8 MHz on the STM32F4-DISCOVERY Kit */ - #define HSE_VALUE ((uint32_t)8000000) - From 45d46b076fcb8d9c85ac31edac1120c01a43930b Mon Sep 17 00:00:00 2001 From: "www220@tom.com" Date: Wed, 14 Oct 2015 10:28:25 +0800 Subject: [PATCH 26/36] =?UTF-8?q?=E4=BF=AE=E6=AD=A3romfs=E5=9C=A8=E8=BE=93?= =?UTF-8?q?=E5=85=A5=E7=9A=84=E7=9B=AE=E5=BD=95=E5=90=8D=E7=A7=B0=E6=AF=94?= =?UTF-8?q?=E5=AE=9E=E9=99=85=E7=9A=84=E5=90=8D=E7=A7=B0=E7=9F=AD=E6=97=B6?= =?UTF-8?q?=E5=AD=98=E5=9C=A8=E7=9A=84=E5=88=A4=E6=96=AD=E9=94=99=E8=AF=AF?= =?UTF-8?q?=20=E6=AF=94=E5=A6=82=E5=AE=9E=E9=99=85=E7=9B=AE=E5=BD=95?= =?UTF-8?q?=E4=B8=BAabcde=EF=BC=8Cmsh=E6=89=A7=E8=A1=8C=20cd=20abc?= =?UTF-8?q?=E4=B9=9F=E8=83=BD=E6=89=A7=E8=A1=8C=E6=88=90=E5=8A=9F=EF=BC=8C?= =?UTF-8?q?=E5=88=A4=E6=96=AD=E5=90=8D=E7=A7=B0=E6=97=B6=E5=AD=98=E5=9C=A8?= =?UTF-8?q?bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/dfs/filesystems/romfs/dfs_romfs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/components/dfs/filesystems/romfs/dfs_romfs.c b/components/dfs/filesystems/romfs/dfs_romfs.c index 1dd41b41eb..6110d61227 100644 --- a/components/dfs/filesystems/romfs/dfs_romfs.c +++ b/components/dfs/filesystems/romfs/dfs_romfs.c @@ -96,7 +96,8 @@ struct romfs_dirent *dfs_romfs_lookup(struct romfs_dirent *root_dirent, const ch { if (check_dirent(&dirent[index]) != 0) return RT_NULL; - if (rt_strncmp(dirent[index].name, subpath, (subpath_end - subpath)) == 0) + if (rt_strlen(dirent[index].name) == (subpath_end - subpath) && + rt_strncmp(dirent[index].name, subpath, (subpath_end - subpath)) == 0) { dirent_size = dirent[index].size; From e460034a97fc7da8891f6b4a1c8ddf476451b244 Mon Sep 17 00:00:00 2001 From: Bernard Xiong Date: Wed, 14 Oct 2015 11:07:03 +0800 Subject: [PATCH 27/36] [BSP] use DoBuilding to replace env.Program/EndBuilding --- bsp/frdm-k64f/SConstruct | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/bsp/frdm-k64f/SConstruct b/bsp/frdm-k64f/SConstruct index d4132b593c..eb4f3d8eac 100644 --- a/bsp/frdm-k64f/SConstruct +++ b/bsp/frdm-k64f/SConstruct @@ -30,8 +30,5 @@ Export('rtconfig') # prepare building environment objs = PrepareBuilding(env, RTT_ROOT, has_libcpu=False) -# build program -env.Program(TARGET, objs) - -# end building -EndBuilding(TARGET) +# do building +DoBuilding(TARGET, objs) From 1086f6cfa03330a7afc87830e8e9a36a4db554a4 Mon Sep 17 00:00:00 2001 From: Bernard Xiong Date: Wed, 14 Oct 2015 11:07:42 +0800 Subject: [PATCH 28/36] [Tools] Fix the buildlib with LOCAL_* options group --- tools/building.py | 42 ++++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/tools/building.py b/tools/building.py index 38b7881797..07f5e91fc9 100644 --- a/tools/building.py +++ b/tools/building.py @@ -497,37 +497,35 @@ def DoBuilding(target, objects): lst.append(item) return lst - objects = one_list(objects) - - # remove source files with local flags setting - for group in Projects: - if group.has_key('LOCAL_CCFLAGS') or group.has_key('LOCAL_CPPPATH') or group.has_key('LOCAL_CPPDEFINES'): - for source in group['src']: - for obj in objects: - if source.abspath == obj.abspath or (len(obj.sources) > 0 and source.abspath == obj.sources[0].abspath): - objects.remove(obj) - - # re-add the source files to the objects - for group in Projects: + # handle local group + def local_group(group, objects): if group.has_key('LOCAL_CCFLAGS') or group.has_key('LOCAL_CPPPATH') or group.has_key('LOCAL_CPPDEFINES'): CCFLAGS = Env.get('CCFLAGS', '') + group.get('LOCAL_CCFLAGS', '') CPPPATH = Env.get('CPPPATH', ['']) + group.get('LOCAL_CPPPATH', ['']) CPPDEFINES = Env.get('CPPDEFINES', ['']) + group.get('LOCAL_CPPDEFINES', ['']) for source in group['src']: - objects += Env.Object(source, CCFLAGS = CCFLAGS, - CPPPATH = CPPPATH, - CPPDEFINES = CPPDEFINES) + objects.append(Env.Object(source, CCFLAGS = CCFLAGS, + CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES)) + + return True + + return False + + objects = one_list(objects) program = None # check whether special buildlib option lib_name = GetOption('buildlib') if lib_name: + objects = [] # remove all of objects # build library with special component for Group in Projects: if Group['name'] == lib_name: lib_name = GroupLibName(Group['name'], Env) - objects = Env.Object(Group['src']) + if not local_group(Group, objects): + objects = Env.Object(Group['src']) + program = Env.Library(lib_name, objects) # add library copy action @@ -535,6 +533,18 @@ def DoBuilding(target, objects): break else: + # remove source files with local flags setting + for group in Projects: + if group.has_key('LOCAL_CCFLAGS') or group.has_key('LOCAL_CPPPATH') or group.has_key('LOCAL_CPPDEFINES'): + for source in group['src']: + for obj in objects: + if source.abspath == obj.abspath or (len(obj.sources) > 0 and source.abspath == obj.sources[0].abspath): + objects.remove(obj) + + # re-add the source files to the objects + for group in Projects: + local_group(group, objects) + program = Env.Program(target, objects) EndBuilding(target, program) From 066ec6dc917e83102ea6d5f8ac07bc4209ba536d Mon Sep 17 00:00:00 2001 From: Bernard Xiong Date: Thu, 15 Oct 2015 12:22:16 +0800 Subject: [PATCH 29/36] [BSP] remove display_controller.h/c from ls1cdev bsp --- bsp/ls1cdev/applications/application.c | 36 +--- bsp/ls1cdev/applications/startup.c | 6 - bsp/ls1cdev/drivers/SConscript | 4 - bsp/ls1cdev/drivers/board.c | 2 - bsp/ls1cdev/drivers/display_controller.c | 234 ----------------------- bsp/ls1cdev/drivers/display_controller.h | 59 ------ bsp/ls1cdev/rtconfig.h | 11 +- 7 files changed, 11 insertions(+), 341 deletions(-) delete mode 100644 bsp/ls1cdev/drivers/display_controller.c delete mode 100644 bsp/ls1cdev/drivers/display_controller.h diff --git a/bsp/ls1cdev/applications/application.c b/bsp/ls1cdev/applications/application.c index f907c9f347..6690da528a 100644 --- a/bsp/ls1cdev/applications/application.c +++ b/bsp/ls1cdev/applications/application.c @@ -9,44 +9,18 @@ * * Change Logs: * Date Author Notes - * 2010-06-25 Bernard first version - * 2011-08-08 lgnq modified for Loongson LS1B - * 2015-07-06 chinesebear modified for Loongson LS1C + * 2010-06-25 Bernard first version + * 2011-08-08 lgnq modified for Loongson LS1B + * 2015-07-06 chinesebear modified for Loongson LS1C */ #include -#include - -#ifdef RT_USING_COMPONENTS_INIT #include -#endif - -#ifdef RT_USING_RTGUI -#include -extern void rt_hw_dc_init(void); -#endif void rt_init_thread_entry(void *parameter) { -#ifdef RT_USING_RTGUI - { - rt_device_t dc; - - /* init Display Controller */ - rt_hw_dc_init(); - - /* find Display Controller device */ - dc = rt_device_find("dc"); - - /* set Display Controller device as rtgui graphic driver */ - rtgui_graphic_set_device(dc); - } -#endif - -#ifdef RT_USING_COMPONENTS_INIT /* initialization RT-Thread Components */ rt_components_init(); -#endif } int rt_application_init(void) @@ -56,11 +30,9 @@ int rt_application_init(void) /* create initialization thread */ tid = rt_thread_create("init", rt_init_thread_entry, RT_NULL, - 4096, 8, 20); + 4096, RT_THREAD_PRIORITY_MAX/3, 20); if (tid != RT_NULL) rt_thread_startup(tid); return 0; } - - diff --git a/bsp/ls1cdev/applications/startup.c b/bsp/ls1cdev/applications/startup.c index 36171b72c1..5c78776f84 100644 --- a/bsp/ls1cdev/applications/startup.c +++ b/bsp/ls1cdev/applications/startup.c @@ -77,12 +77,6 @@ void rtthread_startup(void) /* init application */ rt_application_init(); - /* init finsh*/ - #ifdef RT_USING_FINSH - finsh_system_init(); - finsh_set_device("uart2"); - #endif - /* start scheduler */ rt_system_scheduler_start(); diff --git a/bsp/ls1cdev/drivers/SConscript b/bsp/ls1cdev/drivers/SConscript index 5e1060d78e..6c6d2c7adb 100644 --- a/bsp/ls1cdev/drivers/SConscript +++ b/bsp/ls1cdev/drivers/SConscript @@ -3,10 +3,6 @@ from building import * cwd = GetCurrentDir() src = Glob('*.c') -# remove no need file. -if GetDepend('RT_USING_RTGUI') == False: - SrcRemove(src, 'display_controller.c') - CPPPATH = [cwd] group = DefineGroup('Drivers', src, depend = [''], CPPPATH = CPPPATH) diff --git a/bsp/ls1cdev/drivers/board.c b/bsp/ls1cdev/drivers/board.c index c1267b8f7d..f9c7454a16 100644 --- a/bsp/ls1cdev/drivers/board.c +++ b/bsp/ls1cdev/drivers/board.c @@ -110,5 +110,3 @@ void rt_hw_console_output(const char *ptr) } /*@}*/ - - diff --git a/bsp/ls1cdev/drivers/display_controller.c b/bsp/ls1cdev/drivers/display_controller.c deleted file mode 100644 index 1c91ebf8d8..0000000000 --- a/bsp/ls1cdev/drivers/display_controller.c +++ /dev/null @@ -1,234 +0,0 @@ -/* - * File : display_controller.c - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2006-2012, RT-Thread Develop Team - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rt-thread.org/license/LICENSE - * - * Change Logs: - * Date Author Notes - * 2011-08-09 lgnq first version for LS1B DC - */ - -#include -#include "display_controller.h" - -struct vga_struct vga_mode[] = -{ - {/*"640x480_70.00"*/ 28560, 640, 664, 728, 816, 480, 481, 484, 500, }, - {/*"640x640_60.00"*/ 33100, 640, 672, 736, 832, 640, 641, 644, 663, }, - {/*"640x768_60.00"*/ 39690, 640, 672, 736, 832, 768, 769, 772, 795, }, - {/*"640x800_60.00"*/ 42130, 640, 680, 744, 848, 800, 801, 804, 828, }, - {/*"800x480_70.00"*/ 35840, 800, 832, 912, 1024, 480, 481, 484, 500, }, - {/*"800x600_60.00"*/ 38220, 800, 832, 912, 1024, 600, 601, 604, 622, }, - {/*"800x640_60.00"*/ 40730, 800, 832, 912, 1024, 640, 641, 644, 663, }, - {/*"832x600_60.00"*/ 40010, 832, 864, 952, 1072, 600, 601, 604, 622, }, - {/*"832x608_60.00"*/ 40520, 832, 864, 952, 1072, 608, 609, 612, 630, }, - {/*"1024x480_60.00"*/ 38170, 1024, 1048, 1152, 1280, 480, 481, 484, 497, }, - {/*"1024x600_60.00"*/ 48960, 1024, 1064, 1168, 1312, 600, 601, 604, 622, }, - {/*"1024x640_60.00"*/ 52830, 1024, 1072, 1176, 1328, 640, 641, 644, 663, }, - {/*"1024x768_60.00"*/ 64110, 1024, 1080, 1184, 1344, 768, 769, 772, 795, }, - {/*"1152x764_60.00"*/ 71380, 1152, 1208, 1328, 1504, 764, 765, 768, 791, }, - {/*"1280x800_60.00"*/ 83460, 1280, 1344, 1480, 1680, 800, 801, 804, 828, }, - {/*"1280x1024_55.00"*/ 98600, 1280, 1352, 1488, 1696, 1024, 1025, 1028, 1057, }, - {/*"1440x800_60.00"*/ 93800, 1440, 1512, 1664, 1888, 800, 801, 804, 828, }, - {/*"1440x900_67.00"*/ 120280, 1440, 1528, 1680, 1920, 900, 901, 904, 935, }, -}; - -ALIGN(16) -volatile rt_uint16_t _rt_framebuffer[FB_YSIZE][FB_XSIZE]; -static struct rt_device_graphic_info _dc_info; - -#define abs(x) ((x<0)?(-x):x) -#define min(a,b) ((atype = RT_Device_Class_Graphic; - dc->init = rt_dc_init; - dc->open = RT_NULL; - dc->close = RT_NULL; - dc->control = rt_dc_control; - dc->user_data = (void*)&_dc_info; - - /* register Display Controller device to RT-Thread */ - rt_device_register(dc, "dc", RT_DEVICE_FLAG_RDWR); -} diff --git a/bsp/ls1cdev/drivers/display_controller.h b/bsp/ls1cdev/drivers/display_controller.h deleted file mode 100644 index 6ea1657037..0000000000 --- a/bsp/ls1cdev/drivers/display_controller.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * File : display_controller.h - * This file is part of RT-Thread RTOS - * COPYRIGHT (C) 2006-2012, RT-Thread Develop Team - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rt-thread.org/license/LICENSE - * - * Change Logs: - * Date Author Notes - * 2011-08-08 lgnq first version for LS1B - * 2015-07-06 chinesebear modified for loongson 1c - */ - -#ifndef __DISPLAY_CONTROLLER_H__ -#define __DISPLAY_CONTROLLER_H__ - -#include -#include "ls1c.h" - -#define DC_BASE 0xBC301240 //Display Controller - -/* Frame Buffer registers */ -#define DC_FB_CONFIG __REG32(DC_BASE + 0x000) -#define DC_FB_BUFFER_ADDR0 __REG32(DC_BASE + 0x020) -#define DC_FB_BUFFER_STRIDE __REG32(DC_BASE + 0x040) -#define DC_FB_BUFFER_ORIGIN __REG32(DC_BASE + 0x060) -#define DC_DITHER_CONFIG __REG32(DC_BASE + 0x120) -#define DC_DITHER_TABLE_LOW __REG32(DC_BASE + 0x140) -#define DC_DITHER_TABLE_HIGH __REG32(DC_BASE + 0x160) -#define DC_PANEL_CONFIG __REG32(DC_BASE + 0x180) -#define DC_PANEL_TIMING __REG32(DC_BASE + 0x1A0) -#define DC_HDISPLAY __REG32(DC_BASE + 0x1C0) -#define DC_HSYNC __REG32(DC_BASE + 0x1E0) -#define DC_VDISPLAY __REG32(DC_BASE + 0x240) -#define DC_VSYNC __REG32(DC_BASE + 0x260) -#define DC_FB_BUFFER_ADDR1 __REG32(DC_BASE + 0x340) - -/* Display Controller driver for 1024x768 16bit */ -#define FB_XSIZE 1024 -#define FB_YSIZE 768 -#define CONFIG_VIDEO_16BPP - -#define APB_CLK 33333333 - -#define K1BASE 0xA0000000 -#define KSEG1(addr) ((void *)(K1BASE | (rt_uint32_t)(addr))) -#define HW_FB_ADDR KSEG1(_rt_framebuffer) -#define HW_FB_PIXEL(x, y) *(volatile rt_uint16_t*)((rt_uint8_t*)HW_FB_ADDR + (y * FB_XSIZE * 2) + x * 2) - -struct vga_struct -{ - long pclk; - int hr,hss,hse,hfl; - int vr,vss,vse,vfl; -}; - -#endif diff --git a/bsp/ls1cdev/rtconfig.h b/bsp/ls1cdev/rtconfig.h index 6c021a44dc..d6fed266e6 100644 --- a/bsp/ls1cdev/rtconfig.h +++ b/bsp/ls1cdev/rtconfig.h @@ -23,6 +23,8 @@ #define RT_USING_OVERFLOW_CHECK // #define RT_USING_INTERRUPT_INFO +// +#define IDLE_THREAD_STACK_SIZE 1024 //
// @@ -91,15 +93,16 @@ #define FINSH_USING_DESCRIPTION // #define FINSH_THREAD_STACK_SIZE 4096 +// +#define FINSH_USING_MSH +// +#define FINSH_USING_MSH_DEFAULT // - //
#define RT_USING_LIBC -// -// #define RT_USING_NEWLIB // -// #define RT_USING_PTHREADS +#define RT_USING_PTHREADS //
//
From 68095474915c95f9271151e2e8eece48bee05200 Mon Sep 17 00:00:00 2001 From: Bernard Xiong Date: Thu, 15 Oct 2015 23:10:59 +0800 Subject: [PATCH 30/36] [lwIP] Add ETHIF_LINK_AUTOUP/PHYUP flag to ethernet interface --- components/net/lwip-1.4.1/src/arch/sys_arch.c | 7 ++++--- .../net/lwip-1.4.1/src/include/netif/ethernetif.h | 10 +++++++--- components/net/lwip-1.4.1/src/netif/ethernetif.c | 14 ++++++++------ 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/components/net/lwip-1.4.1/src/arch/sys_arch.c b/components/net/lwip-1.4.1/src/arch/sys_arch.c index d3a69f9ac3..c0aed9d4f0 100644 --- a/components/net/lwip-1.4.1/src/arch/sys_arch.c +++ b/components/net/lwip-1.4.1/src/arch/sys_arch.c @@ -115,9 +115,10 @@ static void tcpip_init_done_callback(void *arg) netif_set_up(ethif->netif); } -#if LWIP_NETIF_LINK_CALLBACK - netif_set_link_up(ethif->netif); -#endif + if (!(ethif->flags & ETHIF_LINK_PHYUP)) + { + netif_set_link_up(ethif->netif); + } /* enter critical */ rt_enter_critical(); diff --git a/components/net/lwip-1.4.1/src/include/netif/ethernetif.h b/components/net/lwip-1.4.1/src/include/netif/ethernetif.h index 2019df7017..bdad32ec20 100644 --- a/components/net/lwip-1.4.1/src/include/netif/ethernetif.h +++ b/components/net/lwip-1.4.1/src/include/netif/ethernetif.h @@ -11,6 +11,10 @@ #define ETHERNET_MTU RT_LWIP_ETH_MTU #endif +/* eth flag with auto_linkup or phy_linkup */ +#define ETHIF_LINK_AUTOUP 0x0000 +#define ETHIF_LINK_PHYUP 0x0100 + struct eth_device { /* inherit from rt_device */ @@ -20,9 +24,9 @@ struct eth_device struct netif *netif; struct rt_semaphore tx_ack; - rt_uint8_t flags; + rt_uint16_t flags; rt_uint8_t link_changed; - rt_uint16_t link_status; + rt_uint8_t link_status; /* eth device interface */ struct pbuf* (*eth_rx)(rt_device_t dev); @@ -31,7 +35,7 @@ struct eth_device rt_err_t eth_device_ready(struct eth_device* dev); rt_err_t eth_device_init(struct eth_device * dev, char *name); -rt_err_t eth_device_init_with_flag(struct eth_device *dev, char *name, rt_uint8_t flag); +rt_err_t eth_device_init_with_flag(struct eth_device *dev, char *name, rt_uint16_t flag); rt_err_t eth_device_linkchange(struct eth_device* dev, rt_bool_t up); int eth_system_device_init(void); diff --git a/components/net/lwip-1.4.1/src/netif/ethernetif.c b/components/net/lwip-1.4.1/src/netif/ethernetif.c index 2e0ef2f8bd..f0b2f814dc 100644 --- a/components/net/lwip-1.4.1/src/netif/ethernetif.c +++ b/components/net/lwip-1.4.1/src/netif/ethernetif.c @@ -154,7 +154,7 @@ static err_t eth_netif_device_init(struct netif *netif) } /* copy device flags to netif flags */ - netif->flags = ethif->flags; + netif->flags = (ethif->flags & 0xff); /* set default netif */ if (netif_default == RT_NULL) @@ -173,9 +173,11 @@ static err_t eth_netif_device_init(struct netif *netif) netif_set_up(ethif->netif); } -#ifdef LWIP_NETIF_LINK_CALLBACK - netif_set_link_up(ethif->netif); -#endif + if (!(ethif->flags & ETHIF_LINK_PHYUP)) + { + /* set link_up for this netif */ + netif_set_link_up(ethif->netif); + } return ERR_OK; } @@ -184,7 +186,7 @@ static err_t eth_netif_device_init(struct netif *netif) } /* Keep old drivers compatible in RT-Thread */ -rt_err_t eth_device_init_with_flag(struct eth_device *dev, char *name, rt_uint8_t flags) +rt_err_t eth_device_init_with_flag(struct eth_device *dev, char *name, rt_uint16_t flags) { struct netif* netif; @@ -246,7 +248,7 @@ rt_err_t eth_device_init_with_flag(struct eth_device *dev, char *name, rt_uint8_ rt_err_t eth_device_init(struct eth_device * dev, char *name) { - rt_uint8_t flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP; + rt_uint16_t flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP; #if LWIP_DHCP /* DHCP support */ From 8f607deff3ec6f072d7a5efbd8e72da82cea1970 Mon Sep 17 00:00:00 2001 From: Bernard Xiong Date: Thu, 15 Oct 2015 23:14:27 +0800 Subject: [PATCH 31/36] [BSP] Add EMAC driver in lpc4088 --- .../Templates/system_LPC407x_8x_177x_8x.c | 4 +- bsp/lpc408x/Libraries/Device/SConscript | 2 +- bsp/lpc408x/applications/board.c | 5 +- bsp/lpc408x/applications/board.h | 18 +- bsp/lpc408x/drivers/drv_emac.c | 512 ++++++++++++++++++ bsp/lpc408x/drivers/drv_emac.h | 291 ++++++++++ bsp/lpc408x/drivers/drv_led.c | 33 +- bsp/lpc408x/drivers/drv_sdram.c | 153 ++++++ bsp/lpc408x/drivers/drv_sdram.h | 35 ++ bsp/lpc408x/drivers/drv_uart.c | 280 ++++++---- bsp/lpc408x/drivers/drv_uart.h | 14 + bsp/lpc408x/rtconfig.h | 2 +- bsp/lpc408x/template.uvopt | 164 ++++++ 13 files changed, 1382 insertions(+), 131 deletions(-) create mode 100644 bsp/lpc408x/drivers/drv_emac.c create mode 100644 bsp/lpc408x/drivers/drv_emac.h create mode 100644 bsp/lpc408x/drivers/drv_sdram.c create mode 100644 bsp/lpc408x/drivers/drv_sdram.h create mode 100644 bsp/lpc408x/template.uvopt diff --git a/bsp/lpc408x/Libraries/Device/NXP/LPC407x_8x_177x_8x/Source/Templates/system_LPC407x_8x_177x_8x.c b/bsp/lpc408x/Libraries/Device/NXP/LPC407x_8x_177x_8x/Source/Templates/system_LPC407x_8x_177x_8x.c index d85871526e..b716d06f62 100644 --- a/bsp/lpc408x/Libraries/Device/NXP/LPC407x_8x_177x_8x/Source/Templates/system_LPC407x_8x_177x_8x.c +++ b/bsp/lpc408x/Libraries/Device/NXP/LPC407x_8x_177x_8x/Source/Templates/system_LPC407x_8x_177x_8x.c @@ -221,12 +221,12 @@ #define SCS_Val 0x00000020 #define CLKSRCSEL_Val 0x00000001 #define PLL0_SETUP 1 -#define PLL0CFG_Val 0x0000000a +#define PLL0CFG_Val 0x00000009 #define PLL1_SETUP 1 #define PLL1CFG_Val 0x00000023 #define CCLKSEL_Val 0x00000101 #define USBCLKSEL_Val 0x00000201 -#define EMCCLKSEL_Val 0x00000001 +#define EMCCLKSEL_Val 0x00000000 #define PCLKSEL_Val 0x00000002 #define SPIFICLKSEL_Val 0x00000002 #define PCONP_Val 0x042887DE diff --git a/bsp/lpc408x/Libraries/Device/SConscript b/bsp/lpc408x/Libraries/Device/SConscript index f61ac45490..6d7e911b8e 100644 --- a/bsp/lpc408x/Libraries/Device/SConscript +++ b/bsp/lpc408x/Libraries/Device/SConscript @@ -18,6 +18,6 @@ elif rtconfig.CROSS_TOOL == 'keil': elif rtconfig.CROSS_TOOL == 'iar': src += ['NXP/LPC407x_8x_177x_8x/Source/Templates/IAR/startup_LPC407x_8x_177x_8x.s'] -group = DefineGroup('CMSIS', src, depend = [''], CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES) +group = DefineGroup('Libraries', src, depend = [''], CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES) Return('group') diff --git a/bsp/lpc408x/applications/board.c b/bsp/lpc408x/applications/board.c index ed1e8e769b..a2bb22bfe4 100644 --- a/bsp/lpc408x/applications/board.c +++ b/bsp/lpc408x/applications/board.c @@ -52,9 +52,10 @@ void rt_hw_board_init() #endif /* init systick */ - SysTick_Config(SystemCoreClock / RT_TICK_PER_SECOND); + SysTick_Config(SystemCoreClock / RT_TICK_PER_SECOND - 1); /* set pend exception priority */ NVIC_SetPriority(PendSV_IRQn, (1 << __NVIC_PRIO_BITS) - 1); + /*init uart device*/ rt_hw_uart_init(); rt_console_set_device(RT_CONSOLE_DEVICE_NAME); @@ -64,5 +65,5 @@ void rt_hw_board_init() lpc_sdram_hw_init(); rt_kprintf("done!\n"); #endif - rt_components_board_init(); + // rt_components_board_init(); } diff --git a/bsp/lpc408x/applications/board.h b/bsp/lpc408x/applications/board.h index f34cb2acee..392dcf2031 100644 --- a/bsp/lpc408x/applications/board.h +++ b/bsp/lpc408x/applications/board.h @@ -11,6 +11,7 @@ * Date Author Notes * 2009-09-22 Bernard add board.h to this bsp * 2010-02-04 Magicoe add board.h to LPC176x bsp + * 2013-12-18 Bernard porting to LPC4088 bsp */ #ifndef __BOARD_H__ @@ -19,10 +20,21 @@ #include "LPC407x_8x_177x_8x.h" #include +/* SRAM allocation for Peripherals */ +#define USB_RAM_BASE 0x20000000 +#define MCI_RAM_BASE 0x20002000 +#define ETH_RAM_BASE 0x20004000 + +/* use SDRAM in default */ +#define LPC_EXT_SDRAM 1 + +/* disable SDRAM in default */ +#ifndef LPC_EXT_SDRAM +#define LPC_EXT_SDRAM 0 +#endif + // -// -//#define LPC_EXT_SDRAM 0 // #define LPC_EXT_SDRAM_BEGIN 0xA0000000 // @@ -47,7 +59,7 @@ extern int Image$$RW_IRAM1$$ZI$$Limit; extern int __bss_end; #define HEAP_BEGIN ((void *)&__bss_end) #endif -#define HEAP_END (0x10000000 + 0x10000) +#define HEAP_END (void*)(0x10000000 + 0x10000) #define FINSH_DEVICE_NAME RT_CONSOLE_DEVICE_NAME void rt_hw_board_init(void); diff --git a/bsp/lpc408x/drivers/drv_emac.c b/bsp/lpc408x/drivers/drv_emac.c new file mode 100644 index 0000000000..2b6293a953 --- /dev/null +++ b/bsp/lpc408x/drivers/drv_emac.c @@ -0,0 +1,512 @@ +/* + * File : drv_emac.c + * This file is part of RT-Thread RTOS + * COPYRIGHT (C) 2009-2013 RT-Thread Develop Team + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rt-thread.org/license/LICENSE + * + * Change Logs: + * Date Author Notes + * 2013-05-19 Bernard porting from LPC17xx drivers. + */ + +#include +#include "lwipopts.h" +#include +#include + +#include "lpc_pinsel.h" +#include "drv_emac.h" + +#define EMAC_PHY_AUTO 0 +#define EMAC_PHY_10MBIT 1 +#define EMAC_PHY_100MBIT 2 + +#define MAX_ADDR_LEN 6 + +/* EMAC_RAM_BASE is defined in board.h and the size is 16KB */ +#define RX_DESC_BASE ETH_RAM_BASE +#define RX_STAT_BASE (RX_DESC_BASE + NUM_RX_FRAG*8) +#define TX_DESC_BASE (RX_STAT_BASE + NUM_RX_FRAG*8) +#define TX_STAT_BASE (TX_DESC_BASE + NUM_TX_FRAG*8) +#define RX_BUF_BASE (TX_STAT_BASE + NUM_TX_FRAG*4) +#define TX_BUF_BASE (RX_BUF_BASE + NUM_RX_FRAG*ETH_FRAG_SIZE) + +/* RX and TX descriptor and status definitions. */ +#define RX_DESC_PACKET(i) (*(unsigned int *)(RX_DESC_BASE + 8*i)) +#define RX_DESC_CTRL(i) (*(unsigned int *)(RX_DESC_BASE+4 + 8*i)) +#define RX_STAT_INFO(i) (*(unsigned int *)(RX_STAT_BASE + 8*i)) +#define RX_STAT_HASHCRC(i) (*(unsigned int *)(RX_STAT_BASE+4 + 8*i)) +#define TX_DESC_PACKET(i) (*(unsigned int *)(TX_DESC_BASE + 8*i)) +#define TX_DESC_CTRL(i) (*(unsigned int *)(TX_DESC_BASE+4 + 8*i)) +#define TX_STAT_INFO(i) (*(unsigned int *)(TX_STAT_BASE + 4*i)) +#define RX_BUF(i) (RX_BUF_BASE + ETH_FRAG_SIZE*i) +#define TX_BUF(i) (TX_BUF_BASE + ETH_FRAG_SIZE*i) + +struct lpc_emac +{ + /* inherit from ethernet device */ + struct eth_device parent; + + rt_uint8_t phy_mode; + + /* interface address info. */ + rt_uint8_t dev_addr[MAX_ADDR_LEN]; /* hw address */ +}; +static struct lpc_emac lpc_emac_device; +static struct rt_semaphore sem_lock; +static struct rt_event tx_event; + +/* Local Function Prototypes */ +static void write_PHY(rt_uint32_t PhyReg, rt_uint32_t Value); +static rt_uint16_t read_PHY(rt_uint8_t PhyReg) ; + +void ENET_IRQHandler(void) +{ + rt_uint32_t status; + + /* enter interrupt */ + rt_interrupt_enter(); + + status = LPC_EMAC->IntStatus; + + if (status & INT_RX_DONE) + { + /* Disable EMAC RxDone interrupts. */ + LPC_EMAC->IntEnable = INT_TX_DONE; + + /* a frame has been received */ + eth_device_ready(&(lpc_emac_device.parent)); + } + else if (status & INT_TX_DONE) + { + /* set event */ + rt_event_send(&tx_event, 0x01); + } + + if (status & INT_RX_OVERRUN) + { + rt_kprintf("rx overrun\n"); + } + + if (status & INT_TX_UNDERRUN) + { + rt_kprintf("tx underrun\n"); + } + + /* Clear the interrupt. */ + LPC_EMAC->IntClear = status; + + /* leave interrupt */ + rt_interrupt_leave(); +} + +/* phy write */ +static void write_PHY(rt_uint32_t PhyReg, rt_uint32_t Value) +{ + unsigned int tout; + + LPC_EMAC->MADR = DP83848C_DEF_ADR | PhyReg; + LPC_EMAC->MWTD = Value; + + /* Wait utill operation completed */ + tout = 0; + for (tout = 0; tout < MII_WR_TOUT; tout++) + { + if ((LPC_EMAC->MIND & MIND_BUSY) == 0) + { + break; + } + } +} + +/* phy read */ +static rt_uint16_t read_PHY(rt_uint8_t PhyReg) +{ + rt_uint32_t tout; + + LPC_EMAC->MADR = DP83848C_DEF_ADR | PhyReg; + LPC_EMAC->MCMD = MCMD_READ; + + /* Wait until operation completed */ + tout = 0; + for (tout = 0; tout < MII_RD_TOUT; tout++) + { + if ((LPC_EMAC->MIND & MIND_BUSY) == 0) + { + break; + } + } + LPC_EMAC->MCMD = 0; + return (LPC_EMAC->MRDD); +} + +/* init rx descriptor */ +rt_inline void rx_descr_init(void) +{ + rt_uint32_t i; + + for (i = 0; i < NUM_RX_FRAG; i++) + { + RX_DESC_PACKET(i) = RX_BUF(i); + RX_DESC_CTRL(i) = RCTRL_INT | (ETH_FRAG_SIZE - 1); + RX_STAT_INFO(i) = 0; + RX_STAT_HASHCRC(i) = 0; + } + + /* Set EMAC Receive Descriptor Registers. */ + LPC_EMAC->RxDescriptor = RX_DESC_BASE; + LPC_EMAC->RxStatus = RX_STAT_BASE; + LPC_EMAC->RxDescriptorNumber = NUM_RX_FRAG - 1; + + /* Rx Descriptors Point to 0 */ + LPC_EMAC->RxConsumeIndex = 0; +} + +/* init tx descriptor */ +rt_inline void tx_descr_init(void) +{ + rt_uint32_t i; + + for (i = 0; i < NUM_TX_FRAG; i++) + { + TX_DESC_PACKET(i) = TX_BUF(i); + TX_DESC_CTRL(i) = (1ul << 31) | (1ul << 30) | (1ul << 29) | (1ul << 28) | (1ul << 26) | (ETH_FRAG_SIZE - 1); + TX_STAT_INFO(i) = 0; + } + + /* Set EMAC Transmit Descriptor Registers. */ + LPC_EMAC->TxDescriptor = TX_DESC_BASE; + LPC_EMAC->TxStatus = TX_STAT_BASE; + LPC_EMAC->TxDescriptorNumber = NUM_TX_FRAG - 1; + + /* Tx Descriptors Point to 0 */ + LPC_EMAC->TxProduceIndex = 0; +} + +/* +TX_EN P1_4 +TXD0 P1_0 +TXD1 P1_1 + +RXD0 P1_9 +RXD1 P1_10 +RX_ER P1_14 +CRS_DV P1_8 + +MDC P1_16 +MDIO P1_17 + +REF_CLK P1_15 +*/ +static rt_err_t lpc_emac_init(rt_device_t dev) +{ + /* Initialize the EMAC ethernet controller. */ + rt_uint32_t regv, tout; + + /* Power Up the EMAC controller. */ + LPC_SC->PCONP |= (1UL << 30); + + /* Enable P1 Ethernet Pins. */ + PINSEL_ConfigPin(1, 0, 1); /**< P1_0 ENET_TXD0 */ + PINSEL_ConfigPin(1, 1, 1); /**< P1_1 ENET_TXD1 */ + PINSEL_ConfigPin(1, 4, 1); /**< P1_4 ENET_TX_EN */ + PINSEL_ConfigPin(1, 8, 1); /**< P1_8 ENET_CRS_DV */ + PINSEL_ConfigPin(1, 9, 1); /**< P1_9 ENET_RXD0 */ + PINSEL_ConfigPin(1, 10, 1); /**< P1_10 ENET_RXD1 */ + PINSEL_ConfigPin(1, 14, 1); /**< P1_14 ENET_RX_ER */ + PINSEL_ConfigPin(1, 15, 1); /**< P1_15 ENET_REF_CLK */ + PINSEL_ConfigPin(1, 16, 1); /**< P1_16 ENET_MDC */ + PINSEL_ConfigPin(1, 17, 1); /**< P1_17 ENET_MDIO */ + + /* Reset all EMAC internal modules. */ + LPC_EMAC->MAC1 = MAC1_RES_TX | MAC1_RES_MCS_TX | MAC1_RES_RX | MAC1_RES_MCS_RX | + MAC1_SIM_RES | MAC1_SOFT_RES; + LPC_EMAC->Command = CR_REG_RES | CR_TX_RES | CR_RX_RES; + + /* A short delay after reset. */ + for (tout = 100; tout; tout--); + + /* Initialize MAC control registers. */ + LPC_EMAC->MAC1 = MAC1_PASS_ALL; + LPC_EMAC->MAC2 = MAC2_CRC_EN | MAC2_PAD_EN; + LPC_EMAC->MAXF = ETH_MAX_FLEN; + LPC_EMAC->CLRT = CLRT_DEF; + LPC_EMAC->IPGR = IPGR_DEF; + + /* PCLK=18MHz, clock select=6, MDC=18/6=3MHz */ + /* Enable Reduced MII interface. */ + LPC_EMAC->MCFG = MCFG_CLK_DIV20 | MCFG_RES_MII; + for (tout = 100; tout; tout--); + LPC_EMAC->MCFG = MCFG_CLK_DIV20; + + /* Enable Reduced MII interface. */ + LPC_EMAC->Command = CR_RMII | CR_PASS_RUNT_FRM | CR_PASS_RX_FILT; + + /* Reset Reduced MII Logic. */ + LPC_EMAC->SUPP = SUPP_RES_RMII | SUPP_SPEED; + for (tout = 100; tout; tout--); + LPC_EMAC->SUPP = SUPP_SPEED; + + /* Put the PHY in reset mode */ + write_PHY(PHY_REG_BMCR, 0x8000); + for (tout = 1000; tout; tout--); + + /* Configure the PHY device */ + /* Configure the PHY device */ + switch (lpc_emac_device.phy_mode) + { + case EMAC_PHY_AUTO: + /* Use autonegotiation about the link speed. */ + write_PHY(PHY_REG_BMCR, PHY_AUTO_NEG); + break; + case EMAC_PHY_10MBIT: + /* Connect at 10MBit */ + write_PHY(PHY_REG_BMCR, PHY_FULLD_10M); + break; + case EMAC_PHY_100MBIT: + /* Connect at 100MBit */ + write_PHY(PHY_REG_BMCR, PHY_FULLD_100M); + break; + } + if (tout >= 0x100000) return -RT_ERROR; // auto_neg failed + + regv = 0x0004; + /* Configure Full/Half Duplex mode. */ + if (regv & 0x0004) + { + /* Full duplex is enabled. */ + LPC_EMAC->MAC2 |= MAC2_FULL_DUP; + LPC_EMAC->Command |= CR_FULL_DUP; + LPC_EMAC->IPGT = IPGT_FULL_DUP; + } + else + { + /* Half duplex mode. */ + LPC_EMAC->IPGT = IPGT_HALF_DUP; + } + + /* Configure 100MBit/10MBit mode. */ + if (regv & 0x0002) + { + /* 10MBit mode. */ + LPC_EMAC->SUPP = 0; + } + else + { + /* 100MBit mode. */ + LPC_EMAC->SUPP = SUPP_SPEED; + } + + /* Set the Ethernet MAC Address registers */ + LPC_EMAC->SA0 = (lpc_emac_device.dev_addr[1] << 8) | lpc_emac_device.dev_addr[0]; + LPC_EMAC->SA1 = (lpc_emac_device.dev_addr[3] << 8) | lpc_emac_device.dev_addr[2]; + LPC_EMAC->SA2 = (lpc_emac_device.dev_addr[5] << 8) | lpc_emac_device.dev_addr[4]; + + /* Initialize Tx and Rx DMA Descriptors */ + rx_descr_init(); + tx_descr_init(); + + /* Receive Broadcast and Perfect Match Packets */ + LPC_EMAC->RxFilterCtrl = RFC_BCAST_EN | RFC_PERFECT_EN; + + /* Reset all interrupts */ + LPC_EMAC->IntClear = 0xFFFF; + + /* Enable EMAC interrupts. */ + LPC_EMAC->IntEnable = INT_RX_DONE | INT_TX_DONE; + + /* Enable receive and transmit mode of MAC Ethernet core */ + LPC_EMAC->Command |= (CR_RX_EN | CR_TX_EN); + LPC_EMAC->MAC1 |= MAC1_REC_EN; + + /* Enable the ENET Interrupt */ + NVIC_EnableIRQ(ENET_IRQn); + + return RT_EOK; +} + +static rt_err_t lpc_emac_open(rt_device_t dev, rt_uint16_t oflag) +{ + return RT_EOK; +} + +static rt_err_t lpc_emac_close(rt_device_t dev) +{ + return RT_EOK; +} + +static rt_size_t lpc_emac_read(rt_device_t dev, rt_off_t pos, void *buffer, rt_size_t size) +{ + rt_set_errno(-RT_ENOSYS); + return 0; +} + +static rt_size_t lpc_emac_write(rt_device_t dev, rt_off_t pos, const void *buffer, rt_size_t size) +{ + rt_set_errno(-RT_ENOSYS); + return 0; +} + +static rt_err_t lpc_emac_control(rt_device_t dev, rt_uint8_t cmd, void *args) +{ + switch (cmd) + { + case NIOCTL_GADDR: + /* get mac address */ + if (args) rt_memcpy(args, lpc_emac_device.dev_addr, 6); + else return -RT_ERROR; + break; + + default : + break; + } + + return RT_EOK; +} + +/* EtherNet Device Interface */ +/* transmit packet. */ +rt_err_t lpc_emac_tx(rt_device_t dev, struct pbuf *p) +{ + rt_uint32_t Index, IndexNext; + rt_uint8_t *ptr; + + /* calculate next index */ + IndexNext = LPC_EMAC->TxProduceIndex + 1; + if (IndexNext > LPC_EMAC->TxDescriptorNumber) IndexNext = 0; + + /* check whether block is full */ + while (IndexNext == LPC_EMAC->TxConsumeIndex) + { + rt_err_t result; + rt_uint32_t recved; + + /* there is no block yet, wait a flag */ + result = rt_event_recv(&tx_event, 0x01, + RT_EVENT_FLAG_AND | RT_EVENT_FLAG_CLEAR, RT_WAITING_FOREVER, &recved); + + RT_ASSERT(result == RT_EOK); + } + + /* lock EMAC device */ + rt_sem_take(&sem_lock, RT_WAITING_FOREVER); + + /* get produce index */ + Index = LPC_EMAC->TxProduceIndex; + + /* calculate next index */ + IndexNext = LPC_EMAC->TxProduceIndex + 1; + if (IndexNext > LPC_EMAC->TxDescriptorNumber) + IndexNext = 0; + + /* copy data to tx buffer */ + ptr = (rt_uint8_t *)TX_BUF(Index); + pbuf_copy_partial(p, ptr, p->tot_len, 0); + + TX_DESC_CTRL(Index) &= ~0x7ff; + TX_DESC_CTRL(Index) |= (p->tot_len - 1) & 0x7ff; + + /* change index to the next */ + LPC_EMAC->TxProduceIndex = IndexNext; + + /* unlock EMAC device */ + rt_sem_release(&sem_lock); + + return RT_EOK; +} + +/* reception packet. */ +struct pbuf *lpc_emac_rx(rt_device_t dev) +{ + struct pbuf *p; + rt_uint32_t size; + rt_uint32_t Index; + + /* init p pointer */ + p = RT_NULL; + + /* lock EMAC device */ + rt_sem_take(&sem_lock, RT_WAITING_FOREVER); + + Index = LPC_EMAC->RxConsumeIndex; + if (Index != LPC_EMAC->RxProduceIndex) + { + size = (RX_STAT_INFO(Index) & 0x7ff) + 1; + if (size > ETH_FRAG_SIZE) size = ETH_FRAG_SIZE; + + /* allocate buffer */ + p = pbuf_alloc(PBUF_LINK, size, PBUF_RAM); + if (p != RT_NULL) + { + pbuf_take(p, (rt_uint8_t *)RX_BUF(Index), size); + } + + /* move Index to the next */ + if (++Index > LPC_EMAC->RxDescriptorNumber) + Index = 0; + + /* set consume index */ + LPC_EMAC->RxConsumeIndex = Index; + } + else + { + /* Enable RxDone interrupt */ + LPC_EMAC->IntEnable = INT_RX_DONE | INT_TX_DONE; + } + + /* unlock EMAC device */ + rt_sem_release(&sem_lock); + + return p; +} + +int lpc_emac_hw_init(void) +{ + rt_event_init(&tx_event, "tx_event", RT_IPC_FLAG_FIFO); + rt_sem_init(&sem_lock, "eth_lock", 1, RT_IPC_FLAG_FIFO); + + /* set autonegotiation mode */ + lpc_emac_device.phy_mode = EMAC_PHY_AUTO; + + // OUI 00-60-37 NXP Semiconductors + lpc_emac_device.dev_addr[0] = 0x00; + lpc_emac_device.dev_addr[1] = 0x60; + lpc_emac_device.dev_addr[2] = 0x37; + /* set mac address: (only for test) */ + lpc_emac_device.dev_addr[3] = 0x12; + lpc_emac_device.dev_addr[4] = 0x34; + lpc_emac_device.dev_addr[5] = 0x56; + + lpc_emac_device.parent.parent.init = lpc_emac_init; + lpc_emac_device.parent.parent.open = lpc_emac_open; + lpc_emac_device.parent.parent.close = lpc_emac_close; + lpc_emac_device.parent.parent.read = lpc_emac_read; + lpc_emac_device.parent.parent.write = lpc_emac_write; + lpc_emac_device.parent.parent.control = lpc_emac_control; + lpc_emac_device.parent.parent.user_data = RT_NULL; + + lpc_emac_device.parent.eth_rx = lpc_emac_rx; + lpc_emac_device.parent.eth_tx = lpc_emac_tx; + + eth_device_init(&(lpc_emac_device.parent), "e0"); + return 0; +} +INIT_DEVICE_EXPORT(lpc_emac_hw_init); + +#ifdef RT_USING_FINSH +#include +void emac_dump() +{ + rt_kprintf("Command : %08x\n", LPC_EMAC->Command); + rt_kprintf("Status : %08x\n", LPC_EMAC->Status); + rt_kprintf("RxStatus : %08x\n", LPC_EMAC->RxStatus); + rt_kprintf("TxStatus : %08x\n", LPC_EMAC->TxStatus); + rt_kprintf("IntEnable: %08x\n", LPC_EMAC->IntEnable); + rt_kprintf("IntStatus: %08x\n", LPC_EMAC->IntStatus); +} +FINSH_FUNCTION_EXPORT(emac_dump, dump emac register); +#endif + diff --git a/bsp/lpc408x/drivers/drv_emac.h b/bsp/lpc408x/drivers/drv_emac.h new file mode 100644 index 0000000000..abadc18520 --- /dev/null +++ b/bsp/lpc408x/drivers/drv_emac.h @@ -0,0 +1,291 @@ +/* + * File : drv_emac.h + * This file is part of RT-Thread RTOS + * COPYRIGHT (C) 2009-2013 RT-Thread Develop Team + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rt-thread.org/license/LICENSE + * + * Change Logs: + * Date Author Notes + * 2013-05-19 Bernard porting from LPC17xx drivers. + */ + +#ifndef __DRV_EMAC_H__ +#define __DRV_EMAC_H__ + +#include "board.h" + +/* EMAC Memory Buffer configuration for 16K Ethernet RAM. */ +#define NUM_RX_FRAG 4 /* Num.of RX Fragments 4*1536= 6.0kB */ +#define NUM_TX_FRAG 3 /* Num.of TX Fragments 3*1536= 4.6kB */ +#define ETH_FRAG_SIZE 1536 /* Packet Fragment size 1536 Bytes */ + +#define ETH_MAX_FLEN 1536 /* Max. Ethernet Frame Size */ + + +/* MAC Configuration Register 1 */ +#define MAC1_REC_EN 0x00000001 /* Receive Enable */ +#define MAC1_PASS_ALL 0x00000002 /* Pass All Receive Frames */ +#define MAC1_RX_FLOWC 0x00000004 /* RX Flow Control */ +#define MAC1_TX_FLOWC 0x00000008 /* TX Flow Control */ +#define MAC1_LOOPB 0x00000010 /* Loop Back Mode */ +#define MAC1_RES_TX 0x00000100 /* Reset TX Logic */ +#define MAC1_RES_MCS_TX 0x00000200 /* Reset MAC TX Control Sublayer */ +#define MAC1_RES_RX 0x00000400 /* Reset RX Logic */ +#define MAC1_RES_MCS_RX 0x00000800 /* Reset MAC RX Control Sublayer */ +#define MAC1_SIM_RES 0x00004000 /* Simulation Reset */ +#define MAC1_SOFT_RES 0x00008000 /* Soft Reset MAC */ + +/* MAC Configuration Register 2 */ +#define MAC2_FULL_DUP 0x00000001 /* Full Duplex Mode */ +#define MAC2_FRM_LEN_CHK 0x00000002 /* Frame Length Checking */ +#define MAC2_HUGE_FRM_EN 0x00000004 /* Huge Frame Enable */ +#define MAC2_DLY_CRC 0x00000008 /* Delayed CRC Mode */ +#define MAC2_CRC_EN 0x00000010 /* Append CRC to every Frame */ +#define MAC2_PAD_EN 0x00000020 /* Pad all Short Frames */ +#define MAC2_VLAN_PAD_EN 0x00000040 /* VLAN Pad Enable */ +#define MAC2_ADET_PAD_EN 0x00000080 /* Auto Detect Pad Enable */ +#define MAC2_PPREAM_ENF 0x00000100 /* Pure Preamble Enforcement */ +#define MAC2_LPREAM_ENF 0x00000200 /* Long Preamble Enforcement */ +#define MAC2_NO_BACKOFF 0x00001000 /* No Backoff Algorithm */ +#define MAC2_BACK_PRESSURE 0x00002000 /* Backoff Presurre / No Backoff */ +#define MAC2_EXCESS_DEF 0x00004000 /* Excess Defer */ + +/* Back-to-Back Inter-Packet-Gap Register */ +#define IPGT_FULL_DUP 0x00000015 /* Recommended value for Full Duplex */ +#define IPGT_HALF_DUP 0x00000012 /* Recommended value for Half Duplex */ + +/* Non Back-to-Back Inter-Packet-Gap Register */ +#define IPGR_DEF 0x00000012 /* Recommended value */ + +/* Collision Window/Retry Register */ +#define CLRT_DEF 0x0000370F /* Default value */ + +/* PHY Support Register */ +#define SUPP_SPEED 0x00000100 /* Reduced MII Logic Current Speed */ +#define SUPP_RES_RMII 0x00000800 /* Reset Reduced MII Logic */ + +/* Test Register */ +#define TEST_SHCUT_PQUANTA 0x00000001 /* Shortcut Pause Quanta */ +#define TEST_TST_PAUSE 0x00000002 /* Test Pause */ +#define TEST_TST_BACKP 0x00000004 /* Test Back Pressure */ + +/* MII Management Configuration Register */ +#define MCFG_SCAN_INC 0x00000001 /* Scan Increment PHY Address */ +#define MCFG_SUPP_PREAM 0x00000002 /* Suppress Preamble */ +#define MCFG_CLK_SEL 0x0000001C /* Clock Select Mask */ +#define MCFG_RES_MII 0x00008000 /* Reset MII Management Hardware */ + +#define MCFG_CLK_DIV4 0x00000000 /* MDC = hclk / 4 */ +#define MCFG_CLK_DIV6 0x00000008 /* MDC = hclk / 6 */ +#define MCFG_CLK_DIV8 0x0000000C /* MDC = hclk / 8 */ +#define MCFG_CLK_DIV10 0x00000010 /* MDC = hclk / 10 */ +#define MCFG_CLK_DIV14 0x00000014 /* MDC = hclk / 14 */ +#define MCFG_CLK_DIV20 0x00000018 /* MDC = hclk / 20 */ +#define MCFG_CLK_DIV28 0x0000001C /* MDC = hclk / 28 */ + + +/* MII Management Command Register */ +#define MCMD_READ 0x00000001 /* MII Read */ +#define MCMD_SCAN 0x00000002 /* MII Scan continuously */ + +#define MII_WR_TOUT 0x00050000 /* MII Write timeout count */ +#define MII_RD_TOUT 0x00050000 /* MII Read timeout count */ + +/* MII Management Address Register */ +#define MADR_REG_ADR 0x0000001F /* MII Register Address Mask */ +#define MADR_PHY_ADR 0x00001F00 /* PHY Address Mask */ + +/* MII Management Indicators Register */ +#define MIND_BUSY 0x00000001 /* MII is Busy */ +#define MIND_SCAN 0x00000002 /* MII Scanning in Progress */ +#define MIND_NOT_VAL 0x00000004 /* MII Read Data not valid */ +#define MIND_MII_LINK_FAIL 0x00000008 /* MII Link Failed */ + +/* Command Register */ +#define CR_RX_EN 0x00000001 /* Enable Receive */ +#define CR_TX_EN 0x00000002 /* Enable Transmit */ +#define CR_REG_RES 0x00000008 /* Reset Host Registers */ +#define CR_TX_RES 0x00000010 /* Reset Transmit Datapath */ +#define CR_RX_RES 0x00000020 /* Reset Receive Datapath */ +#define CR_PASS_RUNT_FRM 0x00000040 /* Pass Runt Frames */ +#define CR_PASS_RX_FILT 0x00000080 /* Pass RX Filter */ +#define CR_TX_FLOW_CTRL 0x00000100 /* TX Flow Control */ +#define CR_RMII 0x00000200 /* Reduced MII Interface */ +#define CR_FULL_DUP 0x00000400 /* Full Duplex */ + +/* Status Register */ +#define SR_RX_EN 0x00000001 /* Enable Receive */ +#define SR_TX_EN 0x00000002 /* Enable Transmit */ + +/* Transmit Status Vector 0 Register */ +#define TSV0_CRC_ERR 0x00000001 /* CRC error */ +#define TSV0_LEN_CHKERR 0x00000002 /* Length Check Error */ +#define TSV0_LEN_OUTRNG 0x00000004 /* Length Out of Range */ +#define TSV0_DONE 0x00000008 /* Tramsmission Completed */ +#define TSV0_MCAST 0x00000010 /* Multicast Destination */ +#define TSV0_BCAST 0x00000020 /* Broadcast Destination */ +#define TSV0_PKT_DEFER 0x00000040 /* Packet Deferred */ +#define TSV0_EXC_DEFER 0x00000080 /* Excessive Packet Deferral */ +#define TSV0_EXC_COLL 0x00000100 /* Excessive Collision */ +#define TSV0_LATE_COLL 0x00000200 /* Late Collision Occured */ +#define TSV0_GIANT 0x00000400 /* Giant Frame */ +#define TSV0_UNDERRUN 0x00000800 /* Buffer Underrun */ +#define TSV0_BYTES 0x0FFFF000 /* Total Bytes Transferred */ +#define TSV0_CTRL_FRAME 0x10000000 /* Control Frame */ +#define TSV0_PAUSE 0x20000000 /* Pause Frame */ +#define TSV0_BACK_PRESS 0x40000000 /* Backpressure Method Applied */ +#define TSV0_VLAN 0x80000000 /* VLAN Frame */ + +/* Transmit Status Vector 1 Register */ +#define TSV1_BYTE_CNT 0x0000FFFF /* Transmit Byte Count */ +#define TSV1_COLL_CNT 0x000F0000 /* Transmit Collision Count */ + +/* Receive Status Vector Register */ +#define RSV_BYTE_CNT 0x0000FFFF /* Receive Byte Count */ +#define RSV_PKT_IGNORED 0x00010000 /* Packet Previously Ignored */ +#define RSV_RXDV_SEEN 0x00020000 /* RXDV Event Previously Seen */ +#define RSV_CARR_SEEN 0x00040000 /* Carrier Event Previously Seen */ +#define RSV_REC_CODEV 0x00080000 /* Receive Code Violation */ +#define RSV_CRC_ERR 0x00100000 /* CRC Error */ +#define RSV_LEN_CHKERR 0x00200000 /* Length Check Error */ +#define RSV_LEN_OUTRNG 0x00400000 /* Length Out of Range */ +#define RSV_REC_OK 0x00800000 /* Frame Received OK */ +#define RSV_MCAST 0x01000000 /* Multicast Frame */ +#define RSV_BCAST 0x02000000 /* Broadcast Frame */ +#define RSV_DRIB_NIBB 0x04000000 /* Dribble Nibble */ +#define RSV_CTRL_FRAME 0x08000000 /* Control Frame */ +#define RSV_PAUSE 0x10000000 /* Pause Frame */ +#define RSV_UNSUPP_OPC 0x20000000 /* Unsupported Opcode */ +#define RSV_VLAN 0x40000000 /* VLAN Frame */ + +/* Flow Control Counter Register */ +#define FCC_MIRR_CNT 0x0000FFFF /* Mirror Counter */ +#define FCC_PAUSE_TIM 0xFFFF0000 /* Pause Timer */ + +/* Flow Control Status Register */ +#define FCS_MIRR_CNT 0x0000FFFF /* Mirror Counter Current */ + +/* Receive Filter Control Register */ +#define RFC_UCAST_EN 0x00000001 /* Accept Unicast Frames Enable */ +#define RFC_BCAST_EN 0x00000002 /* Accept Broadcast Frames Enable */ +#define RFC_MCAST_EN 0x00000004 /* Accept Multicast Frames Enable */ +#define RFC_UCAST_HASH_EN 0x00000008 /* Accept Unicast Hash Filter Frames */ +#define RFC_MCAST_HASH_EN 0x00000010 /* Accept Multicast Hash Filter Fram.*/ +#define RFC_PERFECT_EN 0x00000020 /* Accept Perfect Match Enable */ +#define RFC_MAGP_WOL_EN 0x00001000 /* Magic Packet Filter WoL Enable */ +#define RFC_PFILT_WOL_EN 0x00002000 /* Perfect Filter WoL Enable */ + +/* Receive Filter WoL Status/Clear Registers */ +#define WOL_UCAST 0x00000001 /* Unicast Frame caused WoL */ +#define WOL_BCAST 0x00000002 /* Broadcast Frame caused WoL */ +#define WOL_MCAST 0x00000004 /* Multicast Frame caused WoL */ +#define WOL_UCAST_HASH 0x00000008 /* Unicast Hash Filter Frame WoL */ +#define WOL_MCAST_HASH 0x00000010 /* Multicast Hash Filter Frame WoL */ +#define WOL_PERFECT 0x00000020 /* Perfect Filter WoL */ +#define WOL_RX_FILTER 0x00000080 /* RX Filter caused WoL */ +#define WOL_MAG_PACKET 0x00000100 /* Magic Packet Filter caused WoL */ + +/* Interrupt Status/Enable/Clear/Set Registers */ +#define INT_RX_OVERRUN 0x00000001 /* Overrun Error in RX Queue */ +#define INT_RX_ERR 0x00000002 /* Receive Error */ +#define INT_RX_FIN 0x00000004 /* RX Finished Process Descriptors */ +#define INT_RX_DONE 0x00000008 /* Receive Done */ +#define INT_TX_UNDERRUN 0x00000010 /* Transmit Underrun */ +#define INT_TX_ERR 0x00000020 /* Transmit Error */ +#define INT_TX_FIN 0x00000040 /* TX Finished Process Descriptors */ +#define INT_TX_DONE 0x00000080 /* Transmit Done */ +#define INT_SOFT_INT 0x00001000 /* Software Triggered Interrupt */ +#define INT_WAKEUP 0x00002000 /* Wakeup Event Interrupt */ + +/* Power Down Register */ +#define PD_POWER_DOWN 0x80000000 /* Power Down MAC */ + +/* RX Descriptor Control Word */ +#define RCTRL_SIZE 0x000007FF /* Buffer size mask */ +#define RCTRL_INT 0x80000000 /* Generate RxDone Interrupt */ + +/* RX Status Hash CRC Word */ +#define RHASH_SA 0x000001FF /* Hash CRC for Source Address */ +#define RHASH_DA 0x001FF000 /* Hash CRC for Destination Address */ + +/* RX Status Information Word */ +#define RINFO_SIZE 0x000007FF /* Data size in bytes */ +#define RINFO_CTRL_FRAME 0x00040000 /* Control Frame */ +#define RINFO_VLAN 0x00080000 /* VLAN Frame */ +#define RINFO_FAIL_FILT 0x00100000 /* RX Filter Failed */ +#define RINFO_MCAST 0x00200000 /* Multicast Frame */ +#define RINFO_BCAST 0x00400000 /* Broadcast Frame */ +#define RINFO_CRC_ERR 0x00800000 /* CRC Error in Frame */ +#define RINFO_SYM_ERR 0x01000000 /* Symbol Error from PHY */ +#define RINFO_LEN_ERR 0x02000000 /* Length Error */ +#define RINFO_RANGE_ERR 0x04000000 /* Range Error (exceeded max. size) */ +#define RINFO_ALIGN_ERR 0x08000000 /* Alignment Error */ +#define RINFO_OVERRUN 0x10000000 /* Receive overrun */ +#define RINFO_NO_DESCR 0x20000000 /* No new Descriptor available */ +#define RINFO_LAST_FLAG 0x40000000 /* Last Fragment in Frame */ +#define RINFO_ERR 0x80000000 /* Error Occured (OR of all errors) */ + +#define RINFO_ERR_MASK (RINFO_FAIL_FILT | RINFO_CRC_ERR | RINFO_SYM_ERR | \ + RINFO_LEN_ERR | RINFO_ALIGN_ERR | RINFO_OVERRUN) + +/* TX Descriptor Control Word */ +#define TCTRL_SIZE 0x000007FF /* Size of data buffer in bytes */ +#define TCTRL_OVERRIDE 0x04000000 /* Override Default MAC Registers */ +#define TCTRL_HUGE 0x08000000 /* Enable Huge Frame */ +#define TCTRL_PAD 0x10000000 /* Pad short Frames to 64 bytes */ +#define TCTRL_CRC 0x20000000 /* Append a hardware CRC to Frame */ +#define TCTRL_LAST 0x40000000 /* Last Descriptor for TX Frame */ +#define TCTRL_INT 0x80000000 /* Generate TxDone Interrupt */ + +/* TX Status Information Word */ +#define TINFO_COL_CNT 0x01E00000 /* Collision Count */ +#define TINFO_DEFER 0x02000000 /* Packet Deferred (not an error) */ +#define TINFO_EXCESS_DEF 0x04000000 /* Excessive Deferral */ +#define TINFO_EXCESS_COL 0x08000000 /* Excessive Collision */ +#define TINFO_LATE_COL 0x10000000 /* Late Collision Occured */ +#define TINFO_UNDERRUN 0x20000000 /* Transmit Underrun */ +#define TINFO_NO_DESCR 0x40000000 /* No new Descriptor available */ +#define TINFO_ERR 0x80000000 /* Error Occured (OR of all errors) */ + +/* ENET Device Revision ID */ +#define OLD_EMAC_MODULE_ID 0x39022000 /* Rev. ID for first rev '-' */ + +/* DP83848C PHY Registers */ +#define PHY_REG_BMCR 0x00 /* Basic Mode Control Register */ +#define PHY_REG_BMSR 0x01 /* Basic Mode Status Register */ +#define PHY_REG_IDR1 0x02 /* PHY Identifier 1 */ +#define PHY_REG_IDR2 0x03 /* PHY Identifier 2 */ +#define PHY_REG_ANAR 0x04 /* Auto-Negotiation Advertisement */ +#define PHY_REG_ANLPAR 0x05 /* Auto-Neg. Link Partner Abitily */ +#define PHY_REG_ANER 0x06 /* Auto-Neg. Expansion Register */ +#define PHY_REG_ANNPTR 0x07 /* Auto-Neg. Next Page TX */ + +/* PHY Extended Registers */ +#define PHY_REG_STS 0x10 /* Status Register */ +#define PHY_REG_MICR 0x11 /* MII Interrupt Control Register */ +#define PHY_REG_MISR 0x12 /* MII Interrupt Status Register */ +#define PHY_REG_FCSCR 0x14 /* False Carrier Sense Counter */ +#define PHY_REG_RECR 0x15 /* Receive Error Counter */ +#define PHY_REG_PCSR 0x16 /* PCS Sublayer Config. and Status */ +#define PHY_REG_RBR 0x17 /* RMII and Bypass Register */ +#define PHY_REG_LEDCR 0x18 /* LED Direct Control Register */ +#define PHY_REG_PHYCR 0x19 /* PHY Control Register */ +#define PHY_REG_10BTSCR 0x1A /* 10Base-T Status/Control Register */ +#define PHY_REG_CDCTRL1 0x1B /* CD Test Control and BIST Extens. */ +#define PHY_REG_EDCR 0x1D /* Energy Detect Control Register */ + +#define PHY_FULLD_100M 0x2100 /* Full Duplex 100Mbit */ +#define PHY_HALFD_100M 0x2000 /* Half Duplex 100Mbit */ +#define PHY_FULLD_10M 0x0100 /* Full Duplex 10Mbit */ +#define PHY_HALFD_10M 0x0000 /* Half Duplex 10MBit */ +#define PHY_AUTO_NEG 0x3000 /* Select Auto Negotiation */ + +#define DP83848C_DEF_ADR 0x0F00 /* Default PHY device address */ +#define DP83848C_ID 0x20005C90 /* PHY Identifier */ + +int lpc_emac_hw_init(void); + +#endif diff --git a/bsp/lpc408x/drivers/drv_led.c b/bsp/lpc408x/drivers/drv_led.c index f9cc5e602f..e00f3a2fb1 100644 --- a/bsp/lpc408x/drivers/drv_led.c +++ b/bsp/lpc408x/drivers/drv_led.c @@ -1,7 +1,7 @@ #include #include "board.h" -#define RT_DEVICE_CTRL_RTC_GET_COUNT 0x81 /**< get count */ +#define LED_DEVICE_CTRL 0x81 /*LED control command*/ #define LED_NUM 4 struct led_ctrl @@ -22,24 +22,24 @@ static struct lpc_led led; static rt_err_t rt_led_init(rt_device_t dev) { - /* led0 : P4.14,led1:P4.15 ,led2:P4.16 ,led3:P4.17*/ + /* led0 : P4.27,led1:P4.15 ,led2:P4.16 ,led3:P4.17*/ /* set P4.14,P4.15,P4.16,P4.17 as GPIO. */ - LPC_IOCON->P4_14 = 0x00; + LPC_IOCON->P4_27 = 0x00; LPC_IOCON->P4_15 = 0x00; LPC_IOCON->P4_16 = 0x00; LPC_IOCON->P4_17 = 0x00; - /* set P4.14,P4.15,P4.16,P4.17 output. */ - LPC_GPIO4->DIR |= (0x0f << 14); + /* set P4.27,P4.15,P4.16,P4.17 output. */ + LPC_GPIO4->DIR |= (0x07 << 15) | (0x01 << 27); /* turn off all the led */ - LPC_GPIO4->SET = (0x0f << 14); - led.ctrl[0].num = 14; - led.ctrl[0].port = LPC_GPIO4; - led.ctrl[1].num = 15; - led.ctrl[1].port = LPC_GPIO4; - led.ctrl[2].num = 16; - led.ctrl[2].port = LPC_GPIO4; - led.ctrl[3].num = 17; + LPC_GPIO4->SET = (0x07 << 15) | (0x01 << 27); + led.ctrl[3].num = 27; led.ctrl[3].port = LPC_GPIO4; + led.ctrl[2].num = 15; + led.ctrl[2].port = LPC_GPIO4; + led.ctrl[1].num = 16; + led.ctrl[1].port = LPC_GPIO4; + led.ctrl[0].num = 17; + led.ctrl[0].port = LPC_GPIO4; return RT_EOK; } @@ -106,7 +106,7 @@ static rt_err_t rt_led_control(rt_device_t dev, rt_uint8_t cmd, void *args) { RT_ASSERT(dev == &led.parent); - if (cmd == RT_DEVICE_CTRL_RTC_GET_COUNT) + if (cmd == LED_DEVICE_CTRL) { rt_uint32_t *led_num = args; *led_num = LED_NUM; @@ -114,7 +114,7 @@ static rt_err_t rt_led_control(rt_device_t dev, rt_uint8_t cmd, void *args) return RT_EOK; } -void rt_led_hw_init(void) +int rt_led_hw_init(void) { led.parent.type = RT_Device_Class_Char; led.parent.rx_indicate = RT_NULL; @@ -131,8 +131,9 @@ void rt_led_hw_init(void) rt_device_register(&led.parent, "led", RT_DEVICE_FLAG_RDWR); /* init led device */ rt_led_init(&led.parent); + return 0; } - +INIT_DEVICE_EXPORT(rt_led_hw_init); #ifdef RT_USING_FINSH #include void led_test(rt_uint32_t led_num, rt_uint32_t value) diff --git a/bsp/lpc408x/drivers/drv_sdram.c b/bsp/lpc408x/drivers/drv_sdram.c new file mode 100644 index 0000000000..b648ed079c --- /dev/null +++ b/bsp/lpc408x/drivers/drv_sdram.c @@ -0,0 +1,153 @@ +/* + * File : drv_sdram.c + * This file is part of RT-Thread RTOS + * COPYRIGHT (C) 2009-2013 RT-Thread Develop Team + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rt-thread.org/license/LICENSE + * + * Change Logs: + * Date Author Notes + * 2013-05-19 Bernard The first version for LPC40xx + */ + +#include "drv_sdram.h" + +#include +#include + +#define SDRAM_BASE_ADDR 0xA0000000 +#define SDRAM_SIZE 0x2000000 + +/******************************************************************************************* +* @函数名:sdram_gpio_config() +* @参数 :void +* @返回值:void +* @描述 :SDRAM管脚配置函数,内部调用 +*********************************************************************************************/ +static void sdram_gpio_config(void) +{ + LPC_IOCON->P3_0 = (1 << 0 | 0 << 3 | 0 << 5 | 1 << 9); /* D0 @ P3.0 */ + LPC_IOCON->P3_1 = (1 << 0 | 0 << 3 | 0 << 5 | 1 << 9); /* D1 @ P3.1 */ + LPC_IOCON->P3_2 = (1 << 0 | 0 << 3 | 0 << 5 | 1 << 9); /* D2 @ P3.2 */ + LPC_IOCON->P3_3 = (1 << 0 | 0 << 3 | 0 << 5 | 1 << 9); /* D3 @ P3.3 */ + + LPC_IOCON->P3_4 = (1 << 0 | 0 << 3 | 0 << 5 | 1 << 9); /* D4 @ P3.4 */ + LPC_IOCON->P3_5 = (1 << 0 | 0 << 3 | 0 << 5 | 1 << 9); /* D5 @ P3.5 */ + LPC_IOCON->P3_6 = (1 << 0 | 0 << 3 | 0 << 5 | 1 << 9); /* D6 @ P3.6 */ + LPC_IOCON->P3_7 = (1 << 0 | 0 << 3 | 0 << 5 | 1 << 9); /* D7 @ P3.7 */ + + LPC_IOCON->P3_8 = (1 << 0 | 0 << 3 | 0 << 5 | 1 << 9); /* D8 @ P3.8 */ + LPC_IOCON->P3_9 = (1 << 0 | 0 << 3 | 0 << 5 | 1 << 9); /* D9 @ P3.9 */ + LPC_IOCON->P3_10 = (1 << 0 | 0 << 3 | 0 << 5 | 1 << 9); /* D10 @ P3.10 */ + LPC_IOCON->P3_11 = (1 << 0 | 0 << 3 | 0 << 5 | 1 << 9); /* D11 @ P3.11 */ + + LPC_IOCON->P3_12 = (1 << 0 | 0 << 3 | 0 << 5 | 1 << 9); /* D12 @ P3.12 */ + LPC_IOCON->P3_13 = (1 << 0 | 0 << 3 | 0 << 5 | 1 << 9); /* D13 @ P3.13 */ + LPC_IOCON->P3_14 = (1 << 0 | 0 << 3 | 0 << 5 | 1 << 9); /* D14 @ P3.14 */ + LPC_IOCON->P3_15 = (1 << 0 | 0 << 3 | 0 << 5 | 1 << 9); /* D15 @ P3.15 */ + + + LPC_IOCON->P4_0 = (1 << 0 | 0 << 3 | 0 << 5 | 1 << 9); /* A0 @ P4.0 */ + LPC_IOCON->P4_1 = (1 << 0 | 0 << 3 | 0 << 5 | 1 << 9); /* A1 @ P4.1 */ + LPC_IOCON->P4_2 = (1 << 0 | 0 << 3 | 0 << 5 | 1 << 9); /* A2 @ P4.2 */ + LPC_IOCON->P4_3 = (1 << 0 | 0 << 3 | 0 << 5 | 1 << 9); /* A3 @ P4.3 */ + + LPC_IOCON->P4_4 = (1 << 0 | 0 << 3 | 0 << 5 | 1 << 9); /* A4 @ P4.4 */ + LPC_IOCON->P4_5 = (1 << 0 | 0 << 3 | 0 << 5 | 1 << 9); /* A5 @ P4.5 */ + LPC_IOCON->P4_6 = (1 << 0 | 0 << 3 | 0 << 5 | 1 << 9); /* A6 @ P4.6 */ + LPC_IOCON->P4_7 = (1 << 0 | 0 << 3 | 0 << 5 | 1 << 9); /* A7 @ P4.7 */ + + LPC_IOCON->P4_8 = (1 << 0 | 0 << 3 | 0 << 5 | 1 << 9); /* A8 @ P4.8 */ + LPC_IOCON->P4_9 = (1 << 0 | 0 << 3 | 0 << 5 | 1 << 9); /* A9 @ P4.9 */ + LPC_IOCON->P4_10 = (1 << 0 | 0 << 3 | 0 << 5 | 1 << 9); /* A10 @ P4.10 */ + LPC_IOCON->P4_11 = (1 << 0 | 0 << 3 | 0 << 5 | 1 << 9); /* A11 @ P4.11 */ + + LPC_IOCON->P4_12 = (1 << 0 | 0 << 3 | 0 << 5 | 1 << 9); /* A12 @ P4.12 */ + LPC_IOCON->P4_13 = (1 << 0 | 0 << 3 | 0 << 5 | 1 << 9); /* A13 @ P4.13 */ + LPC_IOCON->P4_14 = (1 << 0 | 0 << 3 | 0 << 5 | 1 << 9); /* A14 @ P4.14 */ + + LPC_IOCON->P4_25 = (1 << 0 | 0 << 3 | 0 << 5 | 1 << 9); /* WEN @ P4.25 */ + + LPC_IOCON->P2_16 = (1 << 0 | 0 << 3 | 0 << 5 | 1 << 9); /* CASN @ P2.16 */ + LPC_IOCON->P2_17 = (1 << 0 | 0 << 3 | 0 << 5 | 1 << 9); /* RASN @ P2.17 */ + LPC_IOCON->P2_18 = (1 << 0 | 0 << 3 | 0 << 5 | 1 << 9); /* CLK[0] @ P2.18 */ + LPC_IOCON->P2_19 = (1 << 0 | 0 << 3 | 0 << 5 | 1 << 9); /* CLK[1] @ P2.19 */ + + LPC_IOCON->P2_20 = (1 << 0 | 0 << 3 | 0 << 5 | 1 << 9); /* DYCSN[0] @ P2.20 */ + LPC_IOCON->P2_24 = (1 << 0 | 0 << 3 | 0 << 5 | 1 << 9); /* CKE[0] @ P2.24 */ + + LPC_IOCON->P2_28 = (1 << 0 | 0 << 3 | 0 << 5 | 1 << 9); /* DQM[0] @ P2.28 */ + LPC_IOCON->P2_29 = (1 << 0 | 0 << 3 | 0 << 5 | 1 << 9); /* DQM[1] @ P2.29 */ +} + +void lpc_sdram_hw_init(void) +{ + volatile uint32_t i; + volatile uint32_t dwtemp; + uint16_t wtemp = wtemp; + TIM_TIMERCFG_Type TIM_ConfigStruct; + + TIM_ConfigStruct.PrescaleOption = TIM_PRESCALE_USVAL; + TIM_ConfigStruct.PrescaleValue = 1; + + // Set configuration for Tim_config and Tim_MatchConfig + TIM_Init(LPC_TIM0, TIM_TIMER_MODE, &TIM_ConfigStruct); + + LPC_SC->PCONP |= 0x00000800; + LPC_SC->EMCDLYCTL = 0x00001010; + LPC_EMC->Control = 0x00000001; + LPC_EMC->Config = 0x00000000; + + sdram_gpio_config(); + //LPC_SC->EMCCLKSEL = 1; //跑主频的一般频率,60Mhz + LPC_EMC->DynamicRP = EMC_NS2CLK(20); /* 20ns, */ + LPC_EMC->DynamicRAS = /*EMC_NS2CLK(42, nsPerClk);*/ 15; /* 42ns to 100K ns, */ + LPC_EMC->DynamicSREX = 1 - 1; /* tSRE, 1clk, */ + LPC_EMC->DynamicAPR = 2 - 1; /* Not found!!! Estimated as 2clk, */ + LPC_EMC->DynamicDAL = EMC_NS2CLK(20) + 2; /* tDAL = tRP + tDPL = 20ns + 2clk */ + LPC_EMC->DynamicWR = 2 - 1; /* 2CLK, */ + LPC_EMC->DynamicRC = EMC_NS2CLK(63); /* H57V2562GTR-75C tRC=63ns(min)*/ + LPC_EMC->DynamicRFC = EMC_NS2CLK(63); /* H57V2562GTR-75C tRFC=tRC */ + LPC_EMC->DynamicXSR = 0x0000000F; /* exit self-refresh to active, 不知道,设为最久 */ + LPC_EMC->DynamicRRD = EMC_NS2CLK(63); /* 3clk, tRRD=15ns(min) */ + LPC_EMC->DynamicMRD = 2 - 1; /* 2clk, tMRD=2clk(min) */ + + LPC_EMC->DynamicReadConfig = 0x00000001; /* Command delayed strategy, using EMCCLKDELAY */ + /* H57V2562GTR-75C: tCL=3CLK, tRCD=20ns(min), 3 CLK=24ns */ + LPC_EMC->DynamicRasCas0 = 0x303; + + /* For Manley lpc1778 SDRAM: H57V2562GTR-75C, 256Mb, 16Mx16, 4 banks, row=13, column=9 */ +#ifdef SDRAM_CONFIG_16BIT + LPC_EMC->DynamicConfig0 = 0x680; /* 256Mb, 16Mx16, 4 banks, row=13, column=9, RBC */ +#elif defined SDRAM_CONFIG_32BIT + LPC_EMC->DynamicConfig0 = 0x4680; /* 256Mb, 16Mx16, 4 banks, row=13, column=9, RBC */ +#endif + TIM_Waitms(100); + + LPC_EMC->DynamicControl = 0x00000183; /* Issue NOP command */ + TIM_Waitms(200); /* wait 200ms */ + + LPC_EMC->DynamicControl = 0x00000103; /* Issue PALL command */ + + LPC_EMC->DynamicRefresh = 0x00000002; /* ( n * 16 ) -> 32 clock cycles */ + for (i = 0; i < 0x80; i++); /* wait 128 AHB clock cycles */ + + LPC_EMC->DynamicRefresh = EMC_SDRAM_REFRESH(64); + + LPC_EMC->DynamicControl = 0x00000083; /* Issue MODE command */ + +#ifdef SDRAM_CONFIG_16BIT + wtemp = *((volatile uint16_t *)(SDRAM_BASE | (0x33 << 12))); /* 8 burst, 3 CAS latency */ +#elif defined SDRAM_CONFIG_32BIT + dwtemp = *((volatile uint32_t *)(SDRAM_BASE | (0x32 << 13))); /* 4 burst, 3 CAS latency */ +#endif + + LPC_EMC->DynamicControl = 0x00000000; /* Issue NORMAL command */ + + LPC_EMC->DynamicConfig0 |= 0x80000; /* enable buffer */ + TIM_Waitms(1); + + TIM_DeInit(LPC_TIM0); +} diff --git a/bsp/lpc408x/drivers/drv_sdram.h b/bsp/lpc408x/drivers/drv_sdram.h new file mode 100644 index 0000000000..a689f1ed98 --- /dev/null +++ b/bsp/lpc408x/drivers/drv_sdram.h @@ -0,0 +1,35 @@ +/* + * File : drv_sdram.h + * This file is part of RT-Thread RTOS + * COPYRIGHT (C) 2009-2013 RT-Thread Develop Team + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rt-thread.org/license/LICENSE + * + * Change Logs: + * Date Author Notes + * 2013-05-19 Bernard The first version for LPC40xx + */ + +#ifndef __DRV_SDRAM_H__ +#define __DRV_SDRAM_H__ + +#include + +#define SDRAM_CONFIG_16BIT //use the 16 bitSDRAM +//#define SDRAM_CONFIG_32BIT //use the 32 bitSDRAM + +#ifdef SDRAM_CONFIG_16BIT +#define SDRAM_SIZE 0x2000000 // 256Mbit +#elif defined SDRAM_CONFIG_32BIT // +#define SDRAM_SIZE 0x4000000 // 512Mbit +#else +error Wrong SDRAM config, check ex_sdram.h +#endif + +#define SDRAM_BASE 0xA0000000 /* CS0 */ + +void lpc_sdram_hw_init(void); + +#endif diff --git a/bsp/lpc408x/drivers/drv_uart.c b/bsp/lpc408x/drivers/drv_uart.c index 0b3756a5b9..ef50f3a4d8 100644 --- a/bsp/lpc408x/drivers/drv_uart.c +++ b/bsp/lpc408x/drivers/drv_uart.c @@ -17,20 +17,17 @@ #include #include "board.h" -#include "lpc_uart.h" -#include "lpc_pinsel.h" struct lpc_uart { - UART_ID_Type UART; + LPC_UART_TypeDef *UART; IRQn_Type UART_IRQn; }; static rt_err_t lpc_configure(struct rt_serial_device *serial, struct serial_configure *cfg) { struct lpc_uart *uart; - UART_CFG_Type UARTConfigStruct; - UART_FIFO_CFG_Type UARTFIFOConfigStruct; + uint32_t Fdiv = 0; RT_ASSERT(serial != RT_NULL); uart = (struct lpc_uart *)serial->parent.user_data; @@ -41,25 +38,20 @@ static rt_err_t lpc_configure(struct rt_serial_device *serial, struct serial_con * 1 Stop bit * None parity */ - UART_ConfigStructInit(&UARTConfigStruct); - UARTConfigStruct.Baud_rate = 115200; + /* set DLAB=1 */ + uart->UART->LCR |= 0x80; + /* config uart baudrate */ + Fdiv = (PeripheralClock / 16) / cfg->baud_rate; + uart->UART->DLM = Fdiv / 256; + uart->UART->DLL = Fdiv % 256; + /* set DLAB=0 */ + uart->UART->LCR &= ~0x80; + /* config to 8 data bit,1 Stop bit,None parity */ + uart->UART->LCR |= 0x03; - // Initialize UART0 peripheral with given to corresponding parameter - UART_Init(uart->UART, &UARTConfigStruct); + /*enable and reset FIFO*/ + uart->UART->FCR = 0x07; - /* Initialize FIFOConfigStruct to default state: - * - FIFO_DMAMode = DISABLE - * - FIFO_Level = UART_FIFO_TRGLEV0 - * - FIFO_ResetRxBuf = ENABLE - * - FIFO_ResetTxBuf = ENABLE - * - FIFO_State = ENABLE - */ - UART_FIFOConfigStructInit(&UARTFIFOConfigStruct); - - // Initialize FIFO for UART0 peripheral - UART_FIFOConfig(uart->UART, &UARTFIFOConfigStruct); - - UART_TxCmd(uart->UART, ENABLE); return RT_EOK; } @@ -75,11 +67,11 @@ static rt_err_t lpc_control(struct rt_serial_device *serial, int cmd, void *arg) { case RT_DEVICE_CTRL_CLR_INT: /* disable rx irq */ - UART_IntConfig(uart->UART, UART_INTCFG_RBR, DISABLE); + uart->UART->IER &= ~0x01; break; case RT_DEVICE_CTRL_SET_INT: /* enable rx irq */ - UART_IntConfig(uart->UART, UART_INTCFG_RBR, ENABLE); + uart->UART->IER |= 0x01; break; } @@ -91,21 +83,21 @@ static int lpc_putc(struct rt_serial_device *serial, char c) struct lpc_uart *uart; uart = (struct lpc_uart *)serial->parent.user_data; - UART_Send(uart->UART, (uint8_t *)&c, 1, BLOCKING); + while (!(uart->UART->LSR & 0x20)); + uart->UART->THR = c; return 1; } static int lpc_getc(struct rt_serial_device *serial) { - uint8_t ch; struct lpc_uart *uart; uart = (struct lpc_uart *)serial->parent.user_data; - if (UART_Receive(uart->UART, &ch, 1, NONE_BLOCKING) == 1) - return (int) ch; - - return -1; + if (uart->UART->LSR & 0x01) + return (uart->UART->RBR); + else + return -1; } static const struct rt_uart_ops lpc_uart_ops = @@ -116,127 +108,167 @@ static const struct rt_uart_ops lpc_uart_ops = lpc_getc, }; -#if defined(RT_USING_UART0) +#ifdef RT_USING_UART0 /* UART0 device driver structure */ +#if RTTHREAD_VERSION < 20000 /* RT-Thread 1.x */ +struct serial_ringbuffer uart0_int_rx; +#endif + struct lpc_uart uart0 = { - UART_0, + LPC_UART0, UART0_IRQn, }; struct rt_serial_device serial0; void UART0_IRQHandler(void) { - struct lpc_uart *uart; - uint32_t intsrc, tmp, tmp1; - - uart = &uart0; + volatile uint32_t IIR, tmp; /* enter interrupt */ rt_interrupt_enter(); - /* Determine the interrupt source */ - intsrc = UART_GetIntId(uart->UART); - tmp = intsrc & UART_IIR_INTID_MASK; - - // Receive Line Status - if (tmp == UART_IIR_INTID_RLS) + IIR = LPC_UART0->IIR; + IIR &= 0x0e; + switch (IIR) { - // Check line status - tmp1 = UART_GetLineStatus(uart->UART); - // Mask out the Receive Ready and Transmit Holding empty status - tmp1 &= (UART_LSR_OE | UART_LSR_PE | UART_LSR_FE \ - | UART_LSR_BI | UART_LSR_RXFE); - // If any error exist - if (tmp1) - { - // - } - } - // Receive Data Available or Character time-out - if ((tmp == UART_IIR_INTID_RDA) || (tmp == UART_IIR_INTID_CTI)) - { + case 0x04: + case 0x0C: + #if RTTHREAD_VERSION < 20000 + rt_hw_serial_isr(&serial0); + #else rt_hw_serial_isr(&serial0, RT_SERIAL_EVENT_RX_IND); + #endif + break; + case 0x06: + tmp = LPC_UART0->LSR; + break; + default : + tmp = LPC_UART0->LSR; + break; } - /* leave interrupt */ rt_interrupt_leave(); } #endif -#if defined(RT_USING_UART2) +#ifdef RT_USING_UART2 /* UART2 device driver structure */ +#if RTTHREAD_VERSION < 20000 /* RT-Thread 1.x */ +struct serial_ringbuffer uart2_int_rx; +#endif + struct lpc_uart uart2 = { - UART_2, + LPC_UART2, UART2_IRQn, }; struct rt_serial_device serial2; void UART2_IRQHandler(void) { - struct lpc_uart *uart; - uint32_t intsrc, tmp, tmp1; - - uart = &uart2; + volatile uint32_t IIR, tmp; /* enter interrupt */ rt_interrupt_enter(); - /* Determine the interrupt source */ - intsrc = UART_GetIntId(uart->UART); - tmp = intsrc & UART_IIR_INTID_MASK; - - // Receive Line Status - if (tmp == UART_IIR_INTID_RLS) - { - // Check line status - tmp1 = UART_GetLineStatus(uart->UART); - // Mask out the Receive Ready and Transmit Holding empty status - tmp1 &= (UART_LSR_OE | UART_LSR_PE | UART_LSR_FE \ - | UART_LSR_BI | UART_LSR_RXFE); - // If any error exist - if (tmp1) - { - // - } - } - - // Receive Data Available or Character time-out - if ((tmp == UART_IIR_INTID_RDA) || (tmp == UART_IIR_INTID_CTI)) + IIR = LPC_UART2->IIR; + IIR &= 0x0e; + switch (IIR) { + case 0x04: + case 0x0C: + #if RTTHREAD_VERSION < 20000 + rt_hw_serial_isr(&serial2); + #else rt_hw_serial_isr(&serial2, RT_SERIAL_EVENT_RX_IND); + #endif + break; + case 0x06: + tmp = LPC_UART2->LSR; + break; + default : + tmp = LPC_UART2->LSR; + break; } /* leave interrupt */ rt_interrupt_leave(); } #endif + +#ifdef RT_USING_UART4 +/* UART4 device driver structure */ +#if RTTHREAD_VERSION < 20000 /* RT-Thread 1.x */ +struct serial_ringbuffer uart4_int_rx; +#endif + +struct lpc_uart uart4 = +{ + LPC_UART4, + UART4_IRQn, +}; +struct rt_serial_device serial4; + +void UART4_IRQHandler(void) +{ + volatile uint32_t IIR, tmp; + + /* enter interrupt */ + rt_interrupt_enter(); + + IIR = LPC_UART4->IIR; + IIR &= 0x0e; + switch (IIR) + { + case 0x04: + case 0x0C: + #if RTTHREAD_VERSION < 20000 + rt_hw_serial_isr(&serial4); + #else + rt_hw_serial_isr(&serial4, RT_SERIAL_EVENT_RX_IND); + #endif + break; + case 0x06: + tmp = LPC_UART4->LSR; + break; + default : + tmp = LPC_UART4->LSR; + break; + } + + /* leave interrupt */ + rt_interrupt_leave(); +} +#endif + void rt_hw_uart_init(void) { struct lpc_uart *uart; - struct serial_configure config; + struct serial_configure config = RT_SERIAL_CONFIG_DEFAULT; #ifdef RT_USING_UART0 uart = &uart0; - config.baud_rate = BAUD_RATE_115200; - config.bit_order = BIT_ORDER_LSB; - config.data_bits = DATA_BITS_8; - config.parity = PARITY_NONE; - config.stop_bits = STOP_BITS_1; - config.invert = NRZ_NORMAL; - config.bufsz = RT_SERIAL_RB_BUFSZ; serial0.ops = &lpc_uart_ops; serial0.config = config; - + #if RTTHREAD_VERSION < 20000 + serial0.int_rx = &uart0_int_rx; + #endif + serial0.parent.user_data = uart; + /* * Initialize UART0 pin connect * P0.2: U0_TXD * P0.3: U0_RXD */ - PINSEL_ConfigPin(0, 2, 1); - PINSEL_ConfigPin(0, 3, 1); + LPC_IOCON->P0_2 &= ~0x07; + LPC_IOCON->P0_2 |= 0x01; + LPC_IOCON->P0_3 &= ~0x07; + LPC_IOCON->P0_3 |= 0x01; + + /* enable the uart0 power and clock */ + LPC_SC->PCONP |= 0x01 << 3; /* preemption = 1, sub-priority = 1 */ NVIC_SetPriority(uart->UART_IRQn, ((0x01 << 3) | 0x01)); @@ -244,41 +276,77 @@ void rt_hw_uart_init(void) /* Enable Interrupt for UART channel */ NVIC_EnableIRQ(uart->UART_IRQn); - /* register UART1 device */ + /* register UART0 device */ rt_hw_serial_register(&serial0, "uart0", RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX | RT_DEVICE_FLAG_STREAM, uart); #endif + #ifdef RT_USING_UART2 uart = &uart2; - config.baud_rate = BAUD_RATE_115200; - config.bit_order = BIT_ORDER_LSB; - config.data_bits = DATA_BITS_8; - config.parity = PARITY_NONE; - config.stop_bits = STOP_BITS_1; - config.invert = NRZ_NORMAL; - config.bufsz = RT_SERIAL_RB_BUFSZ; serial2.ops = &lpc_uart_ops; serial2.config = config; + #if RTTHREAD_VERSION < 20000 + serial2.int_rx = &uart2_int_rx; + #endif + serial2.parent.user_data = uart; /* * Initialize UART2 pin connect * P2.8: U2_TXD * P0.11: U2_RXD */ - PINSEL_ConfigPin(2, 8, 2); - PINSEL_ConfigPin(0, 11, 1); + LPC_IOCON->P2_8 &= ~0x07; + LPC_IOCON->P0_11 &= ~0x07; + LPC_IOCON->P2_8 |= 0x02; + LPC_IOCON->P0_11 |= 0x01; + /* enable the uart2 power and clock */ + LPC_SC->PCONP |= 0x01 << 24; /* preemption = 1, sub-priority = 1 */ NVIC_SetPriority(uart->UART_IRQn, ((0x01 << 3) | 0x01)); /* Enable Interrupt for UART channel */ NVIC_EnableIRQ(uart->UART_IRQn); - /* register UART1 device */ + /* register UART2 device */ rt_hw_serial_register(&serial2, "uart2", RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX | RT_DEVICE_FLAG_STREAM, uart); #endif + +#ifdef RT_USING_UART4 + uart = &uart4; + + serial4.ops = &lpc_uart_ops; + serial4.config = config; + #if RTTHREAD_VERSION < 20000 + serial4.int_rx = &uart4_int_rx; + #endif + serial4.parent.user_data = uart; + + /* + * Initialize UART2 pin connect + * P5.4: U2_TXD + * P5.3: U2_RXD + */ + LPC_IOCON->P5_4 &= ~0x07; + LPC_IOCON->P5_3 &= ~0x07; + LPC_IOCON->P5_4 |= 0x04; + LPC_IOCON->P5_3 |= 0x04; + + /* enable the uart4 power and clock */ + LPC_SC->PCONP |= 0x01 << 8; + /* preemption = 1, sub-priority = 1 */ + NVIC_SetPriority(uart->UART_IRQn, ((0x01 << 3) | 0x01)); + + /* Enable Interrupt for UART channel */ + NVIC_EnableIRQ(uart->UART_IRQn); + + /* register UART2 device */ + rt_hw_serial_register(&serial4, "uart4", + RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_INT_RX | RT_DEVICE_FLAG_STREAM, + uart); +#endif } diff --git a/bsp/lpc408x/drivers/drv_uart.h b/bsp/lpc408x/drivers/drv_uart.h index c5ca6c70c4..d93995b96e 100644 --- a/bsp/lpc408x/drivers/drv_uart.h +++ b/bsp/lpc408x/drivers/drv_uart.h @@ -1,3 +1,17 @@ +/* + * File : drv_uart.c + * This file is part of RT-Thread RTOS + * COPYRIGHT (C) 2009-2014 RT-Thread Develop Team + * + * The license and distribution terms for this file may be + * found in the file LICENSE in this distribution or at + * http://www.rt-thread.org/license/LICENSE + * + * Change Logs: + * Date Author Notes + * 2014-01-05 NongXiaoming The first version for LPC40xx + */ + #ifndef __UART_H__ #define __UART_H__ diff --git a/bsp/lpc408x/rtconfig.h b/bsp/lpc408x/rtconfig.h index 2ef8f1523e..9b04e63aab 100644 --- a/bsp/lpc408x/rtconfig.h +++ b/bsp/lpc408x/rtconfig.h @@ -165,7 +165,7 @@ // // #define RT_LWIP_SNMP // -// #define RT_LWIP_DHCP +#define RT_LWIP_DHCP // #define RT_LWIP_TCPTHREAD_PRIORITY 12 // diff --git a/bsp/lpc408x/template.uvopt b/bsp/lpc408x/template.uvopt new file mode 100644 index 0000000000..bfe099d207 --- /dev/null +++ b/bsp/lpc408x/template.uvopt @@ -0,0 +1,164 @@ + + + + 1.0 + +
### uVision Project, (C) Keil Software
+ + + *.c + *.s*; *.src; *.a* + *.obj + *.lib + *.txt; *.h; *.inc + *.plm + *.cpp + + + + 0 + 0 + + + + RT-Thread LPC408x + 0x4 + ARM-ADS + + 12000000 + + 1 + 1 + 1 + 0 + + + 1 + 65535 + 0 + 0 + 0 + + + 79 + 66 + 8 + .\build\ + + + 1 + 1 + 1 + 0 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 0 + + + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 0 + + + 0 + 0 + 1 + + 0 + + SARMCM3.DLL + -MPU + DCM.DLL + -pCM4 + SARMCM3.DLL + -MPU + TCM.DLL + -pCM4 + + + 0 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 0 + 1 + 1 + 1 + 0 + 1 + 0 + 0 + 0 + 7 + + + + + + + + + + + Segger\JL2CM3.dll + + + + 0 + JL2CM3 + -U4294967295 -O78 -S0 -A0 -C0 -JU1 -JI127.0.0.1 -JP0 -RST0 -N00("ARM CoreSight SW-DP") -D00(2BA01477) -L00(4) -TO18 -TC10000000 -TP21 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -TB1 -TFE0 -FO11 -FD10000000 -FC800 -FN1 -FF0LPC_IAP_512 -FS00 -FL080000 + + + + + 0 + + + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + + + + + + +
From 587086d34d5c002dd33be2523be9d84018eb759d Mon Sep 17 00:00:00 2001 From: Bernard Xiong Date: Thu, 15 Oct 2015 23:36:51 +0800 Subject: [PATCH 32/36] Update README.md --- README.md | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 7aa3854ca6..014d5d3282 100644 --- a/README.md +++ b/README.md @@ -3,17 +3,17 @@ [![Build Status](https://travis-ci.org/RT-Thread/rt-thread.svg)](https://travis-ci.org/RT-Thread/rt-thread) [![Gitter](https://badges.gitter.im/Join Chat.svg)](https://gitter.im/RT-Thread/rt-thread?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) -RT-Thread is an open source real-time operating system for embedded devices from China. RT-Thread RTOS is a scalable real-time operating system: a tiny kernel for ARM Cortex-M0, Cortex-M3/4/7, or a rich feature system like ARM Cortex-A8, ARM Cortex-A9 DualCore etc. +RT-Thread is an open source real-time operating system for embedded devices from China, which has strong scalability: from a tiny kernel running on a tiny core, for example ARM Cortex-M0, or Cortex-M3/4/7, to a rich feature system running on ARM Cortex-A8, ARM Cortex-A9 DualCore etc. ## Overview ## -RT-Thread RTOS like a traditional real-time operating system. The kernel has real-time multi-task scheduling, semaphore, mutex, mail box, message queue etc. However, it has two different things: +RT-Thread RTOS like a traditional real-time operating system. The kernel has real-time multi-task scheduling, semaphore, mutex, mail box, message queue etc. However, it has three different things: * Device Driver; * Component; * Application Module -The device driver is more like a driver framework, UART, IIC, SPI, SDIO, USB device/host, EMAC, MTD NAND etc. The developer can easily add low level driver and board configuration, then he/she can use lots of features. +The device driver is more like a driver framework, UART, IIC, SPI, SDIO, USB device/host, EMAC, MTD NAND etc. The developer can easily add low level driver and board configuration, then combined with the upper framework, he/she can use lots of features. The Component is a software concept upon RT-Thread kernel, for example a shell (finsh/msh shell), virtual file system (FAT, YAFFS, UFFS, ROM/RAM file system etc), TCP/IP protocol stack (lwIP), POSIX (thread) interface etc. One component must be a directory under RT-Thread/Components and one component can be descripted by a SConscript file (then be compiled and linked into the system). @@ -41,7 +41,6 @@ As a special exception, including RT-Thread RTOS header files in a file, instant ## Usage ## RT-Thread RTOS uses [scons](http://www.scons.org) as building system. Therefore, please install scons and Python 2.7 firstly. - So far, the RT-Thread scons building system support the command line compile or generate some IDE's project. There are some option varaibles in the scons building script (rtconfig.py): * ```CROSS_TOOL``` the compiler which you want to use, gcc/keil/iar. @@ -58,7 +57,7 @@ When you set these variables correctly, you can use command: under BSP directory to simplely compile RT-Thread RTOS. If you want to generate the IDE's project file, you can use command: -s + scons --target=mdk/mdk4/mdk5/iar/cb -s to generate the project file. @@ -67,4 +66,4 @@ NOTE: RT-Thread scons building system will tailor the system according to your r ## Contribution ## -Thank all of RT-Thread Developers. +Please refer the contributors in the github. Thank all of RT-Thread Developers. From 11d984c52d5e7a3d10057c910ea598c8dffd533a Mon Sep 17 00:00:00 2001 From: Bernard Xiong Date: Fri, 16 Oct 2015 22:04:37 +0800 Subject: [PATCH 33/36] Update ChangeLog_CN.md --- ChangeLog_CN.md | 265 +++++++++++++++++++++--------------------------- 1 file changed, 117 insertions(+), 148 deletions(-) diff --git a/ChangeLog_CN.md b/ChangeLog_CN.md index 31ccb8ef9e..12435ced95 100644 --- a/ChangeLog_CN.md +++ b/ChangeLog_CN.md @@ -1,9 +1,58 @@ +# RT-Thread v2.1.0 beta鐗堟湰鏇存敼璇存槑 + +## BSP閮ㄥ垎 + +* BeagleBone鍔犲叆GPIO椹卞姩锛 +* 浜井闆呮牸M7锛屾洿鏂伴┍鍔ㄥ簱骞舵敼杩汦MAC椹卞姩绋嬪簭锛 +* 鏂板姞鍏m365绉绘锛堝寘鎷珽MAC銆丟PIO銆両2C銆丮MC/SD銆丼PI绛夐┍鍔級锛 +* LPC4088鍔犲叆EMC銆佺‖浠跺畾鏃跺櫒銆丆AN椹卞姩锛 +* 鏂板姞鍏ラ緳鑺1C锛屾櫤榫檝2寮鍙戞澘绉绘锛堝寘鎷涓插彛椹卞姩锛夛紱 +* 鏇存敼mini2440绉绘涓篴pplications/drivers绛夌殑鐩綍鏂瑰紡锛 +* 鏇存柊simulator鍦∕S VC++涓婄殑绉绘锛屽鐞嗗ソ鍒濆鍖栦唬鐮佸伐浣滐紝瀹屽杽UART鎺у埗鍙伴┍鍔紱 +* 鏂板姞鍏tm32f7-disco绉绘锛 +* 鍦╯tm32f10x涓柊鍔犲叆CAN椹卞姩鍙婂簲鐢ㄤ唬鐮佺ず渚嬶紱 +* 鍦╯tm32f40x涓姞鍏ョ‖浠跺畾鏃跺櫒椹卞姩锛孯TC椹卞姩锛 +* 璋冩暣stm32f107涓烘柊鐨勪覆鍙i┍鍔ㄦ鏋讹紱 + +## 缁勪欢 + +* DFS鐨剆truct stat瀹氫箟涓Щ闄t_blksize鎴愬憳锛堝彲浠ュ吋瀹逛簬VC++涓殑stat瀹氫箟锛夛紱 +* 淇DFS涓璼elect瀹炵幇鐨勯棶棰橈紱 +* 淇DFS涓枃浠舵搷浣滃嚭閿欍佸叧闂椂鐨刦d澶勭悊闂锛 +* 淇DFS涓璵kdir鍜宭seek鍑洪敊鏃剁殑fd澶勭悊闂锛 +* 淇lwIP涓璖YS_ARCH_PROTECT/SYS_ARCH_UNPROTECT淇濇姢鐨勯棶棰橈紱 +* 澧炲姞CAN椹卞姩妗嗘灦锛 +* 澧炲姞纭欢瀹氭椂鍣ㄩ┍鍔ㄦ鏋讹紱 +* SD/MMC椹卞姩妗嗘灦涓鍔爀MMC鏀寔锛 +* 淇娉ㄥ唽SDIO椹卞姩鏃堕┍鍔ㄥ叧鑱旂殑闂锛 +* 淇涓插彛椹卞姩妗嗘灦DMA鍙戦佹椂婵娲绘爣蹇楃殑闂锛 +* SPI Flash椹卞姩涓姞鍏ュGD25Q spi flash鑺墖鏀寔锛 +* 澧炲姞paho-mqtt缁勪欢绉绘锛 +* 澧炲姞msh鐨勮剼鏈墽琛岃兘鍔涳紝鍙互鍦╩sh涓嬫墽琛*.sh鑴氭湰锛 +* 澧炲姞msh涓嬬殑mkfs鍛戒护锛 +* 淇鍦↙inux Telnet涓嬩娇鐢╢insh shell鍥炶溅绗﹀鐞嗙殑闂锛 +* 澧炲姞搴旂敤妯″潡鍦ㄤ娇鐢╝rmcc銆乬nu gcc缂栬瘧鍣ㄦ椂鐨刲ibc绗﹀彿瀵煎嚭锛 +* 鍦ㄤ互澶綉缃戝崱椹卞姩妗嗘灦涓鍔燛THIF_LINK_AUTOUP/PHYUP鍙傛暟鐢ㄤ簬鎸囧畾鍒濆鏃剁殑閾捐矾Up/Down鐘舵侊紱 +* 鍦ㄧ粍浠跺垵濮嬪寲涓鍑簂og_trace缁勪欢锛 + +## 鍐呮牳 + +* 鏇存敼UNUSED/USED绛夋洿鏀规垚RT_UNUSED/RT_USED锛 +* 閾炬帴鏃跺鍔.rodata.name section锛屽綋绌洪棿璧勬簮鍙楅檺鏃跺彲浠ユ妸瀹冩斁鍒版ц兘浣庣殑鍐呭瓨鍖哄煙锛 +* 瀹屽杽IAR缂栬瘧鍣ㄤ笅鐨勭粍浠惰嚜鍔ㄥ垵濮嬪寲锛 +* 澧炲姞rt_assert_hook锛屽湪瑙﹀彂鏂█鏃跺彲浠ユ墽琛岃繖涓挬瀛愬嚱鏁帮紱 +* 淇搴旂敤妯″潡鍒嗘暎鍔犺浇鎯呭喌涓嬬殑闂锛 + +## 宸ュ叿 + +* scons涓畾涔塆roup鏃跺姞鍏ヤ簡鏈珿roup鍐呯殑缂栬瘧鍙傛暟瀹氫箟锛 +* 淇浜嗗鏋淕roup涓嵆鍖呭惈浠g爜锛屼篃鍖呭惈浜岃繘鍒跺簱鏃讹紝鐢熸垚鐨凨eil MDK宸ョ▼鏂囦欢鏈変袱涓噸鍚岹roup鐨勯棶棰橈紱 鐗堟湰: RT-Threadv2.0.1鍙妚2.1.0 alpha RT-Thread v2.0.1鏄2.0杩欎釜绯诲垪鐨刡ug淇鐗堬紝鑰寁2.1.0 alpha鍒欐槸褰撳墠寮鍙戜富骞茬殑涓涓妧鏈瑙堢増鏈紝瀹冪粰鍑轰簡v2.1.0杩欎釜鐗堟湰绯诲垪鐨勬妧鏈瑙堟儏鍐碉紝涓嶅缓璁敤浜庡疄闄呬骇鍝佷腑锛屽洜涓哄畠鍙兘瀛樺湪澶ч噺鐨勪竴浜沚ug銆 -RT-Thread v2.0.1淇鐨勪富瑕佸唴瀹瑰寘鎷細 +# RT-Thread v2.0.1鏇存敼璇存槑 * IAR鐢ㄧ殑dlib锛屽姞鍏HREAD_SUPPORT 鍜 FILE_DESCRIPTOR鐨勬敮鎸侊紱 * 淇finsh涓璭cho鍥炴樉妯″紡鐨勯棶棰橈紱 @@ -15,28 +64,19 @@ RT-Thread v2.0.1淇鐨勪富瑕佸唴瀹瑰寘鎷細 * lwip鏇存繁搴︾殑闆嗘垚锛氭妸瀹冮泦鎴愬埌RT-Thread鐨勬枃浠剁郴缁熸帴鍙d腑锛岃繖鏍稬inux/Unix涓嬬殑涓浜泂ocket缃戠粶搴旂敤鑳藉鏇撮『鍒╃殑绉绘鍒癛T-Thread涓婏紝涔熶负浠ュ悗鍙互搴旂敤鍒版洿澶氬湴鏂圭殑select鎺ュ彛閾鸿矾銆 -* 杩欓儴鍒嗘槸鍜孯T-Thread鍙戝竷鏈韩鏃犲叧锛屼絾涔熸槸杩欎釜鐗堟湰绯诲垪璁惧畾鐨勭洰鏍囦箣涓锛氬紑鍚竴涓簯绔泦鎴愬紑鍙戠幆澧冪殑鏃朵唬锛佷簯绔細鏄粈涔堟牱鐨勶紝璇风敤鐜颁唬鍖栫殑娴忚鍣ㄦ墦寮浠ヤ笅鍦板潃锛 -http://lab.rt-thread.org/cloudide/simulator/index.html +* 杩欓儴鍒嗘槸鍜孯T-Thread鍙戝竷鏈韩鏃犲叧锛屼絾涔熸槸杩欎釜鐗堟湰绯诲垪璁惧畾鐨勭洰鏍囦箣涓锛氬紑鍚竴涓簯绔泦鎴愬紑鍙戠幆澧冪殑鏃朵唬锛佷簯绔細鏄粈涔堟牱鐨勶紝璇风敤鐜颁唬鍖栫殑娴忚鍣ㄦ墦寮[CloudIDE](http://lab.rt-thread.org/cloudide/simulator/index.html) - - -//---------------------------------------------------------------------------------------- - -//---------------------------------------------------------------------------------------- - -//---------------------------------------------------------------------------------------- - -鐗堟湰: RT-Thread 2.0.0姝e紡鐗 +# RT-Thread 2.0.0姝e紡鐗堟洿鏀硅鏄 缁忓巻浜嗗ぇ绾1骞寸殑鏃堕棿锛孯T-Thread v2.0.0鐨勬渶缁堢増鏈粓浜庡彂甯冨嚭鏉ヤ簡銆傝嚜杩欎釜鐗堟湰寮鍙戜互鏉ワ紝寮曞叆浜嗗椤瑰姛鑳姐佷慨鏀广佸寮虹瓑銆傛劅璋㈠弬涓庣殑璇镐綅寮鍙戜汉鍛橈紒 浠ヤ笅鏄嚜v2.0.0 RC鐗堟湰浠ユ潵鐨勮缁嗘洿鏀硅褰曘傚悗缁垜杩樹細缁欏嚭v2.0.0鐗堟湰鑷獀1.2.x鐗堟湰鐨勪富瑕佷笉鍚屻佺湅鐐癸紝浠ュ強缁欏嚭涓嬩竴涓増鏈殑roadmap瑙勫垝銆 - [鍐呮牳] +## 鍐呮牳 * console浠T_DEVICE_FLAG_STREAM鍙傛暟鎵撳紑瀛楃璁惧锛 * 鍦╮t_memheap_free涓姞鍏ユ洿澶氱殑鏂█妫鏌ワ紱 - [缁勪欢] +## 缁勪欢 * 鏇存柊RW009椹卞姩浠ユ敮鎸乄i-Fi SoftAP妯″紡锛坅ozima锛夛紱 * 淇sensor妗嗘灦鐨勪竴浜涢棶棰橈紝骞跺姞鍏 API鎺ュ彛锛堢澘璧涘痉鏈嶅姟鍏徃鎻愪緵锛夛紱 @@ -53,10 +93,9 @@ http://lab.rt-thread.org/cloudide/simulator/index.html * 澧炲姞lwIP/NAT缁勪欢锛屽彲浠ュ仛澶氫釜缃戝彛闂寸殑鍦板潃杞崲锛圚icard锛夛紱 * 澧炲姞lwIP/DHCP鏈嶅姟绔紝鐢ㄤ簬鍚戝鎴风鍒嗛厤IP鍦板潃锛堢澘璧涘痉鏈嶅姟鍏徃鎻愪緵锛夛紱 - [BSP] +## BSP * 淇LPC4357涓插彛椹卞姩鍒濆鍖栨椂杩囨棭鎵撳紑涓柇鐨勯棶棰橈紙nongxiaoming锛夛紱 - * 閲嶅啓LPC4357涓插彛椹卞姩锛屽苟璁╄姱鐗囦笂M4/M0鏍稿績鍒嗗埆閮芥墽琛孯T-Thread绯荤粺锛屼袱鏍稿績涔嬮棿浠BUS缁勪欢杩涜绯荤粺闂撮氫俊锛堢澘璧涘痉鏈嶅姟鍏徃鎹愯禒锛夛紱 * 鏂板RX绉绘锛坙imxuzheng锛夛紱 * 鏂板NuMicro M051 Series绉绘锛屾敮鎸丟CC銆並eil MDK缂栬瘧鍣紙bright-pan锛夛紱 @@ -65,17 +104,11 @@ http://lab.rt-thread.org/cloudide/simulator/index.html * 鍦↙inux Clang缂栬瘧鍒嗘瀽涓紝寮哄埗浠32浣嶆ā寮忚繘琛岀紪璇戯紙grissiom锛夛紱 * 淇STM32F103涓覆鍙i┍鍔ㄤ腑鏂繃鏃╂墦寮鐨勯棶棰橈紙armink锛夛紱 - [宸ュ叿] +## 宸ュ叿 * 澧炲姞scons涓殑MD5鏀寔锛坆right-pan锛夛紱 -//---------------------------------------------------------------------------------------- - -//---------------------------------------------------------------------------------------- - -//---------------------------------------------------------------------------------------- - -鐗堟湰: RT-Thread 2.0.0 RC +# RT-Thread 2.0.0 RC 鏇存敼璇存槑 鍙戝竷鏃堕棿:2014/11/4 @@ -96,7 +129,7 @@ CSDN寮婧愬浠よ惀鍏朵粬鐨勬垚鏋滐紝渚嬪bluedroid绉绘涔熸湁浜嗗垵姝ョ殑鎴 浠ヤ笅鏄繖涓増鏈殑鏇存敼璁板綍: - [鍐呮牳] +## 鍐呮牳 * 淇褰撻噰鐢ㄩ珮绾у埆浼樺寲缂栬瘧鏃讹紝idle浠诲姟涓煡璇㈡槸鍚︽湁鍍靛案绾跨▼鐨勬綔鍦╞ug锛 @@ -104,93 +137,53 @@ CSDN寮婧愬浠よ惀鍏朵粬鐨勬垚鏋滐紝渚嬪bluedroid绉绘涔熸湁浜嗗垵姝ョ殑鎴 * 鍦╟onsole涓墦寮璁惧鏃讹紝鍔犲叆娴佹爣蹇楄繘琛屾墦寮锛 - [缁勪欢] +## 缁勪欢 * 鍔犲叆C++鍩虹鏀拺缁勪欢銆侰++缁勪欢渚濊禆浜嶳T_USING_LIBC搴擄紝褰撲娇鐢℅CC缂栬瘧鍣ㄦ椂璇锋敞鎰忔煡鐪嬪叾涓殑璇存槑鏂囨。骞舵洿鏀筶d script锛 - * 淇DFS涓璑FS鎵撳紑鐩綍鐨刡ug锛 - * 鏇存敼DFS ROMFS榛樿romfs_root涓哄急鍖栫鍙凤紱 - * 娣诲姞DFS涓璬fs_file_lseek鎺ュ彛涓叧浜巉s鐨勬鏌ワ紱 - * 绉婚櫎I2C core涓棤鐢ㄧ殑core lock閿侊紱 - * 娣诲姞sensor framework锛堥噰鐢–++鐨勬柟寮忔敮鎸佸悇绉峴ensor锛夛紱 - * 淇serial妗嗘灦涓璂MA鍙戦佺殑bug锛坔eyuanjie87锛夛紱 - * 绉婚櫎SPI妗嗘灦涓笉蹇呰鐨刣evice鍒濆鍖栦唬鐮侊紱 - * 瀹屽杽SPI Wi-Fi缃戝崱RW009椹卞姩骞舵彁渚汻SSI鐩稿叧鐨勫懡浠わ紱 - * 淇MSH涓湭瀹氫箟DFS_USING_WORKDIR鏃舵洿鏀瑰綋鍓嶇洰褰曠殑bug锛 - * 淇MSH涓湭瀹氫箟RT_LWIP_TCP鏃朵緷鐒跺畾涔変簡netstat鍛戒护鐨刡ug锛 - * 淇MSH涓湭瀹氫箟RT_USING_HEAP鏃朵緷鐒跺畾涔変簡free鍛戒护鐨刡ug锛 - * 淇finsh涓璅INSH_USING_HISTORY鐩稿叧鐨勮鍓紱 - * 鍔犲叆gdb stub缁勪欢锛屽綋鍓嶆敮鎸丄RM Cortex-A8鍜孋ortex-M3/4锛坵zyy2锛夛紱 - * 缁熶竴涓嶅悓缂栬瘧鍣ㄤ笅浣跨敤LIBC鐨勫畯涓篟T_USING_LIBC锛屽師鏈夌殑瀹忓畾涔塕T_USING_NEWLIB/RT_USING_ARM_LIBC闇瑕佷粠rtconfig.h涓Щ闄わ紝骞舵浛鎹㈡垚RT_USING_LIBC锛 - * 鍔犲叆鏈鏂扮殑lwIP鍒嗘敮锛歭wip-head锛屼互鎻愪緵IPv4/v6鍙屾爤鐨勫姛鑳斤紙hduffddybz锛夛紱 - * YMode涓墦寮涓插彛璁惧鏃讹紝娣诲姞open flag锛坅rmink锛夛紱 - [bsp] +## bsp * 鍔犲叆鍖椾含浜井闆呮牸鐨凪7锛堝崕灞憋級浣庡姛鑰桭PGA鐨凙RM Cortex-M3绉绘锛坅ozima锛夛紱 - * 鍔犲叆鍖椾含浜井闆呮牸鐨凪7 EMAC浠ュお缃戦┍鍔紙aozima锛夛紱 - * AT91SAM9260鍒嗘敮涓洿鏀筊T_USING_NEWLIB涓篟T_USING_LIBC锛 - * BeagleBoneBlack鍒嗘敮涓姞鍏db stub鏀寔锛坵zyy2锛夛紱 - * LPC176x鍒嗘敮涓姞鍏++鏀寔锛 - * LPC176x鍒嗘敮涓慨姝D鍗¢┍鍔ㄨ繑鍥炲崱淇℃伅鐨刡ug锛 - * 淇LPC408x鍒嗘敮涓璆CC缂栬瘧鏃剁殑闂锛 - * LPC408x鍒嗘敮涓姞鍏++鏀寔锛 - * 榫欒姱1B鍒嗘敮涓姞鍏ART3椹卞姩锛 - * 鍔犲叆椋炵储鍗婂浣撶殑MB9BF568 FM4鍒嗘敮绉绘锛坹angfasheng锛夛紱 - * mini2440鍒嗘敮涓洿鏀筊T_USING_NEWLIB涓 RT_USING_LIBC锛 - * stm32f0x鍒嗘敮涓Щ闄や笉鍚岀紪璇戝櫒涓嬬殑LIBC瀹氫箟锛岀粺涓鏇存敼涓篟T_USING_LIBC锛 - * stm32f0x鍒嗘敮涓姞鍏ヤ覆鍙f帴鏀舵孩鍑轰腑鏂鐞嗭紙armink锛夛紱 - * stm32f40x鍒嗘敮涓姞鍏db stub鏀寔骞舵坊鍔燯ART6椹卞姩锛坵zzy2锛夛紱 - * zynq7000鍒嗘敮涓洿鏀筊T_USING_NEWLIB涓篟T_USING_LIBC锛 - * 鍔犲叆ARM Cortex-M4鑺墖鎸囦护绾х殑ffs瀹炵幇锛 - * 淇MB0BF618S鍒嗘敮涓己灏憈imer鍒濆鍖栫殑bug锛坢ike mao锛夛紱 - [宸ュ叿] +## 宸ュ叿 * 绉婚櫎Python 2.6涓湭鏀寔鐨勮娉曪紙xfguo锛夛紱 - * 绉婚櫎Windows骞冲彴涓殑startupinfo淇℃伅锛堝Python鐗堟湰鍏煎鎬ф洿濂斤級锛 - * 淇CPPPATH琚墦涔辩殑bug锛 -//---------------------------------------------------------------------------------------- - -//---------------------------------------------------------------------------------------- - -//---------------------------------------------------------------------------------------- - -鐗堟湰: RT-Thread 2.0.0 Beta +# RT-Thread 2.0.0 Beta鏇存敼璇存槑 鍙戝竷鏃堕棿:2014/8/1 @@ -200,7 +193,7 @@ v2.0.0鐗堟湰鐨勫紑鍙戠浉瀵规椿璺冧簺锛屽紑婧愮ぞ鍖烘彁渚涗簡寮烘湁鍔涚殑鏀寔 鏇存敼璁板綍 -[鍐呮牳] +## 鍐呮牳 * 绉婚櫎rt_device_init_all()鍑芥暟锛氬湪绯荤粺鍚姩鏃朵笉闇瑕佸啀璋冪敤杩欎釜鍑芥暟鏉ュ垵濮嬪寲椹卞姩锛岃屾槸鐢变笂灞傚簲鐢ㄦ墽琛宺t_device_open鏃惰嚜鍔ㄨ繘琛岃澶囧垵濮嬪寲锛 * 淇璁惧瀵硅薄寮曠敤璁℃暟鍦ㄦ墦寮璁惧澶辫触渚濈劧閫掑鐨勯棶棰橈紱 @@ -211,11 +204,11 @@ v2.0.0鐗堟湰鐨勫紑鍙戠浉瀵规椿璺冧簺锛屽紑婧愮ぞ鍖烘彁渚涗簡寮烘湁鍔涚殑鏀寔 * 鍦ㄦ墽琛宻oft timer瓒呮椂鍑芥暟鏃讹紝鎵撳紑璋冨害鍣ㄩ攣锛 * 鏂板鍧楄澶囩殑鑷姩鍒锋柊鍙傛暟锛孯T_DEVICE_CTRL_BLK_AUTOREFRESH锛 -[宸ュ叿] +## 宸ュ叿 * 淇scons鍛戒护缂栬瘧鏃讹紝閫夋嫨keil mdk (armcc)缂栬瘧鍣ㄦ椂锛屽懡浠よ澶暱缂栬瘧澶辫触鐨勯棶棰橈紱 -[绉绘] +## 绉绘 * 绉婚櫎rt_device_init_all()鐩稿叧鐨勮皟鐢紱 * 鏍规嵁涓插彛妗嗘灦璋冩暣鐩稿叧鐨勯┍鍔ㄤ唬鐮侊紱 @@ -233,7 +226,7 @@ v2.0.0鐗堟湰鐨勫紑鍙戠浉瀵规椿璺冧簺锛屽紑婧愮ぞ鍖烘彁渚涗簡寮烘湁鍔涚殑鏀寔 * 鏂板MB9BF618S绉绘锛 * 鏂板tm4c129x绉绘锛屽苟鍔犲叆鐩稿簲鐨凟MAC浠ュお缃戦┍鍔紱 -[缁勪欢] +## 缁勪欢 * DFS: 鏂板鏍规嵁璁惧瀵硅薄鑾峰緱鍏朵笂瑁呰浇鏂囦欢绯荤粺璺緞鐨勫嚱鏁帮細dfs_filesystem_get_mounted_path(struct rt_device* device); * DFS: 淇readdir鍦℅NU GCC涓嬬殑缂栬瘧璀﹀憡锛 @@ -260,18 +253,13 @@ v2.0.0鐗堟湰鐨勫紑鍙戠浉瀵规椿璺冧簺锛屽紑婧愮ぞ鍖烘彁渚涗簡寮烘湁鍔涚殑鏀寔 * log trace: log trace涓殑session寮曠敤鏇存敼鎴愬父閲忓舰寮忥紱 * ymodem: 澧炲己鏁版嵁鎺ユ敹鐨勭ǔ瀹氭э紱 -//---------------------------------------------------------------------------------------- +# RT-Thread 2.0.0 Alpha鏇存敼璇存槑 -//---------------------------------------------------------------------------------------- - -//---------------------------------------------------------------------------------------- - -鐗堟湰: RT-Thread 2.0.0 Alpha 鍙戝竷鏃堕棿:2014/4/8 RT-Thread 2.0.0鍒嗘敮鐨勭涓涓妧鏈瑙堢増鏈紝浠呯敤浜庡睍绀2.0.0鍙戝睍鍒嗘敮鐨勬紨鍖栧姩鍚(鎸夌収roadmap锛2.0.0杩欎釜鍒嗘敮浼氭湁涓閮ㄥ垎RT-Thread鍜孡inux浜掕ˉ鎬х殑鎶鏈紝涓篖inux澧炲姞鏇村ソ鐨勫疄鏃舵э紝涓篟T-Thread澧炲姞鏇村鐨勫姛鑳芥э紝杩欎唤鎶鏈瑙堢増姝f槸鏈濈潃杩欎釜鐩爣鑰屽姫鍔)锛屾杩庡弽棣堝缓璁拰闂銆 -[缁勪欢鍙樻洿] +## 缁勪欢 * msh锛 bugfix 鍜屽姛鑳芥у寮恒傛柊鐨 msh 鍦ㄨ皟鐢ㄥ閮ㄦā鍧楁柟闈㈡洿鍔犳柟渚裤 * DFS锛 nfs 鐨 bugfix 鍜屽唴缃懡浠ょ殑澧炲己銆侲LM FatFS鍔犲叆瀵规墖鍖轰笉鍖归厤鎯呭喌涓嬬殑淇℃伅杈撳嚭锛岃繖鏍疯兘澶熷強鏃跺畾浣嶉棶棰樸 @@ -280,12 +268,12 @@ RT-Thread 2.0.0鍒嗘敮鐨勭涓涓妧鏈瑙堢増鏈紝浠呯敤浜庡睍绀2.0.0鍙戝睍 * CMSIS锛氱増鏈洿鏂拌嚦 3.20 * drivers锛歎SB 鍗忚鏍堢殑閲嶆瀯銆傛柊鐨勬鏋朵腑缂栧啓椹卞姩鍙樺緱鏇村姞瀹规槗浜嗐 -[BSP 鍙樻洿] +## BSP * beaglebone锛氫覆鍙i┍鍔ㄦ洿鏂 * realview-a8锛氭坊鍔犱簡 VMM 缁勪欢 -[缂栬瘧鑴氭湰] +## 宸ュ叿 * 鍥轰欢鍔犲叆scons --target=ua -s锛岀敤浜庡噯澶囩敤鎴峰簲鐢ㄧ幆澧冿紱 @@ -301,28 +289,29 @@ insmod rtvmm.ko 鏉ュ惎鍔 RT-Thread銆俁T-Thread 鍚姩涔嬪悗鎺у埗鍙板湪绗簩涓覆鍙d笂(Atl + Ctrl + 4)銆傜涓涓覆鍙inux shell渚濈劧鍙互浣跨敤锛岀浜屼釜涓插彛鍒欐槸RT-Thread鐨剆hell銆 - JavaScript瑙f瀽鍣紝杩欎釜鏄敱鐗涘ご鍝ョЩ妞嶇殑锛屽彲浠ュ湪涓涓潪甯稿皬璧勬枡鐨凪CU涓婁互JavaScript鑴氭湰鏂瑰紡杩涜缂栫▼銆佸紑鍙戙傛牴鎹繖绉嶆柟寮忥紝涔熸彁渚涗簡RN001JS鐨勪互澶綉纭欢妯″潡锛氫互JavaScript鑴氭湰璇█浣滀负浜屾寮鍙戯紝鎻愪緵鍦ㄧ嚎web(鍗砏ebIDE)杩涜缂栫▼骞惰繍琛孞avaScript绋嬪簭銆侸avaScript浣滀负涓闂ㄨ交閲忕骇銆佽В閲婂瀷鐨勮瑷锛屾洿瀹规槗涓婃墜锛岄厤鍚圵ebIDE銆佸強鎻愪緵鐨勪竴浜沞xample鍙互浣垮緱寮鍙戝彉寰楅潪甯哥殑杞绘澗锛屼篃鍖呮嫭涓浜涗紶鎰熷櫒鐨凧avaScript渚嬪瓙锛岃鍋氱綉椤电殑浜轰篃鍙互鐜╃‖浠朵簡锛 -//---------------------------------------------------------------------------------------- -//---------------------------------------------------------------------------------------- -//---------------------------------------------------------------------------------------- +# RT-Thread 1.2.1鏇存敼璇存槑 -鐗堟湰: RT-Thread 1.2.1 鍙戝竷鏃堕棿: 2014/4/8 鍦ㄥ師鏈夌殑1.2.0鐗堟湰鐨刡ug淇鐗堟湰锛屼篃鏄1.2.0绯诲垪鐨勭涓涓慨姝g増鏈紝鍘熷垯涓婁笉娣诲姞浠讳綍鐨勬柊鍔熻兘锛屾垜浠敖閲忎細鎸夌収姣忎釜瀛e害涓涓慨璁㈢増鏈殑鏂瑰紡鎺ㄨ繘銆傚ぇ瀹跺湪浣跨敤鐨勮繃绋嬩腑鏈変粈涔堥棶棰樿繕璇峰弽棣堢粰鎴戜滑锛岃繖浜涢棶棰樺緢鍙兘浼氬湪涓嬩釜鐗堟湰涓慨姝o紒 浠ヤ笅鏄洿鏀硅褰曪細 -[鍐呮牳] + +## 鍐呮牳 + * 鐢ㄦ埛搴旂敤锛屽鍔犵敤鎴峰簲鐢ㄥ懡浠よ鍙傛暟鏀寔锛 * 鍦ㄦ寕璧蜂竴涓换鍔℃椂锛屾妸鐩稿簲鐨勫畾鏃跺櫒涔熷叧闂紱 -[BSP] +## BSP + * BeagleBone锛屽姞鍏ユ洿澶氫覆鍙i┍鍔ㄦ敮鎸侊紱 * 绉婚櫎BSP涓璻t_device_init_all鍑芥暟璋冪敤锛屾敼鎴愭墦寮璁惧鏃惰嚜鍔ㄨ繘琛屽垵濮嬪寲锛 * LPC176x锛岀Щ闄omponents鍒濆鍖栫鐞嗗櫒锛 * LPC4088锛屼慨姝ED椹卞姩鐨勯棶棰橈紱 * STM32F107锛岀Щ闄omponents鍒濆鍖栫鐞嗗櫒锛 -[缁勪欢] +## 缁勪欢 + * 鏂囦欢绯荤粺锛孍LM FatFS鍔犲叆瀵规墖鍖轰笉鍖归厤鎯呭喌涓嬬殑淇℃伅杈撳嚭锛岃繖鏍疯兘澶熷強鏃跺畾浣嶉棶棰橈紱 * 鏂囦欢绯荤粺锛孨FS缃戠粶鏂囦欢绯荤粺淇鐩稿叧鐨勪竴浜涚紪璇戣鍛婁俊鎭紱 * 鏂囦欢绯荤粺锛宑opy鍛戒护鍔犲叆鏂囦欢澶规柟寮忓鍒跺姛鑳斤紱 @@ -336,18 +325,16 @@ insmod rtvmm.ko * POSIX thread锛屼慨姝d簡鍚屾椂浣跨敤lwIP缁勪欢鏃剁殑缂栬瘧璀﹀憡锛 * 绗笁鏂圭粍浠讹紝鍔犲叆TJPGD鐨勭Щ妞嶏紝鍔犲叆libpng鐨勭Щ妞嶏紱 -[缂栬瘧鑴氭湰] +## 宸ュ叿 + * 鍥轰欢鍔犲叆scons --target=ua -s锛岀敤浜庡噯澶囩敤鎴峰簲鐢ㄧ幆澧冿紱 [鍙戝竷鍚庤] * RT-Thread鎼哄甫浜嗕紬澶氱殑BSP锛屼笉涓瀹氳兘澶熶竴涓淇濊瘉姣忎釜鍒嗘敮涓婃妸RT-Thread涓婄浉搴旂殑鍔熻兘浣跨敤璧锋潵銆傛墍浠ラ拡瀵硅繖绉嶆儏鍐碉紝鎴戜滑鏈変竴娆捐瘎浼扮敤鐨勭‖浠跺紑鍙戞澘锛歊ealBoard 4088锛屽湪涓婇潰鍔涙眰鎶婁竴浜涚浉鍏充緥绋嬮兘娣诲姞涓婏紝杩欐牱鍦ㄤ竴涓熀鏈殑BSP鍩虹涓婏紝鍙互瀵圭収鐫鎶婂叾浠栫殑缁勪欢銆佸姛鑳芥坊鍔犺繘鍘伙紱 * RealBoard 4088浣跨敤鐨凴T-Thread鐗堟湰涓昏浠T-Thread 1.2.1鐗堟湰涓轰富銆 -//---------------------------------------------------------------------------------------- -//---------------------------------------------------------------------------------------- -//---------------------------------------------------------------------------------------- +# RT-Thread 1.2.0姝e紡鐗堟湰鏇存敼璇存槑 -鐗堟湰: RT-Thread 1.2.0姝e紡鐗堟湰 鍙戝竷鏃堕棿: 2014/1/6 瀹炵幇roadmap涓彁鍒扮殑澶ч儴鍒嗗唴瀹 @@ -362,18 +349,22 @@ insmod rtvmm.ko - 榛樿浣跨敤lwIP 1.4.1 涓嬮潰鏄嚜RT-Thread 1.2.0 RC鐗堟湰鍙戝竷浠ユ潵鍏蜂綋鐨勫彉鏇村饱鍘嗭細 -鍐呮牳锛 + +## 鍐呮牳 + * timer.c - 浣跨敤璺宠穬琛(skip list)瀹炵幇绯荤粺瀹氭椂鍣ㄩ摼琛紝骞跺湪bsp涓殑startup.c涓噸鏂板姞鍏ュ畾鏃跺櫒鍒濆鍖栧嚱鏁皉t_system_timer_init() * rtdebug.h - 鏂板瀹忓畾涔塕T_DEBUG_IN_THREAD_CONTEXT * idle.c - 鍦ㄥ嚱鏁皉t_thread_idle_excute()涓竴娆℃竻闄ゆ墍鏈夌殑姝荤嚎绋 * scheduler.c - 鏂板API rt_critical_level()杩斿洖璋冨害鍣ㄤ笂閿佹鏁 -绉绘锛 +## 绉绘 + * cortex-m0 - 淇 cortex-m0 GCC绉绘涓環ardfault鐨勯棶棰樼偣 * cortex-r4 - 鍦╯tartup鍚庨噴鏀綢RQ鍫嗘爤绌洪棿 * cortex-r4 - 鎸夊瓧鑺傞暱搴﹀垎閰嶅爢鏍堢┖闂 -BSP鍒嗘敮锛 +## BSP鍒嗘敮 + * 鏂板lpc408x绉绘 * bsp/stm32f0x - 澧炲姞USART1锛孶SART2椹卞姩锛屾敮鎸乫insh锛屾敮鎸佺粍浠跺垵濮嬪寲 * bsp/simulator - 褰揜TGUI閰嶇疆鏃犳晥鏃舵墦鍗伴敊璇俊鎭 @@ -385,7 +376,8 @@ BSP鍒嗘敮锛 * bsp/rm48x50 - 鏂板GCC鐨勭Щ妞 * bsp/K60Fxxxx - 淇涓涓紪璇戦敊璇 -缁勪欢锛 +## 缁勪欢 + * dfs - 姝g‘澶勭悊mkfs鏈疄鐜扮殑鎯呭喌 * dfs - 浣跨敤鎸囬拡浠f浛index鍙橀噺 * dfs - 鍦ㄥ嚱鏁癲fs_filesystem_lookup()灏嗗惈涔夋ā绯婄殑鎸囬拡鍙橀噺鍚嶇Оempty閲嶅懡鍚嶄负fs @@ -410,7 +402,8 @@ BSP鍒嗘敮锛 * drivers/pipe - 澧炲姞涓涓猚ontrol鍛戒护鏉ヨ幏寰梡ipe鍓╀綑鐨勭┖闂 * drivers/serial - 濡傛灉璇诲啓闀垮害涓0锛屽垯绔嬪嵆杩斿洖 -渚嬬▼锛 +## 渚嬬▼ + * examples - 鐢╮t_sem_control()涓殑RT_IPC_CMD_RESET鍛戒护rt_sem_trytake()鏉ユ竻闄や俊鍙烽噺 * examples - 濮嬬粓鎵撳嵃杈撳嚭娴嬭瘯缁撴灉 * examples - 鍦ㄦ墍鏈夌殑娴嬭瘯缁撴潫鍚庢墦鍗拌緭鍑虹畝鎶 @@ -429,11 +422,8 @@ BSP鍒嗘敮锛 鍏朵粬锛 * 鏇存柊README.md -//---------------------------------------------------------------------------------------- -//---------------------------------------------------------------------------------------- -//---------------------------------------------------------------------------------------- - -鐗堟湰: RT-Thread 1.2.0RC +# RT-Thread 1.2.0RC鏇存敼璇存槑 + 鍙戝竷鏃堕棿: 2013/10/10/ 10:19 涓昏璇存槑: 璇ョ増鏈柊澧濧RM Cortex-A8鐨勬敮鎸(BeagleBone)锛屾柊澧濽NITY-2鍐呮牳鐨勬敮鎸(SEP6200)锛屾柊澧瀁modem鍗忚銆 @@ -1367,11 +1357,8 @@ RT-Thread瀹炴椂鎿嶄綔绯荤粺缂栫▼鎸囧崡涓0.3.0姝e紡鐗堢殑鐩稿悓锛屼互鍚庝細閫 (*) 甯屾湜浣跨敤鏂扮壒鎬х殑寮鍙戜汉鍛樿鍏虫敞鍚庣画0.4.0鐗堟湰鐨勫彂甯冩儏鍐碉紝0.4.0鐗堟湰娣诲姞浜嗗緢澶氱殑鏂扮壒鎬э紝渚嬪锛16浣嶇殑鐟炶惃M16鍒嗘敮锛屽ぇ绔ā寮忕殑AVR32鍒嗘敮锛屼互鍙奙IPS鍒嗘敮绛夈 -//---------------------------------------------------------------------------------------- -//---------------------------------------------------------------------------------------- -//---------------------------------------------------------------------------------------- +# RT-Thread 0.4.0 beta2鍙戝竷璇存槑 -鐗堟湰: RT-Thread 0.4.0 beta2 鍙戝竷鏃堕棿: 2011/7/4 杩欐槸RT-Thread 0.4.x绯诲垪鐨勭浜屼釜娴嬭瘯鐗堟湰銆傝繖涓祴璇曠増鏈紝渚濈劧鏇村鐨勯潰鍚戞祴璇曠洰鐨勶紝涓嶅缓璁洿鎺ュ簲鐢ㄥ埌瀹為檯鐨勪骇鍝佷腑銆俁T-Thread 0.4.0鐨勯潪姝e紡鐗堟湰渚濈劧娌跨敤GPL v2璁稿彲璇佽繘琛屽彂甯冿紝娆㈣繋娴嬭瘯銆 @@ -1439,11 +1426,8 @@ tools: ** 鑷姩鍒涘缓IAR宸ョ▼ ** 鑷姩鍒涘缓MDK4宸ョ▼ -//---------------------------------------------------------------------------------------- -//---------------------------------------------------------------------------------------- -//---------------------------------------------------------------------------------------- +# RT-Thread 0.4.0 beta1鍙戝竷璇存槑 -鐗堟湰: RT-Thread 0.4.0 beta1 鍙戝竷鏃堕棿: 2010/11/30 鑷猂T-Thread 0.3.0姝e紡鐗堝彂甯冧互鏉ワ紝缁忚繃寮鍙戜汉鍛樺瘑闆嗙殑鏁8涓湀寮鍙戯紝澶т紬鐢ㄦ埛鐨勭Н鏋佸弽棣堛佹祴璇曪紝缁堜簬瀹屾垚浜哛T-Thread 0.4.x绯诲垪鐨勭涓涓祴璇曠増鏈傝繖涓祴璇曠増鏈紝渚濈劧鏇村鐨勯潰鍚戞祴璇曠洰鐨勶紝涓嶅缓璁洿鎺ュ簲鐢ㄥ埌瀹為檯鐨勪骇鍝佷腑銆俁T-Thread 0.4.0鐨勯潪姝e紡鐗堟湰渚濈劧娌跨敤GPL v2璁稿彲璇佽繘琛屽彂甯冿紝娆㈣繋娴嬭瘯銆 RT-Thread 0.4.0鐗堟湰鍒濆鎻愬嚭鐨勫嚑涓姛鑳戒害鍩烘湰杈惧埌锛屾彁渚涗簡鐩稿瀹屽杽鐨凱OSIX thread鎺ュ彛锛屽姩鎬佸簱杞藉叆鎺ュ彛libdl浠ュ強搴旂敤妯″潡鏀寔銆傝繖浜涙柊鍔熻兘鐨勫姞鍏ヤ娇寰桼T-Thread鑳藉鍒濇鐨勫吋瀹逛簬POSIX鏍囧噯銆 @@ -1504,11 +1488,9 @@ RT-Thread 0.4.0 beta1涓嬭浇 - FTK GUI銆 瀵逛簬Cortex-M3绛夊钩鍙帮紝鎴戜滑鐩墠涔熷湪瀵 搴旂敤妯″潡鐗规 杩涜璇勪及锛岀湅鐪嬩粠鎶鏈笂鏄惁鑳藉浠庡彟澶栫殑閫斿緞瑙e喅鍔ㄦ佽繍琛岄熷害鎱㈢殑闂銆 -//---------------------------------------------------------------------------------------- -//---------------------------------------------------------------------------------------- -//---------------------------------------------------------------------------------------- - -鐗堟湰: RT-Thread 0.3.1姝e紡鐗 + +# RT-Thread 0.3.1姝e紡鐗 鍙戝竷璇存槑 + 鍙戝竷鏃堕棿: 2010/9/29 鏄彂甯0.3.1姝e紡鐗堢殑鏃跺欎簡锛氬湪0.3.1鐨勭淮鎶よ繃绋嬩腑锛屽緱鍒颁簡澶у寰堝鐨勫弽棣堬紝鍏朵腑涓浜沚ug鍙婁慨姝d篃鏄敱澶у鎸囧嚭锛岃繖閲屾劅璋㈠ぇ瀹朵竴鐩翠互鏉ョ殑鏀寔锛孯T-Thread鐨勫彂灞曡繘姝ョ涓嶅紑澶у鐨勫府鍔╋紝璋㈣阿锛 鐩歌緝RT-Thread 0.3.0鐗堟湰锛0.3.1鐗堟湰鏄竴涓猙ug淇鐗堬紝骞舵棤娣诲姞鏂扮殑鐗规(*)锛屼娇鐢ㄤ笂涓0.3.0鐗堟湰瀹屽叏鍏煎銆傚缓璁娇鐢≧T-Thread 0.3.0鐗堟湰鐨勭敤鎴凤紝濡傛灉闇瑕侀暱鏃堕棿涓嶉棿鏂繍琛岋紙澶т簬1骞达級锛岃鍒囨崲鍒0.3.1姝e紡鐗堟湰鏉ャ @@ -1539,7 +1521,7 @@ RT-Thread鍦℅oogle SVN鏈嶅姟鍣ㄤ笂鐨勫紑鍙戝垎鏀害鍋氫簡鐩稿簲璋冩暣锛 RT-Thread瀹炴椂鎿嶄綔绯荤粺缂栫▼鎸囧崡涓0.3.0姝e紡鐗堢殑鐩稿悓锛屼互鍚庝細閫愭笎鐢盇PI璇存槑鏂囨。鏇夸唬锛屾湞鐫姝h鍖栫殑鏂瑰悜鍙戝睍銆 STM32鍒嗘敮 ---------- + 璇锋敞鎰廠TM32鍒嗘敮鐨勫伐绋嬫枃浠剁粍缁囨柟寮忓拰0.3.0鐗堟湰涓殑涓嶄竴鏍凤紝鍘熸潵鐨勫嚑涓洰褰曟槸涓嶇浉鐙珛鐨勫伐绋嬶紝鑰0.3.1涓负浜嗛伩鍏嶆贩娣嗭紝鎶婂畠浠彉鎴愪簡鐙珛鐨勫伐绋(娉細鍥犱负0.3.1涓0.3.0鏄畬鍏ㄥ吋瀹圭殑锛屾墍浠ヤ笉涓瀹氳鏇存柊BSP鐩綍)銆 project_107鏄拡瀵筍TM32F107鑺墖鐨勫伐绋嬶紝project_valueline鏄拡瀵筍TM32F100鑺墖 STM32 Discovery寮鍙戠増鐨勫伐绋嬶紝鍏朵綑鐨勮姱鐗囬粯璁ゆ槸STM32F103ZE銆傚鏋滆淇敼鎴愯嚜宸辨墍闇瑕佺殑鑺墖锛岃閬靛惊涓涓嬫楠わ細 @@ -1554,22 +1536,14 @@ keep { section VSymTab }; 鍏蜂綋璇风湅stm32f10x_flash.icf鏂囦欢銆 -LM3S鍒嗘敮 --------- -LM3S鍒嗘敮榛樿閲囩敤LM3S8962鑺墖锛岄拡瀵圭殑鏄疶I杩欐鍙戠殑48锟 8962寮鍙戞澘銆 +* LM3S鍒嗘敮 - LM3S鍒嗘敮榛樿閲囩敤LM3S8962鑺墖锛岄拡瀵圭殑鏄疶I杩欐鍙戠殑48锟 8962寮鍙戞澘銆 -LPC176x鍒嗘敮 ------------ -宸ョ▼榛樿鍖呮嫭finsh shell锛屾枃浠剁郴缁燂紝缃戠粶鍗忚鏍堢殑鏀寔銆 +* LPC176x鍒嗘敮 - 宸ョ▼榛樿鍖呮嫭finsh shell锛屾枃浠剁郴缁燂紝缃戠粶鍗忚鏍堢殑鏀寔銆 (*) 甯屾湜浣跨敤鏂扮壒鎬х殑寮鍙戜汉鍛樿鍏虫敞鍚庣画0.4.0鐗堟湰鐨勫彂甯冩儏鍐碉紝0.4.0鐗堟湰娣诲姞浜嗗緢澶氱殑鏂扮壒鎬э紝渚嬪锛16浣嶇殑鐟炶惃M16鍒嗘敮锛屽ぇ绔ā寮忕殑AVR32鍒嗘敮锛屼互鍙奙IPS鍒嗘敮绛夈 +# RT-Thread 0.3.0姝e紡鐗堝彂甯冭鏄 -//---------------------------------------------------------------------------------------- -//---------------------------------------------------------------------------------------- -//---------------------------------------------------------------------------------------- - -鐗堟湰: RT-Thread 0.3.0姝e紡鐗 鍙戝竷鏃堕棿: 2010/3/30 鐩歌緝浠ュ墠鐨凴T-Thread 0.3.0 RC鐗堟湰锛屾棤澶х殑淇敼锛坈onsole璋冩暣涓烘敮鎸佽澶囩殑妯″紡锛夛紝浣嗕緷鐒跺缓璁墍鏈変娇鐢0.2.x銆0.3.0 beta/rc鐗堢殑鐢ㄦ埛閮藉紑濮嬩娇鐢0.3.0姝e紡鐗堛傚綋鍓嶇増鏈敮鎸佸涓嬬Щ妞嶅垎鏀細 @@ -1602,10 +1576,8 @@ LM3S鐨凨eil MDK宸ョ▼鏂囦欢鏀惧湪bsp\lm3s鐩綍涓嬶紱閽堝LM3S8962鑺墖(鍥犱负 鎶婂涓婅繖涓畾涔夋洿鏀逛负SYSCTL_XTAL_8MHZ锛屽惁鍒欏緱璇濅細閿佹JTAG銆 -//---------------------------------------------------------------------------------------- -//---------------------------------------------------------------------------------------- -//---------------------------------------------------------------------------------------- -鐗堟湰: RT-Thread/LM3S 0.3.0 RC1鐗堝彂甯 +# RT-Thread/LM3S 0.3.0 RC1鐗堝彂甯冭鏄 + 鍙戝竷鏃堕棿: 2010/1/4 瀹炴椂绾跨▼鎿嶄綔绯荤粺鏄竴娆鹃潰鍚戝疄鏃堕鍩熺殑鎿嶄綔绯荤粺锛岃繖涓拰閫氬父鐨勯氱敤鎿嶄綔绯荤粺鏈夌潃寰堝ぇ鐨勪笉鍚屻傞氱敤鎿嶄綔绯荤粺閫氬父闈㈠鐨勬槸鏃ュ父搴旂敤锛屼緥濡傛墦寮娴忚鍣ㄤ笂缃戯紝鎾斁闊充箰锛岄噰鐢ㄥ瓧澶勭悊杞欢缂栬緫鏂囨。銆 @@ -1613,7 +1585,8 @@ LM3S鐨凨eil MDK宸ョ▼鏂囦欢鏀惧湪bsp\lm3s鐩綍涓嬶紱閽堝LM3S8962鑺墖(鍥犱负 瀹炴椂绯荤粺鍜岃繖绉嶉氱敤绯荤粺鏈夊緢澶х殑宸埆銆傚疄鏃剁郴缁熸寚鐨勬槸锛屽綋澶栫晫鏈夌郴缁熷叧娉ㄧ殑鐩稿簲浜嬩欢鍙戠敓鏃讹紝绯荤粺鑳藉鍦ㄦ寚瀹氱殑鏃堕棿鍐咃紙deadline锛夎繘琛屾纭殑鍝嶅簲銆傜敤浜庡疄鏃剁郴缁熺殑鎿嶄綔绯荤粺灏卞彨鍋氬疄鏃舵搷浣滅郴缁熴備粠绯荤粺鐨勫畾涔変篃鍙互鐪嬪緱鍑猴紝瀹炴椂鎿嶄綔绯荤粺鍜岄氱敤鎿嶄綔绯荤粺鍦ㄤ簨鍔$殑澶勭悊涓婃湁鏄庢樉鐨勫尯鍒紝瀹炴椂鎿嶄綔绯荤粺鏈夐潪甯稿己鐨勯拡瀵规э紝瀵圭浉搴旂殑浜嬩欢鍔涙眰鍋氬埌杩欏浐瀹氱殑鏃堕棿鍐呰繘琛屽搷搴旓紱鑰岄氱敤鎿嶄綔绯荤粺鍒欓渶瑕佸姫鍔涘湴鍋氬埌鍚勪釜浜嬪姟鐨勫叕骞虫э紙鏌愪簺绯荤粺涔熶細闈炲父娉ㄦ剰鏁版嵁鐨勫悶鍚愰噺锛屼緥濡傜綉缁滄湇鍔″櫒锛夈 瀹炴椂绾跨▼鎿嶄綔绯荤粺锛堣嫳鏂囧悕RT-Thread锛夐潰鍚戠殑姝f槸杩欎箞涓绫荤殑瀹炴椂绯荤粺锛屽洜涓哄叾灏忓瀷鐨勭壒鐐逛篃鍙互鐪嬫垚鏄竴涓祵鍏ュ紡鎿嶄綔绯荤粺锛堝祵鍏ュ紡绯荤粺涓鑸槸閽堝涓浜涗笓鏈夌洰鐨勮屽瓨鍦紝姣旇緝鍚濆暚浜庢垚鏈傝屽熀浜庝笓鏈夌洰鐨勭殑鐗圭偣锛屼篃娉ㄥ畾浜嗗祵鍏ュ紡绯荤粺鎴栧鎴栧皯鐨勫叿鏈変竴浜涘疄鏃舵х殑鐗圭偣锛夈傝繖绉嶇郴缁熷彲浠ョ敤浜庤嚜鍔ㄥ敭绁ㄦ満锛岀◣鎺ф満锛岀Щ鍔ㄩ氫俊璁惧锛宮p3/mp4绛変究鎼哄紡闊充箰璁惧锛岄琛屽櫒鎺у埗锛岃溅浣撳鑸帶鍒讹紝鎵撳嵃鏈猴紝澶嶅嵃鏈猴紝鍚勭被鐩戞帶璁惧锛岃矾鐢卞櫒锛孉DSL锛屾満椤剁洅绛夌綉缁滆澶囷紝鍖荤枟璁惧绛夌瓑銆 TI娴佹槑LM3S绯诲垪鑺墖鏄熀浜嶢RM Cortex M3 v7鏋勬灦鐨32浣嶈姱鐗囷紝鍏朵腑LM3S S6000锛孲8000锛孲9000绯诲垪鑺墖鎼哄甫缃戠粶鍔熻兘銆俁T-Thread鐨勬爣鍑嗗唴鏍稿彲浠ヨ繍琛屽湪闄M3S S100绯诲垪澶栫殑鎵鏈夌郴鍒楄姱鐗囦笂銆傝繖娆T-Thread閽堝浜嶭M3S杩涜绉绘楠岃瘉骞剁粡杩囧帇鍔涙祴璇曠殑鏄疞M3S6918鑺墖锛岃姱鐗囨惡甯64K鐗囧唴闈欐佸唴瀛橈紝256K闂瓨锛岄鐜囨槸50MHz銆傚湪杩欎釜骞冲彴涓婏紝RT-Thread鏀寔鐨勭壒鎬у寘鎷細 -? 瀹屽杽鐨勫疄鏃舵牳蹇 + +* 瀹屽杽鐨勫疄鏃舵牳蹇 - 闈㈠悜瀵硅薄鏂瑰紡鐨勫疄鏃舵牳蹇冿紙浣嗕緷鐒朵繚鐣欎簡C璇█鐨勪紭闆呫佸皬宸ч鏍硷級锛 - 榛樿32绾跨▼浼樺厛绾х殑鍏ㄦ姠鍗犲紡瀹炴椂鍐呮牳锛堜害鍙厤缃垚256绾跨▼浼樺厛绾э級锛涚浉鍚屼紭鍏堢骇绾跨▼鏃堕棿鐗囪疆杞皟搴︼紱 - 鐩稿悓浼樺厛绾х嚎绋嬪疄鏂芥椂闂寸墖鍙厤缃殑鍒嗘椂鏃堕棿鐗囪疆杞皟搴︼紱 @@ -1622,25 +1595,25 @@ TI娴佹槑LM3S绯诲垪鑺墖鏄熀浜嶢RM Cortex M3 v7鏋勬灦鐨32浣嶈姱鐗囷紝鍏朵腑LM - 鏀寔绾跨▼鎸傝捣鍜屽敜閱掔殑鍥哄畾鍐呭瓨鍧楃鐞嗗強绾跨▼瀹夊叏鐨勫姩鎬佸唴瀛樺爢绠$悊锛 - 鍚戜笂灞傛彁渚涘熀浜庡悕瀛楃殑缁熶竴鎺ュ彛璁惧椹卞姩妯″瀷锛 -? FinSH shell鍛戒护琛 +* FinSH shell鍛戒护琛 - 鍛戒护鍗矯浠g爜鐨勫懡浠よ鏂瑰紡锛 - 鐩存帴鍦ㄥ懡浠よ涓皟鐢ㄧ郴缁熷唴鏍稿嚱鏁帮紱 - 鐩存帴鍦ㄥ懡浠よ涓闂郴缁熷叏灞鍙橀噺锛 - 鍘嗗彶璁板綍鍙婂懡浠よ嚜鍔ㄨˉ鍏紱 -? 闈㈠悜灏忓瀷璁惧鐨勮櫄鎷熸枃浠剁郴缁 +* 闈㈠悜灏忓瀷璁惧鐨勮櫄鎷熸枃浠剁郴缁 - 鍚戜笂灞傚簲鐢ㄦ彁渚汸OSIX椋庢牸鐨凙PI鎺ュ彛锛 - 鏀寔澶氱鍏蜂綋鏂囦欢绯荤粺瀹炵幇锛 - LM3S鍒嗘敮鍐呯疆SD鍗¢┍鍔ㄧ▼搴忥紱 -? LwIP杞诲瀷TCP/IP鍗忚鏍 +* LwIP杞诲瀷TCP/IP鍗忚鏍 - 鏍囧噯鐨凚SD Socket鎺ュ彛锛 - IP銆両CMP銆乁DP銆乀CP鏍囧噯鍗忚鏀寔锛 - DNS锛孌HCP锛孭PP鍗忚鏀寔锛 - TFTP銆丠TTP銆丗TP搴旂敤鍗忚鏀寔锛堣netutil缁勪欢锛夛紱 - LM3S鍒嗘敮鍐呯疆浠ュお缃戦┍鍔紱 -? 寮鍙戠幆澧冩敮鎸侊細 +* 寮鍙戠幆澧冩敮鎸侊細 - GNU GCC (scons鍋氫负鏋勫缓宸ュ叿) - Keil MDK @@ -1701,11 +1674,8 @@ Packet size 8k bytes: 870 KByte/s Tx, 3239 KByte/s Rx. 璁稿彲璇 浣滀负涓濂楀熀纭缁勪欢锛屽氨渚嬪鐢佃剳涓殑涓枃杈撳叆娉曚竴鏍凤紝瀹冧笉搴旇鏀惰垂锛屽洜姝ゅ畠鑳藉鍏嶈垂鐨勪娇鐢ㄤ簬鍟嗕笟浜у搧涓紙0.3.x绯荤粺浠呴渶瑕佸湪鎴戜滑杩欒竟杩涜浜у搧淇℃伅澶囨锛屾洿鎹PLv2璁稿彲璇佷负鍟嗕笟璁稿彲璇侊紒0.4.x灏嗘洿鎹骇鍝佽鍙瘉涓築SD鎴朅pache寮婧愯鍙瘉锛夈 -//---------------------------------------------------------------------------------------- -//---------------------------------------------------------------------------------------- -//---------------------------------------------------------------------------------------- - -鐗堟湰: RT-Thread RTOS v0.2.3鐗堟湰 +# RT-Thread RTOS v0.2.3鐗堟湰鏇存敼璇存槑 + 鍙戝竷鏃堕棿: 2008/10/6 鏇存柊璁板綍 @@ -1719,11 +1689,10 @@ Packet size 8k bytes: 870 KByte/s Tx, 3239 KByte/s Rx. - 淇閾捐〃涓垵濮嬪寲闂锛 - 淇Object涓皟鐢ㄩ挬瀛愬嚱鏁扮殑闂锛 -//---------------------------------------------------------------------------------------- -//---------------------------------------------------------------------------------------- -//---------------------------------------------------------------------------------------- -鐗堟湰: RT-Thread v0.2.2 +# RT-Thread v0.2.2鏇存敼璇存槑 + 鍙戝竷鏃堕棿: 2008/6/12 + RT-Thread v0.2.2鍗曞唴鏍告寮忕増鍙戝竷锛岃繖涓増鏈富瑕佹槸澧炲姞鏇村鐨凚SP绉绘锛 - s3c44b0鐨勭Щ妞 [Xu Xinming] - AT91SAM7S64鐨勭Щ妞 [Bernard Xiong锛屾劅璋cdev.com.cn鎻愪緵寮鍙戞澘] @@ -1741,4 +1710,4 @@ AT91SAM7S64: (绯荤粺璧勬簮锛16k RAM锛64k ROM Flash) ia32: 鏀寔i386-elf-gcc for windows鐨勭紪璇戯紝linux涓嬬殑杩樻病璇曪紝搴旇涔熷彲浠ラ『鍒╃紪璇戙 缂栬瘧瀹屾垚鍚庡湪bsp/qemu鐩綍涓嬬敓鎴恟tthread-qemu.elf -鎶婅繖涓猠lf鏂囦欢閰嶇疆鍒癵rub鐨勯厤缃枃浠朵腑锛屽叿浣撶殑grub閰嶇疆璇峰弬鐪媑rub鏂囨。 \ No newline at end of file +鎶婅繖涓猠lf鏂囦欢閰嶇疆鍒癵rub鐨勯厤缃枃浠朵腑锛屽叿浣撶殑grub閰嶇疆璇峰弬鐪媑rub鏂囨。 From 1e3c79602d5089f1a707f425cdd5d455f83e6f2b Mon Sep 17 00:00:00 2001 From: cedar-renjun <819280802@qq.com> Date: Sat, 17 Oct 2015 20:58:42 +0800 Subject: [PATCH 34/36] Update board.h Use *.icf ram symbal, to avoid hardcode. --- bsp/stm32f40x/drivers/board.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/bsp/stm32f40x/drivers/board.h b/bsp/stm32f40x/drivers/board.h index 97b506c146..7f362503b0 100644 --- a/bsp/stm32f40x/drivers/board.h +++ b/bsp/stm32f40x/drivers/board.h @@ -37,8 +37,14 @@ // Internal SRAM memory size[Kbytes] <8-64> // Default: 64 +#ifdef __ICCARM__ +// Use *.icf ram symbal, to avoid hardcode. +extern char __ICFEDIT_region_RAM_end__; +#define STM32_SRAM_END &__ICFEDIT_region_RAM_end__ +#else #define STM32_SRAM_SIZE 128 #define STM32_SRAM_END (0x20000000 + STM32_SRAM_SIZE * 1024) +#endif // Console on USART: <0=> no console <1=>USART 1 <2=>USART 2 <3=> USART 3 // Default: 1 From f19d4381e49bfc894bbbe849198656f85d1fe15e Mon Sep 17 00:00:00 2001 From: cedar-renjun <819280802@qq.com> Date: Sat, 17 Oct 2015 21:01:41 +0800 Subject: [PATCH 35/36] Update stm32f40x_flash.icf Export the end address of ram, to avoid hard-code heap size in application --- bsp/stm32f40x/stm32f40x_flash.icf | 3 +++ 1 file changed, 3 insertions(+) diff --git a/bsp/stm32f40x/stm32f40x_flash.icf b/bsp/stm32f40x/stm32f40x_flash.icf index 8888d0e081..204f459388 100644 --- a/bsp/stm32f40x/stm32f40x_flash.icf +++ b/bsp/stm32f40x/stm32f40x_flash.icf @@ -8,6 +8,9 @@ define symbol __ICFEDIT_region_ROM_start__ = 0x08000000; define symbol __ICFEDIT_region_ROM_end__ = 0x0807FFFF; define symbol __ICFEDIT_region_RAM_start__ = 0x20000000; define symbol __ICFEDIT_region_RAM_end__ = 0x2001FFFF; /*STM32 F446RE*/ + +/*Export the end address of ram, to avoid hard-code heap size in application*/ +export symbol __ICFEDIT_region_RAM_end__; /*-Sizes-*/ define symbol __ICFEDIT_size_cstack__ = 0x200; define symbol __ICFEDIT_size_heap__ = 0x000; From 59681213320cba71f6d09517730d790d1d77b265 Mon Sep 17 00:00:00 2001 From: yuanbin Date: Fri, 23 Oct 2015 21:54:40 +0800 Subject: [PATCH 36/36] Thread: Make comments in more accurate way --- src/thread.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/thread.c b/src/thread.c index 6c0490a6a3..f94ad21a74 100644 --- a/src/thread.c +++ b/src/thread.c @@ -331,7 +331,7 @@ RTM_EXPORT(rt_thread_create); /** * This function will delete a thread. The thread object will be removed from - * thread queue and detached/deleted from system object management. + * thread queue and deleted from system object management in the idle thread. * * @param thread the thread to be deleted *