utils_ringbuff.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. * Tencent is pleased to support the open source community by making IoT Hub
  3. available.
  4. * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
  5. * Licensed under the MIT License (the "License"); you may not use this file
  6. except in
  7. * compliance with the License. You may obtain a copy of the License at
  8. * http://opensource.org/licenses/MIT
  9. * Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is
  11. * distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  12. KIND,
  13. * either express or implied. See the License for the specific language
  14. governing permissions and
  15. * limitations under the License.
  16. *
  17. */
  18. #ifndef __AT_RING_BUFF_H__
  19. #define __AT_RING_BUFF_H__
  20. #include "stdbool.h"
  21. #include "stdint.h"
  22. #define RINGBUFF_OK 0 /* No error, everything OK. */
  23. #define RINGBUFF_ERR -1 /* Out of memory error. */
  24. #define RINGBUFF_EMPTY -3 /* Timeout. */
  25. #define RINGBUFF_FULL -4 /* Routing problem. */
  26. #define RINGBUFF_TOO_SHORT -5
  27. typedef struct _ring_buff_ {
  28. uint32_t size;
  29. uint32_t readpoint;
  30. uint32_t writepoint;
  31. char * buffer;
  32. bool full;
  33. } sRingbuff;
  34. typedef sRingbuff *ring_buff_t;
  35. int ring_buff_init(sRingbuff *ring_buff, char *buff, uint32_t size);
  36. int ring_buff_flush(sRingbuff *ring_buff);
  37. int ring_buff_push_data(sRingbuff *ring_buff, uint8_t *pData, int len);
  38. int ring_buff_pop_data(sRingbuff *ring_buff, uint8_t *pData, int len);
  39. #endif // __ringbuff_h__