Keil ARTX(Advanced Real-Time eXecutive)是Keil为ARM 系列所提供的一个小型实时操作系统,整合于其UV3开发环境之中.在下载并安装了RealView MDK个人学习版后,ARTX同时安装到了C:\Keil\ARM\RL\RTX目录下,在C:\Keil\ARM\Boards\Keil\MCBSTM32\STLIB_RTX_Blinky目录下有STM32的例子程序。经过简单修改,运行在万利开发板上。
#include <RTL.h>
#include <stm32f10x_lib.h>
OS_TID t_phaseA; /* assigned task id of task: phase_a */
OS_TID t_phaseB; /* assigned task id of task: phase_b */
OS_TID t_phaseC; /* assigned task id of task: phase_c */
OS_TID t_phaseD; /* assigned task id of task: phase_d */
#define LED_A GPIO_Pin_4
#define LED_B GPIO_Pin_5
#define LED_C GPIO_Pin_6
#define LED_D GPIO_Pin_7
#define LED_On(led) GPIO_SetBits(GPIOC, led)
#define LED_Off(led) GPIO_ResetBits(GPIOC, led)
/* Import functions from Setup.c */
extern void SetupClock (void);
extern void SetupLED (void);
/*----------------------------------------------------------------------------
* Task 1 'phaseA': Phase A output
*---------------------------------------------------------------------------*/
void phaseA (void) __task {
for (;;) {
LED_On (LED_A);
os_dly_wait (100);
LED_Off(LED_A);
os_dly_wait (100);
}
}
/*----------------------------------------------------------------------------
* Task 2 'phaseB': Phase B output
*---------------------------------------------------------------------------*/
void phaseB (void) __task {
for (;;) {
LED_On (LED_B);
os_dly_wait (100);
LED_Off(LED_B);
os_dly_wait (100);
}
}
/*----------------------------------------------------------------------------
* Task 3 'phaseC': Phase C output
*---------------------------------------------------------------------------*/
void phaseC (void) __task {
for (;;) {
LED_On (LED_C);
os_dly_wait (100);
LED_Off(LED_C);
os_dly_wait (100);
}
}
/*----------------------------------------------------------------------------
* Task 4 'phaseD': Phase D output
*---------------------------------------------------------------------------*/
void phaseD (void) __task {
for (;;) {
LED_On (LED_D);
os_dly_wait (100);
LED_Off(LED_D);
os_dly_wait (100);
}
}
/*----------------------------------------------------------------------------
* Task 8 'init': Initialize
*---------------------------------------------------------------------------*/
void init (void) __task {
t_phaseA = os_tsk_create (phaseA, 0); /* start task phaseA */
os_dly_wait (50);
t_phaseB = os_tsk_create (phaseB, 0); /* start task phaseB */
os_dly_wait (50);
t_phaseC = os_tsk_create (phaseC, 0); /* start task phaseC */
os_dly_wait (50);
t_phaseD = os_tsk_create (phaseD, 0); /* start task phaseD */
os_tsk_delete_self ();
}
/*----------------------------------------------------------------------------
* Main: Initialize and start RTX Kernel
*---------------------------------------------------------------------------*/
int main (void) {
SetupClock();
SetupLED ();
os_sys_init (init); /* Initialize RTX and start init */
}
/*----------------------------------------------------------------------------
* end of file
*---------------------------------------------------------------------------*/
经过初试化后,os_sys_init (init)启动了初试化任务。在初试化任务中,又先后启动了4个任务,启动后,删除初试化任务。这4个任务各自控制一个LED的开关。 |