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

📄 main_entry.c

📁 基于s3c4510开发平台上的ucosII的移植源程序
💻 C
字号:
#include <stdio.h>

#define IRQVector	((unsigned *)0x18)

extern int  Angel_IRQ_Address;
extern void handler_irq(void);

#define SYSCFG	0x03ff0000

#define INTPND							((volatile unsigned *)(SYSCFG+0x4004))
#define INTMSK							((volatile unsigned *)(SYSCFG+0x4008))
#define INT_GLOBAL						(21)

#define TMOD				((volatile unsigned *)(SYSCFG+0x6000))  // timer mode register
#define TDATA0				((volatile unsigned *)(SYSCFG+0x6004))
#define TCNT0				((volatile unsigned *)(SYSCFG+0x600c))

#define COUNTDOWN	0x01effff0;

static int counter = 0;


void  timer_irq (void) 
{ 

	// *TMOD	= 0; 
	*INTPND	= 1 << 10;
	*TDATA0	= COUNTDOWN; // reset interrupt

   // -- toggle the LED D4 to show timer interrupt...
   
    printf( "\n^ time-ticks = %d !\n", counter );
    counter = counter + 1;


	// -- re-enable interrupts ...

	// *TMOD	= 1;
	 *(volatile int*)INTMSK &= ~((1 << INT_GLOBAL) | (1 <<10) | (1<<0));
	 
} 


static void irq_installhandler (unsigned routine, unsigned *vector) 
{
unsigned old_vector_value = 0;
unsigned *absolute;   
  
   old_vector_value = 0;
   
   old_vector_value  = *vector;  	 // Get old vector contents ....................
   old_vector_value ^= 0xe59ff000;	 // Mask off the instruction to get the offset
 
	// ** calculate absolute address

   absolute	     	= (unsigned *) (0x18 + old_vector_value+0x8); 
					// IRQ Address
   Angel_IRQ_Address 	= *absolute; 	// chain Angel Interrupt Handler	  
   *absolute		= routine; 	// IRQ handler

}

void timer_init (void)
{
  *TMOD		= 0;
  *INTPND 	= 0x00000000; 	// Clear pending interrupts .............
}

void timer_start (void)
{	
  *TDATA0		 = COUNTDOWN;	// reload CT .......................
  *TMOD 		|= 0x1;			// enable interval interrupt ...................
  
  *(volatile int*)INTMSK &= ~((1 << INT_GLOBAL) | (1 <<10) | (1<<0));
}

#include "includes.h"

void OSTickISR(void);


void Sleep(INT16U uSec)
{
	OSTimeDly((INT16U) (uSec));
}

void Task1(void * pParam)
{
	timer_init();
	timer_start();	
	while(1)	
	{
		printf( "@\n" );
		printf( "@\n" );
		printf( "@ task 1 running ... \n" );
		printf( "@    Q__Q    \n" );
		printf( "@   /____\\   \n" );
		printf( "@   \\____/   \n" );
		printf( "@    /\\/\\    \n" );
		printf( "@ __(\\\\//)__ \n" );
		printf( "@ >__/ww\\__< \n" );
		printf( "@\n" );
		printf( "@ go to sleep 10 time-ticks\n" );
		printf( "@\n" );
		printf( "@\n" );
		Sleep(2);
	}

}

/* Task2 print_user_input */
void Task2(void * pParam)
{
	while(1)	
	{
		printf( "+++ \n" );
		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" );
		printf( "+++ \n" );
		Sleep(2);
	}
}


#define	N_TASKS			3	// 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 C_Entry( void )
{
	int	task_1 = 0;
	int	task_2 = 1;
	counter = 0;
	printf( "start kernel ok!\n" );
	irq_installhandler ((unsigned)OSTickISR, IRQVector);
	
	OSInit();
	
	OSTaskCreate(Task1, &task_1, &TaskStk[0][TASK_STK_SIZE-1], 0);
	OSTaskCreate(Task2, &task_2, &TaskStk[1][TASK_STK_SIZE-1], 1);
	
	OSStart();
}
	

⌨️ 快捷键说明

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