CubeMX之FreeRTOS学习day02

开发环境:CubeMX Version:5.6.1
Keil:Version:V5.31.0
FreeRTOS: V2.0参考API连接

软件定时器:

/* Definitions for myTimer_TreatTime */
osTimerId_t myTimer_TreatTimeHandle;
const osTimerAttr_t myTimer_TreatTime_attributes = {
  .name = "myTimer_TreatTime"
};

myTimer_TreatTimeHandle = osTimerNew(Callback_TreatTime, osTimerPeriodic, NULL, &myTimer_TreatTime_attributes);

osTimerStart (myTimer_TreatTimeHandle, 1000);//开启定时器

New之后直接开启,然后就会在CallBack函数中定时处理:

/* Callback_TreatTime function */
void Callback_TreatTime(void *argument)
{
  /* USER CODE BEGIN Callback_TreatTime */
	Treat_Time_Sec--;
	if(Treat_Time_Sec<0)
	{
		Treat_Time_Sec = 60;
		Magnetic.Treat_Time_Value-=2;
	}
	printf("Treat_Time_Min:%dTreat_Time_Sec:%d\r\n",Magnetic.Treat_Time_Value/2,Treat_Time_Sec);
  /* USER CODE END Callback_TreatTime */
}

参考API:

osTimerNew (osTimerFunc_t func, osTimerType_t type, void *argument, const osTimerAttr_t *attr)//新建
osTimerStart (osTimerId_t timer_id, uint32_t ticks)//开启,ticks调用时长,单位为ms
osTimerStop (osTimerId_t timer_id)//停止
osTimerIsRunning (osTimerId_t timer_id)//是否运行
osTimerDelete (osTimerId_t timer_id)//删除
const char *osTimerGetName (osTimerId_t timer_id)//获取定时器名字
posted @ 2020-11-12 10:32  火红色祥云  阅读(35)  评论(0编辑  收藏  举报