Embedded Computing
  • About
  • Blog
  • Hardware
    • Which Platform?
    • Controller Platforms >
      • Adafruit Platform
      • Arduino Plaform
      • BBC micro:bit
      • Espressif Platform
      • iLabs Platform
      • Raspberry Pi Platform (MCU)
      • Seeed Platform
      • Silicon Labs Platform
      • Teensy Plaform
    • Computer Platforms >
      • BeagleBone Platform
      • Raspberry Pi Platform (SBC)
      • UDOO Platform
    • Peripherals >
      • Shields
      • Grove System
      • Sensors
      • Actuators
    • Displays >
      • E-Paper Displays
      • Reflective Displays
      • TFT Displays
      • LCD Displays
    • Legacy Platforms >
      • chipKIT Plaform
      • 4D Systems Platform
      • Intel Platform
      • LaunchPad Plaform
      • BoosterPacks for LaunchPads
      • LightBlue Bean
      • Maple Plaform
      • Mediatek Platform
      • Microsoft Azure IoT DevKit
      • Particle Platform
  • Software
    • Exploring RTOS with Galaxia >
      • Event Library
      • Semaphore Library
      • Mailbox Library
      • Timer Library
      • Clock Library
      • SWI Library
      • Task Library
    • Ultra-Low Power with EnergyTrace >
      • Ultra-Low Power with MSP430
      • Ultra-Low Power with Energia MT and Galaxia
    • Using Integers Instead of Reals
    • Going Python?
  • IoT
    • IoT Platforms: Which Hardware? >
      • Matter with Silicon Labs MG24
    • IoT Services: Which Solution? >
      • Recommended IoT Solutions
      • Platform-Specific IoT Solutions
      • Other IoT Solutions
      • Not tested IoT Solutions
      • Notification Solutions
    • Get Date and Time from Internet with NTP
    • Fast and Easy WiFi Connection with QR-Code
  • Tools
    • How to Start?
    • Reference >
      • Asking for Help
      • Boards Pins Maps
      • Ruler
      • Boards and Plugs
      • I²C Logic Level Converter
      • Standards for Connectors
    • Training >
      • Texas Instruments Workshops
      • Embedded Systems: Shape The World — MOOC edX UTAustinX UT.6.02x
      • Embedded Systems - Shape The World: Microcontroller Input/Output — MOOC edX UTAustinX UT.6.10x
      • Embedded Systems - Shape The World: Multi-Threaded Interfacing — MOOC edX UTAustinX UT.6.20x
      • Real-Time Bluetooth Networks: Shape the World — MOOC edX UTAustinX UT.RTBN.12.01x
      • Systems Thinking with Texas Instruments Robotics System Learning Kit
    • Books >
      • Getting Started with the MSP430 LaunchPad
      • Getting Started with Arduino
      • Arduino Cookbook
    • IDE >
      • The Battle of IDEs
      • More Options
      • Assessing the Next Generation of IDEs
      • Tools for Documentation
    • Equipment >
      • Saleae Logic Analyser
      • Rigol DS1102E Oscilloscope
      • XDS110 Debug Probe with EnergyTrace​
      • Segger J-Link Programmer-Debugger
      • Nordic Power Profiler Kit II
  • Projects
    • Libraries >
      • Master I²C Software Library
      • Date and Time Library
      • highView Library Suite
      • Others Libraries
    • smartDevices >
      • I²C smartColours Smart Sensor
      • I²C smartRFID Smart Sensor
      • I²C smartLED Display
      • I²C smartControls Smart Device
      • I²C smartWiFi Smart Device
      • I²C smartBLE Smart Device
      • I²C smartNode Smart Device
    • IoT Projects >
      • Remote E-Paper Weather and Message Board
      • Typie-Walkie with LoRa and E-Paper Screen
      • Typie-Walkie with E-Paper Screen
      • Remote e-Paper Pictures Panel
      • Remote e-Paper Messages Panel
      • Industrial IoT Project
      • Remote Contactless Temperature Monitor
      • Using Node-RED for IIoT
      • Low Power Home Network Weather Monitoring
      • Updated Low Power Home Network Weather Monitoring
      • Weather and Security Station with Blynk
      • SensorTag to Blynk Using Node-RED
      • Pervasive Reporting
    • AI Projects >
      • Colour Recognition with Neural Network
    • Other Projects >
      • Air Quality Monitoring
      • Driving a Large E-Paper Display with a Compact Xiao RP2040
      • Low-Power E-Paper Weather Station
      • Portable Particulate​ Matter Monitor
      • FRAM-based E-Paper Screen Controller
      • General Purpose 3.5" Screen
      • Colour Recognition with Neural Network
      • A Low Power Weather Station
      • Digital Volt-Amp-Watt Meter
      • Mobile Measurement with LCD Display
      • Screen with SRAM for GUI
      • Volt-Amp-Watt-Meter for Grove
      • Multi-Touch Project with CapTIvate

SWI Library

The TI-RTOS Energia MT is built upon includes four major types of threads:
  • HWI threads or HWIs, are threads triggered by hardware interrupts and have the highest priority.
  • SWI threads or SWIs, are threads triggered by software interrupts and come second after the HWIs.
  • Task threads, or tasks, each one with its own stack, come third after the HWIs and the SWIs.
  • Idle thread has the lowest priority. On Energia MT, it turns the MCU in low power mode.

SWIs and tasks can have up to 32 levels of priority. For more information, please refer to the SYS/BIOS (TI-RTOS Kernel) v6.41 User's Guide.

Unfortunately, the underlying SWI libraries are no longer included in the Energia MT distribution.
Picture
The rtosGlobals.h header file contains all the elements shared across the different tasks and includes the mains setup function rtosSetup().

// *** Header rtosGlobals.h


#ifndef rtosGlobals_h

#define rtosGlobals_h


// Core library

#include "Energia.h"


// Include application, user and local libraries

#include "Semaphore.h"

#include "SWI.h"

#include "Event.h"


// Prototypes


// Define variables and constants

Semaphore mySemaphore;

SWI mySWI;

uint32_t chrono;

Event myEvent;


The function associated with the mySWI event posts the myEvent event.

The function attached to the falling PUSH1 event posts the mySWI event.

// SWI function

void functionSWI()

{

    chrono = millis();

    myEvent.send();

}


// PUSH1 function

void functionPUSH1()

{

    mySWI.post();

}


The main setup function, rtosSetup(), 
  • defines the semaphore with 1 resource for the Serial port, 
  • associates the function functionSWI to the mySWI event, 
  • initialises the myEvent event, and 
  • attaches the function functionPUSH1 for the hardware event falling PUSH1.

Function functionPUSH1 has the highest priority, followed by function  functionSWI and then the 4 tasks similar to the example for the semaphore library.

// Add optional rtosSetup function

void rtosSetup()

{

    Serial.begin(115200);


    mySemaphore.begin(1);

    mySWI.begin(functionSWI);

    myEvent.begin();

    

    mySemaphore.waitFor();

    Serial.println("rtosSetup");

    mySemaphore.post();

    

    pinMode(PUSH1, INPUT_PULLUP);

    attachInterrupt(PUSH1, functionPUSH1, FALLING);

}


#endif


The specific sketch greenLED.ino initialises the GREEN_LED output and waits for the event myEvent to blink the green LED.

The other sketches or tasks are similar to the example for the semaphore library.

// *** Sketck greenLED.ino


// Setup

void greenLED_setup()

{

    pinMode(GREEN_LED, OUTPUT);

}


// Loop

void greenLED_loop()

{

    myEvent.waitFor();

    

    blink(GREEN_LED, 3, 333);

    

    digitalWrite(RED_LED, LOW);

    digitalWrite(BLUE_LED, LOW);

    

    mySemaphore.waitFor();

    

    Serial.print(millis(), DEC);

    Serial.println("\t4\t*");

    

    mySemaphore.post();

}

SWI with Trigger Library Variant

The SWI offers an interesting option called trigger.

The SWI mySWItrigger is defined with a trigger, here 3.

The function functionSWItrigger associated with mySWItrigger event is fired 
  • after mySWItrigger.dec(), only when the count reaches 0, but 
  • always after mySWItrigger.inc() or mySWItrigger.post().

So the button PUSH1 needs be pressed and released three times before the function functionSWItrigger is fired and myEvent sent.

The example includes additional LEDs, 
  • blue when button PUSH1 is pressed and released and mySWItrigger is counting, and 
  • red when the count reaches the trigger and runs functionSWItrigger.

Once functionSWItrigger, has run, the count resumes the initial value of the trigger, here 3.

// *** Header rtosGlobals.h


// Include application, user and local libraries

#include "SWItrigger.h"


// Define variables and constants

SWItrigger mySWItrigger;


// SWItrigger function

void functionSWItrigger()

{

    chrono = millis();

    digitalWrite(BLUE_LED, LOW);

    digitalWrite(RED_LED, HIGH);


    myEvent.send();

}


// PUSH1 function

void functionPUSH1()

{

    digitalWrite(RED_LED, LOW);

    digitalWrite(BLUE_LED, HIGH);


    mySWItrigger.dec();

}


// Add optional rtosSetup function

void rtosSetup()

{

    pinMode(RED_LED, OUTPUT);

    pinMode(BLUE_LED, OUTPUT);

    

    Serial.begin(115200);

    mySemaphore.begin(1);

    mySWItrigger.begin(3, functionSWItrigger);

    myEvent.begin();

    

    mySemaphore.waitFor();

    Serial.println("rtosSetup");

    mySemaphore.post();

    

    // Solution 2: Energia interrupt

    pinMode(PUSH1, INPUT_PULLUP);

    attachInterrupt(PUSH1, functionPUSH1, FALLING);

}


#endif

Powered by Create your own unique website with customizable templates.