📄 app.c
字号:
/*
*********************************************************************************************************
* EXAMPLE CODE
*
* (c) Copyright 2003-2007; 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
* IAR STM32-SK Evaluation Board
*
* Filename : app.c
* Version : V1.00
* Programmer(s) : Brian Nagel
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* INCLUDE FILES
*********************************************************************************************************
*/
#include <includes.h>
#define COEFFICIENT 2
CPU_INT16U MeterCount;
CPU_INT16U CircleCount1;
CPU_INT16U CircleCount2;
CPU_INT16U NowCircleCount1;
CPU_INT16U NowCircleCount2;
CPU_INT16U SureFlag;
/*
*********************************************************************************************************
* LOCAL DEFINES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL GLOBAL VARIABLES
*********************************************************************************************************
*/
/* ----------------- APPLICATION GLOBALS ------------------ */
static OS_STK AppTaskStartStk[APP_TASK_START_STK_SIZE];
static OS_STK AppTaskUserIFStk[APP_TASK_USER_IF_STK_SIZE];
static OS_STK AppTaskKbdStk[APP_TASK_KBD_STK_SIZE];
static OS_EVENT *AppUserIFMbox;
static CPU_CHAR AppLCDLine1[17];
static CPU_CHAR AppLCDLine2[17];
/* -------------- uC/PROBE RELATED GLOBALS ---------------- */
#if (uC_PROBE_OS_PLUGIN > 0)
volatile CPU_INT32U Probe_Counts;
volatile CPU_BOOLEAN Probe_B1;
volatile CPU_BOOLEAN Probe_B2;
volatile CPU_BOOLEAN Probe_B3;
volatile CPU_BOOLEAN Probe_B_WakeUp;
volatile CPU_INT16U Probe_ADC;
#endif
#if (uC_PROBE_COM_MODULE > 0) && \
(PROBE_COM_SUPPORT_STR > 0)
static OS_STK AppTaskProbeStrStk[APP_TASK_PROBE_STR_STK_SIZE];
#endif
#if (uC_PROBE_OS_PLUGIN > 0) && \
(uC_PROBE_COM_MODULE > 0) && \
(PROBE_COM_STAT_EN > 0)
static CPU_FP32 Probe_RS232RxSpd;
static CPU_FP32 Probe_RS232TxSpd;
static CPU_FP32 Probe_ComRxPktSpd;
static CPU_FP32 Probe_ComTxPktSpd;
static CPU_FP32 Probe_ComTxSymSpd;
static CPU_FP32 Probe_ComTxSymByteSpd;
static CPU_INT32U Probe_RS232RxLast;
static CPU_INT32U Probe_RS232TxLast;
static CPU_INT32U Probe_ComRxPktLast;
static CPU_INT32U Probe_ComTxPktLast;
static CPU_INT32U Probe_ComTxSymLast;
static CPU_INT32U Probe_ComTxSymByteLast;
static CPU_INT32U Probe_ComCtrLast;
#endif
void Exit_Init(void);
/*
*********************************************************************************************************
* LOCAL FUNCTION PROTOTYPES
*********************************************************************************************************
*/
static void AppTaskCreate (void);
static void AppTaskStart (void *p_arg);
#if (uC_LCD_MODULE > 0)
static void AppTaskUserIF (void *p_arg);
#endif
static void AppTaskKbd (void *p_arg);
#if (uC_LCD_MODULE > 0)
static void AppDispScr_WorkMode (void);
static void AppDispScr_InputMeter (void);
#endif
#if (uC_PROBE_OS_PLUGIN > 0)
static void AppProbeCallback (void);
#endif
#if (uC_PROBE_COM_MODULE > 0) && \
(PROBE_COM_SUPPORT_STR > 0)
static void AppTaskProbeStr (void *p_arg);
#endif
static void AppFormatDec (CPU_INT08U *s, CPU_INT32U value, CPU_INT08U digits);
/*
*********************************************************************************************************
* 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.
*
* Arguments : none
*
* Returns : none
*********************************************************************************************************
*/
int main (void)
{
/* Start multitasking (i.e. give control to uC/OS-II) */
}
/*
*********************************************************************************************************
* 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 'AppTaskStart()' by 'OSTaskCreate()'.
*
* Returns : none
*
* 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.
*********************************************************************************************************
*/
static void AppTaskStart (void *p_arg)
{
(void)p_arg;
BSP_Init(); /* Initialize BSP functions */
#if (OS_TASK_STAT_EN > 0)
OSStatInit(); /* Determine CPU capacity */
#endif
#if (uC_PROBE_COM_MODULE > 0)
ProbeCom_Init(); /* Initialize the uC/Probe communications module */
ProbeRS232_Init(115200);
ProbeRS232_RxIntEn();
#endif
#if (uC_PROBE_OS_PLUGIN > 0)
#if (uC_PROBE_COM_MODULE > 0) && \
(PROBE_COM_STAT_EN > 0)
(void)Probe_RS232RxSpd;
(void)Probe_RS232TxSpd;
(void)Probe_ComRxPktSpd;
(void)Probe_ComTxPktSpd;
(void)Probe_ComTxSymSpd;
(void)Probe_ComTxSymByteSpd;
(void)Probe_RS232RxLast;
(void)Probe_RS232TxLast;
(void)Probe_ComRxPktLast;
(void)Probe_ComTxPktLast;
(void)Probe_ComTxSymLast;
(void)Probe_ComTxSymByteLast;
(void)Probe_ComCtrLast;
#endif
OSProbe_Init();
OSProbe_SetCallback(AppProbeCallback);
OSProbe_SetDelay(50);
#endif
AppUserIFMbox = OSMboxCreate((void *)0); /* Create MBOX for communication between Kbd and UserIF */
Exit_Init();
AppTaskCreate(); /* Create application tasks */
LED_Off(0);
while (DEF_TRUE)
{
OSTaskSuspend ( APP_TASK_START_PRIO);
}
}
/*
*********************************************************************************************************
* CREATE APPLICATION TASKS
*
* Description: This function creates the application tasks.
*
* Arguments : none
*
* Returns : none
*********************************************************************************************************
*/
static void AppTaskCreate (void)
{
CPU_INT08U err;
#if (uC_LCD_MODULE > 0)
OSTaskCreateExt(AppTaskUserIF,
(void *)0,
(OS_STK *)&AppTaskUserIFStk[APP_TASK_USER_IF_STK_SIZE - 1],
APP_TASK_USER_IF_PRIO,
APP_TASK_USER_IF_PRIO,
(OS_STK *)&AppTaskUserIFStk[0],
APP_TASK_USER_IF_STK_SIZE,
(void *)0,
OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);
#if (OS_TASK_NAME_SIZE > 8)
OSTaskNameSet(APP_TASK_USER_IF_PRIO, "User I/F", &err);
#endif
#endif
OSTaskCreateExt(AppTaskKbd,
(void *)0,
(OS_STK *)&AppTaskKbdStk[APP_TASK_KBD_STK_SIZE - 1],
APP_TASK_KBD_PRIO,
APP_TASK_KBD_PRIO,
(OS_STK *)&AppTaskKbdStk[0],
APP_TASK_KBD_STK_SIZE,
(void *)0,
OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);
#if (OS_TASK_NAME_SIZE > 8)
OSTaskNameSet(APP_TASK_KBD_PRIO, "Keyboard", &err);
#endif
#if (uC_PROBE_COM_MODULE > 0) && \
(PROBE_COM_SUPPORT_STR > 0)
OSTaskCreateExt(AppTaskProbeStr,
(void *)0,
(OS_STK *)&AppTaskProbeStrStk[APP_TASK_PROBE_STR_STK_SIZE - 1],
APP_TASK_PROBE_STR_PRIO,
APP_TASK_PROBE_STR_PRIO,
(OS_STK *)&AppTaskProbeStrStk[0],
APP_TASK_PROBE_STR_STK_SIZE,
(void *)0,
OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);
#if (OS_TASK_NAME_SIZE > 9)
OSTaskNameSet(APP_TASK_PROBE_STR_PRIO, "Probe Str", &err);
#endif
#endif
}
/*
*********************************************************************************************************
* USER INTERFACE TASK
*
* Description : This task updates the LCD screen based on messages passed to it by AppTaskKbd().
*
* Arguments : p_arg is the argument passed to 'AppStartUserIF()' by 'OSTaskCreate()'.
*
* Returns : none
*********************************************************************************************************
*/
#if (uC_LCD_MODULE > 0)
static void AppTaskUserIF (void *p_arg)
{
CPU_INT08U *msg;
CPU_INT08U err;
CPU_INT32U nstate;
(void)p_arg;
DispInit(2, 16);
DispClrScr();
LCD_LightOn();
AppDispScr_InputMeter();
OSTimeDlyHMSM(0, 0, 1, 0);
nstate = 0;
while (DEF_TRUE)
{
msg = (CPU_INT08U *)(OSMboxPend(AppUserIFMbox, OS_TICKS_PER_SEC / 3, &err));
if (err == OS_NO_ERR)
{
nstate = (CPU_INT32U)msg;
}
if (nstate == 1)
{
nstate = 0;
MeterCount ++;
if (MeterCount >= 100)
{
MeterCount = 0;
}
AppDispScr_InputMeter();
}
else if (nstate == 2)
{
nstate = 0;
DispClrScr();
CircleCount1 = MeterCount * 40;
CircleCount2 = MeterCount * 40;
while (1)
{
msg = (CPU_INT08U *)(OSMboxPend(AppUserIFMbox, OS_TICKS_PER_SEC / 3, &err));
if (err == OS_NO_ERR)
{
nstate = (CPU_INT32U)msg;
}
if (nstate == 2)
{
nstate = 0;
MeterCount = 0;
NowCircleCount1 = 0;
NowCircleCount2 = 0;
GPIO_WriteBit(GPIOA,GPIO_Pin_6,Bit_SET);
GPIO_WriteBit(GPIOA,GPIO_Pin_7,Bit_SET);
AppDispScr_InputMeter();
break;
}
AppDispScr_WorkMode();
if (NowCircleCount1 > CircleCount1)
{
GPIO_WriteBit(GPIOA,GPIO_Pin_6,Bit_RESET);
}
if (NowCircleCount2 > CircleCount2)
{
GPIO_WriteBit(GPIOA,GPIO_Pin_7,Bit_RESET);
}
OSTimeDlyHMSM(0, 0, 0, 2);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -