Developer World
Spresense SDK Library v3.2.0-ebc0364
Message.h
Go to the documentation of this file.
1/****************************************************************************
2 * modules/include/memutils/message/Message.h
3 *
4 * Copyright 2018 Sony Semiconductor Solutions Corporation
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 * 3. Neither the name of Sony Semiconductor Solutions Corporation nor
17 * the names of its contributors may be used to endorse or promote
18 * products derived from this software without specific prior written
19 * permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
28 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 *
34 ****************************************************************************/
40#ifndef __SONY_APPS_INCLUDE_MEMUTILS_MESSAGE_MESSAGE_H
41#define __SONY_APPS_INCLUDE_MEMUTILS_MESSAGE_MESSAGE_H
42
52#include "memutils/common_utils/common_errcode.h"
53#include "memutils/message/message_type.h"
55
56#define MSG_LIB_NAME "MsgLib"
57#define MSG_LIB_VER "2.03"
58#define MSG_QUE_NULL 0
59
60/*****************************************************************
61 * Types of data generated by the message queue layout generation tool
62 *****************************************************************
63 */
64struct MsgQueDef {
65 drm_t n_drm;
66 uint16_t n_size;
67 uint16_t n_num;
68 drm_t h_drm;
69 uint16_t h_size;
70 uint16_t h_num;
71 MsgCpuId owner;
72#ifdef USE_MULTI_CORE
73 InterCpuLock::SpinLockId spinlock;
74#else
75 uint16_t spinlock;
76#endif
77}; /* MsgQueDef */
78
79/*****************************************************************
80 * Message library class
81 *****************************************************************
82 */
83
88class MsgLib {
89private:
90 static uint32_t num_msg_pools;
91 static uint32_t msgq_top_drm;
92
93public:
94
101 static err_t initFirst(uint32_t num_pools, uint32_t top_drm);
102
109 static err_t initPerCpu();
110
117 static err_t finalize();
118
119 /* Get initialization state. */
120
121 static bool isInitFirstComplete();
122
123 /* Get initialization state of message queue. */
124
125 static err_t isInitComplete(MsgQueId id, bool &done);
126
127 /* Get a reference to the specified message queue block. */
128
129 static err_t referMsgQueBlock(MsgQueId id, MsgQueBlock **que);
130
131 /* Transmission of message packet.(task context, no parameter) */
132 static err_t send(MsgQueId dest, MsgPri pri, MsgType type, MsgQueId reply);
133
134 /* Transmission of message packet.(task context, with parameter) */
144 template<typename T>
145 static err_t send(MsgQueId dest, MsgPri pri, MsgType type, MsgQueId reply, const T& param)
146 {
147 FAR MsgQueBlock* que;
148 err_t err_code = ERR_OK;
149
150 err_code = referMsgQueBlock(dest, &que);
151 if (err_code == ERR_OK)
152 {
153 return que->send(pri, type, reply, MsgPacket::MsgFlagWaitParam, param);
154 }
155
156 return err_code;
157 }
158
159 /* Transmission of message packet.(task context, address range parameter) */
160 static err_t send(MsgQueId dest, MsgPri pri, MsgType type, MsgQueId reply, const void* param, size_t param_size);
161
162 /* Transmission of message packet.(non task context, no parameters) */
163 static err_t sendIsr(MsgQueId dest, MsgPri pri, MsgType type, MsgQueId reply);
164
165 /* Transmission of message packet.(non task context, with parameter) */
166 template<typename T>
167 static err_t sendIsr(MsgQueId dest, MsgPri pri, MsgType type, MsgQueId reply, const T& param)
168 {
169 FAR MsgQueBlock* que;
170 err_t err_code = ERR_OK;
171
172 err_code = referMsgQueBlock(dest, &que);
173 if (err_code == ERR_OK)
174 {
175 return que->sendIsr(pri, type, reply, param);
176 }
177
178 return err_code;
179 }
180
181 /* Transmission of message packet.(non task context, address range parameter) */
182 static err_t sendIsr(MsgQueId dest, MsgPri pri, MsgType type, MsgQueId reply, const void* param, size_t param_size);
183
184 /* Notify message reception (call this API from inter-processor communication interrupt handler) */
185 static err_t notifyRecv(MsgQueId dest);
186
187 static void dump();
188
189}; /* class MsgLib */
190
191#include "MsgNotify.h" /* User implemented by processor */
192
201#endif /* __SONY_APPS_INCLUDE_MEMUTILS_MESSAGE_MESSAGE_H */
Message Library API.
Message Library Class.
Definition: Message.h:88
static err_t initPerCpu()
static err_t send(MsgQueId dest, MsgPri pri, MsgType type, MsgQueId reply, const T &param)
Definition: Message.h:145
static err_t initFirst(uint32_t num_pools, uint32_t top_drm)
static err_t finalize()
Message Queue Class.
Definition: MsgQueBlock.h:72
Definition: Message.h:64