I'm implementing a "passthrough" functionality with the K22 acting as a slave. Essentially I take some USB data in, strip the protocol extras, and pass the payload over to the I2C line. In return, the Master will send data back to the K22 slave, and that will be packetized, and send back over USB.
My question is, since I don't necessarily know how many bytes the master is going to send back to me, what is the best method to receive an arbitrary number of bytes from a master?
I do know the maximum amount of bytes the master can send to me. So would the best method be something like this:
uint32_t timeout = OSA_TimeGetMsec() + I2C_RX_TX_TIMEOUT;
i2cStatus = I2C_DRV_SlaveReceiveData(I2C_RTOS_SLAVE_INSTANCE, usbTxBuff, MAX_PAYLOAD_SIZE);
i2cStatus = I2C_DRV_SlaveGetTransmitStatus(I2C_RTOS_SLAVE_INSTANCE, &remainingRx);
currTimeMs = OSA_TimeGetMsec();
while(i2cStatus != kStatus_I2C_Success && timeout > currTimeMs);
numUsbTx = MAX_PAYLOAD_SIZE - remainingRx;
Essentially, wait for a timeout and and send only the number of bytes that were received. Are there any other ways? Would this be easier with the ReceiveDataBlocking call?