📄 springboardio.c
字号:
/* occurred in the high byte of the data */
/* word pointed to by uiTrigOffset. */
/* pDataSamples = Pointer to the 8K data array that the */
/* data is to be stored into. */
/* Returns: bSuccess = Successful read of the SpringBoard */
/* module. */
/* Globals affected: None */
/* Hardware affected: None */
/* */
/*============================================================================*/
/* Change History: */
/* */
/* ECO#: ? */
/* Change Date: dd-mmm-yyyy */
/* Changed By: ? */
/* Description of Change: ? */
/* */
/*============================================================================*/
Boolean sbioReadBuffData (UInt8 uiBankSelect, UInt16 uiDataBuffOffset,
Boolean bTrigInHiByte, UInt8 *pDataSamples)
{
/*========================================================================*/
/* Declare all local variables. */
/*========================================================================*/
UInt16 *uiRegAddress;
UInt16 *uiMaxAddress;
UInt16 *uiMinAddress;
Boolean bSuccess = true;
union
{
UInt16 DataWord; /* Mapping for received data word. */
UInt8 DataByte[2]; /* Mapping for usable byte data. */
} uiRcvdData;
UInt16 index = 0;
EventType event;
#ifndef EmulateSBIO
/*========================================================================*/
/* Set the maximum and minimum addresses for the active data bank. This */
/* address is the data base address plus the size of the of the data bank */
/* times the selected bank number. Set the Register Address equal to the */
/* address specified by the data bank base address plus the trigger */
/* offset into the circular buffer minus the pretrigger. */
/*========================================================================*/
uiMinAddress = (unsigned short *)((UInt32)DataBankBaseAddr +
((UInt32)DataBuffSize * (UInt32)uiBankSelect));
uiMaxAddress = (unsigned short *)((UInt32)uiMinAddress +
(UInt32)DataBuffSize - 1L);
/*========================================================================*/
/* Set the Register Address equal to the address specified by the data */
/* bank base address plus the trigger offset into the circular buffer */
/* minus the pretrigger sample count. If the resulting address is less */
/* than the minimum address, reset the address back to the maximum */
/* address minus the amount the previous address was below the minimum */
/* address. This is necessary because the data buffer is a circular */
/* buffer into which data is written until the trigger is found and */
/* marked for our use. Data is then stored into the circular buffer until*/
/* enough samples have been acquired to finish the post-trigger samples */
/* required. This means that the trigger can occur anywhere within the */
/* buffer. By setting the Register Address in this way we can store the */
/* data sequentially in the data sample buffer. */
/*========================================================================*/
uiRegAddress = (unsigned short *)((UInt32)uiMinAddress +
((UInt32)uiDataBuffOffset * 2L) -
(UInt32)PreTrigSmpls(AppPrefs.PreTrigger));
/*========================================================================*/
/* Since the SpringBoard module must be accessed on an even-word boundary,*/
/* ensure that the address is even. */
/*========================================================================*/
if (((UInt32)uiRegAddress % 2L) != 0)
uiRegAddress = (unsigned short *)((UInt32)uiRegAddress - 1L);
/*========================================================================*/
/* If the calculated Register Address is below the bottom of the circular */
/* buffer, then loop it around to the top. */
/*========================================================================*/
if (uiRegAddress < uiMinAddress)
uiRegAddress = uiMaxAddress - (uiMinAddress - uiRegAddress);
/*========================================================================*/
/* For each of the samples acquired, read the data from the SpringBoard */
/* Module as a packed 16-bit word. Then unpack each of the bytes of data */
/* from the word and store them in the byte array. Since the data is */
/* stored in the SpringBoard Module in a circular buffer, store it in */
/* sequential order in the array to simplify the data plotting. */
/*========================================================================*/
for (index = 0; (index < DataBuffSize); (index += 2))
{
/*========================================================================*/
/* Read the data from the SpringBoard Module. */
/*========================================================================*/
HsCardErrTry
{
uiRcvdData.DataWord = *uiRegAddress;
}
HsCardErrCatch
{
bSuccess = false;
/*====================================================================*/
/* Alert the user that the HandSpring Module must be installed before */
/* the PocketAnalyzer Application can be run. */
/*====================================================================*/
FrmAlert (NoSpringBoardModuleAlert);
/*====================================================================*/
/* Add and event to the queue to inform the PocketAnalyzer application*/
/* to stop and shutdown. */
/*====================================================================*/
event.eType = appStopEvent;
EvtAddEventToQueue(&event);
/*================================================================*/
/* Return indicating that the data acquisition was unsuccessful. */
/*================================================================*/
return (false);
} HsCardErrEnd
/*====================================================================*/
/* Store the data in the byte array. If this is the first sample */
/* then properly process the data depending on whether the trigger */
/* was in the high byte or the low byte. */
/*====================================================================*/
pDataSamples[index] = uiRcvdData.DataByte[1];
pDataSamples[index+1] = uiRcvdData.DataByte[0];
/*====================================================================*/
/* Increment the Register Address to point to the next data set. If */
/* the new address is greater than the Maximum Address for this data */
/* buffer, then set the Register Address back to the Minimum Address. */
/* This will properly process the circular buffer. */
/*====================================================================*/
if (++uiRegAddress > uiMaxAddress)
uiRegAddress = uiMinAddress;
}
#else
for (index = 0; index < DataBuffSize; index++)
{
#ifdef SimRandomIO
pDataSamples[index] = (UInt8)(SysRandom(0) & 0x00FF);
#else
pDataSamples[index] = (UInt8)(Counter() & 0x00FF);
#endif
}
#endif
return (bSuccess);
}
/*============================================================================*/
/* Function: StartAcquisition */
/* Description: This routine loads the SpringBoard module with the */
/* data necessary to start the acquisition of the data. */
/* Then send the start command specifying which data */
/* buffer to store the data in. Then set the EventLoop */
/* timeout to 20 milliseconds. Finally, disable the */
/* Start button and enable the Stop button. */
/* */
/* Arguments: None */
/* Returns: None */
/* Globals affected: None */
/* Hardware affected: None */
/* */
/*============================================================================*/
/* Change History: */
/* */
/* ECO#: ? */
/* Change Date: dd-mmm-yyyy */
/* Changed By: ? */
/* Description of Change: ? */
/* */
/*============================================================================*/
void StartAcquisition (void)
{
/*========================================================================*/
/* Declare all local variables. */
/*========================================================================*/
/***** None *****/
sbioWriteSmplRateReg (AppPrefs.Timebase);
sbioWritePreTrigger (PreTrigSmpls(AppPrefs.PreTrigger));
sbioWriteTriggerWord (&AppPrefs.ChnlTriggers[0]);
sbioWriteRunReg (true, 0);
CtlHideControl(GetObjectPtr(frmMainStartGraphicButton));
CtlShowControl(GetObjectPtr(frmMainStopGraphicButton));
EventLoopTimeout = SysTicksPerSecond();
PlotData.AcquisitionInProcess = true;
}
/*============================================================================*/
/* Function: StopAcquisition */
/* Description: This routine sends the stop command to the SpringBoard*/
/* module. Then set the EventLoop to loop forever. */
/* Finally, enable the Start button and disenable the */
/* Stop button. */
/* */
/* Arguments: None */
/* Returns: None */
/* Globals affected: None */
/* Hardware affected: None */
/* */
/*============================================================================*/
/* Change History: */
/* */
/* ECO#: ? */
/* Change Date: dd-mmm-yyyy */
/* Changed By: ? */
/* Description of Change: ? */
/* */
/*============================================================================*/
void StopAcquisition (void)
{
/*========================================================================*/
/* Declare all local variables. */
/*========================================================================*/
/***** None *****/
sbioWriteRunReg (false, 0);
CtlHideControl(GetObjectPtr(frmMainStopGraphicButton));
CtlShowControl(GetObjectPtr(frmMainStartGraphicButton));
EventLoopTimeout = evtWaitForever;
PlotData.AcquisitionInProcess = false;
}
/*============================================================================*/
/* Function: Counter */
/* Description: This routine generates a count sequence that is */
/* returned for use in simulating the I/O. */
/* */
/* Arguments: None */
/* Returns: Counter = unsigned 16-bit random number. */
/* Globals affected: None */
/* Hardware affected: None */
/* */
/*============================================================================*/
/* Change History: */
/* */
/* ECO#: ? */
/* Change Date: dd-mmm-yyyy */
/* Changed By: ? */
/* Description of Change: ? */
/* */
/*============================================================================*/
unsigned int Counter (void)
{
/*========================================================================*/
/* Declare all local variables. */
/*========================================================================*/
static unsigned long int CountValue = 0;
return (unsigned int) (CountValue++);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -