samples: Fix device instance const qualifier loss
Keep the device pointer locally. Fixes #27399 Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
This commit is contained in:
parent
8d0a3f3b5c
commit
9a0fe24ae9
3 changed files with 19 additions and 15 deletions
|
@ -8,10 +8,10 @@
|
|||
#include <stdio.h>
|
||||
#include <zephyr.h>
|
||||
|
||||
const struct device *dev;
|
||||
|
||||
static void user_entry(void *p1, void *p2, void *p3)
|
||||
{
|
||||
const struct device *dev = p1;
|
||||
|
||||
hello_world_print(dev);
|
||||
}
|
||||
|
||||
|
@ -19,12 +19,12 @@ void main(void)
|
|||
{
|
||||
printk("Hello World from the app!\n");
|
||||
|
||||
const struct device *dev = device_get_binding("CUSTOM_DRIVER");
|
||||
dev = device_get_binding("CUSTOM_DRIVER");
|
||||
|
||||
__ASSERT(dev, "Failed to get device binding");
|
||||
|
||||
printk("device is %p, name is %s\n", dev, dev->name);
|
||||
|
||||
k_object_access_grant(dev, k_current_get());
|
||||
k_thread_user_mode_enter(user_entry, dev, NULL, NULL);
|
||||
k_thread_user_mode_enter(user_entry, NULL, NULL, NULL);
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ K_THREAD_STACK_DEFINE(rx_thread_stack, RX_THREAD_STACK_SIZE);
|
|||
K_THREAD_STACK_DEFINE(poll_state_stack, STATE_POLL_THREAD_STACK_SIZE);
|
||||
|
||||
const struct device *can_dev;
|
||||
const struct device *led_gpio_dev;
|
||||
|
||||
struct k_thread rx_thread_data;
|
||||
struct k_thread poll_state_thread_data;
|
||||
|
@ -77,24 +78,26 @@ void rx_thread(void *arg1, void *arg2, void *arg3)
|
|||
}
|
||||
}
|
||||
|
||||
void change_led(struct zcan_frame *msg, void *led_dev_param)
|
||||
void change_led(struct zcan_frame *msg, void *unused)
|
||||
{
|
||||
const struct device *led_dev = (const struct device *)led_dev_param;
|
||||
ARG_UNUSED(unused);
|
||||
|
||||
#if DT_PHA_HAS_CELL(DT_ALIAS(led0), gpios, pin) && \
|
||||
DT_NODE_HAS_PROP(DT_ALIAS(led0), gpios)
|
||||
|
||||
if (!led_dev_param) {
|
||||
if (!led_gpio_dev) {
|
||||
printk("No LED GPIO device\n");
|
||||
return;
|
||||
}
|
||||
|
||||
switch (msg->data[0]) {
|
||||
case SET_LED:
|
||||
gpio_pin_set(led_dev, DT_GPIO_PIN(DT_ALIAS(led0), gpios), 1);
|
||||
gpio_pin_set(led_gpio_dev,
|
||||
DT_GPIO_PIN(DT_ALIAS(led0), gpios), 1);
|
||||
break;
|
||||
case RESET_LED:
|
||||
gpio_pin_set(led_dev, DT_GPIO_PIN(DT_ALIAS(led0), gpios), 0);
|
||||
gpio_pin_set(led_gpio_dev,
|
||||
DT_GPIO_PIN(DT_ALIAS(led0), gpios), 0);
|
||||
break;
|
||||
}
|
||||
#else
|
||||
|
@ -192,7 +195,6 @@ void main(void)
|
|||
};
|
||||
uint8_t toggle = 1;
|
||||
uint16_t counter = 0;
|
||||
const struct device *led_gpio_dev = NULL;
|
||||
k_tid_t rx_tid, get_state_tid;
|
||||
int ret;
|
||||
|
||||
|
@ -227,7 +229,7 @@ void main(void)
|
|||
k_work_init(&state_change_work, state_change_work_handler);
|
||||
|
||||
ret = can_attach_workq(can_dev, &k_sys_work_q, &rx_work, change_led,
|
||||
led_gpio_dev, &change_led_filter);
|
||||
NULL, &change_led_filter);
|
||||
if (ret == CAN_NO_FREE_FILTER) {
|
||||
printk("Error, no filter available!\n");
|
||||
return;
|
||||
|
|
|
@ -24,6 +24,7 @@ LOG_MODULE_REGISTER(sample_driver);
|
|||
((struct sample_driver_foo_dev_data *const)(dev)->data)
|
||||
|
||||
struct sample_driver_foo_dev_data {
|
||||
const struct device *dev;
|
||||
sample_driver_callback_t cb;
|
||||
void *cb_context;
|
||||
struct k_timer timer; /* to fake 'interrupts' */
|
||||
|
@ -57,7 +58,7 @@ static int sample_driver_foo_state_set(const struct device *dev, bool active)
|
|||
|
||||
LOG_DBG("%s(%p, %d)", __func__, dev, active);
|
||||
|
||||
data->timer.user_data = dev;
|
||||
data->timer.user_data = data;
|
||||
if (active) {
|
||||
k_timer_start(&data->timer, K_MSEC(100), K_MSEC(100));
|
||||
} else {
|
||||
|
@ -75,8 +76,7 @@ static struct sample_driver_api sample_driver_foo_api = {
|
|||
|
||||
static void sample_driver_foo_isr(void *param)
|
||||
{
|
||||
const struct device *dev = param;
|
||||
struct sample_driver_foo_dev_data *data = DEV_DATA(dev);
|
||||
struct sample_driver_foo_dev_data *data = param;
|
||||
|
||||
char data_payload[SAMPLE_DRIVER_MSG_SIZE];
|
||||
|
||||
|
@ -85,7 +85,7 @@ static void sample_driver_foo_isr(void *param)
|
|||
|
||||
/* Just for demonstration purposes; the data payload is full of junk */
|
||||
if (data->cb) {
|
||||
data->cb(dev, data->cb_context, data_payload);
|
||||
data->cb(data->dev, data->cb_context, data_payload);
|
||||
}
|
||||
|
||||
data->count++;
|
||||
|
@ -104,6 +104,8 @@ static int sample_driver_foo_init(const struct device *dev)
|
|||
|
||||
LOG_DBG("initialized foo sample driver %p", dev);
|
||||
|
||||
data->dev = dev;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue