dpharris / OlcbRefresh

Refresh of the Arduino base libs
1 stars 3 forks source link

OlcbRefresh

WARNING This code is in development. TivaCAN appears to work, but not AT90CAN (it transmits, but does not receive). Others not tested.

This is a refresh of the Arduino base libs, ie OlcbStarLibraries.

It is meant to simplify and extend the Arduino code.

Changes:

  1. Added support for multiple processors: Arduino, Teensy, Tiva.
    • Each set of files specific to a CAN-processor is kept in its own directory.
    • The processor is automatically selected in the processor.h file.
  2. A sorted Index[] is used to speed eventID processing, using a hash of the eventid.
  3. Simplified the definition of CDI/xml for the node by matching a struct{} to the xml structure, see the example below.

e.g.: This CDI/xml, which self-describes the node to the system:

    <cdi>
        ...
        <group replication='8'>
        <name>Channels</name>
            <eventid><name>event0</name></eventid>
            <eventid><name>event1</name></eventid>
        </group>
        ...
    </cdi>

parallels this program structure:

    typedef struct {
        ...
        struct {
            EventID event0;
            EventID event1;
        } channels[8];
        ...
    } MemStruct;

Memory Models:

The code can be written to be maximize space or speed, and the user can choose from three memory models:

  1. Small: All operations are from EEPROM
    Minimizes RAM size, but is slower. If many eventIDs are needed, it may be the only choice.
  2. Medium: only eventIDs are copied to RAM into eventids[]
    Quite good compromize between size and speed.
  3. Large: The whole of EEPROM is mirrored to RAM as mem[]
    Faster but larger. This is best on larger processors.

    In Flash:

    eventidOffset[] stores the offset of each eventID into the EEPROM or RAM struct{}.
    It is initialized at compile-time.

    In RAM:

    eventidIndex[] contains a hash of each eventID, and an associated sequential index into eventidOffset[].
    It is sorted on the hash values.

In the medium model only, eventids[] contains a copy of the node's eventIDs, and is indexed by eventidIndex[].

This restated as a diagram:

More about OpenLCB/LCC - what is it?

OpenLCB/LCC is a set of heirarchical protocols to let nodes talk to each other.
For more information on OpenLCB, see: OpenLCB.org
For protocol descriptions, see: Adopted LCC Documents

These protocols consist of:

How the Above Translates to the Codebase

The 'codebase' is a set of libraries and functions that implement the basic protocols of OpenLCB/LCC.
Each protocol has corresponding code, usually in the form of a class, and implemented as a pair of .h and .cpp files.
The codebase tries to hide some of the complexity in #include files.

However, each protocol needs to have:

For example there are some selected lines of code from the OlcbBasicNode example used for initialization:

  NodeID nodeid(5,1,1,1,3,255);    // This node's default ID; must be valid 
  const char SNII_const_data[] PROGMEM = "\001OpenLCB\000DPHOlcbBasicNode\0001.0\000" OlcbCommonVersion ; 
  uint8_t protocolIdentValue[6] = {0xD7,0x58,0x00,0,0,0};
  ButtonLed* buttons[] = { &pA,&pA,&pB,&pB,&pC,&pC,&pD,&pD };
  PCE pce(&nodal, &txBuffer, pceCallback, restore, &link);
  BG bg(&pce, buttons, patterns, NUM_EVENT, &blue, &gold, &txBuffer);

Most of the processing is hidden as functions in the #include files.

How Does the Application Interact with the Codebase?

The programmer of the Application must:

Example Applications

The provided examples will give some ideas of how to accomplish sample projects. They can form the basis of, or be adapted to, a new Application, or just used for inspiration.