2022-10-07 12:27:11 +00:00
|
|
|
#include "base.h"
|
2022-12-26 12:13:30 +00:00
|
|
|
#include "check.h"
|
2022-10-07 12:27:11 +00:00
|
|
|
#include "stream_buffer.h"
|
|
|
|
#include "common_defines.h"
|
|
|
|
#include <FreeRTOS.h>
|
|
|
|
#include <FreeRTOS-Kernel/include/stream_buffer.h>
|
|
|
|
|
|
|
|
FuriStreamBuffer* furi_stream_buffer_alloc(size_t size, size_t trigger_level) {
|
2022-12-26 12:13:30 +00:00
|
|
|
furi_assert(size != 0);
|
|
|
|
|
|
|
|
StreamBufferHandle_t handle = xStreamBufferCreate(size, trigger_level);
|
|
|
|
furi_check(handle);
|
|
|
|
|
|
|
|
return handle;
|
2022-10-07 12:27:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void furi_stream_buffer_free(FuriStreamBuffer* stream_buffer) {
|
2022-12-26 12:13:30 +00:00
|
|
|
furi_assert(stream_buffer);
|
2022-10-07 12:27:11 +00:00
|
|
|
vStreamBufferDelete(stream_buffer);
|
|
|
|
};
|
|
|
|
|
|
|
|
bool furi_stream_set_trigger_level(FuriStreamBuffer* stream_buffer, size_t trigger_level) {
|
2022-12-26 12:13:30 +00:00
|
|
|
furi_assert(stream_buffer);
|
2022-10-07 12:27:11 +00:00
|
|
|
return xStreamBufferSetTriggerLevel(stream_buffer, trigger_level) == pdTRUE;
|
|
|
|
};
|
|
|
|
|
|
|
|
size_t furi_stream_buffer_send(
|
|
|
|
FuriStreamBuffer* stream_buffer,
|
|
|
|
const void* data,
|
|
|
|
size_t length,
|
|
|
|
uint32_t timeout) {
|
|
|
|
size_t ret;
|
|
|
|
|
2022-11-05 15:07:24 +00:00
|
|
|
if(FURI_IS_IRQ_MODE()) {
|
2022-10-07 12:27:11 +00:00
|
|
|
BaseType_t yield;
|
|
|
|
ret = xStreamBufferSendFromISR(stream_buffer, data, length, &yield);
|
|
|
|
portYIELD_FROM_ISR(yield);
|
|
|
|
} else {
|
|
|
|
ret = xStreamBufferSend(stream_buffer, data, length, timeout);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
};
|
|
|
|
|
|
|
|
size_t furi_stream_buffer_receive(
|
|
|
|
FuriStreamBuffer* stream_buffer,
|
|
|
|
void* data,
|
|
|
|
size_t length,
|
|
|
|
uint32_t timeout) {
|
|
|
|
size_t ret;
|
|
|
|
|
2022-11-05 15:07:24 +00:00
|
|
|
if(FURI_IS_IRQ_MODE()) {
|
2022-10-07 12:27:11 +00:00
|
|
|
BaseType_t yield;
|
|
|
|
ret = xStreamBufferReceiveFromISR(stream_buffer, data, length, &yield);
|
|
|
|
portYIELD_FROM_ISR(yield);
|
|
|
|
} else {
|
|
|
|
ret = xStreamBufferReceive(stream_buffer, data, length, timeout);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t furi_stream_buffer_bytes_available(FuriStreamBuffer* stream_buffer) {
|
|
|
|
return xStreamBufferBytesAvailable(stream_buffer);
|
|
|
|
};
|
|
|
|
|
|
|
|
size_t furi_stream_buffer_spaces_available(FuriStreamBuffer* stream_buffer) {
|
|
|
|
return xStreamBufferSpacesAvailable(stream_buffer);
|
|
|
|
};
|
|
|
|
|
|
|
|
bool furi_stream_buffer_is_full(FuriStreamBuffer* stream_buffer) {
|
|
|
|
return xStreamBufferIsFull(stream_buffer) == pdTRUE;
|
|
|
|
};
|
|
|
|
|
|
|
|
bool furi_stream_buffer_is_empty(FuriStreamBuffer* stream_buffer) {
|
|
|
|
return (xStreamBufferIsEmpty(stream_buffer) == pdTRUE);
|
|
|
|
};
|
|
|
|
|
|
|
|
FuriStatus furi_stream_buffer_reset(FuriStreamBuffer* stream_buffer) {
|
|
|
|
if(xStreamBufferReset(stream_buffer) == pdPASS) {
|
|
|
|
return FuriStatusOk;
|
|
|
|
} else {
|
|
|
|
return FuriStatusError;
|
|
|
|
}
|
|
|
|
}
|