srsLTE/lib/include/srsran/phy/utils/ringbuffer.h

81 lines
2.7 KiB
C
Raw Normal View History

/**
2019-04-23 01:53:11 -07:00
*
* \section COPYRIGHT
2019-04-23 01:53:11 -07:00
*
2021-03-19 03:45:56 -07:00
* Copyright 2013-2021 Software Radio Systems Limited
2019-04-23 01:53:11 -07:00
*
* By using this file, you agree to the terms and conditions set
* forth in the LICENSE file which can be found at the top level of
* the distribution.
2019-04-23 01:53:11 -07:00
*
*/
2017-04-05 02:41:48 -07:00
2021-03-19 03:45:56 -07:00
#ifndef SRSRAN_RINGBUFFER_H
#define SRSRAN_RINGBUFFER_H
2017-04-05 02:41:48 -07:00
2021-03-19 03:45:56 -07:00
#include "srsran/config.h"
2017-04-05 02:41:48 -07:00
#include <pthread.h>
#include <stdbool.h>
#include <stdint.h>
2017-04-05 02:41:48 -07:00
typedef struct {
uint8_t* buffer;
bool active;
int capacity;
int count;
int wpm;
int rpm;
pthread_mutex_t mutex;
pthread_cond_t write_cvar;
pthread_cond_t read_cvar;
2021-03-19 03:45:56 -07:00
} srsran_ringbuffer_t;
2017-04-05 02:41:48 -07:00
#ifdef __cplusplus
extern "C" {
#endif
2017-04-05 02:41:48 -07:00
2021-03-19 03:45:56 -07:00
SRSRAN_API int srsran_ringbuffer_init(srsran_ringbuffer_t* q, int capacity);
2017-04-05 02:41:48 -07:00
2021-03-19 03:45:56 -07:00
SRSRAN_API void srsran_ringbuffer_free(srsran_ringbuffer_t* q);
2021-03-19 03:45:56 -07:00
SRSRAN_API void srsran_ringbuffer_reset(srsran_ringbuffer_t* q);
2017-04-05 02:41:48 -07:00
2021-03-19 03:45:56 -07:00
SRSRAN_API int srsran_ringbuffer_status(srsran_ringbuffer_t* q);
2021-03-19 03:45:56 -07:00
SRSRAN_API int srsran_ringbuffer_space(srsran_ringbuffer_t* q);
2018-03-16 03:23:10 -07:00
2021-03-19 03:45:56 -07:00
SRSRAN_API int srsran_ringbuffer_resize(srsran_ringbuffer_t* q, int capacity);
// write to the buffer immediately, if there isnt enough space it will overflow
2021-03-19 03:45:56 -07:00
SRSRAN_API int srsran_ringbuffer_write(srsran_ringbuffer_t* q, void* ptr, int nof_bytes);
2017-04-05 02:41:48 -07:00
// block forever until there is enough space then write to buffer
2021-03-19 03:45:56 -07:00
SRSRAN_API int srsran_ringbuffer_write_block(srsran_ringbuffer_t* q, void* ptr, int nof_bytes);
// block for timeout_ms milliseconds, then either write to buffer if there is space or return an error without writing
2021-03-19 03:45:56 -07:00
SRSRAN_API int srsran_ringbuffer_write_timed(srsran_ringbuffer_t* q, void* ptr, int nof_bytes, int32_t timeout_ms);
2021-03-19 03:45:56 -07:00
SRSRAN_API int
srsran_ringbuffer_write_timed_block(srsran_ringbuffer_t* q, void* ptr, int nof_bytes, int32_t timeout_ms);
// read from buffer, blocking until there is enough samples
2021-03-19 03:45:56 -07:00
SRSRAN_API int srsran_ringbuffer_read(srsran_ringbuffer_t* q, void* ptr, int nof_bytes);
2017-04-05 02:41:48 -07:00
// read from buffer, blocking for timeout_ms milliseconds until there is enough samples or return an error
2021-03-19 03:45:56 -07:00
SRSRAN_API int srsran_ringbuffer_read_timed(srsran_ringbuffer_t* q, void* p, int nof_bytes, int32_t timeout_ms);
2021-03-19 03:45:56 -07:00
SRSRAN_API int srsran_ringbuffer_read_timed_block(srsran_ringbuffer_t* q, void* p, int nof_bytes, int32_t timeout_ms);
// read samples from the buffer, convert them from uint16_t to cplx float and get the conjugate
2021-03-19 03:45:56 -07:00
SRSRAN_API int srsran_ringbuffer_read_convert_conj(srsran_ringbuffer_t* q, cf_t* dst_ptr, float norm, int nof_samples);
2021-03-19 03:45:56 -07:00
SRSRAN_API int srsran_ringbuffer_read_block(srsran_ringbuffer_t* q, void** p, int nof_bytes, int32_t timeout_ms);
2021-03-19 03:45:56 -07:00
SRSRAN_API void srsran_ringbuffer_stop(srsran_ringbuffer_t* q);
2017-04-05 02:41:48 -07:00
#ifdef __cplusplus
}
#endif
2021-03-19 03:45:56 -07:00
#endif // SRSRAN_RINGBUFFER_H