Scratchpad

Acroname SCRATCHPAD exampleOVERVIEW

Scratchpad is where the BrainStem stores variable information that can be used for multiple reflexes.  Information stored here can be used for many applications because, when a value is changed, the changes carry throughout the rest of the reflexes.

BrainStem application examples require that the BrainStem Support package. Acroname provides simulated BrainStem modules within this distribution that can be used, in the absence of hardware, using the Symonym application .

THE SETUP

There are several hardware components needed for this example:

  • 40-Pin EtherStem 1.0 Module
  • 40-Pin Development Board
  • Ethernet Cable
  • Power Supply
  • Computer

- OR -

  • Symonym Software Package

Acroname SCRATCHPAD example setup
Example Setup

SCRATCHPAD

The Scratchpad serves as on-board RAM.  It is communicated to by the host and reflexes.  It is available to multiple processes at once as a shared location and makes inner process communication quick and easy.  The Scratchpad provides a location to store important information that can be accessed and manipulated at any time, with the manipulations affecting all relevant processes.

DEVELOPING THE CODE

The mapEnable function utilizes a function call to primerIterate.  The function primerIterate utilizes the System class and the Timer class.  The Expiration entity of the Timer class is then used to adjust the length of time between Timer executions.  Inside the Timer the System class utilizes the LED entity to get the current state of the User LED and to inverse that state.  The Timer then uses a function call to primerIterate again.

CHANGING LED FLASH RATE

#include <a40PinModule.reflex>

#define DELAY 1000000
#define INCREMENT 10000

a40PinModule stem;

pad[0:3] signed int timing;

void primerIterate() {
  if(timing >= DELAY) {
      stem.system.setLED(false);
  } else {
    stem.timer[1].setExpiration(timing);
  }
}

reflex mapEnable() {
  timing = 10000;
  primerIterate();
}

reflex timer[1].expiration(){

  unsigned char bLEDState;

  stem.system.getLED(bLEDState);
  stem.system.setLED(!bLEDState);

  timing = timing + INCREMENT;

  primerIterate();
}

Line 8 - Creates a variable in the scratchpad called timing.
Line 12 - Turns User LED off after timing.
Line 14 - Starts Timer [1].
Line 20 - Calls the primerIterate function.
Line 27 - Reads the current User LED state.
Line 28 - Inverses current User LED state.
Line 32 - Calls primerIterate function.

Weight
0