FreeRTOS

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

Previous topic - Next topic

tha

Common Problems and Solutions

Creating Threads

Problem

การสร้าง external threads ด้วย pthread_create (ตัวอย่างเช่น: การจำลอง interrupts) สามารถส่งผลต่อ FreeRTOS schedules tasks, เนื่องจาก the underlying RTOS port อาศัยการรับของ signals บางอย่างในการทำงาน. The created thread สามารถรับ the signal แทน ซึ่งเป็นเหตุให้ the scheduler ปล้น the thread จากจุดประสงค์ของมันเพื่อให้บริการกับ FreeRTOS specific tasks. นี้สามารถนำไปสู่การชนกันและแม้กระทั่งการหยุดชะงัก(ล็อคตาย).

Solution

เมื่อสร้าง a thread ด้วย pthread_create, signals ควรถูกบล็อกบน thread นั้นโดยการเพิ่มบางสิ่งต่อไปนี้ในเนื้อหาของ the thread:

sigset_t set;
sigfillset( &set );

pthread_sigmask( SIG_SETMASK, &set, NULL );

อีกทางหนึ่ง มีวิธีแก้ปัญหาที่ดีกว่า, แต่ non portable, แก้ปัญหาโดยการบล็อก signals ก่อนที่ the thread จะถูกสร้าง:

void * args;
sigset_t set;
pthread_t tid;
pthread_attr attr;

sigfillset( &set );
pthread_attr_init( &attr );
pthread_attr_setsigmask_np( &attr, &set );

pthread_create( &tid, &attr, start_routine, args );

tha

Creating new tasks

RTOS tasks ที่สร้างด้วย xTaskCreate() ส่งผ่าน their created stack ลงใน port.c เพื่อยอมให้ the pthread library ใช้ stack นั้นด้วย pthread_attr_setstack. A limitation มีอยู่สำหรับ the minimal stack size ที่สามารถถูกสร้าง. limitation นี้เป็น platform dependent และเท่ากันกับ PTHREAD_STACK_MIN. . ด้วยเหตุนี้, pthread_create() จะสร้าง stack ของตัวมันเองและจะไม่สนใจ the stack ที่ส่งผ่านโดย FreeRTOS. ไม่มีอะไรเลวร้ายจะเกิดขึ้นกับ the runtime system หากเกิดเหตุการณ์นี้ขึ้น, แต่ผู้ใช้บางรายที่ใช้ FreeRTOS debugging tools เพื่อแสดงข้อมูลสแต็กหรือตัวแปร FreeRTOS อื่น ๆ จะสังเกตเห็นความไม่สอดคล้องกันบางอย่าง.

วิธีแก้ปัญหา, ส่งผ่าน a stack ขนาด PTHREAD_STACK_MIN เสมอถ้า the desired stack น้อยกว่า PTHREAD_STACK_MIN เมื่อรันบน a Posix port.

tha

https://www.freertos.org/RTOS_ports.html

FreeRTOS Kernel Ports

ไม่เห็นความตรงกันจริงๆสำหรับ your microcontroller part number และ compiler vendor choice? demos เหล่านี้สามารถถูกปรับให้เข้ากับ microcontroller ใดๆภายใน a supported microcontroller family. ดู the Creating a new FreeRTOS application และ Adapting a FreeRTOS Demo documentation pages. เนื่องจาก IDEs จำนวนมากตอนนี้อิงตาม Eclipse, ดูหน้าที่อธิบายวิธีการใช้ virtual and linked paths ใน the Eclipse project explorer เพื่อให้แน่ใจว่าคุณไม่จำเป็ต้องก๊อปปี้y the RTOS source files ลงใน an Eclipse project directory.

FreeRTOS ports ถูกจัดประเภทเป็นอย่างใดอย่างหนึ่ง ถูกรองรับอย่างเป็นทางการ, หรือที่มีส่วนช่วย. The Official and Contributed Definitions page อธิบายหมวดหมู่และเหตุผลในการสร้างความแตกต่าง หน้านี้แสดงรายการพอร์ต RTOS อย่างเป็นทางการเท่านั้น:

(ตารางดูในลิ้งค์เอานะ สั้นๆแปลกันเอาเองนะครับ)


tha

https://www.freertos.org/a00090.html

Supported Demos
[Supported Devices]

ไม่เห็นความตรงกันจริงๆสำหรับ your microcontroller part number และ compiler vendor choice? demos เหล่านี้สามารถถูกปรับให้เข้ากับ microcontroller ใดๆภายใน a supported microcontroller family. ดู the Creating a new FreeRTOS application และ Adapting a FreeRTOS Demo documentation pages.

The 'Officially Supported' and 'Contributed' FreeRTOS Code page จัดให้มีคำอธิบายโดยละเอียดเกี่ยวกับความแตกต่างระหว่างที่รองรับอย่างเป็นทางการ, หรือที่มีส่วนช่วย FreeRTOS ports. Officially supported FreeRTOS demos ถูกจัดให้มีสำหรับ target microcontrollers จาก the following manufacturers:

(สั้นๆเลือกแปลเอาเองนะ บางตัวก็ไม่ได้ใช้ก็เลือกดูที่ใช้กันเอาเองนะครับ)

tha

https://www.freertos.org/a00102.html

FreeRTOS Demo Applications

Introduction

The RTOS source code download รวม a demonstration project สำหรับแต่ละ port. The sample projects ถูกกำหนดค่าล่วงหน้าเพื่อปฏิบัติบน the single board computer หรือ prototyping board ที่ใช้ในระหว่าง the port development. แต่ละควร build ได้โดยตรงตามที่ดาวน์โหลดมาโดยไม่มี warnings หรือ errors ใดๆ. ชุดของ hardware independent starter functions ถูกจัดให้มีอีกด้วย.

The demonstration projects ถูกจัดให้มีดังนี้:

     1. An aid to learning how to use FreeRTOS - แต่ละ source file แสดงให้เห็นถึงส่วนประกอบของ the RTOS.

     2. A preconfigured starting point for new applications - เพื่อให้แน่ใจว่า the correct development tool setup (compiler switches,
         debugger format, etc) ขอแนะนำว่า new applications ถูกสร้างโดย modifying the existing demo projects. เมื่อคุณมี the demo application
         กำลังรัน, ให้ถอด the demo functions and source files ออกทีละน้อยและแทนที่พวกมันด้วย application code ของตัวคุณเอง.

Locating a demo application

Every demo application ที่อยู่ใน a subdirectory ของ the FreeRTOS/Demo directory. ชื่อของแต่ละ subdirectory ดังกล่าวอธิบายการกำหนดค่าของ the demo application ที่มันบรรจุ. โปรดดู the FreeRTOS source code organization page สำหรับการอธิบายโดยละเอียดของ the FreeRTOS directory structure, และ the quick start guide สำหรับข้อมูลที่เป็นประโยชน์เพิ่มเติม.

Demo specific documentation

เว็บไซต์นี้บรรจุ a documentation page สำรหรับแต่ละ demo application ที่รวมใน the FreeRTOS download. หน้าเหล่านี้บรรจุหน้าข้อมูลที่มีค่าและประหยัดเวลา เช่น วิธีการตั้งค่าฮาร์ดแวร์และวิธีการบิวด์ the demo. การคลิกชื่อผู้ขายจะนำคุณไปยังรายการหน้าเอกสารเฉพาะสำหรับผู้ขายรายนั้น.

tha

The structure of a demo application

แต่ละ demo application สร้างชุดของ demo real time tasks และ/หรือ co-routines - ซึ่งส่วนใหญ่ไม่ได้เฉพาะเจาะจงไปยัง demo ใด demo หนึ่ง แต่จะทั่วไปถึงหลาย demo. tasks เหล่านี้ถูกสร้างภายใน main(), ซึ่งในทางกลับกันถูก defined ภายใน main.c. ตัวอย่างเช่น, the main() function สำหรับ the Luminary Micro LM3S811 GCC demo ถูกบรรจุไว้ภายใน FreeRTOS/Demo/CORTEX_LM3S811_GCC/main.c.

demos applications สร้าง a 'check' task ในรูปแบบใดรูปแบบหนึ่งอีกด้วย. The 'check' task จะดำเนินการไม่บ่อยนัก (โดยทั่วไปคือทุกๆ 3 หรือ 5 วินาที) แต่มี a high priority ดังนั้นถูกรับประกันได้ว่าจะได้รับ processor time. ความรับผิดชอบหลักของมันคือการตรวจสอบว่า tasks อื่นๆ ทั้งหมดยังคงทำงานตามที่คาดไว้, และไม่มี errors ถูกตรวจพบ. The check task จะรายงาน the system status อย่างใดอย่างหนึ่ง บน an LCD (ถ้ามี) หรือโดยการสลับ an LED.

A typical main() function จะมี the following structure:


tha

Partest.c - Accessing LEDs

demo applications จำนวนมากมีไฟล์ที่ชื่อ partest.c (ชื่อนี้มาจากประวัติศาสตร์และสูญเสียความหมายไป แต่มาจาก 'parallel port test'). The file บรรจุ the interface functions สำหรับ setting LEDs, clearing LEDs และ toggling LEDs. มีการกล่าวถึงที่นี่ด้วยเหตุผลสองประการ: ประการแรกเนื่องจากฟังก์ชันของไฟล์ไม่ชัดเจนจากชื่อของมัน และประการที่สองเนื่องจากการให้เอาต์พุต LED ทำงานเป็นปกติขั้นตอนแรกเมื่อย้ายการสาธิตจากแพลตฟอร์มฮาร์ดแวร์หนึ่งไปยังอีกแพลตฟอร์มหนึ่ง

tha

Demo application files

The files ที่จัดให้มีใช้ the tasks ที่ถูกใช้โดยทุก the demo applications จะอยู่ใน the FreeRTOS/Demo/Common/Minimal directory. The files ใน the FreeRTOS/Demo/Common/Full directory ไม่ถูกใช้อีกต่อไป, แต่ยังคงถูกแจกจ่ายเพื่อให้แน่ใจว่าตัวอย่างเก่ามากๆยังคงสามารถถูกบิวด์.

ข้อมูลพื้นฐานเกี่ยวกับ the common demo task ถูกจัดให้มี, แต่โปรดทราบว่า the documentation มักจะล้าสมัยเนื่องจาก new common demo tasks ถูกสร้างขึ้นบ่อยครั้ง. Demo task files ที่ถูกเพิ่มมาเร็วๆนี้มีแนวโน้มที่จะถูกออกแบบให้เฉพาะเจาะจงสำหรับการตรวจสอบมากว่าเพียงสำหรับการสาธิต, ดังนั้นจึงอาจซับซ้อนได้.