Table of Contents Previous Chapter ACIS

41.0 FEP Timed Exposure Modes (36-53224 02)

41.1 Purpose

The fepSciTimed module, executing in the FEP, implements timed-exposure science processing, comprising either raw mode, event detection mode, or raw histogramming mode. It is called from fepCtl with a single argument, fp, a pointer to the fepParm structure. Before invoking fepSciTimed, the FEP must be commanded to (a) load a timed-exposure FEPparmBlock into fp->tp, and (b) perform a bias calibration.

41.2 Uses

The fepSciTimed function operates in one of the following modes, according to the value of fp->tp.type:

  1. Identify and report 3x3 candidate X-ray events to the BEP.

  2. Identify and report 5x5 candidate X-ray events to the BEP.

  3. Report rows of raw pixels to the BEP.

  4. Accumulate raw pixel histograms and report them to the BEP.

FIGURE 171. fepSciTimed subroutines and their calling hierarchy


41.3 Organization

All interactions with the BEP and with FEP hardware are made through fepio library functions described in Section 38.0. The data structures that are passed between FEP and BEP are defined in that document and in Section 4.10. fepSciTimed makes use of the following functions which call each other in the manner shown in Figure 171:

41.4 Global Variables

The following FEPparm fields, defined in fepCtl.h and invariably addressed by 
the fp pointer parameter, are used by all timed exposure modes:
bepCmd
latest command received from BEP
ex
current
FEPexpRec record
exend
current FEPexpEndRec record
flags
flag bits:
FP_EDGE_ROW
current row is at the top or bottom of the frame
FP_SUSPEND
BEP has sent BEP_FEP_CMD_SUSPEND
FP_PAST_EOR
FEP hardware has finished with the current frame
FP_TERMINATE
BEP has sent BEP_FEP_CMD_STOP
nextexpnum
the next exposure index that the FEP is to process
quadrants
the number of DEA output nodes being sampled
tp
exposure parameter block
The following FEPparm fields are only used by fepSciTimedEvent:
br
pointer to bias calibration parameters
colshft
bit shift to transform column index to node index
fidpix[]
fiducial pixel address list
image
pointer to start of current image row
lastcol
index of last image column
nfidpix
fiducial pixel count
The following FEPparm fields are only used by fepSciTimedHist:
expcount
count of processed exposures
ocount[4]
overclock counters
osum[4][2]
sum of overclock values
osumsq[4][2]
sum of squares of overclock values
phist
pointer to FEPeventRecHist structure

41.5 Scenarios

The following paragraphs describe the basic functions performed in timed exposure mode. All Timed Exposure modes wait until an image frame is processed and copied to the ring buffer before commanding the hardware thresholder to read the next frame, thereby ensuring that no partially processed frames are generated.

41.5.1 Use 1: Report 3x3 Events

FIGURE 173. The Relation Between Image Pixels and FEP Register Values.


FIGURE 174. The Relation Between the Bias Map and FEP Register Values.


41.5.2 Use 2: Report 5x5 Events

41.5.3 Use 3: Report Raw Pixels

41.5.4 Use 4: Report Raw Pixel Histograms.

41.6 Specification


This section describes the functions that are local to the fepSciTimed unit. The only external is fepSciTimed itself which is called from fepCtl. The FEPparm structure is defined in fepCtl.h, along with several pixel access macros. The interface to the FEP I/O library is described in Section 38.0, and data and messages exchanged between FEP and BEP are described in Section 4.10.

41.6.1 fepSciTimed()

#include fepCtl.h
Scope: Science
Return type: void
Arguments
FEPparm *fp
Description:
fepSciTimed is called from fepCtl with a single argument: the pointer fp 
to the fepParm structure. It is responsible for all FEP actions associated with a 
timed exposure science run, except for bias calibration. It performs the following 
actions:
Calls FEPsciTimedInit to validate the BEP's parameter block, fp->tp, for the current mode, to verify that pixel biases have been computed, and to initialize mode-dependent variables. If FEPsciTimedInit returns FEP_CMD_NOERR, fepSciTimed calls fepAckCmd and continues. Otherwise, it calls fepNackCmd to pass the error code to the BEP, indicating that the command has failed, and fepSciTimed then returns to fepCtl.
fepSciTimed calls FIOgetExpInfo to determine the current exposure number and calls fioWriteImPulseReg to set the thresholder's IPULSE_ARMNXTACQ (write-enable) flag.
fepSciTimed then enters a loop, labelled "next frame..." in Figure , calling FIOgetExpInfo until the exposure numbered fp->nextexpnum is encountered (or exceeded). During this loop, calls are made to FIOgetNextCmd to handle any incoming BEP commands, and to FIOtouchWatchdog to prevent the Watchdog Timer from expiring while waiting for that particular frame.
Once the desired exposure index is reached, i.e. once that frame starts to be processed by the FEP hardware, fepSciTimed writes a FEPexpRec record to the ring buffer and then calls either FEPsciTimedEvent, FEPsciTimedRaw, or FEPsciTimedHist to process the frame.
fepSciTimed repeats the steps described in these last three bullets.
The process continues until a BEP_FEP_CMD_STOP command is received from the BEP, which sets the FP_TERMINATE bit in fp->flags. When this occurs, fepSciTimed will finish processing the current frame before returning to fepCtl.

41.6.2 FEPsciTimedInit()

#include fepCtl.h
Scope: Science
Return type: fepCmdRetCode
Arguments
FEPparm *fp
Description:
This function is called from fepSciTimed to verify the contents of the 
FEPparmBlock, fp->tp, and to check whether a bias calibration has been per
formed. It also performs any necessary mode-dependent initialization.
If an error is detected, FEPsciTimedInit returns a fepCmdRetCode code as 
defined in fepBep.h; otherwise it returns FEP_CMD_NOERR.


41.6.3 FEPsciTimedEvent()

#include fepCtl.h
Scope: Science
Return type: void
Arguments
FEPparm *fp
Description:
This function is called from fepSciTimed to process a single timed exposure 
frame. It initializes the following pointers to the addresses of data structures used 
by the hardware thresholder:
pTPlane
points to T-plane buffer
pOclk
points to overclock buffer
fp->image
points to start of first data row
and these pointers will be advanced from row to row. The FP_EDGE_ROW bit in fp->flags is set to indicate that this is the first data row, and the four oSum[] overclock accumulators (one per DEA output node) are zeroed. FEPsciTimedEvent then loops over CCD pixel rows. Once per row, it calls FIOgetNextCmd to see whether the BEP is trying to command the FEP. A re turned value of TRUE signals that a science command has been received (utility commands will be executed within FIOgetNextCmd and will return FALSE), and a call will be made to fepHandleCmd to process it. NOTE: only one call is made to FIOgetNextCmd per incoming pixel row. The function then processes the row data. It adds the overclocks to the oSum ac cumulators. Then it reads the T-plane, 32 bits at a time, until a non-zero value is found---indicating that the hardware detected a threshold crossing. Because the 12- bit pixel and bias values must be loaded in pairs, the 32 T-plane mask bits are tested two at a time---if an even-offset bit has been set, FEPtestEvenPixel is called; otherwise FEPtestOddPixel is called. After processing the image row, FEPsciTimedEvent increments the fp->im age pointer, and recomputes the FP_EDGE_ROW flag. After processing the last row, the oSum overclock accumulators are normalized and used to derive thresh olds for the next exposure, which are communicated to the hardware by calls to FIOsetThresholdRegister for each DEA output node.

41.6.4 FEPtestEvenPixel()

#include fepCtl.h
Scope: Science
Return type: void
Arguments
unsigned irow
unsigned icol
FEPparm *fp
Description:
This function is called from FEPsciTimedEvent for every bit set in the T-plane 
whose bit offset is even. This pixel is located in row irow, column icol, and 
fp->image points to the first pair of pixels in that row. The corresponding pair 
of bias values are to be found in fp->image[BIAS_OFFSET].
FEPtestEvenPixel first loads the 32-bit pixel and bias fields that contain the cen
tral pixel. Since the FEP is a little-endian processor, and the central pixel is stored 
in the lower address pair of bytes, pixel and bias will be loaded into the least-sig
nificant 16 bits of each 32-bit variable. (The most significant 16 bits of these vari
ables will contain the pixel and bias for row irow and column icol+1.)
The pair of bias values is now validated---the bias parity flags (bits 15 and 31) are 
tested to determine whether a parity error has occurred in either of those locations 
in the bias map. If so, a call is made to FEPsciTimedFixBias to handle the 
problem. Since this may instead be a fiducial pixel, the corrected 32-bit bias pair 
is examined; if it still contains a BIAS_PARITY flag, the central pixel is not fidu
cial---the pair of values is written back to the bias map, and the central pixel is ig
nored. Otherwise, processing continues.
Next, a test is made to determine whether this central pixel lies on the boundary of 
the CCD, or if its bias value is either BIAS_BAD (indicating that it had previously 
been found to have a parity error) or PIXEL_BAD (indication that the pixel is a 
member of the bad-pixel list). In any of these situations, the pixel is ignored.

The 12-bit value of the central pixel is saved in ev.p[1][1] and the correspond
ing 12-bit bias value in ev.b[1][1]. Two threshold values are loaded from the 
fp->ex.dOclk[] array---dql and dq---the former referring to the 3 pixels at 
a lower column number than the central pixel, the latter to the remaining 6 (which 
may belong to a different DEA output node). To assist in later FEPsciPixTest 
calls, the variable val is set equal to the difference between the center pixel value 
and the sum of its bias and threshold values, as discussed in Section 41.6.6.
The center pixel is now compared to those lying to its left, to its right, and to those 
on the preceding row, using FEPsciPixTest, which also saves the pixel and 
bias values in the appropriate elements of the ev.p and ev.b arrays. If a test fails, 
i.e. if the central pixel isn't a local maximum, the function returns.
Before testing the row that follows the center pixel, FEPtestEvenPixel calls 
FIOgetExpInfo to see whether the hardware is still processing the same frame 
as the software. If so, it loops over calls to FIOgetImageMapRowPtr until the 
hardware has finished processing the current row. Then the three pixels in the fol
lowing row are also tested against the center pixel using FEPsciPixTest. This 
time, however, it is also necessary to check each pair of bias values for a possible 
parity error. If discovered, FEPsciTimedFixBias is called to log the occur
rence, and the fixed bias value pair is stored back in the bias map.
If all 8 pixels that surround the central pixel survive the FEPsciPixTest crite
ria, the 3x3 pixel and bias arrays in the ev structure will have been loaded. If 5x5 
mode has been selected, FEPtestEvenPixel calls FEPappend5x5 to append 
the 16 bordering pixels and their corresponding bias values to the 
FEPeventRec3x3, transforming it into a FEPeventRec5x5 record. Finally, 
FEPtestEvenPixel calls FIOappendData to write the 
FEPeventRec3x3 record or FEPeventRec5x5 record to the FEP-BEP ring 
buffer.


41.6.5 FEPtestOddPixel()

#include fepCtl.h
Scope: Science
Return type: void
Arguments
unsigned irow
unsigned icol
FEPparm *fp
Description:
This function is called from FEPsciTimedEvent for every bit set in the T-plane 
whose bit offset is odd. This pixel is located in row irow, column icol, and 
fp>image points to the first pair of pixels in that row. The corresponding pair 
of bias values are to be found in fp->image[BIAS_OFFSET]
FEPtestOddPixel first loads the 32-bit pixel and bias fields that contain the 
central pixel. Since the FEP is a little-endian processor, and the central pixel is 
stored in the upper address pair of bytes, pixel and bias will be loaded into the most 
-significant 16 bits of each 32-bit variable. (The least significant 16 bits of these 
variables will contain the pixel and bias for row irow and column icol--1.)
The pair of bias values is now validated---the bias parity flags (bits 15 and 31) are 
tested to determine whether a parity error has occurred in either of those locations 
in the bias map. If so, a call is made to FEPsciTimedFixBias to handle the 
problem, the corrected 32-bit bias pair is written back to the bias map, and the cen
tral pixel is ignored. Note that pixels from odd numbered columns cannot be fidu
cial (cf. FEPtestEvenPixel).
Next, a test is made to determine whether this central pixel lies on the boundary of 
the CCD, or if its bias value is either BIAS_BAD (indicating that it had previously 
been found to have a parity error) or PIXEL_BAD (indication that the pixel is a 
member of the bad-pixel list). In any of these situations, the pixel is ignored.

The 12-bit value of the central pixel is saved in ev.p[1][1] and the correspond
ing 12-bit bias value in ev.b[1][1]. Two threshold values are loaded from the 
fp->ex.dOclk[] array---dqr and dq---the former referring to the 3 pixels at a 
higher column number than the central pixel, the latter to the remaining 6 (which 
may belong to a different DEA output node). To assist in later FEPsciPixTest 
calls, the variable val is set equal to the difference between the center pixel value 
and the sum of its bias and threshold values, as discussed in Section 41.6.6.
The center pixel is now compared to those lying to its left, to its right, and to those 
on the preceding row, using FEPsciPixTest, which also saves the pixel and 
bias values in the appropriate elements of the ev.p and ev.b arrays. If a test fails, 
i.e. if the central pixel isn't a local maximum, the function returns.
Before testing the row that follows the center pixel, FEPtestOddPixel calls 
FIOgetExpInfo to see whether the hardware is still processing the same frame 
as the software. If it is, it loops over calls to FIOgetImageMapRowPtr until the 
hardware has finished processing the current row. Then the three pixels in the fol
lowing row are also tested against the center pixel using FEPsciPixTest. This 
time, however, it is also necessary to check each pair of bias values for a possible 
parity error. If discovered, FEPsciTimedFixBias is called to log the occur
rence, and the fixed bias value pair is stored back in the bias map.
If all 8 pixels that surround the central pixel survive the FEPsciPixTest crite
ria, the 3x3 pixel and bias arrays in the ev structure will have been loaded. If 5x5 
mode has been selected, FEPtestOddPixel calls FEPappend5x5 to append 
the 16 bordering pixels and their corresponding bias values to the 
FEPeventRec3x3, transforming it into a FEPeventRec5x5 record. Finally, 
FEPtestOddPixel calls FIOappendData to write the FEPeventRec3x3 
record or FEPeventRec5x5 record to the FEP-BEP ring buffer.

