📄 updown.c
字号:
typedef struct UploadMap_tag {
int32_T nSections;
UploadSection *sections;
int_T nBytes; /* total number of bytes in this map */
} UploadMap;
/*
* Each system contains a table of UploadMap's (one for each tid). If no data
* uploading is being done for a given tid, the uploadMap pointer is NULL.
* The enableState field indicates whether the system in question is active.
*
* For a model with 5 total tids, the table looks like:
*
* tid 0 tid 1 tid 2 tid 3 tid 4
* uploadMap -------------------------------------------
* | ptr | NULL | NULL | ptr | NULL |
* ----|-------------------------|------------
* | |
* v v
* UploadMap UploadMap
* for tid 0 for tid 3
*/
typedef struct SysUploadTable_tag {
int8_T *enableState;
UploadMap **uploadMap;
} SysUploadTable;
typedef struct TriggerInfo_tag {
TriggerState state;
int_T tid;
int32_T duration;
int32_T holdOff;
int32_T delay;
int_T lookForRising;
int_T lookForFalling;
real_T level;
int_T count;
int_T overFlow;
UploadMap trigSignals;
real_T *oldTrigSigVals;
int_T haveOldTrigSigVal;
struct {
int32_T duration;
int32_T count;
int_T checkUnderFlow; /* ??? */
} preTrig;
} TriggerInfo;
/*
* The BdUploadInfo contains all information regarding data logging.
*/
struct BdUploadInfo_tag {
int32_T upInfoIdx; /* index of upInfo in the array */
int32_T nSys; /* # of sys's for which data logging is active */
SysUploadTable *sysTables; /* array of SysUploadTables */
CircularBuf *circBufs; /* circular buffers to store upload data */
BufMemList bufMemList; /* list of buffer memory holding data to upload */
TriggerInfo trigInfo;
};
/*==============================================================================
* Global upload data.
*/
/*
* Definitions that must match Simulink definitions.
*/
#define UPLOAD_RISING_TRIGGER ((int32_T) 0)
#define UPLOAD_FALLING_TRIGGER ((int32_T) 1)
#define UPLOAD_EITHER_RISING_OR_FALLING_TRIGGER ((int32_T) 2)
/*
* Definitions.
*/
#define TRIGMODE_ONESHOT (-1)
#define NUM_UPINFOS 2
static BdUploadInfo uploadInfoArray[NUM_UPINFOS];
#ifdef LCDUSE4ERRORS
/* Function DisplayTriggerStateOnLCD =========================================
* Display the current trigger state on the LCD display... called whenever the
* trigger state changes -- fw-07-07
*/
PRIVATE void DisplayTriggerStateOnLCD(int32_T upInfoIdx) {
BdUploadInfo *uploadInfo= &uploadInfoArray[upInfoIdx];
// local function name... debugging only
#if DEBUG_MSG_LVL > 0
const char *funct_name="DisplayTriggerStateOnLCD";
#endif
switch(uploadInfo->trigInfo.state) {
case TRIGGER_UNARMED:
writeLine("-> trig UNARMED ", 1);
break;
case TRIGGER_HOLDING_OFF:
writeLine("-> trig HOLDOFF ", 1);
break;
case TRIGGER_ARMED:
writeLine("-> trig ARMED ", 1);
break;
case TRIGGER_DELAYED:
writeLine("-> trig DELAYED ", 1);
break;
case TRIGGER_FIRED:
writeLine("-> trig FIRED ", 1);
break;
case TRIGGER_TERMINATING:
writeLine("-> trig TERMINTG", 1);
break;
}
PRINT_DEBUG_MSG_LVL2("trigInfo.state = ");
PRINT_DEBUG_MSG_LVL2_Raw(debugTriggerStrings[uploadInfo->trigInfo.state]);
PRINT_DEBUG_MSG_NL2;
} /* end DisplayTriggerStateOnLCD */
#endif
/* Function ====================================================================
* Dump the signal selection packet (EXT_SELECT_SIGNALS). The packet looks
* like:
*
* upInfoIdx - Index of the UploadInfo.
*
* nSys - the number of systems that contain upload blocks (length of the
* (BdUploadInfo list)
*
* enableIdx - the index into the "mode vector" that tells whether or not
* a given system is active
*
* nTids - the number of tids in a system that contain upload blocks (number
* of non NULL entries in a SysUploadTable)
*
* nSections - the number of contiguous blockio or dwork sections that
* correspond to all blocks within a tid (number of sections in
* an UploadMap)
*
* B - Index into data type transition table - gives base address
* S - the starting index of a blockio section - with respect to B
* W - the number of elements in a blockio section
* DI - data type index - index into the rtw data type table
*
* target buf size - size of the upload buffer (to be allocated by target) for
* a given tid
*
* Here's the packet format:
*
* [upInfoIdx
*
* nSys
*
* enableIdx ---
* nTids |
* tid nSections B S W DI B S W DI ... | system
* tid nSections B S W DI B S W DI ... |
* ---
* enableIdx ---
* nTids |
* tid nSections B S W DI B S W DI ... | system
* tid nSections B S W DI B S W DI ... |
* ---
* target buf size for tid 0
* target buf size for tid 1
* .
* .
* target buf size for tid n
* ]
*
* All elements are int32_T.
*/
#if DUMP_PKT
PRIVATE void DumpSelectSignalPkt(const char *pkt, int nRootTids) {
int32_T i,
j,
k;
int32_T upInfoIdx;
int32_T nSys;
const char *bufPtr=pkt-sizeof(int32_T);
// const char *bufPtr = pkt; // wrong (corrected, fw-07-07)
// local function name... debugging only
#if DEBUG_MSG_LVL > 0
const char *funct_name="DumpSelectSignalPkt";
#endif
PRINT_DEBUG_MSG_LVL2("Signal Select Pkt-----------\n\r");
/* upInfoIdx */
(void)memcpy(&upInfoIdx, bufPtr, sizeof(int32_T));
bufPtr+=sizeof(int32_T);
PRINT_DEBUG_MSG_LVL2("upInfoIdx: ");
PRINT_DEBUG_MSG_LVL2_UDec((uint16_T)upInfoIdx);
PRINT_DEBUG_MSG_NL2;
/* nSys */
(void)memcpy(&nSys, bufPtr, sizeof(int32_T));
bufPtr+=sizeof(int32_T);
PRINT_DEBUG_MSG_LVL2("nSys: ");
PRINT_DEBUG_MSG_LVL2_UDec((uint16_T)nSys);
PRINT_DEBUG_MSG_NL2;
for(i=0; i<nSys; i++) {
int32_T enableIdx,
nTids;
/* [enableIdx, nTids] */
(void)memcpy(&enableIdx, bufPtr, sizeof(int32_T));
bufPtr+=sizeof(int32_T);
(void)memcpy(&nTids, bufPtr, sizeof(int32_T));
bufPtr+=sizeof(int32_T);
PRINT_DEBUG_MSG_LVL2("[enableIdx, nTids]: ");
PRINT_DEBUG_MSG_LVL2_UDec((uint16_T)enableIdx);
PRINT_DEBUG_MSG_LVL2_Raw(" ");
PRINT_DEBUG_MSG_LVL2_UDec((uint16_T)nTids);
PRINT_DEBUG_MSG_NL2;
for(j=0; j<nTids; j++) {
int32_T tid;
int32_T nSections;
/* [tid nSections] */
(void)memcpy(&tid, bufPtr, sizeof(int32_T));
bufPtr+=sizeof(int32_T);
(void)memcpy(&nSections, bufPtr, sizeof(int32_T));
bufPtr+=sizeof(int32_T);
PRINT_DEBUG_MSG_LVL2("[tid nSects]: ");
PRINT_DEBUG_MSG_LVL2_UDec((uint16_T)tid);
PRINT_DEBUG_MSG_LVL2_Raw(" ");
PRINT_DEBUG_MSG_LVL2_UDec((uint16_T)nSections);
PRINT_DEBUG_MSG_NL2;
for(k=0; k<nSections; k++) {
const int B=0;
const int S=1;
const int W=2;
const int DI=3;
int32_T tmpBuf[4];
/* [B S W DI] */
(void)memcpy(&tmpBuf, bufPtr, sizeof(int32_T)*4);
bufPtr+=(sizeof(int32_T)*4);
PRINT_DEBUG_MSG_LVL2("");
PRINT_DEBUG_MSG_LVL2_UDec((uint16_T)tmpBuf[B]);
PRINT_DEBUG_MSG_LVL2_Raw(" ");
PRINT_DEBUG_MSG_LVL2_UDec((uint16_T)tmpBuf[S]);
PRINT_DEBUG_MSG_LVL2_Raw(" ");
PRINT_DEBUG_MSG_LVL2_UDec((uint16_T)tmpBuf[W]);
PRINT_DEBUG_MSG_LVL2_Raw(" ");
PRINT_DEBUG_MSG_LVL2_UDec((uint16_T)tmpBuf[DI]);
PRINT_DEBUG_MSG_NL2;
}
PRINT_DEBUG_MSG_NL2;
}
PRINT_DEBUG_MSG_NL2;
}
/*
* Now the buffer sizes.
*/
PRINT_DEBUG_MSG_LVL2("bufSizes: ");
for(i=0; i<nRootTids; i++) {
int32_T bufSize;
PRINT_DEBUG_MSG_NL2;
PRINT_DEBUG_MSG_LVL2("bufSize[");
PRINT_DEBUG_MSG_LVL2_UDec((uint16_T)i);
PRINT_DEBUG_MSG_LVL2_Raw("] of ");
PRINT_DEBUG_MSG_LVL2_UDec((uint16_T)nRootTids);
PRINT_DEBUG_MSG_LVL2_Raw(" ");
(void)memcpy(&bufSize, bufPtr, sizeof(int32_T));
bufPtr+=sizeof(int32_T);
PRINT_DEBUG_MSG_LVL2_UDec((uint16_T)bufSize);
/* limit size on the 9S12 - only 12k of RAM available -- fw-03-05 */
if(bufSize>CIRCBUFSIZE) {
PRINT_DEBUG_MSG_LVL2_Raw(" (capped at CIRCBUFSIZE = ");
PRINT_DEBUG_MSG_LVL2_UDec(CIRCBUFSIZE);
PRINT_DEBUG_MSG_LVL2_Raw(")");
}
}
PRINT_DEBUG_MSG_NL2;
PRINT_DEBUG_MSG_LVL2("End of select sigs pkt----\n\r");
} /* end DumpSelectSignalPkt */
#else
#define DumpSelectSignalPkt(buf, nRootTids) /* do nothing */
#endif
/* Function ====================================================================
* Dump the trigger selection packet (EXT_SELECT_TRIGGER). The packet looks
* like:
*
* upInfoIdx - Index of the UploadInfo.
*
* tid - tid of the trigger signal
*
* duration - The number of base rate steps for which the data logging event
* occurs.
*
* holdOff - (-1), signifies that this trigger event is a one_shot, else we
* are in normal mode. For normal mode the the value indicates
* the number of base rate steps to wait between the end a data
* logging event and the re-arming of the trigger for the next data
* logging event. The end of a data logging event is defined as
* when the last bit of data has been sent to the host (i.e.,
* immediately after the termination flag has been sent).
*
* delay - The number of base rate steps to wait after the trigger event
* occurs and the before starting the data collection. This can
* be either positive or negative (pre-trigger). This field is
* ignored if the trigger source is manual.
*
* nsections - The sections of the blockio array to monitor for a trigger event.
* If the trigger event is not based on a signal, this is set to
* 0 (e.g., the signal source is manual).
*
* sections - "B, S, W, DI" description of a signal (see Signal Selection Pkt).
* These are the elements of the blockio vector that are monitored
* for trigger events when the trigger is based on a signal. It is
* ignored if the trigger event is not based on a signal
* (nsections == 0).
*
* direction - If the triggering source is a signal, then this specifies the
* direction of the crossing (rising, falling or either). If we
* are not triggering on a signal (nsections == 0), then this field
* is ignored.
*
* level - If the triggering source is a signal, then this field specifies
* the level (value) of the crossing (0 by default). If we are not
* triggering on a signal (nsections == 0), then this field is
* ignored.
*
* The packet looks like:
* [tid duration holdOff delay nsections B S W DI B S W DI ... direction level]
*
* All fields are int32_T except for level, which is an SL_DOUBLE (real_T
* on target).
*/
#if DUMP_PKT
PRIVATE void DumpSelectTriggerPkt(const char *pkt) {
int32_T i;
int32_T upInfoIdx,
tid,
duration,
holdOff,
delay,
nSections;
int32_T direction;
real_T level;
const char *bufPtr=pkt;
// local function name... debugging only
#if DEBUG_MSG_LVL > 0
const char *funct_name="DumpSelectTriggerPkt";
#endif
PRINT_DEBUG_MSG_LVL2("Trigger Select Pkt-----------\n\r");
/* upInfoIdx */
(void)memcpy(&upInfoIdx, bufPtr, sizeof(int32_T));
bufPtr+=sizeof(int32_T);
PRINT_DEBUG_MSG_NL2;
PRINT_DEBUG_MSG_LVL2("upInfoIdx: ");
PRINT_DEBUG_MSG_LVL2_UDec((uint16_T)upInfoIdx);
PRINT_DEBUG_MSG_NL2;
/* tid */
(void)memcpy(&tid, bufPtr, sizeof(int32_T));
bufPtr+=sizeof(int32_T);
PRINT_DEBUG_MSG_NL2;
PRINT_DEBUG_MSG_LVL2("tid: ");
PRINT_DEBUG_MSG_LVL2_UDec((uint16_T)tid);
PRINT_DEBUG_MSG_NL2;
/* duration */
(void)memcpy(&duration, bufPtr, sizeof(int32_T));
bufPtr+=sizeof(int32_T);
PRINT_DEBUG_MSG_NL2;
PRINT_DEBUG_MSG_LVL2("duration: ");
PRINT_DEBUG_MSG_LVL2_UDec((uint16_T)duration);
PRINT_DEBUG_MSG_NL2;
/* holdOff */
(void)memcpy(&holdOff, bufPtr, sizeof(int32_T));
bufPtr+=sizeof(int32_T);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -