[FL-2839] Furi stream buffer (#1834)
* Core: stream buffer * stream buffer: API and usage * stream buffer: documentation * stream buffer: more documentation * Furi: fix spelling Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
This commit is contained in:
@@ -9,7 +9,6 @@
|
||||
#include <furi.h>
|
||||
|
||||
#include <notification/notification_messages.h>
|
||||
#include <stream_buffer.h>
|
||||
|
||||
#define INFRARED_WORKER_RX_TIMEOUT INFRARED_RAW_RX_TIMING_DELAY_US
|
||||
|
||||
@@ -50,7 +49,7 @@ struct InfraredWorkerSignal {
|
||||
|
||||
struct InfraredWorker {
|
||||
FuriThread* thread;
|
||||
StreamBufferHandle_t stream;
|
||||
FuriStreamBuffer* stream;
|
||||
|
||||
InfraredWorkerSignal signal;
|
||||
InfraredWorkerState state;
|
||||
@@ -100,15 +99,13 @@ static void infrared_worker_rx_timeout_callback(void* context) {
|
||||
static void infrared_worker_rx_callback(void* context, bool level, uint32_t duration) {
|
||||
InfraredWorker* instance = context;
|
||||
|
||||
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
|
||||
furi_assert(duration != 0);
|
||||
LevelDuration level_duration = level_duration_make(level, duration);
|
||||
|
||||
size_t ret = xStreamBufferSendFromISR(
|
||||
instance->stream, &level_duration, sizeof(LevelDuration), &xHigherPriorityTaskWoken);
|
||||
size_t ret =
|
||||
furi_stream_buffer_send(instance->stream, &level_duration, sizeof(LevelDuration), 0);
|
||||
uint32_t events = (ret == sizeof(LevelDuration)) ? INFRARED_WORKER_RX_RECEIVED :
|
||||
INFRARED_WORKER_OVERRUN;
|
||||
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
|
||||
|
||||
uint32_t flags_set = furi_thread_flags_set(furi_thread_get_id(instance->thread), events);
|
||||
furi_check(flags_set & events);
|
||||
@@ -179,7 +176,7 @@ static int32_t infrared_worker_rx_thread(void* thread_context) {
|
||||
if(instance->signal.timings_cnt == 0)
|
||||
notification_message(instance->notification, &sequence_display_backlight_on);
|
||||
while(sizeof(LevelDuration) ==
|
||||
xStreamBufferReceive(
|
||||
furi_stream_buffer_receive(
|
||||
instance->stream, &level_duration, sizeof(LevelDuration), 0)) {
|
||||
if(!instance->rx.overrun) {
|
||||
bool level = level_duration_get_level(level_duration);
|
||||
@@ -232,7 +229,7 @@ InfraredWorker* infrared_worker_alloc() {
|
||||
size_t buffer_size =
|
||||
MAX(sizeof(InfraredWorkerTiming) * (MAX_TIMINGS_AMOUNT + 1),
|
||||
sizeof(LevelDuration) * MAX_TIMINGS_AMOUNT);
|
||||
instance->stream = xStreamBufferCreate(buffer_size, sizeof(InfraredWorkerTiming));
|
||||
instance->stream = furi_stream_buffer_alloc(buffer_size, sizeof(InfraredWorkerTiming));
|
||||
instance->infrared_decoder = infrared_alloc_decoder();
|
||||
instance->infrared_encoder = infrared_alloc_encoder();
|
||||
instance->blink_enable = false;
|
||||
@@ -249,7 +246,7 @@ void infrared_worker_free(InfraredWorker* instance) {
|
||||
furi_record_close(RECORD_NOTIFICATION);
|
||||
infrared_free_decoder(instance->infrared_decoder);
|
||||
infrared_free_encoder(instance->infrared_encoder);
|
||||
vStreamBufferDelete(instance->stream);
|
||||
furi_stream_buffer_free(instance->stream);
|
||||
furi_thread_free(instance->thread);
|
||||
|
||||
free(instance);
|
||||
@@ -259,7 +256,7 @@ void infrared_worker_rx_start(InfraredWorker* instance) {
|
||||
furi_assert(instance);
|
||||
furi_assert(instance->state == InfraredWorkerStateIdle);
|
||||
|
||||
xStreamBufferSetTriggerLevel(instance->stream, sizeof(LevelDuration));
|
||||
furi_stream_set_trigger_level(instance->stream, sizeof(LevelDuration));
|
||||
|
||||
furi_thread_set_callback(instance->thread, infrared_worker_rx_thread);
|
||||
furi_thread_start(instance->thread);
|
||||
@@ -285,9 +282,9 @@ void infrared_worker_rx_stop(InfraredWorker* instance) {
|
||||
furi_thread_flags_set(furi_thread_get_id(instance->thread), INFRARED_WORKER_EXIT);
|
||||
furi_thread_join(instance->thread);
|
||||
|
||||
BaseType_t xReturn = xStreamBufferReset(instance->stream);
|
||||
furi_assert(xReturn == pdPASS);
|
||||
(void)xReturn;
|
||||
FuriStatus status = furi_stream_buffer_reset(instance->stream);
|
||||
furi_assert(status == FuriStatusOk);
|
||||
(void)status;
|
||||
|
||||
instance->state = InfraredWorkerStateIdle;
|
||||
}
|
||||
@@ -325,7 +322,7 @@ void infrared_worker_tx_start(InfraredWorker* instance) {
|
||||
furi_assert(instance->tx.get_signal_callback);
|
||||
|
||||
// size have to be greater than api hal infrared async tx buffer size
|
||||
xStreamBufferSetTriggerLevel(instance->stream, sizeof(InfraredWorkerTiming));
|
||||
furi_stream_set_trigger_level(instance->stream, sizeof(InfraredWorkerTiming));
|
||||
|
||||
furi_thread_set_callback(instance->thread, infrared_worker_tx_thread);
|
||||
|
||||
@@ -358,7 +355,7 @@ static FuriHalInfraredTxGetDataState
|
||||
FuriHalInfraredTxGetDataState state;
|
||||
|
||||
if(sizeof(InfraredWorkerTiming) ==
|
||||
xStreamBufferReceiveFromISR(instance->stream, &timing, sizeof(InfraredWorkerTiming), 0)) {
|
||||
furi_stream_buffer_receive(instance->stream, &timing, sizeof(InfraredWorkerTiming), 0)) {
|
||||
*level = timing.level;
|
||||
*duration = timing.duration;
|
||||
state = timing.state;
|
||||
@@ -420,7 +417,7 @@ static bool infrared_worker_tx_fill_buffer(InfraredWorker* instance) {
|
||||
InfraredWorkerTiming timing;
|
||||
InfraredStatus status = InfraredStatusError;
|
||||
|
||||
while(!xStreamBufferIsFull(instance->stream) && !instance->tx.need_reinitialization &&
|
||||
while(!furi_stream_buffer_is_full(instance->stream) && !instance->tx.need_reinitialization &&
|
||||
new_data_available) {
|
||||
if(instance->signal.decoded) {
|
||||
status = infrared_encode(instance->infrared_encoder, &timing.duration, &timing.level);
|
||||
@@ -454,7 +451,7 @@ static bool infrared_worker_tx_fill_buffer(InfraredWorker* instance) {
|
||||
furi_assert(0);
|
||||
}
|
||||
uint32_t written_size =
|
||||
xStreamBufferSend(instance->stream, &timing, sizeof(InfraredWorkerTiming), 0);
|
||||
furi_stream_buffer_send(instance->stream, &timing, sizeof(InfraredWorkerTiming), 0);
|
||||
furi_assert(sizeof(InfraredWorkerTiming) == written_size);
|
||||
(void)written_size;
|
||||
}
|
||||
@@ -564,10 +561,9 @@ void infrared_worker_tx_stop(InfraredWorker* instance) {
|
||||
furi_hal_infrared_async_tx_set_signal_sent_isr_callback(NULL, NULL);
|
||||
|
||||
instance->signal.timings_cnt = 0;
|
||||
BaseType_t xReturn = pdFAIL;
|
||||
xReturn = xStreamBufferReset(instance->stream);
|
||||
furi_assert(xReturn == pdPASS);
|
||||
(void)xReturn;
|
||||
FuriStatus status = furi_stream_buffer_reset(instance->stream);
|
||||
furi_assert(status == FuriStatusOk);
|
||||
(void)status;
|
||||
instance->state = InfraredWorkerStateIdle;
|
||||
}
|
||||
|
||||
|
@@ -2,7 +2,6 @@
|
||||
#include <toolbox/stream/file_stream.h>
|
||||
#include <toolbox/buffer_stream.h>
|
||||
#include <toolbox/varint.h>
|
||||
#include <stream_buffer.h>
|
||||
#include "lfrfid_raw_worker.h"
|
||||
#include "lfrfid_raw_file.h"
|
||||
#include "tools/varint_pair.h"
|
||||
@@ -16,7 +15,7 @@
|
||||
// emulate mode
|
||||
typedef struct {
|
||||
size_t overrun_count;
|
||||
StreamBufferHandle_t stream;
|
||||
FuriStreamBuffer* stream;
|
||||
} RfidEmulateCtx;
|
||||
|
||||
typedef struct {
|
||||
@@ -126,20 +125,13 @@ void lfrfid_raw_worker_stop(LFRFIDRawWorker* worker) {
|
||||
static void lfrfid_raw_worker_capture(bool level, uint32_t duration, void* context) {
|
||||
LFRFIDRawWorkerReadData* ctx = context;
|
||||
|
||||
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
|
||||
|
||||
bool need_to_send = varint_pair_pack(ctx->pair, level, duration);
|
||||
|
||||
if(need_to_send) {
|
||||
buffer_stream_send_from_isr(
|
||||
ctx->stream,
|
||||
varint_pair_get_data(ctx->pair),
|
||||
varint_pair_get_size(ctx->pair),
|
||||
&xHigherPriorityTaskWoken);
|
||||
ctx->stream, varint_pair_get_data(ctx->pair), varint_pair_get_size(ctx->pair));
|
||||
varint_pair_reset(ctx->pair);
|
||||
}
|
||||
|
||||
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
|
||||
}
|
||||
|
||||
static int32_t lfrfid_raw_read_worker_thread(void* thread_context) {
|
||||
@@ -236,7 +228,7 @@ static void rfid_emulate_dma_isr(bool half, void* context) {
|
||||
RfidEmulateCtx* ctx = context;
|
||||
|
||||
uint32_t flag = half ? HalfTransfer : TransferComplete;
|
||||
size_t len = xStreamBufferSendFromISR(ctx->stream, &flag, sizeof(uint32_t), pdFALSE);
|
||||
size_t len = furi_stream_buffer_send(ctx->stream, &flag, sizeof(uint32_t), 0);
|
||||
if(len != sizeof(uint32_t)) {
|
||||
ctx->overrun_count++;
|
||||
}
|
||||
@@ -251,7 +243,7 @@ static int32_t lfrfid_raw_emulate_worker_thread(void* thread_context) {
|
||||
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
data->ctx.overrun_count = 0;
|
||||
data->ctx.stream = xStreamBufferCreate(sizeof(uint32_t), sizeof(uint32_t));
|
||||
data->ctx.stream = furi_stream_buffer_alloc(sizeof(uint32_t), sizeof(uint32_t));
|
||||
|
||||
LFRFIDRawFile* file = lfrfid_raw_file_alloc(storage);
|
||||
|
||||
@@ -287,7 +279,8 @@ static int32_t lfrfid_raw_emulate_worker_thread(void* thread_context) {
|
||||
uint32_t flag = 0;
|
||||
|
||||
while(true) {
|
||||
size_t size = xStreamBufferReceive(data->ctx.stream, &flag, sizeof(uint32_t), 100);
|
||||
size_t size =
|
||||
furi_stream_buffer_receive(data->ctx.stream, &flag, sizeof(uint32_t), 100);
|
||||
|
||||
if(size == sizeof(uint32_t)) {
|
||||
size_t start = 0;
|
||||
@@ -348,7 +341,7 @@ static int32_t lfrfid_raw_emulate_worker_thread(void* thread_context) {
|
||||
FURI_LOG_E(TAG_EMULATE, "overruns: %lu", data->ctx.overrun_count);
|
||||
}
|
||||
|
||||
vStreamBufferDelete(data->ctx.stream);
|
||||
furi_stream_buffer_free(data->ctx.stream);
|
||||
lfrfid_raw_file_free(file);
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
free(data);
|
||||
|
@@ -2,7 +2,6 @@
|
||||
#include <furi_hal.h>
|
||||
#include "lfrfid_worker_i.h"
|
||||
#include "tools/t5577.h"
|
||||
#include <stream_buffer.h>
|
||||
#include <toolbox/pulse_protocols/pulse_glue.h>
|
||||
#include <toolbox/buffer_stream.h>
|
||||
#include "tools/varint_pair.h"
|
||||
@@ -81,17 +80,12 @@ static void lfrfid_worker_read_capture(bool level, uint32_t duration, void* cont
|
||||
furi_hal_gpio_write(LFRFID_WORKER_READ_DEBUG_GPIO_VALUE, level);
|
||||
#endif
|
||||
|
||||
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
|
||||
bool need_to_send = varint_pair_pack(ctx->pair, level, duration);
|
||||
if(need_to_send) {
|
||||
buffer_stream_send_from_isr(
|
||||
ctx->stream,
|
||||
varint_pair_get_data(ctx->pair),
|
||||
varint_pair_get_size(ctx->pair),
|
||||
&xHigherPriorityTaskWoken);
|
||||
ctx->stream, varint_pair_get_data(ctx->pair), varint_pair_get_size(ctx->pair));
|
||||
varint_pair_reset(ctx->pair);
|
||||
}
|
||||
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
|
||||
}
|
||||
|
||||
typedef enum {
|
||||
@@ -407,14 +401,14 @@ typedef enum {
|
||||
} LFRFIDWorkerEmulateDMAEvent;
|
||||
|
||||
static void lfrfid_worker_emulate_dma_isr(bool half, void* context) {
|
||||
StreamBufferHandle_t stream = context;
|
||||
FuriStreamBuffer* stream = context;
|
||||
uint32_t flag = half ? HalfTransfer : TransferComplete;
|
||||
xStreamBufferSendFromISR(stream, &flag, sizeof(uint32_t), pdFALSE);
|
||||
furi_stream_buffer_send(stream, &flag, sizeof(uint32_t), 0);
|
||||
}
|
||||
|
||||
static void lfrfid_worker_mode_emulate_process(LFRFIDWorker* worker) {
|
||||
LFRFIDWorkerEmulateBuffer* buffer = malloc(sizeof(LFRFIDWorkerEmulateBuffer));
|
||||
StreamBufferHandle_t stream = xStreamBufferCreate(sizeof(uint32_t), sizeof(uint32_t));
|
||||
FuriStreamBuffer* stream = furi_stream_buffer_alloc(sizeof(uint32_t), sizeof(uint32_t));
|
||||
LFRFIDProtocol protocol = worker->protocol;
|
||||
PulseGlue* pulse_glue = pulse_glue_alloc();
|
||||
|
||||
@@ -449,7 +443,7 @@ static void lfrfid_worker_mode_emulate_process(LFRFIDWorker* worker) {
|
||||
|
||||
while(true) {
|
||||
uint32_t flag = 0;
|
||||
size_t size = xStreamBufferReceive(stream, &flag, sizeof(uint32_t), 100);
|
||||
size_t size = furi_stream_buffer_receive(stream, &flag, sizeof(uint32_t), 100);
|
||||
|
||||
#ifdef LFRFID_WORKER_READ_DEBUG_GPIO
|
||||
furi_hal_gpio_write(LFRFID_WORKER_READ_DEBUG_GPIO_LOAD, true);
|
||||
@@ -497,7 +491,7 @@ static void lfrfid_worker_mode_emulate_process(LFRFIDWorker* worker) {
|
||||
#endif
|
||||
|
||||
free(buffer);
|
||||
vStreamBufferDelete(stream);
|
||||
furi_stream_buffer_free(stream);
|
||||
pulse_glue_free(pulse_glue);
|
||||
}
|
||||
|
||||
|
@@ -1,5 +1,4 @@
|
||||
#include "reader_analyzer.h"
|
||||
#include <stream_buffer.h>
|
||||
#include <lib/nfc/protocols/nfc_util.h>
|
||||
#include <lib/nfc/protocols/mifare_classic.h>
|
||||
#include <m-array.h>
|
||||
@@ -26,7 +25,7 @@ struct ReaderAnalyzer {
|
||||
FuriHalNfcDevData nfc_data;
|
||||
|
||||
bool alive;
|
||||
StreamBufferHandle_t stream;
|
||||
FuriStreamBuffer* stream;
|
||||
FuriThread* thread;
|
||||
|
||||
ReaderAnalyzerParseDataCallback callback;
|
||||
@@ -86,8 +85,8 @@ int32_t reader_analyzer_thread(void* context) {
|
||||
ReaderAnalyzer* reader_analyzer = context;
|
||||
uint8_t buffer[READER_ANALYZER_MAX_BUFF_SIZE] = {};
|
||||
|
||||
while(reader_analyzer->alive || !xStreamBufferIsEmpty(reader_analyzer->stream)) {
|
||||
size_t ret = xStreamBufferReceive(
|
||||
while(reader_analyzer->alive || !furi_stream_buffer_is_empty(reader_analyzer->stream)) {
|
||||
size_t ret = furi_stream_buffer_receive(
|
||||
reader_analyzer->stream, buffer, READER_ANALYZER_MAX_BUFF_SIZE, 50);
|
||||
if(ret) {
|
||||
reader_analyzer_parse(reader_analyzer, buffer, ret);
|
||||
@@ -103,7 +102,7 @@ ReaderAnalyzer* reader_analyzer_alloc() {
|
||||
instance->nfc_data = reader_analyzer_nfc_data[ReaderAnalyzerNfcDataMfClassic];
|
||||
instance->alive = false;
|
||||
instance->stream =
|
||||
xStreamBufferCreate(READER_ANALYZER_MAX_BUFF_SIZE, sizeof(ReaderAnalyzerHeader));
|
||||
furi_stream_buffer_alloc(READER_ANALYZER_MAX_BUFF_SIZE, sizeof(ReaderAnalyzerHeader));
|
||||
|
||||
instance->thread = furi_thread_alloc();
|
||||
furi_thread_set_name(instance->thread, "ReaderAnalyzerWorker");
|
||||
@@ -129,7 +128,7 @@ static void reader_analyzer_mfkey_callback(Mfkey32Event event, void* context) {
|
||||
void reader_analyzer_start(ReaderAnalyzer* instance, ReaderAnalyzerMode mode) {
|
||||
furi_assert(instance);
|
||||
|
||||
xStreamBufferReset(instance->stream);
|
||||
furi_stream_buffer_reset(instance->stream);
|
||||
if(mode & ReaderAnalyzerModeDebugLog) {
|
||||
instance->debug_log = nfc_debug_log_alloc();
|
||||
}
|
||||
@@ -171,7 +170,7 @@ void reader_analyzer_free(ReaderAnalyzer* instance) {
|
||||
|
||||
reader_analyzer_stop(instance);
|
||||
furi_thread_free(instance->thread);
|
||||
vStreamBufferDelete(instance->stream);
|
||||
furi_stream_buffer_free(instance->stream);
|
||||
free(instance);
|
||||
}
|
||||
|
||||
@@ -215,12 +214,12 @@ static void reader_analyzer_write(
|
||||
ReaderAnalyzerHeader header = {
|
||||
.reader_to_tag = reader_to_tag, .crc_dropped = crc_dropped, .len = len};
|
||||
size_t data_sent = 0;
|
||||
data_sent = xStreamBufferSend(
|
||||
data_sent = furi_stream_buffer_send(
|
||||
instance->stream, &header, sizeof(ReaderAnalyzerHeader), FuriWaitForever);
|
||||
if(data_sent != sizeof(ReaderAnalyzerHeader)) {
|
||||
FURI_LOG_W(TAG, "Sent %d out of %d bytes", data_sent, sizeof(ReaderAnalyzerHeader));
|
||||
}
|
||||
data_sent = xStreamBufferSend(instance->stream, data, len, FuriWaitForever);
|
||||
data_sent = furi_stream_buffer_send(instance->stream, data, len, FuriWaitForever);
|
||||
if(data_sent != len) {
|
||||
FURI_LOG_W(TAG, "Sent %d out of %d bytes", data_sent, len);
|
||||
}
|
||||
|
@@ -2,7 +2,6 @@
|
||||
#include <furi_hal.h>
|
||||
#include "ibutton_worker_i.h"
|
||||
#include "ibutton_key_command.h"
|
||||
#include <stream_buffer.h>
|
||||
|
||||
void ibutton_worker_mode_idle_start(iButtonWorker* worker);
|
||||
void ibutton_worker_mode_idle_tick(iButtonWorker* worker);
|
||||
@@ -65,7 +64,7 @@ void ibutton_worker_mode_idle_stop(iButtonWorker* worker) {
|
||||
|
||||
typedef struct {
|
||||
uint32_t last_dwt_value;
|
||||
StreamBufferHandle_t stream;
|
||||
FuriStreamBuffer* stream;
|
||||
} iButtonReadContext;
|
||||
|
||||
void ibutton_worker_comparator_callback(bool level, void* context) {
|
||||
@@ -75,7 +74,7 @@ void ibutton_worker_comparator_callback(bool level, void* context) {
|
||||
|
||||
LevelDuration data =
|
||||
level_duration_make(level, current_dwt_value - read_context->last_dwt_value);
|
||||
xStreamBufferSend(read_context->stream, &data, sizeof(LevelDuration), 0);
|
||||
furi_stream_buffer_send(read_context->stream, &data, sizeof(LevelDuration), 0);
|
||||
|
||||
read_context->last_dwt_value = current_dwt_value;
|
||||
}
|
||||
@@ -91,7 +90,7 @@ bool ibutton_worker_read_comparator(iButtonWorker* worker) {
|
||||
|
||||
iButtonReadContext read_context = {
|
||||
.last_dwt_value = DWT->CYCCNT,
|
||||
.stream = xStreamBufferCreate(sizeof(LevelDuration) * 512, 1),
|
||||
.stream = furi_stream_buffer_alloc(sizeof(LevelDuration) * 512, 1),
|
||||
};
|
||||
|
||||
furi_hal_rfid_comp_set_callback(ibutton_worker_comparator_callback, &read_context);
|
||||
@@ -100,7 +99,8 @@ bool ibutton_worker_read_comparator(iButtonWorker* worker) {
|
||||
uint32_t tick_start = furi_get_tick();
|
||||
while(true) {
|
||||
LevelDuration level;
|
||||
size_t ret = xStreamBufferReceive(read_context.stream, &level, sizeof(LevelDuration), 100);
|
||||
size_t ret =
|
||||
furi_stream_buffer_receive(read_context.stream, &level, sizeof(LevelDuration), 100);
|
||||
|
||||
if((furi_get_tick() - tick_start) > 100) {
|
||||
break;
|
||||
@@ -141,7 +141,7 @@ bool ibutton_worker_read_comparator(iButtonWorker* worker) {
|
||||
furi_hal_rfid_comp_set_callback(NULL, NULL);
|
||||
furi_hal_rfid_pins_reset();
|
||||
|
||||
vStreamBufferDelete(read_context.stream);
|
||||
furi_stream_buffer_free(read_context.stream);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@@ -1,5 +1,4 @@
|
||||
#include "subghz_file_encoder_worker.h"
|
||||
#include <stream_buffer.h>
|
||||
|
||||
#include <toolbox/stream/stream.h>
|
||||
#include <flipper_format/flipper_format.h>
|
||||
@@ -11,7 +10,7 @@
|
||||
|
||||
struct SubGhzFileEncoderWorker {
|
||||
FuriThread* thread;
|
||||
StreamBufferHandle_t stream;
|
||||
FuriStreamBuffer* stream;
|
||||
|
||||
Storage* storage;
|
||||
FlipperFormat* flipper_format;
|
||||
@@ -48,7 +47,7 @@ void subghz_file_encoder_worker_add_level_duration(
|
||||
|
||||
if(res) {
|
||||
instance->level = !instance->level;
|
||||
xStreamBufferSend(instance->stream, &duration, sizeof(int32_t), 100);
|
||||
furi_stream_buffer_send(instance->stream, &duration, sizeof(int32_t), 100);
|
||||
} else {
|
||||
FURI_LOG_E(TAG, "Invalid level in the stream");
|
||||
}
|
||||
@@ -83,10 +82,7 @@ LevelDuration subghz_file_encoder_worker_get_level_duration(void* context) {
|
||||
furi_assert(context);
|
||||
SubGhzFileEncoderWorker* instance = context;
|
||||
int32_t duration;
|
||||
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
|
||||
int ret = xStreamBufferReceiveFromISR(
|
||||
instance->stream, &duration, sizeof(int32_t), &xHigherPriorityTaskWoken);
|
||||
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
|
||||
int ret = furi_stream_buffer_receive(instance->stream, &duration, sizeof(int32_t), 0);
|
||||
if(ret == sizeof(int32_t)) {
|
||||
LevelDuration level_duration = {.level = LEVEL_DURATION_RESET};
|
||||
if(duration < 0) {
|
||||
@@ -137,7 +133,7 @@ static int32_t subghz_file_encoder_worker_thread(void* context) {
|
||||
} while(0);
|
||||
|
||||
while(res && instance->worker_running) {
|
||||
size_t stream_free_byte = xStreamBufferSpacesAvailable(instance->stream);
|
||||
size_t stream_free_byte = furi_stream_buffer_spaces_available(instance->stream);
|
||||
if((stream_free_byte / sizeof(int32_t)) >= SUBGHZ_FILE_ENCODER_LOAD) {
|
||||
if(stream_read_line(stream, instance->str_data)) {
|
||||
furi_string_trim(instance->str_data);
|
||||
@@ -183,7 +179,7 @@ SubGhzFileEncoderWorker* subghz_file_encoder_worker_alloc() {
|
||||
furi_thread_set_stack_size(instance->thread, 2048);
|
||||
furi_thread_set_context(instance->thread, instance);
|
||||
furi_thread_set_callback(instance->thread, subghz_file_encoder_worker_thread);
|
||||
instance->stream = xStreamBufferCreate(sizeof(int32_t) * 2048, sizeof(int32_t));
|
||||
instance->stream = furi_stream_buffer_alloc(sizeof(int32_t) * 2048, sizeof(int32_t));
|
||||
|
||||
instance->storage = furi_record_open(RECORD_STORAGE);
|
||||
instance->flipper_format = flipper_format_file_alloc(instance->storage);
|
||||
@@ -199,7 +195,7 @@ SubGhzFileEncoderWorker* subghz_file_encoder_worker_alloc() {
|
||||
void subghz_file_encoder_worker_free(SubGhzFileEncoderWorker* instance) {
|
||||
furi_assert(instance);
|
||||
|
||||
vStreamBufferDelete(instance->stream);
|
||||
furi_stream_buffer_free(instance->stream);
|
||||
furi_thread_free(instance->thread);
|
||||
|
||||
furi_string_free(instance->str_data);
|
||||
@@ -215,7 +211,7 @@ bool subghz_file_encoder_worker_start(SubGhzFileEncoderWorker* instance, const c
|
||||
furi_assert(instance);
|
||||
furi_assert(!instance->worker_running);
|
||||
|
||||
xStreamBufferReset(instance->stream);
|
||||
furi_stream_buffer_reset(instance->stream);
|
||||
furi_string_set(instance->file_path, file_path);
|
||||
instance->worker_running = true;
|
||||
furi_thread_start(instance->thread);
|
||||
|
@@ -1,6 +1,5 @@
|
||||
#include "subghz_tx_rx_worker.h"
|
||||
|
||||
#include <stream_buffer.h>
|
||||
#include <furi.h>
|
||||
|
||||
#define TAG "SubGhzTxRxWorker"
|
||||
@@ -13,8 +12,8 @@
|
||||
|
||||
struct SubGhzTxRxWorker {
|
||||
FuriThread* thread;
|
||||
StreamBufferHandle_t stream_tx;
|
||||
StreamBufferHandle_t stream_rx;
|
||||
FuriStreamBuffer* stream_tx;
|
||||
FuriStreamBuffer* stream_rx;
|
||||
|
||||
volatile bool worker_running;
|
||||
volatile bool worker_stoping;
|
||||
@@ -30,9 +29,9 @@ struct SubGhzTxRxWorker {
|
||||
bool subghz_tx_rx_worker_write(SubGhzTxRxWorker* instance, uint8_t* data, size_t size) {
|
||||
furi_assert(instance);
|
||||
bool ret = false;
|
||||
size_t stream_tx_free_byte = xStreamBufferSpacesAvailable(instance->stream_tx);
|
||||
size_t stream_tx_free_byte = furi_stream_buffer_spaces_available(instance->stream_tx);
|
||||
if(size && (stream_tx_free_byte >= size)) {
|
||||
if(xStreamBufferSend(
|
||||
if(furi_stream_buffer_send(
|
||||
instance->stream_tx, data, size, SUBGHZ_TXRX_WORKER_TIMEOUT_READ_WRITE_BUF) ==
|
||||
size) {
|
||||
ret = true;
|
||||
@@ -43,12 +42,12 @@ bool subghz_tx_rx_worker_write(SubGhzTxRxWorker* instance, uint8_t* data, size_t
|
||||
|
||||
size_t subghz_tx_rx_worker_available(SubGhzTxRxWorker* instance) {
|
||||
furi_assert(instance);
|
||||
return xStreamBufferBytesAvailable(instance->stream_rx);
|
||||
return furi_stream_buffer_bytes_available(instance->stream_rx);
|
||||
}
|
||||
|
||||
size_t subghz_tx_rx_worker_read(SubGhzTxRxWorker* instance, uint8_t* data, size_t size) {
|
||||
furi_assert(instance);
|
||||
return xStreamBufferReceive(instance->stream_rx, data, size, 0);
|
||||
return furi_stream_buffer_receive(instance->stream_rx, data, size, 0);
|
||||
}
|
||||
|
||||
void subghz_tx_rx_worker_set_callback_have_read(
|
||||
@@ -148,11 +147,11 @@ static int32_t subghz_tx_rx_worker_thread(void* context) {
|
||||
|
||||
while(instance->worker_running) {
|
||||
//transmit
|
||||
size_tx = xStreamBufferBytesAvailable(instance->stream_tx);
|
||||
size_tx = furi_stream_buffer_bytes_available(instance->stream_tx);
|
||||
if(size_tx > 0 && !timeout_tx) {
|
||||
timeout_tx = 10; //20ms
|
||||
if(size_tx > SUBGHZ_TXRX_WORKER_MAX_TXRX_SIZE) {
|
||||
xStreamBufferReceive(
|
||||
furi_stream_buffer_receive(
|
||||
instance->stream_tx,
|
||||
&data,
|
||||
SUBGHZ_TXRX_WORKER_MAX_TXRX_SIZE,
|
||||
@@ -160,20 +159,20 @@ static int32_t subghz_tx_rx_worker_thread(void* context) {
|
||||
subghz_tx_rx_worker_tx(instance, data, SUBGHZ_TXRX_WORKER_MAX_TXRX_SIZE);
|
||||
} else {
|
||||
//todo checking that he managed to write all the data to the TX buffer
|
||||
xStreamBufferReceive(
|
||||
furi_stream_buffer_receive(
|
||||
instance->stream_tx, &data, size_tx, SUBGHZ_TXRX_WORKER_TIMEOUT_READ_WRITE_BUF);
|
||||
subghz_tx_rx_worker_tx(instance, data, size_tx);
|
||||
}
|
||||
} else {
|
||||
//recive
|
||||
if(subghz_tx_rx_worker_rx(instance, data, size_rx)) {
|
||||
if(xStreamBufferSpacesAvailable(instance->stream_rx) >= size_rx[0]) {
|
||||
if(furi_stream_buffer_spaces_available(instance->stream_rx) >= size_rx[0]) {
|
||||
if(instance->callback_have_read &&
|
||||
xStreamBufferBytesAvailable(instance->stream_rx) == 0) {
|
||||
furi_stream_buffer_bytes_available(instance->stream_rx) == 0) {
|
||||
callback_rx = true;
|
||||
}
|
||||
//todo checking that he managed to write all the data to the RX buffer
|
||||
xStreamBufferSend(
|
||||
furi_stream_buffer_send(
|
||||
instance->stream_rx,
|
||||
&data,
|
||||
size_rx[0],
|
||||
@@ -208,9 +207,9 @@ SubGhzTxRxWorker* subghz_tx_rx_worker_alloc() {
|
||||
furi_thread_set_context(instance->thread, instance);
|
||||
furi_thread_set_callback(instance->thread, subghz_tx_rx_worker_thread);
|
||||
instance->stream_tx =
|
||||
xStreamBufferCreate(sizeof(uint8_t) * SUBGHZ_TXRX_WORKER_BUF_SIZE, sizeof(uint8_t));
|
||||
furi_stream_buffer_alloc(sizeof(uint8_t) * SUBGHZ_TXRX_WORKER_BUF_SIZE, sizeof(uint8_t));
|
||||
instance->stream_rx =
|
||||
xStreamBufferCreate(sizeof(uint8_t) * SUBGHZ_TXRX_WORKER_BUF_SIZE, sizeof(uint8_t));
|
||||
furi_stream_buffer_alloc(sizeof(uint8_t) * SUBGHZ_TXRX_WORKER_BUF_SIZE, sizeof(uint8_t));
|
||||
|
||||
instance->status = SubGhzTxRxWorkerStatusIDLE;
|
||||
instance->worker_stoping = true;
|
||||
@@ -221,8 +220,8 @@ SubGhzTxRxWorker* subghz_tx_rx_worker_alloc() {
|
||||
void subghz_tx_rx_worker_free(SubGhzTxRxWorker* instance) {
|
||||
furi_assert(instance);
|
||||
furi_assert(!instance->worker_running);
|
||||
vStreamBufferDelete(instance->stream_tx);
|
||||
vStreamBufferDelete(instance->stream_rx);
|
||||
furi_stream_buffer_free(instance->stream_tx);
|
||||
furi_stream_buffer_free(instance->stream_rx);
|
||||
furi_thread_free(instance->thread);
|
||||
|
||||
free(instance);
|
||||
@@ -232,8 +231,8 @@ bool subghz_tx_rx_worker_start(SubGhzTxRxWorker* instance, uint32_t frequency) {
|
||||
furi_assert(instance);
|
||||
furi_assert(!instance->worker_running);
|
||||
bool res = false;
|
||||
xStreamBufferReset(instance->stream_tx);
|
||||
xStreamBufferReset(instance->stream_rx);
|
||||
furi_stream_buffer_reset(instance->stream_tx);
|
||||
furi_stream_buffer_reset(instance->stream_rx);
|
||||
|
||||
instance->worker_running = true;
|
||||
|
||||
|
@@ -1,13 +1,12 @@
|
||||
#include "subghz_worker.h"
|
||||
|
||||
#include <stream_buffer.h>
|
||||
#include <furi.h>
|
||||
|
||||
#define TAG "SubGhzWorker"
|
||||
|
||||
struct SubGhzWorker {
|
||||
FuriThread* thread;
|
||||
StreamBufferHandle_t stream;
|
||||
FuriStreamBuffer* stream;
|
||||
|
||||
volatile bool running;
|
||||
volatile bool overrun;
|
||||
@@ -30,16 +29,14 @@ struct SubGhzWorker {
|
||||
void subghz_worker_rx_callback(bool level, uint32_t duration, void* context) {
|
||||
SubGhzWorker* instance = context;
|
||||
|
||||
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
|
||||
LevelDuration level_duration = level_duration_make(level, duration);
|
||||
if(instance->overrun) {
|
||||
instance->overrun = false;
|
||||
level_duration = level_duration_reset();
|
||||
}
|
||||
size_t ret = xStreamBufferSendFromISR(
|
||||
instance->stream, &level_duration, sizeof(LevelDuration), &xHigherPriorityTaskWoken);
|
||||
size_t ret =
|
||||
furi_stream_buffer_send(instance->stream, &level_duration, sizeof(LevelDuration), 0);
|
||||
if(sizeof(LevelDuration) != ret) instance->overrun = true;
|
||||
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
|
||||
}
|
||||
|
||||
/** Worker callback thread
|
||||
@@ -52,8 +49,8 @@ static int32_t subghz_worker_thread_callback(void* context) {
|
||||
|
||||
LevelDuration level_duration;
|
||||
while(instance->running) {
|
||||
int ret =
|
||||
xStreamBufferReceive(instance->stream, &level_duration, sizeof(LevelDuration), 10);
|
||||
int ret = furi_stream_buffer_receive(
|
||||
instance->stream, &level_duration, sizeof(LevelDuration), 10);
|
||||
if(ret == sizeof(LevelDuration)) {
|
||||
if(level_duration_is_reset(level_duration)) {
|
||||
FURI_LOG_E(TAG, "Overrun buffer");
|
||||
@@ -97,7 +94,8 @@ SubGhzWorker* subghz_worker_alloc() {
|
||||
furi_thread_set_context(instance->thread, instance);
|
||||
furi_thread_set_callback(instance->thread, subghz_worker_thread_callback);
|
||||
|
||||
instance->stream = xStreamBufferCreate(sizeof(LevelDuration) * 4096, sizeof(LevelDuration));
|
||||
instance->stream =
|
||||
furi_stream_buffer_alloc(sizeof(LevelDuration) * 4096, sizeof(LevelDuration));
|
||||
|
||||
//setting filter
|
||||
instance->filter_running = true;
|
||||
@@ -109,7 +107,7 @@ SubGhzWorker* subghz_worker_alloc() {
|
||||
void subghz_worker_free(SubGhzWorker* instance) {
|
||||
furi_assert(instance);
|
||||
|
||||
vStreamBufferDelete(instance->stream);
|
||||
furi_stream_buffer_free(instance->stream);
|
||||
furi_thread_free(instance->thread);
|
||||
|
||||
free(instance);
|
||||
|
@@ -1,5 +1,4 @@
|
||||
#include "buffer_stream.h"
|
||||
#include <stream_buffer.h>
|
||||
|
||||
struct Buffer {
|
||||
volatile bool occupied;
|
||||
@@ -10,7 +9,7 @@ struct Buffer {
|
||||
|
||||
struct BufferStream {
|
||||
size_t stream_overrun_count;
|
||||
StreamBufferHandle_t stream;
|
||||
FuriStreamBuffer* stream;
|
||||
|
||||
size_t index;
|
||||
Buffer* buffers;
|
||||
@@ -54,7 +53,7 @@ BufferStream* buffer_stream_alloc(size_t buffer_size, size_t buffers_count) {
|
||||
buffer_stream->buffers[i].data = malloc(buffer_size);
|
||||
buffer_stream->buffers[i].max_data_size = buffer_size;
|
||||
}
|
||||
buffer_stream->stream = xStreamBufferCreate(
|
||||
buffer_stream->stream = furi_stream_buffer_alloc(
|
||||
sizeof(BufferStream*) * buffer_stream->max_buffers_count, sizeof(BufferStream*));
|
||||
buffer_stream->stream_overrun_count = 0;
|
||||
buffer_stream->index = 0;
|
||||
@@ -66,7 +65,7 @@ void buffer_stream_free(BufferStream* buffer_stream) {
|
||||
for(size_t i = 0; i < buffer_stream->max_buffers_count; i++) {
|
||||
free(buffer_stream->buffers[i].data);
|
||||
}
|
||||
vStreamBufferDelete(buffer_stream->stream);
|
||||
furi_stream_buffer_free(buffer_stream->stream);
|
||||
free(buffer_stream->buffers);
|
||||
free(buffer_stream);
|
||||
}
|
||||
@@ -83,11 +82,7 @@ static inline int8_t buffer_stream_get_free_buffer(BufferStream* buffer_stream)
|
||||
return id;
|
||||
}
|
||||
|
||||
bool buffer_stream_send_from_isr(
|
||||
BufferStream* buffer_stream,
|
||||
const uint8_t* data,
|
||||
size_t size,
|
||||
BaseType_t* const task_woken) {
|
||||
bool buffer_stream_send_from_isr(BufferStream* buffer_stream, const uint8_t* data, size_t size) {
|
||||
Buffer* buffer = &buffer_stream->buffers[buffer_stream->index];
|
||||
bool result = true;
|
||||
|
||||
@@ -96,7 +91,7 @@ bool buffer_stream_send_from_isr(
|
||||
// if buffer is full - send it
|
||||
buffer->occupied = true;
|
||||
// we always have space for buffer in stream
|
||||
xStreamBufferSendFromISR(buffer_stream->stream, &buffer, sizeof(Buffer*), task_woken);
|
||||
furi_stream_buffer_send(buffer_stream->stream, &buffer, sizeof(Buffer*), 0);
|
||||
|
||||
// get new buffer from the pool
|
||||
int8_t index = buffer_stream_get_free_buffer(buffer_stream);
|
||||
@@ -119,7 +114,8 @@ bool buffer_stream_send_from_isr(
|
||||
|
||||
Buffer* buffer_stream_receive(BufferStream* buffer_stream, TickType_t timeout) {
|
||||
Buffer* buffer;
|
||||
size_t size = xStreamBufferReceive(buffer_stream->stream, &buffer, sizeof(Buffer*), timeout);
|
||||
size_t size =
|
||||
furi_stream_buffer_receive(buffer_stream->stream, &buffer, sizeof(Buffer*), timeout);
|
||||
|
||||
if(size == sizeof(Buffer*)) {
|
||||
return buffer;
|
||||
@@ -134,9 +130,8 @@ size_t buffer_stream_get_overrun_count(BufferStream* buffer_stream) {
|
||||
|
||||
void buffer_stream_reset(BufferStream* buffer_stream) {
|
||||
FURI_CRITICAL_ENTER();
|
||||
BaseType_t xReturn = xStreamBufferReset(buffer_stream->stream);
|
||||
furi_assert(xReturn == pdPASS);
|
||||
UNUSED(xReturn);
|
||||
furi_stream_buffer_reset(buffer_stream->stream);
|
||||
|
||||
buffer_stream->stream_overrun_count = 0;
|
||||
for(size_t i = 0; i < buffer_stream->max_buffers_count; i++) {
|
||||
buffer_reset(&buffer_stream->buffers[i]);
|
||||
|
@@ -59,14 +59,9 @@ void buffer_stream_free(BufferStream* buffer_stream);
|
||||
* @param buffer_stream
|
||||
* @param data
|
||||
* @param size
|
||||
* @param task_woken
|
||||
* @return bool
|
||||
*/
|
||||
bool buffer_stream_send_from_isr(
|
||||
BufferStream* buffer_stream,
|
||||
const uint8_t* data,
|
||||
size_t size,
|
||||
BaseType_t* const task_woken);
|
||||
bool buffer_stream_send_from_isr(BufferStream* buffer_stream, const uint8_t* data, size_t size);
|
||||
|
||||
/**
|
||||
* @brief Receive buffer from stream
|
||||
|
Reference in New Issue
Block a user