A real world migration from TI-RTOS to the POSIX API of TI SimpleLink.

Texas Instruments migrated from the proprietary TI-RTOS to the open POSIX API.

I'm migrating a project that extensively used the TI paradigms to that POSIX API. You're my witness.

The blog assumes that you are a TI-RTOS user and want to adapt to the new ways of working.

 

This time the topic is SimpleLink and MSP432 DriverLib related. Not POSIX specific, but an impact of switching to SimpleLink.

Where the original driver lib for the MSP432 used the Flash API (see git), the SimpleLink release uses EEPROM API.

The functions are similar but there's less work defining where the data is stored. No more messing with the linker command file and fixed addresses.

The new API does that for you. You still have to give an offset in the EEPROM memory area, but we're using 0 - start of the block.

You don't need to explecitly unprotect and protect the memory in the new API. It's simpler to use.

 

I'm using the API to persistently store calibration data and retrieve it at startup of the Programmable Electronic Load.

 

Initialising the API

 

Initialise the API before you use it.

Because it's not often used in my firmware (in normal use only a single EEPROM read at startup) I've lazily chosen to try and initialise it whenever I call an API function,

with a static flag to skip the initialisation if it's already done.

Feel free to criticise in the comments. I have some weak defense points.

 

#include <ti/devices/msp432e4/driverlib/eeprom.h>

 

void calibrationInit() {
    static bool bInited = false;
    if(!bInited) {
        /* Enable the EEPROM peripheral. */
        SysCtlPeripheralEnable(SYSCTL_PERIPH_EEPROM0);


        /* Initialize the EEPROM */
        EEPROMInit();
        bInited = true;
    }
}

 

I've made a structure to capture the data. This is unchanged from the old TI-RTOS approach.

The only difference is the CALIBRATION_START definition. It used to be an addres in the Flash range. Now it's an offset in the dedicated non-volatile storage range of the controller.

 

#define CALIBRATION_DATA_VERSION 1U
#define CALIBRATION_START 0x00


typedef struct CalibrationData {
    uint32_t version;
    float temperature_threshold;  // todo convert to the ADC 16 bit value in stead of float
    float sense_voltage_read_multiplier;
    float sense_voltage_read_offset;
    float current_read_multiplier;
    float current_read_offset;
    float current_write_multiplier;
    float current_write_offset;
} CalibrationData;


#define CALIBRATION_DATA_SIZE (sizeof(CalibrationData))


CalibrationData _CalibrationData;

 

Reading Data

 

Very simple. Tell the API where the EEPROM offset is (the persistent source), where the data needs to be copied to (the in-memory calibration structure) and the size of the data ( == the size of that calibration structure).

 

void calibrationRead() {
    calibrationInit();
    EEPROMRead((uint32_t *)&_CalibrationData, (uint32_t)(CALIBRATION_START),
               (uint32_t)CALIBRATION_DATA_SIZE);
}

 

Writing Data

 

Also simple. Do the same logic as above, but the other way around: from RAM to persistent Flash.

 

void calibrationWrite() {
    _CalibrationData.version = CALIBRATION_DATA_VERSION; // writing calibration data will always set the version to the latest
    calibrationInit();
    EEPROMProgram((uint32_t *)&_CalibrationData, (uint32_t)(CALIBRATION_START),
                  (uint32_t)CALIBRATION_DATA_SIZE);
}

 

That's it.

If you'd check out the same code I wrote for the original MSP432 driverlib (see git), you'd see that it was a little deeper under the hood (not a lot - still understandable) and that you'd use memcpy() to move data from Flash to RAM.

Everything got a little bit simpler and easier to code.

 

The ext blog will very likely be POSIX related. The only non-POSIX topic I have to cover later on is the LCD driver (SimpleLink has a driver for that - yay).

 

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