void serialWriteBuf(serialPort_t *instance, const uint8_t *data, int count) { if (instance->vTable->writeBuf) { instance->vTable->writeBuf(instance, data, count); } else { for (const uint8_t *p = data; count > 0; count--, p++) { while (!serialTxBytesFree(instance)) { }; serialWrite(instance, *p); } } }
static int mspSerialSendFrame(mspPort_t *msp, const uint8_t * hdr, int hdrLen, const uint8_t * data, int dataLen, const uint8_t * crc, int crcLen) { // We are allowed to send out the response if // a) TX buffer is completely empty (we are talking to well-behaving party that follows request-response scheduling; // this allows us to transmit jumbo frames bigger than TX buffer (serialWriteBuf will block, but for jumbo frames we don't care) // b) Response fits into TX buffer const int totalFrameLength = hdrLen + dataLen + crcLen; if (!isSerialTransmitBufferEmpty(msp->port) && ((int)serialTxBytesFree(msp->port) < totalFrameLength)) return 0; // Transmit frame serialBeginWrite(msp->port); serialWriteBuf(msp->port, hdr, hdrLen); serialWriteBuf(msp->port, data, dataLen); serialWriteBuf(msp->port, crc, crcLen); serialEndWrite(msp->port); return totalFrameLength; }