【项目笔记:RP453】天线端程序结构的梳理(链表的使用)

程序逻辑的梳理

在这里插入图片描述

  • 上面的逻辑优化: 将SPI处理线程与RF出现线程合并掉
    整理之后得逻辑时序图如下:(黑色为接收缓存,红色为发送缓存)
    在这里插入图片描述

对应的软件缓存操作的链表与缓存的结构定义如下:

  rbuf_t rbuf[SPI_RBUF_SZIE + 1];  /* 接收缓存 */
  tbuf_t tbuf[SPI_RBUF_SZIE + 1];  /* 发送缓存 */
  node_t rbuf_node[SPI_RBUF_SZIE]; /* 接收缓存节点 */
  node_t tbuf_node[SPI_RBUF_SZIE]; /* 发送缓存节点 */
  list_t s0_rbuf_list;             /* 未使用 SPI 接收缓存 */
  list_t spi_rbuf_list;            /* 中断接收 */
  list_t rf_rbuf_list;             /* 待处理 RF 缓存数据 */
  list_t s0_tbuf_list;             /* 未使用 SPI 发送缓存 */
  list_t spi_tbuf_list;            /* 处理好等待发送 SPI 缓存 */

程序核心代码

核心数据结构

struct node
{
  struct node *next; /**< point to next node. */
  struct node *prev; /**< point to prev node. */
  uint8_t *pbuf;
};

typedef struct node node_t; /**< Type for lists. */
typedef struct node list_t; /**< Type for lists. */

核心函数

void list_init(list_t *l)
{
  l->next = l->prev = l;
}

void list_insert_after(list_t *l, node_t *n)
{
  __set_PRIMASK(1);
  l->next->prev = n;
  n->next = l->next;

  l->next = n;
  n->prev = l;
  __set_PRIMASK(0);
}

void list_insert_before(list_t *l, node_t *n)
{
  __set_PRIMASK(1);
  l->prev->next = n;
  n->prev = l->prev;

  l->prev = n;
  n->next = l;
  __set_PRIMASK(0);
}

void list_remove(list_t *n)
{
  __set_PRIMASK(1);
  n->next->prev = n->prev;
  n->prev->next = n->next;
  n->next = n->prev = n;
  __set_PRIMASK(0);
}

uint32_t list_isempty(const list_t *l)
{
  return l->next == l;
}

uint32_t list_len(const list_t *l)
{
  __set_PRIMASK(1);
  uint32_t len = 0;
  const list_t *p = l;
  while (p->next != l)
  {
    p = p->next;
    len++;
  }
  __set_PRIMASK(0);
  return len;
}

核心操作

移除节点
    node_t *c_node;
    c_node = spi_tcb.spi_rbuf_list.next;
    list_remove(spi_tcb.spi_rbuf_list.next);
添加节点
    list_insert_before(&spi_tcb.spi_tbuf_list, c_node);
转接节点

从 rf_rbuf_list 移除头结点转接到 s0_rbuf_list 尾节点上默认拼接采用FIFO的方式操作

  node_t *c_node = spi_tcb.rf_rbuf_list.next;
  list_remove(spi_tcb.rf_rbuf_list.next);
  list_insert_before(&spi_tcb.s0_rbuf_list, (node_t *)c_node);

调试操作的显示如下:

    LIST_BUF_LOG("[%s] rlist:[i:%2d r:%2d d:%2d] tlist:[u:%2d t:%2d]\n",
                 tag, list_len(&spi_tcb.s0_rbuf_list), list_len(&spi_tcb.spi_rbuf_list),
                 list_len(&spi_tcb.rf_rbuf_list), list_len(&spi_tcb.s0_tbuf_list),
                 list_len(&spi_tcb.spi_tbuf_list));

调试操作的对应的输出如下:
在这里插入图片描述
从日志中可以看到数据节点在不同的链表上面流转。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值