driver/sensor: support access remote sensor by rpmsg

Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
This commit is contained in:
Jiuzhu Dong 2022-04-08 22:46:29 +08:00 committed by Xiang Xiao
parent 1cc7f6e63a
commit c5f87bb5c6
5 changed files with 1389 additions and 6 deletions

View File

@ -18,6 +18,13 @@ config USENSOR
---help---
Allow application to register user sensor by /dev/usensor.
config SENSORS_RPMSG
bool "Sensor rpmsg Support"
default n
depends on RPTUN
---help---
Allow application to read or control remote sensor device by rpmsg.
config SENSORS_WTGAHRS2
bool "Wtgahrs2 Sensor Support"
default n

View File

@ -28,6 +28,10 @@ ifeq ($(CONFIG_USENSOR),y)
CSRCS += usensor.c
endif
ifeq ($(CONFIG_SENSORS_RPMSG),y)
CSRCS += sensor_rpmsg.c
endif
ifeq ($(CONFIG_SENSORS_WTGAHRS2),y)
CSRCS += wtgahrs2.c
endif

View File

@ -599,8 +599,9 @@ static ssize_t sensor_write(FAR struct file *filep, FAR const char *buffer,
{
FAR struct inode *inode = filep->f_inode;
FAR struct sensor_upperhalf_s *upper = inode->i_private;
FAR struct sensor_lowerhalf_s *lower = upper->lower;
return sensor_push_event(upper, buffer, buflen);
return lower->push_event(lower->priv, buffer, buflen);
}
static int sensor_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
@ -967,8 +968,6 @@ int sensor_custom_register(FAR struct sensor_lowerhalf_s *lower,
/* Initialize the upper-half data structure */
upper->lower = lower;
list_initialize(&upper->userlist);
upper->state.esize = esize;
upper->state.min_interval = ULONG_MAX;
@ -1007,6 +1006,16 @@ int sensor_custom_register(FAR struct sensor_lowerhalf_s *lower,
goto drv_err;
}
#ifdef CONFIG_SENSORS_RPMSG
lower = sensor_rpmsg_register(lower, path);
if (lower == NULL)
{
ret = -EIO;
goto drv_err;
}
#endif
upper->lower = lower;
return ret;
drv_err:
@ -1069,6 +1078,10 @@ void sensor_custom_unregister(FAR struct sensor_lowerhalf_s *lower,
sninfo("UnRegistering %s\n", path);
unregister_driver(path);
#ifdef CONFIG_SENSORS_RPMSG
sensor_rpmsg_unregister(lower);
#endif
nxsem_destroy(&upper->exclsem);
if (circbuf_is_init(&upper->buffer))
{

File diff suppressed because it is too large Load Diff

View File

@ -857,6 +857,11 @@ struct sensor_ops_s
* Sensor driver.
*/
typedef CODE ssize_t (*sensor_push_event_t)(FAR void *priv,
FAR const void *data,
size_t bytes);
typedef CODE void (*sensor_notify_event_t)(FAR void *priv);
struct sensor_lowerhalf_s
{
/* The type of sensor device */
@ -908,8 +913,7 @@ struct sensor_lowerhalf_s
* A negated errno value is returned on any failure.
**********************************************************************/
CODE ssize_t (*push_event)(FAR void *priv, FAR const void *data,
size_t bytes);
sensor_push_event_t push_event;
/**********************************************************************
* Name: notify_event
@ -925,7 +929,7 @@ struct sensor_lowerhalf_s
* priv - Upper half driver handle
**********************************************************************/
CODE void (*notify_event)(FAR void *priv);
sensor_notify_event_t notify_event;
};
/* The private opaque pointer to be passed to upper-layer during callback */
@ -1084,6 +1088,58 @@ void sensor_custom_unregister(FAR struct sensor_lowerhalf_s *dev,
int usensor_initialize(void);
#endif
/****************************************************************************
* Name: sensor_rpmsg_register
*
* Description:
* This function registers rpmsg takeover for the real lower half, and
* initialize rpmsg resource.
*
* Input Parameters:
* lower - The instance of lower half sensor driver.
* path - The path of character node, ex: /dev/sensor/xxx.
*
* Returned Value:
* The takeover rpmsg lowerhalf returned on success, NULL on failure.
****************************************************************************/
#ifdef CONFIG_SENSORS_RPMSG
FAR struct sensor_lowerhalf_s *sensor_rpmsg_register(
FAR struct sensor_lowerhalf_s *lower,
FAR const char *path);
#endif
/****************************************************************************
* Name: sensor_rpmsg_unregister
*
* Description:
* This function unregisters rpmsg takeover for the real lower half, and
* release rpmsg resource. This API corresponds to the
* sensor_rpmsg_register.
*
* Input Parameters:
* lower - The instance of lower half sensor driver.
****************************************************************************/
#ifdef CONFIG_SENSORS_RPMSG
void sensor_rpmsg_unregister(FAR struct sensor_lowerhalf_s *lower);
#endif
/****************************************************************************
* Name: sensor_rpmsg_initialize
*
* Description:
* This function initializes the context of sensor rpmsg, registers
* rpmsg callback and prepares enviroment to intercat with remote sensor.
*
* Returned Value:
* OK on success; A negated errno value is returned on any failure.
****************************************************************************/
#ifdef CONFIG_SENSORS_RPMSG
int sensor_rpmsg_initialize(void);
#endif
#undef EXTERN
#if defined(__cplusplus)
}