📄 app.c
字号:
#include <includes.h>
static OS_STK App_TaskStartStk[APP_TASK_START_STK_SIZE];
#if (OS_VIEW_MODULE == DEF_ENABLED)
OS_STK TerminalTaskStk[APP_TASK_TERMINAL_STK_SIZE];
void TerminalTask(void *pdata);
void AppTerminalRx(CPU_INT08U rx_data);
CPU_INT08U AppTerminalRxMboxData = 0;
OS_EVENT *AppTerminalRxMbox;
#endif
static void App_TaskCreate (void);
static void App_EventCreate (void);
static void App_TaskStart (void *p_arg);
#if (APP_LCD_EN == DEF_ENABLED)
static void App_TaskUserIF (void *p_arg);
static void App_DispScr_SignOn (void);
static void App_DispScr_VersionTickRate(void);
static void App_DispScr_CPU (void);
static void App_DispScr_CtxSw (void);
static void App_DispScr_GPS (void);
#endif
INT32S main (void)
{
CPU_INT08U os_err;
#if 0
INT32U sdret, i;
INT8U buffer[512];
BSP_Init();
sdret = SD_Initialize();
printf("sdret=0x%02X\r\n", sdret);
if(!sdret) {
while(1) {
sdret = SD_ReadBlock(0, 512, buffer);
if(sdret) {
printf("sdret=0x%02X\r\n", sdret);
break;
}
OSTimeDly(1);
}
}
#endif
BSP_IntDisAll(); /* Disable all ints until we are ready to accept them. */
OSInit(); /* Initialize "uC/OS-II, The Real-Time Kernel". */
os_err = OSTaskCreateExt((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,
(INT16U ) APP_TASK_START_PRIO,
(OS_STK * )&App_TaskStartStk[0],
(INT32U ) APP_TASK_START_STK_SIZE,
(void * )0,
(INT16U )(OS_TASK_OPT_STK_CLR | OS_TASK_OPT_STK_CHK));
#if OS_TASK_NAME_EN > 0
OSTaskNameSet(APP_TASK_START_PRIO, (CPU_INT08U *)"Start Task", &os_err);
#endif
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_INT08U os_err;
INT32U count = 0, sdret, i;
INT8U buffer[512];
(void)p_arg;
BSP_Init(); /* Initialize BSP functions. */
OS_CPU_SysTickInit(); /* Initialize the SysTick. */
#if (OS_TASK_STAT_EN > 0)
OSStatInit(); /* Determine CPU capacity. */
#endif
#if (GPS_MODULE == DEF_ENABLED)
GPS_Init(); /* GPS Init */
GPS_RxIntEn(); /* Enable Rx Interrupts */
#endif
#if (OS_VIEW_MODULE == DEF_ENABLED)
OSView_Init(115200); /* OSView Init, baud rate = 115200 */
OSView_TerminalRxSetCallback(AppTerminalRx);
OSView_RxIntEn(); /* Enable Rx Interrupts */
AppTerminalRxMbox = OSMboxCreate((void *)0);
#endif
App_EventCreate(); /* Create application events. */
App_TaskCreate(); /* Create application tasks. */
sdret = SD_Initialize();
printf("sdret=0x%02X\r\n", sdret);
if(!sdret) {
while(1) {
sdret = SD_ReadBlock(0, 512, buffer);
if(sdret) {
printf("sdret=0x%02X\r\n", sdret);
break;
}
OSTimeDly(1);
}
}
BSP_LED_Off(2);
while (DEF_TRUE) { /* Task body, always written as an infinite loop. */
count++;
if(count % 25 == 0) {
BSP_LED_Toggle(2);
}
OSTimeDlyHMSM(0, 0, 0, 10);
}
}
/*
*********************************************************************************************************
* App_EventCreate()
*
* Description : Create the application events.
*
* Argument(s) : none.
*
* Return(s) : none.
*
* Caller(s) : App_TaskStart().
*
* Note(s) : none.
*********************************************************************************************************
*/
static void App_EventCreate (void)
{
#if (OS_EVENT_NAME_SIZE > 12)
CPU_INT08U os_err;
#endif
App_ADCSem = OSSemCreate(0); /* Create MBOX for communication between Kbd and UserIF.*/
#if (OS_EVENT_NAME_SIZE > 12)
OSEventNameSet(App_ADCSem, "ADC Sem", &os_err);
#endif
}
/*
*********************************************************************************************************
* 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;
#if (OS_VIEW_MODULE == DEF_ENABLED)
os_err = OSTaskCreateExt((void (*)(void *)) TerminalTask,
(void * ) 0,
(OS_STK * )&TerminalTaskStk[APP_TASK_TERMINAL_STK_SIZE - 1],
(INT8U ) APP_TASK_TERMINAL_PRIO,
(INT16U ) APP_TASK_TERMINAL_PRIO,
(OS_STK * )&TerminalTaskStk[0],
(INT32U ) APP_TASK_TERMINAL_STK_SIZE,
(void * ) 0,
(INT16U )(OS_TASK_OPT_STK_CLR | OS_TASK_OPT_STK_CHK));
#if OS_TASK_NAME_EN > 0
OSTaskNameSet(APP_TASK_TERMINAL_PRIO, "Terminal Task", &os_err);
#endif
#endif
}
/*
*********************************************************************************************************
* AppTerminalRx()
*
* Description : Callback function for uC/OS-View
*
* Argument(s) : rx_data The received data.
*
* Return(s) : none.
*********************************************************************************************************
*/
#if (OS_VIEW_MODULE == DEF_ENABLED)
void AppTerminalRx (CPU_INT08U rx_data)
{
AppTerminalRxMboxData = rx_data;
OSMboxPost(AppTerminalRxMbox, &AppTerminalRxMboxData);
}
#endif
/*
*********************************************************************************************************
*********************************************************************************************************
* uC/OS-II APP HOOKS
*********************************************************************************************************
*********************************************************************************************************
*/
#if (OS_APP_HOOKS_EN > 0)
/*
*********************************************************************************************************
* TASK CREATION HOOK (APPLICATION)
*
* Description : This function is called when a task is created.
*
* Argument(s) : ptcb is a pointer to the task control block of the task being created.
*
* Note(s) : (1) Interrupts are disabled during this call.
*********************************************************************************************************
*/
void App_TaskCreateHook (OS_TCB *ptcb)
{
#if (OS_VIEW_MODULE == DEF_ENABLED)
OSView_TaskCreateHook(ptcb);
#endif
}
/*
*********************************************************************************************************
* TASK DELETION HOOK (APPLICATION)
*
* Description : This function is called when a task is deleted.
*
* Argument(s) : ptcb is a pointer to the task control block of the task being deleted.
*
* Note(s) : (1) Interrupts are disabled during this call.
*********************************************************************************************************
*/
void App_TaskDelHook (OS_TCB *ptcb)
{
(void)ptcb;
}
/*
*********************************************************************************************************
* IDLE TASK HOOK (APPLICATION)
*
* Description : This function is called by OSTaskIdleHook(), which is called by the idle task. This hook
* has been added to allow you to do such things as STOP the CPU to conserve power.
*
* Argument(s) : none.
*
* Note(s) : (1) Interrupts are enabled during this call.
*********************************************************************************************************
*/
#if OS_VERSION >= 251
void App_TaskIdleHook (void)
{
}
#endif
/*
*********************************************************************************************************
* STATISTIC TASK HOOK (APPLICATION)
*
* Description : This function is called by OSTaskStatHook(), which is called every second by uC/OS-II's
* statistics task. This allows your application to add functionality to the statistics task.
*
* Argument(s) : none.
*********************************************************************************************************
*/
void App_TaskStatHook (void)
{
}
/*
*********************************************************************************************************
* TASK SWITCH HOOK (APPLICATION)
*
* Description : This function is called when a task switch is performed. This allows you to perform other
* operations during a context switch.
*
* Argument(s) : none.
*
* Note(s) : (1) Interrupts are disabled during this call.
*
* (2) It is assumed that the global pointer 'OSTCBHighRdy' points to the TCB of the task that
* will be 'switched in' (i.e. the highest priority task) and, 'OSTCBCur' points to the
* task being switched out (i.e. the preempted task).
*********************************************************************************************************
*/
#if OS_TASK_SW_HOOK_EN > 0
void App_TaskSwHook (void)
{
#if (OS_VIEW_MODULE == DEF_ENABLED)
OSView_TaskSwHook();
#endif
}
#endif
/*
*********************************************************************************************************
* OS_TCBInit() HOOK (APPLICATION)
*
* Description : This function is called by OSTCBInitHook(), which is called by OS_TCBInit() after setting
* up most of the TCB.
*
* Argument(s) : ptcb is a pointer to the TCB of the task being created.
*
* Note(s) : (1) Interrupts may or may not be ENABLED during this call.
*********************************************************************************************************
*/
#if OS_VERSION >= 204
void App_TCBInitHook (OS_TCB *ptcb)
{
(void)ptcb;
}
#endif
/*
*********************************************************************************************************
* TICK HOOK (APPLICATION)
*
* Description : This function is called every tick.
*
* Argument(s) : none.
*
* Note(s) : (1) Interrupts may or may not be ENABLED during this call.
*********************************************************************************************************
*/
#if OS_TIME_TICK_HOOK_EN > 0
void App_TimeTickHook (void)
{
#if (OS_VIEW_MODULE == DEF_ENABLED)
OSView_TickHook();
#endif
}
#endif
#endif
#if (OS_VIEW_MODULE == DEF_ENABLED)
void TerminalTask(void *pdata)
{
INT8U s[100];
INT8U *key;
INT8U err;
(void)pdata;
/* Prevent compiler warning */
while (1) {
key = (INT8U *)OSMboxPend(AppTerminalRxMbox, 0, &err);
switch (*key) {
case '1':
sprintf((char *)s, "\nCPU Usage = %3u%%\n", OSCPUUsage);
OSView_TxStr(s, 1);
break;
case '2':
sprintf((char *)s, "\n#Tasks = %3u\n", OSTaskCtr);
OSView_TxStr(s, 1);
break;
default:
OSView_TxStr("\n\nMicrium, Inc.", 1);
OSView_TxStr("\n1: CPU Usage (%)", 1);
OSView_TxStr("\n2: #Tasks", 1);
OSView_TxStr("\n?: Help (This menu)\n", 1);
break;
}
}
}
#endif
#ifdef DEBUG
/******************************************************************
* Function name : assert_failed
* Description : Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* Input : - file: pointer to the source file name
* - line: assert_param error line source number
* Output : None * Return : None
******************************************************************/
void assert_failed(u8* file, u32 line) {
printf("Wrong parameters value: file %s on line %d\r\n", file, line);
while (1) { }
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -