📄 test.c
字号:
/*
*********************************************************************************************************
* uC/OS
* The Real-Time Kernel
*
* (c) Copyright 1992-1996, Jean J. Labrosse, Plantation, FL
* All Rights Reserved
*
*
* MCS-251 Sample code
*
* File : TEST.C
* By : Jean J. Labrosse
*********************************************************************************************************
*/
#include "INCLUDES.H"
/*
*********************************************************************************************************
* LOCAL VARIABLES
*********************************************************************************************************
*/
UBYTE AppStartTaskStk[256];
UBYTE AppTask2Stk[256];
/*
*********************************************************************************************************
* FUNCTION PROTOTYPES
*********************************************************************************************************
*/
void OS_FAR AppStartTask(void *pdata);
void OS_FAR AppTask2(void *pdata);
void AppTickInit(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 MCS-251 and C initialization.
* Arguments : none
*********************************************************************************************************
*/
void main(void)
{
SET_VECTOR(TIMER0, OSTickISR); /* Set interrupt vector */
/*---- Any initialization code prior to calling OSInit() goes HERE --------------------------------*/
OSInit(); /* Initialize "uC/OS, The Real-Time Kernel" */
/*---- Any initialization code before starting multitasking ---------------------------------------*/
OSTaskCreate(AppStartTask, (void *)0, (void *)&AppStartTaskStk[0], 10);
/*---- Create any other task you want before we start multitasking --------------------------------*/
OSStart(); /* Start multitasking (i.e. give control to uC/OS) */
}
/*$PAGE*/
/*
*********************************************************************************************************
* STARTUP TASK
*
* Description : This is an example of a startup task. As mentioned in the book, you MUST initialize
* the ticker only once multitasking has started.
* Arguments : pdata is the argument passed to 'AppStartTask()' by 'OSTaskCreate()'.
* Notes : 1) The first line of code is used to prevent a compiler warning because 'pdata' is not
* used. The compiler should not generate any code for this statement.
* 2) Interrupts are not-enabled once the task start. Because of this, you MUST invoke the
* OS_EXIT_CRITICAL() before starting the infinite loop.
*********************************************************************************************************
*/
void OS_FAR AppStartTask(void *pdata)
{
pdata = pdata;
OSTaskCreate(AppTask2, (void *)0, (void *)&AppTask2Stk[0], 20);
AppTickInit(); /* Initialize the ticker */
/*---- Task initialization code goes HERE! --------------------------------------------------------*/
OS_EXIT_CRITICAL(); /* Enable interrupts */
while (TRUE) { /* Task body, always written as an infinite loop. */
/*---- Task code goes HERE ... ----------------------------------------------------------------*/
OSTimeDly(1); /* Delay task execution for one clock tick */
/*---- ... and/or HERE! -----------------------------------------------------------------------*/
}
}
/*
*********************************************************************************************************
* TASK #2
*
* 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 : pdata is the argument passed to 'AppStartTask()' by 'OSTaskCreate()'.
* Notes : 1) The first line of code is used to prevent a compiler warning because 'pdata' is not
* used. The compiler should not generate any code for this statement.
* 2) Interrupts are not-enabled once the task start. Because of this, you MUST invoke the
* OS_EXIT_CRITICAL() before starting the infinite loop.
*********************************************************************************************************
*/
void OS_FAR AppTask2(void *pdata)
{
pdata = pdata;
/*---- Task initialization code goes HERE! --------------------------------------------------------*/
OS_EXIT_CRITICAL(); /* Enable interrupts */
while (TRUE) { /* Task body, always written as an infinite loop. */
/*---- Task code goes HERE ... ----------------------------------------------------------------*/
OSTimeDly(1); /* Delay task execution for one clock tick */
/*---- ... and/or HERE! -----------------------------------------------------------------------*/
}
}
/*$PAGE*/
/*
*********************************************************************************************************
* TICKER INITIALIZATION
*
* Description : This function is used to initialize timer #0 which is assumed to be used as the system
* ticker. If you use another source to produce tick interrupts, you will need to modify
* this code.
* Arguments : none
* Notes : Timer #0 is set in Mode 1 and will generate an interrupt every 65536 * 12 oscillator
* counts. The following table shows the tick rate based on the oscillator frequency:
*
* Osc. Freq. (MHz) Tick Rate (Hz)
* ---------------- --------------
* 10 12.71
* 12 15.26
* 14 17.80
* 16 20.35
*********************************************************************************************************
*/
void AppTickInit(void)
{
TH0 = 0; /* Set reload value for timer #0 */
TL0 = 0; /* Set initial value for timer #0 */
TMOD = 0x01; /* Timer #0: Mode 1, interrupt every 65536 counts */
ET0 = 1; /* Enable timer #0 interrupt */
TR0 = 1; /* Enable timer #0 */
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -