在线时间1 小时
UID3066848
注册时间2016-1-27
NXP金币0
该用户从未签到
新手上路

- 积分
- 20
- 最后登录
- 2016-2-19
|

楼主 |
发表于 2016-2-19 10:30:33
|
显示全部楼层
- static void MainTask(void *p_arg)
- {
- (void) p_arg; //转换成空指针,防止编译器错误
- // INIT_PIT();
-
- AppTickInit();
- EnableInterrupts;
- while(TRUE)
- {
- LED=~LED;
- a=a+1;
- OSTimeDlyHMSM(0, 0, 1,0);
-
- }
- }
- void main(void) {
-
-
- DisableInterrupts;
- INIT_PLL();
- INIT_LED();
-
- OSInit();
-
-
- /*OSTaskCreate( MainTask,
- (void *)0,
- &MainTaskStk[MAIN_TASK_STK_SIZE-1],
- MAIN_TASK_PRIO);*/
- Sys_CreateTask(TASK_ID_MAIN, MainTask, 0); //任务创建函数 返回值ret
-
-
-
-
-
-
-
- OSStart();
- }
复制代码- void INIT_PLL(void)
- {
- CLKSEL &= 0x7f; //set OSCCLK as sysclk
- PLLCTL &= 0x8F; //Disable PLL circuit
- CRGINT &= 0xDF;
-
- #if(BUS_CLOCK == 40000000)
- SYNR = 0x44;
- #elif(BUS_CLOCK == 80000000)
- SYNR = 0xC9;
- #elif(BUS_CLOCK == 24000000)
- SYNR = 0x42;
- #endif
- REFDV = 0x81; //PLLCLK=2×OSCCLK×(SYNR+1)/(REFDV+1)=80MHz ,fbus=40M
- PLLCTL =PLLCTL|0x70; //Enable PLL circuit
- asm NOP;
- asm NOP;
- while(!(CRGFLG&0x08)); //PLLCLK is Locked already
- CLKSEL |= 0x80; //set PLLCLK as sysclk
-
- }
- void INIT_PIT(void)
- {
- PITCFLMT=0X00; //禁用PIT模块
- PITCE_PCE0=1; //使能PIT定时器0通道
- PITMUX=0X00; //使用基准1计数
- PITMTLD0=199; //八位微定时器的模数递减计数器的装载初值 1
- PITLD0=1999; // 2 4dd (4DD+1)(FF+1)/64M=1ms
- PITINTE=0X01; //允许PIT通道0中断请求。
- PITCFLMT=0X80; //使能PIT模块
- }
- void INIT_LED(void)
- {
- LED_dir=0xff; //设置为输出
- LED=0b10101010; //点咩LED1
- }
- #define OS_TICK_OC_CNTS (BUS_CLOCK / OS_TICKS_PER_SEC)
- void AppTickInit (void)
- {
- TSCR1 = 0x80; //定时器使能位置位
- TIOS |= 0x80; //7通道输出比较
- TC7 = TCNT + OS_TICK_OC_CNTS;
- TCTL1 |= 0x40; //OC7输出翻转
- TIE |= 0x80; //使能通道7中断
-
- } [code]void OSCtxSw(void) //软中断服务子程序 实现用户级上下文切换,用汇编语言实现
- {
- __asm{
- ldaa $15 ;restored ppage;
- psha
- ldx OSTCBCur ; 3~, OSTCBCur->OSTCBStkPtr = Stack Pointer
- sts 0,x ; 3~
- }
-
- #if OS_CPU_HOOKS_EN > 0
- OSTaskSwHook(); /* 4~, Invoke user defined context switch hook */
- #endif
-
- __asm{
- ldx OSTCBHighRdy ; 3~, OSTCBCur = OSTCBHighRdy
- stx OSTCBCur ; 3~
- ldab OSPrioHighRdy ; 3~, OSPrioCur = OSPrioHighRdy
- stab OSPrioCur ; 3~
- ldx OSTCBCur
- lds 0,x ;3~, Load SP into 68HC12
- pula ;use ppage
- staa $15
- nop
- }
- }
- [code]/* use these definitions in plane of the vector table ('vectors') above */
- VECTOR 0 _Startup /* reset vector: this is the default entry point for a C/C++ application. */
- VECTOR 4 OSCtxSw
- VECTOR 15 OSTickISR
- VECTOR 66 PIT_ISR
复制代码 [/code]
[/code]
- OSTickISR:
- ldaa PPAGE ; 3~, Get current value of PPAGE register
- psha ; 2~, Push PPAGE register onto current task's stack
- inc OSIntNesting ; 4~, Notify uC/OS-II about ISR
- ldab OSIntNesting ; 4~, if (OSIntNesting == 1) {
- cmpb #$01 ; 2~
- bne OSTickISR1 ; 3~
- ldy OSTCBCur ; 3~, OSTCBCur->OSTCBStkPtr = Stack Pointer
- sts 0,y ; 3~, }
- OSTickISR1:
- call OSTickISR_Handler
- ; cli ; 2~, Enable interrupts to allow interrupt nesting
-
- call OSIntExit ; 6~+, Notify uC/OS-II about end of ISR
-
- pula ; 3~, Get value of PPAGE register
- staa PPAGE ; 3~, Store into CPU's PPAGE register
-
- rti ; 12~, Return from interrupt, no higher priority tasks ready.
- ULONG g_SysTick;
- void OSTickISR_Handler (void)
- {
- TFLG1 |= 0x80; /* Clear interrupt */
- TC7 += OS_TICK_OC_CNTS; /* Set TC7 to present time + OS_TICK_OC_CNTS */
-
- g_SysTick++;
-
- OSTimeTick(); /* Inform the OS about the Time Tick */
- }
-
- void PIT_ISR(void){
-
- OSIntEnter();
- asm cli;
-
- PITTF_PTF0=1;
- OSTimeTick(); /* Call uC/OS-II's OSTimeTick()*/
- //g_SysTick++;
- OSIntExit();
- }
复制代码 |
|