?? app.c
字號:
/*
*********************************************************************************************************
* (c) Copyright 2006, Micrium, Weston, FL
* All Rights Reserved
*
*
* Cortex M3 Sample code
*
* File : APP.C
* By : Jean J. Labrosse
*********************************************************************************************************
*/
#include <includes.h>
/*
*********************************************************************************************************
* CONSTANTS
*********************************************************************************************************
*/
#define APP_SCR_LO '0'
#define APP_SCR_HI '3'
/*
*********************************************************************************************************
* VARIABLES
*********************************************************************************************************
*/
static INT8U AppDispScrID;
static OS_STK AppTask_StartStk[APP_TASK_START_STK_SIZE];
static OS_STK AppTask_LEDStk[APP_TASK_LED_STK_SIZE];
/*
*********************************************************************************************************
* FUNCTION PROTOTYPES
*********************************************************************************************************
*/
static void AppTask_Create (void);
static void AppTask_Start (void *p_arg);
static void AppTask_UserIF (void);
static void AppTask_LED (void *p_arg);
static void AppDisp_SignOn (void);
static void AppDisp_VersionTickRate (void);
static void AppDisp_CPU (void);
static void AppDisp_CtxSw (void);
static void AppFormatDec (CPU_INT08U *s, CPU_INT32U value, CPU_INT08U digits);
#if OS_VIEW_MODULE > 0
static void AppTerminalRx (INT8U rx_data);
#endif
/*
*********************************************************************************************************
* 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)
{
#if OS_TASK_NAME_SIZE > 13
INT8U err;
#endif
BSP_IntDisAll(); /* Disable all interrupts until we are ready to accept them */
OSInit(); /* Initialize "uC/OS-II, The Real-Time Kernel" */
OSTaskCreateExt(AppTask_Start, /* Create the start task */
(void *)0,
(OS_STK *)&AppTask_StartStk[APP_TASK_START_STK_SIZE - 1],
APP_TASK_START_PRIO,
APP_TASK_START_PRIO,
(OS_STK *)&AppTask_StartStk[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) */
}
/*$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 AppTask_Start (void *p_arg)
{
CPU_INT08U i;
(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); /* Initialize the uC/OS-View module */
OSView_TerminalRxSetCallback(AppTerminalRx);
#endif
AppTask_Create(); /* Create application tasks */
AppDispScrID = '0';
while (1) { /* Task body, always written as an infinite loop. */
for (i = 0; i < 4; i++) {
AppTask_UserIF();
OSTimeDly(OS_TICKS_PER_SEC / 2);
}
AppDispScrID++;
if (AppDispScrID > APP_SCR_HI) {
AppDispScrID = APP_SCR_LO;
}
}
}
/*$PAGE*/
/*
*********************************************************************************************************
* LED TASK
*
* Description : This is a task that controls the 8 LEDs connected on the PDC.
*
* Arguments : p_arg is the argument passed to 'AppStartTask()' by 'OSTaskCreate()'. Not used.
*********************************************************************************************************
*/
static void AppTask_LED (void *p_arg)
{
CPU_INT08U i;
(void)p_arg;
LED_Off(0); /* Turn OFF all the LEDs */
while (1) { /* Task body, always written as an infinite loop. */
for (i = 1; i <= 8; i++) {
LED_On(i);
OSTimeDly(OS_TICKS_PER_SEC / 20);
LED_Off(i);
}
for (i = 1; i <= 8; i++) {
LED_On(9 - i);
OSTimeDly(OS_TICKS_PER_SEC / 20);
LED_Off(9 - i);
}
}
}
/*$PAGE*/
/*
*********************************************************************************************************
* CREATE APPLICATION TASKS
*********************************************************************************************************
*/
static void AppTask_Create (void)
{
#if OS_TASK_NAME_SIZE > 13
INT8U err;
#endif
OSTaskCreateExt(AppTask_LED,
(void *)0,
(OS_STK *)&AppTask_LEDStk[APP_TASK_LED_STK_SIZE - 1],
APP_TASK_LED_PRIO,
APP_TASK_LED_PRIO,
(OS_STK *)&AppTask_LEDStk[0],
APP_TASK_LED_STK_SIZE,
(void *)0,
OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);
#if OS_TASK_NAME_SIZE > 13
OSTaskNameSet(APP_TASK_LED_PRIO, "LED Task", &err);
#endif
}
/*
*********************************************************************************************************
* USER INTERFACE TASK
*********************************************************************************************************
*/
static void AppTask_UserIF (void)
{
switch (AppDispScrID) {
case '0':
AppDisp_SignOn();
break;
case '1':
AppDisp_VersionTickRate();
break;
case '2':
AppDisp_CPU();
break;
case '3':
AppDisp_CtxSw();
break;
default:
AppDispScrID = '0';
break;
}
}
/*
*********************************************************************************************************
* DISPLAY SCREENS
*********************************************************************************************************
*/
static void AppDisp_SignOn (void)
{
PDCLCDClear();
PDCLCDSetPos(0, 0);
PDCLCDWrite("Micrium uC/OS-II", 16);
PDCLCDSetPos(0, 1);
PDCLCDWrite(" ARM Cortex-M3 ", 16);
}
static void AppDisp_VersionTickRate (void)
{
CPU_INT08U s[20];
CPU_INT32U value;
PDCLCDClear();
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';
PDCLCDSetPos(0, 0);
PDCLCDWrite((char const *)s, 16);
OS_StrCopy(s, "TickRate:xxxx Hz");
value = (INT32U)OS_TICKS_PER_SEC;
AppFormatDec(&s[9], value, 4);
s[13] = ' ';
s[14] = 'H';
s[15] = 'z';
s[16] = 0;
PDCLCDSetPos(0, 1);
PDCLCDWrite((char const *)s, 16);
}
static void AppDisp_CPU (void)
{
CPU_INT08U s[20];
CPU_INT32U value;
PDCLCDClear();
OS_StrCopy(s, "CPU Usage:xx % ");
value = (CPU_INT32U)OSCPUUsage;
s[10] = (value / 10) + '0';
s[11] = (value % 10) + '0';
PDCLCDSetPos(0, 0);
PDCLCDWrite((char const *)s, 16);
OS_StrCopy(s, "CPU Speed:xx MHz");
value = (CPU_INT32U)SysCtlClockGet() / 1000000L;
s[10] = (value / 10) + '0';
s[11] = (value % 10) + '0';
PDCLCDSetPos(0, 1);
PDCLCDWrite((char const *)s, 16);
}
static void AppDisp_CtxSw (void)
{
CPU_INT08U s[20];
CPU_INT32U value;
PDCLCDClear();
OS_StrCopy(s, "#Ticks: xxxxxxxx");
value = (CPU_INT32U)OSTime;
AppFormatDec(&s[8], value, 8);
PDCLCDSetPos(0, 0);
PDCLCDWrite((char const *)s, 16);
OS_StrCopy(s, "#CtxSw: xxxxxxxx");
value = (CPU_INT32U)OSCtxSwCtr;
AppFormatDec(&s[8], value, 8);
PDCLCDSetPos(0, 1);
PDCLCDWrite((char const *)s, 16);
}
/*
*********************************************************************************************************
* 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;
}
/*
*********************************************************************************************************
* uC/OS-View TERMINAL WINDOW CALLBACK
*********************************************************************************************************
*/
#if OS_VIEW_MODULE > 0
static void AppTerminalRx (INT8U rx_data)
{
(void)rx_data;
}
#endif
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -