zephyr/tests/kernel/device/src/abstract_driver.c
Tomasz Bursztyka e18fcbba5a device: Const-ify all device driver instance pointers
Now that device_api attribute is unmodified at runtime, as well as all
the other attributes, it is possible to switch all device driver
instance to be constant.

A coccinelle rule is used for this:

@r_const_dev_1
  disable optional_qualifier
@
@@
-struct device *
+const struct device *

@r_const_dev_2
 disable optional_qualifier
@
@@
-struct device * const
+const struct device *

Fixes #27399

Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-09-02 13:48:13 +02:00

67 lines
1.3 KiB
C

/*
* Copyright (c) 2020 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <ztest.h>
#include <device.h>
#include "abstract_driver.h"
#define MY_DRIVER_A "my_driver_A"
#define MY_DRIVER_B "my_driver_B"
/* define indivial driver A */
static int my_driver_A_do_this(const struct device *device, int foo, int bar)
{
return foo + bar;
}
static void my_driver_A_do_that(const struct device *device,
unsigned int *baz)
{
*baz = 1;
}
static struct subsystem_api my_driver_A_api_funcs = {
.do_this = my_driver_A_do_this,
.do_that = my_driver_A_do_that
};
int common_driver_init(const struct device *dev)
{
return 0;
}
/* define indivial driver B */
static int my_driver_B_do_this(const struct device *device, int foo, int bar)
{
return foo - bar;
}
static void my_driver_B_do_that(const struct device *device,
unsigned int *baz)
{
*baz = 2;
}
static struct subsystem_api my_driver_B_api_funcs = {
.do_this = my_driver_B_do_this,
.do_that = my_driver_B_do_that
};
/**
* @cond INTERNAL_HIDDEN
*/
DEVICE_AND_API_INIT(my_driver_A, MY_DRIVER_A, &common_driver_init, NULL, NULL,
POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT,
&my_driver_A_api_funcs);
DEVICE_AND_API_INIT(my_driver_B, MY_DRIVER_B, &common_driver_init, NULL, NULL,
POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT,
&my_driver_B_api_funcs);
/**
* @endcond
*/