Implemented unit timed tick and uart rx timeout
This commit is contained in:
+5
-3
@@ -1,6 +1,7 @@
|
||||
//
|
||||
// Created by MightyPork on 2018/01/14.
|
||||
//
|
||||
#include <platform/irq_dispatcher.h>
|
||||
#include "platform.h"
|
||||
#include "unit_base.h"
|
||||
|
||||
@@ -43,9 +44,6 @@ error_t UUSART_preInit(Unit *unit)
|
||||
priv->de_assert_time = 8;
|
||||
priv->de_clear_time = 8;
|
||||
|
||||
priv->rx_buffer = NULL;
|
||||
priv->tx_buffer = NULL;
|
||||
|
||||
return E_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -315,6 +313,10 @@ error_t UUSART_init(Unit *unit)
|
||||
// modifies some usart registers that can't be modified when enabled
|
||||
TRY(UUSART_SetupDMAs(unit));
|
||||
|
||||
// timeout based on the baudrate
|
||||
unit->tick_interval = (uint16_t) ((50 * 1000) / priv->baudrate); // receive timeout (ms)
|
||||
if (unit->tick_interval < 5) unit->tick_interval = 5;
|
||||
|
||||
return E_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@@ -57,6 +57,8 @@ struct priv {
|
||||
volatile uint16_t tx_buf_nw;
|
||||
volatile uint16_t tx_buf_chunk;
|
||||
volatile bool tx_dma_busy;
|
||||
|
||||
volatile uint16_t rx_last_dmapos;
|
||||
};
|
||||
|
||||
/** Allocate data structure and set defaults */
|
||||
@@ -95,6 +97,13 @@ void UUSART_DMA_HandleRxFromIRQ(Unit *unit, uint16_t endpos);
|
||||
*/
|
||||
uint16_t UUSART_DMA_TxQueue(struct priv *priv, const uint8_t *buffer, uint16_t len);
|
||||
|
||||
/**
|
||||
* Handle rx timeout, grab what is received and send it immediately.
|
||||
*
|
||||
* @param unit
|
||||
*/
|
||||
void UUSART_DMA_HandleRxTimeout(Unit *unit);
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// Created by MightyPork on 2018/01/02.
|
||||
//
|
||||
|
||||
#include <stm32f072xb.h>
|
||||
#include "platform.h"
|
||||
#include "comm/messages.h"
|
||||
#include "unit_base.h"
|
||||
@@ -68,6 +69,23 @@ void UUSART_DMA_HandleRxFromIRQ(Unit *unit, uint16_t endpos)
|
||||
priv->rx_buf_readpos = endpos;
|
||||
}
|
||||
|
||||
void UUSART_Tick(Unit *unit)
|
||||
{
|
||||
assert_param(unit);
|
||||
struct priv *priv = unit->data;
|
||||
assert_param(priv);
|
||||
|
||||
if (priv->rx_last_dmapos == priv->dma_rx->CNDTR) {
|
||||
uint16_t endpos = (uint16_t) (UUSART_RXBUF_LEN - priv->rx_last_dmapos);
|
||||
if (endpos != priv->rx_buf_readpos) {
|
||||
dbg("DMA timeout");
|
||||
UUSART_DMA_HandleRxFromIRQ(unit, endpos);
|
||||
}
|
||||
} else {
|
||||
priv->rx_last_dmapos = (uint16_t) priv->dma_rx->CNDTR;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
error_t UU_USART_Write(Unit *unit, const uint8_t *buffer, uint32_t len)
|
||||
{
|
||||
@@ -155,5 +173,6 @@ const UnitDriver UNIT_USART = {
|
||||
.init = UUSART_init,
|
||||
.deInit = UUSART_deInit,
|
||||
// Function
|
||||
.updateTick = UUSART_Tick,
|
||||
.handleRequest = UUSART_handleRequest,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user