📄 tasks.c
字号:
/**********************************************************************************************
file : Tasks.c
Author : Farid LEZIAR ( fleziar@yahoo.fr )
Date : July 2002
This file contains Tasks's implementations of the Test Port
**********************************************************************************************/
#include "librtos32\includes.h"
#include "Tasks.h"
/*********************************************************************************************
void Task1();
Initializes the timer, starts statistic task and creates other tasks
This Task prints message every second and stops after 5 seconds.
*********************************************************************************************/
void Task1 (void *pdata)
{
INT8U err;
INT32U cpt = 0;
OSNiosStartTicks((void*)ND_TIMER); /* starts the timer */
#if ND_USE_UCOSVIEW == 1
OSStatInit(); /* OSCPUUsage = % of cpu usage */
OSView_Init(); /* uC/OS-View */
#endif
if (OSNiosInstallUserISR(20, UserTimerISR))
{
((np_timer*)na_timer_for_test)->np_timerperiodl = 0xFFFF & (nasys_clock_freq/1);
((np_timer*)na_timer_for_test)->np_timerperiodh = 0xFFFF & ((nasys_clock_freq/1)>>16);
((np_timer*)na_timer_for_test)->np_timercontrol = np_timercontrol_cont_mask | np_timercontrol_start_mask | np_timercontrol_ito_mask;
}
/* Creates other Tasks */
OSTaskCreateExt(Task2, (void*)0, &Task2Stk[TASK_STACKSIZE-1], 20,
20, &Task2Stk[0], TASK_STACKSIZE, (void*)0,
OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);
OSTaskNameSet(20, "Task2", &err);
OSTaskCreateExt(Task3, (void*)0, &Task3Stk[TASK_STACKSIZE-1], 30,
30, &Task3Stk[0], TASK_STACKSIZE, (void*)0,
OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);
OSTaskNameSet(30, "Task3", &err);
while(1)
{
printf("TASK 1 : cpt = %d\n", cpt++);
OSTimeDlyHMSM(0,0,1,0); /* Waits 1 second */
if (cpt > 500) OSTaskDel(OS_PRIO_SELF); /* terminates current task */
}
}
/*********************************************************************************************
void Task2();
This Task prints message every 2 seconds and never stops.
*********************************************************************************************/
void Task2 (void *pdata)
{
INT32U cpt = 0;
while(1)
{
printf("TASK 2 : cpt = %d\n", cpt++);
OSTimeDlyHMSM(0,0,2,0);
}
}
/*********************************************************************************************
void Task3();
This Task prints message every 3 seconds and never stops.
*********************************************************************************************/
void Task3 (void *pdata)
{
INT32U cpt = 0;
while(1)
{
for (cpt=0;cpt<10;cpt++)
printf("TASK 3 : cpt = %d\n", cpt);
OSTimeDlyHMSM(0,0,3,0);
}
}
/*********************************************************************************************
void UserTimerISR();
This functions is C User ISR.
*********************************************************************************************/
void UserTimerISR()
{
((np_timer*)na_timer_for_test)->np_timerstatus = 0; /* clears the interrupt */
printf("UserTimerISR() : irq = %d\n", getIPRI());
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -