【OK210试用体验】第四弹 手动写 uCOS II 的移植程序 - 在线问答 - 电子技术论坛 - 最好最受欢迎电子论坛!

【OK210试用体验】第四弹 手动写 uCOS II 的移植程序

陌路绝途 ( 楼主 ) 2015-8-8 21:04:20  显示全部楼层
#include "all.h"


OS_STK  InitTaskStk[1024];
OS_STK  MyTaskStk1[1024];
OS_STK  MyTaskStk2[1024];


static void MyTask1(void *parg)
{
        
        Uart_Printf("MyTaskStartn");
        
        while (1) {
                OSTimeDly(100);
               Uart_Printf("An");
        }        
}

static void MyTask2(void *parg)
{

        while (1) {
               Uart_Printf("Bn");
                OSTimeDly(68);
        }        
        
}


extern void print_cpuinfo(void);

void InitTask(void *parg)
{
                parg = parg ;
               Uart_Printf("Initn");
                //
初始化代码段
                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("       ccStartn");
        
        inerrupt_vector_init();
        s3c2416_memcpy((void *)0xffff0000, (void*)(exception_vector), 128);

        MMU_EnableDCache();
        MMU_EnableICache();        
        
        Uart_Printf("Startn");
        
        
        OSInit();
        InitTaskStart();
        
        OSStart();  

}


#include


extern INT32U get_PCLK(void);

static void timer_0_ISRService(void)
{
        SRCPND_REG |= (0x01<<10);                       /* write 1 toclear */
        INTPND_REG |= (0x01<<10);                       /* write 1 toclear */
        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 'manualupdate', note page 297*/
        TCON_REG |= 0x09;                       /* 1001-- auto reload, starttimer0 */
}

1个回复

燕小飞 发表于 2015-8-10 17:25:31
谢谢分享!!!
回复

举报 使用道具

您需要登录后才可以回帖 登录 | 注册

本版积分规则


关闭

站长推荐上一条 /6 下一条

小黑屋|手机版|Archiver|电子发烧友 ( 湘ICP备2023018690号 )

GMT+8, 2024-3-29 18:37 , Processed in 0.554916 second(s), Total 61, Slave 43 queries .

Powered by 电子发烧友网

© 2015 bbs.elecfans.com

微信扫描
快速回复 返回顶部 返回列表