Embedded Computing
  • About
  • Blog
  • Hardware
    • Which Platform?
    • Controller Platforms >
      • Adafruit Platform
      • Arduino Plaform
      • BBC micro:bit
      • Espressif Platform
      • LaunchPad Plaform
      • Microsoft Azure IoT DevKit
      • Seeeduino Platform
      • Teensy Plaform
    • Computer Platforms >
      • BeagleBone Platform
      • Mediatek Platform
      • UDOO Platform
    • Legacy Platforms >
      • chipKIT Plaform >
        • chipKIT Uno32 and uC32
        • chipKIT WF32 and WiFire
        • Compatibility
        • chipKIT PGM Programmer-Debugger
        • 4D Systems PICadillo-35T
        • Shields for chipKIT Uno32
        • 4D Systems Platform >
          • 4D Systems PICadillo-35T
          • 4D Systems gen4-IoD-28T
      • Cosa, an Alternative Framework for AVR Boards
      • DFRobot Platform >
        • DFRobot BLuno
        • DFRobot Wido
      • Digistump Platform >
        • Digispark
        • Oak
      • Intel Platform >
        • Intel Curie with Neural Network
        • Intel Edison
      • LightBlue Bean
      • Little Robot Friends
      • Maple Plaform >
        • LeafLabs Maple
      • Microduino Plaform >
        • Microduino
      • Particle Platform >
        • Particle Core
        • Particle Photon
        • Particle Tools
      • Protostack Platform >
        • Protostack Boards
      • RedBear Platform >
        • RedBearLab CC3200
        • RedBearLab WiFi Mini
        • RedBear Duo
      • Wiring Plaform >
        • Wiring S
        • Wiring Play Shield
    • Boards and Plugs
    • I²C Logic Level Converter
    • Peripherals >
      • BoosterPacks for LaunchPads
      • Shields
      • Grove System
      • Ten Years with the Grove System
      • Sensors
      • Actuators
    • Displays >
      • Pervasive Displays e-Paper Screens
      • FRAM-based E-Paper Screen Controller
      • The 2.8" HY28A LCD Screen
      • High-Definition 480x320 3.5" Screen With Touch and Fonts
      • Kentec 3.5" LCD SPI with Touch BoosterPack
      • 4D Systems Intelligent Screens
      • East Rising 5" LCD with RA8875, Touch, Fonts, Flash and SD-card
      • East Rising 5" LCD with SSD1963, Touch, Flash and SD-card
  • Software
    • The IDE Question >
      • The Battle of IDEs
      • More IDE Options
      • Looking for a Better IDE
      • Assessing the Next Generation of IDEs
    • 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
  • IoT
    • IoT Platforms: Which Hardware?
    • 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
      • LaunchPad and BoosterPack Boards Pins Maps
      • Ruler
      • 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
    • IDEs >
      • Texas Instruments Code Composer Studio 6
      • Texas Instruments Code Composer Studio Cloud
      • Energia
      • Tools for Documentation
    • Equipment >
      • Saleae Logic Analyser
      • Rigol DS1102E Oscilloscope
      • XDS110 Debug Probe with EnergyTrace​
      • Segger J-Link Programmer-Debugger
  • Projects
    • Libraries >
      • Master I²C Software Library
      • Date and Time Library
      • highView Library Suite
      • LCD_screen 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 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 >
      • 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

Mailbox Library

How to send data from one task to another? Mailbox brings one solution.

The mailbox is defined by two parameters: 
  • the kind of data, here the structure myMessage_t
  • the number of slots, here 4 set during initialisation with begin().

Contrary to the Queue element that stores pointers, the Mailbox element copies and stores the messages inside. This provides a safe and clean way for sending data from one task to another.

The Mailbox element runs shares the same logic and same limitation with the Event element. The Mailbox element can have multiple senders but only one receiver. 

// myMessage type for mailbox

typedef struct myMessage_t

{

uint32_t chrono;

char buffer[10];

};


// Number of messages on the mailbox

#define NUMBER 4


// Mailbox post modality: either BIOS_WAIT_FOREVER or BIOS_NO_WAIT.

#define MODALITY BIOS_WAIT_FOREVER


