1 /* 2 * Arm SCP/MCP Software 3 * Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved. 4 * 5 * SPDX-License-Identifier: BSD-3-Clause 6 */ 7 8 #ifndef _CLI_FIFO_H_ 9 #define _CLI_FIFO_H_ 10 11 #include <stdbool.h> 12 #include <stdint.h> 13 14 /*****************************************************************************/ 15 /* Structure Types */ 16 /*****************************************************************************/ 17 18 typedef struct { 19 uint32_t put_ptr; 20 uint32_t get_ptr; 21 uint32_t count; 22 uint32_t high_water; 23 bool reset_high_water; 24 uint32_t buf_size; 25 char *buf; 26 } fifo_st; 27 28 /*****************************************************************************/ 29 /* Function Prototypes */ 30 /*****************************************************************************/ 31 32 /* 33 * fifo_init 34 * Description 35 * Initializes a FIFO structure, the caller must supply the buffer memory. 36 * Parameters 37 * fifo_st *fifo 38 * Pointer to a pre-allocated fifo_st structure. 39 * char *buf 40 * Pointer to memory to store FIFO entries. 41 * uint32_t buf_size 42 * Size of the buffer in bytes. 43 * Return 44 * Platform return codes defined in cli_config.h. 45 */ 46 uint32_t fifo_init(fifo_st *fifo, char *buf, uint32_t buf_size); 47 48 /* 49 * fifo_get 50 * Description 51 * Gets a byte from a FIFO and places into the address supplied. 52 * Parameters 53 * fifo_st *fifo 54 * Pointer to fifo_st structure to get the byte from. 55 * char *val 56 * Pointer to location in which to place the retrieved byte. 57 * Return 58 * Platform return codes defined in cli_config.h. 59 */ 60 uint32_t fifo_get(fifo_st *fifo, char *val); 61 62 /* 63 * fifo_put 64 * Description 65 * Places a byte into a FIFO buffer. 66 * Parameters 67 * fifo_st *fifo 68 * Pointer to fifo_st structure to put the byte into. 69 * char *val 70 * Pointer to location from which to get the byte. 71 * Return 72 * Platform return codes defined in cli_config.h. 73 */ 74 uint32_t fifo_put(fifo_st *fifo, char *val); 75 76 /* 77 * fifo_free_space 78 * Description 79 * Returns the number of unused entries in the FIFO buffer. 80 * Parameters 81 * fifo_st *fifo 82 * Pointer to fifo_st structure to get the free space from. 83 * Return 84 * Number of free spaces in the FIFO. 85 */ 86 uint32_t fifo_free_space(fifo_st *fifo); 87 88 /* 89 * fifo_count 90 * Description 91 * Returns the number of bytes currently in a FIFO. 92 * Paremeters 93 * fifo_st *fifo 94 * Buffer from which to get the count. 95 * Return 96 * Number of bytes in the FIFO. 97 */ 98 uint32_t fifo_count(fifo_st *fifo); 99 100 /* 101 * fifo_capacity 102 * Description 103 * Gets the maximum number of bytes that can be stored by a FIFO. 104 * Parameters 105 * fifo_st *fifo 106 * Pointer to FIFO structure from which to get the capacity. 107 * Return 108 * Total capacity of the FIFO, this will be one less than the buffer size. 109 */ 110 uint32_t fifo_capacity(fifo_st *fifo); 111 112 /* 113 * fifo_high_water 114 * Description 115 * Returns the high-water point from the FIFO buffer. 116 * Parameters 117 * fifo_st *fifo 118 * Buffer structure to get the high-water count from. 119 * Return 120 * High water mark from FIFO. 121 */ 122 uint32_t fifo_high_water(fifo_st *fifo); 123 124 /* 125 * fifo_high_water_reset 126 * Description 127 * Resets the high water counter by freezing it until the buffer is empty. 128 * Paremeters 129 * fifo_st *fifo 130 * Buffer structure to reset the high-water count in. 131 * Return 132 * Platform return codes defined in cli_config.h. 133 */ 134 uint32_t fifo_high_water_reset(fifo_st *fifo); 135 136 /* 137 * fifo_empty 138 * Description 139 * Removes every item from the FIFO buffer. 140 * Parameters 141 * fifo_st *fifo 142 * Pointer to fifo_st structure to empty. 143 * Return 144 * Platform return codes defined in cli_config.h. 145 */ 146 uint32_t fifo_empty(fifo_st *fifo); 147 148 #endif /* _CLI_FIFO_H_ */ 149