zynq + ucos
int main()
{
UCOSStartup(MainTask);
return 0;
}
void MainTask (void *p_arg)
{
OS_ERR os_err;
UCOS_Print ("Hello world from the main task\r\n");
OSTaskCreate(&AppTask1_TCB,
"AppTask1",
AppTask1,
(void *)0,
3,
&AppTask1_Stk[0],
0,
1024,
0,
0,
DEF_NULL,
(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
&os_err);
OSTaskCreate(&AppTask2_TCB,
"AppTask2",
AppTask2,
(void *)0,
10,
&AppTask2_Stk[0],
0,
1024,
0,
0,
DEF_NULL,
(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
&os_err);
while (DEF_TRUE) {
OSTimeDlyHMSM(0, 0, 10, 0, OS_OPT_TIME_HMSM_STRICT, &os_err);
UCOS_Print("MainTask,prio is 5\r\n");
}
}
static void AppTask1 (void *p_arg)
{
OS_ERR os_err;
p_arg = p_arg;
while(DEF_TRUE)
{
UCOS_Print ("AppTask1,prio is 3\r\n");
OSTimeDlyHMSM(0, 0, 0, 100, OS_OPT_TIME_HMSM_STRICT, &os_err);
}
}
static void AppTask2 (void *p_arg)
{
OS_ERR os_err;
p_arg = p_arg;
while(DEF_TRUE)
{
UCOS_Print ("AppTask2,prio is 10\r\n");
OSTimeDlyHMSM(0, 0, 0, 100, OS_OPT_TIME_HMSM_STRICT, &os_err);
}
}
void MainTask (void *p_arg)
{
OS_ERR os_err;
g_uiTimeCnt = 0;
OSSemCreate(&g_timer_sem,"g_timer_sem",(OS_SEM_CTR)0,&os_err);
OSSemCreate(&g_task1_sem,"g_task1_sem",(OS_SEM_CTR)0,&os_err);
OSSemCreate(&g_task2_sem,"g_task2_sem",(OS_SEM_CTR)0,&os_err);
OSTaskCreate(&TimerTask_TCB,"TimerTask",TimerTask,(void *)NULL,10,&TimerTask_Stk[0],
0,1024,0,0,DEF_NULL,(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),&os_err);
OSTaskCreate(&AppTask1_TCB,"AppTask1",AppTask1,(void *)NULL,20,&AppTask1_Stk[0],
0,1024,0,0,DEF_NULL,(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),&os_err);
OSTaskCreate(&AppTask2_TCB,"AppTask2",AppTask2,(void *)NULL,30,&AppTask2_Stk[0],
0,1024,0,0,DEF_NULL,(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),&os_err);
while (DEF_TRUE) {
OSTimeDlyHMSM(0, 0, 10, 0, OS_OPT_TIME_HMSM_STRICT, &os_err);
}
}
static void TimerTask (void *p_arg)
{
OS_ERR os_err;
static u32 s_dataRead_pre;
static u32 s_dataRead;
static u32 s_cnt = 0;
p_arg = p_arg;
while(DEF_TRUE)
{
g_uiTimeCnt++;
s_dataRead_pre = s_dataRead;
s_dataRead = EmcRead(0x0004,DSP_CE);
g_uiTimeSubAy[s_cnt] = s_dataRead - s_dataRead_pre;
s_cnt++;
if(s_cnt>=1024)
{
s_cnt = 0;
}
OSSemPost(&g_timer_sem,OS_OPT_POST_1,&os_err);
OSTimeDlyHMSM(0, 0, 0, 1, OS_OPT_TIME_HMSM_STRICT, &os_err);
}
}
static void AppTask1 (void *p_arg)
{
OS_ERR os_err;
CPU_TS ts;
u32 uiData;
p_arg = p_arg;
while(DEF_TRUE)
{
OSSemPend(&g_timer_sem,0,OS_OPT_PEND_BLOCKING,&ts,&os_err);
uiData = EmcRead(0xFFFF,DSP_CE);
OSSemPost(&g_task1_sem,OS_OPT_POST_1,&os_err);
OSTimeDlyHMSM(0, 0, 0, 1, OS_OPT_TIME_HMSM_STRICT, &os_err);
}
}
static void AppTask2 (void *p_arg)
{
OS_ERR os_err;
CPU_TS ts;
p_arg = p_arg;
while(DEF_TRUE)
{
OSSemPend(&g_task1_sem,0,OS_OPT_PEND_BLOCKING,&ts,&os_err);
EmcWrite(0xFFFF,0x12345678,DSP_CE);
// OSSemPost(&g_task2_sem,OS_OPT_POST_1,&os_err);
OSTimeDlyHMSM(0, 0, 0, 1, OS_OPT_TIME_HMSM_STRICT, &os_err);
}
}
《实时操作系统任务调度算法的硬件实现》