?? app.c
字號:
/*
*********************************************************************************************************
* uC/OS-II
* The Real-Time Kernel
*
* (c) Copyright 1998-2005, Micrium, Weston, FL
* All Rights Reserved
*
*
* ARM Sample code
*
* File : APP.C
* By : Jean J. Labrosse
*********************************************************************************************************
*/
#include <includes.h>
/*
*********************************************************************************************************
* VARIABLES
*********************************************************************************************************
*/
OS_STK AppTaskStartStk[APP_TASK_START_STK_SIZE];
OS_STK AppTaskUserIFStk[APP_TASK_USER_IF_STK_SIZE];
CPU_INT08U AppUserIFState; /* User I/F state */
/*
*********************************************************************************************************
* FUNCTION PROTOTYPES
*********************************************************************************************************
*/
static void AppTaskCreate(void);
static void AppTaskStart(void *p_arg);
static void AppTaskUserIF(void *p_arg);
#if OS_VIEW_MODULE > 0
static void AppTerminalRx(INT8U rx_data);
#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 68HC12 and C initialization.
* Arguments : 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, "Startup", &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 AppTaskStart (void *p_arg)
{
(void)p_arg;
BSP_Init(); /* Initialize BSP functions */
#if OS_TASK_STAT_EN > 0
OSStatInit(); /* Determine CPU capacity */
#endif
#if OS_VIEW_MODULE > 0
OSView_Init(38400);
OSView_TerminalRxSetCallback(AppTerminalRx);
OSView_RxIntEn(); /* Enable Rx Interrupts */
#endif
LED_Off(0); /* Turn OFF all the LEDs */
AppTaskCreate(); /* Create application tasks */
while (DEF_TRUE) { /* Task body, always written as an infinite loop. */
OSTimeDlyHMSM(0, 0, 0, 100);
}
}
/*$PAGE*/
/*
*********************************************************************************************************
* USER INTERFACE TASK
*********************************************************************************************************
*/
static void AppTaskUserIF (void *p_arg)
{
CPU_INT08U s[20];
CPU_BOOLEAN b1; /* State of Push Button #1 */
CPU_BOOLEAN b1_prev;
CPU_BOOLEAN b2; /* State of Push Button #2 */
CPU_BOOLEAN b2_prev;
CPU_INT32U value;
p_arg = p_arg;
DispInit(2, 16); /* Initialize the LCD module */
LED_On(1); /* Turn ON the LCD Backlight */
DispStr(0, 0, "Micrium uC/OS-II"); /* Display 'sign on' message */
DispStr(1, 0, "NXP LPC2138");
OSTimeDlyHMSM(0, 0, 1, 0);
AppUserIFState = 1;
b1_prev = DEF_FALSE;
b2_prev = DEF_FALSE;
while (DEF_TRUE) { /* Task body, always written as an infinite loop. */
b1 = PB_GetStatus(1);
b2 = PB_GetStatus(2);
if (b1 == DEF_TRUE && b1_prev == DEF_FALSE) {
if (AppUserIFState == 3) {
AppUserIFState = 0;
} else {
AppUserIFState++;
}
}
if (b2 == DEF_TRUE && b2_prev == DEF_FALSE) { /* Toggle LCD backlight */
LED_Toggle(1);
}
b1_prev = b1;
b2_prev = b2;
switch (AppUserIFState) {
case 0:
DispStr(0, 0, "Micrium uC/OS-II"); /* Display 'sign on' message */
DispStr(1, 0, "NXP LPC2138");
break;
case 1:
OS_StrCopy(s, "uC/OS-II: Vx.yy");
value = (CPU_INT32U)OSVersion();
s[12] = value / 100 + '0';
s[14] = (value % 100) / 10 + '0';
s[15] = (value % 10) + '0';
DispStr(0, 0, s);
OS_StrCopy(s, "TickRate: xxxx");
value = (CPU_INT32U)OS_TICKS_PER_SEC;
AppFormatDec(&s[12], value, 4);
DispStr(1, 0, s);
break;
case 2:
OS_StrCopy(s, "CPU Usage:xx % ");
value = (CPU_INT32U)OSCPUUsage;
s[10] = (value / 10) + '0';
s[11] = (value % 10) + '0';
DispStr(0, 0, s);
OS_StrCopy(s, "CPU Speed:xx MHz");
value = (CPU_INT32U)BSP_CPU_ClkFreq() / 1000000L;
s[10] = (value / 10) + '0';
s[11] = (value % 10) + '0';
DispStr(1, 0, s);
break;
case 3:
OS_StrCopy(s, "#Ticks: xxxxxxxx");
value = (CPU_INT32U)OSTime;
AppFormatDec(&s[8], value, 8);
DispStr(0, 0, s);
OS_StrCopy(s, "#CtxSw: xxxxxxxx");
value = (CPU_INT32U)OSCtxSwCtr;
AppFormatDec(&s[8], value, 8);
DispStr(1, 0, s);
break;
case 4:
AppUserIFState = 0;
break;
}
OSTimeDlyHMSM(0, 0, 0, 50);
}
}
/*$PAGE*/
/*
*********************************************************************************************************
* CREATE APPLICATION TASKS
*********************************************************************************************************
*/
static void AppTaskCreate (void)
{
CPU_INT08U err;
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 > 13
OSTaskNameSet(APP_TASK_USER_IF_PRIO, "User I/F", &err);
#endif
}
/*
*********************************************************************************************************
* TERMINAL WINDOW CALLBACK
*********************************************************************************************************
*/
#if OS_VIEW_MODULE > 0
static void AppTerminalRx (INT8U rx_data)
{
switch (rx_data) {
case '0':
case '1':
case '2':
case '3':
case '4':
AppUserIFState = rx_data - '0';
break;
}
}
#endif
/*
*********************************************************************************************************
* FORMAT A DECIMAL VALUE
*
* Description: This function converts a decimal value to ASCII (with leading zeros)
* Arguments : s is a pointer to the destination ASCII string
* value is the value to convert (assumes an unsigned value)
* digits is the desired number of digits
*********************************************************************************************************
*/
static void AppFormatDec (CPU_INT08U *s, CPU_INT32U value, CPU_INT08U digits)
{
CPU_INT08U i;
CPU_INT32U mult;
mult = 1;
for (i = 0; i < (digits - 1); i++) {
mult *= 10;
}
while (mult > 0) {
*s++ = value / mult + '0';
value %= mult;
mult /= 10;
}
*s = 0;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -