📄 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
*
* NXP LPC2888
*
* Filename : app.c
* Version : V1.00
* Programmer(s) : Brian Nagel
*********************************************************************************************************
*/
#include <includes.h>
/*
*********************************************************************************************************
* VARIABLES
*********************************************************************************************************
*/
OS_STK AppTaskStartStk[APP_TASK_START_STK_SIZE];
/*
*********************************************************************************************************
* FUNCTION PROTOTYPES
*********************************************************************************************************
*/
static void AppTaskStart(void *p_arg);
#if OS_VIEW_MODULE > 0
static void AppTerminalRx(CPU_INT08U rx_data);
#endif
static void AppFormatDec(CPU_INT08U *s, CPU_INT32U value, CPU_INT08U digits);
static void AppPrintPage(void);
static void AppUpdatePage(void);
/*
*********************************************************************************************************
* 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 CPU 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, "Start Task", &err);
#endif
OSStart(); /* 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 '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)
{
CPU_INT08U i;
CPU_INT08U j;
CPU_BOOLEAN status1;
CPU_BOOLEAN status2;
CPU_INT16U adc_old;
CPU_INT16U adc_new;
(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_On(1); /* Turn ON the LED */
i = 0;
j = 0;
AppPrintPage();
adc_old = (ADC_GetStatus(1) >> 5) + 32;
while (DEF_TRUE) { /* Task body, always written as an infinite loop. */
OSTimeDly(OS_TICKS_PER_SEC / 10);
j = (j + 1) % 2;
if (j == 0) {
AppUpdatePage();
}
status1 = PB_GetStatus(1);
status2 = PB_GetStatus(2);
if ((status1 == DEF_TRUE) && (status2 == DEF_FALSE)) {
i = (i + 2) % 64;
LCD_SetStartLine(i);
LED_Toggle(1);
} else if ((status1 == DEF_FALSE) && status2 == DEF_TRUE) {
i = 63 - (65 - i) % 64;
LCD_SetStartLine(i);
LED_Toggle(1);
}
adc_new = (ADC_GetStatus(1) >> 5) + 32;
if (adc_new != adc_old) {
LCD_SetBrightness(adc_new);
adc_old = adc_new;
}
}
}
/*
*********************************************************************************************************
* TERMINAL WINDOW CALLBACK
*********************************************************************************************************
*/
#if OS_VIEW_MODULE > 0
static void AppTerminalRx (CPU_INT08U rx_data)
{
}
#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;
}
/*
*********************************************************************************************************
* PRINT SYSTEM INFORMATION ON LCD
*
* Description: This function displays uC/OS-II system information on the LCD.
*
* Argument(s): None
*
* Returns : None
*********************************************************************************************************
*/
static void AppPrintPage (void)
{
CPU_INT08U s[20];
CPU_INT32U value;
LCD_DispStr(0, 0, "Micrium uC/OS-II");
LCD_DispStr(1, 0, "NXP LPC2888");
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';
LCD_DispStr(2, 0, s);
OS_StrCopy(s, "TickRate: xxxx");
value = (CPU_INT32U)OS_TICKS_PER_SEC;
AppFormatDec(&s[12], value, 4);
LCD_DispStr(3, 0, s);
OS_StrCopy(s, "CPU Usage:xx % ");
value = (CPU_INT32U)OSCPUUsage;
s[10] = (value / 10) + '0';
s[11] = (value % 10) + '0';
LCD_DispStr(4, 0, s);
OS_StrCopy(s, "CPU Speed:xx MHz");
value = (CPU_INT32U)BSP_CPU_ClkFreq() / 1000L;
s[10] = (value / 10) + '0';
s[11] = (value % 10) + '0';
LCD_DispStr(5, 0, s);
OS_StrCopy(s, "#Ticks: xxxxxxxx");
value = (CPU_INT32U)OSTime;
AppFormatDec(&s[8], value, 8);
LCD_DispStr(6, 0, s);
OS_StrCopy(s, "#CtxSw: xxxxxxxx");
value = (CPU_INT32U)OSCtxSwCtr;
AppFormatDec(&s[8], value, 8);
LCD_DispStr(7, 0, s);
}
/*
*********************************************************************************************************
* UPDATE LCD
*
* Description: This function updates the information on the LCD.
*
* Argument(s): None
*
* Returns : None
*********************************************************************************************************
*/
static void AppUpdatePage (void)
{
CPU_INT08U s[9];
CPU_INT32U value;
OS_StrCopy(s, "xxxx");
value = (CPU_INT32U)OS_TICKS_PER_SEC;
AppFormatDec(&s[0], value, 4);
LCD_DispStr(3, 12, s);
OS_StrCopy(s, "xx");
value = (CPU_INT32U)OSCPUUsage;
s[0] = (value / 10) + '0';
s[1] = (value % 10) + '0';
LCD_DispStr(4, 10, s);
OS_StrCopy(s, "xx");
value = (CPU_INT32U)BSP_CPU_ClkFreq() / 1000L;
s[0] = (value / 10) + '0';
s[1] = (value % 10) + '0';
LCD_DispStr(5, 10, s);
OS_StrCopy(s, "xxxxxxxx");
value = (CPU_INT32U)OSTime;
AppFormatDec(&s[0], value, 8);
LCD_DispStr(6, 8, s);
OS_StrCopy(s, "xxxxxxxx");
value = (CPU_INT32U)OSCtxSwCtr;
AppFormatDec(&s[0], value, 8);
LCD_DispStr(7, 8, s);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -