1 /* 2 * Copyright (c) 2022 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 24 extern "C" { 25 #endif 26 27 /** 28 * Generic MHU error enumeration types. 29 */ 30 enum 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 */ 50 enum 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 */ 61 enum 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 */ 77 enum mhu_error_t mhu_send_data(void *mhu_sender_dev, 78 const uint8_t *send_buffer, 79 size_t size); 80 81 /** 82 * \brief Receives data from MHU. 83 * 84 * \param[in] mhu_receiver_dev Pointer to the receiver MHU. 85 * \param[out] receive_buffer Pointer the buffer where to store the 86 * received data. 87 * \param[in,out] size As input the size of the receive_buffer, 88 * as output the number of bytes received. 89 * As a limitation, the size of the buffer 90 * must be a multiple of 4. 91 * 92 * \return Returns mhu_error_t error code. 93 * 94 * \note The receive_buffer must be 4-byte aligned and its length must be a 95 * multiple of 4. 96 */ 97 enum mhu_error_t mhu_receive_data(void *mhu_receiver_dev, 98 uint8_t *receive_buffer, 99 size_t *size); 100 101 #ifdef __cplusplus 102 } 103 #endif 104 105 #endif /* __MHU_H__ */ 106