WizziLab's serial protocol library
Dependents: modem_ref_helper_for_v5_3_217 modem_ref_helper
Diff: kal_buf_circ.cpp
- Revision:
- 10:c87566aded6e
- Parent:
- 9:0140247bab90
--- a/kal_buf_circ.cpp Mon Jan 25 09:45:10 2021 +0000 +++ b/kal_buf_circ.cpp Mon Jan 25 11:23:32 2021 +0000 @@ -52,8 +52,7 @@ #ifndef CIRCULAR_BUFFER_FREE #define CIRCULAR_BUFFER_FREE(_p) KAL_FREE(_p) #endif -#else -#define CIRCULAR_BUFFER_STATIC_ONLY +#define CIRCULAR_BUFFER_DYNAMIC #endif static __inline uint32_t kal_buf_circ_next_head(kal_buf_circ_static_handle_t* h, uint32_t nb_elements) @@ -68,7 +67,7 @@ return (next >= h->max_length)? next - h->max_length : next; } -#ifndef CIRCULAR_BUFFER_STATIC_ONLY +#ifdef CIRCULAR_BUFFER_DYNAMIC kal_buf_circ_handle_t kal_buf_circ_create(uint32_t nb_elements, uint32_t element_size) { // Malloc the h and the buffer @@ -110,7 +109,7 @@ memset(h->buffer, 0, h->max_length); memset(h, 0, sizeof(kal_buf_circ_static_handle_t)); } -#ifndef CIRCULAR_BUFFER_STATIC_ONLY +#ifdef CIRCULAR_BUFFER_DYNAMIC else { CIRCULAR_BUFFER_FREE(h->buffer); @@ -132,7 +131,7 @@ return 0; } -__inline int kal_buf_circ_full(kal_buf_circ_handle_t handle) +int kal_buf_circ_full(kal_buf_circ_handle_t handle) { kal_buf_circ_static_handle_t* h = (kal_buf_circ_static_handle_t*)handle; @@ -140,7 +139,7 @@ return (kal_buf_circ_next_head(h, 1) == h->tail)? true : false; } -__inline int kal_buf_circ_empty(kal_buf_circ_handle_t handle) +int kal_buf_circ_empty(kal_buf_circ_handle_t handle) { kal_buf_circ_static_handle_t* h = (kal_buf_circ_static_handle_t*)handle; @@ -165,6 +164,13 @@ } } +uint32_t kal_buf_circ_space(kal_buf_circ_handle_t handle) +{ + kal_buf_circ_static_handle_t* h = (kal_buf_circ_static_handle_t*)handle; + + return ((h->max_length / h->element_size) - 1) - kal_buf_circ_size(handle); +} + int kal_buf_circ_push(kal_buf_circ_handle_t handle, uint8_t* p) { kal_buf_circ_static_handle_t* h = (kal_buf_circ_static_handle_t*)handle; @@ -375,4 +381,3 @@ // return success to indicate successful erase. return 0; } -