⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 这是一个用于在S3C44B0开发板(网上公版)
💻 C
字号:
#include "..\startup\44b.h"#include "..\inc\44blib.h"#include "..\startup\option.h"#include "..\inc\def.h"#include "..\ucos\includes.h"extern void OSSchedLock(void);#define IRQ_VECTOR_OFFSET	(0x18)//-------------------------------------------------------// globle variables//-------------------------------------------------------volatile static int isrCount = 0;		// tick counter//volatile static unsigned int Dump_Pool[16];//-------------------------------------------------------// OS_Tick Hook Fubction//-------------------------------------------------------void tick_hook(void){	isrCount++;	rI_ISPC = (unsigned int)1 << 20;}//-------------------------------------------------------// install a new ISR// this function must be synchronized//-------------------------------------------------------unsigned int ISR_Install(unsigned int offset, void *pf_ISR){	unsigned int pOldEntry;	// get absolute address of IRQ vector	// _ISR_STARTADDRESS : see Option.h	offset += _ISR_STARTADDRESS;	// get the Old ISR service routine entry point	pOldEntry = *((unsigned int *)offset);		// install new interrupt service routine	*((unsigned int *)offset) = (unsigned int)pf_ISR;	return pOldEntry;}//-------------------------------------------------------// must be synchronized//-------------------------------------------------------void tick_off(void){	rRTCCON = (unsigned char)1;		rTICNT = (unsigned char)0;		rRTCCON = (unsigned char)0;}//--------------------------------------------------------// set or clear TICK interrupt mask// this function must be synchronized//--------------------------------------------------------void tick_int_enable(unsigned char bEnabled){	// clear interrupt pending first	rI_ISPC = (unsigned int)0x01 << 20;		rINTMSK &= (unsigned int)~(0x01 << 20);}//--------------------------------------------------------// start tick function of RTC// interval = (1 + div) / 128  second// this function must be synchronized// div MUST >= 1 && <= 128//--------------------------------------------------------void tick_init(unsigned char div){	rRTCCON = (unsigned char)1;//	ASSERT(div >= 1 && div <= 127);	rTICNT = (unsigned char)(div | 0x80);	rRTCCON = (unsigned char)0;	tick_int_enable(1);}//--------------------------------------------------------// interrupt controler initilization//--------------------------------------------------------void intcon_init(void){	rINTMOD = 0;			// all interrupt sources configed as IRQ	rI_ISPC = 0x7ffffff;	// clear all intrrupt request	rINTCON = 0x05;			// irq interrupt available}//--------------------------------------------------------// globel interrupt enable//--------------------------------------------------------void globle_int_enable(unsigned char bEnabled){	if(bEnabled)		rINTMSK &= ~(0x03 << 26);	else		rINTMSK |= 0x01 << 26;}__inline void Sleep(INT16U uSec){	OSTimeDly((INT16U) (uSec));}void sys_init(void){	tick_off();	tick_int_enable(0);	globle_int_enable(0);	intcon_init();	isrCount = 0;		// Set the function of the pins	Port_Init();	Uart_Init(0, 115200);	// hook the tick ISR	ISR_Install(IRQ_VECTOR_OFFSET, (void *)OSTickISR);	globle_int_enable(1);}#define printf Uart_Printf//**********************************************************// THE MAIN FUNCTION BODY//**********************************************************#define	N_TASKS			5					// Number of tasks#define	TASK_STK_SIZE	1024				// Stack size, in sizeof OS_STK, or int 32bitOS_STK	TaskStk[N_TASKS][TASK_STK_SIZE];	// Tasks stacksvoid Task1(void *);void Task2(void *);int Main(int argc, char **argv){	int	task_1 = 0, task_2 = 1;	sys_init();	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	tick_init(7);	// 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();		printf( "@@@\n");		printf( "@@@  task 1 running ... \n" );		printf( "@@@     Q__Q    \n" );		printf( "@@@    /____\\   \n" );		printf( "@@@    \\____/   \n" );		printf( "@@@     /\\/\\    \n" );		printf( "@@@  __(\\\\//)__ \n" );		printf( "@@@  >__/w w\\__< \n" );		printf( "@@@\n" );		printf( "@@@  go to sleep 10 time-ticks\n" );		printf( "@@@\n" );		OSSchedUnlock();		Sleep(7);	}}void Task2(void * pParam){	while(1)		{		OSSchedLock();		printf( "+++ \n" );		printf( "+++  task 2 running ... \n" );		printf( "+++  ╭︿︿︿╮ \n" );		printf( "+++ {/ o o \\} \n" );		printf( "+++  ( (oo) ) \n" );		printf( "+++      ︶ \n" );		printf( "+++ \n" );		printf( "+++  go to sleep 5 time-ticks\n" );		printf( "+++ \n" );		OSSchedUnlock();		Sleep(3);	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -