📄 app.c
字号:
/*
*********************************************************************************************************
* uC/OS-II
* The Real-Time Kernel
*
* (c) Copyright 1998-2004, Micrium, Weston, FL
* All Rights Reserved
*
*
* ARM Sample code
*
* File : APP.C
* By : Jean J. Labrosse
*********************************************************************************************************
*/
#include <includes.h>
// P0.7为蜂鸣器的控制I/O
#define BEEP (1<<7)
// LED控制宏函数定义。LED1--LED4的控制I/O为P2.28--P2.31
#define LED_ADJ 28U
#define LED_IOCON (0xFF<<LED_ADJ)
#define LED_OFF() IO2SET=LED_IOCON
#define LED_DISP(dat) LED_OFF(); IO2CLR=((dat)<<LED_ADJ)
#define TaskStkLengh 64 //定义用户任务堆栈长度
OS_STK TaskStk0[TaskStkLengh]; //Define the Task0 stack 定义用户任务0的堆栈
OS_STK TaskStk1[TaskStkLengh]; //Define the Task1 stack 定义用户任务1的堆栈
void Task0(void *pdata); //Task0 任务0
void Task1(void *pdata); //Task0 任务1
/*
*********************************************************************************************************
* VARIABLES
*********************************************************************************************************
*/
OS_STK AppStartTaskStk[APP_TASK_STK_SIZE];
/*
*********************************************************************************************************
* FUNCTION PROTOTYPES
*********************************************************************************************************
*/
static void AppStartTask(void *p_arg);
/*
*********************************************************************************************************
* main()
*
* Description : This is the standard entry point for C code. It is assumed that your code will call
* main() once you have performed all necessary 68HC12 and C initialization.
* Arguments : none
*********************************************************************************************************
*/
void main (void)
{
INT8U err;
OSInit(); /* Initialize "uC/OS-II, The Real-Time Kernel" */
OSTaskCreateExt(AppStartTask,
(void *)0,
(OS_STK *)&AppStartTaskStk[APP_TASK_STK_SIZE - 1],
APP_TASK_START_PRIO,
APP_TASK_START_PRIO,
(OS_STK *)&AppStartTaskStk[0],
APP_TASK_STK_SIZE,
(void *)0,
OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);
#if OS_TASK_NAME_SIZE > 11
OSTaskNameSet(APP_TASK_START_PRIO, "Start Task", &err);
#endif
#if OS_TASK_NAME_SIZE > 14
OSTaskNameSet(OS_IDLE_PRIO, "uC/OS-II Idle", &err);
#endif
#if (OS_TASK_NAME_SIZE > 14) && (OS_TASK_STAT_EN > 0)
OSTaskNameSet(OS_STAT_PRIO, "uC/OS-II Stat", &err);
#endif
OSStart(); /* Start multitasking (i.e. give control to uC/OS-II) */
}
/*$PAGE*/
/*
*********************************************************************************************************
* STARTUP TASK
*
* Description : This is an example of a startup task. As mentioned in the book's text, you MUST
* initialize the ticker only once multitasking has started.
* Arguments : p_arg is the argument passed to 'AppStartTask()' by 'OSTaskCreate()'.
* Notes : 1) The first line of code is used to prevent a compiler warning because 'p_arg' is not
* used. The compiler should not generate any code for this statement.
* 2) Interrupts are enabled once the task start because the I-bit of the CCR register was
* set to 0 by 'OSTaskCreate()'.
*********************************************************************************************************
*/
static void AppStartTask (void *p_arg)
{
(void)p_arg;
BSP_Init(); /* Initialize BSP functions */
OSTaskCreate (Task0,(void *)0, &TaskStk0[TaskStkLengh - 1], 2);
#if OS_TASK_STAT_EN > 0
OSStatInit(); /* Determine CPU capacity */
#endif
while(1)
{
OSTimeDly(OS_TICKS_PER_SEC/2);
}
}
/*********************************************************************************************************
** Task0 任务0
********************************************************************************************************/
void Task0(void *pdata)
{ const INT8U DISP_TAB[24] = { 0x0F,0x00,0x0F,0x00,0x0F,0x00,0x0F,0x00,
0x01,0x02,0x04,0x08,0x04,0x02,0x01,0x00,
0x05,0x0A,0x05,0x0A,0x05,0x0A,0x05,0x00 };
INT8U i;
pdata = pdata;
PINSEL0 = 0x00000000; // 设置P0口管脚连接GPIO
IO0DIR = BEEP; // 设置蜂鸣器控制口为输出
IO0SET = BEEP;
IO2DIR = LED_IOCON; // 设置LED1--LED4的控制口为输出
LED_OFF();
// 建立任务1(用于蜂鸣器控制)
OSTaskCreate (Task1,(void *)0, &TaskStk1[TaskStkLengh - 1], 3);
while (1)
{ for(i=0; i<24; i++)
{ LED_DISP(DISP_TAB[i]); // 输出LED显示数据
OSTimeDly(OS_TICKS_PER_SEC/2); // 延时0.5S
}
}
}
/*********************************************************************************************************
** Task1 任务1
********************************************************************************************************/
void Task1(void *pdata)
{
pdata = pdata;
while (1)
{ OSTimeDly(OS_TICKS_PER_SEC*10); // 延时10S
IO0CLR = BEEP; // 控制蜂鸣器响
OSTimeDly(OS_TICKS_PER_SEC/2);
IO0SET = BEEP;
}
}
/*********************************************************************************************************
** End Of File
********************************************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -