Hi!
The datasheet/User guide SWRU191B says...
The Instruction that sets the PCON.IDLE bit must be aligned in a certain way for correct operation. The first byte of the assembly instruction immediately following this instruction must not be placed on a 4-byte boundary. Furthermore, cache must not be disabled (see CM in the FCTL register description in chapter 6). Failure to comply with this requirement may cause higher current consumption. Provided this requirement is fulfilled, the first assembly instruction after the instruction that sets the PCON.IDLE bit is performed before the ISR of the interrupt that caused the system to wake up, but after the system woke up. If this instruction is a global interrupt disable, it is possible to have it followed by code for execution after wakeup, but before the ISR is serviced.
I cannot understand how to exactly realise this with my c code. And since I am not using IAR, I am on Linux and using sdcc compiler to compile my CC2530 software. I have done the following in my main.c (Still developing and not completed project):
...
#define GO_SLEEP (PCON |= 0x0E)
...
void isr_tamper(void) interrupt (P0INT_VECTOR){//Tamper pin interrupt vector, which wakes up the CPU P0IE = 0; EA = 0; //do something uart_tx("katkestus!"); //useful here P0IF = 0; P0IFG = ~_BV(6); EA = 1; P0IE = 1; } ...
void init_sleep_mode(char a[]){
FCTL |= 0x0C;//Flash cache enabled, real-time mode
if(a == "PM3"){
SLEEPCMD |= _BV(0);//PM3
SLEEPCMD |= _BV(1);}
if(a == "PM2"){
SLEEPCMD &= ~_BV(0);//PM2
SLEEPCMD |= _BV(1);}
if(a == "PM1"){
SLEEPCMD |= _BV(0);//PM1
SLEEPCMD &= ~_BV(1);}
}
...
void go_sleep(void){/* Enter Sleep mode defined by SLEEPCMD*/
__asm;
//Can somebody tell me what i have to exactly do here?
__endasm;
}
...
void main(void){
init_sleep_mode("PM2");
GO_SLEEP;
.... //?????????????
....
}
As u can see in init_sleep_mode() the cache is also enabled as said in datasheet...
Any suggestions? Because right now i can minimize the current down to 4.04 mA only :/ Mainly i cannot understand how to put those instructions out/into 4 byte boundaries...
Thank you!