Line data Source code
1 0 : /* ipm_console.c - Console messages to/from another processor */
2 :
3 : /*
4 : * Copyright (c) 2015 Intel Corporation
5 : *
6 : * SPDX-License-Identifier: Apache-2.0
7 : */
8 :
9 : #ifndef ZEPHYR_INCLUDE_DRIVERS_CONSOLE_IPM_CONSOLE_H_
10 : #define ZEPHYR_INCLUDE_DRIVERS_CONSOLE_IPM_CONSOLE_H_
11 :
12 : #include <zephyr/kernel.h>
13 : #include <zephyr/device.h>
14 : #include <zephyr/sys/ring_buffer.h>
15 :
16 : #ifdef __cplusplus
17 : extern "C" {
18 : #endif
19 :
20 0 : #define IPM_CONSOLE_STDOUT (BIT(0))
21 0 : #define IPM_CONSOLE_PRINTK (BIT(1))
22 :
23 : /*
24 : * Good way to determine these numbers other than trial-and-error?
25 : * using printf() in the thread seems to require a lot more stack space
26 : */
27 0 : #define IPM_CONSOLE_STACK_SIZE CONFIG_IPM_CONSOLE_STACK_SIZE
28 0 : #define IPM_CONSOLE_PRI 2
29 :
30 0 : struct ipm_console_receiver_config_info {
31 : /** Name of the low-level IPM driver to bind to */
32 1 : char *bind_to;
33 :
34 : /**
35 : * Stack for the receiver's thread, which prints out messages as
36 : * they come in. Should be sized CONFIG_IPM_CONSOLE_STACK_SIZE
37 : */
38 1 : k_thread_stack_t *thread_stack;
39 :
40 : /**
41 : * Ring buffer data area for stashing characters from the interrupt
42 : * callback
43 : */
44 1 : uint32_t *ring_buf_data;
45 :
46 : /** Size of ring_buf_data in 32-bit chunks */
47 1 : unsigned int rb_size32;
48 :
49 : /**
50 : * Line buffer for incoming messages, characters accumulate here
51 : * and then are sent to printk() once full (including a trailing NULL)
52 : * or a carriage return seen
53 : */
54 1 : char *line_buf;
55 :
56 : /** Size in bytes of the line buffer. Must be at least 2 */
57 1 : unsigned int lb_size;
58 :
59 : /**
60 : * Destination for received console messages, one of
61 : * IPM_CONSOLE_STDOUT or IPM_CONSOLE_PRINTK
62 : */
63 1 : unsigned int flags;
64 : };
65 :
66 0 : struct ipm_console_receiver_runtime_data {
67 : /** Buffer for received bytes from the low-level IPM device */
68 1 : struct ring_buf rb;
69 :
70 : /** Semaphore to wake up the thread to print out messages */
71 1 : struct k_sem sem;
72 :
73 : /** pointer to the bound low-level IPM device */
74 1 : const struct device *ipm_device;
75 :
76 : /** Indicator that the channel is temporarily disabled due to
77 : * full buffer
78 : */
79 1 : int channel_disabled;
80 :
81 : /** Receiver worker thread */
82 1 : struct k_thread rx_thread;
83 : };
84 :
85 0 : struct ipm_console_sender_config_info {
86 : /** Name of the low-level driver to bind to */
87 1 : char *bind_to;
88 :
89 : /**
90 : * Source of messages to forward, hooks will be installed.
91 : * Can be IPM_CONSOLE_STDOUT, IPM_CONSOLE_PRINTK, or both
92 : */
93 1 : int flags;
94 : };
95 :
96 : #if CONFIG_IPM_CONSOLE_RECEIVER
97 : int ipm_console_receiver_init(const struct device *d);
98 : #endif
99 :
100 : #if CONFIG_IPM_CONSOLE_SENDER
101 : int ipm_console_sender_init(const struct device *d);
102 : #endif
103 :
104 : #ifdef __cplusplus
105 : }
106 : #endif
107 :
108 : #endif /* ZEPHYR_INCLUDE_DRIVERS_CONSOLE_IPM_CONSOLE_H_ */
|