-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathu_tx_threads.c
More file actions
37 lines (29 loc) · 1.12 KB
/
u_tx_threads.c
File metadata and controls
37 lines (29 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "u_tx_threads.h"
#include "u_tx_debug.h"
#include "u_tx_general.h"
// clang-format off
uint8_t create_thread(TX_BYTE_POOL *byte_pool, thread_t *thread)
{
CHAR *pointer;
uint8_t status;
/* Allocate the stack for the thread. */
status = tx_byte_allocate(byte_pool, (VOID **)&pointer, thread->size, TX_NO_WAIT);
if (status != TX_SUCCESS) {
PRINTLN_ERROR("Failed to allocate stack before creating thread (Status: %d/%s, Thread: %s).", status, tx_status_toString(status), thread->name);
return U_ERROR;
}
/* Create the thread. */
status = tx_thread_create(&thread->_TX_THREAD, (CHAR *)thread->name, thread->function, thread->thread_input, pointer, thread->size, thread->priority, thread->threshold, thread->time_slice, thread->auto_start);
if (status != TX_SUCCESS) {
PRINTLN_ERROR("Failed to create thread (Status: %d/%s, Thread: %s).", status, tx_status_toString(status), thread->name);
tx_byte_release(pointer); // Free allocated memory if thread creation fails
return U_ERROR;
}
return U_SUCCESS;
}
uint8_t thread_sleep_ms(uint32_t ms)
{
tx_thread_sleep(MS_TO_TICKS(ms));
return U_SUCCESS;
}
// clang-format on