代码拉取完成,页面将自动刷新
同步操作将从 eric.pyt/xTimer 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
/**
* @file xtimer.c
* @author eric
* @brief
* @version 0.1
* @date 2022-04-16
*
* @copyright Copyright (c) 2022
*
*/
#include <stdio.h>
#include "xtimer.h"
static int head_inited = 0;
static struct list_head head;
int xtimer_start(xtimer_t *timer)
{
list_node_t *node = NULL;
int find = -1;
if (head_inited == 0)
{
printf("[%s] %d: \r\n", __func__, __LINE__);
INIT_LIST_HEAD(&head);
head_inited = 1;
}
/* Find the same??? */
list_for_each_entry(node, &head, list, xtimer_t)
{
if (node == timer) /* restart */
{
find = 0;
node->start = xtimer_get_tick();
}
}
/* add new */
if (find != 0)
{
timer->start = xtimer_get_tick();
list_add(&timer->list, &head);
}
return 0;
}
int xtimer_stop(xtimer_t *timer)
{
list_node_t *node = NULL;
list_node_t *n = NULL;
int find = -1;
if (head_inited == 0)
{
return -404;
}
list_for_each_entry_safe(node, n, &head, list, xtimer_t)
{
if (node == timer)
{
find = 0;
list_del(&node->list);
}
}
return find;
}
int xtimer_isvalid(xtimer_t *timer)
{
list_node_t *node = NULL;
int find = -1;
if (head_inited == 0)
{
return -404;
}
list_for_each_entry(node, &head, list, xtimer_t)
{
if (node == timer)
{
find = 0;
}
}
return find;
}
int xtimer_remain(xtimer_t *timer)
{
if (timer == 0)
{
return -1;
}
uint32_t tick = xtimer_get_tick();
uint32_t remain = timer->timout - (tick - timer->start);
return remain;
}
void xtimer_loop(void)
{
list_node_t *node = NULL;
list_node_t *n = NULL;
uint32_t tick = 0;
if (head_inited == 0)
{
INIT_LIST_HEAD(&head);
head_inited = 1;
}
/* Find the same??? */
list_for_each_entry_safe(node, n, &head, list, xtimer_t)
{
tick = xtimer_get_tick();
if ((tick - node->start) > node->timout)
{
if (node->opt == XTIMER_SINGLE)
{
list_del(&node->list);
}
if (node->callback != NULL)
{
node->callback(node);
node->start = tick;
}
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。