Explorar el Código

【SMART】【BSP】【allwinner】Fix smart serial_v2 bypass compile error issue (#10524)

* Modify the reference path of the header file in the middle section

* format

* Fix smart serial_v2 bypass compile error issue

* add allwinner/d1s ci
rcitach hace 5 meses
padre
commit
ae50e406da

+ 7 - 0
.github/ALL_BSP_COMPILE.json

@@ -490,6 +490,13 @@
       "SUB_RTT_BSP": [
         "xuantie/virt64/c906"
       ]
+    },
+    {
+      "RTT_BSP": "allwinner-smart",
+      "RTT_TOOL_CHAIN": "sourcery-riscv64-general-toolchain",
+      "SUB_RTT_BSP": [
+        "allwinner/d1s"
+      ]
     }
   ]
 }

+ 8 - 0
.github/workflows/bsp_buildings.yml

@@ -163,6 +163,14 @@ jobs:
           /opt/riscv64-unknown-elf-toolchain-10.2.0-2020.12.8-x86_64-linux-ubuntu14/bin/riscv64-unknown-elf-gcc --version
           echo "RTT_EXEC_PATH=/opt/riscv64-unknown-elf-toolchain-10.2.0-2020.12.8-x86_64-linux-ubuntu14/bin" >> $GITHUB_ENV
 
+      - name: Install  Riscv64 rt-thread smart general toolchain
+        if: ${{ matrix.legs.RTT_TOOL_CHAIN == 'sourcery-riscv64-general-toolchain' && success() }}
+        run: |
+          wget -q https://github.com/RT-Thread/rt-thread/releases/download/v5.2.0/riscv64gc-linux-musleabi_for_x86_64-pc-linux-gnu_252938-345d8b6e45.tar.bz2
+          sudo tar xjf riscv64gc-linux-musleabi_for_x86_64-pc-linux-gnu_252938-345d8b6e45.tar.bz2 -C /opt
+          /opt/riscv64gc-linux-musleabi_for_x86_64-pc-linux-gnu/bin/riscv64-unknown-linux-musl-gcc --version
+          echo "RTT_EXEC_PATH=/opt/riscv64gc-linux-musleabi_for_x86_64-pc-linux-gnu/bin" >> $GITHUB_ENV
+
       - name: Install Xuantie-900-gcc-elf-newlib Tools
         if: ${{ matrix.legs.RTT_TOOL_CHAIN == 'sourcery-Xuantie-900-gcc-elf-newlib' && success() }}
         run: |

+ 600 - 555
bsp/allwinner/libraries/sunxi-hal/hal/source/g2d_rcq/g2d.c

@@ -19,12 +19,12 @@
 #include <hal_cache.h>
 #include <stdlib.h>
 #include <string.h>
-#include <interrupt.h>
+#include <hal_interrupt.h>
 #include <init.h>
 #include <hal_clk.h>
 #include <hal_reset.h>
 #include <hal_timer.h>
-// #include <melis/standby/standby.h>
+/* #include <melis/standby/standby.h> */
 
 #include "g2d_driver_i.h"
 #include "g2d_top.h"
@@ -34,37 +34,37 @@
 #define SUNXI_GIC_START 32
 
 #if defined(CONFIG_ARCH_SUN8IW19)
-#define SUNXI_IRQ_G2D				(SUNXI_GIC_START + 21)
-#define SUNXI_G2D_START				0x01480000
-#define SUNXI_G2D_RESET_ID			0
-#define SUNXI_G2D_CLK_ID			HAL_CLK_PERIPH_G2D
-#define SUNXI_G2D_CLK_BUS_ID			(hal_clk_id_t)(-1)
-#define SUNXI_G2D_CLK_MBUS_ID			(hal_clk_id_t)(-1)
-#define SUNXI_G2D_CLK_PARENT			HAL_CLK_PLL_PERI1
+#define SUNXI_IRQ_G2D               (SUNXI_GIC_START + 21)
+#define SUNXI_G2D_START             0x01480000
+#define SUNXI_G2D_RESET_ID          0
+#define SUNXI_G2D_CLK_ID            HAL_CLK_PERIPH_G2D
+#define SUNXI_G2D_CLK_BUS_ID            (hal_clk_id_t)(-1)
+#define SUNXI_G2D_CLK_MBUS_ID           (hal_clk_id_t)(-1)
+#define SUNXI_G2D_CLK_PARENT            HAL_CLK_PLL_PERI1
 
 #elif defined(CONFIG_SOC_SUN20IW1)
-#define SUNXI_IRQ_G2D				105
-#define SUNXI_G2D_START				0x05410000
+#define SUNXI_IRQ_G2D               105
+#define SUNXI_G2D_START             0x05410000
 #define RESET_IOMMU
-#define G2D_IOMMU_MASTER_ID			3
+#define G2D_IOMMU_MASTER_ID         3
 #define IOMMU_RESET_REG                         0x02010010
 #define IOMMU_BGR_REG                           0x020017bc
 #endif
 
 #ifndef SUNXI_G2D_CLK_ID
-#define SUNXI_G2D_CLK_ID			CLK_G2D
+#define SUNXI_G2D_CLK_ID            CLK_G2D
 #endif
 #ifndef SUNXI_G2D_RESET_ID
-#define SUNXI_G2D_RESET_ID			RST_BUS_G2D
+#define SUNXI_G2D_RESET_ID          RST_BUS_G2D
 #endif
 #ifndef SUNXI_G2D_CLK_BUS_ID
-#define SUNXI_G2D_CLK_BUS_ID			CLK_BUS_G2D
+#define SUNXI_G2D_CLK_BUS_ID            CLK_BUS_G2D
 #endif
 #ifndef SUNXI_G2D_CLK_MBUS_ID
-#define SUNXI_G2D_CLK_MBUS_ID			CLK_MBUS_G2D
+#define SUNXI_G2D_CLK_MBUS_ID           CLK_MBUS_G2D
 #endif
 #ifndef SUNXI_G2D_CLK_PARENT
-#define SUNXI_G2D_CLK_PARENT			CLK_PLL_PERIPH0_2X
+#define SUNXI_G2D_CLK_PARENT            CLK_PLL_PERIPH0_2X
 #endif
 
 enum g2d_scan_order scan_order;
