1 /* ipm_console_send.c - Console messages to another processor */ 2 3 /* 4 * Copyright (c) 2015 Intel Corporation 5 * 6 * SPDX-License-Identifier: Apache-2.0 7 */ 8 9 #include <errno.h> 10 11 #include <zephyr/kernel.h> 12 #include <zephyr/sys/printk.h> 13 #include <zephyr/drivers/ipm.h> 14 #include <zephyr/drivers/console/ipm_console.h> 15 16 static const struct device *ipm_console_device; 17 consoleOut(int character)18static int consoleOut(int character) 19 { 20 if (character == '\r') { 21 return character; 22 } 23 24 /* 25 * We just stash the character into the id field and don't supply 26 * any extra data 27 */ 28 ipm_send(ipm_console_device, 1, character, NULL, 0); 29 30 return character; 31 } 32 33 extern void __printk_hook_install(int (*fn)(int)); 34 extern void __stdout_hook_install(int (*fn)(int)); 35 ipm_console_sender_init(const struct device * d)36int ipm_console_sender_init(const struct device *d) 37 { 38 const struct ipm_console_sender_config_info *config_info; 39 40 config_info = d->config; 41 ipm_console_device = device_get_binding(config_info->bind_to); 42 43 if (!ipm_console_device) { 44 printk("unable to bind IPM console sender to '%s'\n", 45 config_info->bind_to); 46 return -EINVAL; 47 } 48 49 if (config_info->flags & IPM_CONSOLE_STDOUT) { 50 __stdout_hook_install(consoleOut); 51 } 52 if (config_info->flags & IPM_CONSOLE_PRINTK) { 53 __printk_hook_install(consoleOut); 54 } 55 56 return 0; 57 } 58