在我们代码的各种低级部分中,我们需要将特定字节发送到设备以使事情发生.因此,我们有很多代码如下:
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*))
有没有更好的方法来声明这些字符串?
我对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代码,首选哪种语法?在这种情况下,"首选"是指用标准或相关材料(明确书写,或通过标准中给出的示例隐含)或用精心设计的样式指南书写的东西.问题不是要求个人偏好!
我目前正在为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) c++ ×2
c ×1
c++11 ×1
char ×1
device-tree ×1
hex ×1
ieee-754 ×1
linux-kernel ×1
syntax ×1
verilog ×1