feat: add user interface for gpio and rtc.

Signed-off-by: jiaziyang <jiaziyang1@huawei.com>
This commit is contained in:
jiaziyang 2022-01-29 17:05:38 +08:00
parent b458bafc50
commit 8ee56c8aff
21 changed files with 2594 additions and 1051 deletions

View File

@ -75,6 +75,25 @@ struct RtcTime {
uint16_t millisecond; /**< Millisecond. The value ranges from 0 to 990, with a precision of 10 milliseconds. */
};
/**
* @brief Enumerates RTC I/O commands.
*
* @since 1.0
*/
enum RtcIoCmd {
RTC_IO_READTIME = 0, /**< Read time. */
RTC_IO_WRITETIME, /**< Write format-compliant time. */
RTC_IO_READALARM, /**< Read the RTC alarm time. */
RTC_IO_WRITEALARM, /**< Write the RTC alarm time. */
RTC_IO_REGISTERALARMCALLBACK, /**< Registers that will be invoked when an alarm is generated at the specified time. */
RTC_IO_ALARMINTERRUPTENABLE, /**< Enables or disables alarm interrupts. */
RTC_IO_GETFREQ, /**< Get the RTC external frequency. */
RTC_IO_SETFREQ, /**< Set the oscillation frequency of RTC external crystal. */
RTC_IO_RESET, /**< Reset the RTC device. */
RTC_IO_READREG, /**< Reads the configuration of a custom RTC register. */
RTC_IO_WRITEREG, /**< Writes the configuration of a custom RTC register. */
};
/**
* @brief Opens the RTC device to obtain its handle.
*

View File

@ -20,6 +20,10 @@ enum GpioIoCmd {
GPIO_IO_WRITE = 1,
GPIO_IO_GETDIR = 2,
GPIO_IO_SETDIR = 3,
GPIO_IO_SETIRQ = 4,
GPIO_IO_UNSETIRQ = 5,
GPIO_IO_ENABLEIRQ = 6,
GPIO_IO_DISABLEIRQ = 7,
};
#ifdef __cplusplus

View File

@ -44,7 +44,6 @@ struct RtcMethod {
int32_t (*WriteReg)(struct RtcHost *host, uint8_t usrDefIndex, uint8_t value);
};
int RtcSetHostMethod(struct RtcHost *host, struct RtcMethod *method);
struct RtcHost *RtcHostCreate(struct HdfDeviceObject *device);
void RtcHostDestroy(struct RtcHost *host);
@ -53,6 +52,30 @@ static inline struct RtcHost *RtcHostFromDevice(struct HdfDeviceObject *device)
return (device == NULL) ? NULL : (struct RtcHost *)device->service;
}
int32_t RtcHostReadTime(struct RtcHost *host, struct RtcTime *time);
int32_t RtcHostWriteTime(struct RtcHost *host, const struct RtcTime *time);
int32_t RtcHostReadAlarm(struct RtcHost *host, enum RtcAlarmIndex alarmIndex, struct RtcTime *time);
int32_t RtcHostWriteAlarm(struct RtcHost *host, enum RtcAlarmIndex alarmIndex, const struct RtcTime *time);
int32_t RtcHostRegisterAlarmCallback(struct RtcHost *host, enum RtcAlarmIndex alarmIndex, RtcAlarmCallback cb);
int32_t RtcHostAlarmInterruptEnable(struct RtcHost *host, enum RtcAlarmIndex alarmIndex, uint8_t enable);
int32_t RtcHostGetFreq(struct RtcHost *host, uint32_t *freq);
int32_t RtcHostSetFreq(struct RtcHost *host, uint32_t freq);
int32_t RtcHostReset(struct RtcHost *host);
int32_t RtcHostReadReg(struct RtcHost *host, uint8_t usrDefIndex, uint8_t *value);
int32_t RtcHostWriteReg(struct RtcHost *host, uint8_t usrDefIndex, uint8_t value);
int32_t RtcIoDispatch(struct HdfDeviceIoClient *client, int cmd, struct HdfSBuf *data, struct HdfSBuf *reply);
#ifdef __cplusplus
#if __cplusplus
}

View File

@ -7,243 +7,13 @@
*/
#include "gpio_if.h"
#ifdef __USER__
#include "gpio/gpio_service.h"
#include "hdf_io_service_if.h"
#include "platform_core.h"
#else
#include "devsvc_manager_clnt.h"
#include "gpio/gpio_core.h"
#endif
#include "hdf_base.h"
#define HDF_LOG_TAG gpio_if
#ifdef __USER__
static void *GpioManagerServiceGet(void)
{
static void *manager = NULL;
if (manager != NULL) {
return manager;
}
manager = (void *)HdfIoServiceBind("HDF_PLATFORM_GPIO_MANAGER");
if (manager == NULL) {
PLAT_LOGE("%s: failed to get gpio manager service!", __func__);
}
return manager;
}
int32_t GpioRead(uint16_t gpio, uint16_t *val)
{
int32_t ret;
struct HdfIoService *service = NULL;
struct HdfSBuf *data = NULL;
struct HdfSBuf *reply = NULL;
service = (struct HdfIoService *)GpioManagerServiceGet();
if (service == NULL) {
return HDF_PLT_ERR_DEV_GET;
}
data = HdfSbufObtainDefaultSize();
if (data == NULL) {
return HDF_ERR_MALLOC_FAIL;
}
reply = HdfSbufObtainDefaultSize();
if (reply == NULL) {
HdfSbufRecycle(data);
return HDF_ERR_MALLOC_FAIL;
}
if (!HdfSbufWriteUint16(data, (uint16_t)gpio)) {
PLAT_LOGE("%s: write gpio number failed!", __func__);
HdfSbufRecycle(data);
HdfSbufRecycle(reply);
return HDF_ERR_IO;
}
ret = service->dispatcher->Dispatch(&service->object, GPIO_IO_READ, data, reply);
if (ret != HDF_SUCCESS) {
PLAT_LOGE("%s: service call failed:%d", __func__, ret);
HdfSbufRecycle(data);
HdfSbufRecycle(reply);
return ret;
}
if (!HdfSbufReadUint16(reply, val)) {
PLAT_LOGE("%s: read sbuf failed", __func__);
HdfSbufRecycle(data);
HdfSbufRecycle(reply);
return HDF_ERR_IO;
}
HdfSbufRecycle(data);
HdfSbufRecycle(reply);
return HDF_SUCCESS;
}
int32_t GpioWrite(uint16_t gpio, uint16_t val)
{
int32_t ret;
struct HdfIoService *service = NULL;
struct HdfSBuf *data = NULL;
service = (struct HdfIoService *)GpioManagerServiceGet();
if (service == NULL) {
return HDF_PLT_ERR_DEV_GET;
}
data = HdfSbufObtainDefaultSize();
if (data == NULL) {
return HDF_ERR_MALLOC_FAIL;
}
if (!HdfSbufWriteUint16(data, (uint16_t)gpio)) {
PLAT_LOGE("%s: write gpio number failed!", __func__);
HdfSbufRecycle(data);
return HDF_ERR_IO;
}
if (!HdfSbufWriteUint16(data, (uint16_t)val)) {
PLAT_LOGE("%s: write gpio value failed!", __func__);
HdfSbufRecycle(data);
return HDF_ERR_IO;
}
ret = service->dispatcher->Dispatch(&service->object, GPIO_IO_WRITE, data, NULL);
if (ret != HDF_SUCCESS) {
PLAT_LOGE("%s: service call failed:%d", __func__, ret);
HdfSbufRecycle(data);
return ret;
}
HdfSbufRecycle(data);
return HDF_SUCCESS;
}
int32_t GpioGetDir(uint16_t gpio, uint16_t *dir)
{
int32_t ret;
struct HdfIoService *service = NULL;
struct HdfSBuf *data = NULL;
struct HdfSBuf *reply = NULL;
service = (struct HdfIoService *)GpioManagerServiceGet();
if (service == NULL) {
return HDF_PLT_ERR_DEV_GET;
}
data = HdfSbufObtainDefaultSize();
if (data == NULL) {
return HDF_ERR_MALLOC_FAIL;
}
reply = HdfSbufObtainDefaultSize();
if (reply == NULL) {
HdfSbufRecycle(data);
return HDF_ERR_MALLOC_FAIL;
}
if (!HdfSbufWriteUint16(data, (uint16_t)gpio)) {
PLAT_LOGE("%s: write gpio number failed!", __func__);
HdfSbufRecycle(data);
HdfSbufRecycle(reply);
return HDF_ERR_IO;
}
ret = service->dispatcher->Dispatch(&service->object, GPIO_IO_GETDIR, data, reply);
if (ret != HDF_SUCCESS) {
PLAT_LOGE("%s: service call failed:%d", __func__, ret);
HdfSbufRecycle(data);
HdfSbufRecycle(reply);
return ret;
}
if (!HdfSbufReadUint16(reply, dir)) {
PLAT_LOGE("%s: read sbuf failed", __func__);
HdfSbufRecycle(data);
HdfSbufRecycle(reply);
return HDF_ERR_IO;
}
HdfSbufRecycle(data);
HdfSbufRecycle(reply);
return HDF_SUCCESS;
}
int32_t GpioSetDir(uint16_t gpio, uint16_t dir)
{
int32_t ret;
struct HdfIoService *service = NULL;
struct HdfSBuf *data = NULL;
service = (struct HdfIoService *)GpioManagerServiceGet();
if (service == NULL) {
return HDF_PLT_ERR_DEV_GET;
}
data = HdfSbufObtainDefaultSize();
if (data == NULL) {
return HDF_ERR_MALLOC_FAIL;
}
if (!HdfSbufWriteUint16(data, (uint16_t)gpio)) {
PLAT_LOGE("%s: write gpio number failed!", __func__);
HdfSbufRecycle(data);
return HDF_ERR_IO;
}
if (!HdfSbufWriteUint16(data, (uint16_t)dir)) {
PLAT_LOGE("%s: write gpio value failed!", __func__);
HdfSbufRecycle(data);
return HDF_ERR_IO;
}
ret = service->dispatcher->Dispatch(&service->object, GPIO_IO_SETDIR, data, NULL);
if (ret != HDF_SUCCESS) {
PLAT_LOGE("%s: service call failed:%d", __func__, ret);
HdfSbufRecycle(data);
return ret;
}
HdfSbufRecycle(data);
return HDF_SUCCESS;
}
int32_t GpioSetIrq(uint16_t gpio, uint16_t mode, GpioIrqFunc func, void *arg)
{
(void)gpio;
(void)mode;
(void)func;
(void)arg;
return HDF_SUCCESS;
}
int32_t GpioUnsetIrq(uint16_t gpio, void *arg)
{
(void)gpio;
(void)arg;
return HDF_SUCCESS;
}
int32_t GpioEnableIrq(uint16_t gpio)
{
(void)gpio;
return HDF_SUCCESS;
}
int32_t GpioDisableIrq(uint16_t gpio)
{
(void)gpio;
return HDF_SUCCESS;
}
#else
int32_t GpioRead(uint16_t gpio, uint16_t *val)
{
int32_t ret;
@ -331,4 +101,3 @@ int32_t GpioDisableIrq(uint16_t gpio)
GpioCntlrPut(cntlr);
return ret;
}
#endif

View File

@ -0,0 +1,369 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
*
* HDF is dual licensed: you can use it either under the terms of
* the GPL, or the BSD license, at your option.
* See the LICENSE file in the root of this repository for complete details.
*/
#include "gpio_if.h"
#include "gpio/gpio_service.h"
#include "hdf_base.h"
#include "hdf_io_service_if.h"
#include "platform_core.h"
#define PLAT_LOG_TAG gpio_if_u
static void *GpioManagerServiceGet(void)
{
static void *manager = NULL;
if (manager != NULL) {
return manager;
}
manager = (void *)HdfIoServiceBind("HDF_PLATFORM_GPIO_MANAGER");
if (manager == NULL) {
HDF_LOGE("%s: fail to get gpio manager service!", __func__);
}
return manager;
}
int32_t GpioRead(uint16_t gpio, uint16_t *val)
{
int32_t ret;
struct HdfIoService *service = NULL;
struct HdfSBuf *data = NULL;
struct HdfSBuf *reply = NULL;
service = (struct HdfIoService *)GpioManagerServiceGet();
if (service == NULL || service->dispatcher == NULL || service->dispatcher->Dispatch == NULL) {
HDF_LOGE("%s: get gpio manager service fail!", __func__);
return HDF_PLT_ERR_DEV_GET;
}
data = HdfSbufObtainDefaultSize();
if (data == NULL) {
HDF_LOGE("%s: fail to obtain data", __func__);
return HDF_ERR_MALLOC_FAIL;
}
reply = HdfSbufObtainDefaultSize();
if (reply == NULL) {
HDF_LOGE("%s: fail to obtain reply", __func__);
HdfSbufRecycle(data);
return HDF_ERR_MALLOC_FAIL;
}
if (!HdfSbufWriteUint16(data, (uint16_t)gpio)) {
HDF_LOGE("%s: write gpio number fail!", __func__);
HdfSbufRecycle(data);
HdfSbufRecycle(reply);
return HDF_ERR_IO;
}
ret = service->dispatcher->Dispatch(&service->object, GPIO_IO_READ, data, reply);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: service call fail:%d", __func__, ret);
HdfSbufRecycle(data);
HdfSbufRecycle(reply);
return ret;
}
if (!HdfSbufReadUint16(reply, val)) {
HDF_LOGE("%s: read sbuf fail", __func__);
HdfSbufRecycle(data);
HdfSbufRecycle(reply);
return HDF_ERR_IO;
}
HdfSbufRecycle(data);
HdfSbufRecycle(reply);
return HDF_SUCCESS;
}
int32_t GpioWrite(uint16_t gpio, uint16_t val)
{
int32_t ret;
struct HdfIoService *service = NULL;
struct HdfSBuf *data = NULL;
service = (struct HdfIoService *)GpioManagerServiceGet();
if (service == NULL || service->dispatcher == NULL || service->dispatcher->Dispatch == NULL) {
HDF_LOGE("%s: get gpio manager service fail!", __func__);
return HDF_PLT_ERR_DEV_GET;
}
data = HdfSbufObtainDefaultSize();
if (data == NULL) {
HDF_LOGE("%s: fail to obtain data", __func__);
return HDF_ERR_MALLOC_FAIL;
}
if (!HdfSbufWriteUint16(data, (uint16_t)gpio)) {
HDF_LOGE("%s: write gpio number fail!", __func__);
HdfSbufRecycle(data);
return HDF_ERR_IO;
}
if (!HdfSbufWriteUint16(data, (uint16_t)val)) {
HDF_LOGE("%s: write gpio value fail!", __func__);
HdfSbufRecycle(data);
return HDF_ERR_IO;
}
ret = service->dispatcher->Dispatch(&service->object, GPIO_IO_WRITE, data, NULL);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: service call fail:%d", __func__, ret);
HdfSbufRecycle(data);
return ret;
}
HdfSbufRecycle(data);
return HDF_SUCCESS;
}
int32_t GpioGetDir(uint16_t gpio, uint16_t *dir)
{
int32_t ret;
struct HdfIoService *service = NULL;
struct HdfSBuf *data = NULL;
struct HdfSBuf *reply = NULL;
if (dir == NULL) {
HDF_LOGE("%s: dir is NULL", __func__);
return HDF_ERR_INVALID_OBJECT;
}
service = (struct HdfIoService *)GpioManagerServiceGet();
if (service == NULL || service->dispatcher == NULL || service->dispatcher->Dispatch == NULL) {
HDF_LOGE("%s: get gpio manager service fail!", __func__);
return HDF_PLT_ERR_DEV_GET;
}
data = HdfSbufObtainDefaultSize();
if (data == NULL) {
HDF_LOGE("%s: fail to obtain data", __func__);
return HDF_ERR_MALLOC_FAIL;
}
reply = HdfSbufObtainDefaultSize();
if (reply == NULL) {
HDF_LOGE("%s: fail to obtain reply", __func__);
HdfSbufRecycle(data);
return HDF_ERR_MALLOC_FAIL;
}
if (!HdfSbufWriteUint16(data, (uint16_t)gpio)) {
HDF_LOGE("%s: write gpio number fail!", __func__);
HdfSbufRecycle(data);
HdfSbufRecycle(reply);
return HDF_ERR_IO;
}
ret = service->dispatcher->Dispatch(&service->object, GPIO_IO_GETDIR, data, reply);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: service call fail:%d", __func__, ret);
HdfSbufRecycle(data);
HdfSbufRecycle(reply);
return ret;
}
if (!HdfSbufReadUint16(reply, dir)) {
HDF_LOGE("%s: read sbuf fail", __func__);
HdfSbufRecycle(data);
HdfSbufRecycle(reply);
return HDF_ERR_IO;
}
HdfSbufRecycle(data);
HdfSbufRecycle(reply);
return HDF_SUCCESS;
}
int32_t GpioSetDir(uint16_t gpio, uint16_t dir)
{
int32_t ret;
struct HdfIoService *service = NULL;
struct HdfSBuf *data = NULL;
service = (struct HdfIoService *)GpioManagerServiceGet();
if (service == NULL || service->dispatcher == NULL || service->dispatcher->Dispatch == NULL) {
HDF_LOGE("%s: get gpio manager service fail!", __func__);
return HDF_PLT_ERR_DEV_GET;
}
data = HdfSbufObtainDefaultSize();
if (data == NULL) {
HDF_LOGE("%s: fail to obtain data", __func__);
return HDF_ERR_MALLOC_FAIL;
}
if (!HdfSbufWriteUint16(data, (uint16_t)gpio)) {
HDF_LOGE("%s: write gpio number fail!", __func__);
HdfSbufRecycle(data);
return HDF_ERR_IO;
}
if (!HdfSbufWriteUint16(data, (uint16_t)dir)) {
HDF_LOGE("%s: write gpio value fail!", __func__);
HdfSbufRecycle(data);
return HDF_ERR_IO;
}
ret = service->dispatcher->Dispatch(&service->object, GPIO_IO_SETDIR, data, NULL);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: service call fail:%d", __func__, ret);
HdfSbufRecycle(data);
return ret;
}
HdfSbufRecycle(data);
return HDF_SUCCESS;
}
int32_t GpioSetIrq(uint16_t gpio, uint16_t mode, GpioIrqFunc func, void *arg)
{
int32_t ret;
struct HdfIoService *service = NULL;
struct HdfSBuf *data = NULL;
(void) func;
(void) arg;
service = (struct HdfIoService *)GpioManagerServiceGet();
if (service == NULL || service->dispatcher == NULL || service->dispatcher->Dispatch == NULL) {
HDF_LOGE("%s: get gpio manager service fail!", __func__);
return HDF_PLT_ERR_DEV_GET;
}
data = HdfSbufObtainDefaultSize();
if (data == NULL) {
HDF_LOGE("%s: fail to obtain data", __func__);
return HDF_ERR_MALLOC_FAIL;
}
if (!HdfSbufWriteUint16(data, gpio)) {
HDF_LOGE("%s: write gpio number fail!", __func__);
HdfSbufRecycle(data);
return HDF_ERR_IO;
}
if (!HdfSbufWriteUint16(data, mode)) {
HDF_LOGE("%s: write gpio mode fail!", __func__);
HdfSbufRecycle(data);
return HDF_ERR_IO;
}
ret = service->dispatcher->Dispatch(&service->object, GPIO_IO_SETIRQ, data, NULL);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: service call fail:%d", __func__, ret);
HdfSbufRecycle(data);
return ret;
}
HdfSbufRecycle(data);
return HDF_SUCCESS;
}
int32_t GpioUnsetIrq(uint16_t gpio, void *arg)
{
int32_t ret;
struct HdfIoService *service = NULL;
struct HdfSBuf *data = NULL;
(void) arg;
service = (struct HdfIoService *)GpioManagerServiceGet();
if (service == NULL || service->dispatcher == NULL || service->dispatcher->Dispatch == NULL) {
HDF_LOGE("%s: get gpio manager service fail!", __func__);
return HDF_PLT_ERR_DEV_GET;
}
data = HdfSbufObtainDefaultSize();
if (data == NULL) {
HDF_LOGE("%s: fail to obtain data", __func__);
return HDF_ERR_MALLOC_FAIL;
}
if (!HdfSbufWriteUint16(data, gpio)) {
HDF_LOGE("%s: write gpio number fail!", __func__);
HdfSbufRecycle(data);
return HDF_ERR_IO;
}
ret = service->dispatcher->Dispatch(&service->object, GPIO_IO_UNSETIRQ, data, NULL);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: service call fail:%d", __func__, ret);
HdfSbufRecycle(data);
return ret;
}
HdfSbufRecycle(data);
return HDF_SUCCESS;
}
int32_t GpioEnableIrq(uint16_t gpio)
{
int32_t ret;
struct HdfIoService *service = NULL;
struct HdfSBuf *data = NULL;
service = (struct HdfIoService *)GpioManagerServiceGet();
if (service == NULL || service->dispatcher == NULL || service->dispatcher->Dispatch == NULL) {
HDF_LOGE("%s: get gpio manager service fail!", __func__);
return HDF_PLT_ERR_DEV_GET;
}
data = HdfSbufObtainDefaultSize();
if (data == NULL) {
HDF_LOGE("%s: fail to obtain data", __func__);
return HDF_ERR_MALLOC_FAIL;
}
if (!HdfSbufWriteUint16(data, (uint16_t)gpio)) {
HDF_LOGE("%s: write gpio number fail!", __func__);
HdfSbufRecycle(data);
return HDF_ERR_IO;
}
ret = service->dispatcher->Dispatch(&service->object, GPIO_IO_ENABLEIRQ, data, NULL);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: service call fail:%d", __func__, ret);
HdfSbufRecycle(data);
return ret;
}
HdfSbufRecycle(data);
return HDF_SUCCESS;
}
int32_t GpioDisableIrq(uint16_t gpio)
{
int32_t ret;
struct HdfIoService *service = NULL;
struct HdfSBuf *data = NULL;
service = (struct HdfIoService *)GpioManagerServiceGet();
if (service == NULL || service->dispatcher == NULL || service->dispatcher->Dispatch == NULL) {
HDF_LOGE("%s: get gpio manager service fail!", __func__);
return HDF_PLT_ERR_DEV_GET;
}
data = HdfSbufObtainDefaultSize();
if (data == NULL) {
HDF_LOGE("%s: fail to obtain data", __func__);
return HDF_ERR_MALLOC_FAIL;
}
if (!HdfSbufWriteUint16(data, (uint16_t)gpio)) {
HDF_LOGE("%s: write gpio number fail!", __func__);
HdfSbufRecycle(data);
return HDF_ERR_IO;
}
ret = service->dispatcher->Dispatch(&service->object, GPIO_IO_DISABLEIRQ, data, NULL);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: service call fail:%d", __func__, ret);
HdfSbufRecycle(data);
return ret;
}
HdfSbufRecycle(data);
return HDF_SUCCESS;
}

View File

@ -21,22 +21,23 @@ static int32_t GpioServiceIoRead(struct HdfSBuf *data, struct HdfSBuf *reply)
uint16_t value;
if (data == NULL || reply == NULL) {
HDF_LOGE("%s: data or reply is NULL", __func__);
return HDF_ERR_INVALID_PARAM;
}
if (!HdfSbufReadUint16(data, &gpio)) {
PLAT_LOGE("%s: read gpio number failed", __func__);
HDF_LOGE("%s: read gpio number fail", __func__);
return HDF_ERR_IO;
}
ret = GpioRead(gpio, &value);
if (ret != HDF_SUCCESS) {
PLAT_LOGE("%s: read gpio failed:%d", __func__, ret);
HDF_LOGE("%s: read gpio fail:%d", __func__, ret);
return ret;
}
if (!HdfSbufWriteUint16(reply, value)) {
PLAT_LOGE("%s: write subf failed:%d", __func__, ret);
HDF_LOGE("%s: write subf fail:%d", __func__, ret);
return ret;
}
@ -50,22 +51,22 @@ static int32_t GpioServiceIoWrite(struct HdfSBuf *data, struct HdfSBuf *reply)
uint16_t value;
if (data == NULL || reply == NULL) {
return HDF_ERR_INVALID_PARAM;
HDF_LOGE("%s: data or reply is NULL", __func__);
}
if (!HdfSbufReadUint16(data, &gpio)) {
PLAT_LOGE("%s: read gpio number failed", __func__);
HDF_LOGE("%s: read gpio number fail", __func__);
return HDF_ERR_IO;
}
if (!HdfSbufReadUint16(data, &value)) {
PLAT_LOGE("%s: read gpio value failed", __func__);
HDF_LOGE("%s: read gpio value fail", __func__);
return HDF_ERR_IO;
}
ret = GpioWrite(gpio, value);
if (ret != HDF_SUCCESS) {
PLAT_LOGE("%s: write gpio failed:%d", __func__, ret);
HDF_LOGE("%s: write gpio fail:%d", __func__, ret);
return ret;
}
@ -79,22 +80,23 @@ static int32_t GpioServiceIoGetDir(struct HdfSBuf *data, struct HdfSBuf *reply)
uint16_t dir;
if (data == NULL || reply == NULL) {
HDF_LOGE("%s: data or reply is NULL", __func__);
return HDF_ERR_INVALID_PARAM;
}
if (!HdfSbufReadUint16(data, &gpio)) {
PLAT_LOGE("%s: read gpio number failed", __func__);
HDF_LOGE("%s: read gpio number fail", __func__);
return HDF_ERR_IO;
}
ret = GpioGetDir(gpio, &dir);
if (ret != HDF_SUCCESS) {
PLAT_LOGE("%s: get gpio dir failed:%d", __func__, ret);
HDF_LOGE("%s: get gpio dir fail:%d", __func__, ret);
return ret;
}
if (!HdfSbufWriteUint16(reply, dir)) {
PLAT_LOGE("%s: write subf failed:%d", __func__, ret);
HDF_LOGE("%s: write subf fail:%d", __func__, ret);
return ret;
}
@ -108,28 +110,121 @@ static int32_t GpioServiceIoSetDir(struct HdfSBuf *data, struct HdfSBuf *reply)
uint16_t dir;
if (data == NULL || reply == NULL) {
HDF_LOGE("%s: data or reply is NULL", __func__);
return HDF_ERR_INVALID_PARAM;
}
if (!HdfSbufReadUint16(data, &gpio)) {
PLAT_LOGE("%s: read gpio number failed", __func__);
HDF_LOGE("%s: read gpio number fail", __func__);
return HDF_ERR_IO;
}
if (!HdfSbufReadUint16(data, &dir)) {
PLAT_LOGE("%s: read gpio dir failed", __func__);
HDF_LOGE("%s: read gpio dir fail", __func__);
return HDF_ERR_IO;
}
ret = GpioSetDir(gpio, dir);
if (ret != HDF_SUCCESS) {
PLAT_LOGE("%s: set gpio dir failed:%d", __func__, ret);
HDF_LOGE("%s: set gpio dir fail:%d", __func__, ret);
return ret;
}
return ret;
}
static int32_t GpioServiceIoSetIrq(struct HdfSBuf *data, struct HdfSBuf *reply)
{
uint16_t gpio;
uint16_t mode;
if (data == NULL || reply == NULL) {
HDF_LOGE("%s: data or reply is NULL", __func__);
return HDF_ERR_INVALID_PARAM;
}
if (!HdfSbufReadUint16(data, &gpio)) {
HDF_LOGE("%s: read gpio fail", __func__);
return HDF_ERR_IO;
}
if (!HdfSbufReadUint16(data, &mode)) {
HDF_LOGE("%s: read gpio mode fail", __func__);
return HDF_ERR_IO;
}
return HDF_SUCCESS;
}
static int32_t GpioServiceIoUnsetIrq(struct HdfSBuf *data, struct HdfSBuf *reply)
{
uint16_t gpio;
(void)reply;
if (data == NULL) {
HDF_LOGE("%s: data is NULL", __func__);
return HDF_ERR_INVALID_PARAM;
}
if (!HdfSbufReadUint16(data, &gpio)) {
HDF_LOGE("%s: read gpio number fail", __func__);
return HDF_ERR_IO;
}
return HDF_SUCCESS;
}
static int32_t GpioServiceIoEnableIrq(struct HdfSBuf *data, struct HdfSBuf *reply)
{
int32_t ret;
uint16_t gpio;
(void)reply;
if (data == NULL) {
HDF_LOGE("%s: data is NULL", __func__);
return HDF_ERR_INVALID_PARAM;
}
if (!HdfSbufReadUint16(data, &gpio)) {
HDF_LOGE("%s: read gpio number fail", __func__);
return HDF_ERR_IO;
}
ret = GpioEnableIrq(gpio);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: enable gpio irq fail:%d", __func__, ret);
return ret;
}
return ret;
}
static int32_t GpioServiceIoDisableIrq(struct HdfSBuf *data, struct HdfSBuf *reply)
{
int32_t ret;
uint16_t gpio;
(void)reply;
if (data == NULL) {
HDF_LOGE("%s: data is NULL", __func__);
return HDF_ERR_INVALID_PARAM;
}
if (!HdfSbufReadUint16(data, &gpio)) {
HDF_LOGE("%s: read gpio number fail", __func__);
return HDF_ERR_IO;
}
ret = GpioDisableIrq(gpio);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: disable gpio irq fail:%d", __func__, ret);
return ret;
}
return ret;
}
static int32_t GpioServiceDispatch(struct HdfDeviceIoClient *client, int cmd,
struct HdfSBuf *data, struct HdfSBuf *reply)
{
@ -144,6 +239,14 @@ static int32_t GpioServiceDispatch(struct HdfDeviceIoClient *client, int cmd,
return GpioServiceIoGetDir(data, reply);
case GPIO_IO_SETDIR:
return GpioServiceIoSetDir(data, reply);
case GPIO_IO_SETIRQ:
return GpioServiceIoSetIrq(data, reply);
case GPIO_IO_UNSETIRQ:
return GpioServiceIoUnsetIrq(data, reply);
case GPIO_IO_ENABLEIRQ:
return GpioServiceIoEnableIrq(data, reply);
case GPIO_IO_DISABLEIRQ:
return GpioServiceIoDisableIrq(data, reply);
default:
ret = HDF_ERR_NOT_SUPPORT;
break;
@ -158,25 +261,25 @@ static int32_t GpioServiceBind(struct HdfDeviceObject *device)
PLAT_LOGI("GpioServiceBind: enter");
if (device == NULL) {
PLAT_LOGE("GpioServiceBind: device is NULL");
HDF_LOGE("GpioServiceBind: device is NULL");
return HDF_ERR_INVALID_OBJECT;
}
gpioMgr = GpioManagerGet();
if (gpioMgr == NULL) {
PLAT_LOGE("GpioServiceBind: get gpio manager failed");
HDF_LOGE("GpioServiceBind: get gpio manager fail");
return HDF_PLT_ERR_DEV_GET;
}
ret = PlatformDeviceCreateService(&gpioMgr->device, GpioServiceDispatch);
if (ret != HDF_SUCCESS) {
PLAT_LOGE("GpioServiceBind: create gpio service failed:%d", ret);
HDF_LOGE("GpioServiceBind: create gpio service fail:%d", ret);
return ret;
}
ret = PlatformDeviceBind(&gpioMgr->device, device);
if (ret != HDF_SUCCESS) {
PLAT_LOGE("GpioServiceBind: bind gpio device failed:%d", ret);
HDF_LOGE("GpioServiceBind: bind gpio device fail:%d", ret);
(void)PlatformDeviceDestroyService(&gpioMgr->device);
return ret;
}
@ -203,7 +306,7 @@ static void GpioServiceRelease(struct HdfDeviceObject *device)
gpioMgr = GpioManagerGet();
if (gpioMgr == NULL) {
PLAT_LOGE("GpioServiceBind: get gpio manager failed");
HDF_LOGE("GpioServiceBind: get gpio manager fail");
return;
}

View File

@ -9,17 +9,173 @@
#include "rtc_core.h"
#include "hdf_log.h"
#include "osal_mem.h"
#include "rtc_if.h"
#define HDF_LOG_TAG rtc_core
#define HDF_LOG_TAG rtc_core_c
int RtcSetHostMethod(struct RtcHost *host, struct RtcMethod *method)
int32_t RtcHostReadTime(struct RtcHost *host, struct RtcTime *time)
{
if (host == NULL || method == NULL) {
HDF_LOGE("RtcSetHostMethod: Invalid parameter");
return HDF_ERR_INVALID_PARAM;
if (host == NULL || time == NULL) {
HDF_LOGE("%s: host or time is NULL!", __func__);
return HDF_ERR_INVALID_OBJECT;
}
host->method = method;
return HDF_SUCCESS;
if (host->method == NULL || host->method->ReadTime == NULL) {
HDF_LOGE("%s: method or ReadTime is NULL", __func__);
return HDF_ERR_NOT_SUPPORT;
}
return host->method->ReadTime(host, time);
}
int32_t RtcHostWriteTime(struct RtcHost *host, const struct RtcTime *time)
{
if (host == NULL || time == NULL) {
HDF_LOGE("%s: host or time is NULL!", __func__);
return HDF_ERR_INVALID_OBJECT;
}
if (host->method == NULL || host->method->WriteTime == NULL) {
HDF_LOGE("%s: method or WriteTime is NULL", __func__);
return HDF_ERR_NOT_SUPPORT;
}
return host->method->WriteTime(host, time);
}
int32_t RtcHostReadAlarm(struct RtcHost *host, enum RtcAlarmIndex alarmIndex, struct RtcTime *time)
{
if (host == NULL || time == NULL) {
HDF_LOGE("%s: host is NULL!", __func__);
return HDF_ERR_INVALID_OBJECT;
}
if (host->method == NULL || host->method->ReadAlarm == NULL) {
HDF_LOGE("%s: method or ReadAlarm is NULL", __func__);
return HDF_ERR_NOT_SUPPORT;
}
return host->method->ReadAlarm(host, alarmIndex, time);
}
int32_t RtcHostWriteAlarm(struct RtcHost *host, enum RtcAlarmIndex alarmIndex, const struct RtcTime *time)
{
if (host == NULL || time == NULL) {
HDF_LOGE("%s: host is NULL!", __func__);
return HDF_ERR_INVALID_OBJECT;
}
if (host->method == NULL || host->method->WriteAlarm == NULL) {
HDF_LOGE("%s: method or WriteAlarm is NULL", __func__);
return HDF_ERR_NOT_SUPPORT;
}
return host->method->WriteAlarm(host, alarmIndex, time);
}
int32_t RtcHostRegisterAlarmCallback(struct RtcHost *host, enum RtcAlarmIndex alarmIndex, RtcAlarmCallback cb)
{
if (host == NULL || cb == NULL) {
HDF_LOGE("%s: host or cb is NULL!", __func__);
return HDF_ERR_INVALID_OBJECT;
}
if (host->method == NULL || host->method->RegisterAlarmCallback == NULL) {
HDF_LOGE("%s: method or RegisterAlarmCallback is NULL", __func__);
return HDF_ERR_NOT_SUPPORT;
}
return host->method->RegisterAlarmCallback(host, alarmIndex, cb);
}
int32_t RtcHostAlarmInterruptEnable(struct RtcHost *host, enum RtcAlarmIndex alarmIndex, uint8_t enable)
{
if (host == NULL) {
HDF_LOGE("%s: host is NULL!", __func__);
return HDF_ERR_INVALID_OBJECT;
}
if (host->method == NULL || host->method->AlarmInterruptEnable == NULL) {
HDF_LOGE("%s: method or AlarmInterruptEnable is NULL", __func__);
return HDF_ERR_NOT_SUPPORT;
}
return host->method->AlarmInterruptEnable(host, alarmIndex, enable);
}
int32_t RtcHostGetFreq(struct RtcHost *host, uint32_t *freq)
{
if (host == NULL || freq == NULL) {
HDF_LOGE("%s: host or freq is NULL!", __func__);
return HDF_ERR_INVALID_OBJECT;
}
if (host->method == NULL || host->method->GetFreq == NULL) {
HDF_LOGE("%s: method or GetFreq is NULL", __func__);
return HDF_ERR_NOT_SUPPORT;
}
return host->method->GetFreq(host, freq);
}
int32_t RtcHostSetFreq(struct RtcHost *host, uint32_t freq)
{
if (host == NULL) {
HDF_LOGE("%s: host is NULL!", __func__);
return HDF_ERR_INVALID_OBJECT;
}
if (host->method == NULL || host->method->SetFreq == NULL) {
HDF_LOGE("%s: method or SetFreq is NULL", __func__);
return HDF_ERR_NOT_SUPPORT;
}
return host->method->SetFreq(host, freq);
}
int32_t RtcHostReset(struct RtcHost *host)
{
if (host == NULL) {
HDF_LOGE("%s: host is NULL!", __func__);
return HDF_ERR_INVALID_OBJECT;
}
if (host->method == NULL || host->method->Reset == NULL) {
HDF_LOGE("%s: method or Reset is NULL", __func__);
return HDF_ERR_NOT_SUPPORT;
}
return host->method->Reset(host);
}
int32_t RtcHostReadReg(struct RtcHost *host, uint8_t usrDefIndex, uint8_t *value)
{
if (host == NULL || value == NULL) {
HDF_LOGE("%s: host or value is NULL!", __func__);
return HDF_ERR_INVALID_OBJECT;
}
if (host->method == NULL || host->method->ReadReg == NULL) {
HDF_LOGE("%s: method or ReadReg is NULL", __func__);
return HDF_ERR_NOT_SUPPORT;
}
return host->method->ReadReg(host, usrDefIndex, value);
}
int32_t RtcHostWriteReg(struct RtcHost *host, uint8_t usrDefIndex, uint8_t value)
{
if (host == NULL) {
HDF_LOGE("%s: host is NULL!", __func__);
return HDF_ERR_INVALID_OBJECT;
}
if (host->method == NULL || host->method->WriteReg == NULL) {
HDF_LOGE("%s: method or WriteReg is NULL", __func__);
return HDF_ERR_NOT_SUPPORT;
}
return host->method->WriteReg(host, usrDefIndex, value);
}
struct RtcHost *RtcHostCreate(struct HdfDeviceObject *device)
@ -27,16 +183,21 @@ struct RtcHost *RtcHostCreate(struct HdfDeviceObject *device)
struct RtcHost *host = NULL;
if (device == NULL) {
HDF_LOGE("RtcHostCreate: device NULL!");
HDF_LOGE("%s: device is NULL!", __func__);
return NULL;
}
host = (struct RtcHost *)OsalMemCalloc(sizeof(*host));
if (host == NULL) {
HDF_LOGE("RtcHostCreate: malloc host fail!");
HDF_LOGE("%s: malloc host fail!", __func__);
return NULL;
}
host->device = device;
device->service = &(host->service);
host->method = NULL;
host->data = NULL;
host->device->service->Dispatch = RtcIoDispatch;
return host;
}
@ -46,6 +207,7 @@ void RtcHostDestroy(struct RtcHost *host)
host->device = NULL;
host->method = NULL;
host->data = NULL;
OsalMemFree(host);
return;
}
}
OsalMemFree(host);
}

View File

@ -7,23 +7,25 @@
*/
#include "rtc_if.h"
#include "devsvc_manager_clnt.h"
#include "hdf_log.h"
#include "osal_mem.h"
#include "rtc_base.h"
#include "rtc_core.h"
#include "securec.h"
#define HDF_LOG_TAG rtc_if
static char *g_rtcServiceName = "HDF_PLATFORM_RTC";
#define HDF_LOG_TAG rtc_if_c
DevHandle RtcOpen()
{
struct RtcHost *host = NULL;
host = (struct RtcHost *)DevSvcManagerClntGetService(g_rtcServiceName);
host = (struct RtcHost *)DevSvcManagerClntGetService("HDF_PLATFORM_RTC");
if (host == NULL) {
HDF_LOGE("rtc get service name failed");
HDF_LOGE("rtc get service name fail");
return NULL;
}
return (DevHandle)host;
}
@ -34,179 +36,120 @@ void RtcClose(DevHandle handle)
int32_t RtcReadTime(DevHandle handle, struct RtcTime *time)
{
struct RtcHost *host = NULL;
if (handle == NULL) {
HDF_LOGE("RtcReadTime: handle is null");
if (handle == NULL || time == NULL) {
HDF_LOGE("%s: handle or time is null", __func__);
return HDF_ERR_INVALID_OBJECT;
}
host = (struct RtcHost *)handle;
if (host->method == NULL || host->method->ReadTime == NULL) {
return HDF_ERR_NOT_SUPPORT;
}
return host->method->ReadTime(host, time);
return RtcHostReadTime((struct RtcHost *)handle, time);
}
int32_t RtcWriteTime(DevHandle handle, const struct RtcTime *time)
{
struct RtcHost *host = NULL;
if (handle == NULL) {
HDF_LOGE("RtcWriteTime: handle is null");
if (handle == NULL || time == NULL) {
HDF_LOGE("%s: handle or time is null", __func__);
return HDF_ERR_INVALID_OBJECT;
}
if (RtcIsInvalid(time) == RTC_TRUE) {
HDF_LOGE("RtcWriteTime: time invalid");
HDF_LOGE("%s: time invalid", __func__);
return HDF_ERR_INVALID_PARAM;
}
host = (struct RtcHost *)handle;
if (host->method == NULL || host->method->WriteTime == NULL) {
return HDF_ERR_NOT_SUPPORT;
}
return host->method->WriteTime(host, time);
return RtcHostWriteTime((struct RtcHost *)handle, time);
}
int32_t RtcReadAlarm(DevHandle handle, enum RtcAlarmIndex alarmIndex, struct RtcTime *time)
{
struct RtcHost *host = NULL;
if (handle == NULL) {
HDF_LOGE("RtcReadAlarm: handle is null");
if (handle == NULL || time == NULL) {
HDF_LOGE("%s: handle or time is null", __func__);
return HDF_ERR_INVALID_OBJECT;
}
host = (struct RtcHost *)handle;
if (host->method == NULL || host->method->ReadAlarm == NULL) {
return HDF_ERR_NOT_SUPPORT;
}
return host->method->ReadAlarm(host, alarmIndex, time);
return RtcHostReadAlarm((struct RtcHost *)handle, alarmIndex, time);
}
int32_t RtcWriteAlarm(DevHandle handle, enum RtcAlarmIndex alarmIndex, const struct RtcTime *time)
{
struct RtcHost *host = NULL;
if (handle == NULL) {
HDF_LOGE("RtcWriteAlarm: handle is null");
if (handle == NULL || time == NULL) {
HDF_LOGE("%s: handle or time is null", __func__);
return HDF_ERR_INVALID_OBJECT;
}
if (RtcIsInvalid(time) == RTC_TRUE) {
HDF_LOGE("RtcWriteAlarm: time invalid");
HDF_LOGE("%s: time invalid", __func__);
return HDF_ERR_INVALID_PARAM;
}
host = (struct RtcHost *)handle;
if (host->method == NULL || host->method->WriteAlarm == NULL) {
return HDF_ERR_NOT_SUPPORT;
}
return host->method->WriteAlarm(host, alarmIndex, time);
return RtcHostWriteAlarm((struct RtcHost *)handle, alarmIndex, time);
}
int32_t RtcRegisterAlarmCallback(DevHandle handle, enum RtcAlarmIndex alarmIndex, RtcAlarmCallback cb)
{
struct RtcHost *host = NULL;
if (handle == NULL) {
HDF_LOGE("RtcRegisterAlarmCallback: handle is null");
if (handle == NULL || cb == NULL) {
HDF_LOGE("%s: handle or cb is null", __func__);
return HDF_ERR_INVALID_OBJECT;
}
host = (struct RtcHost *)handle;
if (host->method == NULL || host->method->RegisterAlarmCallback == NULL) {
return HDF_ERR_NOT_SUPPORT;
}
return host->method->RegisterAlarmCallback(host, alarmIndex, cb);
return RtcHostRegisterAlarmCallback((struct RtcHost *)handle, alarmIndex, cb);
}
int32_t RtcAlarmInterruptEnable(DevHandle handle, enum RtcAlarmIndex alarmIndex, uint8_t enable)
{
struct RtcHost *host = NULL;
if (handle == NULL) {
HDF_LOGE("RtcAlarmInterruptEnable: handle is null");
HDF_LOGE("%s: handle is null", __func__);
return HDF_ERR_INVALID_OBJECT;
}
host = (struct RtcHost *)handle;
if (host->method == NULL || host->method->AlarmInterruptEnable == NULL) {
return HDF_ERR_NOT_SUPPORT;
}
return host->method->AlarmInterruptEnable(host, alarmIndex, enable);
return RtcHostAlarmInterruptEnable((struct RtcHost *)handle, alarmIndex, enable);
}
int32_t RtcGetFreq(DevHandle handle, uint32_t *freq)
{
struct RtcHost *host = NULL;
if (handle == NULL) {
HDF_LOGE("RtcGetFreq: handle is null");
if (handle == NULL || freq == NULL) {
HDF_LOGE("%s: handle or freq is null", __func__);
return HDF_ERR_INVALID_OBJECT;
}
host = (struct RtcHost *)handle;
if (host->method == NULL || host->method->GetFreq == NULL) {
HDF_LOGE("RtcGetFreq: pointer null");
return HDF_ERR_NOT_SUPPORT;
}
return host->method->GetFreq(host, freq);
return RtcHostGetFreq((struct RtcHost *)handle, freq);
}
int32_t RtcSetFreq(DevHandle handle, uint32_t freq)
{
struct RtcHost *host = NULL;
if (handle == NULL) {
HDF_LOGE("RtcSetFreq: handle is null");
HDF_LOGE("%s: handle is null", __func__);
return HDF_ERR_INVALID_OBJECT;
}
host = (struct RtcHost *)handle;
if (host->method == NULL || host->method->SetFreq == NULL) {
return HDF_ERR_NOT_SUPPORT;
}
return host->method->SetFreq(host, freq);
return RtcHostSetFreq((struct RtcHost *)handle, freq);
}
int32_t RtcReset(DevHandle handle)
{
struct RtcHost *host = NULL;
if (handle == NULL) {
HDF_LOGE("RtcReset: handle is null");
HDF_LOGE("%s: handle is null", __func__);
return HDF_ERR_INVALID_OBJECT;
}
host = (struct RtcHost *)handle;
if (host->method == NULL || host->method->Reset == NULL) {
return HDF_ERR_NOT_SUPPORT;
}
return host->method->Reset(host);
return RtcHostReset((struct RtcHost *)handle);
}
int32_t RtcReadReg(DevHandle handle, uint8_t usrDefIndex, uint8_t *value)
{
struct RtcHost *host = NULL;
if (handle == NULL) {
HDF_LOGE("RtcReadReg: handle is null");
if (handle == NULL ||value == NULL) {
HDF_LOGE("%s: handle or value is null", __func__);
return HDF_ERR_INVALID_OBJECT;
}
host = (struct RtcHost *)handle;
if (host->method == NULL || host->method->ReadReg == NULL) {
return HDF_ERR_NOT_SUPPORT;
}
return host->method->ReadReg(host, usrDefIndex, value);
return RtcHostReadReg((struct RtcHost *)handle, usrDefIndex, value);
}
int32_t RtcWriteReg(DevHandle handle, uint8_t usrDefIndex, uint8_t value)
{
struct RtcHost *host = NULL;
if (handle == NULL) {
HDF_LOGE("RtcReadReg: handle is null");
HDF_LOGE("%s: handle is null", __func__);
return HDF_ERR_INVALID_OBJECT;
}
host = (struct RtcHost *)handle;
if (host->method == NULL || host->method->WriteReg == NULL) {
return HDF_ERR_NOT_SUPPORT;
}
return host->method->WriteReg(host, usrDefIndex, value);
}
return RtcHostWriteReg((struct RtcHost *)handle, usrDefIndex, value);
}

View File

@ -0,0 +1,549 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
*
* HDF is dual licensed: you can use it either under the terms of
* the GPL, or the BSD license, at your option.
* See the LICENSE file in the root of this repository for complete details.
*/
#include "rtc_if.h"
#include "hdf_log.h"
#include "hdf_io_service_if.h"
#include "hdf_sbuf.h"
#include "osal_mem.h"
#include "securec.h"
#define HDF_LOG_TAG rtc_if_u_c
static void RtcPutObjByPointer(const void *obj)
{
if (obj == NULL) {
return;
}
HdfIoServiceRecycle((struct HdfIoService *)obj);
};
DevHandle RtcOpen()
{
void *host = NULL;
host = HdfIoServiceBind("HDF_PLATFORM_RTC");
if (host == NULL) {
HDF_LOGE("%s: rtc service bind fail", __func__);
return NULL;
}
return (DevHandle)host;
}
void RtcClose(DevHandle handle)
{
struct RtcHost *host = NULL;
if (handle == NULL) {
HDF_LOGE("%s: handle is NULL", __func__);
return;
}
host = (struct RtcHost *)handle;
RtcPutObjByPointer(host);
}
int32_t RtcReadTime(DevHandle handle, struct RtcTime *time)
{
int32_t ret;
uint32_t len = 0;
struct RtcHost *host = NULL;
struct HdfSBuf *reply = NULL;
struct HdfIoService *service = NULL;
struct RtcTime *temp = NULL;
if(handle == NULL || time == NULL) {
HDF_LOGE("%s: handle or time is NULL.", __func__);
return HDF_ERR_INVALID_OBJECT;
}
host = (struct RtcHost *)handle;
reply = HdfSbufObtain(sizeof(*time) + sizeof(uint64_t));
if (reply == NULL) {
HDF_LOGE("%s: fail to obtain reply!", __func__);
return HDF_ERR_MALLOC_FAIL;
}
service = (struct HdfIoService *)host;
if (service == NULL || service->dispatcher == NULL || service->dispatcher->Dispatch == NULL) {
HDF_LOGE("%s: service is invalid", __func__);
ret = HDF_ERR_MALLOC_FAIL;
goto EXIT;
}
ret = service->dispatcher->Dispatch(&service->object, RTC_IO_READTIME, NULL, reply);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: fail, ret is %d", __func__, ret);
goto EXIT;
}
if (!HdfSbufReadBuffer(reply, (const void **)&temp, &len) || temp == NULL) {
HDF_LOGE("%s: read buffer fail", __func__);
ret = HDF_ERR_IO;
goto EXIT;
}
if (memcpy_s(time, sizeof(*time), temp, len) != EOK) {
HDF_LOGE("%s: memcpy time fail!", __func__);
ret = HDF_ERR_IO;
goto EXIT;
}
EXIT:
HdfSbufRecycle(reply);
return ret;
}
int32_t RtcWriteTime(DevHandle handle, const struct RtcTime *time)
{
int32_t ret;
struct RtcHost *host = NULL;
struct HdfSBuf *data = NULL;
struct HdfIoService *service = NULL;
if(handle == NULL || time == NULL) {
HDF_LOGE("%s: handle or time is NULL.", __func__);
return HDF_ERR_INVALID_OBJECT;
}
host = (struct RtcHost *)handle;
data = HdfSbufObtainDefaultSize();
if (data == NULL) {
HDF_LOGE("%s: fail to obtain data", __func__);
return HDF_ERR_MALLOC_FAIL;
}
if (!HdfSbufWriteBuffer(data, time, sizeof(*time))) {
HDF_LOGE("%s: write rtc time fail!", __func__);
HdfSbufRecycle(data);
return HDF_ERR_IO;
}
service = (struct HdfIoService *)host;
if (service == NULL || service->dispatcher == NULL || service->dispatcher->Dispatch == NULL) {
HDF_LOGE("%s: service is invalid", __func__);
HdfSbufRecycle(data);
return HDF_ERR_MALLOC_FAIL;
}
ret = service->dispatcher->Dispatch(&service->object, RTC_IO_WRITETIME, data, NULL);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: fail, ret is %d", __func__, ret);
HdfSbufRecycle(data);
return ret;
}
HdfSbufRecycle(data);
return HDF_SUCCESS;
}
int32_t RtcReadAlarm(DevHandle handle, enum RtcAlarmIndex alarmIndex, struct RtcTime *time)
{
int32_t ret;
uint32_t len = 0;
struct RtcHost *host = NULL;
struct HdfSBuf *data = NULL;
struct HdfSBuf *reply = NULL;
struct RtcTime *temp = NULL;
struct HdfIoService *service = NULL;
if(handle == NULL || time == NULL) {
HDF_LOGE("%s: handle or time is NULL.", __func__);
return HDF_ERR_INVALID_OBJECT;
}
host = (struct RtcHost *)handle;
data = HdfSbufObtainDefaultSize();
if (data == NULL) {
HDF_LOGE("%s: fail to obtain data", __func__);
return HDF_ERR_MALLOC_FAIL;
}
reply = HdfSbufObtain(sizeof(*time) + sizeof(uint64_t));
if (reply == NULL) {
HDF_LOGE("%s: fail to obtain reply!", __func__);
HdfSbufRecycle(data);
return HDF_ERR_MALLOC_FAIL;
}
if (!HdfSbufWriteUint32(data, (uint32_t)alarmIndex)) {
HDF_LOGE("%s: write rtc alarmIndex fail!", __func__);
ret = HDF_ERR_IO;
goto EXIT;
}
service = (struct HdfIoService *)host;
if (service == NULL || service->dispatcher == NULL || service->dispatcher->Dispatch == NULL) {
HDF_LOGE("%s: service is invalid", __func__);
ret = HDF_ERR_MALLOC_FAIL;
goto EXIT;
}
ret = service->dispatcher->Dispatch(&service->object, RTC_IO_READALARM, data, reply);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: fail, ret is %d", __func__, ret);
goto EXIT;
}
if (!HdfSbufReadBuffer(reply, (const void **)&temp, &len) || temp == NULL) {
HDF_LOGE("%s: read buffer fail", __func__);
ret = HDF_ERR_IO;
goto EXIT;
}
if (memcpy_s(time, sizeof(*time), temp, len) != EOK) {
HDF_LOGE("%s: memcpy time fail!", __func__);
ret = HDF_ERR_IO;
goto EXIT;
}
EXIT:
HdfSbufRecycle(data);
HdfSbufRecycle(reply);
return ret;
}
int32_t RtcWriteAlarm(DevHandle handle, enum RtcAlarmIndex alarmIndex, const struct RtcTime *time)
{
int32_t ret;
struct RtcHost *host = NULL;
struct HdfSBuf *data = NULL;
struct HdfIoService *service = NULL;
if(handle == NULL || time == NULL) {
HDF_LOGE("%s: handle or time is NULL.", __func__);
return HDF_ERR_INVALID_OBJECT;
}
host = (struct RtcHost *)handle;
data = HdfSbufObtainDefaultSize();
if (data == NULL) {
HDF_LOGE("%s: fail to obtain data", __func__);
return HDF_ERR_MALLOC_FAIL;
}
if (!HdfSbufWriteUint32(data, (uint32_t)alarmIndex)) {
HDF_LOGE("%s: write rtc time fail!", __func__);
HdfSbufRecycle(data);
return HDF_ERR_IO;
}
if (!HdfSbufWriteBuffer(data, time, sizeof(*time))) {
HDF_LOGE("%s: write rtc time fail!", __func__);
HdfSbufRecycle(data);
return HDF_ERR_IO;
}
service = (struct HdfIoService *)host;
if (service == NULL || service->dispatcher == NULL || service->dispatcher->Dispatch == NULL) {
HDF_LOGE("%s: service is invalid", __func__);
HdfSbufRecycle(data);
return HDF_ERR_MALLOC_FAIL;
}
ret = service->dispatcher->Dispatch(&service->object, RTC_IO_WRITEALARM, data, NULL);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: fail, ret is %d", __func__, ret);
HdfSbufRecycle(data);
return ret;
}
HdfSbufRecycle(data);
return HDF_SUCCESS;
}
int32_t RtcRegisterAlarmCallback(DevHandle handle, enum RtcAlarmIndex alarmIndex, RtcAlarmCallback cb)
{
(void)alarmIndex;
if(handle == NULL || cb == NULL) {
HDF_LOGE("%s: handle orcb is NULL.", __func__);
return HDF_ERR_INVALID_OBJECT;
}
return HDF_SUCCESS;
}
int32_t RtcAlarmInterruptEnable(DevHandle handle, enum RtcAlarmIndex alarmIndex, uint8_t enable)
{
int32_t ret;
struct RtcHost *host = NULL;
struct HdfSBuf *data = NULL;
struct HdfIoService *service = NULL;
if(handle == NULL) {
HDF_LOGE("%s: handle is NULL.", __func__);
return HDF_ERR_INVALID_OBJECT;
}
host = (struct RtcHost *)handle;
data = HdfSbufObtainDefaultSize();
if (data == NULL) {
HDF_LOGE("%s: fail to obtain data", __func__);
return HDF_ERR_MALLOC_FAIL;
}
if (!HdfSbufWriteUint32(data, (uint32_t)alarmIndex)) {
HDF_LOGE("%s: write rtc alarmIndex fail!", __func__);
HdfSbufRecycle(data);
return HDF_ERR_IO;
}
if (!HdfSbufWriteUint8(data, enable)) {
HDF_LOGE("%s: write rtc time fail!", __func__);
HdfSbufRecycle(data);
return HDF_ERR_IO;
}
service = (struct HdfIoService *)host;
if (service == NULL || service->dispatcher == NULL || service->dispatcher->Dispatch == NULL) {
HDF_LOGE("%s: service is invalid", __func__);
HdfSbufRecycle(data);
return HDF_ERR_MALLOC_FAIL;
}
ret = service->dispatcher->Dispatch(&service->object, RTC_IO_ALARMINTERRUPTENABLE, data, NULL);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: fail, ret is %d", __func__, ret);
HdfSbufRecycle(data);
return ret;
}
HdfSbufRecycle(data);
return HDF_SUCCESS;
}
int32_t RtcGetFreq(DevHandle handle, uint32_t *freq)
{
int32_t ret;
struct RtcHost *host = NULL;
struct HdfSBuf *reply = NULL;
struct HdfIoService *service = NULL;
if(handle == NULL || freq == NULL) {
HDF_LOGE("%s: handle or freq is NULL.", __func__);
return HDF_ERR_INVALID_OBJECT;
}
host = (struct RtcHost *)handle;
reply = HdfSbufObtain(sizeof(*freq) + sizeof(uint64_t));
if (reply == NULL) {
HDF_LOGE("%s: fail to obtain data", __func__);
return HDF_ERR_MALLOC_FAIL;
}
service = (struct HdfIoService *)host;
if (service == NULL || service->dispatcher == NULL || service->dispatcher->Dispatch == NULL) {
HDF_LOGE("%s: service is invalid", __func__);
ret = HDF_ERR_MALLOC_FAIL;
goto EXIT;
}
ret = service->dispatcher->Dispatch(&service->object, RTC_IO_GETFREQ, NULL, reply);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: fail, ret is %d", __func__, ret);
goto EXIT;
}
if (!HdfSbufReadUint32(reply, freq)) {
HDF_LOGE("%s: read buffer fail", __func__);
goto EXIT;
}
EXIT:
HdfSbufRecycle(reply);
return ret;
}
int32_t RtcSetFreq(DevHandle handle, uint32_t freq)
{
int32_t ret;
struct RtcHost *host = NULL;
struct HdfSBuf *data = NULL;
struct HdfIoService *service = NULL;
if(handle == NULL) {
HDF_LOGE("%s: handle is NULL.", __func__);
return HDF_ERR_INVALID_OBJECT;
}
host = (struct RtcHost *)handle;
data = HdfSbufObtainDefaultSize();
if (data == NULL) {
HDF_LOGE("%s: fail to obtain data", __func__);
return HDF_ERR_MALLOC_FAIL;
}
if (!HdfSbufWriteUint32(data, freq)) {
HDF_LOGE("%s: write freq fail", __func__);
HdfSbufRecycle(data);
return HDF_ERR_IO;
}
service = (struct HdfIoService *)host;
if (service == NULL || service->dispatcher == NULL || service->dispatcher->Dispatch == NULL) {
HDF_LOGE("%s: service is invalid", __func__);
HdfSbufRecycle(data);
return HDF_ERR_MALLOC_FAIL;
}
ret = service->dispatcher->Dispatch(&service->object, RTC_IO_SETFREQ, data, NULL);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: fail, ret is %d", __func__, ret);
HdfSbufRecycle(data);
return ret;
}
HdfSbufRecycle(data);
return HDF_SUCCESS;
}
int32_t RtcReset(DevHandle handle)
{
int32_t ret;
struct RtcHost *host = NULL;
struct HdfIoService *service = NULL;
if (handle == NULL) {
HDF_LOGE("%s: handle is NULL", __func__);
return HDF_ERR_INVALID_OBJECT;
}
host = (struct RtcHost *)handle;
service = (struct HdfIoService *)host;
if (service->dispatcher == NULL || service->dispatcher->Dispatch == NULL) {
HDF_LOGE("%s: service is invalid", __func__);
return HDF_ERR_INVALID_PARAM;
}
ret = service->dispatcher->Dispatch(&service->object, RTC_IO_RESET, NULL, NULL);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: rtc close error, ret %d", __func__, ret);
return ret;
}
return HDF_SUCCESS;
}
int32_t RtcReadReg(DevHandle handle, uint8_t usrDefIndex, uint8_t *value)
{
int32_t ret;
struct RtcHost *host = NULL;
struct HdfSBuf *data = NULL;
struct HdfSBuf *reply = NULL;
struct HdfIoService *service = NULL;
if(handle == NULL || value == NULL) {
HDF_LOGE("%s: handle or value is NULL.", __func__);
return HDF_ERR_INVALID_OBJECT;
}
host = (struct RtcHost *)handle;
data = HdfSbufObtainDefaultSize();
if (data == NULL) {
HDF_LOGE("%s: fail to obtain data", __func__);
return HDF_ERR_MALLOC_FAIL;
}
reply = HdfSbufObtain(sizeof(*value) + sizeof(uint64_t));
if (reply == NULL) {
HDF_LOGE("%s: fail to obtain reply!", __func__);
HdfSbufRecycle(data);
return HDF_ERR_MALLOC_FAIL;
}
if (!HdfSbufWriteUint8(data, usrDefIndex)) {
HDF_LOGE("%s: write usrDefIndex fail!", __func__);
ret = HDF_ERR_IO;
goto EXIT;
}
service = (struct HdfIoService *)host;
if (service == NULL || service->dispatcher == NULL || service->dispatcher->Dispatch == NULL) {
HDF_LOGE("%s: service is invalid", __func__);
ret = HDF_ERR_MALLOC_FAIL;
goto EXIT;
}
ret = service->dispatcher->Dispatch(&service->object, RTC_IO_READREG, data, reply);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: fail, ret is %d", __func__, ret);
goto EXIT;
}
if (!HdfSbufReadUint8(reply, value)) {
HDF_LOGE("%s: read value fail", __func__);
ret = HDF_ERR_IO;
goto EXIT;
}
EXIT:
HdfSbufRecycle(data);
HdfSbufRecycle(reply);
return ret;
}
int32_t RtcWriteReg(DevHandle handle, uint8_t usrDefIndex, uint8_t value)
{
int32_t ret;
struct RtcHost *host = NULL;
struct HdfSBuf *data = NULL;
struct HdfIoService *service = NULL;
if(handle == NULL) {
HDF_LOGE("%s: handle is NULL.", __func__);
return HDF_ERR_INVALID_OBJECT;
}
host = (struct RtcHost *)handle;
data = HdfSbufObtainDefaultSize();
if (data == NULL) {
HDF_LOGE("%s: fail to obtain data", __func__);
return HDF_ERR_MALLOC_FAIL;
}
if (!HdfSbufWriteUint8(data, usrDefIndex)) {
HDF_LOGE("%s: write rtc usrDefIndex fail!", __func__);
HdfSbufRecycle(data);
return HDF_ERR_IO;
}
if (!HdfSbufWriteUint8(data, value)) {
HDF_LOGE("%s: write rtc value fail!", __func__);
HdfSbufRecycle(data);
return HDF_ERR_IO;
}
service = (struct HdfIoService *)host;
if (service == NULL || service->dispatcher == NULL || service->dispatcher->Dispatch == NULL) {
HDF_LOGE("%s: service is invalid", __func__);
HdfSbufRecycle(data);
return HDF_ERR_MALLOC_FAIL;
}
ret = service->dispatcher->Dispatch(&service->object, RTC_IO_WRITEREG, data, NULL);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: fail, ret is %d", __func__, ret);
HdfSbufRecycle(data);
return ret;
}
HdfSbufRecycle(data);
return HDF_SUCCESS;
}

View File

@ -0,0 +1,287 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
*
* HDF is dual licensed: you can use it either under the terms of
* the GPL, or the BSD license, at your option.
* See the LICENSE file in the root of this repository for complete details.
*/
#include "hdf_log.h"
#include "hdf_device_desc.h"
#include "osal_mem.h"
#include "rtc_core.h"
#include "rtc_if.h"
#define HDF_LOG_TAG rtc_service_c
static int32_t RtcServiceIoReadTime(struct RtcHost *host, struct HdfSBuf *reply)
{
int32_t ret;
struct RtcTime time;
ret = RtcHostReadTime(host, &time);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: host is NULL!", __func__);
return ret;
}
if (!HdfSbufWriteBuffer(reply, &time, sizeof(time))) {
HDF_LOGE("%s: write buffer fail!", __func__);
return HDF_ERR_IO;
}
return HDF_SUCCESS;
}
static int32_t RtcServiceIoWriteTime(struct RtcHost *host, struct HdfSBuf *data)
{
int32_t ret;
uint32_t len;
struct RtcTime *time = NULL;
if (!HdfSbufReadBuffer(data, (const void **)&time, &len) || sizeof(*time) != len) {
HDF_LOGE("%s: read buffer fail!", __func__);
return HDF_ERR_IO;
}
ret = RtcHostWriteTime(host, time);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: write time fail!", __func__);
return ret;
}
return HDF_SUCCESS;
}
static int32_t RtcServiceIoReadAlarm(struct RtcHost *host, struct HdfSBuf *data, struct HdfSBuf *reply)
{
int32_t ret;
uint32_t alarmIndex = 0;
struct RtcTime time;
if (!HdfSbufReadUint32(data, &alarmIndex)) {
HDF_LOGE("%s: read rtc alarmIndex fail!", __func__);
return HDF_ERR_IO;
}
ret = RtcHostReadAlarm(host, (enum RtcAlarmIndex)alarmIndex, &time);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: host read alarm fail!", __func__);
return ret;
}
if (!HdfSbufWriteBuffer(reply, &time, sizeof(time))) {
HDF_LOGE("%s: write buffer fail!", __func__);
return HDF_ERR_IO;
}
return HDF_SUCCESS;
}
static int32_t RtcServiceIoWriteAlarm(struct RtcHost *host, struct HdfSBuf *data)
{
int32_t ret;
uint32_t len;
uint32_t alarmIndex = 0;
struct RtcTime *time = NULL;
if (!HdfSbufReadUint32(data, &alarmIndex)) {
HDF_LOGE("%s: read rtc alarmIndex fail!", __func__);
return HDF_ERR_IO;
}
if (!HdfSbufReadBuffer(data, (const void **)&time, &len) || sizeof(*time) != len) {
HDF_LOGE("%s: read buffer fail!", __func__);
return HDF_ERR_IO;
}
ret = RtcHostWriteAlarm(host, (enum RtcAlarmIndex)alarmIndex, time);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: write alarm fail!", __func__);
return ret;
}
return HDF_SUCCESS;
}
static int32_t RtcServiceIoRegisterAlarmCallback(struct RtcHost *host, struct HdfSBuf *data)
{
(void)host;
(void)data;
return HDF_SUCCESS;
}
static int32_t RtcServiceIoInterruptEnable(struct RtcHost *host, struct HdfSBuf *data)
{
int32_t ret;
uint32_t alarmIndex = 0;
uint8_t enable = 0;
if (!HdfSbufReadUint32(data, &alarmIndex)) {
HDF_LOGE("%s: read rtc alarmIndex fail!", __func__);
return HDF_ERR_IO;
}
if (!HdfSbufReadUint8(data, &enable)) {
HDF_LOGE("%s: read rtc enable fail!", __func__);
return HDF_ERR_IO;
}
ret = RtcHostAlarmInterruptEnable(host, (enum RtcAlarmIndex)alarmIndex, enable);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: host is NULL!", __func__);
return ret;
}
return HDF_SUCCESS;
}
static int32_t RtcServiceIoGetFreq(struct RtcHost *host, struct HdfSBuf *reply)
{
int32_t ret;
uint32_t freq;
ret = RtcHostGetFreq(host, &freq);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: get freq failde! ret :%d", __func__, ret);
return ret;
}
if (!HdfSbufWriteUint32(reply, freq)) {
HDF_LOGE("%s: write rtc freq fail!", __func__);
return HDF_ERR_IO;
}
return HDF_SUCCESS;
}
static int32_t RtcServiceIoSetFreq(struct RtcHost *host, struct HdfSBuf *data)
{
int32_t ret;
uint32_t freq = 0;
if (!HdfSbufReadUint32(data, &freq)) {
HDF_LOGE("%s: read freq fail", __func__);
return HDF_ERR_IO;
}
ret = RtcHostSetFreq(host, freq);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: set freq fail! ret :%d", __func__, ret);
return ret;
}
return HDF_SUCCESS;
}
static int32_t RtcServiceIoReset(struct RtcHost *host)
{
int32_t ret;
ret = RtcHostReset(host);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: host reset fail!", __func__);
return ret;
}
return HDF_SUCCESS;
}
static int32_t RtcServiceIoReadReg(struct RtcHost *host, struct HdfSBuf *data, struct HdfSBuf *reply)
{
int32_t ret;
uint8_t usrDefIndex;
uint8_t value = 0;
if (!HdfSbufReadUint8(data, &usrDefIndex)) {
HDF_LOGE("%s: read usrDefIndex fail!", __func__);
return HDF_ERR_IO;
}
ret = RtcHostReadReg(host, usrDefIndex, &value);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: read reg fail! ret :%d", __func__, ret);
return ret;
}
if (!HdfSbufWriteUint8(data, value)) {
HDF_LOGE("%s: write value fail!", __func__);
return HDF_ERR_IO;
}
return HDF_SUCCESS;
}
static int32_t RtcServiceIoWriteReg(struct RtcHost *host, struct HdfSBuf *data)
{
int32_t ret;
uint8_t usrDefIndex;
uint8_t value;
if (!HdfSbufReadUint8(data, &usrDefIndex)) {
HDF_LOGE("%s: read usrDefIndex fail!", __func__);
return HDF_ERR_IO;
}
if (!HdfSbufReadUint8(data, &value)) {
HDF_LOGE("%s: read usrDefIndex fail!", __func__);
return HDF_ERR_IO;
}
ret = RtcHostWriteReg(host, usrDefIndex, value);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: write reg fail! ret :%d", __func__, ret);
return ret;
}
return HDF_SUCCESS;
}
int32_t RtcIoDispatch(struct HdfDeviceIoClient *client, int cmd, struct HdfSBuf *data, struct HdfSBuf *reply)
{
struct RtcHost *host = NULL;
if (client == NULL) {
HDF_LOGE("%s: client is NULL", __func__);
return HDF_ERR_INVALID_OBJECT;
}
if (client->device == NULL) {
HDF_LOGE("%s: client->device is NULL", __func__);
return HDF_ERR_INVALID_OBJECT;
}
if (client->device->service == NULL) {
HDF_LOGE("%s: client->device->service is NULL", __func__);
return HDF_ERR_INVALID_OBJECT;
}
host = (struct RtcHost *)client->device->service;
switch (cmd) {
case RTC_IO_READTIME:
return RtcServiceIoReadTime(host, reply);
case RTC_IO_WRITETIME:
return RtcServiceIoWriteTime(host, data);
case RTC_IO_READALARM:
return RtcServiceIoReadAlarm(host, data, reply);
case RTC_IO_WRITEALARM:
return RtcServiceIoWriteAlarm(host, data);
case RTC_IO_REGISTERALARMCALLBACK:
return RtcServiceIoRegisterAlarmCallback(host, data);
case RTC_IO_ALARMINTERRUPTENABLE:
return RtcServiceIoInterruptEnable(host, data);
case RTC_IO_GETFREQ:
return RtcServiceIoGetFreq(host, reply);
case RTC_IO_SETFREQ:
return RtcServiceIoSetFreq(host, data);
case RTC_IO_RESET:
return RtcServiceIoReset(host);
case RTC_IO_READREG:
return RtcServiceIoReadReg(host, data, reply);
case RTC_IO_WRITEREG:
return RtcServiceIoWriteReg(host, data);
default:
return HDF_ERR_NOT_SUPPORT;
}
}

View File

@ -140,3 +140,14 @@ HWTEST_F(HdfLiteGpioTest, GpioTestReliability001, TestSize.Level1)
EXPECT_EQ(0, GpioTestExecute(GPIO_TEST_RELIABILITY));
printf("%s: exit!\n", __func__);
}
/**
* @tc.name: GpioIfPerformanceTest001
* @tc.desc: gpio user if performance test
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(HdfLiteGpioTest, GpioIfPerformanceTest001, TestSize.Level1)
{
EXPECT_EQ(0, GpioTestExecute(GPIO_TEST_PERFORMANCE));
}

View File

@ -15,32 +15,10 @@
#include <gtest/gtest.h>
#include "hdf_uhdf_test.h"
#include "hdf_io_service_if.h"
#include "rtc_test.h"
using namespace testing::ext;
// pal rtc test case number
enum HdfRtcTestCaseCmd {
RTC_INIT,
RTC_UNINIT,
RTC_WR_TIME,
RTC_WR_MAX_TIME,
RTC_WR_MIN_TIME,
RTC_WR_ALARM_TIME,
RTC_WR_ALARM_MAX_TIME,
RTC_WR_ALARM_MIN_TIME,
RTC_ALARM_ENABLE,
RTC_ALARM_IRQ,
RTC_REGISTER_CALLBACK,
RTC_REGISTER_CALLBACK_NULL,
RTC_WR_FREQ,
RTC_WR_MAX_FREQ,
RTC_WR_MIN_FREQ,
RTC_WR_USER_REG,
RTC_WR_USER_REG_MAX_INDEX,
RTC_WR_RELIABILITY,
RTC_FUNCTION_TEST,
};
class HdfRtcTest : public testing::Test {
public:
static void SetUpTestCase();
@ -52,15 +30,10 @@ public:
void HdfRtcTest::SetUpTestCase()
{
HdfTestOpenService();
struct HdfTestMsg msg = { TEST_PAL_RTC_TYPE, RTC_INIT, -1 };
HdfTestSendMsgToService(&msg);
}
void HdfRtcTest::TearDownTestCase()
{
struct HdfTestMsg msg = { TEST_PAL_RTC_TYPE, RTC_UNINIT, -1 };
HdfTestSendMsgToService(&msg);
HdfTestCloseService();
}
@ -80,8 +53,10 @@ void HdfRtcTest::TearDown()
*/
HWTEST_F(HdfRtcTest, testRtcReadWriteTime001, TestSize.Level1)
{
struct HdfTestMsg msg = { TEST_PAL_RTC_TYPE, RTC_WR_TIME, -1 };
struct HdfTestMsg msg = { TEST_PAL_RTC_TYPE, RTC_TEST_CMD_WR_TIME, -1 };
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
EXPECT_EQ(0, RtcTestExecute(RTC_TEST_CMD_WR_TIME));
}
/**
@ -92,8 +67,10 @@ HWTEST_F(HdfRtcTest, testRtcReadWriteTime001, TestSize.Level1)
*/
HWTEST_F(HdfRtcTest, testRtcReadWriteMaxTime001, TestSize.Level1)
{
struct HdfTestMsg msg = { TEST_PAL_RTC_TYPE, RTC_WR_MAX_TIME, -1 };
struct HdfTestMsg msg = { TEST_PAL_RTC_TYPE, RTC_TEST_CMD_WR_MAX_TIME, -1 };
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
EXPECT_EQ(0, RtcTestExecute(RTC_TEST_CMD_WR_MAX_TIME));
}
/**
@ -104,8 +81,10 @@ HWTEST_F(HdfRtcTest, testRtcReadWriteMaxTime001, TestSize.Level1)
*/
HWTEST_F(HdfRtcTest, testRtcReadWriteMinTime001, TestSize.Level1)
{
struct HdfTestMsg msg = { TEST_PAL_RTC_TYPE, RTC_WR_MIN_TIME, -1 };
struct HdfTestMsg msg = { TEST_PAL_RTC_TYPE, RTC_TEST_CMD_WR_MIN_TIME, -1 };
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
EXPECT_EQ(0, RtcTestExecute(RTC_TEST_CMD_WR_MIN_TIME));
}
/**
@ -116,8 +95,10 @@ HWTEST_F(HdfRtcTest, testRtcReadWriteMinTime001, TestSize.Level1)
*/
HWTEST_F(HdfRtcTest, testRtcReadWriteAlarmTime001, TestSize.Level1)
{
struct HdfTestMsg msg = { TEST_PAL_RTC_TYPE, RTC_WR_ALARM_TIME, -1 };
struct HdfTestMsg msg = { TEST_PAL_RTC_TYPE, RTC_TEST_CMD_WR_ALARM_TIME, -1 };
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
EXPECT_EQ(0, RtcTestExecute(RTC_TEST_CMD_WR_ALARM_TIME));
}
/**
@ -128,8 +109,10 @@ HWTEST_F(HdfRtcTest, testRtcReadWriteAlarmTime001, TestSize.Level1)
*/
HWTEST_F(HdfRtcTest, testRtcReadWriteAlarmMaxTime001, TestSize.Level1)
{
struct HdfTestMsg msg = { TEST_PAL_RTC_TYPE, RTC_WR_ALARM_MAX_TIME, -1 };
struct HdfTestMsg msg = { TEST_PAL_RTC_TYPE, RTC_TEST_CMD_WR_ALARM_MAX_TIME, -1 };
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
EXPECT_EQ(0, RtcTestExecute(RTC_TEST_CMD_WR_ALARM_MAX_TIME));
}
/**
* @tc.name: testRtcReadWriteAlarmMinTime001
@ -139,8 +122,10 @@ HWTEST_F(HdfRtcTest, testRtcReadWriteAlarmMaxTime001, TestSize.Level1)
*/
HWTEST_F(HdfRtcTest, testRtcReadWriteAlarmMinTime001, TestSize.Level1)
{
struct HdfTestMsg msg = { TEST_PAL_RTC_TYPE, RTC_WR_ALARM_MIN_TIME, -1 };
struct HdfTestMsg msg = { TEST_PAL_RTC_TYPE, RTC_TEST_CMD_WR_ALARM_MIN_TIME, -1 };
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
EXPECT_EQ(0, RtcTestExecute(RTC_TEST_CMD_WR_ALARM_MIN_TIME));
}
#ifndef HDF_LITEOS_TEST
@ -152,22 +137,27 @@ HWTEST_F(HdfRtcTest, testRtcReadWriteAlarmMinTime001, TestSize.Level1)
*/
HWTEST_F(HdfRtcTest, testRtcAlarmEnable001, TestSize.Level1)
{
struct HdfTestMsg msg = { TEST_PAL_RTC_TYPE, RTC_ALARM_ENABLE, -1 };
struct HdfTestMsg msg = { TEST_PAL_RTC_TYPE, RTC_TEST_CMD_RTC_ALARM_ENABLE, -1 };
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
EXPECT_EQ(0, RtcTestExecute(RTC_TEST_CMD_RTC_ALARM_ENABLE));
}
#endif
#if defined(HDF_LITEOS_TEST)
/**
* @tc.name: testRtcAlarmIqr001
* @tc.name: testRtcAlarmIrq001
* @tc.desc: rtc function test
* @tc.type: FUNC
* @tc.require: AR000EKRKU
*/
HWTEST_F(HdfRtcTest, testRtcAlarmIqr001, TestSize.Level1)
HWTEST_F(HdfRtcTest, testRtcAlarmIrq001, TestSize.Level1)
{
struct HdfTestMsg msg = { TEST_PAL_RTC_TYPE, RTC_ALARM_IRQ, -1 };
struct HdfTestMsg msg = { TEST_PAL_RTC_TYPE, RTC_TEST_CMD_RTC_ALARM_IRQ, -1 };
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
EXPECT_EQ(0, RtcTestExecute(RTC_TEST_CMD_RTC_ALARM_IRQ));
}
/**
@ -178,8 +168,10 @@ HWTEST_F(HdfRtcTest, testRtcAlarmIqr001, TestSize.Level1)
*/
HWTEST_F(HdfRtcTest, testRtcRegCallback001, TestSize.Level1)
{
struct HdfTestMsg msg = { TEST_PAL_RTC_TYPE, RTC_REGISTER_CALLBACK, -1 };
struct HdfTestMsg msg = { TEST_PAL_RTC_TYPE, RTC_TEST_CMD_RTC_REGISTER_CALLBACK, -1 };
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
EXPECT_EQ(0, RtcTestExecute(RTC_TEST_CMD_RTC_REGISTER_CALLBACK));
}
/**
@ -190,8 +182,10 @@ HWTEST_F(HdfRtcTest, testRtcRegCallback001, TestSize.Level1)
*/
HWTEST_F(HdfRtcTest, testRtcRegCallbackNull001, TestSize.Level1)
{
struct HdfTestMsg msg = { TEST_PAL_RTC_TYPE, RTC_REGISTER_CALLBACK_NULL, -1 };
struct HdfTestMsg msg = { TEST_PAL_RTC_TYPE, RTC_TEST_CMD_RTC_REGISTER_CALLBACK_NULL, -1 };
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
EXPECT_EQ(0, RtcTestExecute(RTC_TEST_CMD_RTC_REGISTER_CALLBACK_NULL));
}
/**
@ -202,8 +196,10 @@ HWTEST_F(HdfRtcTest, testRtcRegCallbackNull001, TestSize.Level1)
*/
HWTEST_F(HdfRtcTest, testRtcFreq001, TestSize.Level1)
{
struct HdfTestMsg msg = { TEST_PAL_RTC_TYPE, RTC_WR_FREQ, -1 };
struct HdfTestMsg msg = { TEST_PAL_RTC_TYPE, RTC_TEST_CMD_RTC_WR_FREQ, -1 };
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
EXPECT_EQ(0, RtcTestExecute(RTC_TEST_CMD_RTC_WR_FREQ));
}
/**
@ -214,8 +210,10 @@ HWTEST_F(HdfRtcTest, testRtcFreq001, TestSize.Level1)
*/
HWTEST_F(HdfRtcTest, testRtcMaxFreq001, TestSize.Level1)
{
struct HdfTestMsg msg = { TEST_PAL_RTC_TYPE, RTC_WR_MAX_FREQ, -1 };
struct HdfTestMsg msg = { TEST_PAL_RTC_TYPE, RTC_TEST_CMD_RTC_WR_MAX_FREQ, -1 };
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
EXPECT_EQ(0, RtcTestExecute(RTC_TEST_CMD_RTC_WR_MAX_FREQ));
}
/**
@ -226,8 +224,10 @@ HWTEST_F(HdfRtcTest, testRtcMaxFreq001, TestSize.Level1)
*/
HWTEST_F(HdfRtcTest, testRtcMinFreq001, TestSize.Level1)
{
struct HdfTestMsg msg = { TEST_PAL_RTC_TYPE, RTC_WR_MIN_FREQ, -1 };
struct HdfTestMsg msg = { TEST_PAL_RTC_TYPE, RTC_TEST_CMD_RTC_WR_MIN_FREQ, -1 };
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
EXPECT_EQ(0, RtcTestExecute(RTC_TEST_CMD_RTC_WR_MIN_FREQ));
}
/**
@ -238,8 +238,10 @@ HWTEST_F(HdfRtcTest, testRtcMinFreq001, TestSize.Level1)
*/
HWTEST_F(HdfRtcTest, testRtcUserReg001, TestSize.Level1)
{
struct HdfTestMsg msg = { TEST_PAL_RTC_TYPE, RTC_WR_USER_REG, -1 };
struct HdfTestMsg msg = { TEST_PAL_RTC_TYPE, RTC_TEST_CMD_RTC_WR_USER_REG, -1 };
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
EXPECT_EQ(0, RtcTestExecute(RTC_TEST_CMD_RTC_WR_USER_REG));
}
/**
@ -250,8 +252,10 @@ HWTEST_F(HdfRtcTest, testRtcUserReg001, TestSize.Level1)
*/
HWTEST_F(HdfRtcTest, testRtcUserRegMaxIndex001, TestSize.Level1)
{
struct HdfTestMsg msg = { TEST_PAL_RTC_TYPE, RTC_WR_USER_REG_MAX_INDEX, -1 };
struct HdfTestMsg msg = { TEST_PAL_RTC_TYPE, RTC_TEST_CMD_RTC_WR_USER_REG_MAX_INDEX, -1 };
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
EXPECT_EQ(0, RtcTestExecute(RTC_TEST_CMD_RTC_WR_USER_REG_MAX_INDEX));
}
#endif
/**
@ -262,8 +266,10 @@ HWTEST_F(HdfRtcTest, testRtcUserRegMaxIndex001, TestSize.Level1)
*/
HWTEST_F(HdfRtcTest, testRtcReliability001, TestSize.Level1)
{
struct HdfTestMsg msg = { TEST_PAL_RTC_TYPE, RTC_WR_RELIABILITY, -1 };
struct HdfTestMsg msg = { TEST_PAL_RTC_TYPE, RTC_TEST_CMD_RTC_WR_RELIABILITY, -1 };
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
EXPECT_EQ(0, RtcTestExecute(RTC_TEST_CMD_RTC_WR_RELIABILITY));
}
#if defined(HDF_LITEOS_TEST)
@ -275,7 +281,9 @@ HWTEST_F(HdfRtcTest, testRtcReliability001, TestSize.Level1)
*/
HWTEST_F(HdfRtcTest, testRtcModule001, TestSize.Level1)
{
struct HdfTestMsg msg = { TEST_PAL_RTC_TYPE, RTC_FUNCTION_TEST, -1 };
struct HdfTestMsg msg = { TEST_PAL_RTC_TYPE, RTC_TEST_CMD_RTC_FUNCTION_TEST, -1 };
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
EXPECT_EQ(0, RtcTestExecute(RTC_TEST_CMD_RTC_FUNCTION_TEST));
}
#endif
#endif

View File

@ -131,7 +131,7 @@ HdfTestFuncList g_hdfTestFuncList[] = {
{ TEST_PAL_WDT_TYPE, HdfWatchdogTestEntry },
#endif
#if defined(LOSCFG_DRIVERS_HDF_PLATFORM_RTC) || defined(CONFIG_DRIVERS_HDF_PLATFORM_RTC)
{ TEST_PAL_RTC_TYPE, HdfRtcEntry },
{ TEST_PAL_RTC_TYPE, HdfRtcTestEntry },
#endif
#if defined(LOSCFG_DRIVERS_HDF_PLATFORM_MIPI_DSI) || defined(CONFIG_DRIVERS_HDF_PLATFORM_MIPI_DSI)
{ TEST_PAL_MIPI_DSI_TYPE, HdfMipiDsiEntry },

View File

@ -393,6 +393,33 @@ static int32_t GpioTestReliability(void)
return HDF_SUCCESS;
}
static int32_t GpioIfPerformanceTest(void)
{
#ifdef __LITEOS__
return HDF_SUCCESS;
#endif
uint16_t val;
uint64_t startMs;
uint64_t endMs;
uint64_t useTime; /*ms*/
struct GpioTester *tester = NULL;
tester = GpioTesterGet();
if (tester == NULL) {
HDF_LOGE("%s: get tester failed", __func__);
return HDF_ERR_INVALID_OBJECT;
}
startMs = OsalGetSysTimeMs();
GpioRead(tester->cfg.gpio, &val);
endMs = OsalGetSysTimeMs();
useTime = endMs - startMs;
HDF_LOGI("----->interface performance test:[start:%lld(ms) - end:%lld(ms) = %lld (ms)] < 1ms[%d]\r\n",
startMs, endMs, useTime, useTime < 1 ? true : false );
return HDF_SUCCESS;
}
struct GpioTestEntry {
int cmd;
int32_t (*func)(void);
@ -406,6 +433,7 @@ static struct GpioTestEntry g_entry[] = {
{ GPIO_TEST_IRQ_EDGE, GpioTestIrqEdge, "GpioTestIrqEdge" },
{ GPIO_TEST_IRQ_THREAD, GpioTestIrqThread, "GpioTestIrqThread" },
{ GPIO_TEST_RELIABILITY, GpioTestReliability, "GpioTestReliability" },
{ GPIO_TEST_PERFORMANCE, GpioIfPerformanceTest, "GpioIfPerformanceTest" },
};
int32_t GpioTestExecute(int cmd)

View File

@ -24,7 +24,8 @@ enum GpioTestCmd {
GPIO_TEST_IRQ_EDGE = 3,
GPIO_TEST_IRQ_THREAD = 4,
GPIO_TEST_RELIABILITY = 5,
GPIO_TEST_MAX = 6,
GPIO_TEST_PERFORMANCE = 6,
GPIO_TEST_MAX = 7,
};
struct GpioTestConfig {

View File

@ -0,0 +1,161 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
*
* HDF is dual licensed: you can use it either under the terms of
* the GPL, or the BSD license, at your option.
* See the LICENSE file in the root of this repository for complete details.
*/
#include "rtc_test.h"
#include "device_resource_if.h"
#include "hdf_base.h"
#include "hdf_device_desc.h"
#include "hdf_log.h"
#include "osal_time.h"
#include "rtc_base.h"
#include "rtc_if.h"
#define HDF_LOG_TAG hdf_rtc_driver_test_c
static struct RtcTestConfig g_config;
static int32_t RtcTestDispatch(struct HdfDeviceIoClient *client, int cmd, struct HdfSBuf *data, struct HdfSBuf *reply)
{
if (cmd == 0) {
if (reply == NULL) {
HDF_LOGE("%s: reply is null!", __func__);
return HDF_ERR_INVALID_PARAM;
}
if (!HdfSbufWriteBuffer(reply, &g_config, sizeof(g_config))) {
HDF_LOGE("%s: write reply failed", __func__);
return HDF_ERR_IO;
}
} else {
return HDF_ERR_NOT_SUPPORT;
}
return HDF_SUCCESS;
}
static int32_t RtcTestReadConfig(struct RtcTestConfig *config, const struct DeviceResourceNode *node)
{
int32_t ret;
struct DeviceResourceIface *drsOps = NULL;
drsOps = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
if (drsOps == NULL || drsOps->GetUint32 == NULL) {
HDF_LOGE("%s: invalid drs ops", __func__);
return HDF_FAILURE;
}
ret = drsOps->GetUint32(node, "time", &config->time, 0);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: read time failed", __func__);
return ret;
}
ret = drsOps->GetUint32(node, "maxYear", &config->maxYear, 0);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: read maxYear failed", __func__);
return ret;
}
ret = drsOps->GetUint32(node, "year", &config->year, 0);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: read year failed", __func__);
return ret;
}
ret = drsOps->GetUint32(node, "month", &config->month, 0);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: read month failed", __func__);
return ret;
}
ret = drsOps->GetUint32(node, "day", &config->day, 0);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: read day failed", __func__);
return ret;
}
ret = drsOps->GetUint32(node, "hour", &config->hour, 0);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: read hour failed", __func__);
return ret;
}
ret = drsOps->GetUint32(node, "minute", &config->minute, 0);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: read minute failed", __func__);
return ret;
}
ret = drsOps->GetUint32(node, "second", &config->second, 0);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: read second failed", __func__);
return ret;
}
ret = drsOps->GetUint32(node, "frequence", &config->frequence, 0);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: read frequence failed", __func__);
return ret;
}
ret = drsOps->GetUint32(node, "userValue", &config->userValue, 0);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: read userValue failed", __func__);
return ret;
}
ret = drsOps->GetUint32(node, "userMaxIndex", &config->userMaxIndex, 0);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: read userMaxIndex failed", __func__);
return ret;
}
ret = drsOps->GetUint32(node, "waitTimeSecond", &config->waitTimeSecond, 0);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: read waitTimeSecond failed", __func__);
return ret;
}
ret = drsOps->GetUint32(node, "writeWaitMillisecond", &config->writeWaitMillisecond, 0);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: read writeWaitMillisecond failed", __func__);
return ret;
}
return HDF_SUCCESS;
}
static int32_t RtcTestBind(struct HdfDeviceObject *device)
{
int32_t ret;
static struct IDeviceIoService service;
if (device == NULL || device->property == NULL) {
HDF_LOGE("%s: device or config is null!", __func__);
return HDF_ERR_IO;
}
ret = RtcTestReadConfig(&g_config, device->property);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: read config failed", __func__);
return ret;
}
service.Dispatch = RtcTestDispatch;
device->service = &service;
return HDF_SUCCESS;
}
static int32_t RtcTestInit(struct HdfDeviceObject *device)
{
(void)device;
return HDF_SUCCESS;
}
static void RtcTestRelease(struct HdfDeviceObject *device)
{
if (device != NULL) {
device->service = NULL;
}
return;
}
struct HdfDriverEntry g_rtcTestEntry = {
.moduleVersion = 1,
.Bind = RtcTestBind,
.Init = RtcTestInit,
.Release = RtcTestRelease,
.moduleName = "PLATFORM_RTC_TEST",
};
HDF_INIT(g_rtcTestEntry);

View File

@ -0,0 +1,667 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
*
* HDF is dual licensed: you can use it either under the terms of
* the GPL, or the BSD license, at your option.
* See the LICENSE file in the root of this repository for complete details.
*/
#include "rtc_test.h"
#include "hdf_base.h"
#include "hdf_io_service_if.h"
#include "hdf_log.h"
#include "osal_mem.h"
#include "osal_time.h"
#include "rtc_base.h"
#include "rtc_if.h"
#include "securec.h"
#define HDF_LOG_TAG rtc_test_c
static int32_t RtcTestGetConfig(struct RtcTestConfig *config)
{
int32_t ret;
struct HdfSBuf *reply = NULL;
struct HdfIoService *service = NULL;
const void *buf = NULL;
uint32_t len;
service = HdfIoServiceBind("RTC_TEST");
if (service == NULL) {
HDF_LOGE("%s: service RTC_TEST bind fail", __func__);
return HDF_ERR_NOT_SUPPORT;
}
reply = HdfSbufObtain(sizeof(*config) + sizeof(uint64_t));
if (reply == NULL) {
HDF_LOGE("%s: Failed to obtain reply", __func__);
HdfIoServiceRecycle(service);
return HDF_ERR_MALLOC_FAIL;
}
ret = service->dispatcher->Dispatch(&service->object, 0, NULL, reply);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: Remote dispatch fail", __func__);
HdfIoServiceRecycle(service);
HdfSbufRecycle(reply);
return ret;
}
if (!HdfSbufReadBuffer(reply, &buf, &len)) {
HDF_LOGE("%s: Read buf fail", __func__);
HdfIoServiceRecycle(service);
HdfSbufRecycle(reply);
return HDF_ERR_IO;
}
if (len != sizeof(*config)) {
HDF_LOGE("%s: Config size:%zu, read size:%u", __func__, sizeof(*config), len);
HdfIoServiceRecycle(service);
HdfSbufRecycle(reply);
return HDF_ERR_IO;
}
if (memcpy_s(config, sizeof(*config), buf, sizeof(*config)) != EOK) {
HDF_LOGE("%s: Memcpy buf fail", __func__);
HdfIoServiceRecycle(service);
HdfSbufRecycle(reply);
return HDF_ERR_IO;
}
HdfSbufRecycle(reply);
HdfIoServiceRecycle(service);
return HDF_SUCCESS;
}
struct RtcTester *RtcTesterGet(void)
{
int32_t ret;
static struct RtcTester tester;
ret = RtcTestGetConfig(&tester.config);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: read config fail:%d", __func__, ret);
return NULL;
}
tester.handle = RtcOpen();
if (tester.handle == NULL) {
HDF_LOGE("%s: open Rtc fail!", __func__);
return NULL;
}
return &tester;
}
static void RtcTesterPut(struct RtcTester *tester)
{
if (tester == NULL || tester->handle == NULL) {
HDF_LOGE("%s: rtc handle is null", __func__);
return;
}
RtcClose(tester->handle);
tester->handle = NULL;
}
static int8_t g_rtcIrqCallback = HDF_FAILURE;
int32_t RtcAlarmACallback(enum RtcAlarmIndex alarmIndex)
{
if (alarmIndex == RTC_ALARM_INDEX_A) {
HDF_LOGE("RtcAlarmACallback: alarm a callback success");
g_rtcIrqCallback = HDF_SUCCESS;
} else {
g_rtcIrqCallback = HDF_FAILURE;
}
return 0;
}
static int32_t IsSameRtcTestTime(const struct RtcTime *readTime, const struct RtcTime *writeTime)
{
if ((readTime->year != writeTime->year) || (readTime->month != writeTime->month) ||
(readTime->day != writeTime->day) || (readTime->weekday != writeTime->weekday) ||
(readTime->hour != writeTime->hour) || (readTime->minute != writeTime->minute) ||
(readTime->second < writeTime->second)) {
return HDF_FAILURE;
}
return HDF_SUCCESS;
}
static int32_t TestReadWriteTime(struct RtcTester *tester) {
int32_t ret;
struct RtcTime readTime = {0};
ret = RtcWriteTime(tester->handle, &tester->time);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: write time fail", __func__);
return ret;
}
OsalMSleep(tester->config.writeWaitMillisecond);
ret = RtcReadTime(tester->handle, &readTime);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: read time fail", __func__);
return ret;
}
ret = IsSameRtcTestTime(&readTime, &tester->time);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: different time", __func__);
return ret;
}
return HDF_SUCCESS;
}
static int32_t RtcReadWriteTimeTest(struct RtcTester *tester)
{
int32_t ret;
/* 2020-08-08 Saturday 09:08:08 .000 */
tester->time.year = tester->config.year;
tester->time.month = tester->config.month;
tester->time.day = tester->config.day;
tester->time.hour = tester->config.hour;
tester->time.minute = tester->config.minute;
tester->time.second = tester->config.second;
tester->time.millisecond = 0;
tester->time.weekday = RtcGetWeekDay(&tester->time);
ret = TestReadWriteTime(tester);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: test fail", __func__);
return HDF_FAILURE;
}
return HDF_SUCCESS;
}
static int32_t RtcReadWriteMaxTimeTest(struct RtcTester *tester)
{
int32_t ret;
tester->time.year = tester->config.year;
tester->time.month = tester->config.month + 1;
tester->time.day = RTC_GREAT_MONTH_DAY + 1;
tester->time.hour = RTC_DAY_HOURS;
tester->time.minute = RTC_MAX_MINUTE;
tester->time.second = RTC_MAX_SECOND;
tester->time.millisecond = RTC_MAX_MS;
tester->time.weekday = RtcGetWeekDay(&tester->time);
ret = TestReadWriteTime(tester);
if (ret == HDF_SUCCESS) {
HDF_LOGE("%s: test fail", __func__);
return HDF_FAILURE;
}
return HDF_SUCCESS;
}
static int32_t RtcReadWriteMinTimeTest(struct RtcTester *tester)
{
int32_t ret;
tester->time.year = RTC_BEGIN_YEAR - 1;
tester->time.month = 0;
tester->time.day = 0;
tester->time.hour = 0;
tester->time.minute = 0;
tester->time.second = 0;
tester->time.millisecond = 0;
tester->time.weekday = RtcGetWeekDay(&tester->time);
ret = TestReadWriteTime(tester);
if (ret == HDF_SUCCESS) {
HDF_LOGE("%s: test fail", __func__);
return HDF_FAILURE;
}
return HDF_SUCCESS;
}
static int32_t TestReadWriteAlarm(struct RtcTester *tester) {
int32_t ret;
struct RtcTime readTime = {0};
ret = RtcWriteAlarm(tester->handle, RTC_ALARM_INDEX_A, &tester->time);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: write alarm fail,ret:%d", __func__, ret);
return HDF_FAILURE;
}
OsalMSleep(tester->config.writeWaitMillisecond);
ret = RtcReadAlarm(tester->handle, RTC_ALARM_INDEX_A, &readTime);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: read alarm fail,ret:%d",__func__, ret);
return HDF_FAILURE;
}
ret = IsSameRtcTestTime(&readTime, &tester->time);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: different time", __func__);
return HDF_FAILURE;
}
return HDF_SUCCESS;
}
static int32_t RtcReadWriteAlarmTimeTest(struct RtcTester *tester)
{
int32_t ret;
tester->time.year = tester->config.year;
tester->time.month = tester->config.month;
tester->time.day = tester->config.day;
tester->time.hour = tester->config.hour + RTC_UNIT_DIFF;
tester->time.minute = tester->config.minute;
tester->time.second = tester->config.second;
tester->time.millisecond = 0;
tester->time.weekday = RtcGetWeekDay(&tester->time);
ret = TestReadWriteAlarm(tester);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: test fail", __func__);
return HDF_FAILURE;
}
return HDF_SUCCESS;
}
static int32_t RtcReadWriteAlarmMaxTimeTest(struct RtcTester *tester)
{
int32_t ret;
tester->time.year = tester->config.maxYear;
tester->time.month = RTC_MAX_MONTH + 1;
tester->time.day = RTC_GREAT_MONTH_DAY + 1;
tester->time.hour = RTC_DAY_HOURS;
tester->time.minute = RTC_MAX_MINUTE;
tester->time.second = RTC_MAX_SECOND;
tester->time.millisecond = RTC_MAX_MS;
tester->time.weekday = RtcGetWeekDay(&tester->time);
ret = TestReadWriteAlarm(tester);
if (ret == HDF_SUCCESS) {
HDF_LOGE("%s: test fail", __func__);
return HDF_FAILURE;
}
return HDF_SUCCESS;
}
static int32_t RtcReadWriteAlarmMinTimeTest(struct RtcTester *tester)
{
int32_t ret;
tester->time.year = RTC_BEGIN_YEAR - 1;
tester->time.month = 0;
tester->time.day = 0;
tester->time.hour = 0;
tester->time.minute = 0;
tester->time.second = 0;
tester->time.millisecond = 0;
tester->time.weekday = RtcGetWeekDay(&tester->time);
ret = TestReadWriteAlarm(tester);
if (ret == HDF_SUCCESS) {
HDF_LOGE("%s: test fail", __func__);
return HDF_FAILURE;
}
return HDF_SUCCESS;
}
static int32_t RtcAlarmEnableTest(struct RtcTester *tester)
{
int32_t ret;
/* 2020-08-08 Saturday 08:09:08 .000 */
tester->time.year = tester->config.year;
tester->time.month = tester->config.month;
tester->time.day = tester->config.day;
tester->time.hour = tester->config.hour;
tester->time.minute = tester->config.minute + RTC_UNIT_DIFF;
tester->time.second = tester->config.second;
tester->time.millisecond = 0;
tester->time.weekday = RtcGetWeekDay(&tester->time);
ret = TestReadWriteAlarm(tester);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s:read write alarm time fail.", __func__);
return HDF_FAILURE;
}
ret = RtcAlarmInterruptEnable(tester->handle, RTC_ALARM_INDEX_A, 1);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: alarm enable fail.", __func__);
return ret;
}
return HDF_SUCCESS;
}
#ifndef __USER__
static int32_t RtcAlarmIrqAttachConfig(struct RtcTester *tester)
{
int32_t ret;
uint32_t freq;
ret = RtcRegisterAlarmCallback(tester->handle, RTC_ALARM_INDEX_A, RtcAlarmACallback);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: register alarm callback fail.", __func__);
return ret;
}
freq = tester->config.frequence;
ret = RtcSetFreq(tester->handle, freq);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: rtc set freq fail, ret:%d", __func__, ret);
return ret;
}
ret = RtcAlarmInterruptEnable(tester->handle, RTC_ALARM_INDEX_A, 1);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: alarm interrupt enable fail", __func__);
return ret;
}
return HDF_SUCCESS;
}
#endif
static int32_t RtcAlarmIrqTest(struct RtcTester *tester)
{
#ifndef __USER__
int32_t ret;
/* set time 2020-08-08 Saturday 08:08:08 .000 */
tester->time.year = tester->config.year;
tester->time.month = tester->config.month;
tester->time.day = tester->config.day;
tester->time.hour = tester->config.hour;
tester->time.minute = tester->config.minute;
tester->time.second = tester->config.second;
tester->time.millisecond = 0;
tester->time.weekday = RtcGetWeekDay(&tester->time);
ret = RtcAlarmIrqAttachConfig(tester);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: alarm irq attach config fail, ret:%d", __func__, ret);
return ret;
}
ret = RtcWriteTime(tester->handle, &tester->time);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: write time fail", __func__);
return HDF_FAILURE;
}
/* set alarm time 2020-08-08 Saturday 08:08:09 .000 */
tester->time.second = tester->config.second + 1;
ret = RtcWriteAlarm(tester->handle, RTC_ALARM_INDEX_A, &tester->time);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: write alarm fail, ret:%d", __func__, ret);
return HDF_FAILURE;
}
OsalSleep(tester->config.writeWaitMillisecond);
if (g_rtcIrqCallback == HDF_FAILURE) {
HDF_LOGE("%s:rtc irq call back fail", __func__);
return HDF_FAILURE;
}
g_rtcIrqCallback = HDF_FAILURE;
#else
(void)tester;
#endif
return HDF_SUCCESS;
}
static int32_t RtcRegisterCallbackTest(struct RtcTester *tester)
{
int32_t ret;
ret = RtcRegisterAlarmCallback(tester->handle, RTC_ALARM_INDEX_A, RtcAlarmACallback);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: register alarm callback fail, ret:%d", __func__, ret);
return ret;
}
return HDF_SUCCESS;
}
static int32_t RtcRegisterNullCallbackTest(struct RtcTester *tester)
{
int32_t ret;
ret = RtcRegisterAlarmCallback(tester->handle, RTC_ALARM_INDEX_A, NULL);
if (ret == HDF_SUCCESS) {
HDF_LOGE("%s: register alarm callback fail", __func__);
return HDF_FAILURE;
}
return HDF_SUCCESS;
}
static int32_t RtcSetNormalFreqTest(struct RtcTester *tester)
{
int32_t ret;
ret = RtcSetFreq(tester->handle, tester->config.frequence);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: set normal frequence fail,ret:%d", __func__, ret);
return HDF_FAILURE;
}
return HDF_SUCCESS;
}
static int32_t RtcSetMaxFreqTest(struct RtcTester *tester)
{
int32_t ret;
ret = RtcSetFreq(tester->handle, tester->config.frequence * RTC_TIME_UNIT);
if (ret == HDF_SUCCESS) {
HDF_LOGE("%s: set max frequence test fail", __func__);
return HDF_FAILURE;
}
return HDF_SUCCESS;
}
static int32_t RtcSetMinFreqTest(struct RtcTester *tester)
{
int32_t ret;
ret = RtcSetFreq(tester->handle, 0);
if (ret == HDF_SUCCESS) {
HDF_LOGE("%s: set min frequence test fail", __func__);
return HDF_FAILURE;
}
ret = RtcSetFreq(tester->handle, tester->config.frequence);
return ret;
}
static int32_t RtcReadWriteUserRegTest(struct RtcTester *tester)
{
int32_t ret;
uint8_t value;
value = tester->config.userValue;
ret = RtcWriteReg(tester->handle, 0, value);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: write reg fail, ret:%d", __func__, ret);
return ret;
}
ret = RtcReadReg(tester->handle, 0, &value);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: read min frequence fail, ret:%d", __func__, ret);
return ret;
}
if (value != tester->config.userValue) {
HDF_LOGE("%s: value is not same.", __func__);
return HDF_FAILURE;
}
return HDF_SUCCESS;
}
static int32_t RtcReadWriteMaxUserIndexTest(struct RtcTester *tester)
{
int32_t ret;
uint8_t value;
value = tester->config.userValue;
ret = RtcWriteReg(tester->handle, tester->config.userMaxIndex, value);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: write reg max index test success", __func__);
return HDF_SUCCESS;
}
ret = RtcReadReg(tester->handle, tester->config.userMaxIndex, &value);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: read reg max index test success", __func__);
return HDF_SUCCESS;
}
return HDF_FAILURE;
}
static int32_t RtcTestSample(struct RtcTester *tester)
{
int32_t ret;
uint32_t freq;
struct RtcTime readTime = {0};
ret = RtcRegisterAlarmCallback(tester->handle, RTC_ALARM_INDEX_A, RtcAlarmACallback);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: register alarm callback fail, ret:%d", __func__, ret);
return ret;
}
freq = tester->config.frequence;
ret = RtcSetFreq(tester->handle, freq);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: set frequence fail, ret:%d", __func__, ret);
return ret;
}
ret = RtcAlarmInterruptEnable(tester->handle, RTC_ALARM_INDEX_A, 1);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: alarm interrupt enable fail, ret:%d", __func__, ret);
return ret;
}
tester->time.year= tester->config.year;
tester->time.month = RTC_JANUARY;
tester->time.day = tester->config.day;
tester->time.hour = 0;
tester->time.minute = 0;
tester->time.second = 0;
tester->time.millisecond = 0;
ret = RtcWriteTime(tester->handle, &tester->time);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: write time fail, ret:%d", __func__, ret);
return ret;
}
tester->time.second = tester->config.second;
ret = RtcWriteAlarm(tester->handle, RTC_ALARM_INDEX_A, &tester->time);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: write alarm fail, ret:%d", __func__, ret);
return ret;
}
OsalMSleep(tester->config.writeWaitMillisecond);
ret = RtcReadAlarm(tester->handle, RTC_ALARM_INDEX_A, &readTime);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: read alarm fail, ret:%d", __func__, ret);
return ret;
}
ret = RtcReadTime(tester->handle, &tester->time);
if (ret != HDF_SUCCESS) {
HDF_LOGE("%s: read time fail, ret:%d", __func__, ret);
return ret;
}
return HDF_SUCCESS;
}
static int32_t RtcReadWriteReliability(struct RtcTester *tester)
{
uint32_t i;
for (i = 0; i < tester->config.time; i++) {
(void)RtcReadWriteTimeTest(tester);
(void)RtcReadWriteAlarmTimeTest(tester);
(void)RtcSetNormalFreqTest(tester);
}
return HDF_SUCCESS;
}
struct RtcTestEntry {
int cmd;
int32_t (*func)(struct RtcTester *tester);
const char *name;
};
// add test case entry
static struct RtcTestEntry g_entry[] = {
{ RTC_TEST_CMD_WR_TIME, RtcReadWriteTimeTest, "RtcReadWriteTimeTest"},
{ RTC_TEST_CMD_WR_MAX_TIME, RtcReadWriteMaxTimeTest, "RtcReadWriteMaxTimeTest"},
{ RTC_TEST_CMD_WR_MIN_TIME, RtcReadWriteMinTimeTest, "RtcReadWriteMinTimeTest"},
{ RTC_TEST_CMD_WR_ALARM_TIME, RtcReadWriteAlarmTimeTest, "RtcReadWriteAlarmTimeTest"},
{ RTC_TEST_CMD_WR_ALARM_MAX_TIME, RtcReadWriteAlarmMaxTimeTest, "RtcReadWriteAlarmMaxTimeTest"},
{ RTC_TEST_CMD_WR_ALARM_MIN_TIME, RtcReadWriteAlarmMinTimeTest, "RtcReadWriteAlarmMinTimeTest"},
{ RTC_TEST_CMD_RTC_ALARM_ENABLE, RtcAlarmEnableTest, "RtcAlarmEnableTest"},
{ RTC_TEST_CMD_RTC_ALARM_IRQ, RtcAlarmIrqTest, "RtcAlarmIrqTest"},
{ RTC_TEST_CMD_RTC_REGISTER_CALLBACK, RtcRegisterCallbackTest, "RtcRegisterCallbackTest"},
{ RTC_TEST_CMD_RTC_REGISTER_CALLBACK_NULL, RtcRegisterNullCallbackTest, "RtcRegisterNullCallbackTest"},
{ RTC_TEST_CMD_RTC_WR_FREQ, RtcSetNormalFreqTest, "RtcSetNormalFreqTest"},
{ RTC_TEST_CMD_RTC_WR_MAX_FREQ, RtcSetMaxFreqTest, "RtcSetMaxFreqTest"},
{ RTC_TEST_CMD_RTC_WR_MIN_FREQ, RtcSetMinFreqTest, "RtcSetMinFreqTest"},
{ RTC_TEST_CMD_RTC_WR_USER_REG, RtcReadWriteUserRegTest, "RtcReadWriteUserRegTest"},
{ RTC_TEST_CMD_RTC_WR_USER_REG_MAX_INDEX, RtcReadWriteMaxUserIndexTest, "RtcReadWriteMaxUserIndexTest"},
{ RTC_TEST_CMD_RTC_FUNCTION_TEST, RtcTestSample, "RtcTestSample"},
{ RTC_TEST_CMD_RTC_WR_RELIABILITY, RtcReadWriteReliability, "RtcReadWriteReliability"},
};
int32_t RtcTestExecute(int cmd)
{
uint32_t i;
struct RtcTester *tester = NULL;
int32_t ret = HDF_ERR_NOT_SUPPORT;
tester = RtcTesterGet();
if (tester == NULL) {
HDF_LOGE("%s: tester is null", __func__);
return HDF_ERR_INVALID_OBJECT;
}
if (cmd > RTC_TEST_CMD_MAX) {
HDF_LOGE("%s: invalid cmd:%d", __func__, cmd);
ret = HDF_ERR_NOT_SUPPORT;
goto EXIT;
}
for (i = 0; i < sizeof(g_entry) / sizeof(g_entry[0]); i++) {
if (g_entry[i].cmd != cmd || g_entry[i].func == NULL) {
continue;
}
ret = g_entry[i].func(tester);
break;
}
EXIT:
HDF_LOGE("[%s][======cmd:%d====ret:%d======]", __func__, cmd, ret);
RtcTesterPut(tester);
return ret;
}

View File

@ -0,0 +1,69 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
*
* HDF is dual licensed: you can use it either under the terms of
* the GPL, or the BSD license, at your option.
* See the LICENSE file in the root of this repository for complete details.
*/
#ifndef RTC_TEST_H
#define RTC_TEST_H
#include "rtc_if.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
int32_t RtcTestExecute(int cmd);
struct RtcTestConfig {
uint32_t time;
uint32_t maxYear;
uint32_t year;
uint32_t month;
uint32_t day;
uint32_t weekday;
uint32_t millisecond;
uint32_t hour;
uint32_t minute;
uint32_t second;
uint32_t frequence;
uint32_t userValue;
uint32_t userMaxIndex;
uint32_t waitTimeSecond;
uint32_t writeWaitMillisecond;
};
struct RtcTester {
struct RtcTestConfig config;
struct RtcTime time;
DevHandle handle;
};
enum RtcTestCmd {
RTC_TEST_CMD_WR_TIME = 0,
RTC_TEST_CMD_WR_MAX_TIME,
RTC_TEST_CMD_WR_MIN_TIME,
RTC_TEST_CMD_WR_ALARM_TIME,
RTC_TEST_CMD_WR_ALARM_MAX_TIME,
RTC_TEST_CMD_WR_ALARM_MIN_TIME,
RTC_TEST_CMD_RTC_ALARM_ENABLE,
RTC_TEST_CMD_RTC_ALARM_IRQ,
RTC_TEST_CMD_RTC_REGISTER_CALLBACK,
RTC_TEST_CMD_RTC_REGISTER_CALLBACK_NULL,
RTC_TEST_CMD_RTC_WR_FREQ,
RTC_TEST_CMD_RTC_WR_MAX_FREQ,
RTC_TEST_CMD_RTC_WR_MIN_FREQ,
RTC_TEST_CMD_RTC_WR_USER_REG,
RTC_TEST_CMD_RTC_WR_USER_REG_MAX_INDEX,
RTC_TEST_CMD_RTC_WR_RELIABILITY,
RTC_TEST_CMD_RTC_FUNCTION_TEST,
RTC_TEST_CMD_MAX,
};
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* RTC_TEST_H */

View File

