This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Energy Trace resetting/looping when posting semaphores

Other Parts Discussed in Thread: MSP430FR5969

Hello e2e community,

I've been experiencing some strange behavior with Energy Trace in my TI-RTOS project. I'm working on a low power sensor platform that reads some sensors and transmits the data via an XBee module. I'm using the MSP430FR5969 Wolverine launchpad. This is my first project using the Wolverine and TI-RTOS, so I may just be making a simple beginner mistake somewhere. I use the Clock module to periodically call a function which posts a semaphore to unblock/enable the associated Task function. The problem is that while running, it seems that every time the semaphore posts, the graph in Energy Trace "resets" and starts over. I'm unable to get an estimate of enegry consumption and CPU state because Energy Trace only shows data until the first semaphore before beginning again at time=0. After a few seconds the graph looks like a mess because the traces are drawn over top one another. Has anyone else experienced this sort of behavior? This has been bothering me for a while now and I've been unable to find anything like this elsewhere on e2e. I've posted my MAIN.cfg and .c file below. Thanks in advance for any help or suggestions.

 

MAIN.CFG

/* ================ General configuration ================ */
var Defaults = xdc.useModule('xdc.runtime.Defaults');
var Diags = xdc.useModule('xdc.runtime.Diags');
var Error = xdc.useModule('xdc.runtime.Error');
var Log = xdc.useModule('xdc.runtime.Log');
var Main = xdc.useModule('xdc.runtime.Main');
var System = xdc.useModule('xdc.runtime.System');
var Task = xdc.useModule('ti.sysbios.knl.Task');
var Semaphore = xdc.useModule('ti.sysbios.knl.Semaphore');
var Clock = xdc.useModule('ti.sysbios.knl.Clock');
var Hwi = xdc.useModule('ti.sysbios.hal.Hwi');
var ti_sysbios_family_msp430_Hwi = xdc.useModule('ti.sysbios.family.msp430.Hwi');
var Power = xdc.useModule('ti.sysbios.family.msp430.Power');
var UART = xdc.useModule('ti.drivers.UART');

/* System stack size (used by ISRs and Swis) */
Program.stack = 256;

/*
 * Comment this line to allow module names to be loaded on the target.
 * The module name strings are placed in the .const section. Setting this
 * parameter to false will save space in the .const section.  Error and
 * Assert messages will contain an "unknown module" prefix instead
 * of the actual module name.
 */
Defaults.common$.namedModule = false;

/*
 * Minimize exit handler array in System.  The System module includes
 * an array of functions that are registered with System_atexit() to be
 * called by System_exit().
 */
System.maxAtexitHandlers = 2;

/* ================ System configuration ================ */
var SysMin = xdc.useModule('xdc.runtime.SysMin');
System.SupportProxy = SysMin;
SysMin.bufSize = 128;
System.extendedFormats = '%$L%$S%$F%f';

/* ================ BIOS configuration ================ */
/*
 * Disable unused BIOS features to minimize footprint.
 * This example uses Tasks but not Swis or Clocks.
 */
var BIOS = xdc.useModule('ti.sysbios.BIOS');
BIOS.libType = BIOS.LibType_Custom;
BIOS.swiEnabled = false;
BIOS.logsEnabled = false;
BIOS.assertsEnabled = false;

/* No memory allocation occurs, so no heap is needed */
BIOS.heapSize = 0;

