This blog is a side story: how does the MSP432 magically go into low power mode when the RTOS is idle?

image source: ARM

It is relevant for the "Move to SimpleLink"  blog series because, with the RTOS abstraction, more of what's happening is now under the hood.

 

If the theme for the next Project14 month is low power, I'll submit this blog to that too.

Full disclosure: I've voted for low power as next month's theme.

Other full disclosure: I didn't know at that time that I was going to write this blog.

Feels like Pay to Play

 

What is Configured in the SimpleLink TI-RTOS Project?

 

When you create a SimpleLink project that's based on any of the examples of the CCS Resource Explorer*,

and you select TI-RTOS as the underlying RTOS, you have a project framework that will automatically have power saving functions enabled.

You don't have to do anything. The RTOS will decide what to do when it's not running one of your tasks.

 

This first section will define what's defaulted in that SimpleLink TI-RTOS project.

The second section will define what you can change in your project. But if you don't change anything, you get the default power saving behaviour.

 

The RTOS is configured to run a few tasks when it's not running any of your threads:

 

  • do self-maintenance
  • save power consumption by invoking the Power_idleFunc().

 

The self-maintenance is something TI-RTOS does to keep internal health (mop up resources of closed tasks and POSIX pthreads). We're not going to review them here.

The functionality that's performed by the idle function Power_idleFunc()is what we're interested in. Thats the one that puts our MSP432 microcontroller in sleep whenever possible;

 

Power_idleFunc()is part of the SimpleLink library. The documentation of that function is available online.

 

It will look for a structure that defines the power policy. We'll go deeper into this in the next section, because the structure is defined in your project.

What I want to draw your attention on now are two values that are used by the TI-RTOS power management and a default power policy function, PowerMSP432E4_sleepPolicy().

The two values (we'll see later that they are fetched from your project code) are:

  • policyFxn
  • enablePolicy

 

typedef struct PowerMSP432E4_ModuleState {
    uint32_t dbRecords[PowerMSP432E4_NUMRESOURCES];
    Power_PolicyFxn policyFxn;
    bool enablePolicy;
    bool initialized;
    uint8_t refCount[PowerMSP432E4_NUMRESOURCES];
} PowerMSP432E4_ModuleState;

 

policyFxn is a pointer to the function that TI-RTOS calls when it decides to run Power_idleFunc(), if enablePolicy is true .

This may sound complex, but you'll see how policyFxn and enablePolicy are defined in the next section. And as stated before, if you don't do anything, it'll work.

 

PowerMSP432E4_sleepPolicy()is a default implementation of a power profile. It's defined in the SimpleLink libraries and your project will use this as the policy if you don't make changes to its setup.

I'm documenting the function here because it's part of the 'under the hood' functionality.

 

#define DHCSR (*(volatile uint32_t *)0xE000EDF0)
#define C_DEBUGGEN 0x1

/*
 *  ======== PowerMSP432E4_sleepPolicy ========
 */
void PowerMSP432E4_sleepPolicy()
{
    /* invoke WFI only if CPU is not in debug mode */
    if (!(DHCSR & C_DEBUGGEN)) {
        __asm(" wfi");
    }
}

 

The function will check if you are in active debug. If yes, it won't sleep (it's common, sleeping messes up your debug session).

If you aren't in active debug mode, it will call the ARM WFI instruction. The controller waits for an interrupt and takes a nap in the meantime.

 

image source: Keil

 

That completes the activities that are done outside your project, and the profile that's available for sleeping from SimpleLink.

 

What is Configured in your Project?

 

If you don't configure anything, you are good. Your project's board file (MSP_EXP432E401Y.c) will contain the necessary constructs to tell TI-RTOS to use SimpleLinks default (and good) PowerMSP432E4_sleepPolicy() functionality.

The static declaration below will be found by TI-RTOS and the settings taken over by its scheduler.

 

/*
 *  =============================== Power ===============================
 */
#include 
const PowerMSP432E4_Config PowerMSP432E4_config = {
    .policyFxn = &PowerMSP432E4_sleepPolicy,
    .enablePolicy = true
};

 

If you keep this intact, your project will go to lower power mode whenever possible. If you have a better or worse sleep requirement, you can provide your own function to handle the situation.

If you don't want any low power functionality, set enablePolicy false.

 

 

 

 

 

* TI advises you to always start a project from one of the Code Composer Studio Resource Explorer examples for SimpleLink RTOS projects.

 

Related Blog
Switch from TI-RTOS to SimpleLink POSIX: Threads and Semaphores
Switch from TI-RTOS to SimpleLink POSIX: EEPROM API

Switch from TI-RTOS to SimpleLink POSIX: From MailBox to Message Queue

Switch from TI-RTOS to SimpleLink POSIX: LCD Display Driver
Switch from TI-RTOS to SimpleLink POSIX: Sleep when Idle