Anonymous
Not applicable
Nov 25, 2009
09:18 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Nov 25, 2009
09:18 PM
Hi,
If I have a variable declared in a C file as;
volatile long seconds;
and want to access that from a timer interrupt ISR in asm to increment it, how do I go about that?
The compiler is complaining about not knowing what seconds is in the asm file (undefined symbol). So how can I define it in the asm file?
At the moment I'm doing something like
and F, 0x00 ;
inc [seconds] ;
jnc _end ;
And the same for each subsequent byte [seconds+1, 2 & 3].
Is this the "right" way? Or is there a better way?
Cheers,
James.
If I have a variable declared in a C file as;
volatile long seconds;
and want to access that from a timer interrupt ISR in asm to increment it, how do I go about that?
The compiler is complaining about not knowing what seconds is in the asm file (undefined symbol). So how can I define it in the asm file?
At the moment I'm doing something like
and F, 0x00 ;
inc [seconds] ;
jnc _end ;
And the same for each subsequent byte [seconds+1, 2 & 3].
Is this the "right" way? Or is there a better way?
Cheers,
James.
5 Replies
Nov 25, 2009
09:38 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Nov 25, 2009
09:38 PM
For accessing a C variable in assembly, you have to add an underscore before the variable. The code should be
inc [_seconds]
Some more points to remember.
1. The variables in PSoC Designer are in Big Endian format. So, to increment the LSB of seconds, use [_seconds + 3]
2. If you are dealing with a device with more than 256 bytes of RAM, you may also have to set the CUR_PP register to point to the currect RAM page. Check out the document on Large Memory model in the Help >> Documentation section of PSoC Designer for details about.
inc [_seconds]
Some more points to remember.
1. The variables in PSoC Designer are in Big Endian format. So, to increment the LSB of seconds, use [_seconds + 3]
2. If you are dealing with a device with more than 256 bytes of RAM, you may also have to set the CUR_PP register to point to the currect RAM page. Check out the document on Large Memory model in the Help >> Documentation section of PSoC Designer for details about.
Anonymous
Not applicable
Nov 25, 2009
11:40 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Nov 25, 2009
11:40 PM
Thanks Ganesh.
I've got to look in to the CUR_PP register stuff because although it compiles it doesn't seem to be incrementing the seconds variable.
Cheers,
James.
I've got to look in to the CUR_PP register stuff because although it compiles it doesn't seem to be incrementing the seconds variable.
Cheers,
James.
Nov 26, 2009
12:09 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Nov 26, 2009
12:09 AM
James,
There is one more approach you can try. This is to define the variable in assembly and then access it in C. You can place the variable in RAM Page-0 so that inside the interrupt, you do not have to change the CUR_PP register. Below is the procedure.
1. In the Timer ISR, define the variable like this.
area InterruptRAM(ram)
_seconds:
seconds: BLK 4
This will place the seconds variable in Page-0. Make sure that you place the above instructions inside the custom user code area in the Timer's ISR file
2. To access this variable from a C file, add the following declaration either in a header file that is included in the source file or directly in the source file
extern long seconds;
Now you can access the seconds variable in C as well. Also, as the variable is now placed in Page-0 and as all the memorey operations are by default done on Page-0 inside an interrupt, you can access the variable inside the ISR without changing the CUR_PP register.
There is one more approach you can try. This is to define the variable in assembly and then access it in C. You can place the variable in RAM Page-0 so that inside the interrupt, you do not have to change the CUR_PP register. Below is the procedure.
1. In the Timer ISR, define the variable like this.
area InterruptRAM(ram)
_seconds:
seconds: BLK 4
This will place the seconds variable in Page-0. Make sure that you place the above instructions inside the custom user code area in the Timer's ISR file
2. To access this variable from a C file, add the following declaration either in a header file that is included in the source file or directly in the source file
extern long seconds;
Now you can access the seconds variable in C as well. Also, as the variable is now placed in Page-0 and as all the memorey operations are by default done on Page-0 inside an interrupt, you can access the variable inside the ISR without changing the CUR_PP register.
Anonymous
Not applicable
Dec 08, 2009
06:51 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dec 08, 2009
06:51 PM
That works a treat, thanks!
Dec 09, 2009
11:56 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dec 09, 2009
11:56 AM
You are most welcome