📄 test.c
字号:
* TASK #3
*
* Description: This task waits for up to 250 mS for a message sent by task #1.
*********************************************************************************************************
*/
void Task3 (void *data)
{
INT8U *msg;
INT8U err;
data = data;
for (;;) {
msg = (INT8U *)OSQPend(MsgQueue, OS_TICKS_PER_SEC / 4, &err); /* Wait up to 250 mS for a msg */
if (err == OS_TIMEOUT) {
PC_DispChar(70, 15, 'T', DISP_FGND_YELLOW + DISP_BGND_RED);
} else {
PC_DispChar(70, 15, *msg, DISP_FGND_YELLOW + DISP_BGND_BLUE);
}
}
}
/*
*********************************************************************************************************
* TASK #4
*
* Description: This task posts a message to a mailbox and then immediately reads the message.
*********************************************************************************************************
*/
void Task4 (void *data)
{
OS_EVENT *mbox;
INT8U err;
data = data;
mbox = OSMboxCreate((void *)0);
for (;;) {
OSMboxPost(mbox, (void *)1); /* Send message to mailbox */
OSMboxPend(mbox, 0, &err); /* Get message from mailbox */
OSTimeDlyHMSM(0, 0, 0, 10); /* Delay 10 mS */
}
}
/*$PAGE*/
/*
*********************************************************************************************************
* TASK #5
*
* Description: This task simply delays itself. We basically want to determine how long OSTimeDly() takes
* to execute.
*********************************************************************************************************
*/
void Task5 (void *data)
{
data = data;
for (;;) {
OSTimeDly(1);
}
}
/*
*********************************************************************************************************
* DISPLAY TASK RELATED STATISTICS
*********************************************************************************************************
*/
void DispTaskStat (INT8U id)
{
char s[80];
sprintf(s, "%-18s %05u %5u %10ld",
TaskUserData[id].TaskName,
TaskUserData[id].TaskCtr,
TaskUserData[id].TaskExecTime,
TaskUserData[id].TaskTotExecTime);
PC_DispStr(0, id + 11, s, DISP_FGND_LIGHT_GRAY);
}
/*$PAGE*/
/*
*********************************************************************************************************
* CLOCK TASK
*********************************************************************************************************
*/
void TaskClk (void *data)
{
char s[40];
data = data;
for (;;) {
PC_GetDateTime(s);
PC_DispStr(0, 24, s, DISP_FGND_BLUE + DISP_BGND_CYAN);
OSTimeDlyHMSM(0, 0, 0, 100); /* Execute every 100 mS */
}
}
/*$PAGE*/
/*
*********************************************************************************************************
* OS INITIALIZATION HOOK
* (BEGINNING)
*
* Description: This function is called by OSInit() at the beginning of OSInit().
*
* Arguments : none
*
* Note(s) : 1) Interrupts should be disabled during this call.
*********************************************************************************************************
*/
#if OS_VERSION > 203
void OSInitHookBegin (void)
{
}
#endif
/*
*********************************************************************************************************
* OS INITIALIZATION HOOK
* (END)
*
* Description: This function is called by OSInit() at the end of OSInit().
*
* Arguments : none
*
* Note(s) : 1) Interrupts should be disabled during this call.
*********************************************************************************************************
*/
#if OS_VERSION > 203
void OSInitHookEnd (void)
{
}
#endif
/*
*********************************************************************************************************
* TASK CREATION HOOK
*
* Description: This function is called when a task is created.
*
* Arguments : ptcb is a pointer to the task being created.
*
* Note(s) : 1) Interrupts are disabled during this call.
*********************************************************************************************************
*/
void OSTaskCreateHook (OS_TCB *ptcb)
{
ptcb = ptcb; /* Prevent compiler warning */
}
/*
*********************************************************************************************************
* TASK DELETION HOOK
*
* Description: This function is called when a task is deleted.
*
* Arguments : ptcb is a pointer to the task being created.
*
* Note(s) : 1) Interrupts are disabled during this call.
*********************************************************************************************************
*/
void OSTaskDelHook (OS_TCB *ptcb)
{
ptcb = ptcb; /* Prevent compiler warning */
}
/*$PAGE*/
/*
*********************************************************************************************************
* TASK SWITCH HOOK
*
* Description: This function is called when a task switch is performed. This allows you to perform other
* operations during a context switch.
*
* Arguments : none
*
* Note(s) : 1) Interrupts are disabled during this call.
* 2) It is assumed that the global pointer 'OSTCBHighRdy' points to the TCB of the task that
* will be 'switched in' (i.e. the highest priority task) and, 'OSTCBCur' points to the task
* being switched out (i.e. the preempted task).
*********************************************************************************************************
*/
void OSTaskSwHook (void)
{
INT16U time;
TASK_USER_DATA *puser;
time = PC_ElapsedStop(); /* This task is done */
PC_ElapsedStart(); /* Start for next task */
puser = OSTCBCur->OSTCBExtPtr; /* Point to used data */
if (puser != (void *)0) {
puser->TaskCtr++; /* Increment task counter */
puser->TaskExecTime = time; /* Update the task's execution time */
puser->TaskTotExecTime += time; /* Update the task's total execution time */
}
}
/*
*********************************************************************************************************
* STATISTIC TASK HOOK
*
* Description: This function is called every second by uC/OS-II's statistics task. This allows your
* application to add functionality to the statistics task.
*
* Arguments : none
*********************************************************************************************************
*/
void OSTaskStatHook (void)
{
char s[80];
INT8U i;
INT32U total;
INT8U pct;
total = 0L; /* Totalize TOT. EXEC. TIME for each task */
for (i = 0; i < 7; i++) {
total += TaskUserData[i].TaskTotExecTime;
DispTaskStat(i); /* Display task data */
}
if (total > 0) {
for (i = 0; i < 7; i++) { /* Derive percentage of each task */
pct = 100 * TaskUserData[i].TaskTotExecTime / total;
sprintf(s, "%3d %%", pct);
PC_DispStr(62, i + 11, s, DISP_FGND_YELLOW);
}
}
if (total > 1000000000L) { /* Reset total time counters at 1 billion */
for (i = 0; i < 7; i++) {
TaskUserData[i].TaskTotExecTime = 0L;
}
}
}
/*$PAGE*/
/*
*********************************************************************************************************
* TICK HOOK
*
* Description: This function is called every tick.
*
* Arguments : none
*
* Note(s) : 1) Interrupts may or may not be are ENABLED during this call.
*********************************************************************************************************
*/
void OSTimeTickHook (void)
{
}
/*
*********************************************************************************************************
* OSTCBInit() HOOK
*
* Description: This function is called by OSTCBInit() after setting up most of the TCB.
*
* Arguments : ptcb is a pointer to the TCB of the task being created.
*
* Note(s) : 1) Interrupts may or may not be ENABLED during this call.
*********************************************************************************************************
*/
#if OS_VERSION > 203
void OSTCBInitHook (OS_TCB *ptcb)
{
ptcb = ptcb; /* Prevent Compiler warning */
}
/*
*********************************************************************************************************
* IDLE TASK HOOK
*
* Description: This function is called by the idle task. This hook has been added to allow you to do
* such things as STOP the CPU to conserve power.
*
* Arguments : none
*
* Note(s) : 1) Interrupts are enabled during this call.
*********************************************************************************************************
*/
#if OS_VERSION >= 205
void OSTaskIdleHook (void)
{
}
#endif
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -