I am trying to use low-power mode on the Chronos watch. I am using CCS v5.2 and SimpliciTI to communicate with another device. The Chronos is only receiving two bytes of data every two seconds and displaying the value on the watch. I would like to be in low power mode when not receiving data. Where should I enter and exit low power mode?
I have the following functions that have been modified from the example peer-to-peer application:
- static void linkFrom().
- static uint8_t sRxCallback(linkID_t port).
In function linkFrom(), low-power mode is entered after a reply has been sent. The callback function sRxCallback() exits low-power.
When the application runs, sRxCallback() is called and updates the display but the while(1) in function linkFrom() is never runs.
Any suggestions on the proper use of low-power for this application.
static void linkFrom()
{
uint8_t msg[2], tid = 0;
u8 string[8];
/* listen for link forever... */
display_chars(LCD_SEG_L1_3_0, (u8 *) " 321", SEG_ON); // status message
while (1)
{
if (SMPL_SUCCESS == SMPL_LinkListen(&sLinkID2))
{
break;
}
/* Implement fail-to-link policy here. otherwise, listen again. */
}
display_chars(LCD_SEG_L1_3_0, (u8 *) " -- ", SEG_ON); // double dash on LCD Line1
memcpy(string, " SRN02", 6);
display_chars(LCD_SEG_L2_5_0, string, SEG_ON); // message on LCE Line2
/* turn on LED1 on the peer in response to receiving a frame. */
*msg = 0x01;
/* turn on RX. default is RX off. */
SMPL_Ioctl( IOCTL_OBJ_RADIO, IOCTL_ACT_RADIO_RXON, 0);
while (1)
{
/* Wait for a frame to be received. The Rx handler, which is running in
* ISR thread, will post to this semaphore allowing the application to
* send the reply message in the user thread.
*/
if (sSemaphore)
{
*(msg+1) = ++tid;
SMPL_Send(sLinkID2, msg, 2);
/* Reset semaphore. This is not properly protected and there is a race
* here. In theory we could miss a message. Good enough for a demo, though.
*/
sSemaphore = 0;
// Reply has been sent. go into Low-Power
_BIS_SR(LPM3_bits + GIE);
}
}
}
/* handle received messages */
static uint8_t sRxCallback(linkID_t port)
{
static int ToggleFlag = 0;
uint8_t msg[2], len;
uint8_t value = 0;
u8 *str;
uint8_t ret_val = 0;
// exit Low-power mode so linkFrom() will run
_BIC_SR(LPM3_bits);
/* is the callback for the link ID we want to handle? */
if (port == sLinkID2)
{
/* yes. go get the frame. we know this call will succeed. */
if ((SMPL_SUCCESS == SMPL_Receive(sLinkID2, msg, &len)) && len)
{
/* Check the application sequence number to detect
* late or missing frames...
*/
value = msg[1];
if ((value > 0) && (value < 100))
{
// good number, diaplay it.
str = int_to_array(value, 3, 1);
display_chars(LCD_SEG_L1_3_1, str, SEG_ON);
sRxTid = value;
}
else
{
// invalid number, display double dash.
display_chars(LCD_SEG_L1_3_0, (u8 *) " -- ", SEG_ON);
sRxTid = value;
}
// just toggle the % symbol so we know it's alive.
if (ToggleFlag != 0)
{
display_symbol(LCD_SYMB_PERCENT, SEG_ON);
ToggleFlag = 0;
}
else
{
display_symbol(LCD_SYMB_PERCENT, SEG_OFF);
ToggleFlag = 1;
}
/* Post to the semaphore to let application know so it sends
* the reply
*/
sSemaphore = 1;
/* drop frame. we're done with it. */
ret_val = 1;
}
}
/* keep frame for later handling */
return(ret_val);
}