KM3NeT CLB  2.0
KM3NeT CLB v2 Embedded Software
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
clbstate.h File Reference

The CLB stare module tracks is responsible for state management of the various sub-systems on the CLB. More...

#include <stdint.h>
#include <stdbool.h>
#include "cfg_subsys.h"
#include "util/macro.h"
#include "kernel/err.h"
#include "appcode.h"

Go to the source code of this file.

Macros

#define E_CLBSTATE_STATECHANGE   ( E_CLBSTATE + 0x01 )
 Invalid state change.
 
#define E_CLBSTATE_STATECHANGE_DESCR   "Invalid State Change"
 
#define CLB_SUB_ALL   255
 Indicates all subsystems. Can be used in clbStateGoto.
 
#define CLB_STATUS_PENDING   BIT(0)
 Indicates that the subsystem is in transit to a new state.
 
#define CLB_STATUS_ERROR   BIT(1)
 
#define SUBS(IDX, ID, NAME)   void _subs ## NAME ## ExecEvent (ClbEvent event);
 
#define SUBS(IDX, ID, NAME)   bool _subs ## NAME ## Update (ClbState state, uint32_t time) __attribute__((weak));
 

Enumerations

enum  ClbState {
  clbStateUndefined = 0, clbStateIdle = 1, clbStateStandBy = 2, clbStateReady = 3,
  clbStatePaused = 4, clbStateRunning = 5
}
 Various states. More...
 
enum  ClbEvent {
  clbEventNone = -1, clbEventBoot = 0, clbEventInit = 1, clbEventConfigure = 2,
  clbEventStart = 3, clbEventPause = 4, clbEventContinue = 5, clbEventStop = 6,
  clbEventQuit = 7, clbEventReset = 8
}
 All state change events. More...
 

Functions

void _subsSysExecEvent (ClbEvent event)
 
void _subsNetExecEvent (ClbEvent event)
 
void _subsOptExecEvent (ClbEvent event)
 
void _subsAcsExecEvent (ClbEvent event)
 
void _subsInsExecEvent (ClbEvent event)
 
bool _subsSysUpdate (ClbState state, uint32_t time)
 
bool _subsNetUpdate (ClbState state, uint32_t time)
 
bool _subsOptUpdate (ClbState state, uint32_t time)
 
bool _subsAcsUpdate (ClbState state, uint32_t time)
 
bool _subsInsUpdate (ClbState state, uint32_t time)
 
void clbStateInit ()
 Initializes the state machine.
 
bool clbEvent (int idx, ClbEvent event)
 Request a subsystem to go to a certain state. More...
 
void clbAutoEventSeq (ClbEvent *events, int seqLen)
 Executes an autonomous a sequence of events. More...
 
void _clbStateUpdate (int idx, ClbEvent event, uint8_t status)
 Invoked by the subsystem to indicate a state change has happened. More...
 
int clbSubId (int idx)
 Returns the subsystem ID code for the provided index. More...
 
void _clbStateError (int idx, int error, const char *message, const char *name)
 Invoked by subsystem to indicate an error happened. More...
 
static void _clbStateModErr (int idx)
 Invoked by subsystem to indicate an error happened. More...
 
bool clbStateError (int idx, int *code, const char **message)
 Retrieves the error of a subsystem (if any). More...
 
ClbState clbState (int idx)
 Returns the current clbSubState for the specified subsystem. More...
 
uint8_t clbStatus (int idx)
 Returns the current subsystem status. More...
 
void clbClearErrorState (int idx)
 Clears the error state of the specific subsystem. More...
 
void clbUpdateSubsys ()
 Invoked the update method on each subsystem.
 

Variables

const char *const clbSubsystemNames [5]
 Contains a list of all the subsystems.
 
const char *const clbStateNames [6]
 Contains list of the state names.
 
uint8_t clbSys2Idx [6]
 Mapping from subsystem ID to index.
 
const char *const clbEventNames [9]
 All state change event names.
 

Detailed Description

The CLB stare module tracks is responsible for state management of the various sub-systems on the CLB.

It also tracks the error of each subsystem. CLB State machine

The following state machine is used:

*            +-----------+             +-----------+
*            |           |             |           |
*            | Undefined |----Boot---->|   Idle    |
*            |           |             |           |
*            +-----------+             +-----------+
*                                        ^      |
*                                      Reset   Init
*                                        |      V
*            +-----------+             +-----------+
*            |           |<-Configure--|           |
*            |   Ready   |             |  StandBy  |
*            |           |----Quit---->|           |
*            +-----------+             +-----------+
*                  |                         ^
*                Start                     Stop
*                  V                         |
*            +-----------+             +-----------+
*            |           |<--Continue--|           |
*            |  Running  |             |  Paused   |
*            |           |---Pause---->|           |
*            +-----------+             +-----------+
* 

Definition in file clbstate.h.

Enumeration Type Documentation

enum ClbEvent

All state change events.

Enumerator
clbEventNone 

Internal use only.

clbEventBoot 

Undefined => Idle, for internal use only.

clbEventInit 

Idle => StandBy.

clbEventConfigure 

StandBy => Ready.

clbEventStart 

Ready => Running.

clbEventPause 

Running => Paused.

clbEventContinue 

Paused => Running.

clbEventStop 

Paused => StandBy.

clbEventQuit 

Ready => StandBy.

clbEventReset 

StandBy => Idle.

Definition at line 88 of file clbstate.h.

enum ClbState

Various states.

Enumerator
clbStateUndefined 

Undefined state (prior to module init, should never be seen on shore)

clbStateIdle 

Idle state.

clbStateStandBy 

StandBy state.

clbStateReady 

Ready state.

clbStatePaused 

Paused state.

clbStateRunning 

Running state.

Definition at line 59 of file clbstate.h.

Function Documentation

void _clbStateError ( int  idx,
int  error,
const char *  message,
const char *  name 
)

Invoked by subsystem to indicate an error happened.

The state will automatically be set to clbStateError.

Parameters
idxThe subsystem index.
errorThe error code
messageThe message, if any

Definition at line 258 of file clbstate.c.

static void _clbStateModErr ( int  idx)
inlinestatic

Invoked by subsystem to indicate an error happened.

The state will automatically be set to clbStateError. This copies the error from the error module and clears it.

Parameters
idxThe subsystem index.

Definition at line 189 of file clbstate.h.

void _clbStateUpdate ( int  idx,
ClbEvent  event,
uint8_t  status 
)

Invoked by the subsystem to indicate a state change has happened.

Parameters
idxThe subsystem index which the state change was effected on
eventThe event triggered
statusThe current status

Definition at line 204 of file clbstate.c.

void clbAutoEventSeq ( ClbEvent events,
int  seqLen 
)

Executes an autonomous a sequence of events.

Change updates are suppressed during this operation.

Note
The list of events is not copied, thus should always be present in RAM.
Parameters
eventsA list of events to execute
seqLenThe number of events.

Definition at line 317 of file clbstate.c.

void clbClearErrorState ( int  idx)

Clears the error state of the specific subsystem.

Parameters
idxThe index of the subsystem.

Definition at line 241 of file clbstate.c.

bool clbEvent ( int  idx,
ClbEvent  event 
)

Request a subsystem to go to a certain state.

Parameters
idxThe index, or CLB_SUB_ALL for all subsystems.
eventThe event to execute

Definition at line 221 of file clbstate.c.

ClbState clbState ( int  idx)

Returns the current clbSubState for the specified subsystem.

Parameters
idxThe subsystem index to request the state of.
Returns
The state of the subsystem

Definition at line 92 of file clbstate.c.

bool clbStateError ( int  idx,
int *  code,
const char **  message 
)

Retrieves the error of a subsystem (if any).

Parameters
idxSubsystem index
codePointer in which the code will be written
messagePointer to which the message will be set
Return values
trueSubsystem has an error
falseSubsystem does not have an error

Definition at line 106 of file clbstate.c.

uint8_t clbStatus ( int  idx)

Returns the current subsystem status.

Parameters
idxThe subsystem index to request the state of.
Returns
The status of the subsystem

Definition at line 118 of file clbstate.c.

int clbSubId ( int  idx)

Returns the subsystem ID code for the provided index.

Parameters
idxSubsystem index.
Returns
Subsystem ID code.

Definition at line 99 of file clbstate.c.