Basic C syntax Question

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
atvmainiac
Level 1
Level 1
5 questions asked 10 sign-ins First solution authored

While writing my own code to bit bang the ERU register to set up for an interrupt i saw some syntax i had a question

Correct my if i'm wrong but

#defne  A = (uint32_t*)0x40040660;

would be the same as

uint32_t  *A = 0x40040660

 

only difference is that A is not a macro in the second case, just a local variable to Main(or what ever function i decided to define it in) right?

 

0 Likes
2 Replies
Len_CONSULTRON
Level 9
Level 9
Beta tester 500 solutions authored 1000 replies posted

atvmainiac,

First off, I believe you meant "define" instead of "defne".

The "#define A" assumes what follows is a definition.  In this case the definition is "= (uint32_t*)0x40040660;"

Therefore when you use it in your code, it "expands" to:

 

{
...
uint32_t *B;
uint32_t C;
...
// These lines throw No Error but are odd C syntax
B A      // expands to: B = (uint32_t *)0x40040660;
B A;     // expands to: B = (uint32_t *)0x40040660;;
// These lines throw an "Expression expected" error 
B = A   // expands to: B = = (uint32_t *)0x40040660;
B = A;   // expands to: B = = (uint32_t *)0x40040660;;
C = A   // expands to: C = = (uint32_t *)0x40040660;
C = A;   // expands to: C = = (uint32_t *)0x40040660;;
...
}

 

I'm not sure what is the end goal of what you're trying to do but here's a suggestion:

I'm assuming you're trying to define a specific address in memory space.  Not knowing the XMC address mapping there are two ways to define this mapping.  One is good if you're defining RAM and the other if you're defining a register.

In RAM you'd use:

 

#define RAM_HARDCODED_PTR  ((uint32_t *)0x40040660)

 

This can be problematic to define a 'hardcoded' RAM address since usually all of RAM is available for use unless specifically set aside in your linker map.

In register space you'd use:

 

#define REG_HARDCODED_PTR  ((reg32 *)0x40040660)

 

These register addresses are usually 'hardcoded' and are usually already defined in some system .h file provided by the manufacturer of the XMC.

Therefore the define can be used in the code:

{
...
*REG_HARDCODE_PTR = 0x12345678;  // This will store the 32-bit number at the defined address.
...
}
Len
"Engineering is an Art. The Art of Compromise."
0 Likes
atvmainiac
Level 1
Level 1
5 questions asked 10 sign-ins First solution authored

My question was based arround setting the bit fields for the ERU and NVIC to generate an interrupt

I wanted to try my luck setting the bit fields manually without the use of the apps option to understand a little bit more whats going on behind the scene. so i was attempting to write to the following addresses.

0x40010600(Set as 0x00), 0x40010610(set as 0x108), and 0x40010620(set as 0x1014). to set the bit fields for the ERU, to set up an event to trigger the NVIC. 

I know this can easily be accomplished using the apps in DAVE, but as previously stated, i wanted to get an idea of whats going on, on the bit level. 

0 Likes