#include "all.h"
OS_STK InitTaskStk[1024];
OS_STK MyTaskStk1[1024];
OS_STK MyTaskStk2[1024];
static void MyTask1(void *parg)
{
Uart_Printf("MyTaskStart\n");
while (1) {
OSTimeDly(100);
Uart_Printf("A\n");
}
}
static void MyTask2(void *parg)
{
while (1) {
Uart_Printf("B\n");
OSTimeDly(68);
}
}
extern void print_cpuinfo(void);
void InitTask(void *parg)
{
parg = parg ;
Uart_Printf("Init\n");
//初始化代码段
Uart_0_Init();
timer_0_init();
print_cpuinfo(); //打印CPU信息
//任务创建
OSTaskCreate(MyTask1, (void *)1, (void *)&MyTaskStk1[1023], 4);
OSTaskCreate(MyTask2, (void *)2, (void *)&MyTaskStk2[1023], 8);
OSTaskDel(OSPrioCur);
}
void InitTaskStart(void)
{
OSTaskCreate(InitTask, (void *)0, (void *)&InitTaskStk[1023], 1); //创建优先级为0的任务
}
#include "all.h"
#include
#include
#include
#include
#include
void Uart_Printf(char *fmt,...)
{
va_list ap;
char string[1024];
va_start(ap,fmt);
vsprintf(string,fmt,ap);
va_end(ap);
Uart_0_SendString(string); //default send from uart0
}
void Uart_0_Init(void)
{
/*init GPIO*/
GPHCON &= ~(0xf);
GPHCON |= 0xa;
/*uart registers*/
ULCON0_REG = 0x3;
UFCON0_REG = (0xa << 4) | 0x7;
UMCON0_REG = 0;
UBRDIV0_REG = 35;
UDIVSLOT0_REG = 0x0888;
UCON0_REG = 0x5|(0x1 << 7)|(0x2 << 10);
}
void Uart_0_SendByte(char b)
{
while (!(UTRSTAT0_REG & 0x2));
UTXH0_REG = b;
}
void Uart_0_SendString(char *s)
{
char *tmp = s;
while (*tmp) {
if ('\n' == (char)*tmp) {
Uart_0_SendByte('\r');
}
Uart_0_SendByte(*tmp);
++tmp;
}
}
char Uart_0_ReceiveByte(void)
{
return URXH0_REG;
}
//Uart的中断接受程序没有写,用户自己添加
#include "all.h"
extern void inerrupt_vector_init(void);
extern void exception_vector(void);
extern void MMU_EnableDCache(void);
extern void MMU_EnableICache(void);
extern void MMU_DisableMMU(void);
extern void read_cpsr(void);
extern void InitTaskStart(void);
extern void make_mmu_table (void);
void Main()
{
Uart_Printf(" ccStart\n");
inerrupt_vector_init();
s3c2416_memcpy((void *)0xffff0000, (void *)(exception_vector), 128);
MMU_EnableDCache();
MMU_EnableICache();
Uart_Printf("Start\n");
OSInit();
InitTaskStart();
OSStart();
}
#include
extern INT32U get_PCLK(void);
static void timer_0_ISRService(void)
{
SRCPND_REG |= (0x01<<10); /* write 1 to clear */
INTPND_REG |= (0x01<<10); /* write 1 to clear */
OSTimeTick();
}
static void timer_0_ISRInit(void)
{
INTMOD_REG = 0x00000000;
PRIORITY_MODE_REG = 0x00000000;
INTMSK_REG &= ~(0x01<<10); /* set timer0 interrupt available */
}
/*
*Tclk = PCLK/{precaler+1}/{divider value}
*precaler = PCLK/{Tclk*{divider value}} - 1
*/
void timer_0_init(void)
{
TCON_REG &= ~0x0F; /* default timer0*/
TCFG0_REG &= ~0xFF;
TCFG1_REG &= ~0x0F;
timer_0_ISRInit();
register_irq(10, timer_0_ISRService);
TCFG0_REG |= 15; /* prescaler: 15 */
TCFG1_REG |= 0x01; /* divider value :1/4*/
TCNTB0_REG = get_PCLK()/(15*4*OS_TICKS_PER_SEC) - 1;
TCON_REG |= 0x02; /* update TCNTB0&TCMPB0 */
TCON_REG &= ~0x02; /* must clear 'manual update', note page 297*/
TCON_REG |= 0x09; /* 1001-- auto reload, start timer0 */
}