Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c4efa5ddaa
|
@@ -109,6 +109,7 @@ extern uint32_t SystemCoreClock;
|
||||
#define configQUEUE_REGISTRY_SIZE 0
|
||||
#define configCHECK_FOR_STACK_OVERFLOW 2
|
||||
#define configENABLE_BACKWARD_COMPATIBILITY 0
|
||||
#define configUSE_COUNTING_SEMAPHORES 0
|
||||
|
||||
#define configUSE_TIMERS 0
|
||||
#define configTIMER_TASK_PRIORITY TSK_TIMERS_PRIO // above normal
|
||||
|
||||
@@ -4,11 +4,11 @@
|
||||
// TinyFrame integration
|
||||
//
|
||||
|
||||
#include <USB/usb_device.h>
|
||||
#include "platform.h"
|
||||
#include "task_main.h"
|
||||
|
||||
#include "USB/usbd_cdc_if.h"
|
||||
#include "USB/usb_device.h"
|
||||
#include "TinyFrame.h"
|
||||
|
||||
extern osSemaphoreId semVcomTxReadyHandle;
|
||||
@@ -16,30 +16,6 @@ extern osMutexId mutTinyFrameTxHandle;
|
||||
|
||||
void TF_WriteImpl(TinyFrame *tf, const uint8_t *buff, uint32_t len)
|
||||
{
|
||||
#if 1
|
||||
const uint32_t real_size = len;
|
||||
|
||||
// Padding to a multiple of 64 bytes - this is supposed to maximize the bulk transfer speed
|
||||
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)
|
||||
}
|
||||
|
||||
// We bypass the USBD driver library's overhead by using the HAL function directly
|
||||
assert_param(HAL_OK == HAL_PCD_EP_Transmit(hUsbDeviceFS.pData, CDC_IN_EP, (uint8_t *) buff, len));
|
||||
|
||||
// The buffer is the TF transmit buffer, we can't leave it to work asynchronously because
|
||||
// the next call could modify it before it's been transmitted (in the case of a chunked / multi-part frame)
|
||||
|
||||
// the assumption here is that all until the last chunk use the full buffer capacity
|
||||
if (real_size == TF_SENDBUF_LEN) {
|
||||
if (pdTRUE != xSemaphoreTake(semVcomTxReadyHandle, 100)) {
|
||||
TF_Error("Tx stalled in WriteImpl");
|
||||
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;
|
||||
@@ -53,34 +29,24 @@ void TF_WriteImpl(TinyFrame *tf, const uint8_t *buff, uint32_t len)
|
||||
const uint16_t chunksize = (uint16_t) MIN(total, CHUNK);
|
||||
|
||||
// this is an attempt to speed it up a little by removing a couple levels of indirection
|
||||
assert_param(HAL_OK == HAL_PCD_EP_Transmit(hUsbDeviceFS.pData, CDC_IN_EP, (uint8_t *) buff, chunksize));
|
||||
// assert_param(HAL_OK == HAL_PCD_EP_Transmit(hUsbDeviceFS.pData, CDC_IN_EP, (uint8_t *) buff, chunksize));
|
||||
|
||||
// USBD_LL_Transmit(&hUsbDeviceFS, CDC_IN_EP, (uint8_t *) buff, chunksize);
|
||||
// assert_param(USBD_OK == CDC_Transmit_FS((uint8_t *) buff, chunksize));
|
||||
assert_param(USBD_OK == CDC_Transmit_FS((uint8_t *) buff, chunksize));
|
||||
|
||||
buff += chunksize;
|
||||
total -= chunksize;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/** Claim the TX interface before composing and sending a frame */
|
||||
bool TF_ClaimTx(TinyFrame *tf)
|
||||
{
|
||||
(void) tf;
|
||||
// assert_param(!inIRQ()); // useless delay
|
||||
assert_param(pdTRUE == xSemaphoreTake(mutTinyFrameTxHandle, 5000)); // trips the wd
|
||||
|
||||
// The last chunk from some previous frame may still be being transmitted,
|
||||
// wait for it to finish (the semaphore is given in the CDC tx done handler)
|
||||
if (pdTRUE != xSemaphoreTake(semVcomTxReadyHandle, 100)) {
|
||||
TF_Error("Tx stalled in Claim");
|
||||
|
||||
// release the guarding mutex again
|
||||
assert_param(pdTRUE == xSemaphoreGive(mutTinyFrameTxHandle));
|
||||
return false;
|
||||
}
|
||||
// assert_param(osThreadGetId() != tskMainHandle);
|
||||
assert_param(!inIRQ());
|
||||
|
||||
assert_param(osOK == osMutexWait(mutTinyFrameTxHandle, 5000));
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -88,7 +54,5 @@ bool TF_ClaimTx(TinyFrame *tf)
|
||||
void TF_ReleaseTx(TinyFrame *tf)
|
||||
{
|
||||
(void) tf;
|
||||
assert_param(pdTRUE == xSemaphoreGive(mutTinyFrameTxHandle));
|
||||
|
||||
// the last payload is sent asynchronously
|
||||
assert_param(osOK == osMutexRelease(mutTinyFrameTxHandle));
|
||||
}
|
||||
|
||||
@@ -870,11 +870,7 @@ static inline uint32_t _TF_FN TF_ComposeTail(uint8_t *outbuff, TF_CKSUM *cksum)
|
||||
*/
|
||||
static bool _TF_FN TF_SendFrame_Begin(TinyFrame *tf, TF_Msg *msg, TF_Listener listener, TF_TICKS timeout)
|
||||
{
|
||||
bool suc = TF_ClaimTx(tf);
|
||||
if (!suc) {
|
||||
TF_Error("TF lock not free");
|
||||
return false;
|
||||
}
|
||||
TF_TRY(TF_ClaimTx(tf));
|
||||
|
||||
tf->tx_pos = (uint32_t) TF_ComposeHead(tf, tf->sendbuf, msg); // frame ID is incremented here if it's not a response
|
||||
tf->tx_len = msg->len;
|
||||
@@ -1035,10 +1031,10 @@ bool _TF_FN TF_Query_Multipart(TinyFrame *tf, TF_Msg *msg, TF_Listener listener,
|
||||
return TF_Query(tf, msg, listener, timeout);
|
||||
}
|
||||
|
||||
bool _TF_FN TF_Respond_Multipart(TinyFrame *tf, TF_Msg *msg)
|
||||
void _TF_FN TF_Respond_Multipart(TinyFrame *tf, TF_Msg *msg)
|
||||
{
|
||||
msg->data = NULL;
|
||||
return TF_Respond(tf, msg);
|
||||
TF_Respond(tf, msg);
|
||||
}
|
||||
|
||||
void _TF_FN TF_Multipart_Payload(TinyFrame *tf, const uint8_t *buff, uint32_t length)
|
||||
|
||||
@@ -369,7 +369,7 @@ bool TF_Query_Multipart(TinyFrame *tf, TF_Msg *msg, TF_Listener listener, TF_TIC
|
||||
* TF_Respond() with multipart payload.
|
||||
* msg.data is ignored and set to NULL
|
||||
*/
|
||||
bool TF_Respond_Multipart(TinyFrame *tf, TF_Msg *msg);
|
||||
void TF_Respond_Multipart(TinyFrame *tf, TF_Msg *msg);
|
||||
|
||||
/**
|
||||
* Send the payload for a started multipart frame. This can be called multiple times
|
||||
|
||||
+3
-1
@@ -313,8 +313,10 @@ void USBD_CDC_TransmitDone(USBD_HandleTypeDef *pdev)
|
||||
assert_param(semVcomTxReadyHandle != NULL);
|
||||
assert_param(inIRQ());
|
||||
|
||||
if (uxSemaphoreGetCount(semVcomTxReadyHandle) == 1) return;
|
||||
|
||||
portBASE_TYPE taskWoken = pdFALSE;
|
||||
assert_param(pdTRUE == xSemaphoreGiveFromISR(semVcomTxReadyHandle, &taskWoken));
|
||||
assert_param(xSemaphoreGiveFromISR(semVcomTxReadyHandle, &taskWoken) == pdTRUE);
|
||||
portYIELD_FROM_ISR(taskWoken);
|
||||
}
|
||||
/* USER CODE END PRIVATE_FUNCTIONS_IMPLEMENTATION */
|
||||
|
||||
+10
-2
@@ -397,8 +397,16 @@ USBD_StatusTypeDef USBD_LL_Init (USBD_HandleTypeDef *pdev)
|
||||
HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , MSC_EPOUT_ADDR , PCD_SNG_BUF, ptr += 64); // 64
|
||||
|
||||
// CDC endpoints, EP2 two-way and EP3 in-only
|
||||
HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , CDC_IN_EP , PCD_SNG_BUF, ptr += 64); // 64
|
||||
HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , CDC_OUT_EP , PCD_SNG_BUF, ptr += 64); // 64
|
||||
uint32_t buf1addr, buf2addr;
|
||||
|
||||
buf1addr = (ptr += 64);
|
||||
buf2addr = (ptr += 64);
|
||||
HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , CDC_IN_EP , PCD_DBL_BUF, buf1addr | (buf2addr << 16)); // 64
|
||||
|
||||
buf1addr = (ptr += 64);
|
||||
buf2addr = (ptr += 64);
|
||||
HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , CDC_OUT_EP , PCD_DBL_BUF, buf1addr | (buf2addr << 16)); // 64
|
||||
|
||||
HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , CDC_CMD_EP , PCD_SNG_BUF, ptr += 16); // 16
|
||||
(void)ptr;
|
||||
#endif
|
||||
|
||||
+1
-1
@@ -99,7 +99,7 @@
|
||||
|
||||
#define CDC_CUSTOM_EPS
|
||||
#define CDC_IN_EP 0x82 /* EP1 for data IN */
|
||||
#define CDC_OUT_EP 0x02 /* EP1 for data OUT */
|
||||
#define CDC_OUT_EP 0x04 /* EP1 for data OUT */
|
||||
#define CDC_CMD_EP 0x83 /* EP2 for CDC commands */
|
||||
|
||||
/** @defgroup USBD_Exported_Macros
|
||||
|
||||
+4
-4
@@ -65,7 +65,7 @@ static void settings_bulkread_cb(BulkRead *bulk, uint32_t chunk, uint8_t *buffer
|
||||
if (buffer == NULL) {
|
||||
free_ck(bulk);
|
||||
iw_end();
|
||||
// dbg("INI read complete.");
|
||||
dbg("INI read complete.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ static void settings_bulkread_cb(BulkRead *bulk, uint32_t chunk, uint8_t *buffer
|
||||
*/
|
||||
static TF_Result lst_ini_export(TinyFrame *tf, TF_Msg *msg)
|
||||
{
|
||||
// dbg("Bulk read INI file");
|
||||
dbg("Bulk read INI file");
|
||||
|
||||
BulkRead *bulk = malloc_ck(sizeof(BulkRead));
|
||||
assert_param(bulk != NULL);
|
||||
@@ -114,7 +114,7 @@ static void settings_bulkwrite_cb(BulkWrite *bulk, const uint8_t *chunk, uint32_
|
||||
|
||||
if (bulk->offset > 0) {
|
||||
settings_load_ini_end();
|
||||
// dbg("INI write complete");
|
||||
dbg("INI write complete");
|
||||
} else {
|
||||
dbg("INI write failed");
|
||||
}
|
||||
@@ -131,7 +131,7 @@ static void settings_bulkwrite_cb(BulkWrite *bulk, const uint8_t *chunk, uint32_
|
||||
*/
|
||||
static TF_Result lst_ini_import(TinyFrame *tf, TF_Msg *msg)
|
||||
{
|
||||
// dbg("Bulk write INI file");
|
||||
dbg("Bulk write INI file");
|
||||
|
||||
BulkWrite *bulk = malloc_ck(sizeof(BulkWrite));
|
||||
assert_param(bulk);
|
||||
|
||||
+1
-1
@@ -169,7 +169,7 @@ void MX_FREERTOS_Init(void) {
|
||||
|
||||
/* USER CODE BEGIN RTOS_SEMAPHORES */
|
||||
/* add semaphores, ... */
|
||||
xSemaphoreGive(semVcomTxReadyHandle);
|
||||
assert_param(pdTRUE == xSemaphoreGive(semVcomTxReadyHandle));
|
||||
/* USER CODE END RTOS_SEMAPHORES */
|
||||
|
||||
/* USER CODE BEGIN RTOS_TIMERS */
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
#endif
|
||||
|
||||
// 180 is normally enough if not doing extensive debug logging
|
||||
#define TSK_STACK_MSG 220 // TF message handler task stack size (all unit commands run on this thread)
|
||||
#define TSK_STACK_MSG 260 // TF message handler task stack size (all unit commands run on this thread)
|
||||
#define TSK_STACK_IDLE 64 //configMINIMAL_STACK_SIZE
|
||||
#define TSK_STACK_TIMERS 64 //configTIMER_TASK_STACK_DEPTH
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
|
||||
|
||||
#define BULK_READ_BUF_LEN 256 // Buffer for TF bulk reads
|
||||
#define UNIT_TMP_LEN 256 // Buffer for internal unit operations
|
||||
#define UNIT_TMP_LEN 512 // 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 512 // TF transmit buffer (can be less than a full frame)
|
||||
#define TF_SENDBUF_LEN 64 // 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
|
||||
|
||||
@@ -40,8 +40,7 @@ static void UADC_JobSendBlockChunk(Job *job)
|
||||
.len = (TF_LEN) (1 /*seq*/ + count * sizeof(uint16_t)),
|
||||
.type = type,
|
||||
};
|
||||
|
||||
assert_param(true == TF_Respond_Multipart(comm, &msg));
|
||||
TF_Respond_Multipart(comm, &msg);
|
||||
TF_Multipart_Payload(comm, &priv->stream_serial, 1);
|
||||
TF_Multipart_Payload(comm, (uint8_t *) (priv->dma_buffer + start), count * sizeof(uint16_t));
|
||||
TF_Multipart_Close(comm);
|
||||
@@ -172,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 >> 1); // div2
|
||||
end = (priv->buf_itemcount / 2);
|
||||
}
|
||||
else {
|
||||
end = priv->buf_itemcount;
|
||||
@@ -235,7 +234,7 @@ static void handle_httc(Unit *unit, bool tc)
|
||||
priv->stream_startpos = 0;
|
||||
}
|
||||
else {
|
||||
priv->stream_startpos = priv->buf_itemcount >> 1; // div2
|
||||
priv->stream_startpos = priv->buf_itemcount / 2;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -290,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 >> 1); // div2
|
||||
const uint32_t half = (uint32_t) (priv->buf_itemcount / 2);
|
||||
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)
|
||||
@@ -337,10 +336,8 @@ 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 = 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 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 sample_pos;
|
||||
if (dmapos == 0) {
|
||||
|
||||
Reference in New Issue
Block a user