在RISC-V大会上编写一些MMIO寄存器位的更好方法?
要配置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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不是真的,我认为您有要点。
如果您可以使用半词读/写入,那将碰巧将感兴趣的位定位在低位位置,因此您可以做:
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: