zephyr/drivers/console/ipm_console_sender.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

58 lines
1.2 KiB
C

/* ipm_console_send.c - Console messages to another processor */
/*
* Copyright (c) 2015 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <errno.h>
#include <kernel.h>
#include <sys/printk.h>
#include <drivers/ipm.h>
#include <drivers/console/ipm_console.h>
static const struct device *ipm_console_device;
static int consoleOut(int character)
{
if (character == '\r') {
return character;
}
/*
* We just stash the character into the id field and don't supply
* any extra data
*/
ipm_send(ipm_console_device, 1, character, NULL, 0);
return character;
}
extern void __printk_hook_install(int (*fn)(int));
extern void __stdout_hook_install(int (*fn)(int));
int ipm_console_sender_init(const struct device *d)
{
const struct ipm_console_sender_config_info *config_info;
config_info = d->config;
ipm_console_device = device_get_binding(config_info->bind_to);
if (!ipm_console_device) {
printk("unable to bind IPM console sender to '%s'\n",
config_info->bind_to);
return -EINVAL;
}
if (config_info->flags & IPM_CONSOLE_STDOUT) {
__stdout_hook_install(consoleOut);
}
if (config_info->flags & IPM_CONSOLE_PRINTK) {
__printk_hook_install(consoleOut);
}
return 0;
}