FreeRTOS

Started by tha, October 08, 2021, 08:24:01 AM

Previous topic - Next topic

tha

บางจุดที่ควรทราบ:

     •  ไม่ทุก the Demo/Common files ถูกใช้ในทุกๆ demonstration project. จำนวน files เท่าใดถูกใช้ขึ้นอยู่กับ processor resources.

     •  The demo projects มักจะใช้ the available RAM ทั้งหมดบน the target processor. นี้หมายความว่าคุณไม่สามารถเพิ่ม tasks เพิ่มเติมไปยัง the project
         โดยไม่มีประการแรกลบบางสิ่งออก! นี้ถูกต้องเป็นพิเศษสำหรับ the projects ที่กำหนดค่าให้รันบน the low end 8 and 16-bit processors.

     •  นอกเหนือจาก the standard demo projects, embedded web and FTP server projects ถูกจัดให้มี, ซึ่งจัดให้มีตัวอย่าง application ที่เน้นมากขึ้น.

     •  The standard demo project files ถูกจัดให้มีสำหรับจุดประสงค์ของการสาธิตการใช้ของ the RTOS kernel และไม่ได้มุ่งหมายเพื่อจัดให้มีการแก้ปัญหาที่เหมาะ
         สมที่สุด. นี้เป็นจริงอย่างยิ่งกับ comtest.c (ซึ่งใช้ an example UART driver), ซึ่งโดยทั่วไปถูกเขียนขึ้นโดยมีจุดประสงค์ของการเน้นย้ำ (และด้วยเหตุนี้จึงทำการ
         ทดสอบ) the RTOS kernel implementation แทนที่จะจัดให้มีตัวอย่างของการแก้ปัญหาที่เหมาะสมที่สุด.

The demo application ไม่ได้ปล่อยเป็นอิสระ resources ของมันทั้งหมดเมื่อมันออก, แม้ว่า the RTOS kernel จะทำ. นี้ถูกทำขึ้นอย่างหมดจดเพื่อลดบรรทัดของ code.

tha

https://www.freertos.org/simple-freertos-demos.html

Getting Started with Simple FreeRTOS Projects

[โปรดดู the Quick Start Guide and the hardware independent starter functions ที่จัดให้มี.]

Simply Blinky Projects

The most recent(ล่าสุด) FreeRTOS demos สามารถถูกกำหนดค่าเพื่อ build อย่างใดอย่างหนึ่ง a simple blinky starter application, หรือ a comprehensive test and demo application:

     1. Simple blinky demos

         Blinky demos ถูกมุ่งหมายสำหรับผู้เริ่มต้น. โดยปกติแล้วพวกเขาจะสร้างเพียงสอง tasks, หนึ่ง queue, และบางที่ก็มี a software timer ด้วย. ฟังชั่นของพวก
         มันถูกบรรจุไว้ใน a single C source file ที่เรียกว่า main_blinky.c.

     2. Comprehensive demos

         Comprehensive demos จะสาธิตและทดสอบ FreeRTOS features จำนวนมาก, รวมเอา tasks, direct to task notifications, queues, semaphores,
         recursive semaphores, software timers, และอื่นๆ. Comprehensive demos สร้าง tasks จำนวนมากและใช้ API functions จำนวนมาก, ดังนั้นไม่ขอ
         แนะนำสำหรับผู้เริ่มต้น.

แต่ละ official FreeRTOS project มี documentation page ของตัวเอง. The documentation page อธิบายวิธีกำหนดค่า the project เพือ build อย่างใดอย่างหนึ่ง the simply blinky demo หรือ the comprehensive demo, และอธิบายพฤติกรรมของทั้งสองทางเลือก.

หมายเหตุ: A project ที่ถูกกำหนดค่าเพื่อบิวด์ a simply blinky demo จะยังคงบิวด์ทุก the source files ที่ใช้โดย the comprehensive demo, ถึงแม้ว่า the simply blinky functionality ถูกบรรจุไว้ภายใน the single main_blinky.c source file. อ้างอิงถึง the Source Code Organisation และ Creating a New FreeRTOS Project pages สำหรับคำอธิบายของ the RTOS และ demo application source files.

tha

Try It Now, Using the Windows Port

ยังไม่มีฮาร์ดแวร์? ไม่ต้องกังวล - คุณสามารถรัน a simple blinky demo ใน a Windows environment โดยใช้ free tools และ the FreeRTOS Windows port, ถึงแม้ว่า the FreeRTOS Windows port จะไม่แสดง true real time behaviour.

หากคุณเป็นมือใหม่ อย่าเพิ่งอ่าน the main documentation page for the Windows demo yet, หรือให้ความสนใจกับ the comprehensive demo ที่สามารถถูกบิวด์โดย the same project (the comprehensive demo for the Windows port จะครอบคลุมมากเนื่องจากมันถูกใช้เป็น a development and test platform!) - เพียงแค่เริ่มต้นโดยการใช้คำแนะนำง่ายๆข้างล่างนี้:

     1. หากคุณยังไม่ได้ติดตั้ง ให้ดาวน์โหลดและติดตั้ง Microsoft Visual Studio เวอร์ชันฟรี

     2. หากคุณยังไม่ได้ดำเนินการดังกล่าว ให้ดาวน์โหลดและ unzip the official FreeRTOS distribution.

     3. สตาร์ท Visual Studio, จากนั้นใช้ the File|Open|Project/Solution menu item เพื่อเปิด the Win32.sln solution file, ซึ่งอยู่ใน the
         FreeRTOS/Demo/WIN32-MSVC directory of the official FreeRTOS distribution.

     4. ค้นหาการกำหนดของ mainCREATE_SIMPLE_BLINKY_DEMO_ONLY ที่ส่วนบนของ main.c, และทำให้แน่ใจว่ามันถูกเซ็ตเป็น 1.

     5. อ่าน the comments ที่ส่วนบนของ main_blinky.c, ก่อนการคอมไพล์และจากนั้นอย่างใดอย่างหนึ่ง debugging หรือ running the application.

