blob: a02fdd8835afaf95fc11ab340009fdff23409834 [file] [log] [blame]
Bence Balogh7aec0572024-01-11 10:42:49 +01001/*
2 * Copyright (c) 2022-2023 Arm Limited. All rights reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef __MHU_H__
18#define __MHU_H__
19
20#include <stddef.h>
21#include <stdint.h>
22
23#ifdef __cplusplus
24extern "C" {
25#endif
26
27/**
28 * Generic MHU error enumeration types.
29 */
30enum mhu_error_t {
31 MHU_ERR_NONE = 0,
32 MHU_ERR_NOT_INIT = -1,
33 MHU_ERR_ALREADY_INIT = -2,
34 MHU_ERR_UNSUPPORTED_VERSION = -3,
35 MHU_ERR_UNSUPPORTED = -4,
36 MHU_ERR_INVALID_ARG = -5,
37 MHU_ERR_BUFFER_TOO_SMALL = -6,
38 MHU_ERR_GENERAL = -7,
39};
40
41/**
42 * \brief Initializes sender MHU.
43 *
44 * \param[in] mhu_sender_dev Pointer to the sender MHU.
45 *
46 * \return Returns mhu_error_t error code.
47 *
48 * \note This function must be called before mhu_send_data().
49 */
50enum mhu_error_t mhu_init_sender(void *mhu_sender_dev);
51
52/**
53 * \brief Initializes receiver MHU.
54 *
55 * \param[in] mhu_receiver_dev Pointer to the receiver MHU.
56 *
57 * \return Returns mhu_error_t error code.
58 *
59 * \note This function must be called before mhu_receive_data().
60 */
61enum mhu_error_t mhu_init_receiver(void *mhu_receiver_dev);
62
63/**
64 * \brief Sends data over MHU.
65 *
66 * \param[in] mhu_sender_dev Pointer to the sender MHU.
67 * \param[in] send_buffer Pointer to buffer containing the data to be
68 * transmitted.
69 * \param[in] size Size of the data to be transmitted in bytes.
70 *
71 * \return Returns mhu_error_t error code.
72 *
73 * \note The send_buffer must be 4-byte aligned and its length must be at least
74 * (4 - (size % 4)) bytes bigger than the data size to prevent buffer
75 * over-reading.
76 */
77enum mhu_error_t mhu_send_data(void *mhu_sender_dev,
78 const uint8_t *send_buffer,
79 size_t size);
80
81/**
82 * \brief Wait for data from MHU.
83 *
84 * \param[in] mhu_receiver_dev Pointer to the receiver MHU.
85 *
86 * \return Returns mhu_error_t error code.
87 *
88 * \note This function must be called before mhu_receive_data() if the MHU
89 * receiver interrupt is not used.
90 */
91enum mhu_error_t mhu_wait_data(void *mhu_receiver_dev);
92
93/**
94 * \brief Receives data from MHU.
95 *
96 * \param[in] mhu_receiver_dev Pointer to the receiver MHU.
97 * \param[out] receive_buffer Pointer the buffer where to store the
98 * received data.
99 * \param[in,out] size As input the size of the receive_buffer,
100 * as output the number of bytes received.
101 * As a limitation, the size of the buffer
102 * must be a multiple of 4.
103 *
104 * \return Returns mhu_error_t error code.
105 *
106 * \note The receive_buffer must be 4-byte aligned and its length must be a
107 * multiple of 4.
108 */
109enum mhu_error_t mhu_receive_data(void *mhu_receiver_dev,
110 uint8_t *receive_buffer,
111 size_t *size);
112
113/**
114 * \brief Signals an interrupt over the last available channel and wait for the
115 * values to be cleared by the receiver.
116 *
117 * \param[in] mhu_sender_dev Pointer to the sender MHU.
118 * \param[in] value Value that will be used while signaling.
119 *
120 * \return Returns mhu_error_t error code.
121 */
122enum mhu_error_t signal_and_wait_for_clear(void *mhu_sender_dev,
123 uint32_t value);
124
125/**
126 * \brief Wait for signal on the last available channel in a loop and
127 * acknowledge the transfer by clearing the status on that channel.
128 *
129 * \param[in] mhu_receiver_dev Pointer to the receiver MHU.
130 * \param[in] value Value that will be used while waiting.
131 *
132 * \return Returns mhu_error_t error code.
133 */
134enum mhu_error_t wait_for_signal_and_clear(void *mhu_receiver_dev,
135 uint32_t value);
136#ifdef __cplusplus
137}
138#endif
139
140#endif /* __MHU_H__ */