📄 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 LPC2468
* on the
* Embedded Artists LPC2468 OEM Board
*
* Filename : app.c
* Version : V1.00
* Programmer(s) : Brian Nagel
*********************************************************************************************************
*/
#include <includes.h>
/*
*********************************************************************************************************
* #DEFINE CONSTANTS
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL VARIABLES
*********************************************************************************************************
*/
static OS_STK AppTaskStartStk[APP_TASK_START_STK_SIZE];
static OS_STK AppTaskKbdStk[APP_TASK_KBD_STK_SIZE];
static void *AppKbdQStorage[16];
static OS_EVENT *AppKbdQ;
/*
*********************************************************************************************************
* LOCAL FUNCTION PROTOTYPES
*********************************************************************************************************
*/
static void AppTaskCreate (void);
static void AppTaskStart (void *p_arg);
static void AppTaskKbd (void *p_arg);
#if OS_VIEW_MODULE > 0
static void AppTerminalRx (CPU_INT08U 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 68HC12 and C initialization.
*
* Arguments : none
*
* Returns : 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()'.
*
* Returns : none
*
* 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.
*********************************************************************************************************
*/
static void AppTaskStart (void *p_arg)
{
CPU_INT08U i;
CPU_INT08U j;
void *msg;
CPU_INT08U err;
CPU_INT08U led;
CPU_INT32U leds;
CPU_INT32U delay0;
CPU_INT32U delay1;
(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(115200); /* OSView Init, baud rate = 115200 */
OSView_TerminalRxSetCallback(AppTerminalRx);
OSView_RxIntEn(); /* Enable Rx Interrupts */
#endif
LED_Off(0); /* Turn OFF all the LEDs */
AppKbdQ = OSQCreate(AppKbdQStorage, 16); /* Create Q for communication between Kbd and Ser */
AppTaskCreate(); /* Create application tasks */
while (DEF_TRUE) { /* Task body, always written as an infinite loop. */
for (i = 1; i <= 4; i++) { /* Turn on each LED, one by one, delaying between */
LED_On(i);
delay0 = ADC_GetStatus(0) + 32;
OSTimeDlyHMSM(0, 0, delay0 / 1000, delay0 % 1000);
}
LED_Off(0); /* Turn off all LEDs */
delay0 = ADC_GetStatus(0) + 32;
OSTimeDlyHMSM(0, 0, delay0 / 1000, delay0 % 1000); /* Delay */
/* Determine what buttons have been pressed */
leds = 0;
while (1) {
msg = OSQAccept(AppKbdQ, &err);
if (err == OS_Q_EMPTY || msg == (void *)0) {
break;
}
led = (CPU_INT32U)msg;
if (led > 4) {
break;
}
leds |= (1 << led);
}
/* If no buttons have been pressed, continue at beginning */
if (leds == 0) {
continue;
}
/* Otherwise, blink LEDs that were pressed 20 times */
for (j = 0; j < 20; j++) {
for (i = 1; i <= 4; i++) {
if ((leds & (1 << i)) == (1 << i)) {
LED_Toggle(i);
}
}
delay1 = (ADC_GetStatus(1) >> 2) + 32;
OSTimeDlyHMSM(0, 0, delay1 / 1000, delay1 % 1000);
}
}
}
/*
*********************************************************************************************************
* KEYBOARD RESPONSE TASK
*
* Description : This task monitors the state of the push buttons and passes messages to AppTaskStart()
*
* Arguments : p_arg is the argument passed to 'AppStartKbd()' by 'OSTaskCreate()'.
*
* Returns : none
*********************************************************************************************************
*/
static void AppTaskKbd (void *p_arg)
{
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_BOOLEAN b3; /* State of Push Button #3 */
CPU_BOOLEAN b3_prev;
CPU_BOOLEAN b4; /* State of Push Button #4 */
CPU_BOOLEAN b4_prev;
(void)p_arg;
b1_prev = DEF_FALSE;
b2_prev = DEF_FALSE;
b3_prev = DEF_FALSE;
b4_prev = DEF_FALSE;
while (DEF_TRUE) {
b1 = PB_GetStatus(1);
b2 = PB_GetStatus(2);
b3 = PB_GetStatus(3);
b4 = PB_GetStatus(4);
if (b1 == DEF_TRUE && b1_prev == DEF_FALSE) {
OSQPost(AppKbdQ, (CPU_INT32U *)1);
}
if (b2 == DEF_TRUE && b2_prev == DEF_FALSE) {
OSQPost(AppKbdQ, (CPU_INT32U *)2);
}
if (b3 == DEF_TRUE && b3_prev == DEF_FALSE) {
OSQPost(AppKbdQ, (CPU_INT32U *)3);
}
if (b4 == DEF_TRUE && b4_prev == DEF_FALSE) {
OSQPost(AppKbdQ, (CPU_INT32U *)4);
}
b1_prev = b1;
b2_prev = b2;
b3_prev = b3;
b4_prev = b4;
OSTimeDly(OS_TICKS_PER_SEC / 10);
}
}
/*
*********************************************************************************************************
* CREATE APPLICATION TASKS
*
* Description: This function creates the application tasks.
*
* Arguments : none
*
* Returns : 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 > 9
OSTaskNameSet(APP_TASK_KBD_PRIO, "Keyboard", &err);
#endif
}
/*
*********************************************************************************************************
* uC/OS-VIew Terminal Window Callback
*
* Description : This is the callback function for uC/OS-View
*
* Arguments : rx_data is the received data.
*
* Returns : none
*********************************************************************************************************
*/
#if OS_VIEW_MODULE > 0
static void AppTerminalRx (CPU_INT08U rx_data)
{
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -