Skip to content

Commit 4507e3a

Browse files
committed
sensor: add upoload f/w API
Add Firmware upload API Signed-off-by: Armando Visconti <[email protected]>
1 parent 4a5e3c0 commit 4507e3a

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

drivers/sensor/sensor_handlers.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,15 @@ static inline int z_vrfy_sensor_get_decoder(const struct device *dev,
6868
}
6969
#include <zephyr/syscalls/sensor_get_decoder_mrsh.c>
7070

71+
static inline int z_vrfy_sensor_upload_fw(const struct device *dev,
72+
const void *fw_buf, size_t fw_len)
73+
{
74+
K_OOPS(K_SYSCALL_OBJ(dev, K_OBJ_DRIVER_SENSOR));
75+
K_OOPS(K_SYSCALL_MEMORY_READ(fw_buf, fw_len));
76+
return z_impl_sensor_upload_fw(dev, fw_buf, fw_len);
77+
}
78+
#include <zephyr/syscalls/sensor_upload_fw_mrsh.c>
79+
7180
static inline int z_vrfy_sensor_reconfigure_read_iodev(struct rtio_iodev *iodev,
7281
const struct device *sensor,
7382
const struct sensor_chan_spec *channels,

include/zephyr/drivers/sensor.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,9 @@ struct sensor_read_config {
705705
/* Used to submit an RTIO sqe to the sensor's iodev */
706706
typedef void (*sensor_submit_t)(const struct device *sensor, struct rtio_iodev_sqe *sqe);
707707

708+
/* Used to provide a driver specific callback to upload a f/w in the sensor */
709+
typedef int (*sensor_upload_fw_t)(const struct device *dev, const void *fw_buf, size_t fw_len);
710+
708711
/* The default decoder API */
709712
extern const struct sensor_decoder_api __sensor_default_decoder;
710713

@@ -719,6 +722,7 @@ __subsystem struct sensor_driver_api {
719722
sensor_channel_get_t channel_get;
720723
sensor_get_decoder_t get_decoder;
721724
sensor_submit_t submit;
725+
sensor_upload_fw_t upload_fw;
722726
};
723727

724728
/**
@@ -1004,6 +1008,32 @@ static inline int z_impl_sensor_get_decoder(const struct device *dev,
10041008
return api->get_decoder(dev, decoder);
10051009
}
10061010

1011+
/**
1012+
* @brief Upload a Firmware to the sensor
1013+
*
1014+
* @param[in] dev The sensor device
1015+
* @param[in] fw_buf Pointer to the Firmware buffer
1016+
* @param[in] fw_len Length of Firmware
1017+
* @return 0 on success
1018+
* @return < 0 on error
1019+
*/
1020+
__syscall int sensor_upload_fw(const struct device *dev,
1021+
const void *fw_buf, size_t fw_len);
1022+
1023+
static inline int z_impl_sensor_upload_fw(const struct device *dev,
1024+
const void *fw_buf, size_t fw_len)
1025+
{
1026+
const struct sensor_driver_api *api = (const struct sensor_driver_api *)dev->api;
1027+
1028+
__ASSERT_NO_MSG(api != NULL);
1029+
1030+
if (api->upload_fw == NULL) {
1031+
return -ENOSYS;
1032+
}
1033+
1034+
return api->upload_fw(dev, fw_buf, fw_len);
1035+
}
1036+
10071037
/**
10081038
* @brief Reconfigure a reading iodev
10091039
*

0 commit comments

Comments
 (0)