f411-pulse-recorder/Core/Inc/recorder_buffer.h

40 lines
918 B
C++

#ifndef RECORDER_BUFFER_H
#define RECORDER_BUFFER_H
#ifdef __cplusplus
#include <cstdint>
extern "C" {
#else
#include <stdint.h>
#endif
// размер буфера, должен быть 2^x
#define CHANNEL_BUFFER_SIZE 2048
#define CHANNEL_BUFFER_SIZE_MASK (CHANNEL_BUFFER_SIZE - 1)
typedef struct {
uint64_t timepoint;
uint32_t duration;
} BufferItem_t;
// Структура кольцевого буфера
typedef struct {
volatile uint32_t head;
volatile uint32_t tail;
volatile uint32_t overruns;
BufferItem_t buffer[CHANNEL_BUFFER_SIZE];
} ChannelBuffer_t;
void ChannelBuffer_reset(ChannelBuffer_t *buffer);
void ChannelBuffer_push(ChannelBuffer_t *buffer, const BufferItem_t* item);
int ChannelBuffer_pop(ChannelBuffer_t *buffer, BufferItem_t* dest);
extern ChannelBuffer_t buffer_ch1;
extern ChannelBuffer_t buffer_ch2;
#ifdef __cplusplus
}
#endif
#endif //RECORDER_BUFFER_H