the Reflex, what a game...

Getting started with a BrainStem using Reflexes


This guide describes the basic steps to compile, load and run a Reflex program along with providing a basic example for flashing the User LED.

Required Items

This guide was designed using the following items:

  • BrainStem Module
  • BrainStem Development Board
  • Link transport cable
  • aConsole
  • Acroname Reflex Compiler (arc)

BrainStem Module and optionally a BrainStem Development board can be purchased from the Acroname Store.  aConsole and the Acroname Reflex Compiler can be found in the BrainStem Support Package which is available from the Acroname Download page. Extract the package to the location of your choice once the download is acquired.

About Reflexes

Reflexes are simply reactions to other actions.  The Reflex language is an event driven programming language built around this concept.  A reflex is written to fire when an event occurs providing tight-loop, rapid response without host interaction or other processing.  The host can initiate reflexes and change the state of reflex loops but typically isn't involved with the reflex actions.

The following are some applications that are well suited for reflex loops:

  • Responding to a button press
  • Turning off motors when the host link goes down
  • Initializing hardware after a reset

Compiling a Reflex

Reflexes are compiled using the Acroname Reflex Compiler also known as Arc.  Compiling a Reflex (typically with a .reflex extension) creates a .map file which gets interpreted by the Reflex Virtual Machine.

Acroname also provides the aStemStoreTool to assist users in compiling, loading and running reflexes on BrainStem modules. Arc and aStemStoreTool are included in the BrainStem Support Package.

Example Code

The following Reflex shows how to toggle the User LED.  A copy of this example code can be found in flashmyled.reflex located in the aUser directory of the BrainStem Support Package.  Please visit the Flashing My User LED using Reflex page for a detailed explanation of the code. When creating your own reflex make sure you save it in the aUser directory.

/* file: flashmyled.reflex */

#include <a40PinModule.reflex>

a40PinModule stem;

// 1 second delay
#define DELAY 1000000

reflex mapEnable()
  char i = 0;

  for (i = 0; i < 10; i++) {

  } // end of for loop

} // end of mapEnable

Compile, Load and Run

Navigate to the aBinary folder of the BrainStem Support Package to find aStemStoreTool.  A transport selection dialogue should appear when aStemStoreTool is first opened.  Select the appropriate transport type to continue.  

dialogue box to select appropriate link transport

Transport selection dialogue

The following window should appear once aStemStoreTool has successfully connected to a BrainStem module.

screenshot of astemstoretool that has connected to a BrainStem module

aStemStoreTool app

A user must first select the reflex file to be compiled.  Clicking the "Select" button will show a file selection dialogue box.  The reflex file must be placed inside the aUser directory in order to be found.

The next step is to enter the desired store and slot where the compiled map file will be loaded.  The default value for Store is 0 which refers to the Internal Store.  The Internal Store is persistent across power cycles. Typically used for storing compiled reflex maps and templates. Can be configured to automatically enable on boot up/reset. The default value for Slot is 0 which refers to the first slot in the Internal Store.  Other Stores and Slots may be used but use the default ones for this example.

Clicking the "Load" button will use Arc to compile the reflex file and load the compiled Map file into the specified store and slot if compilation is successful.  The circular red indicator will turn green if the Map file is successfully compiled and loaded into the BrainStem module. 

screenshot of successful compiling and loading of a reflex file

Successful compiling and loading of a reflex

Compiling a reflex by hand

Arc may be run by hand from the command line.  By default Arc will search the aUser directory If none is specified, but files located in other places may be compiled by specifying their relative location to the Arc binary.

$ ./arc flashmyled.reflex

A successful reflex compilation should give the following output:

Acroname Reflex Compiler (arc)
version X.X, build XXXXXX
Copyright 1994-2XXX, Acroname Inc.

compiled to 74 bytes in