1 /*
2  * Copyright (c) 2014, Mentor Graphics Corporation
3  * Copyright (c) 2015 Xilinx, Inc.
4  * Copyright (c) 2016 Freescale Semiconductor, Inc.
5  * Copyright 2016-2022 NXP
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright notice,
12  *    this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright notice,
14  *    this list of conditions and the following disclaimer in the documentation
15  *    and/or other materials provided with the distribution.
16  * 3. Neither the name of the copyright holder nor the names of its
17  *    contributors may be used to endorse or promote products derived from this
18  *    software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
24  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #ifndef RPMSG_DEFAULT_CONFIG_H_
34 #define RPMSG_DEFAULT_CONFIG_H_
35 
36 #define RL_USE_CUSTOM_CONFIG (1)
37 
38 #if RL_USE_CUSTOM_CONFIG
39 #include "rpmsg_config.h"
40 #endif
41 
42 /*!
43  * @addtogroup config
44  * @{
45  * @file
46  */
47 
48 //! @name Configuration options
49 //@{
50 
51 //! @def RL_MS_PER_INTERVAL
52 //!
53 //! Delay in milliseconds used in non-blocking API functions for polling.
54 //! The default value is 1.
55 #ifndef RL_MS_PER_INTERVAL
56 #define RL_MS_PER_INTERVAL (1)
57 #endif
58 
59 //! @def RL_ALLOW_CUSTOM_SHMEM_CONFIG
60 //!
61 //! This option allows to define custom shared memory configuration and replacing
62 //! the shared memory related global settings from rpmsg_config.h This is useful
63 //! when multiple instances are running in parallel but different shared memory
64 //! arrangement (vring size & alignment, buffers size & count) is required. Note,
65 //! that once enabled the platform_get_custom_shmem_config() function needs
66 //! to be implemented in platform layer. The default value is 0 (all RPMsg_Lite
67 //! instances use the same shared memory arrangement as defined by common config macros).
68 #ifndef RL_ALLOW_CUSTOM_SHMEM_CONFIG
69 #define RL_ALLOW_CUSTOM_SHMEM_CONFIG (0)
70 #endif
71 
72 #if !(defined(RL_ALLOW_CUSTOM_SHMEM_CONFIG) && (RL_ALLOW_CUSTOM_SHMEM_CONFIG == 1))
73 //! @def RL_BUFFER_PAYLOAD_SIZE
74 //!
75 //! Size of the buffer payload, it must be equal to (240, 496, 1008, ...)
76 //! [2^n - 16]. Ensure the same value is defined on both sides of rpmsg
77 //! communication. The default value is 496U.
78 #ifndef RL_BUFFER_PAYLOAD_SIZE
79 #define RL_BUFFER_PAYLOAD_SIZE (496U)
80 #endif
81 
82 //! @def RL_BUFFER_COUNT
83 //!
84 //! Number of the buffers, it must be power of two (2, 4, ...).
85 //! The default value is 2U.
86 //! Note this value defines the buffer count for one direction of the rpmsg
87 //! communication only, i.e. if the default value of 2 is used
88 //! in rpmsg_config.h files for the master and the remote side, 4 buffers
89 //! in total are created in the shared memory.
90 #ifndef RL_BUFFER_COUNT
91 #define RL_BUFFER_COUNT (2U)
92 #endif
93 
94 #else
95 //! Define the buffer payload and count per different link IDs (rpmsg_lite instance) when RL_ALLOW_CUSTOM_SHMEM_CONFIG
96 //! is set.
97 //! Refer to the rpmsg_plaform.h for the used link IDs.
98 #ifndef RL_BUFFER_PAYLOAD_SIZE
99 #define RL_BUFFER_PAYLOAD_SIZE(link_id) (496U)
100 #endif
101 
102 #ifndef RL_BUFFER_COUNT
103 #define RL_BUFFER_COUNT(link_id) (((link_id) == 0U) ? 256U : 2U)
104 #endif
105 #endif /* !(defined(RL_ALLOW_CUSTOM_SHMEM_CONFIG) && (RL_ALLOW_CUSTOM_SHMEM_CONFIG == 1))*/
106 
107 //! @def RL_API_HAS_ZEROCOPY
108 //!
109 //! Zero-copy API functions enabled/disabled.
110 //! The default value is 1 (enabled).
111 #ifndef RL_API_HAS_ZEROCOPY
112 #define RL_API_HAS_ZEROCOPY (1)
113 #endif
114 
115 //! @def RL_USE_STATIC_API
116 //!
117 //! Static API functions (no dynamic allocation) enabled/disabled.
118 //! The default value is 0 (static API disabled).
119 #ifndef RL_USE_STATIC_API
120 #define RL_USE_STATIC_API (0)
121 #endif
122 
123 //! @def RL_CLEAR_USED_BUFFERS
124 //!
125 //! Clearing used buffers before returning back to the pool of free buffers
126 //! enabled/disabled.
127 //! The default value is 0 (disabled).
128 #ifndef RL_CLEAR_USED_BUFFERS
129 #define RL_CLEAR_USED_BUFFERS (0)
130 #endif
131 
132 //! @def RL_USE_MCMGR_IPC_ISR_HANDLER
133 //!
134 //! When enabled IPC interrupts are managed by the Multicore Manager (IPC
135 //! interrupts router), when disabled RPMsg-Lite manages IPC interrupts
136 //! by itself.
137 //! The default value is 0 (no MCMGR IPC ISR handler used).
138 #ifndef RL_USE_MCMGR_IPC_ISR_HANDLER
139 #define RL_USE_MCMGR_IPC_ISR_HANDLER (0)
140 #endif
141 
142 //! @def RL_USE_ENVIRONMENT_CONTEXT
143 //!
144 //! When enabled the environment layer uses its own context.
145 //! Added for QNX port mainly, but can be used if required.
146 //! The default value is 0 (no context, saves some RAM).
147 #ifndef RL_USE_ENVIRONMENT_CONTEXT
148 #define RL_USE_ENVIRONMENT_CONTEXT (0)
149 #endif
150 
151 //! @def RL_DEBUG_CHECK_BUFFERS
152 //!
153 //! When enabled buffer pointers passed to rpmsg_lite_send_nocopy() and
154 //! rpmsg_lite_release_rx_buffer() functions (enabled by RL_API_HAS_ZEROCOPY config)
155 //! are checked to avoid passing invalid buffer pointer.
156 //! The default value is 0 (disabled). Do not use in RPMsg-Lite to Linux configuration.
157 #ifndef RL_DEBUG_CHECK_BUFFERS
158 #define RL_DEBUG_CHECK_BUFFERS (0)
159 #endif
160 
161 //! @def RL_ALLOW_CONSUMED_BUFFERS_NOTIFICATION
162 //!
163 //! When enabled the opposite side is notified each time received buffers
164 //! are consumed and put into the queue of available buffers.
165 //! Enable this option in RPMsg-Lite to Linux configuration to allow unblocking
166 //! of the Linux blocking send.
167 //! The default value is 0 (RPMsg-Lite to RPMsg-Lite communication).
168 #ifndef RL_ALLOW_CONSUMED_BUFFERS_NOTIFICATION
169 #define RL_ALLOW_CONSUMED_BUFFERS_NOTIFICATION (0)
170 #endif
171 
172 //! @def RL_HANG
173 //!
174 //! Default implementation of hang assert function
RL_HANG(void)175 static inline void RL_HANG(void)
176 {
177     /* coco begin validated: RL_HANG not reachable in unit tests when own RL_ASSERT implementation used */
178     for (;;)
179     {
180     }
181 }
182 /* coco end */
183 
184 //! @def RL_ASSERT
185 //!
186 //! Assert implementation.
187 #ifndef RL_ASSERT
188 #define RL_ASSERT_BOOL(b) \
189     do                    \
190     {                     \
191         if (!(b))         \
192         {                 \
193             RL_HANG();    \
194         }                 \
195     } while (0 == 1);
196 #define RL_ASSERT(x) RL_ASSERT_BOOL((int32_t)(x) != 0)
197 
198 #endif
199 //@}
200 
201 #endif /* RPMSG_DEFAULT_CONFIG_H_ */
202