diff --git a/sample/platform/uart/include/uart_dev_sample.h b/sample/platform/uart/include/uart_dev_sample.h index f4b218c799f8f99ab7b5340b11ff5c1aedafc170..bc267e18bf4756bca0bb6039d48c23f8fc8e6d52 100755 --- a/sample/platform/uart/include/uart_dev_sample.h +++ b/sample/platform/uart/include/uart_dev_sample.h @@ -30,8 +30,8 @@ extern "C" { /* baudrate config */ #define UART_CFG_BAUDRATE _IO(UART_IOC_MAGIC, 1) -void UartSampleAddDev(struct UartHost *host); -void UartSampleRemoveDev(struct UartHost *host); +void AddUartDevice(struct UartHost *host); +void RemoveUartDevice(struct UartHost *host); #ifdef __cplusplus #if __cplusplus diff --git a/sample/platform/uart/include/uart_dispatch_sample.h b/sample/platform/uart/include/uart_dispatch_sample.h index 21d4dd1ca0e66ff812e2be6b2a242c669187e530..9ecc0f898f813e8fc0e42bca30004e93aa17361b 100755 --- a/sample/platform/uart/include/uart_dispatch_sample.h +++ b/sample/platform/uart/include/uart_dispatch_sample.h @@ -22,6 +22,6 @@ enum { UART_WRITE = 1 }; -void SampleDispatchConstruct(struct UartDevice *device); +int32_t SampleDispatch(struct HdfDeviceIoClient *client, int cmdId, struct HdfSBuf *data, struct HdfSBuf *reply); #endif // UART_DISPATCH_SAMPLE_H diff --git a/sample/platform/uart/src/uart_dev_sample.c b/sample/platform/uart/src/uart_dev_sample.c index c9ab844b394871be4bff23263e5e4a3061bbdf3d..d301971814eaa1e3476d0e86c52feea6ca542f06 100755 --- a/sample/platform/uart/src/uart_dev_sample.c +++ b/sample/platform/uart/src/uart_dev_sample.c @@ -157,7 +157,7 @@ const struct file_operations_vfs g_uartSampleDevFops = { }; #define MAX_DEV_NAME_SIZE 32 -static void UartSampleAddRemoveDev(struct UartHost *host, bool add) +static void AddRemoveUartDev(struct UartHost *host, bool add) { int32_t ret; char *devName = NULL; @@ -193,12 +193,12 @@ static void UartSampleAddRemoveDev(struct UartHost *host, bool add) OsalMemFree(devName); } -void UartSampleAddDev(struct UartHost *host) +void AddUartDevice(struct UartHost *host) { - UartSampleAddRemoveDev(host, true); + AddRemoveUartDev(host, true); } -void UartSampleRemoveDev(struct UartHost *host) +void RemoveUartDevice(struct UartHost *host) { - UartSampleAddRemoveDev(host, false); + AddRemoveUartDev(host, false); } diff --git a/sample/platform/uart/src/uart_dispatch_sample.c b/sample/platform/uart/src/uart_dispatch_sample.c index e70a169a0933f4c89f40a77b74a73729e13cf7ec..82f34678b8afbec3b86551276e675a22f273cab9 100755 --- a/sample/platform/uart/src/uart_dispatch_sample.c +++ b/sample/platform/uart/src/uart_dispatch_sample.c @@ -45,14 +45,19 @@ static int32_t SampleDispatchWrite(struct UartDevice *device, struct HdfSBuf *tx return HDF_SUCCESS; } -static int32_t SampleDispatch(struct HdfDeviceIoClient *client, int cmdId, struct HdfSBuf *data, struct HdfSBuf *reply) +int32_t SampleDispatch(struct HdfDeviceIoClient *client, int cmdId, struct HdfSBuf *data, struct HdfSBuf *reply) { int32_t result = HDF_FAILURE; if (client == NULL || client->device == NULL) { HDF_LOGE("%s: client or client->device is NULL", __func__); return result; } - struct UartDevice *uartDevice = (struct UartDevice *)client->device->service; + struct UartHost *uartHost = (struct UartHost *)client->device->service; + if (uartHost == NULL) { + HDF_LOGE("%s: uartHost is NULL", __func__); + return result; + } + struct UartDevice *uartDevice = (struct UartDevice *)uartHost->priv; if (uartDevice == NULL) { HDF_LOGE("%s: uartDevice is NULL", __func__); return result; @@ -67,11 +72,3 @@ static int32_t SampleDispatch(struct HdfDeviceIoClient *client, int cmdId, struc } return result; } - -void SampleDispatchConstruct(struct UartDevice *device) -{ - struct IDeviceIoService *ioService = &device->ioService; - if (ioService != NULL) { - ioService->Dispatch = &SampleDispatch; - } -} diff --git a/sample/platform/uart/src/uart_sample.c b/sample/platform/uart/src/uart_sample.c index d329600dd8b6c1f2fef5e18fbe22dc52ddb4f8da..bd48b2829359a2cf0b17536734409645f49a3f83 100755 --- a/sample/platform/uart/src/uart_sample.c +++ b/sample/platform/uart/src/uart_sample.c @@ -31,44 +31,44 @@ static uint8_t g_fifoBuffer[UART_RX_FIFO_SIZE] = {0}; /* HdfDriverEntry method definitions */ -static int32_t HdfUartSampleBind(struct HdfDeviceObject *device); -static int32_t HdfUartSampleInit(struct HdfDeviceObject *device); -static void HdfUartSampleRelease(struct HdfDeviceObject *device); +static int32_t SampleUartDriverBind(struct HdfDeviceObject *device); +static int32_t SampleUartDriverInit(struct HdfDeviceObject *device); +static void SampleUartDriverRelease(struct HdfDeviceObject *device); /* HdfDriverEntry definitions */ -struct HdfDriverEntry g_hdfUartSample = { +struct HdfDriverEntry g_sampleUartDriverEntry = { .moduleVersion = 1, .moduleName = "UART_SAMPLE", - .Bind = HdfUartSampleBind, - .Init = HdfUartSampleInit, - .Release = HdfUartSampleRelease, + .Bind = SampleUartDriverBind, + .Init = SampleUartDriverInit, + .Release = SampleUartDriverRelease, }; // Initialize HdfDriverEntry -HDF_INIT(g_hdfUartSample); +HDF_INIT(g_sampleUartDriverEntry); /* UartHostMethod method definitions */ -static int32_t SampleInit(struct UartHost *host); -static int32_t SampleDeinit(struct UartHost *host); -static int32_t SampleWrite(struct UartHost *host, uint8_t *data, uint32_t size); -static int32_t SampleSetBaud(struct UartHost *host, uint32_t baudRate); -static int32_t SampleGetBaud(struct UartHost *host, uint32_t *baudRate); +static int32_t SampleUartHostInit(struct UartHost *host); +static int32_t SampleUartHostDeinit(struct UartHost *host); +static int32_t SampleUartHostWrite(struct UartHost *host, uint8_t *data, uint32_t size); +static int32_t SampleUartHostSetBaud(struct UartHost *host, uint32_t baudRate); +static int32_t SampleUartHostGetBaud(struct UartHost *host, uint32_t *baudRate); /* UartHostMethod definitions */ -struct UartHostMethod g_uartSampleHostMethod = { - .Init = SampleInit, - .Deinit = SampleDeinit, +struct UartHostMethod g_sampleUartHostMethod = { + .Init = SampleUartHostInit, + .Deinit = SampleUartHostDeinit, .Read = NULL, - .Write = SampleWrite, - .SetBaud = SampleSetBaud, - .GetBaud = SampleGetBaud, + .Write = SampleUartHostWrite, + .SetBaud = SampleUartHostSetBaud, + .GetBaud = SampleUartHostGetBaud, .SetAttribute = NULL, .GetAttribute = NULL, .SetTransMode = NULL, }; /* UartHostMethod implementations */ -static int32_t SampleInit(struct UartHost *host) +static int32_t SampleUartHostInit(struct UartHost *host) { HDF_LOGI("%s: Enter", __func__); if (host == NULL) { @@ -78,7 +78,7 @@ static int32_t SampleInit(struct UartHost *host) return HDF_SUCCESS; } -static int32_t SampleDeinit(struct UartHost *host) +static int32_t SampleUartHostDeinit(struct UartHost *host) { HDF_LOGI("%s: Enter", __func__); if (host == NULL) { @@ -88,7 +88,7 @@ static int32_t SampleDeinit(struct UartHost *host) return HDF_SUCCESS; } -static int32_t SampleWrite(struct UartHost *host, uint8_t *data, uint32_t size) +static int32_t SampleUartHostWrite(struct UartHost *host, uint8_t *data, uint32_t size) { HDF_LOGI("%s: Enter", __func__); uint32_t idx; @@ -111,7 +111,7 @@ static int32_t SampleWrite(struct UartHost *host, uint8_t *data, uint32_t size) return HDF_SUCCESS; } -static int32_t SampleSetBaud(struct UartHost *host, uint32_t baudRate) +static int32_t SampleUartHostSetBaud(struct UartHost *host, uint32_t baudRate) { HDF_LOGI("%s: Enter", __func__); struct UartDevice *device = NULL; @@ -141,7 +141,7 @@ static int32_t SampleSetBaud(struct UartHost *host, uint32_t baudRate) return err; } -static int32_t SampleGetBaud(struct UartHost *host, uint32_t *baudRate) +static int32_t SampleUartHostGetBaud(struct UartHost *host, uint32_t *baudRate) { HDF_LOGI("%s: Enter", __func__); struct UartDevice *device = NULL; @@ -159,7 +159,7 @@ static int32_t SampleGetBaud(struct UartHost *host, uint32_t *baudRate) return HDF_SUCCESS; } -static int UartDeviceInit(struct UartDevice *device) +static int InitUartDevice(struct UartDevice *device) { UartPl011Error err; struct UartResource *resource = &device->resource; @@ -187,7 +187,7 @@ static int UartDeviceInit(struct UartDevice *device) return HDF_SUCCESS; } -static uint32_t UartDeviceGetResource( +static uint32_t GetUartDeviceResource( struct UartDevice *device, const struct DeviceResourceNode *resourceNode) { struct UartResource *resource = &device->resource; @@ -199,11 +199,11 @@ static uint32_t UartDeviceGetResource( } if (dri->GetUint32(resourceNode, "num", &resource->num, 0) != HDF_SUCCESS) { - HDF_LOGE("uart config read num fail"); + HDF_LOGE("uart config read num fail"); return HDF_FAILURE; } if (dri->GetUint32(resourceNode, "base", &resource->base, 0) != HDF_SUCCESS) { - HDF_LOGE("uart config read base fail"); + HDF_LOGE("uart config read base fail"); return HDF_FAILURE; } resource->physBase = (unsigned long)OsalIoRemap(resource->base, 0x48); @@ -216,29 +216,29 @@ static uint32_t UartDeviceGetResource( return HDF_FAILURE; } if (dri->GetUint32(resourceNode, "baudrate", &resource->baudrate, 0) != HDF_SUCCESS) { - HDF_LOGE("uart config read baudrate fail"); + HDF_LOGE("uart config read baudrate fail"); return HDF_FAILURE; } if (dri->GetUint32(resourceNode, "wlen", &resource->wlen, 0) != HDF_SUCCESS) { - HDF_LOGE("uart config read wlen fail"); + HDF_LOGE("uart config read wlen fail"); return HDF_FAILURE; } if (dri->GetUint32(resourceNode, "parity", &resource->parity, 0) != HDF_SUCCESS) { - HDF_LOGE("uart config read parity fail"); + HDF_LOGE("uart config read parity fail"); return HDF_FAILURE; } if (dri->GetUint32(resourceNode, "stopBit", &resource->stopBit, 0) != HDF_SUCCESS) { - HDF_LOGE("uart config read stopBit fail"); + HDF_LOGE("uart config read stopBit fail"); return HDF_FAILURE; } if (dri->GetUint32(resourceNode, "uartClk", &resource->uartClk, 0) != HDF_SUCCESS) { - HDF_LOGE("uart config read uartClk fail"); + HDF_LOGE("uart config read uartClk fail"); return HDF_FAILURE; } return HDF_SUCCESS; } -static int32_t SampleAttach(struct UartHost *host, struct HdfDeviceObject *device) +static int32_t AttachUartDevice(struct UartHost *host, struct HdfDeviceObject *device) { int32_t ret; struct UartDevice *uartDevice = NULL; @@ -251,20 +251,18 @@ static int32_t SampleAttach(struct UartHost *host, struct HdfDeviceObject *devic HDF_LOGE("%s: OsalMemCalloc uartDevice error", __func__); return HDF_ERR_MALLOC_FAIL; } - SampleDispatchConstruct(uartDevice); - device->service = &uartDevice->ioService; - ret = UartDeviceGetResource(uartDevice, device->property); + ret = GetUartDeviceResource(uartDevice, device->property); if (ret != HDF_SUCCESS) { (void)OsalMemFree(uartDevice); return HDF_FAILURE; } host->num = uartDevice->resource.num; host->priv = uartDevice; - UartSampleAddDev(host); - return UartDeviceInit(uartDevice); + AddUartDevice(host); + return InitUartDevice(uartDevice); } -static void UartDeviceDeinit(struct UartDevice *device) +static void DeinitUartDevice(struct UartDevice *device) { struct UartRegisterMap *regMap = (struct UartRegisterMap *)device->resource.physBase; /* wait for uart enter idle. */ @@ -275,7 +273,7 @@ static void UartDeviceDeinit(struct UartDevice *device) device->state = UART_DEVICE_UNINITIALIZED; } -static void SampleDetach(struct UartHost *host) +static void DetachUartDevice(struct UartHost *host) { struct UartDevice *uartDevice = NULL; @@ -284,22 +282,31 @@ static void SampleDetach(struct UartHost *host) return; } uartDevice = host->priv; - UartDeviceDeinit(uartDevice); + DeinitUartDevice(uartDevice); (void)OsalMemFree(uartDevice); host->priv = NULL; } /* HdfDriverEntry implementations */ -static int32_t HdfUartSampleBind(struct HdfDeviceObject *device) +static int32_t SampleUartDriverBind(struct HdfDeviceObject *device) { + struct UartHost *uartHost = NULL; + if (device == NULL) { return HDF_ERR_INVALID_OBJECT; } HDF_LOGI("Enter %s:", __func__); - return (UartHostCreate(device) == NULL) ? HDF_FAILURE : HDF_SUCCESS; + + uartHost = UartHostCreate(device); + if (uartHost == NULL) { + HDF_LOGE("%s: UartHostCreate failed", __func__); + return HDF_FAILURE; + } + uartHost->service.Dispatch = SampleDispatch; + return HDF_SUCCESS; } -static int32_t HdfUartSampleInit(struct HdfDeviceObject *device) +static int32_t SampleUartDriverInit(struct HdfDeviceObject *device) { int32_t ret; struct UartHost *host = NULL; @@ -314,16 +321,16 @@ static int32_t HdfUartSampleInit(struct HdfDeviceObject *device) HDF_LOGE("%s: host is NULL", __func__); return HDF_FAILURE; } - ret = SampleAttach(host, device); + ret = AttachUartDevice(host, device); if (ret != HDF_SUCCESS) { HDF_LOGE("%s: attach error", __func__); return HDF_FAILURE; } - host->method = &g_uartSampleHostMethod; + host->method = &g_sampleUartHostMethod; return ret; } -static void HdfUartSampleRelease(struct HdfDeviceObject *device) +static void SampleUartDriverRelease(struct HdfDeviceObject *device) { struct UartHost *host = NULL; HDF_LOGI("Enter %s:", __func__); @@ -338,7 +345,7 @@ static void HdfUartSampleRelease(struct HdfDeviceObject *device) return; } if (host->priv != NULL) { - SampleDetach(host); + DetachUartDevice(host); } UartHostDestroy(host); }