📄 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
*
* AT91SAM7SE512
*
* Filename : app.c
* Version : V1.00
* Programmer(s) : BAN
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* INCLUDE FILES
*********************************************************************************************************
*/
#include <includes.h>
/*
*********************************************************************************************************
* LOCAL DEFINES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL GLOBAL VARIABLES
*********************************************************************************************************
*/
/* ----------------- APPLICATION GLOBALS ------------------ */
static OS_STK AppTaskStartStk[APP_TASK_START_STK_SIZE];
static OS_STK AppTaskKbdStk[APP_TASK_KBD_STK_SIZE];
/* -------------- uC/PROBE RELATED GLOBALS ---------------- */
#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
#if (uC_PROBE_OS_PLUGIN > 0)
static CPU_INT32U Probe_Counts;
static CPU_BOOLEAN Probe_B1;
static CPU_BOOLEAN Probe_B2;
static CPU_BOOLEAN Probe_JoyUp;
static CPU_BOOLEAN Probe_JoyDown;
static CPU_BOOLEAN Probe_JoyLeft;
static CPU_BOOLEAN Probe_JoyRight;
#endif
/*
*********************************************************************************************************
* LOCAL FUNCTION PROTOTYPES
*********************************************************************************************************
*/
static void AppTaskStart (void *p_arg);
static void AppTaskCreate (void);
static void AppTaskKbd (void *p_arg);
#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 : 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.
*********************************************************************************************************
*/
void main (void)
{
CPU_INT08U err;
BSP_IntDisAll(); /* Disable all interrupts until we are ready to accept them */
OSInit(); /* Initialize "uC/OS-II, The Real-Time Kernel" */
OSTaskCreateExt(AppTaskStart, /* Create the start task */
(void *)0,
(OS_STK *)&AppTaskStartStk[APP_TASK_START_STK_SIZE - 1],
APP_TASK_START_PRIO,
APP_TASK_START_PRIO,
(OS_STK *)&AppTaskStartStk[0],
APP_TASK_START_STK_SIZE,
(void *)0,
OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);
#if (OS_TASK_NAME_SIZE > 13)
OSTaskNameSet(APP_TASK_START_PRIO, "Start Task", &err);
#endif
OSStart(); /* Start multitasking (i.e. give control to uC/OS-II) */
}
/*
*********************************************************************************************************
* AppTaskStart()
*
* Description : The startup task. The uC/OS-II ticker should only be initialize once multitasking starts.
*
* Argument(s) : p_arg Argument passed to 'AppTaskStart()' by 'OSTaskCreate()'.
*
* Return(s) : none.
*
* Note(s) : (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 starts because the I-bit of the CCR register was
* set to 0 by 'OSTaskCreate()'.
*********************************************************************************************************
*/
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)
(void)Probe_Counts;
(void)Probe_B1;
(void)Probe_B2;
(void)Probe_JoyUp;
(void)Probe_JoyDown;
(void)Probe_JoyLeft;
(void)Probe_JoyRight;
#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
AppTaskCreate();
while (DEF_TRUE) { /* Task body, always written as an infinite loop. */
OSTimeDlyHMSM(0, 0, 10, 0);
}
}
/*
*********************************************************************************************************
* AppTaskCreate()
*
* Description : Create the application tasks.
*
* Argument(s) : none.
*
* Return(s) : none.
*********************************************************************************************************
*/
static void AppTaskCreate (void)
{
CPU_INT08U err;
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
}
/*
*********************************************************************************************************
* AppTaskKbd()
*
* Description : Monitor the state of the push buttons and joystick.
*
* Argument(s) : p_arg Argument passed to 'AppTaskKbd()' by 'OSTaskCreate()'.
*
* Return(s) : none.
*
* Note(s) : (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 AppTaskKbd (void *p_arg)
{
CPU_INT08U status;
CPU_INT08U status_last_pb0;
CPU_INT08U status_last_pb1;
CPU_INT32U status_joystick;
CPU_INT32U status_last_joystick;
(void)p_arg;
status_last_pb0 = 0;
status_last_pb1 = 0;
status_last_joystick = JOYSTICK_NONE;
LED_Off(0); /* Turn OFF all the LEDs */
while (DEF_TRUE) { /* Task body, always written as an infinite loop. */
status = PB_GetStatus(1);
if (status == DEF_TRUE) {
if (status_last_pb0 == 0) {
status_last_pb0 = 1;
LED_Toggle(1);
}
} else {
status_last_pb0 = 0;
}
status = PB_GetStatus(2);
if (status == DEF_TRUE) {
if (status_last_pb1 == 0) {
status_last_pb1 = 1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -