mirror of
https://github.com/openharmony/drivers_framework.git
synced 2026-07-21 03:35:25 -04:00
Feat:Add timer user mode interface
Signed-off-by: s00442234 <susha@huawei.com>
This commit is contained in:
@@ -24,21 +24,21 @@ extern "C" {
|
||||
typedef int32_t (*TimerHandleCb)(void);
|
||||
|
||||
/**
|
||||
* @brief Gets a timer.
|
||||
* @brief Gets a hardware timer.
|
||||
* This function must be called to get its device handle before operating the timer.
|
||||
* @param number Indicates a timer id.
|
||||
* @return If the operation is successful, a pointer to the timer device handle is returned.
|
||||
* @since 1.0
|
||||
*/
|
||||
DevHandle TimerOpen(const uint32_t number);
|
||||
DevHandle HwTimerOpen(const uint32_t number);
|
||||
|
||||
/**
|
||||
* @brief Close a timer.
|
||||
* @brief Close a hardware timer.
|
||||
* If you no longer need the timer, call this function to close it
|
||||
* @param handle Represents a pointer to the timer device handle.
|
||||
* @since 1.0
|
||||
*/
|
||||
void TimerClose(DevHandle handle);
|
||||
void HwTimerClose(DevHandle handle);
|
||||
|
||||
/**
|
||||
* @brief Start a timer.
|
||||
@@ -47,7 +47,7 @@ void TimerClose(DevHandle handle);
|
||||
* @return success or fail
|
||||
* @since 1.0
|
||||
*/
|
||||
int32_t TimerStart(DevHandle handle);
|
||||
int32_t HwTimerStart(DevHandle handle);
|
||||
|
||||
/**
|
||||
* @brief Stop a timer.
|
||||
@@ -56,7 +56,7 @@ int32_t TimerStart(DevHandle handle);
|
||||
* @return success or fail
|
||||
* @since 1.0
|
||||
*/
|
||||
int32_t TimerStop(DevHandle handle);
|
||||
int32_t HwTimerStop(DevHandle handle);
|
||||
|
||||
/**
|
||||
* @brief Set a period timer.
|
||||
@@ -67,7 +67,7 @@ int32_t TimerStop(DevHandle handle);
|
||||
* @return success or fail
|
||||
* @since 1.0
|
||||
*/
|
||||
int32_t TimerSet(DevHandle handle, uint32_t useconds, TimerHandleCb cb);
|
||||
int32_t HwTimerSet(DevHandle handle, uint32_t useconds, TimerHandleCb cb);
|
||||
|
||||
/**
|
||||
* @brief Set a oneshot timer.
|
||||
@@ -77,7 +77,7 @@ int32_t TimerSet(DevHandle handle, uint32_t useconds, TimerHandleCb cb);
|
||||
* @return success or fail
|
||||
* @since 1.0
|
||||
*/
|
||||
int32_t TimerSetOnce(DevHandle handle, uint32_t useconds, TimerHandleCb cb);
|
||||
int32_t HwTimerSetOnce(DevHandle handle, uint32_t useconds, TimerHandleCb cb);
|
||||
|
||||
/**
|
||||
* @brief Get the timer info.
|
||||
@@ -88,7 +88,28 @@ int32_t TimerSetOnce(DevHandle handle, uint32_t useconds, TimerHandleCb cb);
|
||||
* @return success or fail
|
||||
* @since 1.0
|
||||
*/
|
||||
int32_t TimerGet(DevHandle handle, uint32_t *useconds, bool *isPeriod);
|
||||
int32_t HwTimerGet(DevHandle handle, uint32_t *useconds, bool *isPeriod);
|
||||
|
||||
/**
|
||||
* @brief Enumerates TIMER I/O commands.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
enum TimerIoCmd {
|
||||
TIMER_IO_OPEN = 0, /**< Open the TIMER device. */
|
||||
TIMER_IO_CLOSE, /**< Close the TIMER device. */
|
||||
TIMER_IO_START, /**< Start the TIMER. */
|
||||
TIMER_IO_STOP, /**< Stop the TIMER. */
|
||||
TIMER_IO_SET, /**< Set the period TIMER info. */
|
||||
TIMER_IO_SETONCE, /**< Set the once TIMER info. */
|
||||
TIMER_IO_GET, /**< Get the TIMER info. */
|
||||
};
|
||||
|
||||
struct TimerConfig {
|
||||
uint32_t number;
|
||||
uint32_t useconds;
|
||||
bool isPeriod;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
|
||||
@@ -22,68 +22,7 @@ struct TimerManager {
|
||||
};
|
||||
|
||||
static struct TimerManager *g_timerManager = NULL;
|
||||
|
||||
int32_t TimerCntrlAdd(struct TimerCntrl *cntrl)
|
||||
{
|
||||
CHECK_NULL_PTR_RETURN_VALUE(cntrl, HDF_ERR_INVALID_PARAM);
|
||||
CHECK_NULL_PTR_RETURN_VALUE(cntrl->ops, HDF_ERR_INVALID_PARAM);
|
||||
struct TimerCntrl *pos = NULL;
|
||||
struct TimerCntrl *tmp = NULL;
|
||||
struct TimerManager *manager = g_timerManager;
|
||||
CHECK_NULL_PTR_RETURN_VALUE(manager, HDF_FAILURE);
|
||||
|
||||
DLIST_FOR_EACH_ENTRY_SAFE(pos, tmp, &manager->timerListHead, struct TimerCntrl, node) {
|
||||
if (cntrl->info.number == pos->info.number) {
|
||||
HDF_LOGE("%s: timer[%u] existed", __func__, cntrl->info.number);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
// init info
|
||||
if (OsalMutexInit(&cntrl->lock) != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: OsalMutexInit %u failed", __func__, cntrl->info.number);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
if (OsalMutexLock(&manager->lock) != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: OsalMutexLock %u failed", __func__, cntrl->info.number);
|
||||
return HDF_ERR_DEVICE_BUSY;
|
||||
}
|
||||
DListInsertTail(&cntrl->node, &manager->timerListHead);
|
||||
(void)OsalMutexUnlock(&manager->lock);
|
||||
HDF_LOGI("%s: add timer number[%u] success", __func__, cntrl->info.number);
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t TimerCntrlRemoveByNumber(const uint32_t number)
|
||||
{
|
||||
struct TimerCntrl *pos = NULL;
|
||||
struct TimerCntrl *tmp = NULL;
|
||||
struct TimerManager *manager = g_timerManager;
|
||||
CHECK_NULL_PTR_RETURN_VALUE(manager, HDF_FAILURE);
|
||||
|
||||
if (OsalMutexLock(&manager->lock) != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: OsalMutexLock failed", __func__);
|
||||
return HDF_ERR_DEVICE_BUSY;
|
||||
}
|
||||
|
||||
DLIST_FOR_EACH_ENTRY_SAFE(pos, tmp, &manager->timerListHead, struct TimerCntrl, node) {
|
||||
if (number == pos->info.number) {
|
||||
if ((pos->ops->Remove != NULL) && (pos->ops->Remove(pos) != HDF_SUCCESS)) {
|
||||
HDF_LOGE("%s: remove %u failed", __func__, pos->info.number);
|
||||
}
|
||||
(void)OsalMutexDestroy(&pos->lock);
|
||||
DListRemove(&pos->node);
|
||||
OsalMemFree(pos);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
(void)OsalMutexUnlock(&manager->lock);
|
||||
HDF_LOGI("%s: remove timer %u success", __func__, number);
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
#define TIMER_HANDLE_SHIFT ((uintptr_t)(-1) << 16)
|
||||
|
||||
struct TimerCntrl *TimerCntrlOpen(const uint32_t number)
|
||||
{
|
||||
@@ -212,6 +151,234 @@ int32_t TimerCntrlStop(struct TimerCntrl *cntrl)
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t TimerIoOpen(struct HdfSBuf *data, struct HdfSBuf *reply)
|
||||
{
|
||||
int16_t number;
|
||||
uint32_t handle;
|
||||
|
||||
if ((data == NULL) || (reply == NULL)) {
|
||||
HDF_LOGE("%s: param invalid", __func__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
if (!HdfSbufReadUint16(data, (uint16_t *)&number)) {
|
||||
HDF_LOGE("%s: HdfSbufReadUint16 failed", __func__);
|
||||
return HDF_ERR_IO;
|
||||
}
|
||||
|
||||
if (number < 0) {
|
||||
HDF_LOGE("%s: info read failed", __func__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if (TimerCntrlOpen(number) == NULL) {
|
||||
HDF_LOGE("%s: TimerCntrlOpen %d failed", __func__, number);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
handle = (uint32_t)(number + TIMER_HANDLE_SHIFT);
|
||||
if (!HdfSbufWriteUint32(reply, handle)) {
|
||||
HDF_LOGE("%s: HdfSbufWriteUint32 failed", __func__);
|
||||
return HDF_ERR_IO;
|
||||
}
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t TimerIoClose(struct HdfSBuf *data, struct HdfSBuf *reply)
|
||||
{
|
||||
uint32_t handle;
|
||||
int16_t number;
|
||||
if (data == NULL) {
|
||||
HDF_LOGE("%s: param invalid", __func__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if (!HdfSbufReadUint32(data, &handle)) {
|
||||
HDF_LOGE("%s: HdfSbufReadUint32 failed", __func__);
|
||||
return HDF_ERR_IO;
|
||||
}
|
||||
|
||||
number = (int16_t)(handle - TIMER_HANDLE_SHIFT);
|
||||
if (number < 0) {
|
||||
HDF_LOGE("%s: number[%d] invalid", __func__, number);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
return TimerCntrlClose(TimerCntrlOpen(number));
|
||||
}
|
||||
|
||||
static int32_t TimerIoStart(struct HdfSBuf *data, struct HdfSBuf *reply)
|
||||
{
|
||||
uint32_t handle;
|
||||
int16_t number;
|
||||
if (data == NULL) {
|
||||
HDF_LOGE("%s: param invalid", __func__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
if (!HdfSbufReadUint32(data, &handle)) {
|
||||
HDF_LOGE("%s: HdfSbufReadUint32 failed", __func__);
|
||||
return HDF_ERR_IO;
|
||||
}
|
||||
|
||||
number = (int16_t)(handle - TIMER_HANDLE_SHIFT);
|
||||
if (number < 0) {
|
||||
HDF_LOGE("%s: number[%d] invalid", __func__, number);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
return TimerCntrlStart(TimerCntrlOpen(number));
|
||||
}
|
||||
|
||||
static int32_t TimerIoStop(struct HdfSBuf *data, struct HdfSBuf *reply)
|
||||
{
|
||||
uint32_t handle;
|
||||
int16_t number;
|
||||
if (data == NULL) {
|
||||
HDF_LOGE("%s: param invalid", __func__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
if (!HdfSbufReadUint32(data, &handle)) {
|
||||
HDF_LOGE("%s: HdfSbufReadUint32 failed", __func__);
|
||||
return HDF_ERR_IO;
|
||||
}
|
||||
|
||||
number = (int16_t)(handle - TIMER_HANDLE_SHIFT);
|
||||
if (number < 0) {
|
||||
HDF_LOGE("%s: number[%d] invalid", __func__, number);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
return TimerCntrlStop(TimerCntrlOpen(number));
|
||||
}
|
||||
|
||||
static int32_t TimerIoCb()
|
||||
{
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t TimerIoSet(struct HdfSBuf *data, struct HdfSBuf *reply)
|
||||
{
|
||||
uint32_t len;
|
||||
uint32_t handle;
|
||||
int16_t number;
|
||||
struct TimerConfig *cfg = NULL;
|
||||
if (data == NULL) {
|
||||
HDF_LOGE("%s: param invalid", __func__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
if (!HdfSbufReadUint32(data, &handle)) {
|
||||
HDF_LOGE("%s: read handle failed!", __func__);
|
||||
return HDF_ERR_IO;
|
||||
}
|
||||
|
||||
if (!HdfSbufReadBuffer(data, (const void **)&cfg, &len) || cfg == NULL) {
|
||||
HDF_LOGE("%s: read buffer failed!", __func__);
|
||||
return HDF_ERR_IO;
|
||||
}
|
||||
|
||||
number = (int16_t)(handle - TIMER_HANDLE_SHIFT);
|
||||
if (number < 0) {
|
||||
HDF_LOGE("%s: number[%d] invalid", __func__, number);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
return TimerCntrlSet(TimerCntrlOpen(number), cfg->useconds, TimerIoCb);
|
||||
}
|
||||
|
||||
static int32_t TimerIoSetOnce(struct HdfSBuf *data, struct HdfSBuf *reply)
|
||||
{
|
||||
uint32_t len;
|
||||
uint32_t handle;
|
||||
int16_t number;
|
||||
struct TimerConfig *cfg = NULL;
|
||||
if (data == NULL) {
|
||||
HDF_LOGE("%s: param invalid", __func__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
if (!HdfSbufReadUint32(data, &handle)) {
|
||||
HDF_LOGE("%s: read handle failed!", __func__);
|
||||
return HDF_ERR_IO;
|
||||
}
|
||||
|
||||
if (!HdfSbufReadBuffer(data, (const void **)&cfg, &len) || cfg == NULL) {
|
||||
HDF_LOGE("%s: read buffer failed!", __func__);
|
||||
return HDF_ERR_IO;
|
||||
}
|
||||
|
||||
number = (int16_t)(handle - TIMER_HANDLE_SHIFT);
|
||||
if (number < 0) {
|
||||
HDF_LOGE("%s: number[%d] invalid", __func__, number);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
return TimerCntrlSetOnce(TimerCntrlOpen(number), cfg->useconds, TimerIoCb);
|
||||
}
|
||||
|
||||
static int32_t TimerIoGet(struct HdfSBuf *data, struct HdfSBuf *reply)
|
||||
{
|
||||
int32_t ret = HDF_SUCCESS;
|
||||
struct TimerConfig cfg;
|
||||
uint32_t handle;
|
||||
int16_t number;
|
||||
if ((data == NULL) || (reply == NULL)) {
|
||||
HDF_LOGE("%s: param null", __func__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if (!HdfSbufReadUint32(data, &handle)) {
|
||||
HDF_LOGE("%s: HdfSbufReadUint32 failed", __func__);
|
||||
return HDF_ERR_IO;
|
||||
}
|
||||
|
||||
number = (int16_t)(handle - TIMER_HANDLE_SHIFT);
|
||||
if (number < 0) {
|
||||
HDF_LOGE("%s: number[%d] invalid", __func__, number);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
cfg.number = number;
|
||||
ret = TimerCntrlGet(TimerCntrlOpen(number), &cfg.useconds, &cfg.isPeriod);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: TimerCntrlGet failed!", __func__);
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (!HdfSbufWriteBuffer(reply, &cfg, sizeof(cfg))) {
|
||||
HDF_LOGE("%s: write buffer failed!", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t TimerIoDispatch(struct HdfDeviceIoClient *client, int cmd,
|
||||
struct HdfSBuf *data, struct HdfSBuf *reply)
|
||||
{
|
||||
int32_t ret;
|
||||
|
||||
switch (cmd) {
|
||||
case TIMER_IO_OPEN:
|
||||
ret = TimerIoOpen(data, reply);
|
||||
break;
|
||||
case TIMER_IO_CLOSE:
|
||||
ret = TimerIoClose(data, reply);
|
||||
break;
|
||||
case TIMER_IO_START:
|
||||
ret = TimerIoStart(data, reply);
|
||||
break;
|
||||
case TIMER_IO_STOP:
|
||||
ret = TimerIoStop(data, reply);
|
||||
break;
|
||||
case TIMER_IO_SET:
|
||||
ret = TimerIoSet(data, reply);
|
||||
break;
|
||||
case TIMER_IO_SETONCE:
|
||||
ret = TimerIoSetOnce(data, reply);
|
||||
break;
|
||||
case TIMER_IO_GET:
|
||||
ret = TimerIoGet(data, reply);
|
||||
break;
|
||||
default:
|
||||
ret = HDF_ERR_NOT_SUPPORT;
|
||||
HDF_LOGE("%s: cmd[%d] not support!", __func__, cmd);
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int32_t TimerListRemoveAll(void)
|
||||
{
|
||||
struct TimerCntrl *pos = NULL;
|
||||
@@ -237,6 +404,68 @@ int32_t TimerListRemoveAll(void)
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t TimerCntrlAdd(struct TimerCntrl *cntrl)
|
||||
{
|
||||
CHECK_NULL_PTR_RETURN_VALUE(cntrl, HDF_ERR_INVALID_PARAM);
|
||||
CHECK_NULL_PTR_RETURN_VALUE(cntrl->ops, HDF_ERR_INVALID_PARAM);
|
||||
struct TimerCntrl *pos = NULL;
|
||||
struct TimerCntrl *tmp = NULL;
|
||||
struct TimerManager *manager = g_timerManager;
|
||||
CHECK_NULL_PTR_RETURN_VALUE(manager, HDF_FAILURE);
|
||||
|
||||
DLIST_FOR_EACH_ENTRY_SAFE(pos, tmp, &manager->timerListHead, struct TimerCntrl, node) {
|
||||
if (cntrl->info.number == pos->info.number) {
|
||||
HDF_LOGE("%s: timer[%u] existed", __func__, cntrl->info.number);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
// init info
|
||||
if (OsalMutexInit(&cntrl->lock) != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: OsalMutexInit %u failed", __func__, cntrl->info.number);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
if (OsalMutexLock(&manager->lock) != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: OsalMutexLock %u failed", __func__, cntrl->info.number);
|
||||
return HDF_ERR_DEVICE_BUSY;
|
||||
}
|
||||
DListInsertTail(&cntrl->node, &manager->timerListHead);
|
||||
(void)OsalMutexUnlock(&manager->lock);
|
||||
HDF_LOGI("%s: add timer number[%u] success", __func__, cntrl->info.number);
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t TimerCntrlRemoveByNumber(const uint32_t number)
|
||||
{
|
||||
struct TimerCntrl *pos = NULL;
|
||||
struct TimerCntrl *tmp = NULL;
|
||||
struct TimerManager *manager = g_timerManager;
|
||||
CHECK_NULL_PTR_RETURN_VALUE(manager, HDF_FAILURE);
|
||||
|
||||
if (OsalMutexLock(&manager->lock) != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: OsalMutexLock failed", __func__);
|
||||
return HDF_ERR_DEVICE_BUSY;
|
||||
}
|
||||
|
||||
DLIST_FOR_EACH_ENTRY_SAFE(pos, tmp, &manager->timerListHead, struct TimerCntrl, node) {
|
||||
if (number == pos->info.number) {
|
||||
if ((pos->ops->Remove != NULL) && (pos->ops->Remove(pos) != HDF_SUCCESS)) {
|
||||
HDF_LOGE("%s: remove %u failed", __func__, pos->info.number);
|
||||
}
|
||||
(void)OsalMutexDestroy(&pos->lock);
|
||||
DListRemove(&pos->node);
|
||||
OsalMemFree(pos);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
(void)OsalMutexUnlock(&manager->lock);
|
||||
HDF_LOGI("%s: remove timer %u success", __func__, number);
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t TimerManagerBind(struct HdfDeviceObject *device)
|
||||
{
|
||||
int32_t ret;
|
||||
@@ -260,6 +489,7 @@ static int32_t TimerManagerBind(struct HdfDeviceObject *device)
|
||||
|
||||
manager->device = device;
|
||||
device->service = &manager->service;
|
||||
device->service->Dispatch = TimerIoDispatch;
|
||||
DListHeadInit(&manager->timerListHead);
|
||||
g_timerManager = manager;
|
||||
|
||||
|
||||
@@ -9,12 +9,12 @@
|
||||
#include "hdf_log.h"
|
||||
#include "timer_core.h"
|
||||
|
||||
DevHandle TimerOpen(const uint32_t number)
|
||||
DevHandle HwTimerOpen(const uint32_t number)
|
||||
{
|
||||
return (DevHandle)TimerCntrlOpen(number);
|
||||
}
|
||||
|
||||
void TimerClose(DevHandle handle)
|
||||
void HwTimerClose(DevHandle handle)
|
||||
{
|
||||
struct TimerCntrl *cntrl = (struct TimerCntrl *)handle;
|
||||
if (cntrl == NULL) {
|
||||
@@ -28,7 +28,7 @@ void TimerClose(DevHandle handle)
|
||||
}
|
||||
}
|
||||
|
||||
int32_t TimerSet(DevHandle handle, uint32_t useconds, TimerHandleCb cb)
|
||||
int32_t HwTimerSet(DevHandle handle, uint32_t useconds, TimerHandleCb cb)
|
||||
{
|
||||
struct TimerCntrl *cntrl = (struct TimerCntrl *)handle;
|
||||
if (cntrl == NULL || cb == NULL) {
|
||||
@@ -44,7 +44,7 @@ int32_t TimerSet(DevHandle handle, uint32_t useconds, TimerHandleCb cb)
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t TimerSetOnce(DevHandle handle, uint32_t useconds, TimerHandleCb cb)
|
||||
int32_t HwTimerSetOnce(DevHandle handle, uint32_t useconds, TimerHandleCb cb)
|
||||
{
|
||||
struct TimerCntrl *cntrl = (struct TimerCntrl *)handle;
|
||||
if (cntrl == NULL || cb == NULL) {
|
||||
@@ -60,7 +60,7 @@ int32_t TimerSetOnce(DevHandle handle, uint32_t useconds, TimerHandleCb cb)
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t TimerGet(DevHandle handle, uint32_t *useconds, bool *isPeriod)
|
||||
int32_t HwTimerGet(DevHandle handle, uint32_t *useconds, bool *isPeriod)
|
||||
{
|
||||
struct TimerCntrl *cntrl = (struct TimerCntrl *)handle;
|
||||
if (cntrl == NULL || useconds == NULL || isPeriod == NULL) {
|
||||
@@ -76,7 +76,7 @@ int32_t TimerGet(DevHandle handle, uint32_t *useconds, bool *isPeriod)
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t TimerStart(DevHandle handle)
|
||||
int32_t HwTimerStart(DevHandle handle)
|
||||
{
|
||||
struct TimerCntrl *cntrl = (struct TimerCntrl *)handle;
|
||||
if (cntrl == NULL) {
|
||||
@@ -92,7 +92,7 @@ int32_t TimerStart(DevHandle handle)
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t TimerStop(DevHandle handle)
|
||||
int32_t HwTimerStop(DevHandle handle)
|
||||
{
|
||||
struct TimerCntrl *cntrl = (struct TimerCntrl *)handle;
|
||||
if (cntrl == NULL) {
|
||||
|
||||
Executable
+368
@@ -0,0 +1,368 @@
|
||||
/*
|
||||
* 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 "timer_if.h"
|
||||
#include "hdf_io_service_if.h"
|
||||
#include "hdf_log.h"
|
||||
#include "osal_mem.h"
|
||||
#include "securec.h"
|
||||
|
||||
#define HDF_LOG_TAG timer_if_u
|
||||
|
||||
#define TIMER_SERVICE_NAME "HDF_PLATFORM_TIMER_MANAGER"
|
||||
static void *TimerManagerGetService(void)
|
||||
{
|
||||
static void *manager = NULL;
|
||||
|
||||
if (manager != NULL) {
|
||||
return manager;
|
||||
}
|
||||
manager = (void *)HdfIoServiceBind(TIMER_SERVICE_NAME);
|
||||
if (manager == NULL) {
|
||||
HDF_LOGE("%s: fail to get timer manager!", __func__);
|
||||
}
|
||||
return manager;
|
||||
}
|
||||
|
||||
DevHandle HwTimerOpen(const uint32_t number)
|
||||
{
|
||||
int32_t ret;
|
||||
struct HdfIoService *service = NULL;
|
||||
struct HdfSBuf *data = NULL;
|
||||
struct HdfSBuf *reply = NULL;
|
||||
uint32_t handle;
|
||||
|
||||
service = (struct HdfIoService *)TimerManagerGetService();
|
||||
if (service == NULL || service->dispatcher == NULL || service->dispatcher->Dispatch == NULL) {
|
||||
HDF_LOGE("%s: service is invalid", __func__);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
data = HdfSbufObtainDefaultSize();
|
||||
if (data == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
reply = HdfSbufObtainDefaultSize();
|
||||
if (reply == NULL) {
|
||||
HdfSbufRecycle(data);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!HdfSbufWriteUint16(data, (uint16_t)number)) {
|
||||
HDF_LOGE("%s: write number fail!", __func__);
|
||||
HdfSbufRecycle(data);
|
||||
HdfSbufRecycle(reply);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ret = service->dispatcher->Dispatch(&service->object, TIMER_IO_OPEN, data, reply);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: TIMER_IO_OPEN service process fail:%d", __func__, ret);
|
||||
HdfSbufRecycle(data);
|
||||
HdfSbufRecycle(reply);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!HdfSbufReadUint32(reply, &handle)) {
|
||||
HDF_LOGE("%s: read reply fail!", __func__);
|
||||
HdfSbufRecycle(data);
|
||||
HdfSbufRecycle(reply);
|
||||
return NULL;
|
||||
}
|
||||
HdfSbufRecycle(data);
|
||||
HdfSbufRecycle(reply);
|
||||
return (DevHandle)(uintptr_t)handle;
|
||||
}
|
||||
|
||||
void HwTimerClose(DevHandle handle)
|
||||
{
|
||||
int32_t ret;
|
||||
struct HdfIoService *service = NULL;
|
||||
struct HdfSBuf *data = NULL;
|
||||
|
||||
if (handle == NULL) {
|
||||
HDF_LOGE("%s: handle is invalid", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
service = (struct HdfIoService *)TimerManagerGetService();
|
||||
if (service == NULL || service->dispatcher == NULL || service->dispatcher->Dispatch == NULL) {
|
||||
HDF_LOGE("%s: service is invalid", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
data = HdfSbufObtainDefaultSize();
|
||||
if (data == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!HdfSbufWriteUint32(data, (uint32_t)(uintptr_t)handle)) {
|
||||
HDF_LOGE("%s: write handle fail!", __func__);
|
||||
HdfSbufRecycle(data);
|
||||
return;
|
||||
}
|
||||
|
||||
ret = service->dispatcher->Dispatch(&service->object, TIMER_IO_CLOSE, data, NULL);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: TIMER_IO_CLOSE service process fail:%d", __func__, ret);
|
||||
}
|
||||
HdfSbufRecycle(data);
|
||||
}
|
||||
|
||||
int32_t HwTimerStart(DevHandle handle)
|
||||
{
|
||||
int32_t ret;
|
||||
struct HdfIoService *service = NULL;
|
||||
struct HdfSBuf *data = NULL;
|
||||
|
||||
if (handle == NULL) {
|
||||
HDF_LOGE("%s: handle is invalid", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
service = (struct HdfIoService *)TimerManagerGetService();
|
||||
if (service == NULL || service->dispatcher == NULL || service->dispatcher->Dispatch == NULL) {
|
||||
HDF_LOGE("%s: service is invalid", __func__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
data = HdfSbufObtainDefaultSize();
|
||||
if (data == NULL) {
|
||||
HDF_LOGE("%s: HdfSBufObtainDefaultSize fail!", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
if (!HdfSbufWriteUint32(data, (uint32_t)(uintptr_t)handle)) {
|
||||
HDF_LOGE("%s: write handle fail!", __func__);
|
||||
HdfSbufRecycle(data);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
ret = service->dispatcher->Dispatch(&service->object, TIMER_IO_START, data, NULL);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: TIMER_IO_START service process fail:%d", __func__, ret);
|
||||
HdfSbufRecycle(data);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
HdfSbufRecycle(data);
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t HwTimerStop(DevHandle handle)
|
||||
{
|
||||
int32_t ret;
|
||||
struct HdfIoService *service = NULL;
|
||||
struct HdfSBuf *data = NULL;
|
||||
|
||||
if (handle == NULL) {
|
||||
HDF_LOGE("%s: handle is invalid", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
service = (struct HdfIoService *)TimerManagerGetService();
|
||||
if (service == NULL || service->dispatcher == NULL || service->dispatcher->Dispatch == NULL) {
|
||||
HDF_LOGE("%s: service is invalid", __func__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
data = HdfSbufObtainDefaultSize();
|
||||
if (data == NULL) {
|
||||
HDF_LOGE("%s: HdfSbufObtainDefaultSize fail!", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
if (!HdfSbufWriteUint32(data, (uint32_t)(uintptr_t)handle)) {
|
||||
HDF_LOGE("%s: write handle fail!", __func__);
|
||||
HdfSbufRecycle(data);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
ret = service->dispatcher->Dispatch(&service->object, TIMER_IO_STOP, data, NULL);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: TIMER_IO_STOP service process fail:%d", __func__, ret);
|
||||
HdfSbufRecycle(data);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
HdfSbufRecycle(data);
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t HwTimerSet(DevHandle handle, uint32_t useconds, TimerHandleCb cb)
|
||||
{
|
||||
int32_t ret;
|
||||
struct HdfIoService *service = NULL;
|
||||
struct HdfSBuf *buf = NULL;
|
||||
struct TimerConfig cfg;
|
||||
|
||||
if (handle == NULL) {
|
||||
HDF_LOGE("%s: handle is invalid", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
service = (struct HdfIoService *)TimerManagerGetService();
|
||||
if (service == NULL || service->dispatcher == NULL
|
||||
|| service->dispatcher->Dispatch == NULL || cb == NULL) {
|
||||
HDF_LOGE("%s:param is invalid", __func__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if (memset_s(&cfg, sizeof(cfg), 0, sizeof(cfg)) != EOK) {
|
||||
HDF_LOGE("%s:memset_s FAIL", __func__);
|
||||
return HDF_ERR_IO;
|
||||
}
|
||||
cfg.useconds = useconds;
|
||||
|
||||
buf = HdfSbufObtainDefaultSize();
|
||||
if (buf == NULL) {
|
||||
HDF_LOGE("%s: failed to obtain buf", __func__);
|
||||
return HDF_ERR_MALLOC_FAIL;
|
||||
}
|
||||
if (!HdfSbufWriteUint32(buf, (uint32_t)(uintptr_t)handle)) {
|
||||
HDF_LOGE("%s: sbuf write handle failed", __func__);
|
||||
return HDF_ERR_IO;
|
||||
}
|
||||
if (!HdfSbufWriteBuffer(buf, &cfg, sizeof(cfg))) {
|
||||
HDF_LOGE("%s: sbuf write cfg failed", __func__);
|
||||
HdfSbufRecycle(buf);
|
||||
return HDF_ERR_IO;
|
||||
}
|
||||
|
||||
ret = service->dispatcher->Dispatch(&service->object, TIMER_IO_SET, buf, NULL);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: TIMER_IO_SET service process fail:%d", __func__, ret);
|
||||
HdfSbufRecycle(buf);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
HdfSbufRecycle(buf);
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t HwTimerSetOnce(DevHandle handle, uint32_t useconds, TimerHandleCb cb)
|
||||
{
|
||||
int32_t ret;
|
||||
struct HdfIoService *service = NULL;
|
||||
struct HdfSBuf *buf = NULL;
|
||||
struct TimerConfig cfg;
|
||||
|
||||
if (handle == NULL) {
|
||||
HDF_LOGE("%s: handle is invalid", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
service = (struct HdfIoService *)TimerManagerGetService();
|
||||
if (service == NULL || service->dispatcher == NULL
|
||||
|| service->dispatcher->Dispatch == NULL || cb == NULL) {
|
||||
HDF_LOGE("%s: service is invalid", __func__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if (memset_s(&cfg, sizeof(cfg), 0, sizeof(cfg)) != EOK) {
|
||||
HDF_LOGE("%s:memset_s FAIL", __func__);
|
||||
return HDF_ERR_IO;
|
||||
}
|
||||
cfg.useconds = useconds;
|
||||
|
||||
buf = HdfSbufObtainDefaultSize();
|
||||
if (buf == NULL) {
|
||||
HDF_LOGE("%s: failed to obtain buf", __func__);
|
||||
return HDF_ERR_MALLOC_FAIL;
|
||||
}
|
||||
if (!HdfSbufWriteUint32(buf, (uint32_t)(uintptr_t)handle)) {
|
||||
HDF_LOGE("%s: sbuf write handle failed", __func__);
|
||||
return HDF_ERR_IO;
|
||||
}
|
||||
if (!HdfSbufWriteBuffer(buf, &cfg, sizeof(cfg))) {
|
||||
HDF_LOGE("%s: sbuf write cfg failed", __func__);
|
||||
HdfSbufRecycle(buf);
|
||||
return HDF_ERR_IO;
|
||||
}
|
||||
|
||||
ret = service->dispatcher->Dispatch(&service->object, TIMER_IO_SETONCE, buf, NULL);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: TIMER_IO_SETONCE service process fail:%d", __func__, ret);
|
||||
HdfSbufRecycle(buf);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
HdfSbufRecycle(buf);
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t HwTimerGet(DevHandle handle, uint32_t *useconds, bool *isPeriod)
|
||||
{
|
||||
int32_t ret = HDF_SUCCESS;
|
||||
struct HdfIoService *service = NULL;
|
||||
struct HdfSBuf *data = NULL;
|
||||
const void *rBuf = NULL;
|
||||
struct HdfSBuf *reply = NULL;
|
||||
struct TimerConfig cfg;
|
||||
uint32_t rLen;
|
||||
|
||||
if ((handle == NULL) || (useconds == NULL) || (isPeriod == NULL)) {
|
||||
HDF_LOGE("%s: param is invalid", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
service = (struct HdfIoService *)TimerManagerGetService();
|
||||
if (service == NULL || service->dispatcher == NULL || service->dispatcher->Dispatch == NULL) {
|
||||
HDF_LOGE("%s: service is invalid", __func__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
data = HdfSbufObtainDefaultSize();
|
||||
if (data == NULL) {
|
||||
HDF_LOGE("%s: HdfSBufObtainDefaultSize fail!", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
reply = HdfSbufObtainDefaultSize();
|
||||
if (reply == NULL) {
|
||||
HDF_LOGE("%s: failed to obtain reply", __func__);
|
||||
ret = HDF_ERR_MALLOC_FAIL;
|
||||
goto __EXIT;
|
||||
}
|
||||
|
||||
if (!HdfSbufWriteUint32(data, (uint32_t)(uintptr_t)handle)) {
|
||||
HDF_LOGE("%s: write handle fail!", __func__);
|
||||
ret = HDF_FAILURE;
|
||||
goto __EXIT;
|
||||
}
|
||||
|
||||
ret = service->dispatcher->Dispatch(&service->object, TIMER_IO_GET, data, reply);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: TIMER_IO_GET service process fail:%d", __func__, ret);
|
||||
ret = HDF_FAILURE;
|
||||
goto __EXIT;
|
||||
}
|
||||
|
||||
if (!HdfSbufReadBuffer(reply, &rBuf, &rLen)) {
|
||||
HDF_LOGE("%s: sbuf read buffer failed", __func__);
|
||||
ret = HDF_ERR_IO;
|
||||
goto __EXIT;
|
||||
}
|
||||
if (rLen != sizeof(struct TimerConfig)) {
|
||||
HDF_LOGE("%s: sbuf read buffer len error %u != %zu", __func__, rLen, sizeof(struct TimerConfig));
|
||||
ret = HDF_FAILURE;
|
||||
goto __EXIT;
|
||||
}
|
||||
if (memcpy_s(&cfg, sizeof(struct TimerConfig), rBuf, rLen) != EOK) {
|
||||
HDF_LOGE("%s: memcpy rBuf failed", __func__);
|
||||
ret = HDF_ERR_IO;
|
||||
goto __EXIT;
|
||||
}
|
||||
|
||||
*useconds = cfg.useconds;
|
||||
*isPeriod = cfg.isPeriod;
|
||||
|
||||
__EXIT:
|
||||
HdfSbufRecycle(data);
|
||||
HdfSbufRecycle(reply);
|
||||
return ret;
|
||||
}
|
||||
@@ -15,21 +15,11 @@
|
||||
#include <string>
|
||||
#include <unistd.h>
|
||||
#include "hdf_uhdf_test.h"
|
||||
#include "timer_test.h"
|
||||
#include "hdf_io_service_if.h"
|
||||
|
||||
using namespace testing::ext;
|
||||
|
||||
enum TimerTestCmd {
|
||||
TIMER_START_TEST = 1,
|
||||
TIMER_TEST_SET,
|
||||
TIMER_TEST_SETONCE,
|
||||
TIMER_TEST_GET,
|
||||
TIMER_TEST_START,
|
||||
TIMER_TEST_STOP,
|
||||
TIMER_MULTI_THREAD_TEST,
|
||||
TIMER_RELIABILITY_TEST,
|
||||
};
|
||||
|
||||
class HdfLiteTimerTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase();
|
||||
@@ -65,6 +55,7 @@ HWTEST_F(HdfLiteTimerTest, TimerTestSet001, TestSize.Level1)
|
||||
{
|
||||
struct HdfTestMsg msg = {TEST_PAL_TIMER_TYPE, TIMER_TEST_SET, -1};
|
||||
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
|
||||
EXPECT_EQ(0, TimerTestExecute(TIMER_TEST_SET));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -77,6 +68,7 @@ HWTEST_F(HdfLiteTimerTest, TimerTestSetOnce001, TestSize.Level1)
|
||||
{
|
||||
struct HdfTestMsg msg = {TEST_PAL_TIMER_TYPE, TIMER_TEST_SETONCE, -1};
|
||||
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
|
||||
EXPECT_EQ(0, TimerTestExecute(TIMER_TEST_SETONCE));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -89,6 +81,7 @@ HWTEST_F(HdfLiteTimerTest, TimerTestGet001, TestSize.Level1)
|
||||
{
|
||||
struct HdfTestMsg msg = {TEST_PAL_TIMER_TYPE, TIMER_TEST_GET, -1};
|
||||
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
|
||||
EXPECT_EQ(0, TimerTestExecute(TIMER_TEST_GET));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -101,6 +94,7 @@ HWTEST_F(HdfLiteTimerTest, TimerTestStart001, TestSize.Level1)
|
||||
{
|
||||
struct HdfTestMsg msg = {TEST_PAL_TIMER_TYPE, TIMER_TEST_START, -1};
|
||||
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
|
||||
EXPECT_EQ(0, TimerTestExecute(TIMER_TEST_START));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -113,6 +107,7 @@ HWTEST_F(HdfLiteTimerTest, TimerTestStop001, TestSize.Level1)
|
||||
{
|
||||
struct HdfTestMsg msg = {TEST_PAL_TIMER_TYPE, TIMER_TEST_STOP, -1};
|
||||
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
|
||||
EXPECT_EQ(0, TimerTestExecute(TIMER_TEST_STOP));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -125,6 +120,7 @@ HWTEST_F(HdfLiteTimerTest, TimerTestMultiThread001, TestSize.Level1)
|
||||
{
|
||||
struct HdfTestMsg msg = {TEST_PAL_TIMER_TYPE, TIMER_MULTI_THREAD_TEST, -1};
|
||||
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
|
||||
EXPECT_EQ(0, TimerTestExecute(TIMER_MULTI_THREAD_TEST));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -137,4 +133,5 @@ HWTEST_F(HdfLiteTimerTest, TimerTestReliability001, TestSize.Level1)
|
||||
{
|
||||
struct HdfTestMsg msg = {TEST_PAL_TIMER_TYPE, TIMER_RELIABILITY_TEST, -1};
|
||||
EXPECT_EQ(0, HdfTestSendMsgToService(&msg));
|
||||
EXPECT_EQ(0, TimerTestExecute(TIMER_RELIABILITY_TEST));
|
||||
}
|
||||
|
||||
+119
@@ -0,0 +1,119 @@
|
||||
/*
|
||||
* 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 "timer_test.h"
|
||||
#include "device_resource_if.h"
|
||||
#include "hdf_base.h"
|
||||
#include "hdf_device_desc.h"
|
||||
#include "hdf_log.h"
|
||||
|
||||
#define HDF_LOG_TAG timer_driver_test_c
|
||||
|
||||
static struct TimerTestConfig g_config;
|
||||
|
||||
static int32_t TimerTestDispatch(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 {
|
||||
HDF_LOGE("%s: cmd not support", __func__);
|
||||
return HDF_ERR_NOT_SUPPORT;
|
||||
}
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t TimerTestReadConfig(struct TimerTestConfig *config, const struct DeviceResourceNode *node)
|
||||
{
|
||||
int32_t ret;
|
||||
struct DeviceResourceIface *face = NULL;
|
||||
|
||||
face = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
|
||||
if (face == NULL) {
|
||||
HDF_LOGE("%s: face is null", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
if (face->GetUint32 == NULL) {
|
||||
HDF_LOGE("%s: GetUint32 not support", __func__);
|
||||
return HDF_ERR_NOT_SUPPORT;
|
||||
}
|
||||
|
||||
ret = face->GetUint32(node, "number", &config->number, 0);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: read id fail!", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
ret = face->GetUint32(node, "useconds", &config->uSecond, 0);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: read useconds fail!", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
ret = face->GetUint32(node, "isPeriod", &config->isPeriod, 0);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: read isPeriod fail!", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
HDF_LOGD("timer test init:number[%u][%u][%d]", config->number, config->uSecond, config->isPeriod);
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t TimerTestBind(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_INVALID_OBJECT;
|
||||
}
|
||||
|
||||
ret = TimerTestReadConfig(&g_config, device->property);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: read config failed", __func__);
|
||||
return ret;
|
||||
}
|
||||
|
||||
service.Dispatch = TimerTestDispatch;
|
||||
device->service = &service;
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t TimerTestInit(struct HdfDeviceObject *device)
|
||||
{
|
||||
(void)device;
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
static void TimerTestRelease(struct HdfDeviceObject *device)
|
||||
{
|
||||
if (device != NULL) {
|
||||
device->service = NULL;
|
||||
}
|
||||
HDF_LOGI("%s: Done!", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
struct HdfDriverEntry g_timerTestEntry = {
|
||||
.moduleVersion = 1,
|
||||
.Bind = TimerTestBind,
|
||||
.Init = TimerTestInit,
|
||||
.Release = TimerTestRelease,
|
||||
.moduleName = "PLATFORM_TIMER_TEST",
|
||||
};
|
||||
HDF_INIT(g_timerTestEntry);
|
||||
@@ -8,18 +8,21 @@
|
||||
|
||||
#include "timer_test.h"
|
||||
#include "device_resource_if.h"
|
||||
#include "hdf_io_service_if.h"
|
||||
#include "hdf_log.h"
|
||||
#include "osal_thread.h"
|
||||
#include "osal_mem.h"
|
||||
#include "osal_time.h"
|
||||
#include "securec.h"
|
||||
#include "timer_if.h"
|
||||
|
||||
#define HDF_LOG_TAG timer_test_c
|
||||
|
||||
static bool g_theard1Flag;
|
||||
static bool g_theard2Flag;
|
||||
static bool g_theard1Flag = false;
|
||||
static bool g_theard2Flag = false;
|
||||
|
||||
struct TimerTestFunc {
|
||||
enum TimerTestCmd type;
|
||||
int type;
|
||||
int32_t (*Func)(struct TimerTest *test);
|
||||
};
|
||||
|
||||
@@ -48,7 +51,7 @@ static int32_t TimerSetTest(struct TimerTest *test)
|
||||
return HDF_ERR_INVALID_OBJECT;
|
||||
}
|
||||
|
||||
TimerSet(test->handle, test->uSecond, TimerTestcaseCb);
|
||||
HwTimerSet(test->handle, test->uSecond, TimerTestcaseCb);
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -59,7 +62,7 @@ static int32_t TimerSetOnceTest(struct TimerTest *test)
|
||||
return HDF_ERR_INVALID_OBJECT;
|
||||
}
|
||||
|
||||
TimerSetOnce(test->handle, test->uSecond, TimerTestcaseOnceCb);
|
||||
HwTimerSetOnce(test->handle, test->uSecond, TimerTestcaseOnceCb);
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -73,7 +76,7 @@ static int32_t TimerGetTest(struct TimerTest *test)
|
||||
uint32_t uSecond;
|
||||
bool isPeriod;
|
||||
|
||||
if (TimerGet(test->handle, &uSecond, &isPeriod) != HDF_SUCCESS) {
|
||||
if (HwTimerGet(test->handle, &uSecond, &isPeriod) != HDF_SUCCESS) {
|
||||
HDF_LOGE("func: %s, TimerGet dailed", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
@@ -89,7 +92,7 @@ static int32_t TimerStartTest(struct TimerTest *test)
|
||||
return HDF_ERR_INVALID_OBJECT;
|
||||
}
|
||||
|
||||
TimerStart(test->handle);
|
||||
HwTimerStart(test->handle);
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -100,7 +103,7 @@ static int32_t TimerStopTest(struct TimerTest *test)
|
||||
return HDF_ERR_INVALID_OBJECT;
|
||||
}
|
||||
|
||||
TimerStop(test->handle);
|
||||
HwTimerStop(test->handle);
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -113,13 +116,13 @@ static int TimerOnceTestThreadFunc(void *param)
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
if(TimerSetOnce(handle, TIMER_TEST_TIME_USECONDS, TimerTestcaseOnceCb) != HDF_SUCCESS) {
|
||||
if(HwTimerSetOnce(handle, TIMER_TEST_TIME_USECONDS, TimerTestcaseOnceCb) != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: TimerSetOnce fail", __func__);
|
||||
g_theard1Flag = true;
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
if (TimerStart(handle) != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: TimerStart fail", __func__);
|
||||
if (HwTimerStart(handle) != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: HwTimerStart fail", __func__);
|
||||
g_theard1Flag = true;
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
@@ -135,13 +138,13 @@ static int TimerPeriodTestThreadFunc(void *param)
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
if(TimerSet(handle, TIMER_TEST_TIME_USECONDS, TimerTestcaseCb) != HDF_SUCCESS) {
|
||||
if(HwTimerSet(handle, TIMER_TEST_TIME_USECONDS, TimerTestcaseCb) != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: TimerSet fail", __func__);
|
||||
g_theard2Flag = true;
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
if (TimerStart(handle) != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: TimerStart fail", __func__);
|
||||
if (HwTimerStart(handle) != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: HwTimerStart fail", __func__);
|
||||
g_theard2Flag = true;
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
@@ -164,13 +167,13 @@ int32_t TimerTestMultiThread(struct TimerTest *test)
|
||||
thread2.realThread = NULL;
|
||||
|
||||
do {
|
||||
handle1 = TimerOpen(TIMER_TEST_TIME_ID_THREAD1);
|
||||
handle1 = HwTimerOpen(TIMER_TEST_TIME_ID_THREAD1);
|
||||
if (handle1 == NULL) {
|
||||
HDF_LOGE("%s: timer test get handle1 fail", __func__);
|
||||
ret = HDF_FAILURE;
|
||||
break;
|
||||
}
|
||||
handle2 = TimerOpen(TIMER_TEST_TIME_ID_THREAD2);
|
||||
handle2 = HwTimerOpen(TIMER_TEST_TIME_ID_THREAD2);
|
||||
if (handle1 == NULL) {
|
||||
HDF_LOGE("%s: timer test get handle2 fail", __func__);
|
||||
ret = HDF_FAILURE;
|
||||
@@ -222,11 +225,11 @@ int32_t TimerTestMultiThread(struct TimerTest *test)
|
||||
} while(0);
|
||||
|
||||
if (handle1 != NULL) {
|
||||
TimerClose(handle1);
|
||||
HwTimerClose(handle1);
|
||||
handle1 = NULL;
|
||||
}
|
||||
if (handle2 != NULL) {
|
||||
TimerClose(handle2);
|
||||
HwTimerClose(handle2);
|
||||
handle2 = NULL;
|
||||
}
|
||||
if (thread1.realThread != NULL) {
|
||||
@@ -247,34 +250,122 @@ int32_t TimerTestReliability(struct TimerTest *test)
|
||||
return HDF_ERR_INVALID_OBJECT;
|
||||
}
|
||||
|
||||
TimerSet(test->handle, test->uSecond, NULL);
|
||||
TimerSetOnce(test->handle, test->uSecond, NULL);
|
||||
TimerStart(NULL);
|
||||
HwTimerSet(test->handle, test->uSecond, NULL);
|
||||
HwTimerSetOnce(test->handle, test->uSecond, NULL);
|
||||
HwTimerStart(NULL);
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t TimerTestGetConfig(struct TimerTestConfig *config)
|
||||
{
|
||||
int32_t ret;
|
||||
struct HdfSBuf *reply = NULL;
|
||||
struct HdfIoService *service = NULL;
|
||||
const void *buf = NULL;
|
||||
uint32_t len;
|
||||
|
||||
if (config == NULL) {
|
||||
HDF_LOGE("%s: param null", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
service = HdfIoServiceBind("TIMER_TEST");
|
||||
if (service == NULL) {
|
||||
HDF_LOGE("%s: service TIMER_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__);
|
||||
return HDF_ERR_MALLOC_FAIL;
|
||||
}
|
||||
|
||||
ret = service->dispatcher->Dispatch(&service->object, 0, NULL, reply);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: remote dispatch failed", __func__);
|
||||
HdfSbufRecycle(reply);
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (!HdfSbufReadBuffer(reply, &buf, &len)) {
|
||||
HDF_LOGE("%s: read buf failed", __func__);
|
||||
HdfSbufRecycle(reply);
|
||||
HdfIoServiceRecycle(service);
|
||||
return HDF_ERR_IO;
|
||||
}
|
||||
|
||||
if (len != sizeof(*config)) {
|
||||
HDF_LOGE("%s: config size:%zu, read size:%u", __func__, sizeof(*config), len);
|
||||
HdfSbufRecycle(reply);
|
||||
HdfIoServiceRecycle(service);
|
||||
return HDF_ERR_IO;
|
||||
}
|
||||
|
||||
if (memcpy_s(config, sizeof(*config), buf, sizeof(*config)) != EOK) {
|
||||
HDF_LOGE("%s: memcpy buf failed", __func__);
|
||||
HdfSbufRecycle(reply);
|
||||
HdfIoServiceRecycle(service);
|
||||
return HDF_ERR_IO;
|
||||
}
|
||||
|
||||
HdfSbufRecycle(reply);
|
||||
HdfIoServiceRecycle(service);
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
struct TimerTest *TimerTestGet(void)
|
||||
{
|
||||
int32_t ret;
|
||||
static struct TimerTest tester;
|
||||
static bool hasInit = false;
|
||||
|
||||
if (hasInit) {
|
||||
return &tester;
|
||||
}
|
||||
|
||||
struct TimerTestConfig config;
|
||||
ret = TimerTestGetConfig(&config);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: read config failed:%d", __func__, ret);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
tester.number = config.number;
|
||||
tester.uSecond = config.uSecond;
|
||||
tester.isPeriod = config.isPeriod;
|
||||
hasInit = true;
|
||||
return &tester;
|
||||
}
|
||||
|
||||
static struct TimerTestFunc g_timerTestFunc[] = {
|
||||
{TIMER_TEST_SET, TimerSetTest},
|
||||
{TIMER_TEST_SETONCE, TimerSetOnceTest},
|
||||
{TIMER_TEST_GET, TimerGetTest},
|
||||
{TIMER_TEST_START, TimerStartTest},
|
||||
{TIMER_TEST_STOP, TimerStopTest},
|
||||
{TIMER_RELIABILITY_TEST, TimerTestMultiThread},
|
||||
{TIMER_MULTI_THREAD_TEST, TimerTestReliability},
|
||||
{TIMER_MULTI_THREAD_TEST, TimerTestMultiThread},
|
||||
{TIMER_RELIABILITY_TEST, TimerTestReliability},
|
||||
};
|
||||
|
||||
static int32_t TimerTestEntry(struct TimerTest *test, int32_t cmd)
|
||||
int32_t TimerTestExecute(int cmd)
|
||||
{
|
||||
int32_t i;
|
||||
uint32_t i;
|
||||
int32_t ret = HDF_ERR_NOT_SUPPORT;
|
||||
|
||||
if (cmd > TIMER_RELIABILITY_TEST) {
|
||||
HDF_LOGE("%s: invalid cmd:%d", __func__, cmd);
|
||||
return HDF_ERR_NOT_SUPPORT;
|
||||
}
|
||||
|
||||
struct TimerTest *test = TimerTestGet();
|
||||
if (test == NULL) {
|
||||
HDF_LOGE("%s: test null cmd %d", __func__, cmd);
|
||||
return HDF_ERR_INVALID_OBJECT;
|
||||
}
|
||||
|
||||
if (cmd != TIMER_MULTI_THREAD_TEST) {
|
||||
test->handle = TimerOpen(test->number);
|
||||
test->handle = HwTimerOpen(test->number);
|
||||
if (test->handle == NULL) {
|
||||
HDF_LOGE("%s: timer test get handle fail", __func__);
|
||||
return HDF_FAILURE;
|
||||
@@ -289,96 +380,8 @@ static int32_t TimerTestEntry(struct TimerTest *test, int32_t cmd)
|
||||
}
|
||||
|
||||
if (cmd != TIMER_MULTI_THREAD_TEST) {
|
||||
TimerClose(test->handle);
|
||||
HwTimerClose(test->handle);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int32_t TimerTestBind(struct HdfDeviceObject *device)
|
||||
{
|
||||
static struct TimerTest test;
|
||||
|
||||
if (device != NULL) {
|
||||
device->service = &test.service;
|
||||
} else {
|
||||
HDF_LOGE("%s: device is NULL", __func__);
|
||||
}
|
||||
|
||||
HDF_LOGD("%s: success", __func__);
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t TimerTestInitFromHcs(struct TimerTest *test, const struct DeviceResourceNode *node)
|
||||
{
|
||||
int32_t ret;
|
||||
struct DeviceResourceIface *face = NULL;
|
||||
|
||||
face = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
|
||||
if (face == NULL) {
|
||||
HDF_LOGE("%s: face is null", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
if (face->GetUint32 == NULL) {
|
||||
HDF_LOGE("%s: GetUint32 not support", __func__);
|
||||
return HDF_ERR_NOT_SUPPORT;
|
||||
}
|
||||
|
||||
ret = face->GetUint32(node, "number", &test->number, 0);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: read id fail!", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
ret = face->GetUint32(node, "useconds", &test->uSecond, 0);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: read useconds fail!", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
ret = face->GetUint32(node, "isPeriod", &test->isPeriod, 0);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: read isPeriod fail!", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
HDF_LOGD("timer test init:number[%u][%u][%d]", test->number, test->uSecond, test->isPeriod);
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t TimerTestInit(struct HdfDeviceObject *device)
|
||||
{
|
||||
struct TimerTest *test = NULL;
|
||||
|
||||
if (device == NULL || device->service == NULL || device->property == NULL) {
|
||||
HDF_LOGE("%s: invalid parameter", __func__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
test = (struct TimerTest *)device->service;
|
||||
|
||||
if (TimerTestInitFromHcs(test, device->property) != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: RegulatorTestInitFromHcs failed", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
test->TestEntry = TimerTestEntry;
|
||||
g_theard1Flag = false;
|
||||
g_theard2Flag = false;
|
||||
HDF_LOGD("%s: success", __func__);
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
static void TimerTestRelease(struct HdfDeviceObject *device)
|
||||
{
|
||||
(void)device;
|
||||
}
|
||||
|
||||
struct HdfDriverEntry g_timerTestEntry = {
|
||||
.moduleVersion = 1,
|
||||
.Bind = TimerTestBind,
|
||||
.Init = TimerTestInit,
|
||||
.Release = TimerTestRelease,
|
||||
.moduleName = "PLATFORM_TIMER_TEST",
|
||||
};
|
||||
HDF_INIT(g_timerTestEntry);
|
||||
|
||||
@@ -9,9 +9,12 @@
|
||||
#ifndef TIMER_TEST_H
|
||||
#define TIMER_TEST_H
|
||||
|
||||
#include "hdf_device_desc.h"
|
||||
#include "platform_if.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
enum TimerTestCmd {
|
||||
TIMER_START_TEST = 1,
|
||||
TIMER_TEST_SET,
|
||||
@@ -24,7 +27,7 @@ enum TimerTestCmd {
|
||||
};
|
||||
|
||||
#define TIMER_TEST_STACK_SIZE (1024 * 100)
|
||||
#define TIMER_TEST_WAIT_TIMES 20
|
||||
#define TIMER_TEST_WAIT_TIMES 4
|
||||
#define TIMER_TEST_WAIT_TIMEOUT 5
|
||||
#define TIMER_TEST_PERIOD_TIMES 2
|
||||
|
||||
@@ -32,19 +35,23 @@ enum TimerTestCmd {
|
||||
#define TIMER_TEST_TIME_ID_THREAD2 5
|
||||
#define TIMER_TEST_TIME_USECONDS 5000
|
||||
|
||||
struct TimerTestConfig {
|
||||
uint32_t number;
|
||||
uint32_t uSecond;
|
||||
uint32_t isPeriod;
|
||||
};
|
||||
|
||||
struct TimerTest {
|
||||
struct IDeviceIoService service;
|
||||
struct HdfDeviceObject *device;
|
||||
int32_t (*TestEntry)(struct TimerTest *test, int32_t cmd);
|
||||
DevHandle handle;
|
||||
uint32_t number;
|
||||
uint32_t uSecond;
|
||||
uint32_t isPeriod;
|
||||
};
|
||||
|
||||
static inline struct TimerTest *GetTimerTest(void)
|
||||
{
|
||||
return (struct TimerTest *)DevSvcManagerClntGetService("TIMER_TEST");
|
||||
int32_t TimerTestExecute(int cmd);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* TIMER_TEST_H */
|
||||
|
||||
@@ -14,17 +14,10 @@
|
||||
|
||||
int32_t HdfTimerUnitTestEntry(HdfTestMsg *msg)
|
||||
{
|
||||
struct TimerTest *test = NULL;
|
||||
|
||||
if (msg == NULL) {
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
test = GetTimerTest();
|
||||
if (test == NULL || test->TestEntry == NULL) {
|
||||
HDF_LOGE("%s: tester is NULL!\n", __func__);
|
||||
msg->result = HDF_FAILURE;
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
msg->result = test->TestEntry(test, msg->subCmd);
|
||||
|
||||
msg->result = TimerTestExecute(msg->subCmd);
|
||||
return msg->result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user