AVR Development Arduino Method (Part 7) Embedded Operating System FreeRTOS

Publisher:HarmoniousDreamLatest update time:2019-12-06 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

FreeRTOS can provide functions such as task management, queue management, interrupt management, resource management and memory management. Because it takes up less resources, it can run on the Arduino UNO R3 development board.


You can download it from https://github.com/greiman/FreeRTOS-Arduino , unzip the FreeRTOS-Arduino-master.zip, and copy all the contents in the /FreeRTOS-Arduino-master/libraries folder to the libraries folder under the Arduino IDE installation directory. Here is the frBlink example it provides:


 1 // frBlink.ino

 2 #include AVR.h>

 3 

 4 const uint8_t LED_PIN = 13;

 5 SemaphoreHandle_t sem;

 6 

 7 static void Thread1(void* arg) {

 8   while (1) {

 9     xSemaphoreTake(sem, portMAX_DELAY);

10     digitalWrite(LED_PIN, LOW);

11   }

12 }

13 

14 static void Thread2(void* arg) {

15   pinMode(LED_PIN, OUTPUT);

16 

17   while (1) {

18     digitalWrite(LED_PIN, HIGH);

19     vTaskDelay((200L * configTICK_RATE_HZ) / 1000L);

20     xSemaphoreGive(sem);

21     vTaskDelay((200L * configTICK_RATE_HZ) / 1000L);

22   }

23 }

24 

25 void setup() {

26   portBASE_TYPE s1, s2;

27 

28   Serial.begin(9600);

29   

30   sem = xSemaphoreCreateCounting(1, 0);

31   s1 = xTaskCreate(Thread1, NULL, configMINIMAL_STACK_SIZE, NULL, 2, NULL);

32   s2 = xTaskCreate(Thread2, NULL, configMINIMAL_STACK_SIZE, NULL, 1, NULL);

33   if (sem== NULL || s1 != pdPASS || s2 != pdPASS ) {

34     Serial.println(F("Creation problem"));

35     while(1);

36   }

37 

38 vTaskStartScheduler();

39   Serial.println(F("Insufficient RAM"));

40   while(1);

41 }

42 

43 void loop() {

44 }


This example has the same effect as the Blink example, which demonstrates FreeRTOS's task creation, semaphores, and task sleep functions.


In addition to the 6 basic examples, an additional 16 examples are provided in the FreeRTOSBook folder; due to space constraints, please refer to these 22 examples or other books about FreeRTOS.


Reference address:AVR Development Arduino Method (Part 7) Embedded Operating System FreeRTOS

Previous article:AVR Development Arduino Method (VI) Memory Subsystem
Next article:AVR Development Arduino Method (Appendix 2) Troubleshooting: Burning the Bootloader

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号