/* ================ Driver configuration ================ */
var TIRTOS = xdc.useModule('ti.tirtos.TIRTOS');
var GPIO = xdc.useModule('ti.drivers.GPIO');
var I2C = xdc.useModule('ti.drivers.I2C');
GPIO.libType = GPIO.LibType_NonInstrumented;
I2C.libType = I2C.LibType_NonInstrumented;
var task0Params = new Task.Params();
task0Params.instance.name = "checkTemp";
Program.global.checkTemp = Task.create("&getTemp", task0Params);
var semaphore0Params = new Semaphore.Params();
semaphore0Params.instance.name = "semaphoreBMP";
Program.global.semaphoreBMP = Semaphore.create(0, semaphore0Params);
var clock0Params = new Clock.Params();
clock0Params.instance.name = "BMP180";
clock0Params.period = 1000;
Program.global.BMP180 = Clock.create("&postBMPSemaphore", 1000, clock0Params);
Clock.tickPeriod = 1000;
Clock.tickSource = Clock.TickSource_TIMER;
Clock.tickMode = Clock.TickMode_DYNAMIC;
Clock.timerId = 1;
Clock.swiPriority = 15;
var ti_sysbios_family_msp430_Hwi0Params = new ti_sysbios_family_msp430_Hwi.Params();
ti_sysbios_family_msp430_Hwi0Params.instance.name = "hwi0";
Program.global.hwi0 = ti_sysbios_family_msp430_Hwi.create(47, "&I2CEUSCIB_hwiIntFxn", ti_sysbios_family_msp430_Hwi0Params);
Power.idleMode = Power.LPM3;
Power.allowDynamicMode = false;
var semaphore1Params = new Semaphore.Params();
semaphore1Params.instance.name = "semaphoreL3G";
Program.global.semaphoreL3G = Semaphore.create(null, semaphore1Params);
var task1Params = new Task.Params();
task1Params.instance.name = "checkGyro";
task1Params.priority = 2;
Program.global.checkGyro = Task.create("&getGyro", task1Params);
var clock1Params = new Clock.Params();
clock1Params.instance.name = "L3GD20";
clock1Params.period = 1000;
Program.global.L3GD20 = Clock.create("&postL3GSemaphore", 500, clock1Params);
Power.idle = true;
var semaphore2Params = new Semaphore.Params();
semaphore2Params.instance.name = "semaphoreLSM";
Program.global.semaphoreLSM = Semaphore.create(null, semaphore2Params);
var clock2Params = new Clock.Params();
clock2Params.instance.name = "LSM303";
clock2Params.period = 1000;
Program.global.LSM303 = Clock.create("&postLSMSemaphore", 1500, clock2Params);
var task2Params = new Task.Params();
task2Params.instance.name = "checkAccelMag";
task2Params.priority = 3;
Program.global.checkAccelMag = Task.create("&getAccelMag", task2Params);
BIOS.runtimeCreatesEnabled = false;
var semaphore3Params = new Semaphore.Params();
semaphore3Params.instance.name = "semaphoreSend";
Program.global.semaphoreSend = Semaphore.create(0, semaphore3Params);
var task3Params = new Task.Params();
task3Params.instance.name = "sendTheData";
Program.global.sendTheData = Task.create("&transmitFxn", task3Params);
var clock3Params = new Clock.Params();
clock3Params.instance.name = "sendDataClock";
clock3Params.period = 500;
Program.global.sendDataClock = Clock.create("&postSendSemaphore", 300, clock3Params);
UART.libType = UART.LibType_NonInstrumented;
var ti_sysbios_family_msp430_Hwi1Params = new ti_sysbios_family_msp430_Hwi.Params();
ti_sysbios_family_msp430_Hwi1Params.instance.name = "hwi1";
Program.global.hwi1 = ti_sysbios_family_msp430_Hwi.create(48, "&UARTEUSCIA_hwiIntFxn", ti_sysbios_family_msp430_Hwi1Params);


