FreeRTOS操作系统详解:实用实时内核指南

5星 · 超过95%的资源 需积分: 40 386 下载量 152 浏览量 更新于2024-07-21 11 收藏 3.19MB PDF 举报
"freeRTOS操作系统详解(中文版)—— 一篇详细介绍freeRTOS实时操作系统的文章,旨在为微控制器设计,由Richard Barry撰写,适合嵌入式开发,且免费。" FreeRTOS是一个轻量级的实时操作系统(RTOS),特别设计用于微控制器。它以其小巧、高效和开源的特点,在嵌入式系统领域广受欢迎。本文档提供了对FreeRTOS实时内核的实用指南,由Richard Barry撰写,中文版本在FreeRTOS中文网上可获取。 FreeRTOS的核心特性包括: 1. **任务管理**:FreeRTOS提供了一种创建和管理任务(即并发执行的线程)的方法。每个任务都有自己的堆栈,通过任务调度器实现上下文切换,确保系统能够根据优先级及时响应事件。 2. **优先级调度**:FreeRTOS支持抢占式调度,高优先级的任务可以中断正在运行的低优先级任务。任务的优先级可以动态调整,允许系统根据需要优化响应速度。 3. **信号量**:FreeRTOS提供不同类型的信号量,如二进制信号量、计数信号量和互斥信号量,用于在任务间同步和资源管理。 4. **队列**:任务间通信的一个重要机制是消息队列,允许数据结构安全地在任务间传递,确保数据完整性和一致性。 5. **定时器**:FreeRTOS提供软件定时器,可以在指定时间间隔触发回调函数,用于实现延时或周期性操作。 6. **内存管理**:FreeRTOS提供内存分配和释放功能,允许动态分配和回收内存,适应不同大小的内存需求。 7. **中断服务例程**:FreeRTOS能够处理中断请求,中断服务例程可以在中断发生时快速响应,并在完成后恢复被中断的任务。 8. **硬件抽象层**:FreeRTOS具有可移植性,因为它与底层硬件交互的接口是抽象的。这意味着FreeRTOS可以在各种微控制器平台上运行,只需适配相应的硬件抽象层。 9. **源码开放**:FreeRTOS是开放源码项目,用户可以自由查看、修改和分发代码,这促进了社区的协作和定制。 10. **小体积**:FreeRTOS设计紧凑,可以适应资源有限的微控制器,其占用的内存和处理器资源相对较少。 该文档的翻译者ZouChangjun提到,他翻译此文档的初衷是个人学习和分享,译文可能存在疏漏,但FreeRTOS中文网提供了一个平台,使得更多开发者可以接触到这一强大的操作系统。 通过阅读和理解这份文档,开发者可以学习如何在自己的嵌入式项目中有效地使用FreeRTOS,实现更高效的系统设计和任务调度,提高系统的实时性和可靠性。同时,FreeRTOS的开源特性鼓励开发者参与到系统改进和扩展中,以适应不断变化的嵌入式系统需求。
2018-11-18 上传
中文的参考手册 内容 Contents5..................................................................................................................................................... 列表 Figures8............................................................................................................................................... 代码清单 Listings9....................................................................................................................................... Tables15 名单.............................................................................................................................................. 列表 Notation15........................................................................................................................................... 章节 1 关于这............................................................................................................................. Manual16 1.1Scope17............................................................................................................................................. 章节 2Task 和调度........................................................................................................................... API20 2.1 portSWITCH_TO_USER_MODE() 21.................................................................................. 2.2 vTaskAllocateMPURegions() 22........................................................................................... 2.3 xTaskAbortDelay() 25............................................................................................................. 2.4 xTaskCallApplicationTaskHook() 27.................................................................................... 2.5 xTaskCheckForTimeOut() 30................................................................................................ 2.6 xTaskCreate() 32..................................................................................................................... 2.7 xTaskCreateStatic() 37........................................................................................................... 2.8 xTaskCreateRestricted() 41................................................................................................... 2.9 vTaskDelay() 46....................................................................................................................... 2.10 vTaskDelayUntil() 48............................................................................................................... 2.11 vTaskDelete() 51..................................................................................................................... 2.12 taskDISABLE_INTERRUPTS() 53........................................................................................ 2.13 taskENABLE_INTERRUPTS() 55......................................................................................... 2.14 taskENTER_CRITICAL() 56.................................................................................................. 2.15 taskENTER_CRITICAL_FROM_ISR() 59........................................................................... 2.16 taskEXIT_CRITICAL() 61....................................................................................................... 2.1 taskEXIT_CRITICAL_FROM_ISR() 63................................................................................ 2.2 xTaskGetApplicationTaskTag() 65....................................................................................... 2.3 xTaskGetCurrentTaskHandle() 67........................................................................................ 2.4 xTaskGetIdleTaskHandle() 68............................................................................................... 2.1 xTaskGetHandle() 69.............................................................................................................. 2.2 uxTaskGetNumberOfTasks() 71........................................................................................... 2.3 vTaskGetRunTimeStats() 72................................................................................................. 2.4 xTaskGetSchedulerState() 76...............................................................................................六 2.5 uxTaskGetStackHighWaterMark() 77.................................................................................. 2.6 eTaskGetState() 79................................................................................................................. 2.7 uxTaskGetSystemState() 81.................................................................................................. 2.8 vTaskGetTaskInfo() 85........................................................................................................... 2.9 pvTaskGetThreadLocalStoragePointer() 87.......................................................................7 2.10 pcTaskGetName() 89.............................................................................................................. 2.11 xTaskGetTickCount() 90........................................................................................................ 2.12 xTaskGetTickCountFromISR() 92........................................................................................ 2.13 vTaskList() 94........................................................................................................................... 2.14 xTaskNotify() 97....................................................................................................................... 2.15 xTaskNotifyAndQuery() 100.................................................................................................. 2.16 xTaskNotifyAndQueryFromISR() 104.................................................................................. 2.17 xTaskNotifyFromISR() 108.................................................................................................... 2.18 xTaskNotifyGive() 113............................................................................................................ 2.19 vTaskNotifyGiveFromISR() 116............................................................................................ 2.20 xTaskNotifyStateClear() 119.................................................................................................. 2.21 ulTask​ ​ NotifyTake() 121.................................................................................................. 2.22 xTaskNotifyWait() 124............................................................................................................ 2.23 uxTaskPriorityGet() 127.......................................................................................................... 2.24 vTaskPrioritySet() 129............................................................................................................ 2.25 vTaskResume() 131................................................................................................................ 2.26 xTaskResumeAll() 133........................................................................................................... 2.27 xTaskResumeFromISR() 136................................................................................................ 2.28 vTaskSetApplicationTaskTag() 139...................................................................................... 2.29 vTaskSetThreadLocalStoragePointer() 141........................................................................ 2.30 vTaskSetTimeOutState() 143................................................................................................ 2.31 vTaskStartScheduler() 145.................................................................................................... 2.32 vTaskStepTick() 147............................................................................................................... 2.33 vTaskSuspend() 149............................................................................................................... 2.34 vTaskSuspendAll() 151.......................................................................................................... 2.35 taskYIELD() 153...................................................................................................................... 章节 3Queue.................................................................................................................................. API155 3.1 vQueueAddToRegistry() 156................................................................................................. 3.2 xQueueAddToSet() 158.......................................................................................................... 3.3 xQueueCreate() 160............................................................................................................... 3.4 xQueueCreateSet() 162......................................................................................................... 3.5 xQueueCreateStatic() 166..................................................................................................... 3.6 vQueueDelete() 168................................................................................................................ 3.7 pcQueueGetName() 170........................................................................................................ 3.8 xQueueIsQueueEmptyFromISR() 171................................................................................. 3.9 xQueueIsQueueFullFromISR() 172...................................................................................... 3.10 uxQueueMessagesWaiting() 173.......................................................................................... 3.11 uxQueueMessagesWaitingFromISR() 174..........................................................................六 3.12 xQueueOverwrite() 176.......................................................................................................... 3.13 xQueueOverwriteFromISR() 178.......................................................................................... 3.14 xQueuePeek() 180.................................................................................................................. 3.15 xQueuePeekFromISR() 183.................................................................................................. 3.16 xQueueReceive() 184............................................................................................................. 3.17 xQueueReceiveFromISR() 187............................................................................................. 3.18 xQueueRemoveFromSet() 190............................................................................................. 3.19 xQueueReset() 192................................................................................................................. 3.20 xQueueSelectFromSet() 193................................................................................................. 3.21 xQueueSelectFromSetFromISR() 195................................................................................. 3.22 xQueueSend() , xQueueSendToFront() , xQueueSendToBack() 197............... 3.23 xQueueSendFromISR() , xQueueSendToBackFromISR() , xQueueSendToFrontFromISR() ............................................................200 3.24 uxQueueSpacesAvailable() 204............................................................................................ 章节 4Semaphore......................................................................................................................... API206 4.1 vSemaphoreCreateBinary() 207........................................................................................... 4.2 xSemaphoreCreateBinary() 210........................................................................................... 4.3 xSemaphoreCreateBinaryStatic() 213................................................................................. 4.4 xSemaphoreCreateCounting() 216....................................................................................... 4.5 xSemaphoreCreateCountingStatic() 219............................................................................. 4.6 xSemaphoreCreateMutex() 222............................................................................................ 4.7 xSemaphoreCreateMutexStatic() 224.................................................................................. 4.8 xSemaphoreCreateRecursiveMutex() 226.......................................................................... 4.9 xSemaphoreCreateRecursiveMutexStatic() 229................................................................ 4.10 vSemaphoreDelete() 231....................................................................................................... 4.11 uxSemaphoreGetCount() 232............................................................................................... 4.12 xSemaphoreGetMutexHolder() 233...................................................................................... 4.13 xSemaphoreGive() 234.......................................................................................................... 4.14 xSemaphoreGiveFromISR() 236.......................................................................................... 4.15 xSemaphoreGiveRecursive() 239......................................................................................... 4.16 xSemaphoreTake() 242.......................................................................................................... 4.17 xSemaphoreTakeFromISR() 245.......................................................................................... 4.18 xSemaphoreTakeRecursive() 247........................................................................................ 章节 5Software 定时器................................................................................................................. API251 5.1 xTimerChangePeriod() 252.................................................................................................... 5.2 xTimerChangePeriodFromISR() 255.................................................................................... 5.3 xTimerCreate() 257................................................................................................................. 5.4 xTimerCreateStatic() 261.......................................................................................................9 5.5 xTimerDelete() 265.................................................................................................................. 5.1 xTimerGetExpiryTime() ....................................................................................................267 5.1 pcTimerGetName() 269.......................................................................................................... 5.2 xTimerGetPeriod() 270........................................................................................................... 5.3 xTimerGetTimerDaemonTaskHandle() 271........................................................................ 5.4 pvTimerGetTimerID() 272...................................................................................................... 5.5 xTimerIsTimerActive() 274..................................................................................................... 5.6 xTimerPendFunctionCall() 276.............................................................................................. 5.7 xTimerPendFunctionCallFromISR() 278..............................................................................8 5.8 xTimerReset() 281................................................................................................................... 5.9 xTimerResetFromISR() 284................................................................................................... 5.10 vTimerSetTimerID() 286......................................................................................................... 5.11 xTimerStart() 288..................................................................................................................... 5.12 xTimerStartFromISR() 290..................................................................................................... 5.13 xTimerStop() 292..................................................................................................................... 5.14 xTimerStopFromISR() 294..................................................................................................... 章节 6Event 组............................................................................................................................... API296 6.1 xEventGroupClearBits() 297.................................................................................................. 6.2 xEventGroupClearBitsFromISR() 299.................................................................................. 6.3 xEventGroupCreate() 302...................................................................................................... 6.4 xEventGroupCreateStatic() 304............................................................................................ 6.1 vEventGroupDelete() 306...................................................................................................... 6.2 xEventGroupGetBits() 307..................................................................................................... 6.1 xEventGroupGetBitsFromISR() 308..................................................................................... 6.2 xEventGroupSetBits() 309..................................................................................................... 6.3 xEventGroupSetBitsFromISR() 311..................................................................................... 6.1 xEventGroupSync() 314......................................................................................................... 6.2 xEventGroupWaitBits() 318................................................................................................... 章节 7Kernel................................................................................................................. Configuration321 7.1 FreeRTOSConfig.h322............................................................................................................... 7.2 常量开始“INCLUDE_”...........................................................................................................323 7.3 常量开始“配置”.......................................................................................................................327 附录 1: 数据类型和编码样式.................................................................................................. Guide347