// myMailbox

Mailbox<myMessage_t> myMailbox;


// mySemaphore

Semaphore mySemaphore;


The first sender includes a setup() function to initialise the Serial port and the mailbox myMailBox. Here, the mailbox is set to NUMBER = 4 slots.

The two senders share the same code for the loop() function. Depending on the MODALITY value, 
  • If MODALITY is set to BIOS_WAIT_FOREVER, the post() function waits until a slot is available, and then posts the message and returns TRUE.
  • If MODALITY is set to BIOS_NO_WAIT, the post() function posts the message if a slot is available and return TRUE, otherwise return FALSE as the message hasn't been posted.

The option BIOS_NO_WAIT allows the post() process to be non-blocking, but the returned value should be tested. 


Compare the two options below.

void MailboxSender1_setup()

{

    Serial.begin(115200);


    myMailbox.begin(NUMBER); // default = 16

}


void MailboxSender1_loop()

{

    messageS.chrono = millis();

    strcpy(messageS.buffer, "from 1");


    // Mailbox post modality: either BIOS_WAIT_FOREVER or BIOS_NO_WAIT.

    bool result = myMailbox.post(messageS, MODALITY);


    delay(300);

}


  • With BIOS_WAIT_FOREVER

?   Chrono Action       Message   Available Result

?                  .chrono .buffer                

1>     6    TX     6       from 1     1      1

*<     100  RX     6       from 1     1         

2>     102  TX     100     from 2     1      1

2>     304  TX     304     from 2     2      1

*<     402  RX     100     from 2     1         

2>     506  TX     506     from 2     2      1

1>     508  TX     508     from 1     3      1

*<     704  RX     304     from 2     2         

2>     708  TX     708     from 2     3      1

2>     910  TX     910     from 2     4      1

*<     1006 RX     506     from 2     3         

1>     1010 TX     1010    from 1     4      1

*<     1308 RX     508     from 1     4         

2>     1310 TX     1112    from 2     4      1

*<     1610 RX     708     from 2     4         

1>     1612 TX     1512    from 1     4      1

*<     1912 RX     910     from 2     4         

2>     1914 TX     1513    from 2     4      1

*<     2214 RX     1010    from 1     4         

1>     2216 TX     2115    from 1     4      1

*<     2516 RX     1112    from 2     4         

2>     2518 TX     211     from 2     4      1

  • With BIOS_NO_WAIT

?   Chrono Action     Message      Available Result

?                .chrono    .buffer                 

1>     6    TX     6        from 1     1      1

*<     100  RX     6        from 1     1      1

2>     102  TX     100      from 2     1      1

2>     304  TX     304      from 2     2      1

*<     402  RX     100      from 2     1      1

2>     506  TX     506      from 2     2      1

1>     508  TX     508      from 1     3      1

*<     704  RX     304      from 2     2      1

2>     708  TX     708      from 2     3      1

2>     910  TX     910      from 2     4      1

*<     1006 RX     506      from 2     3      0 <= not posted

1>     1010 TX     1010     from 1     4      1

2>     1112 TX     1112     from 2     4      0 <= not posted

*<     1308 RX     508      from 1     3      0 <= not posted

2>     1314 TX     1314     from 2     4      1

1>     1512 TX     1512     from 1     4      0 <= not posted

2>     1516 TX     1516     from 2     4      0 <= not posted

*<     1610 RX     708      from 2     3         

2>     1718 TX     1718     from 2     4      1


The client loop waits for a message to be available, and prints it to the Serial port. 

The available() function returns the number of messages on the mailbox to be read. 0 means the mailbox is empty.

void MailboxClient_loop()

{

    myMailbox.waitFor(messageR);

    

    mySemaphore.waitFor();

    Serial.print("*<\t");

    Serial.print(millis(), DEC);

    Serial.print("\tRX\t");

    Serial.print(messageB.chrono, DEC);

    Serial.print("\t");

    Serial.print(messageB.buffer);

    Serial.print("\t");

    Serial.print(myMailbox.available());

    Serial.println("\t:\t");

    mySemaphore.post();

    

    delay(300);

}


Powered by Create your own unique website with customizable templates.