//定时器1的回调函数 void tmr1_callback(void *p_tmr,void *p_arg) { u8 *pbuf; static u8 msg_num; OS_ERR err; pbuf = mymalloc(SRAMIN,10); //申请10个字节 if(pbuf) //申请内存成功 { msg_num++; sprintf((char*)pbuf,"ALIENTEK %d",msg_num); //发送消息 OSTaskQPost((OS_TCB* )&Msgdis_TaskTCB, //向任务Msgdis发送消息 (void* )pbuf, (OS_MSG_SIZE)10, (OS_OPT )OS_OPT_POST_FIFO, (OS_ERR* )&err); if(err != OS_ERR_NONE) { myfree(SRAMIN,pbuf); //释放内存 OSTmrStop(&tmr1,OS_OPT_TMR_NONE,0,&err); //停止定时器1 tmr1sta = !tmr1sta; LCD_ShowString(40,150,100,16,16,"TMR1 STOP! "); } } }
//主任务的任务函数 void main_task(void *p_arg) { u8 key,num; OS_ERR err; u8 *p; while(1) { key = KEY_Scan(0); //扫描按键 if(key==WKUP_PRES) { tmr1sta = !tmr1sta; if(tmr1sta) { OSTmrStart(&tmr1,&err); LCD_ShowString(40,150,100,16,16,"TMR1 START!"); } else { OSTmrStop(&tmr1,OS_OPT_TMR_NONE,0,&err); //停止定时器1 LCD_ShowString(40,150,100,16,16,"TMR1 STOP! "); } } num++; if(num%10==0) check_msg_queue(p);//检查DATA_Msg消息队列的容量 if(num==50) { num=0; LED0 = ~LED0; } OSTimeDlyHMSM(0,0,0,10,OS_OPT_TIME_PERIODIC,&err); //延时10ms } }
//Í£Ö¹¶¨Ê±Æ÷ int del_timer(timer_t *tmr) { INT8U perr; OS_TMR *tmr_t = tmr; if (tmr_t == 0) { p_err("del_timer tmr err"); return 0; } if(timer_pending(tmr)) { OSTmrStop(tmr_t, OS_TMR_OPT_NONE, 0, &perr); return 1; } OSTmrStop(tmr_t, OS_TMR_OPT_NONE, 0, &perr); return 0; }