GLAST/LAT > DAQ and FSW > FSW > Doxygen Index > EMP / V1-2-0

Constituent: asc     Tag: mv2304


Interface   Data Structures   File List   Data Fields   Globals  

ASC_eds.c File Reference

Setup the ASC histogram within the EDS framework. More...

#include "EMP/LSD_sdi.h"
#include "EMP/ASC.h"
#include "EMP/ASC_ids.h"
#include "EMP/ASC_ascCtb.h"
#include "EMP/ASC_ascBdy.h"
#include "EMP/EMP_hdrdefs.h"
#include "EMP/EMP_tlmdefs.h"
#include "EMP/EMP_write.h"
#include "EMP_hdr.h"
#include "EMP/ASC_statsdefs.h"
#include "EMP/EMP_msgs.h"
#include "EMP_DB/ASC_DB_schema.h"
#include "EDS_DB/EDS_DB_schema.h"
#include "EDS/EDS_fw.h"
#include "EDS/EBF_evt.h"
#include "EDS/EBF_cid.h"
#include "EDS/EBF_gem.h"
#include "EDS/EBF_dir.h"
#include "EDS/EBF_gemLocate.h"
#include "EDS/EDR_acdUnpack.h"
#include "EDS/FFS.h"
#include "LSF/LSF.h"
#include "LSF/LSF_ids.h"
#include "LSF/LSF_reason.h"
#include "ITC/ITC_pubdefs.h"
#include "ZLIB/zlib.h"
#include "MSG/MSG_pubdefs.h"
#include "PBS/TMR.h"
#include "PBS/MBA.h"
#include "PBS/FPA.h"
#include "PBS/WUT.h"
#include "PBS/WUT_tmr.h"
#include "PBS/FORK.h"
#include "PBS/PTS.h"
#include <string.h>

Include dependency graph for ASC_eds.c:


Data Structures

struct  _OutputMessage
 This is a buffer with a header large enough to hold the control information to both store this on the FPA free que and post it to an output FORK que. The body of the message is the buffer for the output datagram. More...
struct  _Prescaler
 Prescaler control structure. More...
struct  _LastEvent
 Information about the last event in the previous packet. This used to seed the begin information of the next packet. More...
struct  _FlushMessage
 Flush fork message structure. More...
struct  _Flush
 Flush control structure. More...
struct  _ASC
 The control structure for an ASC process. More...

Defines

#define TRACE_PUT(xx, yy)
#define ASC_VER_K_DATAGRAM   0
 The version of the ASC datagram that is being produced.
#define NUM_COUNTER_BUFFS   3
 Number of messages to accumulate histograms in.
#define RND_TO(_v, _r)   (((_v) + (_r) - 1) & ~((_r) - 1))
 Rounds the specified value up to the _r. _r must be a binary power of 2.

Typedefs

typedef _OutputMessage OutputMessage
 Typedef for struct _OutputMessage.
typedef _Prescaler Prescaler
 Typedef for struct _Prescaler.
typedef _LastEvent LastEvent
 Typedef for struct _LastEvent.
typedef _FlushMessage FlushMessage
 Typedef for struct _FlushMessage.
typedef int(* FlushDeliverRtn )(void *ctx, FORK_cb_rtn rtn, FORK_msg_hdr *msg)
 Signature of routine to deliver a flush message.
typedef _Flush Flush
 Typedef for struct _Flush.
typedef _ASC ASC
 Typedef for struct _ASC.

Functions

static unsigned int AscEdsSizeof (const void *db, void *prm)
 This is the EDS service to return the size of the context structure.
static const EDS_fwHandlerServices * AscEdsConstruct (ASC *asc, const ASC_DB_Schema *db, ASC_handlerConstructCfg *cfg, EDS_fw *edsFw)
 This is the EDS constructor for ASC. It's name is supplied to the caller via the ASC_constructServicesGet routine.
static int AscEdsDestruct (ASC *asc)
 The EDS destructor service.
static unsigned int AscEdsObjectsGet (ASC *asc)
 The EDS Objects Get service. This returns a bit mask of the objects managed EDS that ASC requires.
static unsigned int AscEdsNeedsGet (ASC *asc)
 The EDS Needs Get service.
static int AscEdsFlush (ASC *asc, int reason)
 The EDS flush service.
static unsigned int AscEdsProcess (ASC *asc, unsigned int pktBytes, EBF_pkt *pkt, EBF_siv siv, EDS_fwIxb *ixb, int id)
 The EDS Event Processing Service.
static int CompressIt (z_stream *zstream, void *dst, int dstLen, void *src, int srcLen)
 Utility function to call the ZLIB deflate routine.
static unsigned int output (ASC *asc, OutputMessage *msg)
 The datagram output routine. This is a FORK service callback routine.
static unsigned int forkExit (ASC *asc, OutputMessage *msg)
 Forces the FORK task to exit.
static void initMsg (void *unused, OutputMessage *msg, int msg_size, int pcb_offset)
 This is the FPA initialization callback routine used to initialize each packet in the FPA pool.
const EDS_DB_HandlerConstructServices * ASC_constructServicesGet (ASC_handlerConstructCfg *cfg)
 Routine called by LPA (via EMP_DB) to get constructionr info for ASC.
static __inline FPA_fcb * createFpaPool (int cnt)
 Creates the FPA pool used to hold the input message packets.
static __inline unsigned int createOutputTask (ASC *asc)
static __inline ASC_ascBdy_Raw0get_packet (ASC *asc)
 Returns a pointer to the packet to be filled in.
static __inline void set_aem (EBF_dir *dir, EBF_pkt *pkt, unsigned int pktBytes)
 Locates the AEM data without doing a full directory. The pointer to the AEM contribution is stashed away in the EBF directory structure. This is a little sleazy, but that's where EDR_acdUnpack expects to find it.
static void * zlibMalloc (void *arg, unsigned int nitems, unsigned int size)
 Callback function used by ZLIB to allocate memory.
static void zlibFree (void *arg, void *address)
 Callback function used by ZLIB to free memory.
static unsigned int zlibInitStream (z_stream *stream, int level)
 Does the one time initialization of the compression stream.
int flush_forward (void *lcb, FlushMessage *msg)
 Executes in the context of the event handling task.
WUT_cb_status flush_tmr (ASC *asc, WUT_tmr *tmr)
 This is the timer ISR flush routine.
static __inline void dgmComplete (LSF_datagram *dgm, ASC *asc, unsigned int payloadSize, unsigned int bridge)
 Completes the datagram header information.

Variables

static const unsigned char OpenReasons [16]
 Maps a closing reason into its complimentary open reason.

Detailed Description

Setup the ASC histogram within the EDS framework.

Author:
Ed Bacho - ebacho@slac.stanford.edu

JJRussell- russell@slac.stanford.edu

    CVS $Id: ASC_eds.c,v 1.5 2006/03/01 01:44:42 russell Exp $

SYNOPSIS
Sets up the ASC histogram routines as an EDS service to be connected to the event stream. THis also handles the compression of the histograms into science packets to be sent to the SDI.

Define Documentation

#define NUM_COUNTER_BUFFS   3
 

Number of messages to accumulate histograms in.

Processing in fork takes about 300mSec for compress,clear, and output Since buffers will be switched after maybe 10sec, double buffer would probably work but 3 are specified for safety

#define RND_TO _v,
_r   )     (((_v) + (_r) - 1) & ~((_r) - 1))
 

Rounds the specified value up to the _r. _r must be a binary power of 2.

Returns:
The rounded value
Parameters:
_v The value to round
_r The boundary to round up to. This must be a binary power of 2, e.g. 2, 4, 8, 16 etc.


Typedef Documentation

int(* FlushDeliverRtn)(void *ctx, FORK_cb_rtn rtn, FORK_msg_hdr *msg)
 

Signature of routine to deliver a flush message.

Returns:
Status
Parameters:
ctx Context parameter, likely controls the destination
rtn The routine to call once the message is delivered
msg The message to deliver


Function Documentation

const EDS_DB_HandlerConstructServices ASC_constructServicesGet ASC_handlerConstructCfg cfg  ) 
 

Routine called by LPA (via EMP_DB) to get constructionr info for ASC.

Returns:
Pointer to EDS_DB_HandlerConstructServices structure
Parameters:
cfg The handler construction configuration

static const EDS_fwHandlerServices * AscEdsConstruct ASC asc,
const ASC_DB_Schema *  db,
ASC_handlerConstructCfg cfg,
EDS_fw *  edsFw
[static]
 

This is the EDS constructor for ASC. It's name is supplied to the caller via the ASC_constructServicesGet routine.

Returns:
The table of EDS services for ASC
Parameters:
asc The ASC context handle to fill in
db The configuration database.
cfg Optional user parameter. This is just part of the EDS services interface and is not used in the case of ASC. In some applications, the size of the context structure might depend on this parameter. Whereas the schema is meant to be fairly static object read from a file, prm is meant to be used more dynamically, perhaps being derived from command line parameters
edsFw The handle of the controlling EDS framework
This routine, along with AscEdsSizeof, form the pair of routines used by high level applications to install an event handler into an EDS framework. This routine has to functions

  1. To initialize the ASC context handle. This handle is usually allocated by the called using the Sizeof service in the construct services to determine the memory requirements.

  1. To return the vector of standard EDS services

static int AscEdsDestruct ASC asc  )  [static]
 

The EDS destructor service.

Returns:
Status, 0 is considered successful
Parameters:
asc The ASC context handle
This is called when the EDS framework itself is destroyed or when this handler is unregistered. In general, the destructor frees only its internal resources. The memory for the ASC context handle itself should be freed by the same entity that allocated it.

static int AscEdsFlush ASC asc,
int  reason
[static]
 

The EDS flush service.

Parameters:
asc The ASC context handle
reason An enumeration of why the flush is being called.
This routine is called both internally by the ASC event processing routine when a packet is ready to be shipped and by the EDS framework, for example, when a run is being ended and the event handlers are being requested to flush their buffers to the output stream.

static unsigned int AscEdsNeedsGet ASC asc  )  [static]
 

The EDS Needs Get service.

Returns:
Returns a bit mask of which packets in a multi-packet event ASC processing routine needs to see.
Parameters:
asc The ASC context handle
ASC is fairly typical of the event processors in that it wishes to be called back only on the first and last packet in a sequence. On multi-packet events, the processing routine will request EDS to compose a directory on its behalf and to be not called back until the final packet. On single packet events, where the first and last packets are the same packet, the ASC event processing routine processes the event on the first call and cancels its request to be called back on the last packet.

static unsigned int AscEdsObjectsGet ASC asc  )  [static]
 

The EDS Objects Get service. This returns a bit mask of the objects managed EDS that ASC requires.

Parameters:
asc The ASC context handle

static unsigned int AscEdsProcess ASC asc,
unsigned int  pktBytes,
EBF_pkt *  ebfPkt,
EBF_siv  siv,
EDS_fwIxb *  ixb,
int  id
[static]
 

The EDS Event Processing Service.

Return values:
EDS_FW_FN_M_NO_MORE,when no more packets of this event are needed to complete the processing.
EDS_FW_FN_M_DIR,when ASC is requesting EDS to compose a directory on its behalf.
0,when ASC has been handed one of the middle packets in a sequence. This is an error either in AscEdsNeedsGet (it should only specifiy the first and last packet be delivered to this routine) or an internal error in the EDS framework.
Parameters:
asc The ASC context handle
pktBytes The number of bytes in ebfPkt
ebfPkt The EBF packet as delivered by the hardware
siv The state information vector. This value is provided as a community service to all event handlers. It summarizes the current state of the packet, including an transport or protocol errors it has encounter and the packet's sequencing information (FIRST, ONLY, MIDDLE, LAST).
ixb The information exchange block. This is a shared knowledge base managed by EDS and used by the event processors. It contains higher level information about the event. Once filled by one processor, all others are free to use it. This tactic saves the CPU from producing this information for each consumer.
id The EDS identifier. This value is unused in the case for ASC, but some applications need this value as a way of identifying themselves.

static unsigned int AscEdsSizeof const void *  db,
void *  prm
[static]
 

This is the EDS service to return the size of the context structure.

Returns:
The size, in bytes, of the ASC context
Parameters:
db The configuration database. This parameter is just part of the EDS services interface and is not used in the case of ASC. In some applications, the size of the context structure might depend on configuration parameters in the database.
prm Optional user parameter. This is just part of the EDS services interface and is not used in the case of ASC. In some applications, the size of the context structure might depend on this parameter. Whereas the schema is meant to be fairly static object read from a file, prm is meant to be used more dynamically, perhaps being derived from command line parameters
This routine is seeded as the Sizeof service of the ASC constructor services routine and is used by the called to determine the size of and then allocate a ASC context handle. This handle is then passed to the construct service (AscEdsConstruct).

static int CompressIt z_stream *  stream,
void *  dst,
int  dstLen,
void *  src,
int  srcLen
[static]
 

Utility function to call the ZLIB deflate routine.

Returns:
The length, in bytes, of the compressed data. If 0, then the deflate failed.
Parameters:
stream The ZLIB stream used to control the deflation
dst The destination buffer
dstLen The length, in bytes, of the destination buffer
src The source buffer to compress
srcLen The length, in bytes, of the source buffer.
This is just a jacketing routine for the ZLIB deflate routine

static __inline FPA_fcb * createFpaPool int  cnt  )  [static]
 

Creates the FPA pool used to hold the input message packets.

Returns:
On success, the handle to the created FPA pool On failure, NULL
Parameters:
cnt The number of packets to place in the pool

static __inline unsigned int createOutputTask ASC asc  )  [static]
 

Returns:
Status, 0 = success On failure, non-zero
Parameters:
asc The ASC control structure, this is just passed transparently as the user parameter to the created FORK task

static __inline void dgmComplete LSF_datagram *  dgm,
ASC asc,
unsigned int  payloadSize,
unsigned int  bridge
[static]
 

Completes the datagram header information.

Parameters:
dgm The target datagram
asc The ASC context handle
payloadSize The size, in bytes, of the contribution's data
bridge The contribuion bridge word

int flush_forward void *  lcb,
FlushMessage msg
 

Executes in the context of the event handling task.

Parameters:
lcb The LCB device context handle, not used here
msg The message
Forcing this routine to execute in the context of the event handling task provides the necessary synchronization so that an update of the histograms is not happening simoultaneously with this routine.

WUT_cb_status flush_tmr ASC asc,
WUT_tmr *  tmr
 

This is the timer ISR flush routine.

Returns:
WUT_K_STATE_CHANGE_NO
Parameters:
asc The ASC context handle
tmr The timer

static unsigned int forkExit ASC asc,
OutputMessage msg
[static]
 

Forces the FORK task to exit.

Return values:
!FORK_C_CONTINUE 
Parameters:
asc The ASC context handle, ignored
msg The FORK messsage, ignored

static __inline ASC_ascBdy_Raw0 * get_packet ASC asc  )  [static]
 

Returns a pointer to the packet to be filled in.

Returns:
A pointer to the packet to be filled in, or NULL on failure
Parameters:
asc The ASC context handle

static void initMsg void *  unused,
OutputMessage msg,
int  msg_size,
int  pcb_offset
[static]
 

This is the FPA initialization callback routine used to initialize each packet in the FPA pool.

