📄 app.c
字号:
/*
*********************************************************************************************************
* EXAMPLE CODE
*
* (c) Copyright 2003-2006; Micrium, Inc.; Weston, FL
*
* All rights reserved. Protected by international copyright laws.
* Knowledge of the source code may NOT be used to develop a similar product.
* Please help us continue to provide the Embedded community with the finest
* software available. Your honesty is greatly appreciated.
*********************************************************************************************************
*/
/*
*********************************************************************************************************
*
* EXAMPLE CODE
*
* ST Microelectronics STM32
* with the
* STM3210B-LK1 Evaluation Board
*
* Filename : app.c
* Version : V1.10
* Programmer(s) : BH3NVN
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* INCLUDE FILES
*********************************************************************************************************
*/
#include <includes.h>
#include "LCD.h"
/*
*********************************************************************************************************
* LOCAL DEFINES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL GLOBAL VARIABLES
*********************************************************************************************************
*/
static OS_STK App_TaskStartStk[APP_TASK_START_STK_SIZE];
static OS_STK App_TaskLCDStk[APP_TASK_LCD_STK_SIZE];
static OS_STK App_TaskKbdStk[APP_TASK_KBD_STK_SIZE];
static OS_STK App_TaskJoystickStk[APP_TASK_Joystick_STK_SIZE];
static OS_EVENT *InfoSem;
static OS_EVENT *Disp_Box;
static char *dp;
/*
*********************************************************************************************************
* LOCAL FUNCTION PROTOTYPES
*********************************************************************************************************
*/
static void App_TaskCreate (void);
static void App_DispScr_SignOn (void);
static void App_TaskStart (void *p_arg);
static void App_TaskLCD (void *p_arg);
static void App_TaskKbd (void *p_arg);
static void App_TaskJoystick (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 initialization.
*
* Argument(s) : none.
*
* Return(s) : none.
*********************************************************************************************************
*/
int main (void)
{
CPU_INT08U os_err;
BSP_IntDisAll(); /* Disable all ints until we are ready to accept them. */
OSInit(); /* Initialize "uC/OS-II, The Real-Time Kernel". */
BSP_Init(); /* Initialize BSP functions. */
lcdWrStr("uCOS");
App_DispScr_SignOn ();
printf("OS Init OK!\r\n");
os_err = OSTaskCreate((void (*)(void *)) App_TaskStart, /* Create the start task. */
(void * ) 0,
(OS_STK * )&App_TaskStartStk[APP_TASK_START_STK_SIZE - 1],
(INT8U ) APP_TASK_START_PRIO
);
printf("Creat App_TaskStart!\r\n");
#if (OS_TASK_NAME_SIZE >= 11)
OSTaskNameSet(APP_TASK_START_PRIO, (CPU_INT08U *)"Start Task", &os_err);
#endif
InfoSem = OSSemCreate(0);
Disp_Box = OSMboxCreate((void*)0);
OSTimeSet(0);
OSStart(); /* Start multitasking (i.e. give control to uC/OS-II). */
return (0);
}
/*
*********************************************************************************************************
* App_TaskStart()
*
* Description : The startup task. The uC/OS-II ticker should only be initialize once multitasking starts.
*
* Argument(s) : p_arg Argument passed to 'App_TaskStart()' by 'OSTaskCreate()'.
*
* Return(s) : none.
*
* Caller(s) : This is a task.
*
* Note(s) : none.
*********************************************************************************************************
*/
static void App_TaskStart (void *p_arg)
{
CPU_INT32U i;
CPU_INT32U j;
CPU_INT32U dly;
(void)p_arg;
OS_CPU_SysTickInit(); /* Initialize the SysTick. */
#if (OS_TASK_STAT_EN > 0)
OSStatInit(); /* Determine CPU capacity. */
#endif
App_TaskCreate();
while (DEF_TRUE) { /* Task body, always written as an infinite loop. */
for (j = 0; j < 4; j++) {
for (i = 1; i <= 4; i++) {
BSP_LED_On(i);
dly = (BSP_ADC_GetStatus(1) >> 4) + 2;
OSTimeDlyHMSM(0, 0, 0, dly);
BSP_LED_Off(i);
dly = (BSP_ADC_GetStatus(1) >> 4) + 2;
OSTimeDlyHMSM(0, 0, 0, dly);
}
for (i = 3; i >= 2; i--) {
BSP_LED_On(i);
dly = (BSP_ADC_GetStatus(1) >> 4) + 2;
OSTimeDlyHMSM(0, 0, 0, dly);
BSP_LED_Off(i);
dly = (BSP_ADC_GetStatus(1) >> 4) + 2;
OSTimeDlyHMSM(0, 0, 0, dly);
}
}
for (i = 0; i < 4; i++) {
BSP_LED_On(0);
dly = (BSP_ADC_GetStatus(1) >> 4) + 2;
OSTimeDlyHMSM(0, 0, 0, dly * 3);
BSP_LED_Off(0);
dly = (BSP_ADC_GetStatus(1) >> 4) + 2;
OSTimeDlyHMSM(0, 0, 0, dly * 3);
}
}
}
/*
*********************************************************************************************************
* App_TaskCreate()
*
* Description : Create the application tasks.
*
* Argument(s) : none.
*
* Return(s) : none.
*
* Caller(s) : App_TaskStart().
*
* Note(s) : none.
*********************************************************************************************************
*/
static void App_TaskCreate (void)
{
CPU_INT08U os_err;
os_err = OSTaskCreate((void (*)(void *)) App_TaskLCD,
(void * ) 0,
(OS_STK * )&App_TaskLCDStk[APP_TASK_LCD_STK_SIZE - 1],
(INT8U ) APP_TASK_LCD_PRIO
);
printf("Creat App_TaskLCD!\r\n");
#if (OS_TASK_NAME_SIZE >= 9)
OSTaskNameSet(APP_TASK_LCD_PRIO, "LCD", &os_err);
#endif
os_err = OSTaskCreate((void (*)(void *)) App_TaskKbd,
(void * ) 0,
(OS_STK * )&App_TaskKbdStk[APP_TASK_KBD_STK_SIZE - 1],
(INT8U ) APP_TASK_KBD_PRIO
);
printf("Creat App_TaskKbd!\r\n");
#if (OS_TASK_NAME_SIZE >= 9)
OSTaskNameSet(APP_TASK_KBD_PRIO, "KeyBoard", &os_err);
#endif
os_err = OSTaskCreate((void (*)(void *)) App_TaskJoystick,
(void * ) 0,
(OS_STK * )&App_TaskJoystickStk[APP_TASK_Joystick_STK_SIZE - 1],
(INT8U ) APP_TASK_Joystick_PRIO
);
printf("Creat App_TaskJoystick!\r\n");
#if (OS_TASK_NAME_SIZE >= 9)
OSTaskNameSet(APP_TASK_Joystick_PRIO, "Joystick", &os_err);
#endif
}
/*
*********************************************************************************************************
* App_TaskLCD()
*
* Description : The LCD Task
*
* Argument(s) : p_arg Argument passed to 'App_TaskLCD()' by 'OSTaskCreate()'.
*
* Return(s) : none.
*
* Caller(s) : This is a task.
*
* Note(s) : none.
*********************************************************************************************************
*/
static void App_TaskLCD (void *p_arg)
{
char buf[10];
INT8U err;
INT8U dsp=0;;
(void)p_arg;
lcdClr();
while (DEF_TRUE) {
dp=OSMboxPend(Disp_Box,10,&err);
if (err == OS_NO_ERR) {
dsp = (CPU_INT32U)dp;
}
switch (dsp){
case 1:{
sprintf(buf,"V%ld",OSVersion());
lcdWrStr(buf);
break;
}
case 2:{
sprintf(buf,"%4d",OSCPUUsage);
lcdWrStr(buf);
break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -