Using memcpy and friends with memory I / O

I am working on an embedded project that includes I / O to FPGA registers with memory mapping. Pointers to these memory areas should be marked volatile, so the compiler does not "optimize" the reading and writing to the FPGA by caching the values ​​in the CPU registers.

In some cases, we want to copy a series of FPGA registers to the buffer for future use. Since the registers are mapped to adjacent addresses, it memcpyseems appropriate, but passing our pointer volatile, because the original argument gives a warning about dropping the qualifier volatile.

Is it safe (and reasonable) to drop the volatile-ness of the pointer to suppress this warning? If the compiler does not do something magical, I cannot imagine a scenario where the call memcpycannot make the actual copy. An alternative is to just use a loop forand copy bytes by bytes, but memcpyimplementations can (and do) optimize the copy based on copy size, alignment, etc.

+4
source share
2 answers

As a developer of FPGA and firmware, there is only one clear answer: do not use memcpy, etc. for this

Some reasons:

  • There is no guarantee that memcpy will work in any particular order.
  • .
  • acceses . memcpy .
  • undefined.

for . , volatile (. ).

, volatile . (, , ). ( ) .

, /, . , .

, DMA. FPGA PCI (e), busmaster DMA / (, , , ).

( ) , , , , .. mempcy() (1) (1): , , , ).

+4

. , memcpy .

0

All Articles