Parameters:
unused This is usually the user context parameter. In this case it is unused.
msg The message packet to initialize.
msg_size The size, in bytes, of msg. In this case it is unused.
pcb_offset The offset, in bytes, of the packet control block. This parameter is provided by FPA so that the user may avoid stomping on the control block of this packet.

static unsigned int output ASC asc,
OutputMessage msg
[static]
 

The datagram output routine. This is a FORK service callback routine.

Return values:
FORK_C_CONTINUE,to continue processing packets
Parameters:
asc The ASC context handle
msg The FORK messsage
This routine is generally executed in the context of ASC's output FORK task. It is responsible for completing the formatting of an ASC datagram and shoveling it off to the output device (the SDI).

static __inline void set_aem EBF_dir *  dir,
EBF_pkt *  pkt,
unsigned int  pktBytes
[static]
 

Locates the AEM data without doing a full directory. The pointer to the AEM contribution is stashed away in the EBF directory structure. This is a little sleazy, but that's where EDR_acdUnpack expects to find it.

Parameters:
dir The directory structure
pkt The event packet
pktBytes The number of bytes in the packet
This routine can be used only on single packet events and should be used iff the directory has not already been formed. The only reason this routine exists is for speed. In the case where the directory has already been formed, obviously there is no point in locating the AEM structure again. When applicable this routine is about 40% faster than doing a full directory structure (on the SUN DIR is around 3.8 usecs and this routine is around 2.5 usecs.)

static void * zlibFree void *  arg,
void *  address
[static]
 

Callback function used by ZLIB to free memory.

Returns:
A pointer to the memory to free
Parameters:
arg Arbitrary user parameter, unused in this routine
address The adddress of the memory to free
This is just a call-through to MBA_free.

static unsigned int zlibInitStream z_stream *  stream,
int  level
[static]
 

Does the one time initialization of the compression stream.

Return values:
0,on success
EMP_GENERROR,on error
Parameters:
stream The compression stream to initialize
level The compression level to use

static void * zlibMalloc void *  arg,
unsigned int  nitems,
unsigned int  size
[static]
 

Callback function used by ZLIB to allocate memory.

Returns:
A pointer to the allocated memory
Parameters:
arg Arbitrary user parameter, unused in this routine
nitems The number of items to allocate
size The size, in bytes, of an item
This is just a call-through to MBA_alloc.


Variable Documentation

unsigned char OpenReasons[16] [static]
 

Initial value:

{
  LSF_REASON_OPEN_K_START,      
  LSF_REASON_OPEN_K_START_OP,   
  LSF_REASON_OPEN_K_AUTO_TIME,  
  LSF_REASON_OPEN_K_AUTO_COUNT, 


                                
  LSF_REASON_OPEN_K_START,      
  LSF_REASON_OPEN_K_START_OP,   
  LSF_REASON_OPEN_K_START_AUTO, 
  LSF_REASON_OPEN_K_START,      

                                
  LSF_REASON_OPEN_K_RESUME,     
  LSF_REASON_OPEN_K_RESUME_OP,  
  LSF_REASON_OPEN_K_RESUME_AUTO,

                                
  LSF_REASON_OPEN_K_AUTO,       
  LSF_REASON_OPEN_K_AUTO_MODE,  
  LSF_REASON_OPEN_K_AUTO_TIME,  
  LSF_REASON_OPEN_K_AUTO_COUNT, 
  LSF_REASON_OPEN_K_AUTO_FULL   
}
Maps a closing reason into its complimentary open reason.

When a datagram is closed, it is highly likely that a new one will be opened. This new datagram needs a reason for being opened. In many cases this reopening is automatic, so the opening reason must be internally generated. This array fills that need, mapping an closing reason into its complimentary open reason.
Even though this maps all close reasons, some the close reasons are not automatically and likely will not be used. For completeness, a reasonable value is filled in. These entries are marked in the comments with an XX


Generated on Mon Oct 16 23:51:23 2006 by  doxygen 1.4.4