Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions L2_Core/hal/src/ek_hal_adc.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void ek_hal_adc_register(ek_hal_adc_t *const dev, const char *name, const ek_adc
dev->ops = ops;
dev->dev_info = dev_info;
dev->lock = false;
ek_list_add_tail(&ek_hal_adc_head, &dev->node);
ek_list_insert_tail(&ek_hal_adc_head, &dev->node);

dev->ops->init(dev);
}
Expand All @@ -42,7 +42,7 @@ ek_hal_adc_t *ek_hal_adc_find(const char *name)
ek_assert_param(name != NULL);

ek_list_node_t *p;
ek_list_iterate(p, &ek_hal_adc_head)
ek_list_foreach(p, &ek_hal_adc_head)
{
ek_hal_adc_t *dev = ek_list_container(p, ek_hal_adc_t, node);

Expand Down
4 changes: 2 additions & 2 deletions L2_Core/hal/src/ek_hal_dac.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void ek_hal_dac_register(ek_hal_dac_t *const dev, const char *name, const ek_dac
dev->ops = ops;
dev->dev_info = dev_info;
dev->lock = false;
ek_list_add_tail(&ek_hal_dac_head, &dev->node);
ek_list_insert_tail(&ek_hal_dac_head, &dev->node);

dev->ops->init(dev);
}
Expand All @@ -42,7 +42,7 @@ ek_hal_dac_t *ek_hal_dac_find(const char *name)
ek_assert_param(name != NULL);

ek_list_node_t *p;
ek_list_iterate(p, &ek_hal_dac_head)
ek_list_foreach(p, &ek_hal_dac_head)
{
ek_hal_dac_t *dev = ek_list_container(p, ek_hal_dac_t, node);

Expand Down
4 changes: 2 additions & 2 deletions L2_Core/hal/src/ek_hal_dma.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void ek_hal_dma_register(ek_hal_dma_t *const dev, const char *name, const ek_dma
dev->ops = ops;
dev->dev_info = dev_info;
dev->lock = false;
ek_list_add_tail(&ek_hal_dma_head, &dev->node);
ek_list_insert_tail(&ek_hal_dma_head, &dev->node);

dev->ops->init(dev);
}
Expand All @@ -42,7 +42,7 @@ ek_hal_dma_t *ek_hal_dma_find(const char *name)
ek_assert_param(name != NULL);

ek_list_node_t *p;
ek_list_iterate(p, &ek_hal_dma_head)
ek_list_foreach(p, &ek_hal_dma_head)
{
ek_hal_dma_t *dev = ek_list_container(p, ek_hal_dma_t, node);

Expand Down
4 changes: 2 additions & 2 deletions L2_Core/hal/src/ek_hal_dma2d.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ void ek_hal_dma2d_register(ek_hal_dma2d_t *const dev, const char *name, const ek
dev->name = name;
dev->ops = ops;
dev->dev_info = dev_info;
ek_list_add_tail(&ek_hal_dma2d_head, &dev->node);
ek_list_insert_tail(&ek_hal_dma2d_head, &dev->node);

dev->ops->init(dev);
}
Expand All @@ -41,7 +41,7 @@ ek_hal_dma2d_t *ek_hal_dma2d_find(const char *name)
ek_assert_param(name != NULL);

ek_list_node_t *p;
ek_list_iterate(p, &ek_hal_dma2d_head)
ek_list_foreach(p, &ek_hal_dma2d_head)
{
ek_hal_dma2d_t *dev = ek_list_container(p, ek_hal_dma2d_t, node);

Expand Down
4 changes: 2 additions & 2 deletions L2_Core/hal/src/ek_hal_gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void ek_hal_gpio_register(
dev->mode = mode;
dev->ops = ops;
dev->dev_info = dev_info;
ek_list_add_tail(&ek_hal_gpio_head, &dev->node);
ek_list_insert_tail(&ek_hal_gpio_head, &dev->node);

dev->ops->init(dev, mode);
dev->status = dev->ops->read(dev);
Expand All @@ -46,7 +46,7 @@ ek_hal_gpio_t *ek_hal_gpio_find(const char *name)
ek_assert_param(name != NULL);

ek_list_node_t *p;
ek_list_iterate(p, &ek_hal_gpio_head)
ek_list_foreach(p, &ek_hal_gpio_head)
{
ek_hal_gpio_t *dev = ek_list_container(p, ek_hal_gpio_t, node);

Expand Down
4 changes: 2 additions & 2 deletions L2_Core/hal/src/ek_hal_i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void ek_hal_i2c_register(ek_hal_i2c_t *const dev, const char *name, const ek_i2c
dev->ops = ops;
dev->dev_info = dev_info;
dev->lock = false;
ek_list_add_tail(&ek_hal_i2c_head, &dev->node);
ek_list_insert_tail(&ek_hal_i2c_head, &dev->node);

dev->ops->init(dev);
}
Expand All @@ -42,7 +42,7 @@ ek_hal_i2c_t *ek_hal_i2c_find(const char *name)
ek_assert_param(name != NULL);

ek_list_node_t *p;
ek_list_iterate(p, &ek_hal_i2c_head)
ek_list_foreach(p, &ek_hal_i2c_head)
{
ek_hal_i2c_t *dev = ek_list_container(p, ek_hal_i2c_t, node);

Expand Down
4 changes: 2 additions & 2 deletions L2_Core/hal/src/ek_hal_ltdc.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ void ek_hal_ltdc_register(ek_hal_ltdc_t *const dev, const char *name, const ek_l
dev->name = name;
dev->ops = ops;
dev->dev_info = dev_info;
ek_list_add_tail(&ek_hal_ltdc_head, &dev->node);
ek_list_insert_tail(&ek_hal_ltdc_head, &dev->node);

dev->ops->init(dev);
}
Expand All @@ -41,7 +41,7 @@ ek_hal_ltdc_t *ek_hal_ltdc_find(const char *name)
ek_assert_param(name != NULL);

ek_list_node_t *p;
ek_list_iterate(p, &ek_hal_ltdc_head)
ek_list_foreach(p, &ek_hal_ltdc_head)
{
ek_hal_ltdc_t *dev = ek_list_container(p, ek_hal_ltdc_t, node);

Expand Down
4 changes: 2 additions & 2 deletions L2_Core/hal/src/ek_hal_pwm.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void ek_hal_pwm_register(ek_hal_pwm_t *const dev, const char *name, const ek_pwm
dev->ops = ops;
dev->dev_info = dev_info;
dev->lock = false;
ek_list_add_tail(&ek_hal_pwm_head, &dev->node);
ek_list_insert_tail(&ek_hal_pwm_head, &dev->node);

dev->ops->init(dev);
}
Expand All @@ -42,7 +42,7 @@ ek_hal_pwm_t *ek_hal_pwm_find(const char *name)
ek_assert_param(name != NULL);

ek_list_node_t *p;
ek_list_iterate(p, &ek_hal_pwm_head)
ek_list_foreach(p, &ek_hal_pwm_head)
{
ek_hal_pwm_t *dev = ek_list_container(p, ek_hal_pwm_t, node);

Expand Down
4 changes: 2 additions & 2 deletions L2_Core/hal/src/ek_hal_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void ek_hal_spi_register(ek_hal_spi_t *const dev, const char *name, const ek_spi
dev->ops = ops;
dev->dev_info = dev_info;
dev->lock = false;
ek_list_add_tail(&ek_hal_spi_head, &dev->node);
ek_list_insert_tail(&ek_hal_spi_head, &dev->node);

dev->ops->init(dev);
}
Expand All @@ -42,7 +42,7 @@ ek_hal_spi_t *ek_hal_spi_find(const char *name)
ek_assert_param(name != NULL);

ek_list_node_t *p;
ek_list_iterate(p, &ek_hal_spi_head)
ek_list_foreach(p, &ek_hal_spi_head)
{
ek_hal_spi_t *dev = ek_list_container(p, ek_hal_spi_t, node);

Expand Down
4 changes: 2 additions & 2 deletions L2_Core/hal/src/ek_hal_tick.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ void ek_hal_tick_register(ek_hal_tick_t *const dev, const char *name, const ek_t
dev->name = name;
dev->ops = ops;
dev->dev_info = dev_info;
ek_list_add_tail(&ek_hal_tick_head, &dev->node);
ek_list_insert_tail(&ek_hal_tick_head, &dev->node);

dev->ops->init(dev);
}
Expand All @@ -41,7 +41,7 @@ ek_hal_tick_t *ek_hal_tick_find(const char *name)
ek_assert_param(name != NULL);

ek_list_node_t *p;
ek_list_iterate(p, &ek_hal_tick_head)
ek_list_foreach(p, &ek_hal_tick_head)
{
ek_hal_tick_t *dev = ek_list_container(p, ek_hal_tick_t, node);

Expand Down
4 changes: 2 additions & 2 deletions L2_Core/hal/src/ek_hal_tim.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void ek_hal_tim_register(ek_hal_tim_base_t *const dev, const char *name, const e
dev->ops = ops;
dev->dev_info = dev_info;
dev->state = EK_HAL_TIM_STATE_STP;
ek_list_add_tail(&ek_hal_tim_head, &dev->node);
ek_list_insert_tail(&ek_hal_tim_head, &dev->node);

dev->ops->init(dev);
}
Expand All @@ -42,7 +42,7 @@ ek_hal_tim_base_t *ek_hal_tim_find(const char *name)
ek_assert_param(name != NULL);

ek_list_node_t *p;
ek_list_iterate(p, &ek_hal_tim_head)
ek_list_foreach(p, &ek_hal_tim_head)
{
ek_hal_tim_base_t *dev = ek_list_container(p, ek_hal_tim_base_t, node);

Expand Down
4 changes: 2 additions & 2 deletions L2_Core/hal/src/ek_hal_uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ void ek_hal_uart_register(ek_hal_uart_t *const dev, const char *name, const ek_u
dev->ops = ops;
dev->dev_info = dev_info;
dev->lock = false;
ek_list_add_tail(&ek_hal_uart_head, &dev->node);
ek_list_insert_tail(&ek_hal_uart_head, &dev->node);

dev->ops->init(dev);
}
Expand All @@ -42,7 +42,7 @@ ek_hal_uart_t *ek_hal_uart_find(const char *name)
ek_assert_param(name != NULL);

ek_list_node_t *p;
ek_list_iterate(p, &ek_hal_uart_head)
ek_list_foreach(p, &ek_hal_uart_head)
{
ek_hal_uart_t *dev = ek_list_container(p, ek_hal_uart_t, node);

Expand Down
8 changes: 4 additions & 4 deletions L2_Core/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,11 @@ typedef struct {
} my_node_t;

// 添加节点
ek_list_add_tail(&my_list, &node->node);
ek_list_insert_tail(&my_list, &node->node);

// 遍历链表
ek_list_node_t *pos;
ek_list_iterate(pos, &my_list) {
ek_list_foreach(pos, &my_list) {
my_node_t *n = ek_list_container(pos, my_node_t, node);
// 处理节点
}
Expand Down Expand Up @@ -482,13 +482,13 @@ void ek_hal_xxx_register(
dev->name = name;
dev->ops = ops;
dev->dev_info = dev_info;
ek_list_add_tail(&ek_hal_xxx_head, &dev->node);
ek_list_insert_tail(&ek_hal_xxx_head, &dev->node);
}

ek_hal_xxx_t *ek_hal_xxx_find(const char *name)
{
ek_list_node_t *pos;
ek_list_iterate(pos, &ek_hal_xxx_head) {
ek_list_foreach(pos, &ek_hal_xxx_head) {
ek_hal_xxx_t *dev = ek_list_container(pos, ek_hal_xxx_t, node);
if (strcmp(dev->name, name) == 0) {
return dev;
Expand Down
22 changes: 11 additions & 11 deletions L2_Core/utils/inc/ek_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ struct ek_list_node_t
* @param pos 当前节点指针(迭代变量)
* @param head 链表头节点
*
* @warning 遍历过程中不能删除当前节点,否则使用 ek_list_iterate_safe
* @warning 遍历过程中不能删除当前节点,否则使用 ek_list_foreach_safe
*/
#define ek_list_iterate(pos, head) \
#define ek_list_foreach(pos, head) \
for (pos = (head)->next; pos != (head); pos = pos->next)

/**
Expand All @@ -62,7 +62,7 @@ struct ek_list_node_t
* @param n 临时节点指针(保存下一个节点)
* @param head 链表头节点
*/
#define ek_list_iterate_safe(pos, n, head) \
#define ek_list_foreach_safe(pos, n, head) \
for (pos = (head)->next, n = pos->next; pos != (head); pos = n, n = pos->next)

Copilot AI Apr 3, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ek_list_iterate/ek_list_iterate_safe 被直接改名为 ek_list_foreach/ek_list_foreach_safe,旧宏在头文件中不再提供,会导致任何依赖旧 API 的外部代码直接编译失败。建议至少保留旧名字作为兼容别名(可加弃用标记/注释),或在版本/变更说明中明确这是破坏性变更。

Suggested change
/**
* @brief 兼容旧 API 的遍历别名
* @note 新代码请优先使用 ek_list_foreach
*/
#define ek_list_iterate(pos, head) ek_list_foreach(pos, head)
/**
* @brief 兼容旧 API 的安全遍历别名
* @note 新代码请优先使用 ek_list_foreach_safe
*/
#define ek_list_iterate_safe(pos, n, head) ek_list_foreach_safe(pos, n, head)

Copilot uses AI. Check for mistakes.
/* clang-format on */
Expand All @@ -85,7 +85,7 @@ __EK_STATIC_INLINE void ek_list_init(ek_list_node_t *head)
* @param prev 前一个节点(插入位置之前)
* @param next 后一个节点(插入位置之后)
*/
__EK_STATIC_INLINE void __ek_list_add(ek_list_node_t *new_node, ek_list_node_t *prev, ek_list_node_t *next)
__EK_STATIC_INLINE void _ek_list_insert(ek_list_node_t *new_node, ek_list_node_t *prev, ek_list_node_t *next)
{
prev->next = new_node;
new_node->next = next;
Expand All @@ -98,27 +98,27 @@ __EK_STATIC_INLINE void __ek_list_add(ek_list_node_t *new_node, ek_list_node_t *
* @param head 链表头节点指针
* @param new_node 要添加的新节点
*/
__EK_STATIC_INLINE void ek_list_add_head(ek_list_node_t *head, ek_list_node_t *new_node)
__EK_STATIC_INLINE void ek_list_insert_head(ek_list_node_t *head, ek_list_node_t *new_node)
{
__ek_list_add(new_node, head, head->next);
_ek_list_insert(new_node, head, head->next);
}

/**
* @brief 在链表尾部添加节点
* @param head 链表头节点指针
* @param new_node 要添加的新节点
*/
__EK_STATIC_INLINE void ek_list_add_tail(ek_list_node_t *head, ek_list_node_t *new_node)
__EK_STATIC_INLINE void ek_list_insert_tail(ek_list_node_t *head, ek_list_node_t *new_node)
{
__ek_list_add(new_node, head->prev, head);
_ek_list_insert(new_node, head->prev, head);
}

/**
* @brief 内部函数:断开两个节点之间的连接
* @param prev 前一个节点
* @param next 后一个节点
*/
__EK_STATIC_INLINE void __ek_list_remove(ek_list_node_t *prev, ek_list_node_t *next)
__EK_STATIC_INLINE void _ek_list_remove(ek_list_node_t *prev, ek_list_node_t *next)
{
next->prev = prev;
prev->next = next;
Expand All @@ -132,7 +132,7 @@ __EK_STATIC_INLINE void __ek_list_remove(ek_list_node_t *prev, ek_list_node_t *n
*/
__EK_STATIC_INLINE void ek_list_remove(ek_list_node_t *remove)
{
__ek_list_remove(remove->prev, remove->next);
_ek_list_remove(remove->prev, remove->next);
remove->prev = NULL;
remove->next = NULL;
}
Expand All @@ -143,7 +143,7 @@ __EK_STATIC_INLINE void ek_list_remove(ek_list_node_t *remove)
* @return true 链表为空
* @return false 链表非空
*/
__EK_STATIC_INLINE bool ek_list_empty(ek_list_node_t *head)
__EK_STATIC_INLINE bool ek_list_is_empty(ek_list_node_t *head)
{
return head->next == head;
}
Comment on lines +146 to 149

Copilot AI Apr 3, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ek_list_empty 被改为 ek_list_is_empty,不仅是破坏性改动,也与仓库内其它容器命名不一致(例如 ek_ringbuf_emptyek_stack_empty)。建议保留 ek_list_empty 作为兼容别名,或继续沿用 _empty 命名以保持一致性。

Copilot uses AI. Check for mistakes.
Expand Down
Loading