📄 updown.c
字号:
EXIT_POINT:
return(error);
} /* end UploadBufInit */
/* Function ====================================================================
* Reset all data associated with a circular buffers.
*/
PRIVATE void UploadBufReset(CircularBuf *circBuf)
{
circBuf->empty = TRUE;
circBuf->bufSize = 0;
circBuf->buf = NULL;
circBuf->head = NULL;
circBuf->tail = NULL;
circBuf->newTail = NULL;
} /* end UploadBufReset */
/* Function ====================================================================
* Reset fields of the uploadinfo struct.
*/
PUBLIC void UploadLogInfoReset(void)
{
int i;
/* sysUploadTable */
uploadInfo.nSys = 0;
uploadInfo.sysTables = NULL;
/* circular bufs and bufMemLists */
for (i=0; i<NUMST; i++) {
UploadBufReset(&uploadInfo.circBufs[i]);
}
uploadInfo.bufMemList.bufs = NULL;
/*
* Reset trigger info.
*/
uploadInfo.trigInfo.state = TRIGGER_UNARMED;
uploadInfo.trigInfo.duration = 0;
uploadInfo.trigInfo.holdOff = 0;
uploadInfo.trigInfo.delay = 0;
uploadInfo.trigInfo.lookForRising = TRUE;
uploadInfo.trigInfo.lookForFalling = FALSE;
uploadInfo.trigInfo.level = 0.0;
uploadInfo.trigInfo.count = 0;
uploadInfo.trigInfo.overFlow = FALSE;
uploadInfo.trigInfo.trigSignals.nSections = 0;
uploadInfo.trigInfo.trigSignals.sections = NULL;
uploadInfo.trigInfo.trigSignals.nBytes = 0;
uploadInfo.trigInfo.oldTrigSigVals = NULL;
uploadInfo.trigInfo.haveOldTrigSigVal = FALSE;
uploadInfo.trigInfo.preTrig.duration = 0;
uploadInfo.trigInfo.preTrig.count = 0;
uploadInfo.trigInfo.preTrig.checkUnderFlow = FALSE;
} /* end UploadLogInfoReset */
/* Function ====================================================================
* Free all dynamically allocated fields of the trigInfo structure.
*/
PRIVATE void UploadDestroyTrigger(void)
{
TriggerInfo *trigInfo = &uploadInfo.trigInfo;
BIOMap *map = &trigInfo->trigSignals;
free(map->sections);
map->sections = NULL;
free(trigInfo->oldTrigSigVals);
trigInfo->oldTrigSigVals = NULL;
} /* end UploadDestroyTrigger */
/* Function ====================================================================
* Destroy all data associated with data logging. Fields are re-initialized
* and pointers NULL'ed out by UploadBufReset() and UploadLogInfoReset().
*/
PUBLIC void UploadLogInfoTerm(void)
{
int_T i;
/*
* Free fields of the sysUpload tables and then the table itself.
*/
for (i=0; i<uploadInfo.nSys; i++) {
int_T tid;
BIOMap **bioMap = uploadInfo.sysTables[i].bioMap;
for (tid=0; tid<NUMST; tid++) {
if (bioMap[tid] != NULL) {
/* Free fields of bioMap. */
free(bioMap[tid]->sections);
/* Free the bioMap. */
free(bioMap[tid]);
}
}
}
free(uploadInfo.sysTables);
/* Free ciruclar buf fields and bufMemLists. */
for (i=0; i<NUMST; i++) {
free(uploadInfo.circBufs[i].buf);
}
free(uploadInfo.bufMemList.bufs);
/*
* Free trigger info.
*/
UploadDestroyTrigger();
/*
* Reset all vals to initial value and NULL out pointers.
*/
UploadLogInfoReset();
//blinky(100000); /* cancel trigger -> crashes MATLAB... fw-03-05 */
} /* end UploadLogInfoTerm */
/* Function ====================================================================
* Prepare for final flush of buffers. This involves setting the trigger
* state to appropriate values.
*/
PUBLIC void UploadPrepareForFinalFlush(void)
{
switch(uploadInfo.trigInfo.state) {
case TRIGGER_FIRED:
case TRIGGER_TERMINATING:
/*
* 1) set trig state to "terminating" so that the eventual call to
* UploadBufGetData knows to add the terminator flag to
* the data stream.
* 2) set trig state to "oneshot" to prevent re-arming
*/
uploadInfo.trigInfo.state = TRIGGER_TERMINATING; /* 1 */
uploadInfo.trigInfo.holdOff = TRIGMODE_ONESHOT; /* 2 */
break;
case TRIGGER_UNARMED:
case TRIGGER_HOLDING_OFF:
case TRIGGER_ARMED:
case TRIGGER_DELAYED:
case TRIGGER_SENDING_TERM_MSG:
/* do nothing */
break;
}
#ifdef VXWORKS
/* Let upload server run to ensure that term msg is sent to host. One
semGive() is for the background task and the other is for the explicit
call to rt_UploadServerWork() in DisconnectFromHost(). */
semGive(uploadSem);
semGive(uploadSem);
#endif
} /* end UploadPrepareForFinalFlush */
/* Function ====================================================================
* Initialize data uploading by processing the EXT_SELECT_SIGNALS message
* (which is passed in). Return the error status. See DumpSelectSignalMsg()
* for a detailed description of the message.
*/
PUBLIC boolean_T UploadLogInfoInit(RTWExtModeInfo *ei,
const char *msg)
{
int nActiveTids;
int_T i;
boolean_T error = EXT_NO_ERROR;
const char *bufPtr = msg;
DumpSelectSignalMsg(msg, NUMST);
/*
* Don't init data logging while it is already initialized. In most cases,
* this is prevented at a higer level (GUI disabled, etc).
*/
if (uploadInfo.sysTables != NULL) return(EXT_ERROR);
/* nSys */
(void)memcpy(&uploadInfo.nSys, bufPtr, sizeof(int32_T));
bufPtr += sizeof(int32_T);
assert(uploadInfo.sysTables == NULL);
uploadInfo.sysTables = (SysUploadTable *)
calloc((uint16_T)uploadInfo.nSys, sizeof(SysUploadTable));
if (uploadInfo.sysTables == NULL) {
abort_LED(13); error = EXT_ERROR; goto EXIT_POINT;
}
/*
* Init each system table.
*/
for (i=0; i<uploadInfo.nSys; i++) {
error = InitSysUploadTable(ei, &uploadInfo.sysTables[i], &bufPtr);
if (error != EXT_NO_ERROR) goto EXIT_POINT;
}
/*
* Allocate the circular buffers.
*/
nActiveTids = 0;
for (i=0; i<NUMST; i++) {
int32_T size;
(void)memcpy(&size, bufPtr, sizeof(int32_T));
/* limit size on the 9S12 - only 12k of RAM available, heap limited to 8k -- fw-03-05 */
if(size > MAXRBUFSIZE_9S12) size = MAXRBUFSIZE_9S12;
bufPtr += sizeof(int32_T);
(void)UploadBufInit(&uploadInfo.circBufs[i], (uint_T)size);
nActiveTids += (size != 0);
}
/*
* Initialize/Allocate the bufMemLists - these are used by
* ext_svr to pull the appropriate data out of the buffers and send it
* to the host.
*/
#if ASSERTS_ON
uploadInfo.bufMemList.maxBufs = nActiveTids;
#endif
uploadInfo.bufMemList.nActiveBufs = 0;
assert(uploadInfo.bufMemList.bufs == NULL);
uploadInfo.bufMemList.bufs = (BufMem *)malloc(nActiveTids*sizeof(BufMem));
if (uploadInfo.bufMemList.bufs == NULL) {
abort_LED(14); error = EXT_ERROR; goto EXIT_POINT;
}
EXIT_POINT:
if (error != EXT_NO_ERROR) {
UploadLogInfoTerm();
}
return(error);
} /* end UploadLogInfoInit */
/* Function ====================================================================
* Initialize and configure the trigger attributes. See DumpSelectTriggerMsg()
* for a detailed description of the message.
*/
PUBLIC boolean_T UploadInitTrigger(RTWExtModeInfo *ei,
const char *msg)
{
int_T nSections;
int32_T i32_tid;
int32_T direction;
boolean_T error = EXT_NO_ERROR;
TriggerInfo *trigInfo = &uploadInfo.trigInfo;
const char *bufPtr = msg;
DumpSelectTriggerMsg(msg);
/* tid, duration, holdOff, delay and nsections */
(void)memcpy(&i32_tid, bufPtr, sizeof(int32_T));
bufPtr += sizeof(int32_T);
trigInfo->tid = (int_T)i32_tid;
(void)memcpy(&trigInfo->duration, bufPtr, sizeof(int32_T));
bufPtr += sizeof(int32_T);
(void)memcpy(&trigInfo->holdOff, bufPtr, sizeof(int32_T));
bufPtr += sizeof(int32_T);
(void)memcpy(&trigInfo->delay, bufPtr, sizeof(int32_T));
bufPtr += sizeof(int32_T);
(void)memcpy(&trigInfo->trigSignals.nSections, bufPtr, sizeof(int32_T));
bufPtr += sizeof(int32_T);
nSections = (uint_T)trigInfo->trigSignals.nSections;
/*
* Init the BIOSections - if the trigger is signal based.
*/
if (nSections > 0) {
/* trigger is signal based */
int section;
BIOMap *map = &trigInfo->trigSignals;
assert(map->nBytes == 0);
assert(map->sections == NULL);
map->sections = (BIOSection *)malloc((uint16_T)nSections * sizeof(BIOSection));
if (map->sections == NULL) {
abort_LED(15); error = EXT_ERROR; goto EXIT_POINT;
}
for (section=0; section<map->nSections; section++) {
int32_T tmpBuf[4];
BIOSection *bioSection = &map->sections[section];
/* read [B S W DI] */
(void)memcpy(&tmpBuf, bufPtr, sizeof(int32_T)*4);
bufPtr += (sizeof(int32_T) * 4);
InitBioSection(ei, tmpBuf, bioSection);
/* keep track of total number of bytes in this map */
map->nBytes += bioSection->nBytes;
}
/*
* Allocate space to hold the old values of the trigger signals. Note
* that trigger signals are gauranteed to be of type SL_DOUBLE (real_T)
* and noncomplex.
*/
assert(trigInfo->oldTrigSigVals == NULL);
assert(trigInfo->oldTrigSigVals == NULL);
trigInfo->oldTrigSigVals = (real_T *)malloc((uint16_T)map->nBytes);
if (trigInfo->oldTrigSigVals == NULL) {
abort_LED(17); error = EXT_ERROR; goto EXIT_POINT;
}
}
/* Direction. */
(void)memcpy(&direction, bufPtr, sizeof(int32_T));
bufPtr += sizeof(int32_T);
trigInfo->lookForRising =
((direction == UPLOAD_RISING_TRIGGER) ||
(direction == UPLOAD_EITHER_RISING_OR_FALLING_TRIGGER));
trigInfo->lookForFalling =
((direction == UPLOAD_FALLING_TRIGGER) ||
(direction == UPLOAD_EITHER_RISING_OR_FALLING_TRIGGER));
/* level */
(void)memcpy(&trigInfo->level, bufPtr, sizeof(real_T));
bufPtr += sizeof(real_T);
/*
* Convert delay to pre-trigger duration.
*/
if (trigInfo->delay < 0) {
trigInfo->preTrig.duration = -trigInfo->delay;
trigInfo->delay = 0;
} else {
trigInfo->preTrig.duration = 0;
}
EXIT_POINT:
if (error != EXT_NO_ERROR) {
UploadDestroyTrigger();
}
return(error);
} /* end UploadInitTrigger */
/* Function ====================================================================
* Arm the trigger.
*/
PUBLIC void UploadArmTrigger(void)
{
int_T tid;
assert((uploadInfo.trigInfo.state == TRIGGER_UNARMED) ||
(uploadInfo.trigInfo.state == TRIGGER_HOLDING_OFF));
/*
* Re-initialize.
*/
uploadInfo.trigInfo.overFlow = FALSE;
for (tid=0; tid<NUMST; tid++) {
CircularBuf *circBuf = &uploadInfo.circBufs[tid];
if (circBuf->bufSize > 0) {
circBuf->head = circBuf->buf;
circBuf->tail = circBuf->buf;
circBuf->newTail = NULL;
circBuf->empty = TRUE;
}
}
/*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -