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/sys/printk-hooks.h> 14 #include <zephyr/sys/libc-hooks.h> 15 #include <zephyr/drivers/ipm.h> 16 #include <zephyr/drivers/console/ipm_console.h> 17 18 static const struct device *ipm_console_device; 19 console_out(int character)20static int console_out(int character) 21 { 22 if (character == '\r') { 23 return character; 24 } 25 26 /* 27 * We just stash the character into the id field and don't supply 28 * any extra data 29 */ 30 ipm_send(ipm_console_device, 1, character, NULL, 0); 31 32 return character; 33 } 34 ipm_console_sender_init(const struct device * d)35int ipm_console_sender_init(const struct device *d) 36 { 37 const struct ipm_console_sender_config_info *config_info; 38 39 config_info = d->config; 40 ipm_console_device = device_get_binding(config_info->bind_to); 41 42 if (!ipm_console_device) { 43 printk("unable to bind IPM console sender to '%s'\n", 44 config_info->bind_to); 45 return -EINVAL; 46 } 47 48 if (config_info->flags & IPM_CONSOLE_STDOUT) { 49 __stdout_hook_install(console_out); 50 } 51 if (config_info->flags & IPM_CONSOLE_PRINTK) { 52 __printk_hook_install(console_out); 53 } 54 55 return 0; 56 } 57