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>
43 lines
857 B
C
43 lines
857 B
C
/*
|
|
* Copyright (c) 2016 Intel Corporation.
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
#include <zephyr.h>
|
|
#include <sys/printk.h>
|
|
#include <sys/util.h>
|
|
#include <string.h>
|
|
#include <usb/usb_device.h>
|
|
#include <drivers/uart.h>
|
|
|
|
void main(void)
|
|
{
|
|
const struct device *dev = device_get_binding(
|
|
CONFIG_UART_CONSOLE_ON_DEV_NAME);
|
|
uint32_t dtr = 0;
|
|
|
|
if (usb_enable(NULL)) {
|
|
return;
|
|
}
|
|
|
|
/* Poll if the DTR flag was set, optional */
|
|
while (!dtr) {
|
|
uart_line_ctrl_get(dev, UART_LINE_CTRL_DTR, &dtr);
|
|
}
|
|
|
|
if (strlen(CONFIG_UART_CONSOLE_ON_DEV_NAME) !=
|
|
strlen("CDC_ACM_0") ||
|
|
strncmp(CONFIG_UART_CONSOLE_ON_DEV_NAME, "CDC_ACM_0",
|
|
strlen(CONFIG_UART_CONSOLE_ON_DEV_NAME))) {
|
|
printk("Error: Console device name is not USB ACM\n");
|
|
|
|
return;
|
|
}
|
|
|
|
while (1) {
|
|
printk("Hello World! %s\n", CONFIG_ARCH);
|
|
k_sleep(K_SECONDS(1));
|
|
}
|
|
}
|