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

State Machine Driver. More...

#include <stdint.h>
#include "util/macro.h"
#include "lm32soc/dev_soc.h"
#include <stddef.h>
#include <stdbool.h>

Go to the source code of this file.

Macros

#define STMACH_FIFO_AES_TSLICE   BIT(31)
 AES timeslice FIFO bit.
 
#define STMACH_FIFO_AES_CH   BIT(0)
 AES channel fifo bit.
 
#define STMACH_FIFO_TDC_TSLICE   BIT(31)
 TDC timeslice FIFO bit.
 
#define STMACH_FIFO_TDC_CH_MASK   MASK(31)
 TDC channel mask.
 
#define STMACH_FIFO_TDC_CH_SHIFT   0
 TDC channel shift.
 
#define STMACH_FLUSH_OP_START   0x1
 
#define STMACH_FLUSH_OP_END   0x2
 
#define STMACH_FLUSH_OP_TOGGLE   (STMACH_FLUSH_OP_START | STMACH_FLUSH_OP_END)
 

Functions

bool stmachInit (uint32_t domId, void *monbuf, size_t monlen)
 Initializes the state-machine with the DOM ID and the monitoring channel CPU data pointer. More...
 
bool stmachConfig (uint32_t packSize, uint32_t duration)
 Configures the stateMachine. More...
 
void stmachMUCfg (uint32_t intervalMs)
 Configure Monitor Update. More...
 
static void stmachSetRunNo (uint32_t runNo)
 Sets the run-number. More...
 
void stmachFlush (uint32_t flush, uint8_t op)
 Flushes one or more state-machine channels. More...
 
bool stmachEnable (uint32_t enable)
 Enables one or more STMACH channels. More...
 
uint32_t stmachEnabled ()
 Returns which state-machine channels are enabled. More...
 
static uint32_t stmachDomId ()
 
uint32_t stmachTSliceCount ()
 Returns the number of timeslice IRQs since system start.
 
static void stmachWaitForTSlices (int tslice)
 Waits for at least the provided number of time-slices. More...
 
void _stmachUpdateMonitor ()
 Stub function invoked when it is time to update the monitor channel.
 
void _stmachOverflowBegin (uint32_t tdcFifo, uint32_t aesFifo)
 Invoked when an AES or TDC fifo overflow occurs. More...
 
void _stmachOverflowEnd (uint32_t tdcFifo, uint32_t aesFifo)
 Invoked when an AES or TDC fifo should be enabled again. More...
 
void stmachFakeFull (uint32_t mask)
 Debugging stuff, don't touch!
 
void stmachGetStCommit (uint16_t *tdc, uint16_t *aes)
 Debug feature: Get TDC and AES state machine Fifo commits. More...
 

Detailed Description

State Machine Driver.

Definition in file stmach.h.

Function Documentation

void _stmachOverflowBegin ( uint32_t  tdcFifo,
uint32_t  aesFifo 
)

Invoked when an AES or TDC fifo overflow occurs.

Parameters
tdcFifoTDC Fifo mask, each bits corresponds to a specific FIFO.
aesFifoAES Fifo mask

Definition at line 85 of file sub_sys.c.

void _stmachOverflowEnd ( uint32_t  tdcFifo,
uint32_t  aesFifo 
)

Invoked when an AES or TDC fifo should be enabled again.

Parameters
tdcFifoTDC Fifo mask, each bits corresponds to a specific FIFO.
aesFifoAES Fifo mask

Definition at line 130 of file sub_sys.c.

bool stmachConfig ( uint32_t  packSize,
uint32_t  duration 
)

Configures the stateMachine.

Parameters
packSizeThe maximum packet size in bytes (will be rounded to 16 bit words);
durationThe duration in microseconds. Must fit integer number of times in one second. E.g. 100ms, 250ms is okay, but 300ms is not.

Definition at line 98 of file stmach.c.

bool stmachEnable ( uint32_t  enable)

Enables one or more STMACH channels.

Parameters
enableAn OR-ed cobination of STMACH_CH_* values
Return values
TrueSuccess
FalseOn timeout

Definition at line 127 of file stmach.c.

uint32_t stmachEnabled ( )

Returns which state-machine channels are enabled.

Parameters
enableAn OR-ed cobination of STMACH_CH_* values

Definition at line 144 of file stmach.c.

void stmachFlush ( uint32_t  flush,
uint8_t  op 
)

Flushes one or more state-machine channels.

Parameters
flushAn OR-ed cobination of STMACH_CH_* values
opFlush operation to execute.

Definition at line 113 of file stmach.c.

void stmachGetStCommit ( uint16_t *  tdc,
uint16_t *  aes 
)

Debug feature: Get TDC and AES state machine Fifo commits.

Parameters
tdcPointer to uint16 to be set with FIFO commit of TDC
aesPointer to uint16 to be set with FIFO commit of AES

Definition at line 149 of file stmach.c.

bool stmachInit ( uint32_t  domId,
void *  monbuf,
size_t  monlen 
)

Initializes the state-machine with the DOM ID and the monitoring channel CPU data pointer.

Once configured the content of the pointer will be transferred to the monitoring channel packed. The buffer must be word (32 bits) aligned, and the length will be rounded up by 4 bytes.

Parameters
domIdThe DOM ID as transmitted with each packet.
monbufPointer to the data to transfer.
monlenLength of the data
recoverTaskIdThe task invoked when the state-machine buffers are overflowing.
Return values
trueSuccesfully initialized
falseInitialization failure, check error module for issue.

Definition at line 72 of file stmach.c.

void stmachMUCfg ( uint32_t  intervalMs)

Configure Monitor Update.

Parameters
intervalMsInterval to which this must occur.

Definition at line 90 of file stmach.c.

static void stmachSetRunNo ( uint32_t  runNo)
inlinestatic

Sets the run-number.

Parameters
runNoThe run number.

Definition at line 84 of file stmach.h.

static void stmachWaitForTSlices ( int  tslice)
inlinestatic

Waits for at least the provided number of time-slices.

Parameters
tsliceThe number of time slices to wait (minimum)

Definition at line 139 of file stmach.h.