Эх сурвалжийг харах

update:当串口缓存区的数据大于用户预设的长度时,应该上报一下
update:spi的传输优化

alienwalker 2 жил өмнө
parent
commit
49bd91e03a

+ 1 - 0
application/src/luat_uart_air105.c

@@ -233,6 +233,7 @@ int luat_uart_setup(luat_uart_t *uart){
     } else {
     	serials[uart->id].rx_mark = 0;
         Uart_BaseInit(uart->id, uart->baud_rate, 1, (uart->data_bits), parity, stop_bits, NULL);
+        Uart_SetRxBufferSize(uart->id, uart->bufsz);
         serials[uart->id].rs485_param_bit.is_485used = (uart->pin485 < GPIO_NONE)?1:0;
         serials[uart->id].rs485_pin = uart->pin485;
         serials[uart->id].rs485_param_bit.rx_level = uart->rx_level;

+ 7 - 21
bsp/air105/hal/core_spi.c

@@ -75,6 +75,7 @@ typedef struct
 	Buffer_Struct RxBuf;
 	uint32_t Speed;
 	uint32_t TargetSpeed;
+	uint32_t UseDMAValue;
 	uint8_t DMATxStream;
 	uint8_t DMARxStream;
 	uint8_t Is16Bit;
@@ -84,7 +85,7 @@ typedef struct
 	uint8_t SpiMode;
 	uint8_t timeout;
 }SPI_ResourceStruct;
