본문 바로가기
Study/Arduino

Arduino] FreeRTOS 포팅하기

by Answer Choi 2016. 11. 15.
반응형

Arduino에서 FreeRTOS는 라이브러리를 제공하기 때문에 쉽게 포팅할 수 있습니다.


아두이노용으로 몇가지 종류가 있지만 가장 쉽게 아두이노 공식라이브러리로 설치하는 방법입니다.


1. 라이브러리 추가하기



아두이노를 실행시켜 스케치->라이브러리 포함하기->라이브러리 관리... 를 눌러줍니다.



라이브러리 매니저가 나타나면 빨간 네모박스처럼 freertos를 검색합니다.


그리고 파란 네모박스 위치에 install이 나타나고, 


설치가 완료되면, 빨간 밑줄 그은곳이 installed로 바뀝니다.



다시 스케치->라이브러리 포함하기->FreeRTOS를 선택하면 관련 함수들이 자동으로 추가됩니다.


이제 이 상태에서 코딩을 하시면 됩니다.


기본 예제 소스입니다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include <Arduino_FreeRTOS.h>
#include <croutine.h>
#include <event_groups.h>
#include <FreeRTOSConfig.h>
#include <FreeRTOSVariant.h>
#include <list.h>
#include <mpu_wrappers.h>
#include <portable.h>
#include <portmacro.h>
#include <projdefs.h>
#include <queue.h>
#include <semphr.h>
#include <StackMacros.h>
#include <task.h>
#include <timers.h>
 
#define mainDELAY_LOOP_COUNT 400000
 
void setup() {
 Serial.begin(9600);
 
 
  /* Create one of the two tasks. */
  xTaskCreate(  vTask1,   /* Pointer to the function that implements the task. */
    "Task 1"/* Text name for the task.  This is to facilitate debugging only. */
    200,    /* Stack depth - most small microcontrollers will use much less stack than this. */
    NULL,   /* We are not using the task parameter. */
    1,      /* This task will run at priority 1. */
    NULL );   /* We are not using the task handle. */
 
  /* Create the other task in exactly the same way. */
  xTaskCreate( vTask2, "Task 2"200NULL1NULL );
 
  /* Start the scheduler so our tasks start executing. */
  vTaskStartScheduler();
 
  /* If all is well we will never reach here as the scheduler will now be
  running.  If we do reach here then it is likely that there was insufficient
  heap available for the idle task to be created. */
  for( ;; );
//  return 0;
}
/*-----------------------------------------------------------*/
 
void vTask1( void *pvParameters )
{
const char *pcTaskName = "Task 1 is running\r\n";
volatile unsigned long ul;
 
  /* As per most tasks, this task is implemented in an infinite loop. */
  for( ;; )
  {
    /* Print out the name of this task. */
    Serial.println( pcTaskName );
 
    /* Delay for a period. */
    for( ul = 0; ul < mainDELAY_LOOP_COUNT; ul++ )
    {
      /* This loop is just a very crude delay implementation.  There is
      nothing to do in here.  Later exercises will replace this crude
      loop with a proper delay/sleep function. */
    }
  }
}
/*-----------------------------------------------------------*/
 
void vTask2( void *pvParameters )
{
const char *pcTaskName = "Task 2 is running\r\n";
volatile unsigned long ul;
 
  /* As per most tasks, this task is implemented in an infinite loop. */
  for( ;; )
  {
    /* Print out the name of this task. */
    Serial.println( pcTaskName );
 
    /* Delay for a period. */
    for( ul = 0; ul < mainDELAY_LOOP_COUNT; ul++ )
    {
      /* This loop is just a very crude delay implementation.  There is
      nothing to do in here.  Later exercises will replace this crude
      loop with a proper delay/sleep function. */
    }
  }
}
cs


기본예제 실행모습입니다.



반응형

인기글