Dumb question of the day, about pointers

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

cross mob
Anonymous
Not applicable

Hello all.

   

In my isr_1.c file, I wish (for various reasons) to assign a pointer to a specific spot in the SRAM.

   

What I'm doing is calculating an index (based on the number of times I've entered the ISR) and adding that to a static base address, as in:

   

uint16 offset;

   

uint8 *foo;

   

foo = 0x20000000 + offset;

   

The complier issues a warning, stating that I'm creating a pointer from an int without a cast.

   

Is there a more "elegant" or "kosher" way to do this? I am intentionally putting things into this portion of SRAM in order to avoid conflicting with anything related to program execution.

   

Your thoughts are appreciated, thanks.

0 Likes
3 Replies
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

You forgot to mention in which of the three worlds you live: PSoC 1, PSoC3 or PSoC5.

   

for PSoC3 a solution could be:

   

CYXDATA char MyMem[1 ] _at_ 0x2000;

   

and later on:

   

   for(ii=0;ii<1000;MyMem[ii++]=0);

   

 

   

Bob

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked
0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Sorry, the above post lacks some information.

   

 

   

This should work for PSoC3 and 5

   

CYXDATA *MyMem = (void *)0x2000;  // With initialization

   

Bob

0 Likes