-
+#define USE_DMA_MIN_FRQ	(100000)
 static SPI_ResourceStruct prvSPI[SPI_MAX] = {
 		{
 				HSPIM,
@@ -386,6 +387,7 @@ static void HSPI_MasterInit(uint8_t SpiID, uint8_t Mode, uint32_t Speed)
 	SPI->CR0 = ctrl;
 	SPI->DCR = 30|(1 << 7);
 	prvSPI[SpiID].Speed = (SystemCoreClock >> 1) / div;
+	prvSPI[SpiID].UseDMAValue = (prvSPI[SpiID].Speed >> 3) / USE_DMA_MIN_FRQ;
 	ISR_SetHandler(prvSPI[SpiID].IrqLine, HSPI_IrqHandle, (uint32_t)SpiID);
 #ifdef __BUILD_OS__
 	ISR_SetPriority(prvSPI[SpiID].IrqLine, IRQ_MAX_PRIORITY + 1);
@@ -437,6 +439,7 @@ void SPI_MasterInit(uint8_t SpiID, uint8_t DataBit, uint8_t Mode, uint32_t Speed
 		if (!div) div = 2;
 		if (div % 2) div++;
 		prvSPI[SpiID].Speed = (SystemCoreClock >> 2) / div;
+		prvSPI[SpiID].UseDMAValue = (prvSPI[SpiID].Speed >> 3) / USE_DMA_MIN_FRQ;
 		SPI->CTRLR0 = ctrl;
 		SPI->BAUDR = div;
 		SPI->TXFTLR = 0;
@@ -784,18 +787,9 @@ static int32_t prvSPI_BlockTransfer(uint8_t SpiID, const uint8_t *TxData, uint8_
 
 int32_t SPI_BlockTransfer(uint8_t SpiID, const uint8_t *TxData, uint8_t *RxData, uint32_t Len)
 {
-	uint32_t times = 192000000;
-	if (prvSPI[SpiID].Speed >= 48000000)
-	{
-		times = Len * 100000;
-	}
-	else if (prvSPI[SpiID].Speed >= 8000000)
-	{
-		times = Len * 1000000;
-	}
 #ifdef __BUILD_OS__
 	//if ( OS_CheckInIrq() || ((prvSPI[SpiID].Speed >> 3) >= (Len * 50000 * ((SpiID==HSPI_ID0)?2:1))))
-	if ( OS_CheckInIrq() || ((prvSPI[SpiID].Speed >> 3) >= times))
+	if ( OS_CheckInIrq() || (Len <= prvSPI[SpiID].UseDMAValue))
 	{
 		prvSPI[SpiID].IsBlockMode = 0;
 #endif
@@ -976,18 +970,9 @@ static int32_t prvSPI_FlashBlockTransfer(uint8_t SpiID, const uint8_t *TxData, u
 
 int32_t SPI_FlashBlockTransfer(uint8_t SpiID, const uint8_t *TxData, uint32_t WLen, uint8_t *RxData, uint32_t RLen)
 {
-	uint32_t times = 192000000;
-	if (prvSPI[SpiID].Speed >= 48000000)
-	{
-		times = (WLen + RLen) * 100000;
-	}
-	else if (prvSPI[SpiID].Speed >= 8000000)
-	{
-		times = (WLen + RLen)  * 1000000;
-	}
 #ifdef __BUILD_OS__
 //	if ( OS_CheckInIrq() || ((prvSPI[SpiID].Speed >> 3) >= ((WLen + RLen) * 50000 * ((SpiID==HSPI_ID0)?2:1) )))
-	if ( OS_CheckInIrq() || ((prvSPI[SpiID].Speed >> 3) >= times))
+	if ( OS_CheckInIrq() || ((WLen + RLen) <= prvSPI[SpiID].UseDMAValue))
 	{
 		prvSPI[SpiID].IsBlockMode = 0;
 #endif
@@ -1211,4 +1196,5 @@ void SPI_SetNewConfig(uint8_t SpiID, uint32_t Speed, uint8_t NewMode)
 		SPI->SSIENR = 1;
 		break;
 	}
+	prvSPI[SpiID].UseDMAValue = (prvSPI[SpiID].Speed >> 3) / USE_DMA_MIN_FRQ;
 }

+ 11 - 2
bsp/air105/hal/core_uart.c

@@ -48,6 +48,7 @@ typedef struct
 	Buffer_Struct RxDMABuf[RX_BUF_BAND];
 #endif
 	uint32_t LastError;
+	uint32_t RxBufferSize;
 #ifdef __RX_USE_DMA__
 	uint8_t RxDMASn;
 
@@ -200,7 +201,7 @@ void Uart_BaseInit(uint8_t UartID, uint32_t BaudRate, uint8_t IsRxCacheEnable, u
     UART_FIFOInitStruct.FIFO_RX_Trigger = UART_FIFO_RX_Trigger_1_2_Full;
     UART_FIFOInitStruct.FIFO_TX_Trigger = UART_FIFO_TX_Trigger_1_4_Full;
     UART_FIFOInitStruct.FIFO_TX_TriggerIntEnable = ENABLE;
-
+    prvUart[UartID].RxBufferSize = 1024;
     ISR_SetHandler(prvUart[UartID].IrqLine, prvUart_IrqHandle, (void *)UartID);
 #ifdef __BUILD_OS__
 	ISR_SetPriority(prvUart[UartID].IrqLine, IRQ_MAX_PRIORITY + 2);
@@ -298,6 +299,11 @@ void Uart_BaseInit(uint8_t UartID, uint32_t BaudRate, uint8_t IsRxCacheEnable, u
 }
 
 
+void Uart_SetRxBufferSize(uint8_t UartID, uint32_t RxBufferSize)
+{
+	prvUart[UartID].RxBufferSize = RxBufferSize?RxBufferSize:1024;
+}
+
 void Uart_SetCb(uint8_t UartID, CBFuncEx_t CB)
 {
 	if (CB)
@@ -651,10 +657,13 @@ static void prvUart_IrqHandle(int32_t IrqLine, void *pData)
 			if (prvUart[UartID].RxCacheMode)
 			{
 				Uart_CacheRead(UartID, 8);
+				if (prvUart[UartID].RxBuf.Pos > prvUart[UartID].RxBufferSize)
+				{
+					prvUart[UartID].Callback((uint32_t)UartID, (void *)UART_CB_RX_BUFFER_FULL);
+				}
 				break;
 			}
 #endif
-
 			prvUart[UartID].Callback((uint32_t)UartID, (void *)UART_CB_RX_NEW);
 		}
 		break;