freeRTOS 是一个实时的内核,完全免费,即使你用做商用,并且可以配置成抢占式或者支持时间片的抢占式,不像ucosii,开源但是收费,而且只支持抢占式。
目标硬件平台平台:基于arm926ejs的SOC
IDE:CodeWarrior 5.7.0
debug:realdebug + jlink
freeRTOS 版本:V7.0.1
说明:此文档只关注OS的移植,不涉及目标板的boot的初始化配置(PLL MMU CACHE MEMORY...),以及demo\common 下驱动的实现。
1.)下载freeRTOS 源码
https://freertos.svn.sourceforge.net/svnroot/freertos/tags/V7.0.1 下载最新版
https://freertos.svn.sourceforge.net/svnroot/freertos 下载所有的版本,很大,不推荐。
2.)freeRTOS 目录结构
freeRTOS-
-Demo
-许多porting实例
-common
-License
-Source
-include 所有头文件
-portable 包含硬件相关的代码
-TraceCon
Demo 下面每个子目录对应每个porting的实例,子目录里包含了开发环境的工程目录,task 的实现,概括来说此目录存放APPLICATION 相关的文件。
子目录命名遵循一定的规则:CPUCORENAME_SOCNAME_COMPILERNAME.
common 目录下包含硬件驱动,文件系统,网络驱动等在具体平台上的实现。此文章不涉及。
Source 此目录下包含真正的OS kernel的source code.
include 下的头文件和 croutine.c list.c queue.c timers.c tasks.c 为硬件无关的代码,所有硬件平台都共享这些文件。
portable 下包含众多以compiler 命名的文件夹 比如codewarrior rvds等,以及MemMang目录,此目录下包含heap_1.c heap_2.c heap_3.c
实现了MEMORY 管理,具体porting的时候你只需要选择一个文件到IDE,否则会报重复定义的错误。
在以compiler命名的目录下又有一些以SOC名字命名的文件夹。 每个[compiler]目录下的[soc]目录对应着一个具体的porting实例。这些目录下都包含着
类似的文件,port.c portasm.s portmacro.h 有多有少,但是都是实现了硬件平台相关的代码。
3.) 开始移植。
#define configUSE_IDLE_HOOK 1 ///使用idle hook 函数,需要application 实现
#define configUSE_TICK_HOOK 1 ///使用tick hook 函数,需要application 实现
#define configCPU_CLOCK_HZ ( ( unsigned long ) 240000000 ) ///cpu clock 240M
#define configTICK_RATE_HZ ( ( portTickType ) 1 ) ///每秒tick数
#define configMAX_PRIORITIES ( ( unsigned portBASE_TYPE ) 4 )///优先级级数
#define configMINIMAL_STACK_SIZE ( ( unsigned short ) 90 ) ///栈大小
#define configTOTAL_HEAP_SIZE ( ( size_t ) 13 * 1024 ) ///堆大小
#define configMAX_TASK_NAME_LEN ( 8 ) ///task name的长度
#define configUSE_TRACE_FACILITY 0
#define configUSE_16_BIT_TICKS 0 ///对于32的cpu 都配置成0
#define configIDLE_SHOULD_YIELD 1 ///待研究:(
#define configQUEUE_REGISTRY_SIZE 0 ///待研究:(
/* Co-routine definitions. */ ///待研究:(
#define configUSE_CO_ROUTINES 0
#define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) ///待研究:(
/* Set the following definitions to 1 to include the API function, or zero
to exclude the API function. */
#define INCLUDE_vTaskPrioritySet 1
#define INCLUDE_uxTaskPriorityGet 1
#define INCLUDE_vTaskDelete 1
#define INCLUDE_vTaskCleanUpResources 0
#define INCLUDE_vTaskSuspend 1
#define INCLUDE_vTaskDelayUntil 1
#define INCLUDE_vTaskDelay 1
main.c 则实现了几个任务函数,hook函数,以及入口函数,每个任务都有下面的格式
static portTASK_FUNCTION( vTask1, pvParameters )
{
/* Calculate the LED and flash rate. */
for(;;)
{
portTickType xTickCount = xTaskGetTickCount();
printf("task1:%d\n",xTickCount);
/* Delay for half the flash period then turn the LED off. */
vTaskDelay( 4 );
#if configUSE_PREEMPTION == 0
taskYIELD();
#endif
}
}
在 source\portalbe 目录下创建CodeWarrior目录(如果已经有了,则不需要创建),在codeWarrior目录下创建xxxx(SOC名字) 在此目录下
创建了port.c portasm.s portmacro.h
portmacro.h:
#define portCHAR char
#define portFLOAT float
#define portDOUBLE double
#define portLONG long
#define portSHORT short
#define portSTACK_TYPE unsigned portLONG
#define portBASE_TYPE portLONG
#if( configUSE_16_BIT_TICKS == 1 )
目标硬件平台平台:基于arm926ejs的SOC
IDE:CodeWarrior 5.7.0
debug:realdebug + jlink
freeRTOS 版本:V7.0.1
说明:此文档只关注OS的移植,不涉及目标板的boot的初始化配置(PLL MMU CACHE MEMORY...),以及demo\common 下驱动的实现。
1.)下载freeRTOS 源码
https://freertos.svn.sourceforge.net/svnroot/freertos/tags/V7.0.1 下载最新版
https://freertos.svn.sourceforge.net/svnroot/freertos 下载所有的版本,很大,不推荐。
2.)freeRTOS 目录结构
freeRTOS-
-Demo
-许多porting实例
-common
-License
-Source
-include 所有头文件
-portable 包含硬件相关的代码
-TraceCon
Demo 下面每个子目录对应每个porting的实例,子目录里包含了开发环境的工程目录,task 的实现,概括来说此目录存放APPLICATION 相关的文件。
子目录命名遵循一定的规则:CPUCORENAME_SOCNAME_COMPILERNAME.
common 目录下包含硬件驱动,文件系统,网络驱动等在具体平台上的实现。此文章不涉及。
Source 此目录下包含真正的OS kernel的source code.
include 下的头文件和 croutine.c list.c queue.c timers.c tasks.c 为硬件无关的代码,所有硬件平台都共享这些文件。
portable 下包含众多以compiler 命名的文件夹 比如codewarrior rvds等,以及MemMang目录,此目录下包含heap_1.c heap_2.c heap_3.c
实现了MEMORY 管理,具体porting的时候你只需要选择一个文件到IDE,否则会报重复定义的错误。
在以compiler命名的目录下又有一些以SOC名字命名的文件夹。 每个[compiler]目录下的[soc]目录对应着一个具体的porting实例。这些目录下都包含着
类似的文件,port.c portasm.s portmacro.h 有多有少,但是都是实现了硬件平台相关的代码。
3.) 开始移植。
在Demo目录下创建ARM9_XXXX_CodeWarrior目录,添加了boot 代码,scatter 文件 以及FreeRTOSConfig.h和main.c
其中FreeRTOSConfig.h 来自demo中的arm7的实例,文件里重要配置了一些宏,代码如下:
#define configUSE_IDLE_HOOK 1 ///使用idle hook 函数,需要application 实现
#define configUSE_TICK_HOOK 1 ///使用tick hook 函数,需要application 实现
#define configCPU_CLOCK_HZ ( ( unsigned long ) 240000000 ) ///cpu clock 240M
#define configTICK_RATE_HZ ( ( portTickType ) 1 ) ///每秒tick数
#define configMAX_PRIORITIES ( ( unsigned portBASE_TYPE ) 4 )///优先级级数
#define configMINIMAL_STACK_SIZE ( ( unsigned short ) 90 ) ///栈大小
#define configTOTAL_HEAP_SIZE ( ( size_t ) 13 * 1024 ) ///堆大小
#define configMAX_TASK_NAME_LEN ( 8 ) ///task name的长度
#define configUSE_TRACE_FACILITY 0
#define configUSE_16_BIT_TICKS 0 ///对于32的cpu 都配置成0
#define configIDLE_SHOULD_YIELD 1 ///待研究:(
#define configQUEUE_REGISTRY_SIZE 0 ///待研究:(
/* Co-routine definitions. */ ///待研究:(
#define configUSE_CO_ROUTINES 0
#define configMAX_CO_ROUTINE_PRIORITIES ( 2 ) ///待研究:(
/* Set the following definitions to 1 to include the API function, or zero
to exclude the API function. */
#define INCLUDE_vTaskPrioritySet 1
#define INCLUDE_uxTaskPriorityGet 1
#define INCLUDE_vTaskDelete 1
#define INCLUDE_vTaskCleanUpResources 0
#define INCLUDE_vTaskSuspend 1
#define INCLUDE_vTaskDelayUntil 1
#define INCLUDE_vTaskDelay 1
main.c 则实现了几个任务函数,hook函数,以及入口函数,每个任务都有下面的格式
static portTASK_FUNCTION( vTask1, pvParameters )
{
/* Calculate the LED and flash rate. */
for(;;)
{
portTickType xTickCount = xTaskGetTickCount();
printf("task1:%d\n",xTickCount);
/* Delay for half the flash period then turn the LED off. */
vTaskDelay( 4 );
#if configUSE_PREEMPTION == 0
taskYIELD();
#endif
}
}
在 source\portalbe 目录下创建CodeWarrior目录(如果已经有了,则不需要创建),在codeWarrior目录下创建xxxx(SOC名字) 在此目录下
创建了port.c portasm.s portmacro.h
portmacro.h:
#define portCHAR char
#define portFLOAT float
#define portDOUBLE double
#define portLONG long
#define portSHORT short
#define portSTACK_TYPE unsigned portLONG
#define portBASE_TYPE portLONG
#if( configUSE_16_BIT_TICKS == 1 )