FreeRTOS 基础简介

来源:互联网 发布:林原惠美 知乎 编辑:程序博客网 时间:2024/06/08 10:41

为什么选择FreeRTOS
UCOS资料多,尤其是中文资料。FreeRTOS资料少,而且大多数是英文的。原因如下:

1.FreeRTOS免费!UCOS收费。这是主要原因
2.很多半导体厂商,采用FreeRTOS作为其操作系统
3.FreeRTOS文件数量少

下载地址
http://www.freertos.org/

目录结构

# ls -ltotal 28drwx------ 5 pi pi 4096 Sep 16 04:17 FreeRTOSdrwx------ 4 pi pi 4096 Sep 16 04:18 FreeRTOS-Plus-rwx------ 1 pi pi  141 Jan 16  2015 New - Direct to Task Notifications.url-rwx------ 1 pi pi  155 Dec 21  2014 New - FreeRTOS+TCP.url-rwx------ 1 pi pi  144 Sep 17  2013 Quick_Start_Guide.url-rwx------ 1 pi pi 1468 Sep 17  2013 readme.txt-rwx------ 1 pi pi  129 Feb 19  2016 Upgrading-to-FreeRTOS-9.url

FreeRTOS-Plus:包含FreeRTOS+组件和演示例程
FreeRTOS:包含FreeRTOS实时内核源文件和演示例程

# ls -l FreeRTOStotal 28drwx------ 166 pi pi 12288 Sep 16 04:17 Demodrwx------   2 pi pi  4096 Sep 16 04:17 License-rwx------   1 pi pi   124 Oct 30  2014 links_to_doc_pages_for_the_demo_projects.url-rwx------   1 pi pi   912 Sep 17  2013 readme.txtdrwx------   4 pi pi  4096 Sep 16 04:17 Source

Demo:演示例程
License:许可信息
Source:实时内核源文件

# ls -l FreeRTOS/Source/total 352-rwx------  1 pi pi  15771 May 20  2016 croutine.c-rwx------  1 pi pi  26251 May 20  2016 event_groups.cdrwx------  2 pi pi   4096 Sep 16 04:17 include-rwx------  1 pi pi  10993 May 20  2016 list.cdrwx------ 22 pi pi   4096 Sep 16 04:17 portable-rwx------  1 pi pi  83729 May 20  2016 queue.c-rwx------  1 pi pi    822 Sep 17  2013 readme.txt-rwx------  1 pi pi 157816 May 20  2016 tasks.c-rwx------  1 pi pi  41115 May 20  2016 timers.c

tasks.c、queue.c、list.c:核心文件
timers.c、event_groups.c、croutine.c:可选文件
include:内核代码头文件
portable:处理器特定代码

# ls FreeRTOS/Source/portable/ -ltotal 84drwx------  3 pi pi 4096 Sep 16 04:17 BCCdrwx------  5 pi pi 4096 Sep 16 04:17 CCSdrwx------  5 pi pi 4096 Sep 16 04:17 CodeWarriordrwx------  2 pi pi 4096 Sep 16 04:17 Commondrwx------ 37 pi pi 4096 Sep 16 04:17 GCCdrwx------ 25 pi pi 4096 Sep 16 04:17 IARdrwx------  2 pi pi 4096 Sep 16 04:17 Keildrwx------  2 pi pi 4096 Sep 16 04:17 MemMangdrwx------  3 pi pi 4096 Sep 16 04:17 MikroCdrwx------  7 pi pi 4096 Sep 16 04:17 MPLABdrwx------  2 pi pi 4096 Sep 16 04:17 MSVC-MingWdrwx------  3 pi pi 4096 Sep 16 04:17 oWatcomdrwx------  3 pi pi 4096 Sep 16 04:17 Paradigm-rwx------  1 pi pi  866 Feb 11  2016 readme.txtdrwx------  7 pi pi 4096 Sep 16 04:17 Renesasdrwx------  4 pi pi 4096 Sep 16 04:17 Rowleydrwx------  9 pi pi 4096 Sep 16 04:17 RVDSdrwx------  3 pi pi 4096 Sep 16 04:17 SDCCdrwx------  4 pi pi 4096 Sep 16 04:17 Softunedrwx------  3 pi pi 4096 Sep 16 04:17 Taskingdrwx------  3 pi pi 4096 Sep 16 04:17 WizC

Keil、RVDS:使用MDK环境编译所需要的文件
MemMang:内存管理,堆栈实现

# ls -l FreeRTOS/Demo/Common/total 24drwx------ 5 pi pi 4096 Sep 16 04:04 driversdrwx------ 9 pi pi 4096 Sep 16 04:05 ethernetdrwx------ 2 pi pi 4096 Sep 16 04:06 Fulldrwx------ 2 pi pi 4096 Sep 16 04:06 includedrwx------ 2 pi pi 4096 Sep 16 04:06 Minimal-rwx------ 1 pi pi  737 Mar 29  2016 ReadMe.txt

Common:演示例程

测试Demo
替换原有main函数,测试LED闪烁

int main( void ){    volatile unsigned long ul; /* volatile so it is not optimized away. */    prvSetupHardware(); //时钟设置    vParTestInitialise(); //gpio初始化    /* Toggle the LEDs repeatedly. */    for( ;; )    {        /* We don't want to use the RTOS features yet, so just use a very        crude delay mechanism instead. */        for( ul = 0; ul < 0xfffff; ul++ )        {        }        /* Toggle the first four LEDs (on the assumption there are at least        4 fitted. */        vParTestToggleLED( 0 );        vParTestToggleLED( 1 );        vParTestToggleLED( 2 );        vParTestToggleLED( 3 );    }    return 0;}

RTOS调度器
LED不同频率的闪烁

int main( void ){   /* Setup the microcontroller hardware for the demo. */   prvSetupHardware();   vStartLEDFlashTasks( mainFLASH_TASK_PRIORITY );   /* All other functions that create tasks are commented out.      vCreatePollQTasks();      vCreateComTestTasks();      Etc.      xTaskCreate( vCheckTask, "check", STACK_SIZE, NULL, TASK_PRIORITY, NULL );   */   /* Start the RTOS scheduler. */   vTaskStartScheduler();   /* Should never get here! */   return 0;}

参考:http://www.freertos.org/porting-a-freertos-demo-to-different-hardware.html

原创粉丝点击