Skip to content

Commit

Permalink
Merge branch 'dev' into unleashed
Browse files Browse the repository at this point in the history
  • Loading branch information
RogueMaster committed Jun 20, 2022
2 parents 52fdcf1 + 839e52a commit d66f6d6
Show file tree
Hide file tree
Showing 56 changed files with 1,603 additions and 2,917 deletions.
12 changes: 6 additions & 6 deletions applications/cli/cli_commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -255,19 +255,19 @@ void cli_command_ps(Cli* cli, string_t args, void* context) {
UNUSED(context);

const uint8_t threads_num_max = 32;
osThreadId_t threads_id[threads_num_max];
uint8_t thread_num = osThreadEnumerate(threads_id, threads_num_max);
FuriThreadId threads_ids[threads_num_max];
uint8_t thread_num = furi_thread_enumerate(threads_ids, threads_num_max);
printf(
"%-20s %-14s %-8s %-8s %s\r\n", "Name", "Stack start", "Heap", "Stack", "Stack min free");
for(uint8_t i = 0; i < thread_num; i++) {
TaskControlBlock* tcb = (TaskControlBlock*)threads_id[i];
TaskControlBlock* tcb = (TaskControlBlock*)threads_ids[i];
printf(
"%-20s 0x%-12lx %-8d %-8ld %-8ld\r\n",
osThreadGetName(threads_id[i]),
furi_thread_get_name(threads_ids[i]),
(uint32_t)tcb->pxStack,
memmgr_heap_get_thread_memory(threads_id[i]),
memmgr_heap_get_thread_memory(threads_ids[i]),
(uint32_t)(tcb->pxEndOfStack - tcb->pxStack + 1) * sizeof(StackType_t),
osThreadGetStackSpace(threads_id[i]));
furi_thread_get_stack_space(threads_ids[i]));
}
printf("\r\nTotal: %d", thread_num);
}
Expand Down
19 changes: 10 additions & 9 deletions applications/cli/cli_vcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ static void cli_vcp_init() {
}

static void cli_vcp_deinit() {
osThreadFlagsSet(furi_thread_get_thread_id(vcp->thread), VcpEvtStop);
furi_thread_flags_set(furi_thread_get_id(vcp->thread), VcpEvtStop);
furi_thread_join(vcp->thread);
furi_thread_free(vcp->thread);
vcp->thread = NULL;
Expand All @@ -102,7 +102,8 @@ static int32_t vcp_worker(void* context) {
vcp->running = true;

while(1) {
uint32_t flags = osThreadFlagsWait(VCP_THREAD_FLAG_ALL, osFlagsWaitAny, osWaitForever);
uint32_t flags =
furi_thread_flags_wait(VCP_THREAD_FLAG_ALL, osFlagsWaitAny, osWaitForever);
furi_assert((flags & osFlagsError) == 0);

// VCP session opened
Expand Down Expand Up @@ -232,7 +233,7 @@ static size_t cli_vcp_rx(uint8_t* buffer, size_t size, uint32_t timeout) {
FURI_LOG_D(TAG, "rx %u ", batch_size);
#endif
if(len == 0) break;
osThreadFlagsSet(furi_thread_get_thread_id(vcp->thread), VcpEvtStreamRx);
furi_thread_flags_set(furi_thread_get_id(vcp->thread), VcpEvtStreamRx);
size -= len;
buffer += len;
rx_cnt += len;
Expand Down Expand Up @@ -261,7 +262,7 @@ static void cli_vcp_tx(const uint8_t* buffer, size_t size) {
if(batch_size > USB_CDC_PKT_LEN) batch_size = USB_CDC_PKT_LEN;

xStreamBufferSend(vcp->tx_stream, buffer, batch_size, osWaitForever);
osThreadFlagsSet(furi_thread_get_thread_id(vcp->thread), VcpEvtStreamTx);
furi_thread_flags_set(furi_thread_get_id(vcp->thread), VcpEvtStreamTx);
#ifdef CLI_VCP_DEBUG
FURI_LOG_D(TAG, "tx %u", batch_size);
#endif
Expand All @@ -283,7 +284,7 @@ static void cli_vcp_tx_stdout(void* _cookie, const char* data, size_t size) {
static void vcp_state_callback(void* context, uint8_t state) {
UNUSED(context);
if(state == 0) {
osThreadFlagsSet(furi_thread_get_thread_id(vcp->thread), VcpEvtDisconnect);
furi_thread_flags_set(furi_thread_get_id(vcp->thread), VcpEvtDisconnect);
}
}

Expand All @@ -293,21 +294,21 @@ static void vcp_on_cdc_control_line(void* context, uint8_t state) {
bool dtr = state & (1 << 0);

if(dtr == true) {
osThreadFlagsSet(furi_thread_get_thread_id(vcp->thread), VcpEvtConnect);
furi_thread_flags_set(furi_thread_get_id(vcp->thread), VcpEvtConnect);
} else {
osThreadFlagsSet(furi_thread_get_thread_id(vcp->thread), VcpEvtDisconnect);
furi_thread_flags_set(furi_thread_get_id(vcp->thread), VcpEvtDisconnect);
}
}

static void vcp_on_cdc_rx(void* context) {
UNUSED(context);
uint32_t ret = osThreadFlagsSet(furi_thread_get_thread_id(vcp->thread), VcpEvtRx);
uint32_t ret = furi_thread_flags_set(furi_thread_get_id(vcp->thread), VcpEvtRx);
furi_check((ret & osFlagsError) == 0);
}

static void vcp_on_cdc_tx_complete(void* context) {
UNUSED(context);
osThreadFlagsSet(furi_thread_get_thread_id(vcp->thread), VcpEvtTx);
furi_thread_flags_set(furi_thread_get_id(vcp->thread), VcpEvtTx);
}

static bool cli_vcp_is_connected(void) {
Expand Down
7 changes: 4 additions & 3 deletions applications/debug_tools/uart_echo.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ static void uart_echo_on_irq_cb(UartIrqEvent ev, uint8_t data, void* context) {

if(ev == UartIrqEventRXNE) {
xStreamBufferSendFromISR(app->rx_stream, &data, 1, &xHigherPriorityTaskWoken);
osThreadFlagsSet(furi_thread_get_thread_id(app->worker_thread), WorkerEventRx);
furi_thread_flags_set(furi_thread_get_id(app->worker_thread), WorkerEventRx);
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
}
}
Expand Down Expand Up @@ -149,7 +149,8 @@ static int32_t uart_echo_worker(void* context) {
UartEchoApp* app = context;

while(1) {
uint32_t events = osThreadFlagsWait(WORKER_EVENTS_MASK, osFlagsWaitAny, osWaitForever);
uint32_t events =
furi_thread_flags_wait(WORKER_EVENTS_MASK, osFlagsWaitAny, osWaitForever);
furi_check((events & osFlagsError) == 0);

if(events & WorkerEventStop) break;
Expand Down Expand Up @@ -234,7 +235,7 @@ static UartEchoApp* uart_echo_app_alloc() {
static void uart_echo_app_free(UartEchoApp* app) {
furi_assert(app);

osThreadFlagsSet(furi_thread_get_thread_id(app->worker_thread), WorkerEventStop);
furi_thread_flags_set(furi_thread_get_id(app->worker_thread), WorkerEventStop);
furi_thread_join(app->worker_thread);
furi_thread_free(app->worker_thread);

Expand Down
26 changes: 14 additions & 12 deletions applications/gpio/usb_uart_bridge.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ static void usb_uart_on_irq_cb(UartIrqEvent ev, uint8_t data, void* context) {

if(ev == UartIrqEventRXNE) {
xStreamBufferSendFromISR(usb_uart->rx_stream, &data, 1, &xHigherPriorityTaskWoken);
osThreadFlagsSet(furi_thread_get_thread_id(usb_uart->thread), WorkerEvtRxDone);
furi_thread_flags_set(furi_thread_get_id(usb_uart->thread), WorkerEvtRxDone);
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
}
}
Expand Down Expand Up @@ -181,12 +181,13 @@ static int32_t usb_uart_worker(void* context) {
usb_uart_update_ctrl_lines(usb_uart);
}

osThreadFlagsSet(furi_thread_get_thread_id(usb_uart->tx_thread), WorkerEvtCdcRx);
furi_thread_flags_set(furi_thread_get_id(usb_uart->tx_thread), WorkerEvtCdcRx);

furi_thread_start(usb_uart->tx_thread);

while(1) {
uint32_t events = osThreadFlagsWait(WORKER_ALL_RX_EVENTS, osFlagsWaitAny, osWaitForever);
uint32_t events =
furi_thread_flags_wait(WORKER_ALL_RX_EVENTS, osFlagsWaitAny, osWaitForever);
furi_check((events & osFlagsError) == 0);
if(events & WorkerEvtStop) break;
if(events & WorkerEvtRxDone) {
Expand All @@ -205,7 +206,7 @@ static int32_t usb_uart_worker(void* context) {
}
if(events & WorkerEvtCfgChange) {
if(usb_uart->cfg.vcp_ch != usb_uart->cfg_new.vcp_ch) {
osThreadFlagsSet(furi_thread_get_thread_id(usb_uart->tx_thread), WorkerEvtTxStop);
furi_thread_flags_set(furi_thread_get_id(usb_uart->tx_thread), WorkerEvtTxStop);
furi_thread_join(usb_uart->tx_thread);

usb_uart_vcp_deinit(usb_uart, usb_uart->cfg.vcp_ch);
Expand All @@ -217,7 +218,7 @@ static int32_t usb_uart_worker(void* context) {
events |= WorkerEvtLineCfgSet;
}
if(usb_uart->cfg.uart_ch != usb_uart->cfg_new.uart_ch) {
osThreadFlagsSet(furi_thread_get_thread_id(usb_uart->tx_thread), WorkerEvtTxStop);
furi_thread_flags_set(furi_thread_get_id(usb_uart->tx_thread), WorkerEvtTxStop);
furi_thread_join(usb_uart->tx_thread);

usb_uart_serial_deinit(usb_uart, usb_uart->cfg.uart_ch);
Expand Down Expand Up @@ -266,7 +267,7 @@ static int32_t usb_uart_worker(void* context) {
furi_hal_gpio_init_simple(flow_pins[usb_uart->cfg.flow_pins - 1][1], GpioModeAnalog);
}

osThreadFlagsSet(furi_thread_get_thread_id(usb_uart->tx_thread), WorkerEvtTxStop);
furi_thread_flags_set(furi_thread_get_id(usb_uart->tx_thread), WorkerEvtTxStop);
furi_thread_join(usb_uart->tx_thread);
furi_thread_free(usb_uart->tx_thread);

Expand All @@ -288,7 +289,8 @@ static int32_t usb_uart_tx_thread(void* context) {

uint8_t data[USB_CDC_PKT_LEN];
while(1) {
uint32_t events = osThreadFlagsWait(WORKER_ALL_TX_EVENTS, osFlagsWaitAny, osWaitForever);
uint32_t events =
furi_thread_flags_wait(WORKER_ALL_TX_EVENTS, osFlagsWaitAny, osWaitForever);
furi_check((events & osFlagsError) == 0);
if(events & WorkerEvtTxStop) break;
if(events & WorkerEvtCdcRx) {
Expand All @@ -314,7 +316,7 @@ static void vcp_on_cdc_tx_complete(void* context) {

static void vcp_on_cdc_rx(void* context) {
UsbUartBridge* usb_uart = (UsbUartBridge*)context;
osThreadFlagsSet(furi_thread_get_thread_id(usb_uart->tx_thread), WorkerEvtCdcRx);
furi_thread_flags_set(furi_thread_get_id(usb_uart->tx_thread), WorkerEvtCdcRx);
}

static void vcp_state_callback(void* context, uint8_t state) {
Expand All @@ -325,13 +327,13 @@ static void vcp_state_callback(void* context, uint8_t state) {
static void vcp_on_cdc_control_line(void* context, uint8_t state) {
UNUSED(state);
UsbUartBridge* usb_uart = (UsbUartBridge*)context;
osThreadFlagsSet(furi_thread_get_thread_id(usb_uart->thread), WorkerEvtCtrlLineSet);
furi_thread_flags_set(furi_thread_get_id(usb_uart->thread), WorkerEvtCtrlLineSet);
}

static void vcp_on_line_config(void* context, struct usb_cdc_line_coding* config) {
UNUSED(config);
UsbUartBridge* usb_uart = (UsbUartBridge*)context;
osThreadFlagsSet(furi_thread_get_thread_id(usb_uart->thread), WorkerEvtLineCfgSet);
furi_thread_flags_set(furi_thread_get_id(usb_uart->thread), WorkerEvtLineCfgSet);
}

UsbUartBridge* usb_uart_enable(UsbUartConfig* cfg) {
Expand All @@ -351,7 +353,7 @@ UsbUartBridge* usb_uart_enable(UsbUartConfig* cfg) {

void usb_uart_disable(UsbUartBridge* usb_uart) {
furi_assert(usb_uart);
osThreadFlagsSet(furi_thread_get_thread_id(usb_uart->thread), WorkerEvtStop);
furi_thread_flags_set(furi_thread_get_id(usb_uart->thread), WorkerEvtStop);
furi_thread_join(usb_uart->thread);
furi_thread_free(usb_uart->thread);
free(usb_uart);
Expand All @@ -361,7 +363,7 @@ void usb_uart_set_config(UsbUartBridge* usb_uart, UsbUartConfig* cfg) {
furi_assert(usb_uart);
furi_assert(cfg);
memcpy(&(usb_uart->cfg_new), cfg, sizeof(UsbUartConfig));
osThreadFlagsSet(furi_thread_get_thread_id(usb_uart->thread), WorkerEvtCfgChange);
furi_thread_flags_set(furi_thread_get_id(usb_uart->thread), WorkerEvtCfgChange);
}

void usb_uart_get_config(UsbUartBridge* usb_uart, UsbUartConfig* cfg) {
Expand Down
11 changes: 6 additions & 5 deletions applications/gui/gui.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ ViewPort* gui_view_port_find_enabled(ViewPortArray_t array) {

void gui_update(Gui* gui) {
furi_assert(gui);
osThreadFlagsSet(gui->thread, GUI_THREAD_FLAG_DRAW);
furi_thread_flags_set(gui->thread_id, GUI_THREAD_FLAG_DRAW);
}

void gui_input_events_callback(const void* value, void* ctx) {
Expand All @@ -29,7 +29,7 @@ void gui_input_events_callback(const void* value, void* ctx) {
Gui* gui = ctx;

osMessageQueuePut(gui->input_queue, value, 0, osWaitForever);
osThreadFlagsSet(gui->thread, GUI_THREAD_FLAG_INPUT);
furi_thread_flags_set(gui->thread_id, GUI_THREAD_FLAG_INPUT);
}

// Only Fullscreen supports vertical display for now
Expand Down Expand Up @@ -471,7 +471,7 @@ void gui_set_lockdown(Gui* gui, bool lockdown) {
Gui* gui_alloc() {
Gui* gui = malloc(sizeof(Gui));
// Thread ID
gui->thread = osThreadGetId();
gui->thread_id = furi_thread_get_current_id();
// Allocate mutex
gui->mutex = osMutexNew(NULL);
furi_check(gui->mutex);
Expand Down Expand Up @@ -500,7 +500,8 @@ int32_t gui_srv(void* p) {
furi_record_create("gui", gui);

while(1) {
uint32_t flags = osThreadFlagsWait(GUI_THREAD_FLAG_ALL, osFlagsWaitAny, osWaitForever);
uint32_t flags =
furi_thread_flags_wait(GUI_THREAD_FLAG_ALL, osFlagsWaitAny, osWaitForever);
// Process and dispatch input
if(flags & GUI_THREAD_FLAG_INPUT) {
// Process till queue become empty
Expand All @@ -512,7 +513,7 @@ int32_t gui_srv(void* p) {
// Process and dispatch draw call
if(flags & GUI_THREAD_FLAG_DRAW) {
// Clear flags that arrived on input step
osThreadFlagsClear(GUI_THREAD_FLAG_DRAW);
furi_thread_flags_clear(GUI_THREAD_FLAG_DRAW);
gui_redraw(gui);
}
}
Expand Down
2 changes: 1 addition & 1 deletion applications/gui/gui_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ ALGO_DEF(CanvasCallbackPairArray, CanvasCallbackPairArray_t);
/** Gui structure */
struct Gui {
// Thread and lock
osThreadId_t thread;
FuriThreadId thread_id;
osMutexId_t mutex;

// Layers and Canvas
Expand Down
18 changes: 9 additions & 9 deletions applications/gui/modules/file_browser_worker.c
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,10 @@ static int32_t browser_worker(void* context) {
string_t filename;
string_init(filename);

osThreadFlagsSet(furi_thread_get_thread_id(browser->thread), WorkerEvtConfigChange);
furi_thread_flags_set(furi_thread_get_id(browser->thread), WorkerEvtConfigChange);

while(1) {
uint32_t flags = osThreadFlagsWait(WORKER_FLAGS_ALL, osFlagsWaitAny, osWaitForever);
uint32_t flags = furi_thread_flags_wait(WORKER_FLAGS_ALL, osFlagsWaitAny, osWaitForever);
furi_assert((flags & osFlagsError) == 0);

if(flags & WorkerEvtConfigChange) {
Expand All @@ -272,7 +272,7 @@ static int32_t browser_worker(void* context) {
}
idx_last_array_reset(browser->idx_last);

osThreadFlagsSet(furi_thread_get_thread_id(browser->thread), WorkerEvtFolderEnter);
furi_thread_flags_set(furi_thread_get_id(browser->thread), WorkerEvtFolderEnter);
}

if(flags & WorkerEvtFolderEnter) {
Expand Down Expand Up @@ -369,7 +369,7 @@ BrowserWorker* file_browser_worker_alloc(string_t path, const char* filter_ext,
void file_browser_worker_free(BrowserWorker* browser) {
furi_assert(browser);

osThreadFlagsSet(furi_thread_get_thread_id(browser->thread), WorkerEvtStop);
furi_thread_flags_set(furi_thread_get_id(browser->thread), WorkerEvtStop);
furi_thread_join(browser->thread);
furi_thread_free(browser->thread);

Expand Down Expand Up @@ -423,30 +423,30 @@ void file_browser_worker_set_config(
string_set(browser->path_next, path);
string_set_str(browser->filter_extension, filter_ext);
browser->skip_assets = skip_assets;
osThreadFlagsSet(furi_thread_get_thread_id(browser->thread), WorkerEvtConfigChange);
furi_thread_flags_set(furi_thread_get_id(browser->thread), WorkerEvtConfigChange);
}

void file_browser_worker_folder_enter(BrowserWorker* browser, string_t path, int32_t item_idx) {
furi_assert(browser);
string_set(browser->path_next, path);
browser->item_sel_idx = item_idx;
osThreadFlagsSet(furi_thread_get_thread_id(browser->thread), WorkerEvtFolderEnter);
furi_thread_flags_set(furi_thread_get_id(browser->thread), WorkerEvtFolderEnter);
}

void file_browser_worker_folder_exit(BrowserWorker* browser) {
furi_assert(browser);
osThreadFlagsSet(furi_thread_get_thread_id(browser->thread), WorkerEvtFolderExit);
furi_thread_flags_set(furi_thread_get_id(browser->thread), WorkerEvtFolderExit);
}

void file_browser_worker_folder_refresh(BrowserWorker* browser, int32_t item_idx) {
furi_assert(browser);
browser->item_sel_idx = item_idx;
osThreadFlagsSet(furi_thread_get_thread_id(browser->thread), WorkerEvtFolderRefresh);
furi_thread_flags_set(furi_thread_get_id(browser->thread), WorkerEvtFolderRefresh);
}

void file_browser_worker_load(BrowserWorker* browser, uint32_t offset, uint32_t count) {
furi_assert(browser);
browser->load_offset = offset;
browser->load_count = count;
osThreadFlagsSet(furi_thread_get_thread_id(browser->thread), WorkerEvtLoad);
furi_thread_flags_set(furi_thread_get_id(browser->thread), WorkerEvtLoad);
}
6 changes: 3 additions & 3 deletions applications/input/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void input_press_timer_callback(void* arg) {

void input_isr(void* _ctx) {
UNUSED(_ctx);
osThreadFlagsSet(input->thread, INPUT_THREAD_FLAG_ISR);
furi_thread_flags_set(input->thread_id, INPUT_THREAD_FLAG_ISR);
}

const char* input_get_key_name(InputKey key) {
Expand Down Expand Up @@ -66,7 +66,7 @@ const char* input_get_type_name(InputType type) {

int32_t input_srv() {
input = malloc(sizeof(Input));
input->thread = osThreadGetId();
input->thread_id = furi_thread_get_current_id();
input->event_pubsub = furi_pubsub_alloc();
furi_record_create("input_events", input->event_pubsub);

Expand Down Expand Up @@ -129,7 +129,7 @@ int32_t input_srv() {
if(is_changing) {
osDelay(1);
} else {
osThreadFlagsWait(INPUT_THREAD_FLAG_ISR, osFlagsWaitAny, osWaitForever);
furi_thread_flags_wait(INPUT_THREAD_FLAG_ISR, osFlagsWaitAny, osWaitForever);
}
}

Expand Down
2 changes: 1 addition & 1 deletion applications/input/input_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ typedef struct {

/** Input state */
typedef struct {
osThreadId_t thread;
FuriThreadId thread_id;
FuriPubSub* event_pubsub;
InputPinState* pin_states;
Cli* cli;
Expand Down
Loading

0 comments on commit d66f6d6

Please sign in to comment.