树莓派rp2040使用dma传输数据例子函数记录

void logic _analyse r _init (PIO pio , uint sm ,
uint pin _base , uint pin _count , float div) {
41 // Load a program to capture n pins . This
is just a single `in pins, n`
42 // instruction with a wrap .
43 uint16 _t capture _prog _instr = pio _encode _
in (pio _pins , pin _count );
44 struct pio _program capture _prog = {
45 . instructions = &capture _prog _instr ,
46 . length = 1 ,
47 . origin = -1
48 };
49 uint offset = pio _add _program (pio , &cap-
ture _prog );
50
51 // Configure state machine to loop over
this `in` instruction forever,
52 // with autopush enabled.
53 pio _sm _config c = pio _get _default _sm _con-
fig();
54 sm _config _set _in _pins(&c , pin _base);
55 sm _config _set _wrap (&c , offset , offset);
56 sm _config _set _clkdiv(&c , div);
57 // Note that we may push at a < 32 bit thr-
eshold if pin_count does not
58 // divide 32. We are using shift-to-right,
so the sample data ends up
59 // left-justified in the FIFO in this case,
with some zeroes at the LSBs .
60 sm _config _set _in _shift(&c , true , true ,
bits _packed _per _word(pin _count ));
61 sm _config _set _fifo _join(&c , PIO _FIFO _JOIN _
RX );
62 pio _sm _init (pio , sm , offset , &c);
63 }

下面是对这个函数程序的解释:

这段代码是一个用于初始化PIO(可编程输入/输出)逻辑分析器的函数。PIO可能是一个硬件抽象层,用于控制某种类型的可编程I/O硬件。以下是对代码的逐行解释:

 

void logic_analyser_init(PIO pio, uint sm, uint pin_base, uint pin_count, float div) {

这行定义了一个函数logic_analyser_init,它接受五个参数:PIO实例、状态机编号、引脚基础编号、引脚数量和一个浮点数(可能是时钟分频因子)。

uint16_t capture_prog_instr = pio_encode_in(pio_pins, pin_count);

这行代码使用pio_encode_in函数为PIO生成一个指令,该指令将捕获指定数量的引脚。

struct pio_program capture_prog = {

    .instructions = &capture_prog_instr,

    .length = 1,

    .origin = -1

};

这里定义了一个PIO程序,它只包含之前生成的单个指令。

uint offset = pio_add_program(pio, &capture_prog);

将捕获程序添加到PIO,并获取它在PIO程序空间中的偏移量。

pio_sm_config c = pio_get_default_sm_config();

获取PIO状态机的默认配置。

sm_config_set_in_pins(&c, pin_base)

设置状态机的输入引脚为基础引脚编号。

sm_config_set_wrap(&c, offset, offset);

设置状态机的指令循环,使其始终执行之前捕获程序的指令。

sm_config_set_clkdiv(&c, div);

设置状态机的时钟分频因子。

sm_config_set_in_shift(&c, true, true, bits_packed_per_word(pin_count));

配置状态机的输入移位参数。这里,它似乎是为每个引脚打包数据,并可能有一些零位在最低位。

sm_config_set_fifo_join(&c, PIO_FIFO_JOIN_RX);

设置FIFO的合并方式,这里选择的是接收方向。

pio_sm_init(pio, sm, offset, &c);

使用前面设置的配置初始化PIO状态机。

}

函数结束。

总体来说,这个函数是用于初始化PIO硬件以捕获和分析来自特定引脚的数据。它设置了一个PIO程序来捕获数据,并配置了一个PIO状态机来循环执行这个程序,同时根据给定的参数进行一些定制。

  • 10
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

星海露水

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值