@ -8,627 +8,18 @@
#include "hdf_rtc_entry_test.h"
#include "hdf_log.h"
#include "osal_time.h"
#include "rtc_base.h"
#include "rtc_if.h"
#include "rtc_test.h"
#define HDF_LOG_TAG hdf_rtc_entry_test
#define RTC_TEST_TIME 60
#define RTC_TEST_TIME_MAX_YEAR 2222
#define RTC_TEST_TIME_YEAR 2020
#define RTC_TEST_TIME_MONTH 8
#define RTC_TEST_TIME_DAY 8
#define RTC_TEST_TIME_HOUR 8
#define RTC_TEST_TIME_MIN 8
#define RTC_TEST_TIME_SECOND 8
#define RTC_TEST_FREQ 32768
#define RTC_TEST_USER_VALUE 0x8
#define RTC_TEST_USER_MAX_INDEX 8
#define RTC_TEST_WAIT_TIME_S 3
#define RTC_TEST_WR_WAIT_MS 30
DevHandle g_rtcHandle = NULL;
#if defined(LOSCFG_DRIVERS_HDF_PLATFORM_RTC)
static int8_t g_rtcIrqCallback = HDF_FAILURE;
int32_t RtcAlarmACallback(enum RtcAlarmIndex alarmIndex)
int32_t HdfRtcTestEntry(HdfTestMsg *msg)
{
if (alarmIndex == RTC_ALARM_INDEX_A) {
HDF_LOGE("RtcAlarmACallback: alarm a callback success");
g_rtcIrqCallback = HDF_SUCCESS;
} else {
g_rtcIrqCallback = HDF_FAILURE;
}
return 0;
}
#endif
static int32_t RtcTestInit(void)
{
g_rtcHandle = RtcOpen();
if (g_rtcHandle == NULL) {
HDF_LOGE("RtcTestInit: g_rtcHandle NULL");
return -1;
}
return 0;
}
static int32_t RtcTestUniInit(void)
{
if (g_rtcHandle != NULL) {
RtcClose(g_rtcHandle);
g_rtcHandle = NULL;
}
return 0;
}
static int32_t IsSameRtcTestTime(const struct RtcTime *readTime, const struct RtcTime *writeTime)
{
if ((readTime->year != writeTime->year) || (readTime->month != writeTime->month) ||
(readTime->day != writeTime->day) || (readTime->weekday != writeTime->weekday) ||
(readTime->hour != writeTime->hour) || (readTime->minute != writeTime->minute) ||
(readTime->second < writeTime->second)) {
return -1;
}
return 0;
}
static int32_t RtcReadWriteTimeTest(struct RtcTime *writeTime)
{
int32_t ret;
struct RtcTime readTime = {0};
if (g_rtcHandle == NULL) {
HDF_LOGE("RtcReadWriteTimeTest g_rtcHandle null");
return -1;
}
ret = RtcWriteTime(g_rtcHandle, writeTime);
if (ret != 0) {
HDF_LOGE("RtcReadWriteTimeTest write failed");
return -1;
}
OsalMSleep(RTC_TEST_WR_WAIT_MS);
ret = RtcReadTime(g_rtcHandle, &readTime);
if (ret != 0) {
HDF_LOGE("RtcReadWriteTimeTest read failed");
return -1;
}
if (IsSameRtcTestTime(&readTime, writeTime) != 0) {
HDF_LOGE("RtcReadWriteTimeTest: different time");
return -1;
}
return 0;
}
static int32_t RtcReadWriteAlarmTimeTest(struct RtcTime *writeTime)
{
int32_t ret;
struct RtcTime readTime = {0};
if (g_rtcHandle == NULL) {
return -1;
}
ret = RtcWriteAlarm(g_rtcHandle, RTC_ALARM_INDEX_A, writeTime);
if (ret != 0) {
HDF_LOGE("RtcReadWriteAlarmTimeTest write failed");
return -1;
}
OsalMSleep(RTC_TEST_WR_WAIT_MS);
ret = RtcReadAlarm(g_rtcHandle, RTC_ALARM_INDEX_A, &readTime);
if (ret != 0) {
HDF_LOGE("RtcReadWriteAlarmTimeTest read failed");
return -1;
}
if (IsSameRtcTestTime(&readTime, writeTime) != 0) {
return -1;
}
return 0;
}
static int32_t RtcReadWriteTime(void)
{
int32_t ret;
uint8_t weekday;
struct RtcTime tm;
/* 2020-08-08 Saturday 09:08:08 .000 */
tm.year = RTC_TEST_TIME_YEAR;
tm.month = RTC_TEST_TIME_MONTH;
tm.day = RTC_TEST_TIME_DAY;
tm.hour = RTC_TEST_TIME_HOUR;
tm.minute = RTC_TEST_TIME_MIN;
tm.second = RTC_TEST_TIME_SECOND;
tm.millisecond = 0;
weekday = RtcGetWeekDay(&tm);
tm.weekday = weekday;
ret = RtcReadWriteTimeTest(&tm);
if (ret != 0) {
HDF_LOGE("RtcReadWriteTime failed");
return -1;
}
return 0;
}
static int32_t RtcReadWriteMaxTime(void)
{
int32_t ret;
uint8_t weekday;
struct RtcTime tm;
tm.year = RTC_TEST_TIME_MAX_YEAR;
tm.month = RTC_MAX_MONTH + 1;
tm.day = RTC_GREAT_MONTH_DAY + 1;
tm.hour = RTC_DAY_HOURS;
tm.minute = RTC_MAX_MINUTE;
tm.second = RTC_MAX_SECOND;
tm.millisecond = RTC_MAX_MS;
weekday = RtcGetWeekDay(&tm);
tm.weekday = weekday;
ret = RtcReadWriteTimeTest(&tm);
if (ret == 0) {
HDF_LOGE("RtcReadWriteMaxTime failed");
return -1;
}
return 0;
}
static int32_t RtcReadWriteMinTime(void)
{
int32_t ret;
uint8_t weekday;
struct RtcTime tm;
tm.year = RTC_BEGIN_YEAR - 1;
tm.month = 0;
tm.day = 0;
tm.hour = 0;
tm.minute = 0;
tm.second = 0;
tm.millisecond = 0;
weekday = RtcGetWeekDay(&tm);
tm.weekday = weekday;
ret = RtcReadWriteTimeTest(&tm);
if (ret == 0) {
HDF_LOGE("RtcReadWriteMinTime failed");
return -1;
}
return 0;
}
static int32_t RtcReadWriteAlarmTime(void)
{
int32_t ret;
uint8_t weekday;
struct RtcTime tm;
/* 2020-08-08 Saturday 09:08:08 .000 */
tm.year = RTC_TEST_TIME_YEAR;
tm.month = RTC_TEST_TIME_MONTH;
tm.day = RTC_TEST_TIME_DAY;
tm.hour = RTC_TEST_TIME_HOUR + RTC_UNIT_DIFF;
tm.minute = RTC_TEST_TIME_MIN;
tm.second = RTC_TEST_TIME_SECOND;
tm.millisecond = 0;
weekday = RtcGetWeekDay(&tm);
tm.weekday = weekday;
ret = RtcReadWriteAlarmTimeTest(&tm);
if (ret != 0) {
HDF_LOGE("RtcReadWriteAlarmTime read failed");
return -1;
}
return 0;
}
static int32_t RtcReadWriteMaxAlarmTime(void)
{
int32_t ret;
uint8_t weekday;
struct RtcTime tm;
tm.year = RTC_TEST_TIME_MAX_YEAR;
tm.month = RTC_MAX_MONTH + 1;
tm.day = RTC_GREAT_MONTH_DAY + 1;
tm.hour = RTC_DAY_HOURS;
tm.minute = RTC_MAX_MINUTE;
tm.second = RTC_MAX_SECOND;
tm.millisecond = RTC_MAX_MS;
weekday = RtcGetWeekDay(&tm);
tm.weekday = weekday;
ret = RtcReadWriteAlarmTimeTest(&tm);
if (ret == 0) {
HDF_LOGE("RtcReadWriteMaxAlarmTime read failed");
return -1;
}
return 0;
}
static int32_t RtcReadWriteMinAlarmTime(void)
{
int32_t ret;
uint8_t weekday;
struct RtcTime time;
time.year = RTC_BEGIN_YEAR - 1;
time.month = 0;
time.day = 0;
time.hour = 0;
time.minute = 0;
time.second = 0;
time.millisecond = 0;
weekday = RtcGetWeekDay(&time);
time.weekday = weekday;
ret = RtcReadWriteAlarmTimeTest(&time);
if (ret == 0) {
HDF_LOGE("RtcReadWriteMinAlarmTime read failed");
return -1;
}
return 0;
}
#if defined(CONFIG_DRIVERS_HDF_PLATFORM_RTC)
static int32_t RtcAlarmEnable(void)
{
int32_t ret;
uint8_t weekday;
struct RtcTime tm;
/* 2020-08-08 Saturday 08:09:08 .000 */
tm.year = RTC_TEST_TIME_YEAR;
tm.month = RTC_TEST_TIME_MONTH;
tm.day = RTC_TEST_TIME_DAY;
tm.hour = RTC_TEST_TIME_HOUR;
tm.minute = RTC_TEST_TIME_MIN + RTC_UNIT_DIFF;
tm.second = RTC_TEST_TIME_SECOND;
tm.millisecond = 0;
weekday = RtcGetWeekDay(&tm);
tm.weekday = weekday;
ret = RtcReadWriteAlarmTimeTest(&tm);
if (ret != 0) {
HDF_LOGE("RtcReadWriteAlarmTime read failed");
return -1;
}
ret = RtcAlarmInterruptEnable(g_rtcHandle, RTC_ALARM_INDEX_A, 1);
if (ret != 0) {
HDF_LOGE("RtcAlarmInterruptEnable failed");
return -1;
}
return 0;
}
#endif
#if defined(LOSCFG_DRIVERS_HDF_PLATFORM_RTC)
static int32_t RtcAlarmIrqAttachConfig(void)
{
int32_t ret;
const uint32_t freq = RTC_TEST_FREQ;
if (g_rtcHandle == NULL) {
return -1;
}
ret = RtcRegisterAlarmCallback(g_rtcHandle, RTC_ALARM_INDEX_A, RtcAlarmACallback);
if (ret != 0) {
HDF_LOGE("RtcRegisterAlarmCallback failed");
return -1;
}
ret = RtcSetFreq(g_rtcHandle, freq);
if (ret != 0) {
HDF_LOGE("RtcSetFreq failed");
return -1;
}
ret = RtcAlarmInterruptEnable(g_rtcHandle, RTC_ALARM_INDEX_A, 1);
if (ret != 0) {
HDF_LOGE("RtcAlarmInterruptEnable failed");
return -1;
}
return 0;
}
static int32_t RtcAlarmIrq(void)
{
int32_t ret;
uint8_t weekday;
struct RtcTime time;
if (g_rtcHandle == NULL) {
return -1;
}
/* set time 2020-08-08 Saturday 08:08:08 .000 */
time.year = RTC_TEST_TIME_YEAR;
time.month = RTC_TEST_TIME_MONTH;
time.day = RTC_TEST_TIME_DAY;
time.hour = RTC_TEST_TIME_HOUR;
time.minute = RTC_TEST_TIME_MIN;
time.second = RTC_TEST_TIME_SECOND;
time.millisecond = 0;
weekday = RtcGetWeekDay(&time);
time.weekday = weekday;
ret = RtcAlarmIrqAttachConfig();
if (ret != 0) {
HDF_LOGE("RtcWriteTime failed");
return -1;
}
ret = RtcWriteTime(g_rtcHandle, &time);
if (ret != 0) {
HDF_LOGE("RtcWriteTime failed");
return -1;
}
/* set alarm time 2020-08-08 Saturday 08:08:09 .000 */
time.second = RTC_TEST_TIME_SECOND + 1;
ret = RtcWriteAlarm(g_rtcHandle, RTC_ALARM_INDEX_A, &time);
if (ret != 0) {
HDF_LOGE("RtcWriteAlarm failed");
return -1;
}
OsalSleep(RTC_TEST_WAIT_TIME_S);
if (g_rtcIrqCallback == HDF_FAILURE) {
HDF_LOGE("RtcWriteAlarm failed");
return -1;
}
g_rtcIrqCallback = HDF_FAILURE;
return 0;
}
static int32_t RtcRegisterCallback(void)
{
int32_t ret;
if (g_rtcHandle == NULL) {
return -1;
}
ret = RtcRegisterAlarmCallback(g_rtcHandle, RTC_ALARM_INDEX_A, RtcAlarmACallback);
if (ret != 0) {
HDF_LOGE("RtcRegisterCallback failed");
return -1;
}
return 0;
}
static int32_t RtcRegisterNullCallback(void)
{
int32_t ret;
if (g_rtcHandle == NULL) {
return -1;
}
ret = RtcRegisterAlarmCallback(g_rtcHandle, RTC_ALARM_INDEX_A, NULL);
if (ret == 0) {
HDF_LOGE("RtcRegisterCallback failed");
return -1;
}
return 0;
}
static int32_t RtcSetNormalFreq(void)
{
int32_t ret;
if (g_rtcHandle == NULL) {
return -1;
}
ret = RtcSetFreq(g_rtcHandle, RTC_TEST_FREQ);
if (ret != 0) {
HDF_LOGE("RtcSetNormalFreq failed");
return -1;
}
return 0;
}
static int32_t RtcSetMaxFreq(void)
{
int32_t ret;
if (g_rtcHandle == NULL) {
return -1;
}
ret = RtcSetFreq(g_rtcHandle, RTC_TEST_FREQ * RTC_TIME_UNIT);
if (ret == 0) {
HDF_LOGE("RtcSetMaxFreq failed");
return -1;
}
return 0;
}
static int32_t RtcSetMinFreq(void)
{
int32_t ret;
if (g_rtcHandle == NULL) {
return -1;
}
ret = RtcSetFreq(g_rtcHandle, 0);
if (ret == 0) {
HDF_LOGE("RtcSetMinFreq failed");
return -1;
}
ret = RtcSetFreq(g_rtcHandle, RTC_TEST_FREQ);
return ret;
}
static int32_t RtcReadWriteUserReg(void)
{
int32_t ret;
uint8_t value = RTC_TEST_USER_VALUE;
if (g_rtcHandle == NULL) {
return -1;
}
ret = RtcWriteReg(g_rtcHandle, 0, value);
if (ret != 0) {
HDF_LOGE("RtcReadWriteUserReg write failed");
return -1;
}
ret = RtcReadReg(g_rtcHandle, 0, &value);
if (ret != 0) {
HDF_LOGE("RtcSetMinFreq read failed");
return -1;
}
if (value != RTC_TEST_USER_VALUE) {
return -1;
}
return 0;
}
static int32_t RtcReadWriteMaxUserIndex(void)
{
int32_t ret;
uint8_t value = RTC_TEST_USER_VALUE;
if (g_rtcHandle == NULL) {
return -1;
}
ret = RtcWriteReg(g_rtcHandle, RTC_TEST_USER_MAX_INDEX, value);
if (ret == 0) {
HDF_LOGE("RtcReadWriteUserReg write failed");
return -1;
}
ret = RtcReadReg(g_rtcHandle, RTC_TEST_USER_MAX_INDEX, &value);
if (ret == 0) {
HDF_LOGE("RtcSetMinFreq read failed");
return -1;
}
return 0;
}
static int32_t RtcTestSample(void)
{
int32_t ret;
struct RtcTime tm;
const uint32_t freq = RTC_TEST_FREQ;
if (g_rtcHandle == NULL) {
return -1;
}
ret = RtcRegisterAlarmCallback(g_rtcHandle, RTC_ALARM_INDEX_A, RtcAlarmACallback);
if (ret != 0) {
return -1;
}
ret = RtcSetFreq(g_rtcHandle, freq);
if (ret != 0) {
return -1;
}
ret = RtcAlarmInterruptEnable(g_rtcHandle, RTC_ALARM_INDEX_A, 1);
if (ret != 0) {
return -1;
}
tm.year = RTC_TEST_TIME_YEAR;
tm.month = RTC_JANUARY;
tm.day = RTC_TEST_TIME_DAY;
tm.hour = 0;
tm.minute = 0;
tm.second = 0;
tm.millisecond = 0;
ret = RtcWriteTime(g_rtcHandle, &tm);
if (ret != 0) {
return -1;
}
tm.second = RTC_TEST_TIME_SECOND;
ret = RtcWriteAlarm(g_rtcHandle, RTC_ALARM_INDEX_A, &tm);
if (ret != 0) {
return -1;
}
OsalMSleep(RTC_TEST_WR_WAIT_MS);
ret = RtcReadAlarm(g_rtcHandle, RTC_ALARM_INDEX_A, &tm);
if (ret != 0) {
return -1;
}
ret = RtcReadTime(g_rtcHandle, &tm);
if (ret != 0) {
return -1;
}
return 0;
}
#endif
static int32_t RtcReadWriteReliability(void)
{
int i;
for (i = 0; i < RTC_TEST_TIME; i++) {
(void)RtcReadWriteTime();
(void)RtcReadWriteAlarmTime();
#if defined(LOSCFG_DRIVERS_HDF_PLATFORM_RTC)
(void)RtcSetNormalFreq();
#endif
}
return 0;
}
// add test case entry
HdfTestCaseList g_hdfRtcTestCaseList[] = {
{ RTC_INIT, RtcTestInit },
{ RTC_UNINIT, RtcTestUniInit },
{ RTC_WR_TIME, RtcReadWriteTime },
{ RTC_WR_MAX_TIME, RtcReadWriteMaxTime },
{ RTC_WR_MIN_TIME, RtcReadWriteMinTime },
{ RTC_WR_ALARM_TIME, RtcReadWriteAlarmTime },
{ RTC_WR_ALARM_MAX_TIME, RtcReadWriteMaxAlarmTime },
{ RTC_WR_ALARM_MIN_TIME, RtcReadWriteMinAlarmTime },
#if defined(CONFIG_DRIVERS_HDF_PLATFORM_RTC)
{ RTC_ALARM_ENABLE, RtcAlarmEnable },
#endif
#if defined(LOSCFG_DRIVERS_HDF_PLATFORM_RTC)
{ RTC_ALARM_IRQ, RtcAlarmIrq },
{ RTC_REGISTER_CALLBACK, RtcRegisterCallback },
{ RTC_REGISTER_CALLBACK_NULL, RtcRegisterNullCallback },
{ RTC_WR_FREQ, RtcSetNormalFreq },
{ RTC_WR_MAX_FREQ, RtcSetMaxFreq },
{ RTC_WR_MIN_FREQ, RtcSetMinFreq },
{ RTC_WR_USER_REG, RtcReadWriteUserReg },
{ RTC_WR_USER_REG_MAX_INDEX, RtcReadWriteMaxUserIndex },
{ RTC_FUNCTION_TEST, RtcTestSample },
#endif
{ RTC_WR_RELIABILITY, RtcReadWriteReliability },
};
int32_t HdfRtcEntry(HdfTestMsg *msg)
{
int i;
if (msg == NULL) {
HDF_LOGE("%s: msg is NULL", __func__);
return HDF_FAILURE;
}
for (i = 0; i < sizeof(g_hdfRtcTestCaseList) / sizeof(g_hdfRtcTestCaseList[0]); ++i) {
if (msg->subCmd != g_hdfRtcTestCaseList[i].subCmd) {
continue;
}
if (g_hdfRtcTestCaseList[i].testFunc == NULL) {
msg->result = HDF_FAILURE;
continue;
}
msg->result = g_hdfRtcTestCaseList[i].testFunc();
if (msg->result != HDF_SUCCESS) {
continue;
}
}
msg->result = RtcTestExecute(msg->subCmd);
return HDF_SUCCESS;
}

View File

@ -11,27 +11,6 @@
#include "hdf_main_test.h"
typedef enum {
RTC_INIT,
RTC_UNINIT,
RTC_WR_TIME,
RTC_WR_MAX_TIME,
RTC_WR_MIN_TIME,
RTC_WR_ALARM_TIME,
RTC_WR_ALARM_MAX_TIME,
RTC_WR_ALARM_MIN_TIME,
RTC_ALARM_ENABLE,
RTC_ALARM_IRQ,
RTC_REGISTER_CALLBACK,
RTC_REGISTER_CALLBACK_NULL,
RTC_WR_FREQ,
RTC_WR_MAX_FREQ,
RTC_WR_MIN_FREQ,
RTC_WR_USER_REG,
RTC_WR_USER_REG_MAX_INDEX,
RTC_WR_RELIABILITY,
RTC_FUNCTION_TEST,
} HdfRtcTestCaseCmd;
int32_t HdfRtcTestEntry(HdfTestMsg *msg);
int32_t HdfRtcEntry(HdfTestMsg *msg);
#endif /* HDF_RTC_ENTRY_TEST_H */
#endif /* HDF_RTC_ENTRY_TEST_H */