small speed up using larger buffer and multipart Tx

remotes/github/faster
Ondřej Hruška 6 years ago
parent da330b4b73
commit 5687196bdd
Signed by: MightyPork
GPG Key ID: 2C5FD5035250423D
  1. 44
      TinyFrame/TF_Integration.c
  2. 2
      freertos.c
  3. 4
      platform/plat_compat.h
  4. 12
      units/adc/_adc_core.c

@ -14,8 +14,40 @@
extern osSemaphoreId semVcomTxReadyHandle;
extern osMutexId mutTinyFrameTxHandle;
static volatile bool first_tx = false; // XXX global
void TF_WriteImpl(TinyFrame *tf, const uint8_t *buff, uint32_t len)
{
#if 1
// if (!first_tx) {
// // wait for the last USB transmission to be finished
// int32_t mxStatus;
// mxStatus = osSemaphoreWait(semVcomTxReadyHandle, 100);
// if (mxStatus != osOK) {
// TF_Error("Tx stalled");
// return;
// }
// }
// first_tx = false;
// Padding to a multiple of 64 bytes
if (len&0x3F) {
uint32_t pad = (64 - (len&0x3F));
memset((void *) (buff + len), 0, pad);
len += pad; // padding to a multiple of 64 (size of the endpoint)
}
assert_param(HAL_OK == HAL_PCD_EP_Transmit(hUsbDeviceFS.pData, CDC_IN_EP, (uint8_t *) buff, len));
// Wait for the semaphore - HAL keeps a pointer to the buffer, and it's the TinyFrame Tx buffer,
// so if we let it process it in the background, it could get corrupted before the Tx is completed.
int32_t mxStatus;
mxStatus = osSemaphoreWait(semVcomTxReadyHandle, 100);
if (mxStatus != osOK) {
TF_Error("Tx stalled");
return;
}
#else
(void) tf;
#define CHUNK 64 // same as TF_SENDBUF_LEN, so we should always have only one run of the loop
int32_t total = (int32_t) len;
@ -37,6 +69,7 @@ void TF_WriteImpl(TinyFrame *tf, const uint8_t *buff, uint32_t len)
buff += chunksize;
total -= chunksize;
}
#endif
}
/** Claim the TX interface before composing and sending a frame */
@ -47,6 +80,17 @@ bool TF_ClaimTx(TinyFrame *tf)
assert_param(!inIRQ());
assert_param(osOK == osMutexWait(mutTinyFrameTxHandle, 5000));
// // wait for the last USB transmission to be finished
// int32_t mxStatus;
// mxStatus = osSemaphoreWait(semVcomTxReadyHandle, 100);
// if (mxStatus != osOK) {
// TF_Error("Tx stalled");
// return false;
// }
first_tx = true;
return true;
}

@ -169,7 +169,7 @@ void MX_FREERTOS_Init(void) {
/* USER CODE BEGIN RTOS_SEMAPHORES */
/* add semaphores, ... */
xSemaphoreGive(semVcomTxReadyHandle);
// xSemaphoreGive(semVcomTxReadyHandle);
/* USER CODE END RTOS_SEMAPHORES */
/* USER CODE BEGIN RTOS_TIMERS */

@ -30,7 +30,7 @@
#define BULK_READ_BUF_LEN 256 // Buffer for TF bulk reads
#define UNIT_TMP_LEN 512 // Buffer for internal unit operations
#define UNIT_TMP_LEN 256 // Buffer for internal unit operations
#define FLASH_SAVE_BUF_LEN 128 // Malloc'd buffer for saving to flash
@ -38,7 +38,7 @@
#define RX_QUE_CAPACITY 16 // TinyFrame rx queue size (64 bytes each)
#define TF_MAX_PAYLOAD_RX 512 // TF max Rx payload
#define TF_SENDBUF_LEN 64 // TF transmit buffer (can be less than a full frame)
#define TF_SENDBUF_LEN 512 // TF transmit buffer (can be less than a full frame)
#define TF_MAX_ID_LST 4 // Frame ID listener count
#define TF_MAX_TYPE_LST 6 // Frame Type listener count

@ -171,7 +171,7 @@ static void handle_httc(Unit *unit, bool tc)
const bool m_fixcpt = priv->opmode == ADC_OPMODE_BLCAP;
if (ht) {
end = (priv->buf_itemcount / 2);
end = (priv->buf_itemcount >> 1); // div2
}
else {
end = priv->buf_itemcount;
@ -234,7 +234,7 @@ static void handle_httc(Unit *unit, bool tc)
priv->stream_startpos = 0;
}
else {
priv->stream_startpos = priv->buf_itemcount / 2;
priv->stream_startpos = priv->buf_itemcount >> 1; // div2
}
}
@ -289,7 +289,7 @@ void UADC_DMA_Handler(void *arg)
const bool m_stream = priv->opmode == ADC_OPMODE_STREAM;
const bool m_fixcpt = priv->opmode == ADC_OPMODE_BLCAP;
if (m_trigd || m_stream || m_fixcpt) {
const uint32_t half = (uint32_t) (priv->buf_itemcount / 2);
const uint32_t half = (uint32_t) (priv->buf_itemcount >> 1); // div2
if (ht && tc) {
// dual event interrupt - may happen if we missed both and they were pending after
// interrupts became enabled again (this can happen due to the EOS or other higher prio irq's)
@ -336,8 +336,10 @@ void UADC_ADC_EOS_Handler(void *arg)
if (priv->opmode == ADC_OPMODE_UNINIT) return;
// Wait for the DMA to complete copying the last sample
uint32_t dmapos;
hw_wait_while((dmapos = DMA_POS(priv)) % priv->nb_channels != 0, 100); // XXX this could be changed to reading it from the DR instead
uint32_t dmapos = DMA_POS(priv);
if ((DMA_POS(priv) % priv->nb_channels) != 0) {
hw_wait_while((dmapos = DMA_POS(priv)) % priv->nb_channels != 0, 100); // XXX this could be changed to reading it from the DR instead
}
uint32_t sample_pos;
if (dmapos == 0) {

Loading…
Cancel
Save