mirror of
https://github.com/openharmony/drivers_framework.git
synced 2026-08-27 10:51:15 -04:00
modify sensor model driver
Signed-off-by: kevin <liufeihu@huawei.com> Change-Id: I0f773de2029daabcfa61381eb1b787d3b096dcd2
This commit is contained in:
@@ -12,7 +12,6 @@
|
||||
#include "hdf_device_desc.h"
|
||||
#include "osal_math.h"
|
||||
#include "osal_mem.h"
|
||||
#include "osal_time.h"
|
||||
#include "sensor_accel_driver.h"
|
||||
#include "sensor_config_controller.h"
|
||||
#include "sensor_device_manager.h"
|
||||
@@ -20,20 +19,17 @@
|
||||
|
||||
#define HDF_LOG_TAG sensor_accel_driver_c
|
||||
|
||||
#define HDF_ACCEL_WORK_QUEUE_NAME "hdf_accel_work_queue"
|
||||
|
||||
static struct AccelDetectIfList g_accelDetectIfList[] = {
|
||||
{ACCEL_CHIP_NAME_BMI160, DetectAccelBim160Chip},
|
||||
};
|
||||
|
||||
static struct AccelDrvData *g_accelDrvData = NULL;
|
||||
|
||||
static struct AccelDrvData *AccelGetDrvData(void)
|
||||
{
|
||||
static struct AccelDrvData accelDrvData = {
|
||||
.threadStatus = SENSOR_THREAD_NONE,
|
||||
.initStatus = false,
|
||||
.detectFlag = false,
|
||||
.interval = ACC_DEFAULT_SAMPLING_200_MS,
|
||||
};
|
||||
|
||||
return &accelDrvData;
|
||||
return g_accelDrvData;
|
||||
}
|
||||
|
||||
static struct SensorRegCfgGroupNode *g_regCfgGroup[SENSOR_GROUP_MAX] = { NULL };
|
||||
@@ -45,61 +41,62 @@ int32_t RegisterAccelChipOps(const struct AccelOpsCall *ops)
|
||||
CHECK_NULL_PTR_RETURN_VALUE(ops, HDF_ERR_INVALID_PARAM);
|
||||
|
||||
drvData = AccelGetDrvData();
|
||||
CHECK_NULL_PTR_RETURN_VALUE(drvData, HDF_ERR_INVALID_PARAM);
|
||||
drvData->ops.Init = ops->Init;
|
||||
drvData->ops.ReadData = ops->ReadData;
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t ReadAccelDataThreadWorker(void *arg)
|
||||
static void AccelDataWorkEntry(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
int64_t interval;
|
||||
struct AccelDrvData *drvData = NULL;
|
||||
int32_t ret;
|
||||
struct AccelDrvData *drvData = (struct AccelDrvData *)arg;
|
||||
CHECK_NULL_PTR_RETURN(drvData);
|
||||
CHECK_NULL_PTR_RETURN(drvData->ops.ReadData);
|
||||
|
||||
drvData = AccelGetDrvData();
|
||||
drvData->threadStatus = SENSOR_THREAD_START;
|
||||
while (true) {
|
||||
if (drvData->threadStatus == SENSOR_THREAD_RUNNING) {
|
||||
if (drvData->ops.ReadData != NULL) {
|
||||
(void)drvData->ops.ReadData(drvData->accelCfg);
|
||||
}
|
||||
|
||||
interval = OsalDivS64(drvData->interval, (SENSOR_CONVERT_UNIT * SENSOR_CONVERT_UNIT));
|
||||
OsalMSleep(interval);
|
||||
} else if (drvData->threadStatus == SENSOR_THREAD_STOPPING) {
|
||||
drvData->threadStatus = SENSOR_THREAD_STOPPED;
|
||||
break;
|
||||
} else {
|
||||
OsalMSleep(ACC_DEFAULT_SAMPLING_200_MS / SENSOR_CONVERT_UNIT / SENSOR_CONVERT_UNIT);
|
||||
}
|
||||
|
||||
if ((!drvData->initStatus) || (drvData->interval < 0) || drvData->threadStatus != SENSOR_THREAD_RUNNING) {
|
||||
continue;
|
||||
}
|
||||
ret = drvData->ops.ReadData(drvData->accelCfg);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: accel read data failed", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
HDF_LOGD("%s: accel thread have exited", __func__);
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t InitAccelConfig(void)
|
||||
static void AccelTimerEntry(uintptr_t arg)
|
||||
{
|
||||
int64_t interval;
|
||||
int32_t ret;
|
||||
struct AccelDrvData *drvData = (struct AccelDrvData *)arg;
|
||||
CHECK_NULL_PTR_RETURN(drvData);
|
||||
|
||||
if (!HdfAddWork(&drvData->accelWorkQueue, &drvData->accelWork)) {
|
||||
HDF_LOGE("%s: accel add work queue failed", __func__);
|
||||
}
|
||||
|
||||
interval = OsalDivS64(drvData->interval, (SENSOR_CONVERT_UNIT * SENSOR_CONVERT_UNIT));
|
||||
interval = (interval < SENSOR_TIMER_MIN_TIME) ? SENSOR_TIMER_MIN_TIME : interval;
|
||||
ret = OsalTimerSetTimeout(&drvData->accelTimer, interval);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: accel modify time failed", __func__);
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t InitAccelData(void)
|
||||
{
|
||||
struct AccelDrvData *drvData = AccelGetDrvData();
|
||||
int32_t ret;
|
||||
CHECK_NULL_PTR_RETURN_VALUE(drvData, HDF_ERR_INVALID_PARAM);
|
||||
|
||||
if (drvData->initStatus) {
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
if (drvData->threadStatus != SENSOR_THREAD_NONE && drvData->threadStatus != SENSOR_THREAD_DESTROY) {
|
||||
HDF_LOGE("%s: accel thread have created", __func__);
|
||||
return HDF_SUCCESS;
|
||||
if (HdfWorkQueueInit(&drvData->accelWorkQueue, HDF_ACCEL_WORK_QUEUE_NAME) != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: accel init work queue failed", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
ret = CreateSensorThread(&drvData->thread, ReadAccelDataThreadWorker, "hdf_sensor_accel", drvData);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
if (HdfWorkInit(&drvData->accelWork, AccelDataWorkEntry, drvData) != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: accel create thread failed", __func__);
|
||||
drvData->threadStatus = SENSOR_THREAD_STOPPING;
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
@@ -108,17 +105,12 @@ static int32_t InitAccelConfig(void)
|
||||
ret = drvData->ops.Init(drvData->accelCfg);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: accel create thread failed", __func__);
|
||||
drvData->threadStatus = SENSOR_THREAD_STOPPING;
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
drvData->interval = SENSOR_TIMER_MIN_TIME;
|
||||
drvData->initStatus = true;
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t SetAccelInfo(struct SensorBasicInfo *info)
|
||||
{
|
||||
(void)info;
|
||||
drvData->enable = false;
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
@@ -128,14 +120,32 @@ static int32_t SetAccelEnable(void)
|
||||
int32_t ret;
|
||||
struct AccelDrvData *drvData = AccelGetDrvData();
|
||||
|
||||
CHECK_NULL_PTR_RETURN_VALUE(drvData, HDF_ERR_INVALID_PARAM);
|
||||
CHECK_NULL_PTR_RETURN_VALUE(drvData->accelCfg, HDF_ERR_INVALID_PARAM);
|
||||
|
||||
if (drvData->enable) {
|
||||
HDF_LOGE("%s: accel sensor is enabled", __func__);
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
ret = SetSensorRegCfgArray(&drvData->accelCfg->busCfg, drvData->accelCfg->regCfgGroup[SENSOR_ENABLE_GROUP]);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: accel sensor enable config failed", __func__);
|
||||
return HDF_FAILURE;
|
||||
return ret;
|
||||
}
|
||||
|
||||
drvData->threadStatus = SENSOR_THREAD_RUNNING;
|
||||
ret = OsalTimerCreate(&drvData->accelTimer, SENSOR_TIMER_MIN_TIME, AccelTimerEntry, (uintptr_t)drvData);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: accel create timer failed[%d]", __func__, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = OsalTimerStartLoop(&drvData->accelTimer);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: accel start timer failed[%d]", __func__, ret);
|
||||
return ret;
|
||||
}
|
||||
drvData->enable = true;
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
@@ -145,16 +155,26 @@ static int32_t SetAccelDisable(void)
|
||||
int32_t ret;
|
||||
struct AccelDrvData *drvData = AccelGetDrvData();
|
||||
|
||||
CHECK_NULL_PTR_RETURN_VALUE(drvData, HDF_ERR_INVALID_PARAM);
|
||||
CHECK_NULL_PTR_RETURN_VALUE(drvData->accelCfg, HDF_ERR_INVALID_PARAM);
|
||||
|
||||
if (!drvData->enable) {
|
||||
HDF_LOGE("%s: accel sensor had disable", __func__);
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
ret = SetSensorRegCfgArray(&drvData->accelCfg->busCfg, drvData->accelCfg->regCfgGroup[SENSOR_DISABLE_GROUP]);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: accel sensor disable config failed", __func__);
|
||||
return HDF_FAILURE;
|
||||
return ret;
|
||||
}
|
||||
|
||||
drvData->threadStatus = SENSOR_THREAD_STOPPED;
|
||||
|
||||
ret = OsalTimerDelete(&drvData->accelTimer);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: accel delete timer failed", __func__);
|
||||
return ret;
|
||||
}
|
||||
drvData->enable = false;
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -165,6 +185,8 @@ static int32_t SetAccelBatch(int64_t samplingInterval, int64_t interval)
|
||||
struct AccelDrvData *drvData = NULL;
|
||||
|
||||
drvData = AccelGetDrvData();
|
||||
CHECK_NULL_PTR_RETURN_VALUE(drvData, HDF_ERR_INVALID_PARAM);
|
||||
|
||||
drvData->interval = samplingInterval;
|
||||
|
||||
return HDF_SUCCESS;
|
||||
@@ -196,12 +218,16 @@ int32_t BindAccelDriver(struct HdfDeviceObject *device)
|
||||
{
|
||||
CHECK_NULL_PTR_RETURN_VALUE(device, HDF_ERR_INVALID_PARAM);
|
||||
|
||||
static struct IDeviceIoService service = {
|
||||
.object = {0},
|
||||
.Dispatch = DispatchAccel,
|
||||
};
|
||||
device->service = &service;
|
||||
struct AccelDrvData *drvData = (struct AccelDrvData *)OsalMemCalloc(sizeof(*drvData));
|
||||
if (drvData == NULL) {
|
||||
HDF_LOGE("%s: malloc accel drv data fail!", __func__);
|
||||
return HDF_ERR_MALLOC_FAIL;
|
||||
}
|
||||
|
||||
drvData->ioService.Dispatch = DispatchAccel;
|
||||
drvData->device = device;
|
||||
device->service = &drvData->ioService;
|
||||
g_accelDrvData = drvData;
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -209,7 +235,8 @@ static int32_t InitAccelOps(struct SensorDeviceInfo *deviceInfo)
|
||||
{
|
||||
struct AccelDrvData *drvData = AccelGetDrvData();
|
||||
|
||||
deviceInfo->ops.GetInfo = SetAccelInfo;
|
||||
CHECK_NULL_PTR_RETURN_VALUE(drvData, HDF_ERR_INVALID_PARAM);
|
||||
|
||||
deviceInfo->ops.Enable = SetAccelEnable;
|
||||
deviceInfo->ops.Disable = SetAccelDisable;
|
||||
deviceInfo->ops.SetBatch = SetAccelBatch;
|
||||
@@ -222,9 +249,6 @@ static int32_t InitAccelOps(struct SensorDeviceInfo *deviceInfo)
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
drvData->accelCfg->sensorInfo.sensorTypeId = SENSOR_TAG_ACCELEROMETER;
|
||||
drvData->accelCfg->sensorInfo.sensorId = SENSOR_TAG_ACCELEROMETER;
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -232,7 +256,7 @@ static int32_t InitAccelAfterConfig(void)
|
||||
{
|
||||
struct SensorDeviceInfo deviceInfo;
|
||||
|
||||
if (InitAccelConfig() != HDF_SUCCESS) {
|
||||
if (InitAccelData() != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: init accel config failed", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
@@ -256,6 +280,8 @@ static int32_t DetectAccelChip(void)
|
||||
int32_t ret;
|
||||
int32_t loop;
|
||||
struct AccelDrvData *drvData = AccelGetDrvData();
|
||||
|
||||
CHECK_NULL_PTR_RETURN_VALUE(drvData, HDF_ERR_INVALID_PARAM);
|
||||
CHECK_NULL_PTR_RETURN_VALUE(drvData->accelCfg, HDF_ERR_INVALID_PARAM);
|
||||
|
||||
num = sizeof(g_accelDetectIfList) / sizeof(g_accelDetectIfList[0]);
|
||||
@@ -264,30 +290,27 @@ static int32_t DetectAccelChip(void)
|
||||
ret = g_accelDetectIfList[loop].DetectChip(drvData->accelCfg);
|
||||
if (ret == HDF_SUCCESS) {
|
||||
drvData->detectFlag = true;
|
||||
break;
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (loop == num) {
|
||||
HDF_LOGE("%s: detect accel device failed", __func__);
|
||||
drvData->detectFlag = false;
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
return HDF_SUCCESS;
|
||||
HDF_LOGE("%s: detect accel device failed", __func__);
|
||||
drvData->detectFlag = false;
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
int32_t InitAccelDriver(struct HdfDeviceObject *device)
|
||||
{
|
||||
struct AccelDrvData *drvData = AccelGetDrvData();
|
||||
CHECK_NULL_PTR_RETURN_VALUE(device, HDF_ERR_INVALID_PARAM);
|
||||
struct AccelDrvData *drvData = (struct AccelDrvData *)device->service;
|
||||
CHECK_NULL_PTR_RETURN_VALUE(drvData, HDF_ERR_INVALID_PARAM);
|
||||
|
||||
if (drvData->detectFlag) {
|
||||
HDF_LOGE("%s: accel sensor have detected", __func__);
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
CHECK_NULL_PTR_RETURN_VALUE(device, HDF_ERR_INVALID_PARAM);
|
||||
|
||||
drvData->accelCfg = (struct SensorCfgData *)OsalMemCalloc(sizeof(*drvData->accelCfg));
|
||||
if (drvData->accelCfg == NULL) {
|
||||
HDF_LOGE("%s: malloc sensor config data failed", __func__);
|
||||
@@ -322,8 +345,7 @@ int32_t InitAccelDriver(struct HdfDeviceObject *device)
|
||||
return HDF_SUCCESS;
|
||||
|
||||
INIT_EXIT:
|
||||
DestroySensorThread(&drvData->thread, &drvData->threadStatus);
|
||||
(void)DeleteSensorDevice(SENSOR_TAG_ACCELEROMETER);
|
||||
(void)DeleteSensorDevice(&drvData->accelCfg->sensorInfo);
|
||||
REG_CONFIG_EXIT:
|
||||
ReleaseSensorAllRegConfig(drvData->accelCfg);
|
||||
(void)ReleaseSensorBusHandle(&drvData->accelCfg->busCfg);
|
||||
@@ -339,12 +361,12 @@ BASE_CONFIG_EXIT:
|
||||
|
||||
void ReleaseAccelDriver(struct HdfDeviceObject *device)
|
||||
{
|
||||
(void)device;
|
||||
struct AccelDrvData *drvData = NULL;
|
||||
CHECK_NULL_PTR_RETURN(device);
|
||||
|
||||
drvData = AccelGetDrvData();
|
||||
(void)DestroySensorThread(&drvData->thread, &drvData->threadStatus);
|
||||
(void)DeleteSensorDevice(SENSOR_TAG_ACCELEROMETER);
|
||||
struct AccelDrvData *drvData = (struct AccelDrvData *)device->service;
|
||||
CHECK_NULL_PTR_RETURN(drvData);
|
||||
|
||||
(void)DeleteSensorDevice(&drvData->accelCfg->sensorInfo);
|
||||
drvData->detectFlag = false;
|
||||
|
||||
if (drvData->accelCfg != NULL) {
|
||||
|
||||
@@ -9,7 +9,9 @@
|
||||
#ifndef SENSOR_ACCEL_DRIVER_H
|
||||
#define SENSOR_ACCEL_DRIVER_H
|
||||
|
||||
#include "osal_thread.h"
|
||||
#include "hdf_workqueue.h"
|
||||
#include "osal_mutex.h"
|
||||
#include "osal_timer.h"
|
||||
#include "sensor_config_parser.h"
|
||||
#include "sensor_platform_if.h"
|
||||
|
||||
@@ -50,12 +52,16 @@ struct AccelOpsCall {
|
||||
};
|
||||
|
||||
struct AccelDrvData {
|
||||
struct IDeviceIoService ioService;
|
||||
struct HdfDeviceObject *device;
|
||||
HdfWorkQueue accelWorkQueue;
|
||||
HdfWork accelWork;
|
||||
OsalTimer accelTimer;
|
||||
bool detectFlag;
|
||||
uint8_t threadStatus;
|
||||
uint8_t initStatus;
|
||||
bool enable;
|
||||
bool initStatus;
|
||||
int64_t interval;
|
||||
struct SensorCfgData *accelCfg;
|
||||
struct OsalThread thread;
|
||||
struct AccelOpsCall ops;
|
||||
};
|
||||
|
||||
|
||||
@@ -9,21 +9,24 @@
|
||||
#ifndef SENSOR_DEVICE_MANAGER_H
|
||||
#define SENSOR_DEVICE_MANAGER_H
|
||||
|
||||
#include "hdf_workqueue.h"
|
||||
#include "osal_mutex.h"
|
||||
#include "sensor_device_type.h"
|
||||
#include "sensor_device_if.h"
|
||||
|
||||
#define HDF_SENSOR_EVENT_QUEUE_NAME "hdf_sensor_event_queue"
|
||||
|
||||
enum SensorCmd {
|
||||
SENSOR_CMD_GET_INFO_LIST = 0,
|
||||
SENSOR_CMD_OPS = 1,
|
||||
SENSOR_CMD_END,
|
||||
};
|
||||
enum SensorOpsCmd {
|
||||
SENSOR_OPS_CMD_ENABLE = 1,
|
||||
SENSOR_OPS_CMD_DISABLE = 2,
|
||||
SENSOR_OPS_CMD_SET_BATCH = 3,
|
||||
SENSOR_OPS_CMD_SET_MODE = 4,
|
||||
SENSOR_OPS_CMD_SET_OPTION = 5,
|
||||
SENSOR_OPS_CMD_ENABLE = 0,
|
||||
SENSOR_OPS_CMD_DISABLE = 1,
|
||||
SENSOR_OPS_CMD_SET_BATCH = 2,
|
||||
SENSOR_OPS_CMD_SET_MODE = 3,
|
||||
SENSOR_OPS_CMD_SET_OPTION = 4,
|
||||
SENSOR_OPS_CMD_BUTT,
|
||||
};
|
||||
|
||||
|
||||
@@ -28,63 +28,63 @@ static struct SensorDevMgrData *GetSensorDeviceManager(void)
|
||||
|
||||
int32_t AddSensorDevice(const struct SensorDeviceInfo *deviceInfo)
|
||||
{
|
||||
bool existSensor = false;
|
||||
struct SensorDevInfoNode *pos = NULL;
|
||||
struct SensorDevInfoNode *tmp = NULL;
|
||||
struct SensorDevInfoNode *devInfoNode = NULL;
|
||||
struct SensorDevMgrData *manager = GetSensorDeviceManager();
|
||||
|
||||
CHECK_NULL_PTR_RETURN_VALUE(deviceInfo, HDF_ERR_INVALID_PARAM);
|
||||
CHECK_NULL_PTR_RETURN_VALUE(manager, HDF_ERR_INVALID_PARAM);
|
||||
|
||||
(void)OsalMutexLock(&manager->mutex);
|
||||
DLIST_FOR_EACH_ENTRY_SAFE(pos, tmp, &manager->sensorDevInfoHead, struct SensorDevInfoNode, node) {
|
||||
if (deviceInfo->sensorInfo.sensorId == pos->devInfo.sensorInfo.sensorId) {
|
||||
HDF_LOGE("%s: sensor chip[0x%x] had existed", __func__, deviceInfo->sensorInfo.sensorId);
|
||||
existSensor = true;
|
||||
break;
|
||||
DLIST_FOR_EACH_ENTRY(pos, &manager->sensorDevInfoHead, struct SensorDevInfoNode, node) {
|
||||
if ((deviceInfo->sensorInfo.sensorId == pos->devInfo.sensorInfo.sensorId) &&
|
||||
(strcmp(deviceInfo->sensorInfo.sensorName, pos->devInfo.sensorInfo.sensorName) == 0)) {
|
||||
HDF_LOGE("%{public}s: sensor id[%{public}d] had existed", __func__, deviceInfo->sensorInfo.sensorId);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
if (!existSensor) {
|
||||
devInfoNode = (struct SensorDevInfoNode*)OsalMemCalloc(sizeof(*devInfoNode));
|
||||
if (devInfoNode == NULL) {
|
||||
(void)OsalMutexUnlock(&manager->mutex);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
if (memcpy_s(&devInfoNode->devInfo, sizeof(devInfoNode->devInfo),
|
||||
(void *)deviceInfo, sizeof(*deviceInfo)) != EOK) {
|
||||
HDF_LOGE("%s: copy sensor info failed", __func__);
|
||||
OsalMemFree(devInfoNode);
|
||||
(void)OsalMutexUnlock(&manager->mutex);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
DListInsertTail(&devInfoNode->node, &manager->sensorDevInfoHead);
|
||||
HDF_LOGI("%s: register sensor device name[%s] success", __func__, deviceInfo->sensorInfo.sensorName);
|
||||
(void)OsalMutexLock(&manager->mutex);
|
||||
devInfoNode = (struct SensorDevInfoNode*)OsalMemCalloc(sizeof(*devInfoNode));
|
||||
if (devInfoNode == NULL) {
|
||||
(void)OsalMutexUnlock(&manager->mutex);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
if (memcpy_s(&devInfoNode->devInfo, sizeof(devInfoNode->devInfo),
|
||||
(void *)deviceInfo, sizeof(*deviceInfo)) != EOK) {
|
||||
HDF_LOGE("%{public}s: copy sensor info failed", __func__);
|
||||
OsalMemFree(devInfoNode);
|
||||
(void)OsalMutexUnlock(&manager->mutex);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
DListInsertTail(&devInfoNode->node, &manager->sensorDevInfoHead);
|
||||
(void)OsalMutexUnlock(&manager->mutex);
|
||||
HDF_LOGI("%{public}s: register sensor name[%{private}s] success", __func__, deviceInfo->sensorInfo.sensorName);
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t DeleteSensorDevice(int32_t sensorId)
|
||||
int32_t DeleteSensorDevice(const struct SensorBasicInfo *sensorBaseInfo)
|
||||
{
|
||||
struct SensorDevInfoNode *pos = NULL;
|
||||
struct SensorDevInfoNode *tmp = NULL;
|
||||
struct SensorDevMgrData *manager = GetSensorDeviceManager();
|
||||
|
||||
CHECK_NULL_PTR_RETURN_VALUE(sensorBaseInfo, HDF_ERR_INVALID_PARAM);
|
||||
CHECK_NULL_PTR_RETURN_VALUE(manager, HDF_ERR_INVALID_PARAM);
|
||||
|
||||
(void)OsalMutexLock(&manager->mutex);
|
||||
DLIST_FOR_EACH_ENTRY_SAFE(pos, tmp, &manager->sensorDevInfoHead, struct SensorDevInfoNode, node) {
|
||||
if (sensorId == pos->devInfo.sensorInfo.sensorId) {
|
||||
if ((sensorBaseInfo->sensorId == pos->devInfo.sensorInfo.sensorId) &&
|
||||
(strcmp(sensorBaseInfo->sensorName, pos->devInfo.sensorInfo.sensorName) == 0)) {
|
||||
DListRemove(&pos->node);
|
||||
OsalMemFree(pos);
|
||||
break;
|
||||
(void)OsalMutexUnlock(&manager->mutex);
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
}
|
||||
(void)OsalMutexUnlock(&manager->mutex);
|
||||
|
||||
return HDF_SUCCESS;
|
||||
HDF_LOGE("%{public}s: delete sensor id invalid para", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
int32_t ReportSensorEvent(const struct SensorReportEvent *events)
|
||||
@@ -132,7 +132,6 @@ static int32_t GetAllSensorInfo(struct HdfSBuf *data, struct HdfSBuf *reply)
|
||||
{
|
||||
(void)data;
|
||||
struct SensorDevInfoNode *pos = NULL;
|
||||
struct SensorDevInfoNode *tmp = NULL;
|
||||
struct SensorBasicInfo *sensorInfo = NULL;
|
||||
struct SensorDevMgrData *manager = GetSensorDeviceManager();
|
||||
int32_t count = 0;
|
||||
@@ -140,14 +139,12 @@ static int32_t GetAllSensorInfo(struct HdfSBuf *data, struct HdfSBuf *reply)
|
||||
CHECK_NULL_PTR_RETURN_VALUE(reply, HDF_ERR_INVALID_PARAM);
|
||||
CHECK_NULL_PTR_RETURN_VALUE(manager, HDF_ERR_INVALID_PARAM);
|
||||
|
||||
DLIST_FOR_EACH_ENTRY_SAFE(pos, tmp, &manager->sensorDevInfoHead, struct SensorDevInfoNode, node) {
|
||||
DLIST_FOR_EACH_ENTRY(pos, &manager->sensorDevInfoHead, struct SensorDevInfoNode, node) {
|
||||
sensorInfo = &(pos->devInfo.sensorInfo);
|
||||
if (!HdfSbufWriteBuffer(reply, sensorInfo, sizeof(*sensorInfo))) {
|
||||
|
||||
HDF_LOGE("%s: write sbuf failed", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
pos->devInfo.ops.GetInfo(NULL);
|
||||
|
||||
count++;
|
||||
if ((count + 1) * sizeof(*sensorInfo) > HDF_SENSOR_INFO_MAX_BUF) {
|
||||
@@ -240,25 +237,25 @@ static struct SensorCmdHandleList g_sensorCmdHandle[] = {
|
||||
|
||||
static int32_t DispatchCmdHandle(struct SensorDeviceInfo *deviceInfo, struct HdfSBuf *data, struct HdfSBuf *reply)
|
||||
{
|
||||
int32_t methodCmd;
|
||||
int32_t opsCmd;
|
||||
int32_t loop;
|
||||
int32_t count;
|
||||
|
||||
CHECK_NULL_PTR_RETURN_VALUE(data, HDF_ERR_INVALID_PARAM);
|
||||
|
||||
if (!HdfSbufReadInt32(data, &methodCmd)) {
|
||||
HDF_LOGE("%s: sbuf read methodCmd failed", __func__);
|
||||
if (!HdfSbufReadInt32(data, &opsCmd)) {
|
||||
HDF_LOGE("%s: sbuf read opsCmd failed", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
if (methodCmd >= SENSOR_OPS_CMD_BUTT || methodCmd <= 0) {
|
||||
HDF_LOGE("%s: invalid cmd = %d", __func__, methodCmd);
|
||||
if ((opsCmd >= SENSOR_OPS_CMD_BUTT) || (opsCmd < SENSOR_OPS_CMD_ENABLE)) {
|
||||
HDF_LOGE("%s: invalid cmd = %d", __func__, opsCmd);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
count = sizeof(g_sensorCmdHandle) / sizeof(g_sensorCmdHandle[0]);
|
||||
for (loop = 0; loop < count; ++loop) {
|
||||
if ((methodCmd == g_sensorCmdHandle[loop].cmd) && (g_sensorCmdHandle[loop].func != NULL)) {
|
||||
if ((opsCmd == g_sensorCmdHandle[loop].cmd) && (g_sensorCmdHandle[loop].func != NULL)) {
|
||||
return g_sensorCmdHandle[loop].func(deviceInfo, data, reply);
|
||||
}
|
||||
}
|
||||
@@ -272,29 +269,38 @@ static int32_t DispatchSensor(struct HdfDeviceIoClient *client,
|
||||
struct SensorDevMgrData *manager = GetSensorDeviceManager();
|
||||
struct SensorDevInfoNode *pos = NULL;
|
||||
int32_t sensorId;
|
||||
int32_t ret = HDF_FAILURE;
|
||||
int32_t ret;
|
||||
|
||||
CHECK_NULL_PTR_RETURN_VALUE(manager, HDF_ERR_INVALID_PARAM);
|
||||
CHECK_NULL_PTR_RETURN_VALUE(client, HDF_ERR_INVALID_PARAM);
|
||||
|
||||
if (cmd >= SENSOR_CMD_END) {
|
||||
HDF_LOGE("%s: sensor cmd invalid para", __func__);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if (cmd == SENSOR_CMD_GET_INFO_LIST) {
|
||||
return GetAllSensorInfo(data, reply);
|
||||
}
|
||||
|
||||
(void)OsalMutexLock(&manager->mutex);
|
||||
if (!HdfSbufReadInt32(data, &sensorId)) {
|
||||
HDF_LOGE("%s: sbuf read sensorId failed", __func__);
|
||||
(void)OsalMutexUnlock(&manager->mutex);
|
||||
return HDF_ERR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
DLIST_FOR_EACH_ENTRY(pos, &manager->sensorDevInfoHead, struct SensorDevInfoNode, node) {
|
||||
if (!HdfSbufReadInt32(data, &sensorId)) {
|
||||
HDF_LOGE("%s: sbuf read sensorId failed", __func__);
|
||||
continue;
|
||||
}
|
||||
if (sensorId == pos->devInfo.sensorInfo.sensorId) {
|
||||
ret = DispatchCmdHandle(&pos->devInfo, data, reply);
|
||||
break;
|
||||
(void)OsalMutexUnlock(&manager->mutex);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
(void)OsalMutexUnlock(&manager->mutex);
|
||||
|
||||
return ret;
|
||||
HDF_LOGE("%s: not find sensor[%d] handle function", __func__, sensorId);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
int32_t BindSensorDevManager(struct HdfDeviceObject *device)
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
|
||||
#include "securec.h"
|
||||
#include "osal_io.h"
|
||||
#include "osal_thread.h"
|
||||
#include "osal_time.h"
|
||||
#include "sensor_platform_if.h"
|
||||
|
||||
@@ -119,55 +118,3 @@ int32_t SetSensorPinMux(uint32_t regAddr, int32_t regSize, uint32_t regValue)
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t CreateSensorThread(struct OsalThread *thread, OsalThreadEntry threadEntry, char *name, void *entryPara)
|
||||
{
|
||||
struct OsalThreadParam config = {
|
||||
.name = name,
|
||||
.priority = OSAL_THREAD_PRI_DEFAULT,
|
||||
.stackSize = SENSOR_STACK_SIZE,
|
||||
};
|
||||
|
||||
CHECK_NULL_PTR_RETURN_VALUE(thread, HDF_ERR_INVALID_PARAM);
|
||||
CHECK_NULL_PTR_RETURN_VALUE(threadEntry, HDF_ERR_INVALID_PARAM);
|
||||
CHECK_NULL_PTR_RETURN_VALUE(name, HDF_ERR_INVALID_PARAM);
|
||||
CHECK_NULL_PTR_RETURN_VALUE(entryPara, HDF_ERR_INVALID_PARAM);
|
||||
|
||||
int32_t status = OsalThreadCreate(thread, threadEntry, entryPara);
|
||||
if (status != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: sensor create thread failed!status=%d", __func__, status);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
status = OsalThreadStart(thread, &config);
|
||||
if (status != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: sensor start thread failed!status=%d", __func__, status);
|
||||
OsalThreadDestroy(thread);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
void DestroySensorThread(struct OsalThread *thread, uint8_t *status)
|
||||
{
|
||||
int count = 0;
|
||||
CHECK_NULL_PTR_RETURN(thread);
|
||||
CHECK_NULL_PTR_RETURN(status);
|
||||
|
||||
if (*status == SENSOR_THREAD_NONE || *status == SENSOR_THREAD_DESTROY) {
|
||||
HDF_LOGE("%s,delete thread not need!", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
if (*status != SENSOR_THREAD_STOPPED) {
|
||||
*status = SENSOR_THREAD_STOPPING;
|
||||
/* wait until thread worker exit */
|
||||
while ((*status != SENSOR_THREAD_STOPPED) && (count < MAX_SENSOR_EXIT_THREAD_COUNT)) {
|
||||
OsalMSleep(MAX_SENSOR_WAIT_THREAD_TIME);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
OsalThreadDestroy(thread);
|
||||
*status = SENSOR_THREAD_DESTROY;
|
||||
}
|
||||
@@ -12,7 +12,6 @@
|
||||
#include "sensor_device_type.h"
|
||||
|
||||
struct SensorOps {
|
||||
int32_t (*GetInfo)(struct SensorBasicInfo *sensorInfo);
|
||||
int32_t (*Enable)(void);
|
||||
int32_t (*Disable)(void);
|
||||
int32_t (*SetBatch)(int64_t samplingInterval, int64_t reportInterval);
|
||||
@@ -26,7 +25,7 @@ struct SensorDeviceInfo {
|
||||
};
|
||||
|
||||
int32_t AddSensorDevice(const struct SensorDeviceInfo *deviceInfo);
|
||||
int32_t DeleteSensorDevice(int32_t sensorId);
|
||||
int32_t DeleteSensorDevice(const struct SensorBasicInfo *sensorBaseInfo);
|
||||
int32_t ReportSensorEvent(const struct SensorReportEvent *events);
|
||||
|
||||
#endif /* SENSOR_DEVICE_IF_H */
|
||||
|
||||
@@ -40,15 +40,14 @@
|
||||
|
||||
#define SENSOR_ADDR_WIDTH_1_BYTE 1 // 8 bit
|
||||
#define SENSOR_ADDR_WIDTH_2_BYTE 2 // 16 bit
|
||||
#define SENSOR_ADDR_WIDTH_4_BYTE 4 // 32 bit
|
||||
#define SENSOR_ADDR_WIDTH_4_BYTE 4 // 16 bit
|
||||
#define SENSOR_DATA_WIDTH_8_BIT 8 // 8 bit
|
||||
#define SENSOR_CONVERT_UNIT 1000
|
||||
#define SENSOR_1K_UNIT 1024
|
||||
#define SENSOR_SPI_MAX_SPEED 115200
|
||||
#define SENSOR_SECOND_CONVERT_NANOSECOND (SENSOR_CONVERT_UNIT * SENSOR_CONVERT_UNIT * SENSOR_CONVERT_UNIT)
|
||||
|
||||
#define MAX_SENSOR_EXIT_THREAD_COUNT 10
|
||||
#define MAX_SENSOR_WAIT_THREAD_TIME 100 // 100MS
|
||||
#define SENSOR_TIMER_MIN_TIME 20
|
||||
|
||||
enum SensorBusType {
|
||||
SENSOR_BUS_I2C = 0,
|
||||
@@ -96,7 +95,5 @@ enum SENSORConfigValueIndex {
|
||||
int32_t ReadSensor(struct SensorBusCfg *busCfg, uint16_t regAddr, uint8_t *data, uint16_t dataLen);
|
||||
int32_t WriteSensor(struct SensorBusCfg *busCfg, uint8_t *writeData, uint16_t len);
|
||||
int32_t SetSensorPinMux(uint32_t regAddr, int32_t regSize, uint32_t regValue);
|
||||
int32_t CreateSensorThread(struct OsalThread *thread, OsalThreadEntry threadEntry, char *name, void *entryPara);
|
||||
void DestroySensorThread(struct OsalThread *thread, uint8_t *status);
|
||||
|
||||
#endif /* SENSOR_PLATFORM_IF_H */
|
||||
@@ -12,7 +12,6 @@
|
||||
#include "hdf_sensor_test.h"
|
||||
#include "osal_math.h"
|
||||
#include "osal_time.h"
|
||||
#include "osal_timer.h"
|
||||
#include "sensor_platform_if.h"
|
||||
#include "sensor_device_manager.h"
|
||||
#include "sensor_device_type.h"
|
||||
@@ -22,18 +21,19 @@
|
||||
#define HDF_SENSOR_TEST_VALUE 1024000000 // 1g = 9.8m/s^2
|
||||
#define SENSOR_TEST_MAX_RANGE 8
|
||||
#define SENSOR_TEST_MAX_POWER 230
|
||||
#define HDF_SENSOR_TEST_WORK_QUEUE_NAME "hdf_sensor_test_work_queue"
|
||||
|
||||
static struct SensorTestDrvData *GetSensorTestDrvData(void)
|
||||
{
|
||||
static struct SensorTestDrvData sensorTestDrvData = {
|
||||
.threadStatus = SENSOR_THREAD_NONE,
|
||||
.enable = false,
|
||||
.initStatus = false,
|
||||
.interval = SENSOR_TEST_SAMPLING_200_MS,
|
||||
};
|
||||
|
||||
return &sensorTestDrvData;
|
||||
}
|
||||
static void SensorReadTestData(void)
|
||||
static void SensorTestDataWorkEntry(void *arg)
|
||||
{
|
||||
int32_t value = HDF_SENSOR_TEST_VALUE;
|
||||
struct SensorReportEvent event;
|
||||
@@ -52,75 +52,89 @@ static void SensorReadTestData(void)
|
||||
ReportSensorEvent(&event);
|
||||
}
|
||||
|
||||
static int32_t SensorReadDataThreadTestWorker(void *arg)
|
||||
static void SensorTestTimerEntry(uintptr_t arg)
|
||||
{
|
||||
(void)arg;
|
||||
int64_t interval;
|
||||
CHECK_NULL_PTR_RETURN_VALUE(arg, HDF_ERR_INVALID_PARAM);
|
||||
struct SensorTestDrvData *drvData = GetSensorTestDrvData();
|
||||
struct SensorTestDrvData *drvData = (struct SensorTestDrvData *)arg;
|
||||
CHECK_NULL_PTR_RETURN(drvData);
|
||||
|
||||
drvData->threadStatus = SENSOR_THREAD_START;
|
||||
while (true) {
|
||||
if (drvData->threadStatus == SENSOR_THREAD_RUNNING) {
|
||||
SensorReadTestData();
|
||||
interval = OsalDivS64(drvData->interval, (SENSOR_CONVERT_UNIT * SENSOR_CONVERT_UNIT));
|
||||
OsalMSleep(interval);
|
||||
} else if (drvData->threadStatus == SENSOR_THREAD_STOPPING) {
|
||||
drvData->threadStatus = SENSOR_THREAD_STOPPED;
|
||||
break;
|
||||
} else {
|
||||
OsalMSleep(SENSOR_TEST_SAMPLING_200_MS / SENSOR_CONVERT_UNIT / SENSOR_CONVERT_UNIT);
|
||||
}
|
||||
|
||||
if ((!drvData->initStatus) || (drvData->interval < 0) || drvData->threadStatus != SENSOR_THREAD_RUNNING) {
|
||||
continue;
|
||||
}
|
||||
if (!HdfAddWork(&drvData->workQueue, &drvData->work)) {
|
||||
HDF_LOGE("%s: sensor test add work queue failed", __func__);
|
||||
}
|
||||
|
||||
HDF_LOGE("%s: Sensor test thread have exited", __func__);
|
||||
return HDF_SUCCESS;
|
||||
interval = OsalDivS64(drvData->interval, (SENSOR_CONVERT_UNIT * SENSOR_CONVERT_UNIT));
|
||||
interval = (interval < SENSOR_TIMER_MIN_TIME) ? SENSOR_TIMER_MIN_TIME : interval;
|
||||
|
||||
if (OsalTimerSetTimeout(&drvData->timer, interval) != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: sensor test modify time failed", __func__);
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t SensorInitTestConfig(void)
|
||||
{
|
||||
struct SensorTestDrvData *drvData = GetSensorTestDrvData();
|
||||
|
||||
if (drvData->threadStatus != SENSOR_THREAD_NONE && drvData->threadStatus != SENSOR_THREAD_DESTROY) {
|
||||
HDF_LOGE("%s: Sensor test thread have created", __func__);
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t ret = CreateSensorThread(&drvData->thread, SensorReadDataThreadTestWorker, "hdf_sensor_test", drvData);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: Sensor test create thread failed", __func__);
|
||||
drvData->threadStatus = SENSOR_THREAD_NONE;
|
||||
if (HdfWorkQueueInit(&drvData->workQueue, HDF_SENSOR_TEST_WORK_QUEUE_NAME) != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: sensor test init work queue failed", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
if (HdfWorkInit(&drvData->work, SensorTestDataWorkEntry, drvData) != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: sensor test create thread failed", __func__);
|
||||
return HDF_FAILURE;
|
||||
}
|
||||
|
||||
drvData->enable = false;
|
||||
drvData->initStatus = true;
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t SensorGetInfoTest(struct SensorBasicInfo *info)
|
||||
{
|
||||
(void)info;
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t SensorEnableTest(void)
|
||||
{
|
||||
int32_t ret;
|
||||
struct SensorTestDrvData *drvData = GetSensorTestDrvData();
|
||||
|
||||
drvData->threadStatus = SENSOR_THREAD_RUNNING;
|
||||
if (drvData->enable) {
|
||||
HDF_LOGE("%{public}s: sensor test had enable", __func__);
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
ret = OsalTimerCreate(&drvData->timer, SENSOR_TIMER_MIN_TIME, SensorTestTimerEntry, (uintptr_t)drvData);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("%{public}s: sensor test create timer failed[%{public}d]", __func__, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = OsalTimerStartLoop(&drvData->timer);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("%{public}s: sensor test start timer failed[%{public}d]", __func__, ret);
|
||||
return ret;
|
||||
}
|
||||
drvData->enable = true;
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t SensorDisableTest(void)
|
||||
{
|
||||
int32_t ret;
|
||||
struct SensorTestDrvData *drvData = GetSensorTestDrvData();
|
||||
|
||||
drvData->threadStatus = SENSOR_THREAD_STOPPED;
|
||||
if (!drvData->enable) {
|
||||
HDF_LOGE("%s: sensor test had disable", __func__);
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
|
||||
if (drvData->timer.realTimer != NULL) {
|
||||
ret = OsalTimerDelete(&drvData->timer);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: sensor test delete timer failed", __func__);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
drvData->enable = false;
|
||||
|
||||
return HDF_SUCCESS;
|
||||
}
|
||||
@@ -172,7 +186,6 @@ int32_t InitSensorDriverTest(struct HdfDeviceObject *device)
|
||||
{
|
||||
int32_t ret;
|
||||
(void)device;
|
||||
struct SensorTestDrvData *drvData = GetSensorTestDrvData();
|
||||
|
||||
struct SensorDeviceInfo deviceInfo = {
|
||||
.sensorInfo = {
|
||||
@@ -187,7 +200,6 @@ int32_t InitSensorDriverTest(struct HdfDeviceObject *device)
|
||||
.power = SENSOR_TEST_MAX_POWER,
|
||||
},
|
||||
.ops = {
|
||||
.GetInfo = SensorGetInfoTest,
|
||||
.Enable = SensorEnableTest,
|
||||
.Disable = SensorDisableTest,
|
||||
.SetBatch = SensorSetBatchTest,
|
||||
@@ -199,14 +211,13 @@ int32_t InitSensorDriverTest(struct HdfDeviceObject *device)
|
||||
ret = SensorInitTestConfig();
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: sensor test config failed", __func__);
|
||||
return HDF_FAILURE;
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = AddSensorDevice(&deviceInfo);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: sensor test register failed", __func__);
|
||||
(void)DestroySensorThread(&drvData->thread, &drvData->threadStatus);
|
||||
return HDF_FAILURE;
|
||||
return ret;
|
||||
}
|
||||
|
||||
HDF_LOGI("%s: init sensor test driver success", __func__);
|
||||
@@ -216,10 +227,29 @@ int32_t InitSensorDriverTest(struct HdfDeviceObject *device)
|
||||
void ReleaseSensorDriverTest(struct HdfDeviceObject *device)
|
||||
{
|
||||
(void)device;
|
||||
int32_t ret;
|
||||
struct SensorTestDrvData *drvData = GetSensorTestDrvData();
|
||||
struct SensorDeviceInfo deviceInfo = {
|
||||
.sensorInfo = {
|
||||
.sensorName = "sensor_test",
|
||||
.vendorName = "default",
|
||||
.firmwareVersion = "1.0",
|
||||
.hardwareVersion = "1.0",
|
||||
.sensorTypeId = SENSOR_TAG_NONE,
|
||||
.sensorId = SENSOR_TAG_NONE,
|
||||
.maxRange = SENSOR_TEST_MAX_RANGE,
|
||||
.accuracy = 1,
|
||||
.power = SENSOR_TEST_MAX_POWER,
|
||||
}
|
||||
};
|
||||
(void)DeleteSensorDevice(&deviceInfo.sensorInfo);
|
||||
|
||||
(void)DestroySensorThread(&drvData->thread, &drvData->threadStatus);
|
||||
(void)DeleteSensorDevice(SENSOR_TAG_NONE);
|
||||
if (drvData->timer.realTimer != NULL) {
|
||||
ret = OsalTimerDelete(&drvData->timer);
|
||||
if (ret != HDF_SUCCESS) {
|
||||
HDF_LOGE("%s: sensor test delete timer failed", __func__);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct HdfDriverEntry g_sensorTestDevEntry = {
|
||||
|
||||
@@ -9,15 +9,18 @@
|
||||
#ifndef HDF_SENSOR_DRIVER_TEST_H
|
||||
#define HDF_SENSOR_DRIVER_TEST_H
|
||||
|
||||
#include "osal_thread.h"
|
||||
#include "hdf_workqueue.h"
|
||||
#include "osal_timer.h"
|
||||
|
||||
#define SENSOR_TEST_SAMPLING_200_MS 200000000
|
||||
|
||||
struct SensorTestDrvData {
|
||||
uint8_t threadStatus;
|
||||
uint8_t initStatus;
|
||||
int64_t interval;
|
||||
struct OsalThread thread;
|
||||
HdfWorkQueue workQueue;
|
||||
HdfWork work;
|
||||
OsalTimer timer;
|
||||
bool enable;
|
||||
};
|
||||
|
||||
#endif // HDF_SENSOR_DRIVER_TEST_H
|
||||
Reference in New Issue
Block a user