MAIN.C /* XDCtools Header files */ #include <xdc/std.h> #include <xdc/cfg/global.h> #include <xdc/runtime/System.h> /* BIOS Header files */ #include <ti/sysbios/BIOS.h> #include <ti/sysbios/knl/Task.h> /* TI-RTOS Header files */ #include <ti/drivers/GPIO.h> #include <ti/drivers/I2C.h> #include <ti/drivers/UART.h> /* Example/Board Header files */ #include "Board.h" #include "BMP180.h" #include "L3GD20.h" #include "LSM303.h" void enableAutoRangeGyro(bool enabled); void getGyroEvent(sensors_event_t* event); bool gyroBegin(); void readCoefficients(void); float pressureToAltitude(float seaLevel, float atmospheric); bool accelBegin(void); void enableAutoRangeMag(bool enabled); void getAccelEvent(sensors_event_t* event); void getMagEvent(sensors_event_t* event); bool magBegin(); void getAccelMag() { sensors_event_t event; /* Enable auto-ranging */ enableAutoRangeMag(true); /* Initialise the sensors */ if(!magBegin()) { /* There was a problem detecting the LSM303 ... check your connections */ System_printf("Ooops, no LSM303 MAG detected ... Check your wiring!"); System_flush(); while(1); } if(!accelBegin()) { /* There was a problem detecting the LSM303 ... check your connections */ System_printf("Ooops, no LSM303 ACCEL detected ... Check your wiring!"); System_flush(); while(1); } Clock_start(LSM303); while(1){ Semaphore_pend(semaphoreLSM, BIOS_WAIT_FOREVER); getMagEvent(&event); System_printf("Magnetometer:\n"); System_printf("X = %f uT\n", 1.0*event.magnetic.x); System_printf("Y = %f uT\n", 1.0*event.magnetic.y); System_printf("Z = %f uT\n", 1.0*event.magnetic.z); System_flush(); getAccelEvent(&event); System_printf("Accelerometer:\n"); System_printf("X = %f m/s^2\n", 1.0*event.acceleration.x); System_printf("Y = %f m/s^2\n", 1.0*event.acceleration.y); System_printf("Z = %f m/s^2\n", 1.0*event.acceleration.z); System_flush(); } } void getTemp() { float temp = 0; float press = 0; const float seaLevelPressure = SENSORS_PRESSURE_SEALEVELHPA; readCoefficients(); Clock_start(BMP180); while(1){ Semaphore_pend(semaphoreBMP, BIOS_WAIT_FOREVER); getTemperature(&temp); getPressure(&press); System_printf("Baro:\n"); System_printf("Temp_C = %f f\n", temp); System_printf("Temp_F = %f c\n", 1.8*temp+32); System_printf("Pressure = %f hPa\n", press); System_printf("Altitude = %f m\n", pressureToAltitude(seaLevelPressure, press)); System_flush(); } } void getGyro() { sensors_event_t event; const gyroRange_t rng = GYRO_RANGE_250DPS; /* Enable auto-ranging */ enableAutoRangeGyro(true); /* Initialise the sensor */ if(!gyroBegin(rng)) { /* There was a problem detecting the L3GD20 ... check your connections */ System_printf("Ooops, no L3GD20 detected ... Check your wiring!"); System_flush(); while(1); } Clock_start(L3GD20); while(1){ Semaphore_pend(semaphoreL3G, BIOS_WAIT_FOREVER); getGyroEvent(&event); System_printf("Gyro:\n"); System_printf("X = %f RAD/S\n", 1.0*event.gyro.x); System_printf("Y = %f RAD/S\n", 1.0*event.gyro.y); System_printf("Z = %f RAD/S\n", 1.0*event.gyro.z); System_flush(); } } Void transmitFxn() { UART_Handle uart; UART_Params uartParams; const char* echoPrompt0= "0\n"; /* Create a UART with data processing off. */ UART_Params_init(&uartParams); uartParams.writeDataMode = UART_DATA_BINARY; uartParams.readDataMode = UART_DATA_BINARY; uartParams.readReturnMode = UART_RETURN_FULL; uartParams.readEcho = UART_ECHO_OFF; uartParams.baudRate = 9600; uart = UART_open(Board_UART0, &uartParams); if (uart == NULL) { System_abort("Error opening the UART"); } Clock_start(sendDataClock); /* Loop forever echoing */ while (1) { Semaphore_pend(semaphoreSend, BIOS_WAIT_FOREVER); System_printf("SENDING DATA\n"); System_flush(); UART_write(uart, echoPrompt0, 1); if (echoPrompt0 == "0\n") { echoPrompt0 = "1\n"; } else { echoPrompt0 = "0\n"; } } } void postBMPSemaphore(){ Semaphore_post(semaphoreBMP); } void postL3GSemaphore(){ Semaphore_post(semaphoreL3G); } void postLSMSemaphore(){ Semaphore_post(semaphoreLSM); } void postSendSemaphore(){ Semaphore_post(semaphoreSend); } /* * ======== main ======== */ int main(void) { /* Call board init functions */ Board_initGeneral(); Board_initGPIO(); Board_initI2C(); Board_initUART(); /* Turn Off LED's */ GPIO_write(Board_LED1, Board_LED_OFF); GPIO_write(Board_LED0, Board_LED_OFF); /* Turn on 10DOF sensor */ GPIO_setOutputHighOnPin(GPIO_PORT_P3, GPIO_PIN4); System_printf("Starting TI-RTOS\n"); System_flush(); /* Start BIOS */ BIOS_start(); return (0); }