对不起,我不确定我是否准确地写了标题。
但首先,这是我的限制:
- Array[],用作寄存器映射,被声明为一个无符号的 8 位数组 (uint8_t),这样索引(偏移)是每个字节的。
- 要读取/写入数组的数据具有不同的宽度(8 位、16 位、32 位和 64 位)。
- 非常有限的内存和速度是必须的。
执行以下操作有哪些注意事项
uint8_t some_function(uint16_t offset_addr) //16bit address
{
uint8_t Array[0x100];
uint8_t data_byte = 0xAA;
uint16_t data_word;
uint32_t data_double = 0xBEEFFACE;
\\ A. Storing wider-data into the array
*((uint32_t *) &Array[offset_addr]) = data_double;
\\ B. Reading multiple-bytes from the array
data_word = *((uint16_t *) &Array[offset_addr]);
return 0;
}
我知道我可以尝试按字节写入数据,但是由于位移,这会很慢。
这种用法会不会有很大的问题?我已经在我的硬件上运行了它,到目前为止还没有发现任何问题,但我想注意这个实现可能导致的潜在问题。