element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Personal Blogs
  • Community Hub
  • More
Personal Blogs
Legacy Personal Blogs Switch from TI-RTOS to SimpleLink POSIX: Sleep when Idle
  • Blog
  • Documents
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: Jan Cumps
  • Date Created: 15 May 2018 3:29 PM Date Created
  • Views 1578 views
  • Likes 4 likes
  • Comments 3 comments
  • rtos
  • sleeping
  • ti_rtos
  • posix
Related
Recommended

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

Jan Cumps
Jan Cumps
15 May 2018

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

image

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 image

 

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:

 

image

  • 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.

image

 

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 image.

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

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.

 

 

image

 

 

 

* 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
  • Sign in to reply

Top Comments

  • DAB
    DAB over 7 years ago +2
    Another great post Jan. DAB
  • fmilburn
    fmilburn over 7 years ago +1
    TI puts a lot of effort into power saving features and making them available to users and it is one of the main reasons I have been using them. Thanks for the explanation.
  • genebren
    genebren over 7 years ago +1
    Nice update on your project. You seem to be moving well through learning and building process. Gene
  • DAB
    DAB over 7 years ago

    Another great post Jan.

     

    DAB

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • genebren
    genebren over 7 years ago

    Nice update on your project.  You seem to be moving well through learning and building process.

    Gene

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • fmilburn
    fmilburn over 7 years ago

    TI puts a lot of effort into power saving features and making them available to users and it is one of the main reasons I have been using them.  Thanks for the explanation. 

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube