ring_buf.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /**
  2. *******************************************************************************
  3. * @file usart/usart_uart_int/source/ring_buf.h
  4. * @brief This file contains all the functions prototypes of the ring buffer.
  5. @verbatim
  6. Change Logs:
  7. Date Author Notes
  8. 2022-12-31 CDT First version
  9. @endverbatim
  10. *******************************************************************************
  11. * Copyright (C) 2022, Xiaohua Semiconductor Co., Ltd. All rights reserved.
  12. *
  13. * This software component is licensed by XHSC under BSD 3-Clause license
  14. * (the "License"); You may not use this file except in compliance with the
  15. * License. You may obtain a copy of the License at:
  16. * opensource.org/licenses/BSD-3-Clause
  17. *
  18. *******************************************************************************
  19. */
  20. #ifndef __RING_BUF_H__
  21. #define __RING_BUF_H__
  22. /* C binding of definitions if building with C++ compiler */
  23. #ifdef __cplusplus
  24. extern "C"
  25. {
  26. #endif
  27. /*******************************************************************************
  28. * Include files
  29. ******************************************************************************/
  30. #include <stdbool.h>
  31. #include "hc32_ll_def.h"
  32. /**
  33. * @addtogroup USART_UART_Interrupt
  34. * @{
  35. */
  36. /**
  37. * @addtogroup Ring_Buffer
  38. * @{
  39. */
  40. /*******************************************************************************
  41. * Global type definitions ('typedef')
  42. ******************************************************************************/
  43. /**
  44. * @defgroup Ring_Buffer_Global_Types Ring Buffer Global Types
  45. * @{
  46. */
  47. /**
  48. * @brief Ring buffer structure definition
  49. */
  50. typedef struct {
  51. uint8_t *pu8Data;
  52. uint32_t u32In;
  53. uint32_t u32Out;
  54. uint32_t u32Size;
  55. uint32_t u32FreeSize;
  56. } stc_ring_buf_t;
  57. /**
  58. * @}
  59. */
  60. /*******************************************************************************
  61. * Global pre-processor symbols/macros ('#define')
  62. ******************************************************************************/
  63. /*******************************************************************************
  64. * Global variable definitions ('extern')
  65. ******************************************************************************/
  66. /*******************************************************************************
  67. Global function prototypes (definition in C source)
  68. ******************************************************************************/
  69. /**
  70. * @addtogroup Ring_Buffer_Global_Functions
  71. * @{
  72. */
  73. int32_t BUF_Init(stc_ring_buf_t *pstcBuf, uint8_t *pu8Data, uint32_t u32Size);
  74. uint32_t BUF_FreeSize(const stc_ring_buf_t *pstcBuf);
  75. uint32_t BUF_UsedSize(const stc_ring_buf_t *pstcBuf);
  76. bool BUF_Full(const stc_ring_buf_t *pstcBuf);
  77. bool BUF_Empty(const stc_ring_buf_t *pstcBuf);
  78. uint32_t BUF_Read(stc_ring_buf_t *pstcBuf, uint8_t au8Data[], uint32_t u32Len);
  79. uint32_t BUF_Write(stc_ring_buf_t *pstcBuf, uint8_t au8Data[], uint32_t u32Len);
  80. /**
  81. * @}
  82. */
  83. /**
  84. * @}
  85. */
  86. /**
  87. * @}
  88. */
  89. #ifdef __cplusplus
  90. }
  91. #endif
  92. #endif /* __RING_BUF_H__ */
  93. /*******************************************************************************
  94. * EOF (not truncated)
  95. ******************************************************************************/