@@ -79,30 +79,32 @@ __u32 dbg_info;
 void *g2d_malloc(__u32 bytes_num, __u32 *phy_addr)
 {
 
-	char* vir_addr;
-
-	if (bytes_num != 0) {
-		vir_addr = hal_malloc_align(bytes_num, CACHELINE_LEN);
-		if(vir_addr!=NULL){
-			*phy_addr = __va_to_pa((unsigned long)vir_addr);
-			memset((void *)vir_addr, 0, bytes_num);
-			hal_dcache_clean((unsigned long)vir_addr, bytes_num);
-			return vir_addr;
-		}
-		G2D_ERR_MSG("hal_malloc fail!\n");
-		return NULL;
-	}
-	G2D_ERR_MSG("size is zero\n");
-
-	return NULL;
+    char* vir_addr;
+
+    if (bytes_num != 0)
+    {
+        vir_addr = hal_malloc_align(bytes_num, CACHELINE_LEN);
+        if(vir_addr!=NULL)
+        {
+            *phy_addr = __va_to_pa((unsigned long)vir_addr);
+            memset((void *)vir_addr, 0, bytes_num);
+            hal_dcache_clean((unsigned long)vir_addr, bytes_num);
+            return vir_addr;
+        }
+        G2D_ERR_MSG("hal_malloc fail!\n");
+        return NULL;
+    }
+    G2D_ERR_MSG("size is zero\n");
+
+    return NULL;
 }
 
 void g2d_free(void *virt_addr, void *phy_addr, unsigned int size)
 {
 
-	if (virt_addr == NULL)
-		return;
-	hal_free_align(virt_addr);
+    if (virt_addr == NULL)
+        return;
+    hal_free_align(virt_addr);
 }
 
 int g2d_mutex_lock(hal_sem_t sem)
@@ -117,69 +119,77 @@ int g2d_mutex_unlock(hal_sem_t sem)
 
 __s32 g2d_byte_cal(__u32 format, __u32 *ycnt, __u32 *ucnt, __u32 *vcnt)
 {
-	*ycnt = 0;
-	*ucnt = 0;
-	*vcnt = 0;
-	if (format <= G2D_FORMAT_BGRX8888)
-		*ycnt = 4;
-
-	else if (format <= G2D_FORMAT_BGR888)
-		*ycnt = 3;
-
-	else if (format <= G2D_FORMAT_BGRA5551)
-		*ycnt = 2;
-
-	else if (format <= G2D_FORMAT_BGRA1010102)
-		*ycnt = 4;
-
-	else if (format <= 0x23) {
-		*ycnt = 2;
-	}
-
-	else if (format <= 0x25) {
-		*ycnt = 1;
-		*ucnt = 2;
-	}
-
-	else if (format == 0x26) {
-		*ycnt = 1;
-		*ucnt = 1;
-		*vcnt = 1;
-	}
-
-	else if (format <= 0x29) {
-		*ycnt = 1;
-		*ucnt = 2;
-	}
-
-	else if (format == 0x2a) {
-		*ycnt = 1;
-		*ucnt = 1;
-		*vcnt = 1;
-	}
-
-	else if (format <= 0x2d) {
-		*ycnt = 1;
-		*ucnt = 2;
-	}
-
-	else if (format == 0x2e) {
-		*ycnt = 1;
-		*ucnt = 1;
-		*vcnt = 1;
-	}
-
-	else if (format == 0x30)
-		*ycnt = 1;
-
-	else if (format <= 0x36) {
-		*ycnt = 2;
-		*ucnt = 4;
-	}
-
-	else if (format <= 0x39)
-		*ycnt = 6;
-	return 0;
+    *ycnt = 0;
+    *ucnt = 0;
+    *vcnt = 0;
+    if (format <= G2D_FORMAT_BGRX8888)
+        *ycnt = 4;
+
+    else if (format <= G2D_FORMAT_BGR888)
+        *ycnt = 3;
+
+    else if (format <= G2D_FORMAT_BGRA5551)
+        *ycnt = 2;
+
+    else if (format <= G2D_FORMAT_BGRA1010102)
+        *ycnt = 4;
+
+    else if (format <= 0x23)
+    {
+        *ycnt = 2;
+    }
+
+    else if (format <= 0x25)
+    {
+        *ycnt = 1;
+        *ucnt = 2;
+    }
+
+    else if (format == 0x26)
+    {
+        *ycnt = 1;
+        *ucnt = 1;
+        *vcnt = 1;
+    }
+
+    else if (format <= 0x29)
+    {
+        *ycnt = 1;
+        *ucnt = 2;
+    }
+
+    else if (format == 0x2a)
+    {
+        *ycnt = 1;
+        *ucnt = 1;
+        *vcnt = 1;
+    }
+
+    else if (format <= 0x2d)
+    {
+        *ycnt = 1;
+        *ucnt = 2;
+    }
+
+    else if (format == 0x2e)
+    {
+        *ycnt = 1;
+        *ucnt = 1;
+        *vcnt = 1;
+    }
+
+    else if (format == 0x30)
+        *ycnt = 1;
+
+    else if (format <= 0x36)
+    {
+        *ycnt = 2;
+        *ucnt = 4;
+    }
+
+    else if (format <= 0x39)
+        *ycnt = 6;
+    return 0;
 }
 
 
@@ -187,95 +197,102 @@ __s32 g2d_byte_cal(__u32 format, __u32 *ycnt, __u32 *ucnt, __u32 *vcnt)
  */
 __u32 cal_align(__u32 width, __u32 align)
 {
-	switch (align) {
-	case 0:
-		return width;
-	case 4:
-		return (width + 3) >> 2 << 2;
-	case 8:
-		return (width + 7) >> 3 << 3;
-	case 16:
-		return (width + 15) >> 4 << 4;
-	case 32:
-		return (width + 31) >> 5 << 5;
-	case 64:
-		return (width + 63) >> 6 << 6;
-	case 128:
-		return (width + 127) >> 7 << 7;
-	default:
-		return (width + 31) >> 5 << 5;
-	}
+    switch (align)
+    {
+    case 0:
+        return width;
+    case 4:
+        return (width + 3) >> 2 << 2;
+    case 8:
+        return (width + 7) >> 3 << 3;
+    case 16:
+        return (width + 15) >> 4 << 4;
+    case 32:
+        return (width + 31) >> 5 << 5;
+    case 64:
+        return (width + 63) >> 6 << 6;
+    case 128:
+        return (width + 127) >> 7 << 7;
+    default:
+        return (width + 31) >> 5 << 5;
+    }
 }
 
 
 __s32 g2d_image_check(g2d_image_enh *p_image)
 {
-	__s32 ret = -EINVAL;
-
-	if (!p_image) {
-		G2D_ERR_MSG("NUll pointer!\n");
-		goto OUT;
-	}
-
-	if (((p_image->clip_rect.x < 0) &&
-	     ((-p_image->clip_rect.x) > p_image->clip_rect.w)) ||
-	    ((p_image->clip_rect.y < 0) &&
-	     ((-p_image->clip_rect.y) > p_image->clip_rect.h)) ||
-	    ((p_image->clip_rect.x > 0) &&
-	     (p_image->clip_rect.x > p_image->width - 1)) ||
-	    ((p_image->clip_rect.y > 0) &&
-	     (p_image->clip_rect.y > p_image->height - 1))) {
-		G2D_ERR_MSG("Invalid imager parameter setting\n");
-		goto OUT;
-	}
-
-	if (((p_image->clip_rect.x < 0) &&
-				((-p_image->clip_rect.x) <
-				 p_image->clip_rect.w))) {
-		p_image->clip_rect.w =
-			p_image->clip_rect.w +
-			p_image->clip_rect.x;
-		p_image->clip_rect.x = 0;
-	} else if ((p_image->clip_rect.x +
-				p_image->clip_rect.w)
-			> p_image->width) {
-		p_image->clip_rect.w =
-			p_image->width -
-			p_image->clip_rect.x;
-	}
-	if (((p_image->clip_rect.y < 0) &&
-				((-p_image->clip_rect.y) <
-				 p_image->clip_rect.h))) {
-		p_image->clip_rect.h =
-			p_image->clip_rect.h +
-			p_image->clip_rect.y;
-		p_image->clip_rect.y = 0;
-	} else if ((p_image->clip_rect.y +
-				p_image->clip_rect.h)
-			> p_image->height) {
-		p_image->clip_rect.h =
-			p_image->height -
-			p_image->clip_rect.y;
-	}
-
-	p_image->bpremul = 0;
-	p_image->bbuff = 1;
-	p_image->gamut = G2D_BT709;
-	ret = 0;
+    __s32 ret = -EINVAL;
+
+    if (!p_image)
+    {
+        G2D_ERR_MSG("NUll pointer!\n");
+        goto OUT;
+    }
+
+    if (((p_image->clip_rect.x < 0) &&
+         ((-p_image->clip_rect.x) > p_image->clip_rect.w)) ||
+        ((p_image->clip_rect.y < 0) &&
+         ((-p_image->clip_rect.y) > p_image->clip_rect.h)) ||
+        ((p_image->clip_rect.x > 0) &&
+         (p_image->clip_rect.x > p_image->width - 1)) ||
+        ((p_image->clip_rect.y > 0) &&
+         (p_image->clip_rect.y > p_image->height - 1)))
+         {
+        G2D_ERR_MSG("Invalid imager parameter setting\n");
+        goto OUT;
+    }
+
+    if (((p_image->clip_rect.x < 0) &&
+                ((-p_image->clip_rect.x) <
+                 p_image->clip_rect.w)))
+                 {
+        p_image->clip_rect.w =
+            p_image->clip_rect.w +
+            p_image->clip_rect.x;
+        p_image->clip_rect.x = 0;
+    } else if ((p_image->clip_rect.x +
+                p_image->clip_rect.w)
+            > p_image->width)
+            {
+        p_image->clip_rect.w =
+            p_image->width -
+            p_image->clip_rect.x;
+    }
+    if (((p_image->clip_rect.y < 0) &&
+                ((-p_image->clip_rect.y) <
+                 p_image->clip_rect.h)))
+                 {
+        p_image->clip_rect.h =
+            p_image->clip_rect.h +
+            p_image->clip_rect.y;
+        p_image->clip_rect.y = 0;
+    } else if ((p_image->clip_rect.y +
+                p_image->clip_rect.h)
+            > p_image->height)
+            {
+        p_image->clip_rect.h =
+            p_image->height -
+            p_image->clip_rect.y;
+    }
+
+    p_image->bpremul = 0;
+    p_image->bbuff = 1;
+    p_image->gamut = G2D_BT709;
+    ret = 0;
 OUT:
-	return ret;
+    return ret;
 
 }
 
 int g2d_blit_h(g2d_blt_h *para)
 {
-	int ret = -1;
+    int ret = -1;
 
-	ret = g2d_rotate_set_para(&para->src_image_h,
-			    &para->dst_image_h,
-			    para->flag_h);
+    ret = g2d_rotate_set_para(&para->src_image_h,
+                &para->dst_image_h,
+                para->flag_h);
 
-	return ret;
+    return ret;
 }
 
 #ifdef RESET_IOMMU
@@ -284,21 +301,22 @@ int g2d_blit_h(g2d_blt_h *para)
  */
 static void reset_iommu(void)
 {
-	int tmp;
-	int ret;
-	uint32_t regval;
-	*(volatile uint32_t *)(IOMMU_BGR_REG) = 0x1;
-	regval = (*(volatile uint32_t *)(IOMMU_RESET_REG));
-
-	*(volatile uint32_t *)(IOMMU_RESET_REG) = regval & (~(1 << G2D_IOMMU_MASTER_ID));
-	regval = (*(volatile uint32_t *)(IOMMU_RESET_REG));
-	if (!(regval & ((1 << G2D_IOMMU_MASTER_ID)))) {
-		*(volatile uint32_t *)(IOMMU_RESET_REG) = regval | ((1 << G2D_IOMMU_MASTER_ID));
-	}
-	regval = (*(volatile uint32_t *)(IOMMU_RESET_REG));
-
-	*(volatile uint32_t *)(IOMMU_BGR_REG) = 0;
-	return;
+    int tmp;
+    int ret;
+    uint32_t regval;
+    *(volatile uint32_t *)(IOMMU_BGR_REG) = 0x1;
+    regval = (*(volatile uint32_t *)(IOMMU_RESET_REG));
+
+    *(volatile uint32_t *)(IOMMU_RESET_REG) = regval & (~(1 << G2D_IOMMU_MASTER_ID));
+    regval = (*(volatile uint32_t *)(IOMMU_RESET_REG));
+    if (!(regval & ((1 << G2D_IOMMU_MASTER_ID))))
+    {
+        *(volatile uint32_t *)(IOMMU_RESET_REG) = regval | ((1 << G2D_IOMMU_MASTER_ID));
+    }
+    regval = (*(volatile uint32_t *)(IOMMU_RESET_REG));
+
+    *(volatile uint32_t *)(IOMMU_BGR_REG) = 0;
+    return;
 }
 #else
 static void reset_iommu(void)
@@ -308,158 +326,174 @@ static void reset_iommu(void)
 
 int g2d_wait_cmd_finish(unsigned int timeout)
 {
-	int ret;
-	ret = hal_sem_timedwait(g2d_ext_hd.queue_sem,timeout* 10);
-	if (ret < 0) {
-		reset_iommu();
-		g2d_bsp_reset();
-		G2D_ERR_MSG("G2D irq pending flag timeout\n");
-		g2d_ext_hd.finish_flag = 1;
-		//wake_up(&g2d_ext_hd.queue);
-		return -1;
-	}
-	g2d_ext_hd.finish_flag = 0;
-
-	return 0;
+    int ret;
+    ret = hal_sem_timedwait(g2d_ext_hd.queue_sem,timeout* 10);
+    if (ret < 0)
+    {
+        reset_iommu();
+        g2d_bsp_reset();
+        G2D_ERR_MSG("G2D irq pending flag timeout\n");
+        g2d_ext_hd.finish_flag = 1;
+        /* wake_up(&g2d_ext_hd.queue); */
+        return -1;
+    }
+    g2d_ext_hd.finish_flag = 0;
+
+    return 0;
 }
 
 irqreturn_t g2d_handle_irq(int irq, void *dev_id)
 {
 #if G2D_MIXER_RCQ_USED == 1
-	if (g2d_top_rcq_task_irq_query()) {
-		// g2d_top_mixer_reset();
-		g2d_ext_hd.finish_flag = 1;
-		hal_sem_post(g2d_ext_hd.queue_sem);
-		return IRQ_HANDLED;
-	}
+    if (g2d_top_rcq_task_irq_query())
+    {
+        /* g2d_top_mixer_reset(); */
+        g2d_ext_hd.finish_flag = 1;
+        hal_sem_post(g2d_ext_hd.queue_sem);
+        return IRQ_HANDLED;
+    }
 #else
-	if (g2d_mixer_irq_query()) {
-		// g2d_top_mixer_reset();
-		g2d_ext_hd.finish_flag = 1;
-		hal_sem_post(g2d_ext_hd.queue_sem);
-		return IRQ_HANDLED;
-	}
+    if (g2d_mixer_irq_query())
+    {
+        /* g2d_top_mixer_reset(); */
+        g2d_ext_hd.finish_flag = 1;
+        hal_sem_post(g2d_ext_hd.queue_sem);
+        return IRQ_HANDLED;
+    }
 #endif
-	if (g2d_rot_irq_query()) {
-		// g2d_top_rot_reset();
-		g2d_ext_hd.finish_flag = 1;
-		hal_sem_post(g2d_ext_hd.queue_sem);
-		return IRQ_HANDLED;
-	}
-
-	return IRQ_HANDLED;
+    if (g2d_rot_irq_query())
+    {
+        /* g2d_top_rot_reset(); */
+        g2d_ext_hd.finish_flag = 1;
+        hal_sem_post(g2d_ext_hd.queue_sem);
+        return IRQ_HANDLED;
+    }
+
+    return IRQ_HANDLED;
 }
 
 int g2d_clk_init(__g2d_info_t *info)
 {
-	int i;
-	int ret;
-	hal_reset_id_t rst_id;
-	hal_reset_type_t reset_type = HAL_SUNXI_RESET;
-	hal_clk_type_t clk_type = HAL_SUNXI_CCU;
-	hal_clk_id_t clk_id[G2D_CLK_NUM] = {
-			SUNXI_G2D_CLK_ID,/*note SUNXI_G2D_CLK_ID must be here, please see g2d_clock_enable*/
-			SUNXI_G2D_CLK_BUS_ID,
-			SUNXI_G2D_CLK_MBUS_ID,
-	};
-	info->clk_rate = 300000000; /*300Mhz*/
-	info->reset = hal_reset_control_get(reset_type, SUNXI_G2D_RESET_ID);
-	hal_reset_control_deassert(info->reset);
-	info->clk_parent= hal_clock_get(clk_type,SUNXI_G2D_CLK_PARENT);
-	for(i = 0; i < G2D_CLK_NUM; i++) {
-		if (clk_id[i] != (hal_clk_id_t)-1) {
-			info->clk[i] = hal_clock_get(clk_type, clk_id[i]);
-		}
-	}
-	ret = hal_clk_set_parent(info->clk[0], info->clk_parent);
-	if (ret)
-		G2D_ERR_MSG("set clk:%d's parent:%d fail!\n", info->clk, info->clk_parent);
-	return ret;
+    int i;
+    int ret;
+    hal_reset_id_t rst_id;
+    hal_reset_type_t reset_type = HAL_SUNXI_RESET;
+    hal_clk_type_t clk_type = HAL_SUNXI_CCU;
+    hal_clk_id_t clk_id[G2D_CLK_NUM] = {
+            SUNXI_G2D_CLK_ID,/*note SUNXI_G2D_CLK_ID must be here, please see g2d_clock_enable*/
+            SUNXI_G2D_CLK_BUS_ID,
+            SUNXI_G2D_CLK_MBUS_ID,
+    };
+    info->clk_rate = 300000000; /*300Mhz*/
+    info->reset = hal_reset_control_get(reset_type, SUNXI_G2D_RESET_ID);
+    hal_reset_control_deassert(info->reset);
+    info->clk_parent= hal_clock_get(clk_type,SUNXI_G2D_CLK_PARENT);
+    for(i = 0; i < G2D_CLK_NUM; i++)
+    {
+        if (clk_id[i] != (hal_clk_id_t)-1)
+        {
+            info->clk[i] = hal_clock_get(clk_type, clk_id[i]);
+        }
+    }
+    ret = hal_clk_set_parent(info->clk[0], info->clk_parent);
+    if (ret)
+        G2D_ERR_MSG("set clk:%d's parent:%d fail!\n", info->clk, info->clk_parent);
+    return ret;
 }
 
 int g2d_clk_exit(__g2d_info_t *info)
 {
-	int i = 0;
-	for(i = 0; i < G2D_CLK_NUM; i++) {
-		hal_clock_put(info->clk[i]);
-	}
+    int i = 0;
+    for(i = 0; i < G2D_CLK_NUM; i++)
+    {
+        hal_clock_put(info->clk[i]);
+    }
 
-	hal_reset_control_put(info->reset);
+    hal_reset_control_put(info->reset);
 
-	return 0;
+    return 0;
 }
 
 int g2d_clock_enable(__g2d_info_t *info)
 {
-	int ret = -1;
-	int i = 0;
-	ret = hal_reset_control_deassert(info->reset);
-	if (ret) {
-		G2D_ERR_MSG("deassert rst fail:%d\n", ret);
-		goto OUT;
-	}
-
-	ret = hal_clock_enable(info->clk_parent);
-	if (ret) {
-		G2D_ERR_MSG("Enable clk parent fail:%d\n", ret);
-		goto OUT;
-	}
-
-	ret = hal_clk_set_rate(info->clk[0], info->clk_rate);
-	if (ret) {
-		G2D_ERR_MSG("Set clk rate fail:%d:%u!\n", info->clk[0], (unsigned int)info->clk_rate);
-		goto OUT;
-	}
-
-	for(i = 0; i < G2D_CLK_NUM; i++) {
-		ret = hal_clock_enable(info->clk[i]);
-		if (ret) {
-			G2D_ERR_MSG("Enable clk %d fail:%d\n", i, ret);
-			goto OUT;
-		}
-	}
+    int ret = -1;
+    int i = 0;
+    ret = hal_reset_control_deassert(info->reset);
+    if (ret)
+    {
+        G2D_ERR_MSG("deassert rst fail:%d\n", ret);
+        goto OUT;
+    }
+
+    ret = hal_clock_enable(info->clk_parent);
+    if (ret)
+    {
+        G2D_ERR_MSG("Enable clk parent fail:%d\n", ret);
+        goto OUT;
+    }
+
+    ret = hal_clk_set_rate(info->clk[0], info->clk_rate);
+    if (ret)
+    {
+        G2D_ERR_MSG("Set clk rate fail:%d:%u!\n", info->clk[0], (unsigned int)info->clk_rate);
+        goto OUT;
+    }
+
+    for(i = 0; i < G2D_CLK_NUM; i++)
+    {
+        ret = hal_clock_enable(info->clk[i]);
+        if (ret)
+        {
+            G2D_ERR_MSG("Enable clk %d fail:%d\n", i, ret);
+            goto OUT;
+        }
+    }
 
 OUT:
-	return ret;
+    return ret;
 }
 
 static int g2d_clock_disable(__g2d_info_t *info)
 {
-	int ret = -1;
-	int i;
-	for(i = 0; i < G2D_CLK_NUM; i++) {
-		ret = hal_clock_disable(info->clk[i]);
-		if (ret) {
-			G2D_ERR_MSG("Disable clk %d fail:%d\n", i, ret);
-			goto OUT;
-		}
-	}
-
-	ret = hal_reset_control_assert(info->reset);
-	if (ret) {
-		G2D_ERR_MSG("assert rst fail:%d\n", ret);
-		goto OUT;
-	}
+    int ret = -1;
+    int i;
+    for(i = 0; i < G2D_CLK_NUM; i++)
+    {
+        ret = hal_clock_disable(info->clk[i]);
+        if (ret)
+        {
+            G2D_ERR_MSG("Disable clk %d fail:%d\n", i, ret);
+            goto OUT;
+        }
+    }
+
+    ret = hal_reset_control_assert(info->reset);
+    if (ret)
+    {
+        G2D_ERR_MSG("assert rst fail:%d\n", ret);
+        goto OUT;
+    }
 OUT:
-	return  ret;
+    return  ret;
 }
+
 __s32 drv_g2d_init(__g2d_info_t *info)
 {
-	int ret;
-	memset(&g2d_ext_hd, 0, sizeof(__g2d_drv_t));
+    int ret;
+    memset(&g2d_ext_hd, 0, sizeof(__g2d_drv_t));
 
-	g2d_ext_hd.queue_sem = hal_sem_create(0);
-	if (g2d_ext_hd.queue_sem == NULL)
-	{
-		G2D_ERR_MSG("create g2d_ext_hd.queue_sem failed\n");
-		return -1;
-	}
+    g2d_ext_hd.queue_sem = hal_sem_create(0);
+    if (g2d_ext_hd.queue_sem == NULL)
+    {
+        G2D_ERR_MSG("create g2d_ext_hd.queue_sem failed\n");
+        return -1;
+    }
 
 
-	g2d_top_set_base((__u32)info->io);
-	g2d_rot_set_base((__u32)info->io);
-	g2d_mixer_idr_init();
-	return 0;
+    g2d_top_set_base((__u32)info->io);
+    g2d_rot_set_base((__u32)info->io);
+    g2d_mixer_idr_init();
+    return 0;
 }
 
 #ifdef CONFIG_STANDBY
@@ -469,14 +503,15 @@ __s32 drv_g2d_init(__g2d_info_t *info)
  */
 int g2d_suspend(void)
 {
-	g2d_mutex_lock(para.mutex);
-	if (para.opened) {
-		g2d_clock_disable(&para);
-		g2d_bsp_close();
-	}
-	g2d_mutex_unlock(para.mutex);
-
-	return 0;
+    g2d_mutex_lock(para.mutex);
+    if (para.opened)
+    {
+        g2d_clock_disable(&para);
+        g2d_bsp_close();
+    }
+    g2d_mutex_unlock(para.mutex);
+
+    return 0;
 }
 
 /**
@@ -485,18 +520,20 @@ int g2d_suspend(void)
  */
 int g2d_resume(void)
 {
-	g2d_mutex_lock(para.mutex);
-	if (para.opened) {
-		g2d_clock_enable(&para);
-		g2d_bsp_open();
-	}
-	g2d_mutex_unlock(para.mutex);
-
-	return 0;
+    g2d_mutex_lock(para.mutex);
+    if (para.opened)
+    {
+        g2d_clock_enable(&para);
+        g2d_bsp_open();
+    }
+    g2d_mutex_unlock(para.mutex);
+
+    return 0;
 }
+
 static void g2d_register_pm_dev_notify(void)
 {
-	register_pm_dev_notify(g2d_suspend, g2d_resume, NULL);
+    register_pm_dev_notify(g2d_suspend, g2d_resume, NULL);
 }
 #else
 static void g2d_register_pm_dev_notify(void)
@@ -506,277 +543,285 @@ static void g2d_register_pm_dev_notify(void)
 
 int g2d_probe(void)
 {
-	int ret = 0;
-	__g2d_info_t *info = NULL;
+    int ret = 0;
+    __g2d_info_t *info = NULL;
 
-	info = &para;
-	memset(info, 0, sizeof(__g2d_info_t));
-	info->io = SUNXI_G2D_START;
+    info = &para;
+    memset(info, 0, sizeof(__g2d_info_t));
+    info->io = SUNXI_G2D_START;
 
-	if (request_irq(SUNXI_IRQ_G2D, g2d_handle_irq, 0, "g2d", NULL))
+    if (request_irq(SUNXI_IRQ_G2D, g2d_handle_irq, 0, "g2d", NULL))
         {
-		G2D_ERR_MSG("g2d request irq error\n");
-		return -1;
+        G2D_ERR_MSG("g2d request irq error\n");
+        return -1;
         }
-	enable_irq(SUNXI_IRQ_G2D);
-
-	g2d_clk_init(info);
-	drv_g2d_init(info);
-	info->mutex = hal_sem_create(1);
-	global_lock = hal_sem_create(1);
-	if ((info->mutex == NULL) || (global_lock == NULL)) {
-		G2D_ERR_MSG("sysfs_create_file fail!\n");
-		ret = -1;
-	}
-
-	g2d_register_pm_dev_notify();
-
-	G2D_INFO_MSG("g2d probe finished\n");
-	return ret;
+    enable_irq(SUNXI_IRQ_G2D);
+
+    g2d_clk_init(info);
+    drv_g2d_init(info);
+    info->mutex = hal_sem_create(1);
+    global_lock = hal_sem_create(1);
+    if ((info->mutex == NULL) || (global_lock == NULL))
+    {
+        G2D_ERR_MSG("sysfs_create_file fail!\n");
+        ret = -1;
+    }
+
+    g2d_register_pm_dev_notify();
+
+    G2D_INFO_MSG("g2d probe finished\n");
+    return ret;
 }
 
 static int g2d_remove(void)
 {
-	__g2d_info_t *info = &para;
+    __g2d_info_t *info = &para;
 
-	g2d_clk_exit(info);
-	g2d_mixer_idr_remove();
-	INFO("Driver unloaded succesfully.\n");
-	return 0;
+    g2d_clk_exit(info);
+    g2d_mixer_idr_remove();
+    INFO("Driver unloaded succesfully.\n");
+    return 0;
 }
 
 void g2d_ioctl_mutex_lock(void)
 {
 
-	g2d_mutex_lock(para.mutex);
+    g2d_mutex_lock(para.mutex);
 
 }
 
 
 void g2d_ioctl_mutex_unlock(void)
 {
-	g2d_mutex_unlock(para.mutex);
+    g2d_mutex_unlock(para.mutex);
 }
 
 int sunxi_g2d_open(void)
 {
-	g2d_mutex_lock(para.mutex);
-	g2d_clock_enable(&para);
-	para.user_cnt++;
-	if (para.user_cnt == 1) {
-		para.opened = true;
-		g2d_bsp_open();
-	}
-	g2d_mutex_unlock(para.mutex);
-	return 0;
+    g2d_mutex_lock(para.mutex);
+    g2d_clock_enable(&para);
+    para.user_cnt++;
+    if (para.user_cnt == 1)
+    {
+        para.opened = true;
+        g2d_bsp_open();
+    }
+    g2d_mutex_unlock(para.mutex);
+    return 0;
 
 }
 
 int sunxi_g2d_close(void)
 {
-	g2d_mutex_lock(para.mutex);
-	para.user_cnt--;
-	if (para.user_cnt == 0) {
-		para.opened = false;
-		g2d_bsp_close();
-	}
-	g2d_clock_disable(&para);
-	g2d_mutex_unlock(para.mutex);
-
-	g2d_mutex_lock(global_lock);
-	scan_order = G2D_SM_TDLR;
-	g2d_mutex_unlock(global_lock);
-
-	return 0;
+    g2d_mutex_lock(para.mutex);
+    para.user_cnt--;
+    if (para.user_cnt == 0)
+    {
+        para.opened = false;
+        g2d_bsp_close();
+    }
+    g2d_clock_disable(&para);
+    g2d_mutex_unlock(para.mutex);
+
+    g2d_mutex_lock(global_lock);
+    scan_order = G2D_SM_TDLR;
+    g2d_mutex_unlock(global_lock);
+
+    return 0;
 
 }
+
 int sunxi_g2d_control(int cmd, void *arg)
 {
-	int ret = -1;
-
-	g2d_ioctl_mutex_lock();
+    int ret = -1;
+
+    g2d_ioctl_mutex_lock();
+
+    g2d_ext_hd.finish_flag = 0;
+    switch (cmd)
+    {
+    case G2D_CMD_MIXER_TASK:
+        {
+
+        unsigned long *karg;
+        karg = arg;
+        ret  = mixer_task_process(&para, (struct mixer_para *)karg[0], karg[1]);
+        break;
+        }
+    case G2D_CMD_CREATE_TASK:
+        {
+
+        unsigned long *karg;
+        karg = arg;
+        ret = create_mixer_task(&para, (struct mixer_para *)karg[0], karg[1]);
+            break;
+        }
+    case G2D_CMD_TASK_APPLY:
+        {
+
+
+        unsigned long *karg;
+        karg = arg;
+
+
+        struct g2d_mixer_task *p_task = NULL;
+        p_task = g2d_mixer_get_inst((int)karg[0]);
+        ret = p_task->apply(p_task, (struct mixer_para *)karg[1]);
+
+
+
+            break;
+        }
+    case G2D_CMD_TASK_DESTROY:
+        {
 
-	g2d_ext_hd.finish_flag = 0;
-	switch (cmd) {
-	case G2D_CMD_MIXER_TASK:
-		{
+            struct g2d_mixer_task *p_task = NULL;
+            p_task = g2d_mixer_get_inst((int)(unsigned long)arg);
+            ret = p_task->destory(p_task);
+            break;
+        }
+    case G2D_CMD_TASK_GET_PARA:
+        {
+
+            unsigned long *karg;
+            karg = arg;
+            struct g2d_mixer_task *p_task = NULL;
+
+            p_task = g2d_mixer_get_inst((int)karg[0]);
+            if(!p_task)
+            {
+                ret = -EFAULT;
+                goto err_noput;
+            }
+
+            karg[1] = (unsigned long)(p_task->p_para);
+            ret = 0;
+            break;
+        }
+    case G2D_CMD_BITBLT_H:
+        {
+        g2d_blt_h blit_para;
+
+
+        memcpy(&blit_para, arg, sizeof(g2d_blt_h));
+        if (blit_para.flag_h & 0xff00)
+        {
+            ret = g2d_blit_h(&blit_para);
+        }
+
+        else {
+            struct mixer_para mixer_blit_para;
+            memset(&mixer_blit_para, 0, sizeof(struct mixer_para));
+            memcpy(&mixer_blit_para.dst_image_h,
+                   &blit_para.dst_image_h, sizeof(g2d_image_enh));
+            memcpy(&mixer_blit_para.src_image_h,
+                   &blit_para.src_image_h, sizeof(g2d_image_enh));
+            mixer_blit_para.flag_h = blit_para.flag_h;
+            mixer_blit_para.op_flag = OP_BITBLT;
+            ret = mixer_task_process(&para, &mixer_blit_para, 1);
+
+        }
+
+
+        break;
+        }
+
+    case G2D_CMD_LBC_ROT:
+        {
+            g2d_lbc_rot lbc_para;
+            memcpy(&lbc_para, (g2d_lbc_rot *)arg, sizeof(g2d_lbc_rot));
+            ret = g2d_lbc_rot_set_para(&lbc_para);
+            break;
+        }
+
+    case G2D_CMD_BLD_H:{
+
+            g2d_bld bld_para;
+            struct mixer_para mixer_bld_para;
+
+
+
+            memcpy(&bld_para,  (g2d_bld *) arg, sizeof(g2d_bld));
+            memset(&mixer_bld_para, 0, sizeof(struct mixer_para));
+            memcpy(&mixer_bld_para.dst_image_h,
+                   &bld_para.dst_image, sizeof(g2d_image_enh));
+            memcpy(&mixer_bld_para.src_image_h,
+                   &bld_para.src_image[0], sizeof(g2d_image_enh));
+            /* ptn use as src  */
+            memcpy(&mixer_bld_para.ptn_image_h,
+                   &bld_para.src_image[1], sizeof(g2d_image_enh));
+            memcpy(&mixer_bld_para.ck_para, &bld_para.ck_para,
+                   sizeof(g2d_ck));
+            mixer_bld_para.bld_cmd = bld_para.bld_cmd;
+            mixer_bld_para.op_flag = OP_BLEND;
+
+            ret  = mixer_task_process(&para, &mixer_bld_para, 1);
+
+            break;
+        }
+    case G2D_CMD_FILLRECT_H:{
+
+        g2d_fillrect_h fill_para;
+        struct mixer_para mixer_fill_para;
+
+
+        memcpy(&fill_para, (g2d_fillrect_h *) arg,  sizeof(g2d_fillrect_h));
+        memset(&mixer_fill_para, 0, sizeof(struct mixer_para));
+        memcpy(&mixer_fill_para.dst_image_h,
+               &fill_para.dst_image_h, sizeof(g2d_image_enh));
+        mixer_fill_para.op_flag = OP_FILLRECT;
+
+        ret  = mixer_task_process(&para, &mixer_fill_para, 1);
 
-		unsigned long *karg;
-		karg = arg;
-		ret  = mixer_task_process(&para, (struct mixer_para *)karg[0], karg[1]);
-		break;
-		}
-	case G2D_CMD_CREATE_TASK:
-		{
-
-		unsigned long *karg;
-		karg = arg;
-		ret = create_mixer_task(&para, (struct mixer_para *)karg[0], karg[1]);
-			break;
-		}
-	case G2D_CMD_TASK_APPLY:
-		{
-
-
-		unsigned long *karg;
-		karg = arg;
+        break;
+    }
+    case G2D_CMD_MASK_H:{
 
+            g2d_maskblt mask_para;
+            struct mixer_para mixer_mask_para;
 
-		struct g2d_mixer_task *p_task = NULL;
-		p_task = g2d_mixer_get_inst((int)karg[0]);
-		ret = p_task->apply(p_task, (struct mixer_para *)karg[1]);
-
+            memcpy(&mask_para, (g2d_maskblt *) arg, sizeof(g2d_maskblt));
+            memset(&mixer_mask_para, 0, sizeof(struct mixer_para));
+            memcpy(&mixer_mask_para.ptn_image_h,
+                   &mask_para.ptn_image_h, sizeof(g2d_image_enh));
+            memcpy(&mixer_mask_para.mask_image_h,
+                   &mask_para.mask_image_h, sizeof(g2d_image_enh));
+            memcpy(&mixer_mask_para.dst_image_h,
+                   &mask_para.dst_image_h, sizeof(g2d_image_enh));
+            memcpy(&mixer_mask_para.src_image_h,
+                   &mask_para.src_image_h, sizeof(g2d_image_enh));
+            mixer_mask_para.back_flag = mask_para.back_flag;
+            mixer_mask_para.fore_flag = mask_para.fore_flag;
+            mixer_mask_para.op_flag = OP_MASK;
 
+            ret  = mixer_task_process(&para, &mixer_mask_para, 1);
+
+            break;
+        }
+    case G2D_CMD_INVERTED_ORDER:
+        {
+            if ((enum g2d_scan_order)arg > G2D_SM_DTRL)
+            {
+                G2D_ERR_MSG("scan mode is err.\n");
+                ret = -EINVAL;
+                goto err_noput;
+            }
+
+            g2d_mutex_lock(global_lock);
+            scan_order = (enum g2d_scan_order)arg;
+            g2d_mutex_unlock(global_lock);
+            ret = 0;
+            break;
+        }
 
-			break;
-		}
-	case G2D_CMD_TASK_DESTROY:
-		{
-
-			struct g2d_mixer_task *p_task = NULL;
-			p_task = g2d_mixer_get_inst((int)(unsigned long)arg);
-			ret = p_task->destory(p_task);
-			break;
-		}
-	case G2D_CMD_TASK_GET_PARA:
-		{
-
-			unsigned long *karg;
-			karg = arg;
-			struct g2d_mixer_task *p_task = NULL;
-
-			p_task = g2d_mixer_get_inst((int)karg[0]);
-			if(!p_task) {
-				ret = -EFAULT;
-				goto err_noput;
-			}
-
-			karg[1] = (unsigned long)(p_task->p_para);
-			ret = 0;
-			break;
-		}
-	case G2D_CMD_BITBLT_H:
-		{
-		g2d_blt_h blit_para;
-
-
-		memcpy(&blit_para, arg, sizeof(g2d_blt_h));
-		if (blit_para.flag_h & 0xff00) {
-			ret = g2d_blit_h(&blit_para);
-		}
-
-		else {
-			struct mixer_para mixer_blit_para;
-			memset(&mixer_blit_para, 0, sizeof(struct mixer_para));
-			memcpy(&mixer_blit_para.dst_image_h,
-			       &blit_para.dst_image_h, sizeof(g2d_image_enh));
-			memcpy(&mixer_blit_para.src_image_h,
-			       &blit_para.src_image_h, sizeof(g2d_image_enh));
-			mixer_blit_para.flag_h = blit_para.flag_h;
-			mixer_blit_para.op_flag = OP_BITBLT;
-			ret = mixer_task_process(&para, &mixer_blit_para, 1);
-
-		}
-
-
-		break;
-		}
-
-	case G2D_CMD_LBC_ROT:
-		{
-			g2d_lbc_rot lbc_para;
-			memcpy(&lbc_para, (g2d_lbc_rot *)arg, sizeof(g2d_lbc_rot));
-			ret = g2d_lbc_rot_set_para(&lbc_para);
-			break;
-		}
-
-	case G2D_CMD_BLD_H:{
-
-			g2d_bld bld_para;
-			struct mixer_para mixer_bld_para;
-
-
-
-			memcpy(&bld_para,  (g2d_bld *) arg, sizeof(g2d_bld));
-			memset(&mixer_bld_para, 0, sizeof(struct mixer_para));
-			memcpy(&mixer_bld_para.dst_image_h,
-			       &bld_para.dst_image, sizeof(g2d_image_enh));
-			memcpy(&mixer_bld_para.src_image_h,
-			       &bld_para.src_image[0], sizeof(g2d_image_enh));
-			/* ptn use as src  */
-			memcpy(&mixer_bld_para.ptn_image_h,
-			       &bld_para.src_image[1], sizeof(g2d_image_enh));
-			memcpy(&mixer_bld_para.ck_para, &bld_para.ck_para,
-			       sizeof(g2d_ck));
-			mixer_bld_para.bld_cmd = bld_para.bld_cmd;
-			mixer_bld_para.op_flag = OP_BLEND;
-
-			ret  = mixer_task_process(&para, &mixer_bld_para, 1);
-
-			break;
-		}
-	case G2D_CMD_FILLRECT_H:{
-
-		g2d_fillrect_h fill_para;
-		struct mixer_para mixer_fill_para;
-
-
-		memcpy(&fill_para, (g2d_fillrect_h *) arg,  sizeof(g2d_fillrect_h));
-		memset(&mixer_fill_para, 0, sizeof(struct mixer_para));
-		memcpy(&mixer_fill_para.dst_image_h,
-		       &fill_para.dst_image_h, sizeof(g2d_image_enh));
-		mixer_fill_para.op_flag = OP_FILLRECT;
-
-		ret  = mixer_task_process(&para, &mixer_fill_para, 1);
-
-		break;
-	}
-	case G2D_CMD_MASK_H:{
-
-			g2d_maskblt mask_para;
-			struct mixer_para mixer_mask_para;
-
-			memcpy(&mask_para, (g2d_maskblt *) arg, sizeof(g2d_maskblt));
-			memset(&mixer_mask_para, 0, sizeof(struct mixer_para));
-			memcpy(&mixer_mask_para.ptn_image_h,
-			       &mask_para.ptn_image_h, sizeof(g2d_image_enh));
-			memcpy(&mixer_mask_para.mask_image_h,
-			       &mask_para.mask_image_h, sizeof(g2d_image_enh));
-			memcpy(&mixer_mask_para.dst_image_h,
-			       &mask_para.dst_image_h, sizeof(g2d_image_enh));
-			memcpy(&mixer_mask_para.src_image_h,
-			       &mask_para.src_image_h, sizeof(g2d_image_enh));
-			mixer_mask_para.back_flag = mask_para.back_flag;
-			mixer_mask_para.fore_flag = mask_para.fore_flag;
-			mixer_mask_para.op_flag = OP_MASK;
-
-			ret  = mixer_task_process(&para, &mixer_mask_para, 1);
-
-			break;
-		}
-	case G2D_CMD_INVERTED_ORDER:
-		{
-			if ((enum g2d_scan_order)arg > G2D_SM_DTRL) {
-				G2D_ERR_MSG("scan mode is err.\n");
-				ret = -EINVAL;
-				goto err_noput;
-			}
-
-			g2d_mutex_lock(global_lock);
-			scan_order = (enum g2d_scan_order)arg;
-			g2d_mutex_unlock(global_lock);
-			ret = 0;
-			break;
-		}
-
-	default:
-		goto err_noput;
-		break;
-	}
+    default:
+        goto err_noput;
+        break;
+    }
 
 err_noput:
-	g2d_ioctl_mutex_unlock();
+    g2d_ioctl_mutex_unlock();
 
-	return ret;
+    return ret;
 }
 

+ 1 - 1
bsp/allwinner/libraries/sunxi-hal/include/osal/hal_interrupt.h

@@ -8,7 +8,7 @@ extern "C"
 
 #include <stdint.h>
 #include <stddef.h>
-#include <interrupt.h>
+#include "../../../libos/include/interrupt.h"
 
 typedef enum hal_irqreturn {
     HAL_IRQ_OK      = (0 << 0),

+ 3 - 0
components/drivers/include/drivers/dev_serial_v2.h

@@ -333,6 +333,9 @@ struct rt_serial_device
 
     struct rt_spinlock spinlock;
 
+#ifdef RT_USING_SERIAL_BYPASS
+    struct rt_serial_bypass* bypass;
+#endif
     struct rt_device_notify rx_notify;
 };
 

+ 1 - 1
components/drivers/include/rtdevice.h

@@ -152,10 +152,10 @@ extern "C" {
 #include "drivers/dev_serial_v2.h"
 #else
 #include "drivers/dev_serial.h"
+#endif /* RT_USING_SERIAL_V2 */
 #ifdef RT_USING_SERIAL_BYPASS
 #include "drivers/serial_bypass.h"
 #endif /* RT_USING_SERIAL_BYPASS */
-#endif
 #endif /* RT_USING_SERIAL */
 
 #ifdef RT_USING_I2C

+ 21 - 1
components/drivers/serial/bypass.c

@@ -41,7 +41,11 @@ rt_err_t rt_serial_bypass_init(struct rt_serial_device* serial)
 {
     serial->bypass = rt_malloc(sizeof(struct rt_serial_bypass));
     rt_memset(serial->bypass, 0, sizeof(struct rt_serial_bypass));
+#ifdef RT_USING_SERIAL_V2
+    serial->bypass->pipe = rt_ringbuffer_create(serial->config.rx_bufsz);
+#else
     serial->bypass->pipe = rt_ringbuffer_create(serial->config.bufsz);
+#endif
     serial->bypass->mutex = rt_mutex_create("serial_bypass", RT_IPC_FLAG_FIFO);
 
     return RT_EOK;
@@ -140,6 +144,22 @@ static inline rt_err_t _bypass_getchar_form_serial_fifo(struct rt_serial_device*
     level = rt_spin_lock_irqsave(&(serial->spinlock));
 
     /* there's no data: */
+#ifdef RT_USING_SERIAL_V2
+    rt_size_t  ringbuf_date_stat;
+    ringbuf_date_stat = rt_ringbuffer_data_len(&rx_fifo->rb);
+    if(!ringbuf_date_stat)
+    {
+        /* no data, enable interrupt and break out */
+        rt_spin_unlock_irqrestore(&(serial->spinlock), level);
+        return -RT_EEMPTY;
+    }
+    if(!rt_ringbuffer_getchar(&rx_fifo->rb, (rt_uint8_t *)ch))
+    {
+        /* Failed to read data */
+        rt_spin_unlock_irqrestore(&(serial->spinlock), level);
+        return -RT_EOK;
+    }
+#else
     if ((rx_fifo->get_index == rx_fifo->put_index) && (rx_fifo->is_full == RT_FALSE))
     {
         /* no data, enable interrupt and break out */
@@ -156,7 +176,7 @@ static inline rt_err_t _bypass_getchar_form_serial_fifo(struct rt_serial_device*
     {
         rx_fifo->is_full = RT_FALSE;
     }
-
+#endif
     /* enable interrupt */
     rt_spin_unlock_irqrestore(&(serial->spinlock), level);