|
Muteki
EABI code execution on Besta® RTOS devices.
|
Native threading API. More...
Go to the source code of this file.
Data Structures | |
| struct | bxc_waitable_t |
| Common data structure for waitables. More... | |
| struct | bxc_queue_nonatomic_t |
| Nonatomic backend storage for message queues. More... | |
| struct | bxc_thread_s |
| Thread descriptor structure. More... | |
| struct | bxc_semaphore_s |
| Semaphore descriptor structure. More... | |
| struct | bxc_event_s |
| Event descriptor structure. More... | |
| struct | bxc_cs_s |
| Critical section descriptor structure. More... | |
| struct | bxc_queue_s |
| Message queue descriptor structure. More... | |
| union | bxc_waitable_desc_u |
| Generic waitable descriptor. More... | |
Typedefs | |
| typedef enum bxc_wait_result_e | bxc_wait_result_t |
| Result of waitables. | |
| typedef int(*) | bxc_thread_func_t(void *user_data) |
| Thread function type. | |
| typedef unsigned char | bxc_queue_message_t[16] |
| Message type for message queues. | |
| typedef struct bxc_thread_s | bxc_thread_t |
| Thread descriptor type. | |
| typedef struct bxc_semaphore_s | bxc_semaphore_t |
| Semaphore descriptor type. | |
| typedef struct bxc_event_s | bxc_event_t |
| Event descriptor type. | |
| typedef struct bxc_cs_s | bxc_cs_t |
| Critical section descriptor type. | |
| typedef struct bxc_queue_s | bxc_queue_t |
| Message queue descriptor type. | |
| typedef union bxc_waitable_desc_u | bxc_waitable_desc_t |
| Waitable object union used by bxc_thread_t. | |
Enumerations | |
| enum | bxc_wait_reason_e { BXC_WAIT_ON_NONE = 0x0 , BXC_WAIT_ON_SEMAPHORE = 0x1 , BXC_WAIT_ON_EVENT = 0x2 , BXC_WAIT_ON_QUEUE = 0x4 , BXC_WAIT_ON_SUSPEND = 0x8 , BXC_WAIT_ON_CRITICAL_SECTION = 0x10 , BXC_WAIT_ON_SLEEP = 0x20 , BXC_WAIT_ON_YIELD = 0x20 } |
| Thread wait reason enum. More... | |
| enum | bxc_threading_kind_e { BXC_THREADING_KIND_THREAD = 0x100 , BXC_THREADING_KIND_SEMAPHORE = 0x200 , BXC_THREADING_KIND_EVENT = 0x201 , BXC_THREADING_KIND_CS_QUEUE = 0x202 } |
| Runtime threading descriptor kind code. More... | |
| enum | bxc_wait_result_e { BXC_WAIT_RESULT_TIMEOUT = 0x82 , BXC_WAIT_RESULT_RESOLVED , BXC_WAIT_RESULT_ERROR } |
| Result of waitables. More... | |
Functions | |
| bxc_thread_t * | OSCreateThread (bxc_thread_func_t func, void *user_data, size_t stack_size, bool defer_start) |
| Create a new thread. | |
| int | OSTerminateThread (bxc_thread_t *thr, int exit_code) |
| Terminate a thread. | |
| bool | OSSetThreadPriority (bxc_thread_t *thr, short new_slot) |
| Set the thread priority (slot number). | |
| short | OSGetThreadPriority (bxc_thread_t *thr) |
| Get the thread priority (slot number). | |
| bool | OSSuspendThread (bxc_thread_t *thr) |
| Suspend a thread from outside of that thread. | |
| bool | OSResumeThread (bxc_thread_t *thr) |
| Start/restart a previously suspended thread. | |
| bool | OSWakeUpThread (bxc_thread_t *thr) |
| Force wake up a sleeping thread. | |
| int | OSExitThread (int exit_code) |
| Terminate current thread. | |
| void | OSSleep (short time_units) |
Sleep for number of scheduler time_units . | |
| bxc_semaphore_t * | OSCreateSemaphore (short init_ctr) |
| Create an semaphore descriptor. | |
| bxc_wait_result_t | OSWaitForSemaphore (bxc_semaphore_t *semaphore, short timeout) |
| Wait and acquire a semaphore. | |
| bool | OSReleaseSemaphore (bxc_semaphore_t *semaphore) |
| Release a semaphore. | |
| bool | OSCloseSemaphore (bxc_semaphore_t *semaphore) |
| Destroy a semaphore. | |
| bxc_event_t * | OSCreateEvent (short latch_on, int flag) |
| Create an event descriptor. | |
| bxc_wait_result_t | OSWaitForEvent (bxc_event_t *event, short timeout) |
| Wait for an event. | |
| bool | OSSetEvent (bxc_event_t *event) |
| Set the event flag. | |
| bool | OSResetEvent (bxc_event_t *event) |
| Reset the event flag. | |
| bool | OSCloseEvent (bxc_event_t *event) |
| Destroy the event descriptor. | |
| void | OSInitCriticalSection (bxc_cs_t *cs) |
| Initialize a critical section descriptor. | |
| void | OSEnterCriticalSection (bxc_cs_t *cs) |
| Enter/aquire a critical section. | |
| void | OSLeaveCriticalSection (bxc_cs_t *cs) |
| Leave/release a critical section. | |
| void | OSDeleteCriticalSection (bxc_cs_t *cs) |
| Destroy a critical section descriptor. | |
| bxc_queue_t * | OSCreateMsgQue (unsigned short size) |
| Create a message queue descriptor. | |
| bool | OSPostMsgQue (bxc_queue_t *queue, const bxc_queue_message_t *message) |
| Push a message into the queue. | |
| bool | OSSendMsgQue (bxc_queue_t *queue, const bxc_queue_message_t *message) |
| Push a message into the queue and reschedule immediately. | |
| bool | OSPeekMsgQue (bxc_queue_t *queue, bxc_queue_message_t *message) |
| Pop a message from the queue asynchronously. | |
| bool | OSGetMsgQue (bxc_queue_t *queue, bxc_queue_message_t *message) |
| Pop a message from the queue. | |
| bool | OSCloseMsgQue (bxc_queue_t *queue) |
| Destroy a message queue descriptor. | |
| short | OSGetCurrentlyRunningTCBPrio (void) |
| Get the current running thread's priority (slot number). | |
Native threading API.
| typedef unsigned char bxc_queue_message_t[16] |
Message type for message queues.
This needs to be 4 byte aligned since the inline memcpy in the internal FIFO queue routines use hardcoded ldm/stm.
| enum bxc_threading_kind_e |
| enum bxc_wait_reason_e |
Thread wait reason enum.
| Enumerator | |
|---|---|
| BXC_WAIT_ON_NONE | Nothing. |
| BXC_WAIT_ON_SEMAPHORE | Waiting on a semaphore. |
| BXC_WAIT_ON_EVENT | Waiting on an event. |
| BXC_WAIT_ON_QUEUE | Waiting for a message queue push. |
| BXC_WAIT_ON_SUSPEND | Waiting to be unsuspended by OSResumeThread(). |
| BXC_WAIT_ON_CRITICAL_SECTION | Waiting for a critical section to be released. |
| BXC_WAIT_ON_SLEEP | Deprecated name of ::BXC_WAIT_ON_TIMEOUT. |
| BXC_WAIT_ON_YIELD | Waiting to take back control after a yield/timeout. This can either mean the thread has yielded voluntarily by calling OSSleep(0) from itself, or that the thread execution is temporarily on hold because it has timed out. |
| enum bxc_wait_result_e |
|
extern |
Destroy the event descriptor.
| event | The event context. |
| true | The operation was completed successfully. |
| false | The operation failed with error. |
|
extern |
Destroy a message queue descriptor.
| queue | The message queue descriptor. |
| true | The operation was completed successfully. |
| false | The operation failed with error. |
|
extern |
Destroy a semaphore.
| semaphore | The semaphore context. |
| true | The operation was completed successfully. |
| false | The operation failed with error. |
|
extern |
Create an event descriptor.
| latch_on | Set to non-0 will inhibit the event from getting cleared after a OSWaitForEvent() is resolved. |
| flag | The initial flag value. Can be either 0 or 1. |
|
extern |
Create a message queue descriptor.
Effective queue size will be size - 1 due to how the internal ring buffer implementation tracks usage.
| size | Size of the queue in number of messages (will use sizeof(::message_queue_message_t) * size bytes of memory). |
|
extern |
Create an semaphore descriptor.
| init_ctr | Initial counter value. |
|
extern |
Create a new thread.
| func | Function to execute in the new thread. |
| user_data | User data for the thread. |
| stack_size | The size of the thread stack. |
| defer_start | Do not immediately schedule this thread and create it as suspended. |
|
extern |
Destroy a critical section descriptor.
This does not ensure that the critical section's users are properly notified. Therefore one must ensure that no thread is waiting on the critical section before attempting to call this function on it.
| [in,out] | cs | The critical section descriptor. |
|
extern |
Enter/aquire a critical section.
Besta critical sections behave like recursive mutexes. Therefore this will block when multiple threads are trying to enter the same context, but it will let repeated entry attempts initiated by the same thread to pass through. The context is released when all of the entries are reverted by a OSLeaveCriticalSection() call.
| [in,out] | cs | The critical section descriptor. |
|
extern |
Terminate current thread.
This calls OSTerminateThread() with the descriptor of current thread as thr.
| exit_code | The exit code. |
| 0 | The operation was completed successfully. |
|
extern |
Get the current running thread's priority (slot number).
So far only Pocket Challenge implements this syscall. Calling it on other devices will very likely cause the NOSYS handler to be called, which in turn will crash the system.
On other devices, this can be simulated using mutekix:
Requires -lkrnllib when dynamically linking with the shims.
|
extern |
Pop a message from the queue.
| queue | The message queue descriptor. |
| message | The result message. |
| true | The operation was completed successfully. |
| false | The operation failed with error. |
|
extern |
Get the thread priority (slot number).
| thr | The thread descriptor. |
|
extern |
Initialize a critical section descriptor.
| [out] | cs | The critical section descriptor. |
|
extern |
Leave/release a critical section.
| [in,out] | cs | The critical section descriptor. |
|
extern |
Pop a message from the queue asynchronously.
| queue | The message queue descriptor. |
| message | The result message. |
| true | The operation was completed successfully. |
| false | The operation failed with error. |
|
extern |
Push a message into the queue.
| queue | The message queue descriptor. |
| message | The message being pushed. |
| true | The operation was completed successfully. |
| false | The operation failed with error. |
|
extern |
Release a semaphore.
| semaphore | The semaphore context. |
| true | The operation was completed successfully. |
| false | The operation failed with error. |
|
extern |
Reset the event flag.
This sets the event_t::flag to 0.
| event | The event context. |
| true | The operation was completed successfully. |
| false | The operation failed with error. |
|
extern |
Start/restart a previously suspended thread.
| thr | The thread descriptor. |
| true | The operation was completed successfully. |
| false | The operation failed with error. |
|
extern |
Push a message into the queue and reschedule immediately.
This results in the thread receiving a message
| queue | The message queue descriptor. |
| message | The message being pushed. |
| true | The operation was completed successfully. |
| false | The operation failed with error. |
|
extern |
Set the event flag.
This sets the event_t::flag to 1.
| event | The event context. |
| true | The operation was completed successfully. |
| false | The operation failed with error. |
|
extern |
Set the thread priority (slot number).
On Besta RTOS, priority is implied in the natural order of the threads in the global thread table. Some slots in the table seem to be reserved (8 for the top and 18 for the bottom) and are not accessible by just allocating the thread with OSCreateThread(). User can move threads to these reserved slots by calling the OSSetThreadPriority() function.
| thr | The thread descriptor. |
| new_slot | The new slot number. |
| true | The operation was completed successfully. |
| false | The operation failed with error. |
|
extern |
Sleep for number of scheduler time_units .
A time unit is typically around 1ms on Besta RTOS, but this could fluctuate in practice.
When time_units is set to 0, the current thread will yield (voluntarily put itself into the "timed out" state) by clearing the bxc_thread_t::timeout value, and will resume execution after the scheduler goes to idle.
| time_units | Time to sleep in scheduler time units. |
|
extern |
Suspend a thread from outside of that thread.
| thr | The thread descriptor. |
| true | The operation was completed successfully. |
| false | The operation failed with error. |
|
extern |
Terminate a thread.
| thr | Thread to terminate. |
| exit_code | The exit code. |
| 0 | The operation was completed successfully. |
|
extern |
Wait for an event.
| event | The event context. |
| timeout | Timeout in OSSleep() units. |
|
extern |
Wait and acquire a semaphore.
| semaphore | The semaphore context. |
| timeout | Timeout in OSSleep() units. |
|
extern |
Force wake up a sleeping thread.
This expire the sleep counter of a thread immediately and reschedule if the thread is not suspended.
| thr | The thread descriptor. |
| true | The operation was completed successfully. |
| false | The operation failed with error. |