如何从 HPS 向 FPGA 发送浮点数?

How to send a floating point number to FPGA from HPS?

我正在使用 Altera DE0 nano SoC FPGA。我想知道如何从 HPS 向 FPGA 发送浮点数。

float ex_hps = 6000.9282; 通过 Avalon 内存映射接口发送。如果 Avalon_write_data address 有 32 位数据长度(可以从 Qsys 设置),在 FPGA 端这个数字存储在 32 位 std_logic_vector 对吗?

这个std_logic_vector是否包含原始值作为定点类型(13 downto -14)的浮点数?或者如何在 VHDL 的 FPGA 端将此数字放回定点数 ex_fpga(13 downto -14)

这是您可以自己查阅的内容。

您需要先使用系统知识将浮点数映射到 C 中的整数。

#include <math.h>

unsigned int PrepareForTransmission(float inputValue)
{
    if (inputValue < 0) return 0; /* underflow error: clip */
    if (inputValue >= powf(2.0f, 14)) return (unsigned int)pow(2.0, 28) - 1; /* overflow error: clip */
    return (unsigned int)(inputValue * pow(2.0, 14) + 0.5); /* +0.5 to round */
}

然后在 VHDL 中,您可以简单地将未签名的 std_logic_vector(27 downto 0) 移植到 ufixed(13 downto -14)。你(希望)知道该怎么做。