?? main_entry.c
字號:
#include"s3c4510b_add.h"
#include "includes.h"
void InitUART(int Port,int Baudrate);
void PrintUART(int Port,char *s);
#define SYSCFG 0x03ff0000
#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 extern TimeISR(void);
unsigned Install_Handle(unsigned routine,unsigned *vector);
void UART0_Write(int Port,char c);
void Sleep(INT16U uSec)
{
OSTimeDly((INT16U) (uSec));
}
void Task1(void * pParam)
{
INTMSK=0x1ffbff;
while(1)
{
IOPMOD=0xff;
IOPDATA=0xff;
PrintUART(1,"@\n" );
UART0_Write(1,0x0d);
UART0_Write(1,0x0a);
PrintUART(1,"@\n" );
UART0_Write(1,0x0d);
UART0_Write(1,0x0a);
PrintUART(1,"@ task 1 running ... \n" );
UART0_Write(1,0x0d);
UART0_Write(1,0x0a);
PrintUART(1,"@ Q__Q \n" );
UART0_Write(1,0x0d);
UART0_Write(1,0x0a);
PrintUART(1,"@ /____\\ \n" );
UART0_Write(1,0x0d);
UART0_Write(1,0x0a);
PrintUART(1,"@ \\____/ \n" );
UART0_Write(1,0x0d);
UART0_Write(1,0x0a);
PrintUART(1,"@ /\\/\\ \n" );
UART0_Write(1,0x0d);
UART0_Write(1,0x0a);
PrintUART(1,"@ __(\\\\//)__ \n" );
UART0_Write(1,0x0d);
UART0_Write(1,0x0a);
PrintUART(1,"@ >__/ww\\__< \n" );
UART0_Write(1,0x0d);
UART0_Write(1,0x0a);
PrintUART(1,"@\n" );
UART0_Write(1,0x0d);
UART0_Write(1,0x0a);
PrintUART(1,"@ go to sleep 10 time-ticks\n" );
UART0_Write(1,0x0d);
UART0_Write(1,0x0a);
PrintUART(1,"@\n" );
UART0_Write(1,0x0d);
UART0_Write(1,0x0a);
PrintUART(1,"@\n" );
UART0_Write(1,0x0d);
UART0_Write(1,0x0a);
Sleep(5);
}
}
/* Task2 print_user_input */
void Task2(void * pParam)
{
while(1)
{
PrintUART(1,"+++ \n" );
UART0_Write(1,0x0d);
UART0_Write(1,0x0a);
PrintUART(1,"+++ \n" );
UART0_Write(1,0x0d);
UART0_Write(1,0x0a);
PrintUART(1,"+++ task 2 running ... \n" );
UART0_Write(1,0x0d);
UART0_Write(1,0x0a);
PrintUART(1,"+++ ╭︿︿︿╮ \n" );
UART0_Write(1,0x0d);
UART0_Write(1,0x0a);
PrintUART(1,"+++ {/ o o \\} \n" );
UART0_Write(1,0x0d);
UART0_Write(1,0x0a);
PrintUART(1,"+++ ( (oo) ) \n" );
UART0_Write(1,0x0d);
UART0_Write(1,0x0a);
PrintUART(1,"+++ ︶ \n" );
UART0_Write(1,0x0d);
UART0_Write(1,0x0a);
PrintUART(1,"+++ \n" );
UART0_Write(1,0x0d);
UART0_Write(1,0x0a);
PrintUART(1,"+++ go to sleep 5 time-ticks\n" );
UART0_Write(1,0x0d);
UART0_Write(1,0x0a);
PrintUART(1,"+++ \n" );
UART0_Write(1,0x0d);
UART0_Write(1,0x0a);
PrintUART(1,"+++ \n" );
UART0_Write(1,0x0d);
UART0_Write(1,0x0a);
Sleep(6);
}
}
#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 extern C_Entry(void)
{
int task_1 = 0;
int task_2 = 1;
unsigned *irqvec=(unsigned*)0x18;
Install_Handle((unsigned)TimeISR,irqvec);
InitUART(1,0x500); //19200bps 50MHz 0=COM1;1=COM2
counter = 0;
PrintUART(1,"start kernel ok!\n" );
UART0_Write(1,0x0d);
UART0_Write(1,0x0a);
OSInit();
OSTaskCreate(Task1, &task_1, &TaskStk[0][TASK_STK_SIZE-1], 6);
OSTaskCreate(Task2, &task_2, &TaskStk[1][TASK_STK_SIZE-1], 5);
OSStart();
}
void PrintUART(int Port,char *s)
{
if(Port==0)
for(;*s!='\0';s++)
{
for(;(!(USTAT0&0x40)););
UTXBUF0=*s;
}
if(Port==1)
for(;*s!='\0';s++)
{
for(;(!(USTAT1&0x40)););
UTXBUF1=*s;
}
}
void InitUART(int Port,int Baudrate)
{
if(Port==0)
{
ULCON0=0x03;
UCON0=0x09;
UBRDIV0=Baudrate;
}
if(Port==1)
{
ULCON1=0x03;
UCON1=0x09;
UBRDIV1=Baudrate;
}
}
void UART0_Write(int Port,char c)
{
if(Port==0)
while(!(USTAT0&0x40));
UTXBUF0=c;
if(Port==1)
while(!(USTAT1&0x40));
UTXBUF1=c;
}
unsigned Install_Handle(unsigned routine,unsigned *vector)
{
unsigned vec,oldvect;
vec=((routine-(unsigned)vector-0x8)>>2);
if(vec&0xff000000)
{
}
vec=0xea000000|vec;
oldvect=*vector;
*vector=vec;
return(oldvect);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -