新闻中心

EEPW首页 > 嵌入式系统 > 设计应用 > 在pcDuino上学习μC/OS II

在pcDuino上学习μC/OS II

作者:时间:2016-09-12来源:网络收藏

前言

本文引用地址:http://www.eepw.com.cn/article/201609/303410.htm

uC/OS II(Micro Control Operation System Two)是一个可以基于ROM运行的、可裁减的、抢占式、实时多任务内核,具有高度可移植性,特别适合于微处理器和控制器,是和很多商业操作系统性能相当的实时操作系统(RTOS)。为了提供最好的移植性能,uC/OS II最大程度上使用ANSI C语言进行开发,并且已经移植到近40多种处理器体系上,涵盖了从8位到64位各种CPU(包括DSP)。 uC/OS II可以简单的视为一个多任务调度器,在这个任务调度器之上完善并添加了和多任务操作系统相关的系统服务,如信号量、邮箱等。其主要特点有公开源代码,代码结构清晰、明了,注释详尽,组织有条理,可移植性好,可裁剪,可固化。内核属于抢占式,最多可以管理60个任务。从1992年开始,由于高度可靠性、移植性和安全性,uC/OS II已经广泛使用在从照相机到航空电子产品的各种应用中。

想学习操作系统的同学的可以好好分析这个系统的代码

ucos下载编译

$sudo apt-get install git git-core

$git clone https://github.com/Pillar1989/ucos-ii-for-

$cd arduino

$make

$cd ..

$make

ucos-ii测试

编写测试程序:

1 /*

2 *************************************************************************************************** ******

3 * sample.c

4 *

5 * Description: This sample program uses the ucos linux port to start 5 simple tasks.

6 *

7 * Author: Philip Mitchell

8 *

9 *************************************************************************************************** ******

10 */

11

12 #include

13 #include

14 #include “ucos_ii.h”

15 #include

16 #include

17

18 int led_pin = 1;

19 int btn_pin = 5;

20

21 void hardware_init()

22 {

23 pinMode(led_pin, OUTPUT);

24 }

25 /* Function common to all tasks */

26

27 void MyTask( void *p_arg )

28 {

29

30 char* sTaskName = (char*)p_arg;

31 static flag1 = 1;

32 #if OS_CRITICAL_METHOD == 3

33 OS_CPU_SR cpu_sr = 0;

34 #endif

35

36 while(1)

37 {

38 /* printf uses mutex to get terminal access, therefore must enter critical section */

39 OS_ENTER_CRITICAL();

40 printf( “Name: %sn”, sTaskName );

41 if(!strcmp(sTaskName,”Task 1″))

42 {

43 if(flag1 == 1)

44 {

45 flag1 = 0;

46 printf(“HIGHn”);

47 digitalWrite(led_pin, HIGH);

48 }

49 else

50 {

51 flag1 = 1;

52 printf(“LOWn”);

53 digitalWrite(led_pin, LOW);

54 }

55 }

56 OS_EXIT_CRITICAL();

57

58 /* Delay so other tasks may execute. */

59 OSTimeDly(50);

60 }/* while */

61

62 }

63

64

65 int main (void)

66 {

67 /* pthreads allocates its own memory for task stacks. This UCOS linux port needs a minimum stack size

68 in order to pass the function information within the port. */

69 hardware_init();

70 INT8U Stk1[ OSMinStkSize() ];

71 INT8U Stk2[ OSMinStkSize() ];

72 INT8U Stk3[ OSMinStkSize() ];

73 INT8U Stk4[ OSMinStkSize() ];

74 INT8U Stk5[ OSMinStkSize() ];

75

76 char sTask1[] = “Task 1″;

77 char sTask2[] = “Task 2″;

78 char sTask3[] = “Task 3″;

79 char sTask4[] = “Task 4″;

80 // char sTask5[] = “Task 5″;

81

82 OSInit();

83

84 OSTaskCreate( MyTask, sTask1, (void*)Stk1, 4 );

85 // OSTaskCreate( MyTask, sTask2, (void*)Stk2, 5 );

86 // OSTaskCreate( MyTask, sTask3, (void*)Stk3, 6 );

87 // OSTaskCreate( MyTask, sTask4, (void*)Stk4, 7 );

88 // OSTaskCreate( MyTask, sTask5, (void*)Stk5, 8 );

89

90 OSStart();

91

92 return 0;

93 }

94

连接一个led灯到1脚,执行刚刚编译出来的程序

ubuntu@ubuntu:~/ucos-ii-for-$ ./ucos_sample

1Name: Task 1

HIGH

Name: Task 1

LOW

Name: Task 1

HIGH

Name: Task 1

LOW

Name: Task 1

板子上接到1 pin的led会不断的闪烁



关键词: pcDuino μC/OS II

评论


相关推荐

技术专区

关闭