?? main.c
字號:
#include "option.h"
#include "def.h"
#include "44b.h"
#include "44blib.h"
#include "ISR.h"
#include "Ucos_ii.h"
//static U32 TimerCnt=0;
//static int LedStatus=0;
OS_CPU_SR cpu_sr;
#define N_TASKS 5 // Number of tasks
#define TASK_STK_SIZE 1024 // Stack size, in sizeof OS_STK, or int 32bit
OS_STK TaskStk[N_TASKS][TASK_STK_SIZE]; // Tasks stacks
void Task1(void *);
void Task2(void *);
int Main(void)
{ int task_1=0,task_2=1;
rSYSCFG=CACHECFG; // Using 8KB Cache//
uHALr_InitInterrupts();
uHALr_InterruptRequestInit();
uHALr_InstallSystemTimer();
Port_Init();
Uart_Init(0,57600);
Delay(10);
Uart_Select(0); //Select UART0
// Led_Display(0x07);
Uart_Printf("\nucos 中斷DEMO");
Uart_Printf("\n ### Main Starts !\n");
OSInit();
OSTaskCreate(Task1, &task_1, &TaskStk[0][TASK_STK_SIZE-1], 1);
OSTaskCreate(Task2, &task_2, &TaskStk[1][TASK_STK_SIZE-1], 2);
OSStart();
return 0;
}
void Task1(void * pParam)
{
Uart_Printf(" @@@ Task1 will starts time ticker !\n");
// enable Ticker, 16 ticks per second
uHALr_InitTimers();
// why start tick here? see uCOS-II Doc Chapter 8 :
/*
"You MUST enable ticker interrupts AFTER multitasking has started, i.e. after
calling OSStart(). In other words, you should initialize and tick interrupts in
the first task that executes following a call to OSStart(). A common mistake is
to enable ticker interrupts between calling OSInit() and OSStart() ..."
*/
while(1)
{
OSSchedLock();
Uart_Printf( "@@@\n");
Uart_Printf( "@@@ task 1 running ... \n" );
Uart_Printf( "@@@ Q__Q \n" );
Uart_Printf( "@@@ /____\\ \n" );
Uart_Printf( "@@@ \\____/ \n" );
Uart_Printf( "@@@ /\\/\\ \n" );
Uart_Printf( "@@@ __(\\\\//)__ \n" );
Uart_Printf( "@@@ >__/w w\\__< \n" );
Uart_Printf( "@@@\n" );
Uart_Printf( "@@@ go to sleep 10 time-ticks\n" );
Uart_Printf( "@@@\n" );
OSSchedUnlock();
OSTimeDly(1000);
}
}
void Task2(void * pParam)
{
while(1)
{
OSSchedLock();
Uart_Printf( "+++ \n" );
Uart_Printf( "+++ task 2 running ... \n" );
Uart_Printf( "+++ ╭︿︿︿╮ \n" );
Uart_Printf( "+++ {/ o o \\} \n" );
Uart_Printf( "+++ ( (oo) ) \n" );
Uart_Printf( "+++ ︶ \n" );
Uart_Printf( "+++ \n" );
Uart_Printf( "+++ go to sleep 5 time-ticks\n" );
Uart_Printf( "+++ \n" );
OSSchedUnlock();
OSTimeDly(1000);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -