In my project is included an ".h" file with this declaration:
"#define pMDMA_D0_START_ADDR ((void * volatile *)MDMA_D0_START_ADDR)"
If I assign a value (e.g. *pMDMA_S0_START_ADDR = 0x04000
the
As others noted, D0 (dee-zero) vs S0 (ess-zero) makes a big
difference.
That aside, there are a couple of peculiar things going on here.
First, "volatile" suggests you are attempting to program hardware.
This is inherently non-portable. (You can add an abstraction layer,
to make the C code port to "those systems on which the hardare can
be found", and this is often a good idea, but the job itself remains
non-portable so one may as well discard attempts to use nothing
but Standard C. The question then becomes what to put in the
abstraction layer.)
Second, the name MDMA suggests this has something to do with direct
memory access hardware, e.g., I/O devices. (I assume it is not
methylene-dioxy-methamphetamine, aka Ecstasy.
) These tend to
talk to hardware-oriented RAM addresses, rather than C-oriented
software memory addresses. On many machines, the hardware addresses
are different from the software addresses, making C's "void *"
(generic data pointer) type a poor choice for a "hardware DMA
abstraction layer". You probably want some other (likely integral)
type that you can pass around as a "physical address".
This is one of the rare cases where a typedef is useful, e.g.,
using the POSIX namespace:
/* 64-bit physical address, using this compiler's 64-bit integers */
typedef unsigned long long dmaaddr_t;
Or:
/* 32-bit physical address, using this compilers 32-bit integers */
typedef unsigned int dmaaddr_t;
Of course, if "void *" really is suitable for physical DMA
addresses (which also means "you do not need to do arithmetic
on them", which is rare), you could:
typedef void *dmaaddr_t;
In any case, once you have chosen an appropriate "DMA address type",
you can then define a (highly-machine-specific) macro like
pMDMA_S0_START_ADDR using that type:
#define pMDMA_D0_START_ADDR (*(volatile dmaaddr_t *)0x12345678)
(although I find that putting these things into data structures
is often wise.)
... compiler give me these 2 warning:
".\init.c", line 105: cc0513: {D} warning: a value of type "int" cannot
be
assigned to an entity of type "void *"
*pMDMA_S0_START_ADDR = 0x04000;
This is because the thing on the right is an "int" (0x04000 or
16384), while the thing on the left is a "void *".
If you were using a type-alias (typedef) to hide the actual hardware
data type, you might write:
*pMDMA_S0_START_ADDR = (dmaaddr_t)0x4000;
although this obviously assumes that "0x4000" is the correct way
to express the address as an integer (for that particular machine).
If it is in fact the correct way, it seems likely that "dmaaddr_t"
should be integral in the first place.