Browse Source

20211101.1.patch

huangliang 4 years ago
parent
commit
113452caaf

+ 2 - 1
amt630h-freertos/ArkmicroFiles/libcpu-amt630h/source/can.c

@@ -341,6 +341,8 @@ CanPort_t *xCanOpen(uint32_t id)
 	cap->tx_done = xQueueCreate(1, 0);
 	configASSERT(cap->tx_done);
 
+	cap->id = id;
+
 	vListInitialise(&cap->rxRevList);
 	vListInitialise(&cap->rxFreeList);
 	for (i = 0; i < CAN_RX_BUF_NUM; i++) {
@@ -349,7 +351,6 @@ CanPort_t *xCanOpen(uint32_t id)
 		vListInsertEnd(&cap->rxFreeList, &canListItem[cap->id][i]);
 	}
 
-	cap->id = id;
 	cap->pcan = (CAN_TypeDef *)ulCanBase[id];
 	
 	cap->irq = CAN0_IRQn + id;

+ 25 - 7
amt630h-freertos/ArkmicroFiles/libcpu-amt630h/source/uart.c

@@ -341,6 +341,16 @@ static void vUartIntHandler(void *param)
 	}
 }
 
+static void vUart485StopTx(UartPort_t *uap)
+{
+	writel(readl(uap->regbase + UART485_IER) & ~(1 << 1), uap->regbase + UART485_IER);
+}
+
+static void vUart485StartTx(UartPort_t *uap)
+{
+	writel(readl(uap->regbase + UART485_IER) | (1 << 1), uap->regbase + UART485_IER);
+}
+
 static int iUart485RxChars(UartPort_t *uap)
 {
 	uint32_t lsr;
@@ -378,6 +388,11 @@ static BaseType_t xUart485TxChars(UartPort_t *uap, int from_irq)
 	struct circ_buf *xmit = &uap->txbuf;
 	int count = uap->fifosize >> 1;
 
+	if (uart_circ_empty(xmit)) {
+		vUart485StopTx(uap);
+		return pdFALSE;
+	}
+
 	do {
 		if (from_irq && count-- == 0)
 			break;
@@ -559,7 +574,7 @@ void vUartInit(UartPort_t *uap, uint32_t baud, uint32_t flags)
 		writel(readl(uap->regbase + UART485_LCR) & ~(1 << 7), uap->regbase + UART485_LCR);
 		
 		cr = readl(uap->regbase + UART485_LCR);
-		//校验
+		//鏍¢獙
 		cr &= ~(7 << 3);
 		if (flags & PARENB) {
 			cr  |= (1 << 3);
@@ -568,12 +583,12 @@ void vUartInit(UartPort_t *uap, uint32_t baud, uint32_t flags)
 			if (flags & CMSPAR)
 				cr |= (1 << 5);
 		}
-		//停止位
+		//鍋滄�浣�
 		if (flags & CSTOPB)
 			cr |= (1 << 2);
 		else
 			cr &= ~(1 << 2);
-		//数据位
+		//鏁版嵁浣�
 		cr &= ~(3 << 0);
 		switch (flags & CSIZE) {
 		case CS5:
@@ -593,10 +608,10 @@ void vUartInit(UartPort_t *uap, uint32_t baud, uint32_t flags)
 		//set fifo
 		writel((2 << 6) | (3 << 4) | 7, uap->regbase + UART485_FCR);
 		
-		//enable tx/rx and err interrupt	
-		writel((1 << 4) | (1 << 1) | 1, uap->regbase + UART485_IER);
+		//enable rx and err interrupt
+		writel((1 << 4) | 1, uap->regbase + UART485_IER);
 
-		//设置通信模式全双工还是半双工
+		//璁剧疆閫氫俊妯″紡鍏ㄥ弻宸ヨ繕鏄�崐鍙屽伐
 		//485mode disable
 		writel(0, uap->regbase + UART485_TCR);
 	}
@@ -656,7 +671,10 @@ int iUartWrite(UartPort_t *uap, uint8_t *buf, size_t len, TickType_t xBlockTime)
 		xSemaphoreGiveRecursive(uap->xMutex);
 	}
 
-	vUartStartTx(uap);
+	if (uap->id < UART_ID3)
+		vUartStartTx(uap);
+	else
+		vUart485StartTx(uap);
 
 	return ret;
 }

+ 8 - 1
amt630h-freertos/ArkmicroFiles/libcpu-amt630h/source/usb/usb.c

@@ -1968,8 +1968,15 @@ static void prvUsbPortScanTimerCallback( TimerHandle_t xTimerHandle )
 int usb_wait_dev_pluged(uint32_t timeout)
 {
     uint8_t pluged = 0;
+	uint32_t stick = xTaskGetTickCount();
 
-    if (xQueueReceive(usbdev_pluged, &pluged, timeout) == pdPASS)
+	while (!usbdev_pluged) {
+		if (xTaskGetTickCount() - stick > timeout)
+			return -1;
+		vTaskDelay(10);
+	}
+
+    if (usbdev_pluged && xQueueReceive(usbdev_pluged, &pluged, timeout) == pdPASS)
     {
         if(pluged)
         {