|
osTimerId_t osTimerNew (osTimerFunc_t func, osTimerType_t type, void *argument, const osTimerAttr_t *attr) {
const char *name;
TimerHandle_t hTimer;
TimerCallback_t *callb;
UBaseType_t reload;
int32_t mem;
hTimer = NULL;
if (!IS_IRQ() && (func != NULL)) {
/* Allocate memory to store callback function and argument */
callb = pvPortMalloc (sizeof(TimerCallback_t));
if (callb != NULL) {
callb->func = func;
callb->arg = argument;
if (type == osTimerOnce) {
reload = pdFALSE;
} else {
reload = pdTRUE;
}
mem = -1;
name = NULL;
if (attr != NULL) {
if (attr->name != NULL) {
name = attr->name;
}
if ((attr->cb_mem != NULL) && (attr->cb_size >= sizeof(StaticTimer_t))) {
mem = 1;
}
else {
if ((attr->cb_mem == NULL) && (attr->cb_size == 0U)) {
mem = 0;
}
}
}
else {
mem = 0;
}
if (mem == 1) {
hTimer = xTimerCreateStatic (name, 1, reload, callb, TimerCallback, (StaticTimer_t *)attr->cb_mem);
}
else {
if (mem == 0) {
hTimer = xTimerCreate (name, 1, reload, callb, TimerCallback);
}
}
}
}
return ((osTimerId_t)hTimer);
}
TimerHandle_t xTimerCreate( const char * const pcTimerName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
const TickType_t xTimerPeriodInTicks,
const UBaseType_t uxAutoReload,
void * const pvTimerID,
TimerCallbackFunction_t pxCallbackFunction )
TimerHandle_t xTimerCreateStatic( const char * const pcTimerName, /*lint !e971 Unqualified char types are allowed for strings and single characters only. */
const TickType_t xTimerPeriodInTicks,
const UBaseType_t uxAutoReload,
void * const pvTimerID,
TimerCallbackFunction_t pxCallbackFunction,
StaticTimer_t *pxTimerBuffer )
发现cmsis osV2 创建定时器,为啥默认是1个tick呢,调用start时才会设置成用户想要的时间。
如果我程序初始化时候创建了一个定时器,但是暂时不想start,那不是一直在1ms调用用户的函数?这个会不会有问题呢?
osStatus_t osTimerStart (osTimerId_t timer_id, uint32_t ticks) {
TimerHandle_t hTimer = (TimerHandle_t)timer_id;
osStatus_t stat;
if (IS_IRQ()) {
stat = osErrorISR;
}
else if (hTimer == NULL) {
stat = osErrorParameter;
}
else {
if (xTimerChangePeriod (hTimer, ticks, 0) == pdPASS) {
stat = osOK;
} else {
stat = osErrorResource;
}
}
return (stat);
}
|
|