• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  *
4  * HDF is dual licensed: you can use it either under the terms of
5  * the GPL, or the BSD license, at your option.
6  * See the LICENSE file in the root of this repository for complete details.
7  */
8 
9 #include "uart_core.h"
10 #include "uart_dispatch_sample.h"
11 #include "hdf_log.h"
12 #include "hdf_sbuf.h"
13 #include "uart_pl011_sample.h"
14 
15 #define HDF_LOG_TAG uart_dispatch_sample
16 
SampleDispatchWrite(struct UartDevice * device,struct HdfSBuf * txBuf)17 static int32_t SampleDispatchWrite(struct UartDevice *device, struct HdfSBuf *txBuf)
18 {
19     uint32_t idx;
20     uint32_t dataSize = 0;
21     const uint8_t *data = NULL;
22     struct UartRegisterMap *regMap = (struct UartRegisterMap *)device->resource.physBase;
23 
24     if (regMap == NULL) {
25         HDF_LOGE("%s: regMap is NULL", __func__);
26         return HDF_FAILURE;
27     }
28 
29     if (!HdfSbufReadBuffer(txBuf, (const void **)&data, &dataSize)) {
30         HDF_LOGE("%s: Failed to read sbuf", __func__);
31         return HDF_FAILURE;
32     }
33     regMap = (struct UartRegisterMap *)device->resource.physBase;
34     for (idx = 0; idx < dataSize; idx++) {
35         UartPl011Write(regMap, data[idx]);
36     }
37     return HDF_SUCCESS;
38 }
39 
SampleDispatch(struct HdfDeviceIoClient * client,int cmdId,struct HdfSBuf * data,struct HdfSBuf * reply)40 int32_t SampleDispatch(struct HdfDeviceIoClient *client, int cmdId, struct HdfSBuf *data, struct HdfSBuf *reply)
41 {
42     int32_t result = HDF_FAILURE;
43     if (client == NULL || client->device == NULL) {
44         HDF_LOGE("%s: client or client->device is NULL", __func__);
45         return result;
46     }
47     struct UartHost *uartHost = (struct UartHost *)client->device->service;
48     if (uartHost == NULL) {
49         HDF_LOGE("%s: uartHost is NULL", __func__);
50         return result;
51     }
52     struct UartDevice *uartDevice = (struct UartDevice *)uartHost->priv;
53     if (uartDevice == NULL) {
54         HDF_LOGE("%s: uartDevice is NULL", __func__);
55         return result;
56     }
57     switch (cmdId) {
58         case UART_WRITE: {
59             result = SampleDispatchWrite(uartDevice, data);
60             break;
61         }
62         default:
63             break;
64     }
65     return result;
66 }
67