1*91f16700Schasinglulu /* 2*91f16700Schasinglulu * Copyright (c) 2022, Arm Limited. All rights reserved. 3*91f16700Schasinglulu * 4*91f16700Schasinglulu * SPDX-License-Identifier: BSD-3-Clause 5*91f16700Schasinglulu */ 6*91f16700Schasinglulu 7*91f16700Schasinglulu #ifndef MHU_H 8*91f16700Schasinglulu #define MHU_H 9*91f16700Schasinglulu 10*91f16700Schasinglulu #include <stddef.h> 11*91f16700Schasinglulu #include <stdint.h> 12*91f16700Schasinglulu 13*91f16700Schasinglulu /** 14*91f16700Schasinglulu * Generic MHU error enumeration types. 15*91f16700Schasinglulu */ 16*91f16700Schasinglulu enum mhu_error_t { 17*91f16700Schasinglulu MHU_ERR_NONE = 0, 18*91f16700Schasinglulu MHU_ERR_NOT_INIT = -1, 19*91f16700Schasinglulu MHU_ERR_ALREADY_INIT = -2, 20*91f16700Schasinglulu MHU_ERR_UNSUPPORTED_VERSION = -3, 21*91f16700Schasinglulu MHU_ERR_UNSUPPORTED = -4, 22*91f16700Schasinglulu MHU_ERR_INVALID_ARG = -5, 23*91f16700Schasinglulu MHU_ERR_BUFFER_TOO_SMALL = -6, 24*91f16700Schasinglulu MHU_ERR_GENERAL = -7, 25*91f16700Schasinglulu }; 26*91f16700Schasinglulu 27*91f16700Schasinglulu /** 28*91f16700Schasinglulu * Initializes sender MHU. 29*91f16700Schasinglulu * 30*91f16700Schasinglulu * mhu_sender_base Base address of sender MHU. 31*91f16700Schasinglulu * 32*91f16700Schasinglulu * Returns mhu_error_t error code. 33*91f16700Schasinglulu * 34*91f16700Schasinglulu * This function must be called before mhu_send_data(). 35*91f16700Schasinglulu */ 36*91f16700Schasinglulu enum mhu_error_t mhu_init_sender(uintptr_t mhu_sender_base); 37*91f16700Schasinglulu 38*91f16700Schasinglulu 39*91f16700Schasinglulu /** 40*91f16700Schasinglulu * Initializes receiver MHU. 41*91f16700Schasinglulu * 42*91f16700Schasinglulu * mhu_receiver_base Base address of receiver MHU. 43*91f16700Schasinglulu * 44*91f16700Schasinglulu * Returns mhu_error_t error code. 45*91f16700Schasinglulu * 46*91f16700Schasinglulu * This function must be called before mhu_receive_data(). 47*91f16700Schasinglulu */ 48*91f16700Schasinglulu enum mhu_error_t mhu_init_receiver(uintptr_t mhu_receiver_base); 49*91f16700Schasinglulu 50*91f16700Schasinglulu /** 51*91f16700Schasinglulu * Sends data over MHU. 52*91f16700Schasinglulu * 53*91f16700Schasinglulu * send_buffer Pointer to buffer containing the data to be transmitted. 54*91f16700Schasinglulu * size Size of the data to be transmitted in bytes. 55*91f16700Schasinglulu * 56*91f16700Schasinglulu * Returns mhu_error_t error code. 57*91f16700Schasinglulu * 58*91f16700Schasinglulu * The send_buffer must be 4-byte aligned and its length must be at least 59*91f16700Schasinglulu * (4 - (size % 4)) bytes bigger than the data size to prevent buffer 60*91f16700Schasinglulu * over-reading. 61*91f16700Schasinglulu */ 62*91f16700Schasinglulu enum mhu_error_t mhu_send_data(const uint8_t *send_buffer, size_t size); 63*91f16700Schasinglulu 64*91f16700Schasinglulu /** 65*91f16700Schasinglulu * Receives data from MHU. 66*91f16700Schasinglulu * 67*91f16700Schasinglulu * receive_buffer Pointer the buffer where to store the received data. 68*91f16700Schasinglulu * size As input the size of the receive_buffer, as output the 69*91f16700Schasinglulu * number of bytes received. As a limitation, 70*91f16700Schasinglulu * the size of the buffer must be a multiple of 4. 71*91f16700Schasinglulu * 72*91f16700Schasinglulu * Returns mhu_error_t error code. 73*91f16700Schasinglulu * 74*91f16700Schasinglulu * The receive_buffer must be 4-byte aligned and its length must be a 75*91f16700Schasinglulu * multiple of 4. 76*91f16700Schasinglulu */ 77*91f16700Schasinglulu enum mhu_error_t mhu_receive_data(uint8_t *receive_buffer, size_t *size); 78*91f16700Schasinglulu 79*91f16700Schasinglulu /** 80*91f16700Schasinglulu * Gets the maximum amount of bytes that can be transmitted in a single send by MHU. 81*91f16700Schasinglulu * 82*91f16700Schasinglulu * Returns The amount of bytes that can be sent or received in a single message. 83*91f16700Schasinglulu */ 84*91f16700Schasinglulu size_t mhu_get_max_message_size(void); 85*91f16700Schasinglulu 86*91f16700Schasinglulu #endif /* MHU_H */ 87