Darien Figueroa / Mbed OS Final_Program

Dependencies:   USBDevice

Committer:
darienf
Date:
Sat Apr 10 03:05:42 2021 +0000
Revision:
3:36de8b9e4b1a
Parent:
HSP/RpcServer/RpcFifo.h@0:832122ce6748
ayoooo

Who changed what in which revision?

UserRevisionLine numberNew contents of line
darienf 0:832122ce6748 1 /*******************************************************************************
darienf 0:832122ce6748 2 * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved.
darienf 0:832122ce6748 3 *
darienf 0:832122ce6748 4 * Permission is hereby granted, free of charge, to any person obtaining a
darienf 0:832122ce6748 5 * copy of this software and associated documentation files (the "Software"),
darienf 0:832122ce6748 6 * to deal in the Software without restriction, including without limitation
darienf 0:832122ce6748 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
darienf 0:832122ce6748 8 * and/or sell copies of the Software, and to permit persons to whom the
darienf 0:832122ce6748 9 * Software is furnished to do so, subject to the following conditions:
darienf 0:832122ce6748 10 *
darienf 0:832122ce6748 11 * The above copyright notice and this permission notice shall be included
darienf 0:832122ce6748 12 * in all copies or substantial portions of the Software.
darienf 0:832122ce6748 13 *
darienf 0:832122ce6748 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
darienf 0:832122ce6748 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
darienf 0:832122ce6748 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
darienf 0:832122ce6748 17 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
darienf 0:832122ce6748 18 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
darienf 0:832122ce6748 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
darienf 0:832122ce6748 20 * OTHER DEALINGS IN THE SOFTWARE.
darienf 0:832122ce6748 21 *
darienf 0:832122ce6748 22 * Except as contained in this notice, the name of Maxim Integrated
darienf 0:832122ce6748 23 * Products, Inc. shall not be used except as stated in the Maxim Integrated
darienf 0:832122ce6748 24 * Products, Inc. Branding Policy.
darienf 0:832122ce6748 25 *
darienf 0:832122ce6748 26 * The mere transfer of this software does not imply any licenses
darienf 0:832122ce6748 27 * of trade secrets, proprietary technology, copyrights, patents,
darienf 0:832122ce6748 28 * trademarks, maskwork rights, or any other form of intellectual
darienf 0:832122ce6748 29 * property whatsoever. Maxim Integrated Products, Inc. retains all
darienf 0:832122ce6748 30 * ownership rights.
darienf 0:832122ce6748 31 *
darienf 0:832122ce6748 32 ********************************************************************************
darienf 0:832122ce6748 33 */
darienf 0:832122ce6748 34 #ifndef _RPCFIFO_H_
darienf 0:832122ce6748 35 #define _RPCFIFO_H_
darienf 0:832122ce6748 36
darienf 0:832122ce6748 37 #include <stdint.h>
darienf 0:832122ce6748 38
darienf 0:832122ce6748 39 /// Structure used for FIFO management
darienf 0:832122ce6748 40 typedef struct {
darienf 0:832122ce6748 41 unsigned int length; ///< FIFO size (number of elements)
darienf 0:832122ce6748 42 void *data; ///< pointer to the FIFO buffer
darienf 0:832122ce6748 43 unsigned int rindex; ///< current FIFO read index
darienf 0:832122ce6748 44 unsigned int windex; ///< current FIFO write index
darienf 0:832122ce6748 45 } fifo_t;
darienf 0:832122ce6748 46
darienf 0:832122ce6748 47 /**
darienf 0:832122ce6748 48 * @param fifo FIFO on which to perform the operation
darienf 0:832122ce6748 49 * @param mem memory buffer to use for FIFO element storage
darienf 0:832122ce6748 50 * @param length number of elements that the memory buffer can contain
darienf 0:832122ce6748 51 * @returns 0 if successful, -1 upon failure
darienf 0:832122ce6748 52 */
darienf 0:832122ce6748 53 void fifo_init(fifo_t *fifo, void *mem, unsigned int length);
darienf 0:832122ce6748 54
darienf 0:832122ce6748 55 /**
darienf 0:832122ce6748 56 * @brief Adds and 8-bit element to the FIFO
darienf 0:832122ce6748 57 * @param fifo FIFO on which to perform the operation
darienf 0:832122ce6748 58 * @param element element to add to the FIFO
darienf 0:832122ce6748 59 * @returns 0 if successful, -1 upon failure
darienf 0:832122ce6748 60 */
darienf 0:832122ce6748 61 int fifo_put8(fifo_t *fifo, uint8_t element);
darienf 0:832122ce6748 62
darienf 0:832122ce6748 63 /**
darienf 0:832122ce6748 64 * @brief Gets the next 8-bit element to the FIFO
darienf 0:832122ce6748 65 * @param fifo FIFO on which to perform the operation
darienf 0:832122ce6748 66 * @param element pointer to where to store the element from the FIFO
darienf 0:832122ce6748 67 * @returns 0 if successful, -1 upon failure
darienf 0:832122ce6748 68 */
darienf 0:832122ce6748 69 int fifo_get8(fifo_t *fifo, uint8_t *element);
darienf 0:832122ce6748 70
darienf 0:832122ce6748 71 /**
darienf 0:832122ce6748 72 * @brief Adds the next 16-bit element to the FIFO
darienf 0:832122ce6748 73 * @param fifo FIFO on which to perform the operation
darienf 0:832122ce6748 74 * @param element element to add to the FIFO
darienf 0:832122ce6748 75 * @returns 0 if successful, -1 upon failure
darienf 0:832122ce6748 76 */
darienf 0:832122ce6748 77 int fifo_put16(fifo_t *fifo, uint16_t element);
darienf 0:832122ce6748 78
darienf 0:832122ce6748 79 /**
darienf 0:832122ce6748 80 * @brief Gets the next 16-bit element to the FIFO
darienf 0:832122ce6748 81 * @param fifo FIFO on which to perform the operation
darienf 0:832122ce6748 82 * @param element pointer to where to store the element from the FIFO
darienf 0:832122ce6748 83 * @returns 0 if successful, -1 upon failure
darienf 0:832122ce6748 84 */
darienf 0:832122ce6748 85 int fifo_get16(fifo_t *fifo, uint16_t *element);
darienf 0:832122ce6748 86
darienf 0:832122ce6748 87 /**
darienf 0:832122ce6748 88 * @brief Adds the next 16-bit element to the FIFO
darienf 0:832122ce6748 89 * @param fifo FIFO on which to perform the operation
darienf 0:832122ce6748 90 * @param element element to add to the FIFO
darienf 0:832122ce6748 91 * @returns 0 if successful, -1 upon failure
darienf 0:832122ce6748 92 */
darienf 0:832122ce6748 93 int fifo_put32(fifo_t *fifo, uint32_t element);
darienf 0:832122ce6748 94
darienf 0:832122ce6748 95 /**
darienf 0:832122ce6748 96 * @brief Gets the next 16-bit element to the FIFO
darienf 0:832122ce6748 97 * @param fifo FIFO on which to perform the operation
darienf 0:832122ce6748 98 * @param element pointer to where to store the element from the FIFO
darienf 0:832122ce6748 99 * @returns 0 if successful, -1 upon failure
darienf 0:832122ce6748 100 */
darienf 0:832122ce6748 101 int fifo_get32(fifo_t *fifo, uint32_t *element);
darienf 0:832122ce6748 102
darienf 0:832122ce6748 103 /**
darienf 0:832122ce6748 104 * @brief Immediately resets the FIFO to the empty state
darienf 0:832122ce6748 105 * @param fifo FIFO on which to perform the operation
darienf 0:832122ce6748 106 */
darienf 0:832122ce6748 107 void fifo_clear(fifo_t *fifo);
darienf 0:832122ce6748 108
darienf 0:832122ce6748 109 /**
darienf 0:832122ce6748 110 * @brief Determines if the FIFO is empty
darienf 0:832122ce6748 111 * @param fifo FIFO on which to perform the operation
darienf 0:832122ce6748 112 * @returns #TRUE if FIFO is empty, #FALSE otherwise
darienf 0:832122ce6748 113 */
darienf 0:832122ce6748 114 int fifo_empty(fifo_t *fifo);
darienf 0:832122ce6748 115
darienf 0:832122ce6748 116 /**
darienf 0:832122ce6748 117 * @brief FIFO status function
darienf 0:832122ce6748 118 * @param fifo FIFO on which to perform the operation
darienf 0:832122ce6748 119 * @returns #TRUE if FIFO is full, #FALSE otherwise
darienf 0:832122ce6748 120 */
darienf 0:832122ce6748 121 int fifo_full(fifo_t *fifo);
darienf 0:832122ce6748 122
darienf 0:832122ce6748 123 /**
darienf 0:832122ce6748 124 * @brief FIFO status function
darienf 0:832122ce6748 125 * @param fifo FIFO on which to perform the operation
darienf 0:832122ce6748 126 * @returns the number of elements currently in the FIFO
darienf 0:832122ce6748 127 */
darienf 0:832122ce6748 128 unsigned int fifo_level(fifo_t *fifo);
darienf 0:832122ce6748 129
darienf 0:832122ce6748 130 /**
darienf 0:832122ce6748 131 * @brief FIFO status function
darienf 0:832122ce6748 132 * @param fifo FIFO on which to perform the operation
darienf 0:832122ce6748 133 * @returns the remaining elements that can be added to the FIFO
darienf 0:832122ce6748 134 */
darienf 0:832122ce6748 135 unsigned int fifo_remaining(fifo_t *fifo);
darienf 0:832122ce6748 136
darienf 0:832122ce6748 137 #endif // _RPCFIFO_H_