FreeRTOS 基础简介

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

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

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

目录结构

# ls -l
total 28
drwx------ 5 pi pi 4096 Sep 16 04:17 FreeRTOS
drwx------ 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 FreeRTOS
total 28
drwx------ 166 pi pi 12288 Sep 16 04:17 Demo
drwx------   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.txt
drwx------   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.c
drwx------  2 pi pi   4096 Sep 16 04:17 include
-rwx------  1 pi pi  10993 May 20  2016 list.c
drwx------ 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/ -l
total 84
drwx------  3 pi pi 4096 Sep 16 04:17 BCC
drwx------  5 pi pi 4096 Sep 16 04:17 CCS
drwx------  5 pi pi 4096 Sep 16 04:17 CodeWarrior
drwx------  2 pi pi 4096 Sep 16 04:17 Common
drwx------ 37 pi pi 4096 Sep 16 04:17 GCC
drwx------ 25 pi pi 4096 Sep 16 04:17 IAR
drwx------  2 pi pi 4096 Sep 16 04:17 Keil
drwx------  2 pi pi 4096 Sep 16 04:17 MemMang
drwx------  3 pi pi 4096 Sep 16 04:17 MikroC
drwx------  7 pi pi 4096 Sep 16 04:17 MPLAB
drwx------  2 pi pi 4096 Sep 16 04:17 MSVC-MingW
drwx------  3 pi pi 4096 Sep 16 04:17 oWatcom
drwx------  3 pi pi 4096 Sep 16 04:17 Paradigm
-rwx------  1 pi pi  866 Feb 11  2016 readme.txt
drwx------  7 pi pi 4096 Sep 16 04:17 Renesas
drwx------  4 pi pi 4096 Sep 16 04:17 Rowley
drwx------  9 pi pi 4096 Sep 16 04:17 RVDS
drwx------  3 pi pi 4096 Sep 16 04:17 SDCC
drwx------  4 pi pi 4096 Sep 16 04:17 Softune
drwx------  3 pi pi 4096 Sep 16 04:17 Tasking
drwx------  3 pi pi 4096 Sep 16 04:17 WizC

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

# ls -l FreeRTOS/Demo/Common/
total 24
drwx------ 5 pi pi 4096 Sep 16 04:04 drivers
drwx------ 9 pi pi 4096 Sep 16 04:05 ethernet
drwx------ 2 pi pi 4096 Sep 16 04:06 Full
drwx------ 2 pi pi 4096 Sep 16 04:06 include
drwx------ 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

posted @ 2017-09-16 11:42  thomas_blog  阅读(387)  评论(0编辑  收藏  举报