41.6.6 FEPsciPixTest

#include fepCtl.h
Scope: Science
Return type: unsigned
Arguments
FEPeventRec5x5 *ev
unsigned drow
unsigned dcol
unsigned val
unsigned pixel
unsigned code
unsigned bias
Description:
This is an inline function that is invoked several times within the FEPtestEv
enPixel and FEPtestOddPixel functions. It masks the 12 low-order bits of 
pixel and bias and stores them in p[drow][dcol] and b[drow][dcol] in 
the ev structure. It then compares the value of (pixel - bias) against val, 
the corresponding value derived for the central pixel,
val = ev.p[1][1]       - ev.b[1][1] - doclk;
where doclk represents an adjustment, quadrant by quadrant and frame by frame, 
for changes in average overclock. The averages from the first frame that was used 
in bias calibration are stored in fp->br.bias0[] and reported in FEPexpRec 
records, and all subsequent thresholds must be corrected by the difference between 
those bias0 values and the current overclock averages. This difference is report
ed in the dOclk array in FEPexpRec records.
FEPsciPixTest evaluates to TRUE when the value of the pixel at 
(drow,dcol) is inconsistent with a legal event, or FALSE when it isn't. When the 
code argument is TRUE (non-zero), the comparison is "less-than-or-equal", i.e.
return val <= (pixel - bias);

This test is used for the 3 pixels whose drow index is greater than that of the cen
tral pixel, and for the pixel whose drow index is the same but whose dcol index 
is greater than the central pixel; for the remaining pixels, code should be set to 
FALSE (zero) and the comparison will be "less than", i.e.
return val < (pixel - bias);
FEPsciPixTest also returns FALSE when the bias value is either 
PIXEL_BAD or BIAS_BAD, i.e. when a parity error has previously been detected 
in the bias value, or when the corresponding pixel is a member of the bad pixel 
list.
drow and dcol must be in the range 0-2; the "center" pixel has drow=dcol=1; 
drow=0 refers to the row before the center pixel, drow=2 to the row after; 
dcol=0 to the column before, dcol=2 to the column after. Constants 
PIXEL_MASK, PIXEL_BAD, and BIAS_BAD are defined within fepCtl.h, and 
val and ev are local variables.
NOTE: In 3x3 mode, only that part of the FEPeventRec5x5 structure which is 
identical to a FEPeventRec3x3 will be accessed by FEPtestEvenPixel 
and FEPtestOddPixel.


41.6.7 FEPappend5x5()

#include fepCtl.h
Scope: Science
Return type: void
Arguments
FEPeventRec5x5 *ev
unsigned *pImage
FEPparm *fp
Description:
This function is called from FEPtestEvenPixel and from FEPtestOd
dPixel to copy the 16 edge pixels and their corresponding bias values to the ev-
>pe[] and ev->be[] arrays. In entry, pImage points to the 32-bit word in the 
pixel map that contains the central pixel of the event.
Since the calling routines will not have determined whether the last of the 5 rows 
has yet been processed by the FEP hardware, FEPappend5x5 first calls 
FIOgetExpInfo to see whether the hardware is still processing the same frame 
as the software. If so, it loops over calls to FIOgetImageMapRowPtr until the 
5th row (ev->row+2) is available.
The edge pixels and their bias values are then loaded, masked, and copied to 
ev>pe[] and ev->be[], taking care to detect and fix any bias parity violations 
via a call to FEPsciTimedFixBias. 


41.6.8 FEPsciTimedFixBias()

#include fepCtl.h
Scope: Science
Return type: unsigned
Arguments
unsigned bias
unsigned irow
unsigned icol
FEPparm *fp
Description:
This function is called from FEPtestEvenPixel or FEPtestOddPixel, (or 
FEPappend5x5) when a parity error or fiducial pixel is encountered in either or 
both of the halves of a 32-bit bias word.
FEPsciTimedFixBias first determines whether fiducial pixels have been de
fined (fp->nfidpix > 0), and also whether the parity flag is set for the even-
column bias value. If both are true, the fp->fidpix array is scanned to see if it 
contains the current irow,icol address. If so, e.g. in fp->fidpix[ii], 
FEPsciTimedFixBias writes to the ring buffer a FEPfidPixRec record 
containing the index ii and the pair of pixel values, and it then removes the even 
pixel's parity error flag from the bias variable.
Fiducial pixels excepted, each parity-corrupted 12-bit value in bias is replaced 
by BIAS_BAD (defined in fepCtl.h) and FEPsciTimedError is called (twice 
if both 12-bit values are bad) to reset the appropriate bits in the Bias Parity Plane 
and T-plane. It then calls FIOappendData to send a message of type 
FEP_ERROR_REC to the BEP containing irow, icol, the uncorrected bias val
ue, and the current exposure number in fp->ex.expnum. Finally, FEPsci
TimedFixBias returns the fixed-up 32-bit bias word to the caller, which has 
the responsibility for saving it back in the appropriate location in the bias map.
The returned value consists of the pair of input pixels and their parity error flags. 
If the even-column pixel was fiducial, the corresponding error flag is cleared in the 
returned value.


41.6.9 FEPsciTimedError()

#include fepCtl.h
Scope: Science
Return type: void
Arguments
unsigned irow
unsigned icol
FEPparm *fp
Description:
This function is called from FEPsciTimedFixBias when a parity error is de
tected in row irow, column icol of the bias map. It resets the relevant bit in the 
Bias Parity Plane, turns off the corresponding bit in the T-plane, and increments 
the bias error count, fp->exend.parityerrs.


41.6.10 FEPsciTimedRaw()

#include fepCtl.h
Scope: Science
Return type: void
Arguments
FEPparm *fp
Description:
This function is called from fepSciTimed to process a single raw CCD image 
frame. It initializes the following pointers to the addresses of data structures used 
by the hardware thresholder:
pOclk
points to start of overclock buffer
image
points to start of first data row
and these pointers will be advanced from row to row. FEPsciTimedRaw then loops over CCD pixel rows. Once per row, it calls FIOgetNextCmd to see whether the BEP is trying to command the FEP. A re turned value of TRUE signals that a science command has been received (utility commands will be executed within FIOgetNextCmd and will return FALSE), and a call will be made to fepHandleCmd to process it. NOTE: only one call is made to FIOgetNextCmd per incoming pixel row. The function then processes the row data, copying the raw pixels and overclocks to a FEPeventRecRaw structure and then calling FIOappendData to copy it to the ring buffer.

41.6.11 FEPsciTimedHist()

#include fepCtl.h
Scope: Science
Return type: void
Arguments
FEPparm *fp
Description:
This function is called from fepSciTimed to extract raw pixel histogram data 
from a single image frame. It initializes the following pointers to the addresses of 
data structures used by the hardware thresholder:
pOclk
points to start of overclock buffer
image
points to start of first data row
and these pointers will be advanced from row to row. If this is the first of a series of fp->tp.nhist frames, it saves the frame counter in the *fp->phist histo gram record and clears the histogram arrays. FEPsciTimedHist then loops over CCD pixel rows. Once per row, it calls FIOgetNextCmd to see whether the BEP is trying to command the FEP. A re turned value of TRUE signals that a science command has been received (utility commands will be executed within FIOgetNextCmd and will return FALSE), and a call will be made to fepHandleCmd to process it. NOTE: only one call is made to FIOgetNextCmd per incoming pixel row. The routine accumulates each row of pixels into the fp>phist>hist[nq] histogram arrays, where nq represents the appropriate DEA output node index. It then examines the row's overclocks, updating the minimum (fp>phist>omin[nq]) and maximum (fp->phist->omax[nq]) values, and accumulating their sum (fp>osum[nq]) and sum-of-squares (fp>osum sq[nq]). These are calculated in 64-bit arithmetic, using pairs of unsigned fields. After processing the last line of the image frame, FEPsciTimedHist inspects fp>ocount[nq] and computes the mean overclock values (fp>phist>omean[nq]) and their variances (fp>phist->ovar[nq]) for each DEA output node, calling FIOappendData to copy the FEPeven tRecHist record to the ring buffer.
 

Table of Contents Next Chapter