在RISC-V大会上编写一些MMIO寄存器位的更好方法?

发布于 2025-02-06 17:11:09 字数 630 浏览 2 评论 0原文

要配置UART TX,必须写入水印(0到7) 在内存映射的TX控制寄存器上位置位置[18:16]。

我的RISC-V组装功能首先读取当前的控制寄存器值,执行 钻头,带有口罩清除碎屑[18:16],然后或与移位 输入值并回报。

代码下面:

uart_set_txwmark:

    slli a0, 15;  /* shift input value by 15 */
    li t0, UART1_BASE;
    lw t1, UART_TXCTRL_OFFSET(t0); /* Read present value */

.equiv UART_MASK_WMARK, 0x0xFFF8FFFF /* [18:16] zero mask */

    li t2, UART_MASK_WMARK;   
    and t1, t1, t2;      /* clear/zero bits 18:16 */ 
    or t1, t1, a0;       /* OR with input value */
    sw t1, UART_TXCTRL_OFFSET(t0); /* Write back */

我很想知道在RISC-V中是否还有其他更好的方法在内存映射寄存器中设置几个位。

To configure UART tx, water mark (0 to 7) has to be written
on memory mapped tx control register on bit position [18:16].

My RISC-V assembly function first reads the present control register value, perform a
bitwise AND with mask to clear bits [18:16] and then OR with the shifted
input value and write back.

Code below:

uart_set_txwmark:

    slli a0, 15;  /* shift input value by 15 */
    li t0, UART1_BASE;
    lw t1, UART_TXCTRL_OFFSET(t0); /* Read present value */

.equiv UART_MASK_WMARK, 0x0xFFF8FFFF /* [18:16] zero mask */

    li t2, UART_MASK_WMARK;   
    and t1, t1, t2;      /* clear/zero bits 18:16 */ 
    or t1, t1, a0;       /* OR with input value */
    sw t1, UART_TXCTRL_OFFSET(t0); /* Write back */

I am curious to know if there is any other better way of setting few bits in a memory mapped register in RISC-V.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

对你而言 2025-02-13 17:11:09

我很想知道在RISC-V中是否还有其他更好的方法来设置记忆映射的寄存器中的几个位。

不是真的,我认为您有要点。


如果您可以使用半词读/写入,那将碰巧将感兴趣的位定位在低位位置,因此您可以做:

la t0, UART1_BASE
lhu t1, UART_TXCTRL_OFFSET+2(t0)  // fetch high order at offset +2
andi t1, t1, -8
or t1, t1, a0
sh t1, UART_TXCTRL_OFFSET+2(t0)

I am curious to know if there is any other better way of setting few bits in a memory mapped register in RISC-V.

Not really, I think you have the gist of it.


If you can use halfword reads/writes instead, that will happen to position the bits of interest at the low bit positions, so you can maybe do:

la t0, UART1_BASE
lhu t1, UART_TXCTRL_OFFSET+2(t0)  // fetch high order at offset +2
andi t1, t1, -8
or t1, t1, a0
sh t1, UART_TXCTRL_OFFSET+2(t0)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文