0
\$\begingroup\$
#define POKE(addr, val) (*(volatile unsigned int *)(addr) = (val))
#define POKE_AND(addr, val) (*(volatile unsigned int *)(addr) &= (val))
#define POKE_OR(addr, val) (*(volatile unsigned int *)(addr) |= (val))

I dont understand what does it mean

POKE(addr, val) (*(volatile unsigned int *)(addr) = (val))
POKE_AND(addr, val) (*(volatile unsigned int *)(addr) &= (val))
POKE_OR(addr, val) (*(volatile unsigned int *)(addr) |= (val))

for example when i call function

ulVal  = PEEK(NETX_IO_CFG);

where NETX_IO_CFG

#define NETX_IO_CFG     0x00100004U
\$\endgroup\$
  • 1
    \$\begingroup\$ Which package is this in? I want to buy the writer a beer for using the terms peek and poke! \$\endgroup\$ – Asmyldof Jul 20 '15 at 6:45
  • \$\begingroup\$ in netx500 micricontroller project \$\endgroup\$ – user3826752 Jul 20 '15 at 6:48
  • \$\begingroup\$ Peek and poke were used in Basic for the Commodore Pet (6502 processor) for accessing individual memory RAM locations \$\endgroup\$ – Chu Jul 20 '15 at 16:37
2
\$\begingroup\$

define has two practices it can be used to define a constant:

#define PI (3.14)

or it can be used to define macros(somehow look like functions) and it's inlined directly into the code, so there isn't any function call overhead as in :

#define MAX(a, b) ((a) > (b) ? (a) : (b))

in this case,

#define POKE(addr, val) (*(volatile unsigned int *)(addr) = (val))

is a macro(like a function) to store val into the address addr by using the concept of pointers

https://en.wikipedia.org/wiki/Pointer_(computer_programming)

\$\endgroup\$
  • 1
    \$\begingroup\$ Also see PEEK and POKE for some historical reference regarding those terms. \$\endgroup\$ – kkrambo Jul 20 '15 at 13:09
2
\$\begingroup\$

here is being used the way to declare a macro in C compilers. the compiler changes the expression POKE(addr, val) by *(volatile unsigned int *)(addr) = (val) in code which means to assign variable val to derreferenced and casted((volatile unsigned int *)) pointer addr, so on for the remains. Sorry, English is not my first idiom.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.