Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
xIFO.h
00001 00002 /** 00003 * @file xifo.h 00004 * @brief xifo circular buffer 00005 * @details xifo supplies object oriented circular buffer with 32 bit size elements. \n 00006 * To use either as FIFO (First In First Out) or as FILO (First In Last Out) 00007 * 00008 * @author Jeroen Lodder 00009 * @date April 2013 00010 * @version 2 00011 * 00012 * @{ 00013 */ 00014 00015 /** 00016 * Code has been tested on Cortex M0 (LPC1114) 00017 * Performance table, number of core clocks 00018 * Measured with a timer before and after 00019 * r1 = timer->TC 00020 * test_function 00021 * r2 = timer->TC 00022 * 00023 * Function Speed Worst Case 00024 * 00025 * write 69 71 00026 * read_mr 59 59 00027 * read_lr 63 70 00028 * pop_mr 76 78 00029 * pop_lr 45 45 00030 * 00031 */ 00032 00033 #ifndef _xifo_H_ 00034 #define _xifo_H_ 00035 00036 #include <inttypes.h> 00037 00038 #if defined(__arm__) || defined(__DOXYGEN__) 00039 #pragma anon_unions /**< Allow unnamed unions */ 00040 #endif 00041 00042 /** 00043 * @brief Circular Buffer object. 00044 * @details This struct holds the object of a circular buffer 00045 */ 00046 typedef struct { 00047 /* Pointers: */ 00048 uint32_t *startpool; /**< @brief First element in pool */ 00049 uint32_t *endpool; /**< @brief Last element in pool */ 00050 uint32_t *read; /**< @brief Read pointer */ 00051 uint32_t *write; /**< @brief Write pointer */ 00052 /* Variables: */ 00053 uint32_t full; /**< @brief Flag indicating buffer is full */ 00054 uint32_t elementcount;/**< @brief Number of elements used */ 00055 uint32_t size; /**< @brief Size of buffer */ 00056 /* Locally used in functions to prevent stack use: */ 00057 /**< @brief union to prevent lvalue typecasting */ 00058 union { 00059 uint32_t temp; /**< @brief temp variable and padding for even sized block */ 00060 uint32_t *ptemp; /**< @brief temp variable and padding for even sized block */ 00061 }; 00062 }xifo_t; 00063 00064 /** 00065 * @brief Circular Buffer memory pool type. 00066 */ 00067 typedef unsigned int xifo_pool_t; 00068 00069 #ifdef __cplusplus 00070 extern "C" { 00071 #endif 00072 /* xifo Common */ 00073 void xifo_init(xifo_t *c, uint32_t size, uint32_t *startpool); 00074 void xifo_clear(xifo_t *c); 00075 uint32_t xifo_write(xifo_t *c, uint32_t data); 00076 /* FIFO use */ 00077 uint32_t xifo_read_lr(xifo_t *c, uint32_t index); 00078 uint32_t xifo_pop_lr(xifo_t *c); 00079 /* LIFO use */ 00080 uint32_t xifo_read_mr(xifo_t *c, uint32_t index); 00081 uint32_t xifo_pop_mr(xifo_t *c); 00082 /* Extractors */ 00083 uint32_t xifo_get_size(xifo_t *c); 00084 uint32_t xifo_get_used(xifo_t *c); 00085 uint32_t xifo_get_full(xifo_t *c); 00086 uint32_t xifo_get_free(xifo_t *c); 00087 #ifdef __cplusplus 00088 } 00089 #endif 00090 #endif //_xifo_H_ 00091 00092 /** @} */
Generated on Thu Jul 14 2022 08:02:50 by
1.7.2