I am having an issue with fwSwitchOutputBuffer. I have a two buffer setup. I'm running this inside an "infinite loop" in the sensor controller.
I used the "Quick" alert to notify the ARM (after collecting a buffer full of samples as shown here (A buffer and B buffer are from two sensors; both in a single buffer to be exchanged):
At initialization, I set values to pointers being stored in the state structure:
state.Aptr = #output.ABuffer;
state.Bptr = #output.BBuffer;
At the top of the loop, I wait for an edge on an external control signal that indicates that data is available from an SPI peripheral and then access the data.
I then grab pointers to two buffers in my output structure:
Aptr = state.Aptr;
Bptr = state.Bptr;
and store the data using the pointers.
I then write the updated pointer values back to their state variable equivalents.
After storing the data, I check to see if I have filled the buffer. If so, I do an exchange and send a notification to the ARM. Since I stay in a loop, I use the QuickAlert function (since the automated alert from the fwSwitchOutputBuffer() will not be issued because the task continues).
if(state.bufCnt >= cfg.numSamples) {
fwSwitchOutputBuffer();
state.Aptr = #output.ABuffer;
state.Bptr = #output.BBuffer;
state.bufCnt = 0;
fwGenQuickAlertInterrupt();
}
After the exchange, I re-initialize the buffer pointers. Here I expect the pointers to reflect the "exchanged" buffer addresses.
Then the SensorController code loops around to wait for more "edges" and collects more data.
On the ARM side:
void scTaskAlertCallback(void) {
// Called when a buffer is ready from the Sensor Controller
// Clear the ALERT interrupt source
scifClearAlertIntSource();
if(scifGetTaskIoStructAvailCount(SCIF_TASK_ID,SCIF_STRUCT_OUTPUT) == 1) {
SCIF_OUTPUT_T *ptrOutput = scifGetTaskStruct(SCIF_TASK_ID, SCIF_STRUCT_OUTPUT);
memcpy(RawAData,&(ptrOutput->ABuffer),sizeof(RawAData));
memcpy(RawBData,&(ptrOutput->BBuffer),sizeof(RawBData));
scifHandoffTaskStruct(SCIF_TASK_ID, SCIF_STRUCT_OUTPUT);
}
// Acknowledge the alert event
scifAckAlertEvents();
// Set a flag so task knows why it is being wakened.
DataReceived = true;
Semaphore_post(localSem);
}
My application runs but, but every other data buffer has all zeros.
I looked at the assembly code generated by SensorController. I don't think the statements (after the buffer exchange):
state.Aptr = #output.ABuffer;
state.Bptr = #output.BBuffer;
take into consideration that the A/B Buffers are in a multi-buffer structure. They always get initialized (I think) to buffer zero.
The other code does what it is supposed to do, so when the ARM grabs the data and looks at buffer one, it sees zeros because the Sensor Controller is always using buffer zero!
Is there a work around for this? Or is there a different syntax to indicate that one wants the value of the "swapped/updated" buffer?
BTW, I originally had "local" variables for the buffer pointers, but found that the compiler didn't realized that the code looped back, so was "re-using" registers that held the pointers, hence the need to copy them into "state" memory.
Thanks!
Ed