Hi
I am using a AP32, and comunicating to a VDrive (from Vinculum) through the SCI port with Interrupts enabled.
Then I needed to store some variables to flash, and used the ROM Resident Routines.
Once read application note AN28741 and modified the RAM and ROM segments in the proyect.rpm file I had them up and running.
But then, when i wanted to make work both things together, it didn't. Saving and loading data from/into Flash worked fine, but SCI communication didn't. The problem was that the ROM Resident Routines disabled interrupts by setting the Interrupt Mask (I) in the CCR register.
So to avoid interrupts to be disabled i added the code in red to the example code from AN28741:
void FLASHErase(void)
{
asm(TPA); // CCR to register A
asm(PSHA); // Push A onto Stack
asm(LDHX FILE_PTR); // Load address of RAM Data Block to H:X
asm(JSR ERARNGE); // Call ERARNGE ROM Subroutine
asm(PULA); // Pull A from Stack
asm(TAP); // A to CCR to restore Interrupt mask as it were.
}
For now it is working fine, but my question is if this is the best way of doing it. Is there a better way? Maybe I just neet to config some reg and i wont need the extra code. But i didn't fine anything in the forum. Any ideas?
Thanks in advance
Regards
FelixHello Felix,
Yes, your observation is correct that the ERARNGE sub-routine does disable interrupts. Your extra code is the best way if the previous interrupt enable state is unknown prior to the call. If interrupts are known to be enabled, you might alternatively use __asm cli; following the call.
To simplify coding, you might even create some macros within an appropriate header file -
#ifndef critical
#define critical __asm tpa; __asm psha; __asm sei
#define critical_restore __asm pula; __asm tap
#endif
If you intend writing to flash immediately following the page erase, leave the restoration of the interrupt state until after the write.
Regards,
Mac