(รูปให้ดูในลิ้งค์เอานะครับ)


tha

https://www.freertos.org/Hardware-independent-RTOS-example.html

Hardware independent FreeRTOS example

[โปรดดู the Quick Start Guide, and the Getting Started With Simple FreeRTOS Projects documentation page.]

Introduction

The RTOS download รวม example projects จำนวนมากที่ถูกกำหนดค่าไว้ล่วงหน้าเพื่อทำงาน "นอกกรอบ". ทั้งนี้เพื่อให้แน่ใจว่าผู้ใช้จะสามารถได้รับ a working RTOS project รันบน real hardware  ในเวลาที่สั้นที่สุด. อย่างไรก็ตาม เป็นไปไม่ได้ที่จะสนับสนุน microcontroller, compiler and development board ทุกชุดรวมกัน, และเรามักถูกขอให้ยกตัวอย่างที่ไม่อิงกับตัวแปรเหล่านี้. The code ที่จัดให้มีในหน้านี้ถูกจัดให้มีเพื่อวัตถุประสงค์นั้น. ความเรียบง่ายของ the code หมายถึงมันบริการเป็น a good starter project สำหรับผู้ที่ยังไม่คุ้นเคยกับ FreeRTOS อีกด้วย.

The source code ไม่เข้าถึง hardware specific IO ใดๆ. ตัวอย่างเช่น, มันเพียงเพิ่มค่าตัวแปรแทนที่จะพยายามสลับปิดเปิด an LED. อย่างไรก็ตาม, ไม่เหมือน the pre-packaged examples, มันต้องการให้ผู้ใช้สร้าง their own compiler project. ที่เกี่ยวข้องกับ:

     1. สตาร์ทด้วย a working (ไม่ใช่ RTOS) project เพื่อให้แน่ใจว่า the correct start up files และ linker scripts กำลังถูกใช้.

     2. รวม the correct RTOS source files. ใช้ existing official RTOS demo projects เป็นตัวอ้างอิง.

     3. การรวม the correct compiler include paths, ซึ่งต้องรวม the RTOS kernel header files (FreeRTOS/Source/include ใน the RTOS download)
         และ the portable layer header file (FreeRTOS/Source/[compiler]/[architecture]/portmacro.h ใน the RTOS download)

     4. การกำหนด a FreeRTOSConfig.h file - หรืออย่างน้อย - การก๊อปปี้ a FreeRTOSConfig.h จาก an official RTOS demo ที่ตรงกันอย่างใกล้เคียงกับ the
         project ที่กำลังถูกสร้าง.

ดู the Creating a New FreeRTOS Project documentation สำหรับข้อมูลเพิ่มเติม.

tha

Hardware Independent RTOS Demo Functionality

นี่คือคำอธิบายของฟังก์ชันของตัวอย่าง:

The main() Function

main() สร้าง the tasks และ software timers ทีอธิบายใน section นี้, ก่อนการสตาร์ท the scheduler.

The Queue Send task

The queue send task ถูกจัดให้มีใช้โดย the prvQueueSendTask() function. The task ใช้ the FreeRTOS vTaskDelayUntil() and xQueueSend() API functions เพื่อส่งตัวเลข 100 ไปบน a queue เป็นระยะๆ. คาบเวลาถูกเซ็ตเป็น 200ms. ดู the comments ใน the function สำหรับรายละเอียดเพิ่มเติม.

tha

The Queue Receive task

The queue receive task ถูกจัดให้มีใช้โดย the prvQueueReceiveTask() function. The task ใช้ the FreeRTOS xQueueReceive() API function เพื่อรับค่าจาก a queue. The values ที่รับคือเหล่านั้นที่ส่งโดย the queue send task. The queue receive task เพิ่ม the ulCountOfItemsReceivedOnQueue variable แต่ละครั้งที่มันรับค่า 100. ดังนั้น, ตามที่ค่าถูกส่งไปยัง the queue ทุกๆ 200ms, ค่าของ ulCountOfItemsReceivedOnQueue จะเพิ่มขึ้น 5 ทุกๆวินาที.

tha

An example software timer

A software timer ถูกสร้างขึ้นด้วย an auto reloading คาบเวลาที่ 1000ms. The timer's callback function เพิ่ม the ulCountOfTimerCallbackExecutions variable แต่ละครั้งที่มันถูกเรียก. ดังนั้นค่าของ ulCountOfTimerCallbackExecutions จะนับเป็นวินาที.

tha

The FreeRTOS RTOS tick hook (or callback) function

The tick hook function ปฏิบัติใน the context of the FreeRTOS tick interrupt. The function 'ให้' a semaphore ทุกๆ 500th ครั้งที่มันปฏิบัติ. The semaphore ถูกใช้เพื่อซิงโครไนส์กับ the event semaphore task, ซึ่งจะถูกอธิบายถัดไป. ในตัวอย่างนี้, the tick interrupt ถูกใช้ในการเลือก an interrupt ที่สร้างโดย a peripheral เพื่อให้แน่ใจว่า the hardware neutrality ถูกรักษา.