小编Dam*_*ien的帖子

在C++ 11中声明char十六进制常量

在我们代码的各种低级部分中,我们需要将特定字节发送到设备以使事情发生.因此,我们有很多代码如下:

const char magic_bytes[] = { 0x01, 0xFA, 0x92 };
Run Code Online (Sandbox Code Playgroud)

这导致错误(在GCC 4.7.2上)

test_char.cpp:6:51: warning: narrowing conversion of ‘250’ from ‘int’ to ‘const char’ inside { } is ill-formed in C++11 [-Wnarrowing]
Run Code Online (Sandbox Code Playgroud)

因为0xFA超出-128到127的范围.

我能想到两种解决方法:

const char magic_bytes[] = { static_cast<char>(0x01), static_cast<char>(0xFA), static_cast<char>(0x92) };
Run Code Online (Sandbox Code Playgroud)

要么:

const unsigned char magic_bytes[] = { 0x01, 0xFA, 0x92 };
Run Code Online (Sandbox Code Playgroud)

两者都是丑陋的(第一种情况),或者有其他缺点(在后者的情况下必须转换为(const char*))

有没有更好的方法来声明这些字符串?

c++ hex char c++11

7
推荐指数
1
解决办法
5369
查看次数

verilog模块声明的首选语法

我对FPGA相对较新,我正在寻找关于Verilog中模块声明的现代最佳实践的一些指导.

我已经看到了两种在verilog中声明模块的方法.第一个让我想起了传统C,比如维基百科上例子:

module toplevel(clock,reset);
    input clock;
    input reset;

    /* snip */
endmodule
Run Code Online (Sandbox Code Playgroud)

替代语法将输入/输出说明符作为参数列表的一部分,而与VHDL不太相似,如下例所示:

module fadder(
    input a,         //data in a
    input b,         //data in b
    input cin,       //carry in
    output sum_out,  //sum output
    output c_out     //carry output
);

/* snip */
endmodule
Run Code Online (Sandbox Code Playgroud)

对于新编写的verilog代码,首选哪种语法?在这种情况下,"首选"是指用标准或相关材料(明确书写,或通过标准中给出的示例隐含)或用精心设计的样式指南书写的东西.问题不是要求个人偏好!

syntax verilog

7
推荐指数
2
解决办法
5132
查看次数

为什么IEEE-754浮点数不能在平台之间交换?

已经断言(甚至考虑字节字节序)IEEE754浮点并不保证在平台之间可以交换.

所以:

  • 理论上,为什么IEEE浮点不能在平台之间交换?
  • 这些问题是否适用于现代硬件平台(例如i686,x64,arm)?

如果问题是有效的,您能否请举例说明这种情况(首选C或C++)?


动机:一些GPS 制造商在"符合IEEE-754标准的浮点值"中为(例如)纬度,经度和原始数据交换其二进制格式.所以,我无法控制选择文本格式或其他"便携式"格式.因此,我的问题是何时可能会或可能不会发生差异.

c c++ serialization ieee-754 floating-point-conversion

6
推荐指数
1
解决办法
864
查看次数

将设备树中断标志映射到devm_request_irq

我目前正在为Linux使用PowerPC编写设备驱动程序.

设备树条目如下:

// PPS Interrupt client 
pps_hwirq {
    compatible = "pps-hwirq";
    interrupts = <17 0x02>;                     // IPIC 17 = IRQ1, 0x02 = falling edge
    interrupt-parent = < &ipic >;
};
Run Code Online (Sandbox Code Playgroud)

0x02标志非常重要 - PPS与下降沿对齐,但这在GPS接收器上不是通用的,因此应该是可配置的.

probe()驱动程序的功能中,获取IRQ编号很简单:

hwirq = irq_of_parse_and_map(np, 0);
if (hwirq == NO_IRQ) {
    dev_err(&pdev->dev, "No interrupt found in the device tree\n");
    return -EINVAL;
}
Run Code Online (Sandbox Code Playgroud)

但是如何将IRQ标志从设备树映射到驱动程序?

/* ****TODO****: Get the interrupt flags from the device tree 
 * For now, hard code to suit my problem, but since this …
Run Code Online (Sandbox Code Playgroud)

linux-device-driver linux-kernel device-tree

5
推荐指数
1
解决办法
4554
查看次数