?? test.c
字號(hào):
/*
*********************************************************************************************************
* uC/OS-II
* The Real-Time Kernel
*
* (c) Copyright 1998, Jean J. Labrosse, Plantation, FL
* All Rights Reserved
*
* M68HC11 Sample code
*
* COSMIC C V4.1F
*
* File : TEST.C
* By : Jean J. Labrosse
* Port Version : V1.00
*********************************************************************************************************
*/
#include "INCLUDES.H"
/*
*********************************************************************************************************
* VARIABLES
*********************************************************************************************************
*/
OS_STK AppStartTaskStk[128];
OS_STK AppTask1Stk[128];
OS_STK AppTask2Stk[128];
static INT16U Task1Ctr;
static INT16U Task2Ctr;
/*
*********************************************************************************************************
* FUNCTION PROTOTYPES
*********************************************************************************************************
*/
static void AppStartTask(void *pdata);
static void AppTask1(void *pdata);
static void AppTask2(void *pdata);
static 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 68HC11 and C initialization.
* Arguments : none
*********************************************************************************************************
*/
void main (void)
{
/*---- Any initialization code prior to calling OSInit() goes HERE --------------------------------*/
OSInit(); /* Initialize "uC/OS-II, The Real-Time Kernel" */
/*---- Any initialization code before starting multitasking ---------------------------------------*/
OSTaskCreate(AppStartTask, (void *)0, (void *)&AppStartTaskStk[127], 0);
/*---- Create any other task you want before we start multitasking --------------------------------*/
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 : 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 enabled once the task start because the I-bit of the CCR register was
* set to 0 by 'OSTaskCreate()'.
*********************************************************************************************************
*/
static void AppStartTask (void *pdata)
{
pdata = pdata;
AppTickInit(); /* Initialize the ticker */
/*---- Task initialization code goes HERE! --------------------------------------------------------*/
OSTaskCreate(AppTask1, (void *)0, (void *)&AppTask1Stk[127], 1);
OSTaskCreate(AppTask2, (void *)0, (void *)&AppTask2Stk[127], 2);
while (TRUE) { /* Task body, always written as an infinite loop. */
/*---- Task code goes HERE! -------------------------------------------------------------------*/
OSTimeDly(1); /* Delay task execution for one clock tick */
}
}
/*$PAGE*/
/*
*********************************************************************************************************
* TASK #1
*
* Description : This is an example of a task.
* Arguments : pdata is the argument passed to 'AppTask1()' 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 enabled once the task start because the I-bit of the CCR register was
* set to 0 by 'OSTaskCreate()'.
*********************************************************************************************************
*/
static void AppTask1 (void *pdata)
{
pdata = pdata;
/*---- Task initialization code goes HERE! --------------------------------------------------------*/
while (TRUE) { /* Task body, always written as an infinite loop. */
/*---- Task code goes HERE! -------------------------------------------------------------------*/
Task1Ctr++;
OSTimeDly(1); /* Delay task execution for one clock tick */
}
}
/*$PAGE*/
/*
*********************************************************************************************************
* TASK #2
*
* Description : This is an example of a task.
* Arguments : pdata is the argument passed to 'AppTask2()' 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 enabled once the task start because the I-bit of the CCR register was
* set to 0 by 'OSTaskCreate()'.
*********************************************************************************************************
*/
static void AppTask2 (void *pdata)
{
pdata = pdata;
/*---- Task initialization code goes HERE! --------------------------------------------------------*/
while (TRUE) { /* Task body, always written as an infinite loop. */
/*---- Task code goes HERE! -------------------------------------------------------------------*/
Task2Ctr++;
OSTimeDly(1); /* Delay task execution for one clock tick */
}
}
/*$PAGE*/
/*
*********************************************************************************************************
* TICKER INITIALIZATION
*
* Description : This function is used to initialize one of the five output compares to generate an
* interrupt at the desired tick rate. You must decide which output compare you will be
* using by setting the configuration variable OS_TICK_OC (see OS_CFG.H and also OS_CPU_A.S)
* to 1, 2, 3, 4 or 5 depending on which output compare to use.
* OS_TICK_OC set to 1 chooses output compare #1 as the ticker source
* OS_TICK_OC set to 2 chooses output compare #2 as the ticker source
* OS_TICK_OC set to 3 chooses output compare #3 as the ticker source
* OS_TICK_OC set to 4 chooses output compare #4 as the ticker source
* OS_TICK_OC set to 5 chooses output compare #5 as the ticker source
* Arguments : none
* Notes : 1) It is assumed that you have set the prescaler rate of the free running timer within
* the first 64 E clock cycles of the 68HC11.
* 2) TCNT, TOC1, TOC2, TOC3, TOC4, TOC5 and TMSK1 are define in IOF1.H (see COSMIC
* compiler) and in OS_CPU_A.S.
*********************************************************************************************************
*/
static void AppTickInit (void)
{
#if OS_TICK_OC == 1
TOC1 = TCNT + OS_TICK_OC_CNTS; /* Set TOC1 to present time + OS_TICK_OC_CNTS */
TMSK1 |= 0x80; /* Enable OC1 interrupt. */
#endif
#if OS_TICK_OC == 2
TOC2 = TCNT + OS_TICK_OC_CNTS; /* Set TOC2 to present time + OS_TICK_OC_CNTS */
TMSK1 |= 0x40; /* Enable OC2 interrupt. */
#endif
#if OS_TICK_OC == 3
TOC3 = TCNT + OS_TICK_OC_CNTS; /* Set TOC3 to present time + OS_TICK_OC_CNTS */
TMSK1 |= 0x20; /* Enable OC3 interrupt. */
#endif
#if OS_TICK_OC == 4
TOC4 = TCNT + OS_TICK_OC_CNTS; /* Set TOC4 to present time + OS_TICK_OC_CNTS */
TMSK1 |= 0x10; /* Enable OC4 interrupt. */
#endif
#if OS_TICK_OC == 5
TOC5 = TCNT + OS_TICK_OC_CNTS; /* Set TOC5 to present time + OS_TICK_OC_CNTS */
TMSK1 |= 0x08; /* Enable OC5 interrupt. */
#endif
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -