From 1bc334e0e4df9b9a0ee3f9d875237f09ee0d1c0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BB=98=E6=99=A8=E9=98=B3?= <690928667@qq.com> Date: Fri, 28 Jun 2024 10:20:56 +0000 Subject: [PATCH 1/3] =?UTF-8?q?update=20adapter/khdf/linux/platform/uart/u?= =?UTF-8?q?art=5Fadapter.c.=20Signed-off-by:=20=E4=BB=98=E6=99=A8=E9=98=B3?= =?UTF-8?q?=20<690928667@qq.com>?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 付晨阳 <690928667@qq.com> --- .../khdf/linux/platform/uart/uart_adapter.c | 57 ++++++++++++------- 1 file changed, 37 insertions(+), 20 deletions(-) diff --git a/adapter/khdf/linux/platform/uart/uart_adapter.c b/adapter/khdf/linux/platform/uart/uart_adapter.c index e8bac7820..60ef6253b 100644 --- a/adapter/khdf/linux/platform/uart/uart_adapter.c +++ b/adapter/khdf/linux/platform/uart/uart_adapter.c @@ -29,24 +29,21 @@ #include "securec.h" #include "uart_if.h" #include "uart_core.h" - -#define HDF_LOG_TAG hdf_uart_adapter -#define UART_NAME_LEN 20 -#define UART_PATHNAME_LEN (UART_NAME_LEN + 20) - -static char g_driverName[UART_NAME_LEN]; +#include "uart_adapter.h" static int32_t UartAdapterInit(struct UartHost *host) { char name[UART_PATHNAME_LEN] = {0}; struct file *fp = NULL; + struct UartPriv *uartpriv = NULL; mm_segment_t oldfs; if (host == NULL) { HDF_LOGE("UartAdapterInit: host is null!"); return HDF_ERR_INVALID_OBJECT; } - if (sprintf_s(name, UART_PATHNAME_LEN - 1, "/dev/%s%d", g_driverName, host->num) < 0) { + uartpriv = (struct UartPriv *)host->priv; + if (sprintf_s(name, UART_PATHNAME_LEN - 1, "/dev/%s%d", uartpriv->driverName, host->num) < 0) { return HDF_FAILURE; } oldfs = get_fs(); @@ -58,27 +55,29 @@ static int32_t UartAdapterInit(struct UartHost *host) return HDF_FAILURE; } set_fs(oldfs); - host->priv = fp; + uartpriv->fiLp = fp; return HDF_SUCCESS; } static int32_t UartAdapterDeInit(struct UartHost *host) { struct file *fp = NULL; + struct UartPriv *uartpriv = NULL; mm_segment_t oldfs; if (host == NULL) { HDF_LOGE("UartAdapterDeInit: host is null!"); return HDF_ERR_INVALID_OBJECT; } - fp = (struct file *)host->priv; + uartpriv = (struct UartPriv *)host->priv; + fp = uartpriv->fiLp; oldfs = get_fs(); set_fs(KERNEL_DS); if (!IS_ERR(fp) && fp) { filp_close(fp, NULL); } set_fs(oldfs); - host->priv = NULL; + uartpriv->fiLp = NULL; return HDF_SUCCESS; } @@ -87,6 +86,7 @@ static int32_t UartAdapterRead(struct UartHost *host, uint8_t *data, uint32_t si loff_t pos = 0; int ret; struct file *fp = NULL; + struct UartPriv *uartpriv; char *p = (char *)data; mm_segment_t oldfs; uint32_t tmp = 0; @@ -96,7 +96,8 @@ static int32_t UartAdapterRead(struct UartHost *host, uint8_t *data, uint32_t si return HDF_ERR_INVALID_OBJECT; } - fp = (struct file *)host->priv; + uartpriv = (struct UartPriv *)host->priv; + fp = uartpriv->fiLp; oldfs = get_fs(); set_fs(KERNEL_DS); while (size >= tmp) { @@ -116,6 +117,7 @@ static int32_t UartAdapterWrite(struct UartHost *host, uint8_t *data, uint32_t s loff_t pos = 0; int ret; struct file *fp = NULL; + struct UartPriv *uartpriv; char *p = (char *)data; mm_segment_t oldfs; @@ -124,7 +126,8 @@ static int32_t UartAdapterWrite(struct UartHost *host, uint8_t *data, uint32_t s return HDF_ERR_INVALID_OBJECT; } - fp = (struct file *)host->priv; + uartpriv = (struct UartPriv *)host->priv; + fp = uartpriv->fiLp; oldfs = get_fs(); set_fs(KERNEL_DS); ret = vfs_write(fp, p, size, &pos); @@ -210,12 +213,14 @@ static int32_t UartAdapterGetBaud(struct UartHost *host, uint32_t *baudRate) { struct termios termios; struct file *fp = NULL; + struct UartPriv *uartpriv; if (host == NULL) { HDF_LOGE("UartAdapterGetBaud: host is null!"); return HDF_ERR_INVALID_OBJECT; } - fp = (struct file *)host->priv; + uartpriv = (struct UartPriv *)host->priv; + fp = uartpriv->fiLp; if (baudRate == NULL) { HDF_LOGE("UartAdapterGetBaud: baudRate is null!"); return HDF_ERR_INVALID_PARAM; @@ -283,13 +288,15 @@ static int32_t UartAdapterSetBaud(struct UartHost *host, uint32_t baudRate) struct termios termios; struct serial_struct serial; struct file *fp = NULL; + struct UartPriv *uartpriv; int ret; if (host == NULL) { HDF_LOGE("UartAdapterSetBaud: host is null!"); return HDF_ERR_INVALID_OBJECT; } - fp = (struct file *)host->priv; + uartpriv = (struct UartPriv *)host->priv; + fp = uartpriv->fiLp; if (UartAdapterIoctlInner(fp, TCGETS, (unsigned long)&termios) < 0) { HDF_LOGE("UartAdapterSetBaud: tcgets fail!"); @@ -381,13 +388,15 @@ static int32_t UartAdapterGetAttribute(struct UartHost *host, struct UartAttribu { struct termios termios; struct file *fp = NULL; + struct UartPriv *uartpriv; int ret; if (host == NULL) { HDF_LOGE("UartAdapterGetAttribute: host is null!"); return HDF_ERR_INVALID_OBJECT; } - fp = (struct file *)host->priv; + uartpriv = (struct UartPriv *)host->priv; + fp = uartpriv->fiLp; if (attribute == NULL) { HDF_LOGE("UartAdapterGetAttribute: attribute is null!"); return HDF_ERR_INVALID_PARAM; @@ -409,13 +418,15 @@ static int32_t UartAdapterSetAttribute(struct UartHost *host, struct UartAttribu { struct termios termios; struct file *fp = NULL; + struct UartPriv *uartpriv; int ret; if (host == NULL) { HDF_LOGE("UartAdapterSetAttribute: host is null!"); return HDF_ERR_INVALID_OBJECT; } - fp = (struct file *)host->priv; + uartpriv = (struct UartPriv *)host->priv; + fp = uartpriv->fiLp; if (attribute == NULL) { HDF_LOGE("UartAdapterSetAttribute: attribute is null!"); return HDF_ERR_INVALID_PARAM; @@ -485,6 +496,7 @@ static int32_t HdfUartInit(struct HdfDeviceObject *obj) struct DeviceResourceIface *iface = NULL; struct UartHost *host = NULL; const char *drName = NULL; + struct UartPriv *uartpriv; HDF_LOGI("HdfUartInit: entry!"); if (obj == NULL) { @@ -510,17 +522,21 @@ static int32_t HdfUartInit(struct HdfDeviceObject *obj) HDF_LOGE("HdfUartInit: read driver_name fail!"); return HDF_FAILURE; } - g_driverName[UART_NAME_LEN - 1] = 0; if (strlen(drName) > (UART_NAME_LEN - 1)) { HDF_LOGE("HdfUartInit: illegal length of drName!"); return HDF_FAILURE; } - ret = memcpy_s(g_driverName, UART_NAME_LEN, drName, strlen(drName)); - if (ret != EOK) { - HDF_LOGE("HdfUartInit: memcpy_s fail!"); + uartpriv = OsalMemCalloc(sizeof(struct UartPriv)); + if (uartpriv == NULL) { + HDF_LOGE("HdfUartInit: malloc UartPriv fail!"); + return HDF_FAILURE; + } + if (memcpy_s(uartpriv->driverName, UART_NAME_LEN, drName, strlen(drName)) < 0) { + HDF_LOGE("HdfUartInit: memcpy_s drName fail!"); return HDF_FAILURE; } host->method = &g_uartHostMethod; + host->priv = uartpriv; return HDF_SUCCESS; } @@ -534,6 +550,7 @@ static void HdfUartRelease(struct HdfDeviceObject *obj) return; } host = UartHostFromDevice(obj); + OsalMemFree(host->priv); UartHostDestroy(host); } -- Gitee From 7f2cd666047dbc3281067620e85de22b633f9e59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BB=98=E6=99=A8=E9=98=B3?= <690928667@qq.com> Date: Fri, 28 Jun 2024 10:22:18 +0000 Subject: [PATCH 2/3] =?UTF-8?q?update=20framework/support/platform/include?= =?UTF-8?q?/uart/uart=5Fcore.h.=20Signed-off-by:=20=E4=BB=98=E6=99=A8?= =?UTF-8?q?=E9=98=B3=20<690928667@qq.com>?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 付晨阳 <690928667@qq.com> --- framework/support/platform/include/uart/uart_core.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/framework/support/platform/include/uart/uart_core.h b/framework/support/platform/include/uart/uart_core.h index 6ff2d9e11..3017f1bcb 100644 --- a/framework/support/platform/include/uart/uart_core.h +++ b/framework/support/platform/include/uart/uart_core.h @@ -19,6 +19,17 @@ extern "C" { #endif /* __cplusplus */ + +#define HDF_LOG_TAG hdf_uart_adapter +#define UART_NAME_LEN 20 +#define UART_PATHNAME_LEN (UART_NAME_LEN + 20) +/** + * @brief UartPriv. + */ +typedef struct { + struct file *fileFp; + char driverName[UART_NAME_LEN]; +} UartPriv; /** * @brief uart device operations. */ -- Gitee From 554a3d85d2bbc6a5be29684b52880e0ba88936f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BB=98=E6=99=A8=E9=98=B3?= <690928667@qq.com> Date: Fri, 28 Jun 2024 10:23:43 +0000 Subject: [PATCH 3/3] =?UTF-8?q?update=20framework/support/platform/include?= =?UTF-8?q?/uart/uart=5Fcore.h.=20Signed-off-by:=20=E4=BB=98=E6=99=A8?= =?UTF-8?q?=E9=98=B3=20<690928667@qq.com>?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 付晨阳 <690928667@qq.com> --- framework/support/platform/include/uart/uart_core.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/support/platform/include/uart/uart_core.h b/framework/support/platform/include/uart/uart_core.h index 3017f1bcb..a6d44afd0 100644 --- a/framework/support/platform/include/uart/uart_core.h +++ b/framework/support/platform/include/uart/uart_core.h @@ -27,7 +27,7 @@ extern "C" { * @brief UartPriv. */ typedef struct { - struct file *fileFp; + struct file *fiLp; char driverName[UART_NAME_LEN]; } UartPriv; /** -- Gitee