[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:
@@ -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);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user