1 /*
2 * Copyright (c) 2021 Chipsea Technologies (Shenzhen) Corp., Ltd. All rights reserved.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15 #ifndef _BLE_KE_MSG_STRUCT_H
16 #define _BLE_KE_MSG_STRUCT_H
17
18 /// Message structure.
19 struct ke_msg
20 {
21 struct co_list_hdr hdr; ///< List header for chaining
22
23 ke_msg_id_t id; ///< Message id.
24 ke_task_id_t dest_id; ///< Destination kernel identifier.
25 ke_task_id_t src_id; ///< Source kernel identifier.
26 uint16_t param_len; ///< Parameter embedded struct length.
27 uint32_t param[__ARRAY_EMPTY]; ///< Parameter embedded struct. Must be word-aligned.
28 };
29
30
31 /// Status returned by a task when handling a message
32 /*@TRACE*/
33 enum ke_msg_status_tag
34 {
35 KE_MSG_CONSUMED = 0, ///< consumed, msg and ext are freed by the kernel
36 KE_MSG_NO_FREE, ///< consumed, nothing is freed by the kernel
37 KE_MSG_SAVED, ///< not consumed, will be pushed in the saved queue
38 };
39
ke_param2msg(void const * param_ptr)40 __INLINE struct ke_msg * ke_param2msg(void const *param_ptr)
41 {
42 return (struct ke_msg*) (((uint8_t*)param_ptr) - offsetof(struct ke_msg, param));
43 }
44
ke_msg2param(struct ke_msg const * msg)45 __INLINE void * ke_msg2param(struct ke_msg const *msg)
46 {
47 return (void*) (((uint8_t*) msg) + offsetof(struct ke_msg, param));
48 }
49
50 #endif // _BLE_KE_MSG_STRUCT_H
51