OS API¶
Functions¶
-
void
rtos_enter_critical
(void)¶ Enter a critical session, all interrupts are disabled.
- Return
void
- Parameters
void
:
-
void
rtos_exit_critical
(void)¶ Exit a critical session, all interrupts are enabled.
- Return
void
- Parameters
void
:
-
void
rtos_lock_scheduling
(void)¶ disable os scheduling
- Return
void
- Parameters
void
:
-
void
rtos_unlock_scheduling
(void)¶ enable os scheduling
- Return
void
- Parameters
void
:
-
OSStatus
beken_time_get_time
(beken_time_t *time_ptr)¶ Get system time value in milliseconds.
- Return
kNoErr : on success.
kGeneralErr : if an error occurred
- Parameters
time_ptr
: : the pointer of time value in milliseconds
-
OSStatus
rtos_create_thread
(beken_thread_t *thread, uint8_t priority, const char *name, beken_thread_function_t function, uint32_t stack_size, beken_thread_arg_t arg)¶ Creates and starts a new thread.
- Return
kNoErr : on success.
kGeneralErr : if an error occurred
- Parameters
thread
: : Pointer to variable that will receive the thread handle (can be null)priority
: : A priority number. (0:Highest priority, 9:Lowest priority)name
: : a text name for the thread (can be null)function
: : the main thread functionstack_size
: : stack size for this threadarg
: : argument which will be passed to thread function (can be null)
-
OSStatus
rtos_delete_thread
(beken_thread_t *thread)¶ Deletes a terminated thread.
- Return
kNoErr : on success.
kGeneralErr : if an error occurred
- Parameters
thread
: : the handle of the thread to delete, NULL is the current thread
-
OSStatus
rtos_thread_set_priority
(beken_thread_t *thread, int priority)¶ Set thread priority.
- Return
kNoErr : on success.
kGeneralErr : if an error occurred
- Parameters
thread
: : the handle of the thread
-
void
rtos_suspend_thread
(beken_thread_t *thread)¶ Suspend a thread.
- Return
kNoErr : on success.
kGeneralErr : if an error occurred
- Parameters
thread
: : the handle of the thread to suspend, NULL is the current thread
-
void
rtos_resume_thread
(beken_thread_t *thread)¶ Resume a thread.
- Return
kNoErr : on success.
kGeneralErr : if an error occurred
- Parameters
thread
: : the handle of the thread to resume, NULL is the current thread
-
OSStatus
rtos_thread_join
(beken_thread_t *thread)¶ Sleeps until another thread has terminated.
Causes the current thread to sleep until the specified other thread has terminated. If the processor is heavily loaded with higher priority tasks, this thread may not wake until significantly after the thread termination.
- Return
kNoErr : on success.
kGeneralErr : if an error occurred
- Parameters
thread
: : the handle of the other thread which will terminate
-
OSStatus
rtos_thread_force_awake
(beken_thread_t *thread)¶ Forcibly wakes another thread.
Causes the specified thread to wake from suspension. This will usually cause an error or timeout in that thread, since the task it was waiting on is not complete.
- Return
kNoErr : on success.
kGeneralErr : if an error occurred
- Parameters
thread
: : the handle of the other thread which will be woken
-
BOOL
rtos_is_current_thread
(beken_thread_t *thread)¶ Checks if a thread is the current thread.
Checks if a specified thread is the currently running thread
- Return
true : specified thread is the current thread
false : specified thread is not currently running
- Parameters
thread
: : the handle of the other thread against which the current thread will be compared
-
beken_thread_t *
rtos_get_current_thread
(void)¶ Get current thread handler.
- Return
Current RTOS thread handler
-
void
rtos_thread_sleep
(uint32_t seconds)¶ Suspend current thread for a specific time.
- Return
None.
- Parameters
seconds
: : A time interval (Unit: seconds)
-
void
rtos_thread_msleep
(uint32_t milliseconds)¶ Suspend current thread for a specific time.
- Return
None.
- Parameters
milliseconds
: : A time interval (Unit: millisecond)
-
OSStatus
rtos_delay_milliseconds
(uint32_t num_ms)¶ Suspend current thread for a specific time.
- Return
kNoErr.
- Parameters
num_ms
: : A time interval (Unit: millisecond)
-
OSStatus
rtos_print_thread_status
(char *buffer, int length)¶ Print Thread status into buffer.
- Return
none
- Parameters
bufferpoint
: to buffer to store thread statuslengthlength
: of the buffer
-
OSStatus
rtos_init_semaphore
(beken_semaphore_t *semaphore, int maxCount)¶ Initialises a counting semaphore and set count to 0.
- Return
kNoErr : on success. kGeneralErr : if an error occurred
- Parameters
semaphore
: : a pointer to the semaphore handle to be initialisedmaxCount
: : the max count number of this semaphore
-
OSStatus
rtos_init_semaphore_adv
(beken_semaphore_t *semaphore, int maxCount, int init_count)¶ Initialises a counting semaphore and set count to init count.
- Return
kNoErr : on success. kGeneralErr : if an error occurred
- Parameters
semaphore
: : a pointer to the semaphore handle to be initialisedmaxCount
: : the max count number of this semaphoreinit_count
: : the init count number of this semaphore
-
OSStatus
rtos_set_semaphore
(beken_semaphore_t *semaphore)¶ Set (post/put/increment) a semaphore.
- Return
kNoErr : on success. kGeneralErr : if an error occurred
- Parameters
semaphore
: : a pointer to the semaphore handle to be set
-
OSStatus
rtos_get_semaphore
(beken_semaphore_t *semaphore, uint32_t timeout_ms)¶ Get (wait/decrement) a semaphore.
Attempts to get (wait/decrement) a semaphore. If semaphore is at zero already, then the calling thread will be suspended until another thread sets the semaphore with rtos_set_semaphore
- Return
kNoErr : on success. kGeneralErr : if an error occurred
- Parameters
semaphore
: : a pointer to the semaphore handletimeout_ms:
: the number of milliseconds to wait before returning
-
int
rtos_get_sema_count
(beken_semaphore_t *semaphore)¶ Get (wait/decrement) semaphore number.
- Return
the number of semaphore
- Parameters
semaphore
: : a pointer to the semaphore handle
-
OSStatus
rtos_deinit_semaphore
(beken_semaphore_t *semaphore)¶ De-initialise a semaphore.
Deletes a semaphore created with rtos_init_semaphore
- Return
kNoErr : on success.
kGeneralErr : if an error occurred
- Parameters
semaphore
: : a pointer to the semaphore handle
-
OSStatus
rtos_init_mutex
(beken_mutex_t *mutex)¶ Initialises a mutex.
A mutex is different to a semaphore in that a thread that already holds the lock on the mutex can request the lock again (nested) without causing it to be suspended.
- Return
kNoErr : on success.
kGeneralErr : if an error occurred
- Parameters
mutex
: : a pointer to the mutex handle to be initialised
-
OSStatus
rtos_lock_mutex
(beken_mutex_t *mutex)¶ Obtains the lock on a mutex.
Attempts to obtain the lock on a mutex. If the lock is already held by another thead, the calling thread will be suspended until the mutex lock is released by the other thread.
- Return
kNoErr : on success.
kGeneralErr : if an error occurred
- Parameters
mutex
: : a pointer to the mutex handle to be locked
-
OSStatus
rtos_trylock_mutex
(beken_mutex_t *mutex)¶ Obtains the lock on a mutex.
Attempts to obtain the lock on a mutex. If the lock is already held by another thead, the calling thread will not be suspended until the mutex lock is released by the other thread.
- Return
kNoErr : on success.
kGeneralErr : if an error occurred
- Parameters
mutex
: : a pointer to the mutex handle to be locked
-
OSStatus
rtos_unlock_mutex
(beken_mutex_t *mutex)¶ Releases the lock on a mutex.
Releases a currently held lock on a mutex. If another thread is waiting on the mutex lock, then it will be resumed.
- Return
kNoErr : on success.
kGeneralErr : if an error occurred
- Parameters
mutex
: : a pointer to the mutex handle to be unlocked
-
OSStatus
rtos_deinit_mutex
(beken_mutex_t *mutex)¶ De-initialise a mutex.
Deletes a mutex created with rtos_init_mutex
- Return
kNoErr : on success.
kGeneralErr : if an error occurred
- Parameters
mutex
: : a pointer to the mutex handle
-
OSStatus
rtos_init_recursive_mutex
(beken_mutex_t *mutex)¶ Initialises a recursive mutex.
A mutex is different to a semaphore in that a thread that already holds the lock on the mutex can request the lock again (nested) without causing it to be suspended.
- Return
kNoErr : on success.
kGeneralErr : if an error occurred
- Parameters
mutex
: : a pointer to the mutex handle to be initialised
-
OSStatus
rtos_lock_recursive_mutex
(beken_mutex_t *mutex, uint32_t timeout)¶ Obtains the lock on a recursive mutex.
Attempts to obtain the lock on a mutex. If the lock is already held by another thead, the calling thread will be suspended until the mutex lock is released by the other thread.
- Return
kNoErr : on success.
kGeneralErr : if an error occurred
- Parameters
mutex
: : a pointer to the mutex handle to be lockedtimeout: timeout for wait mutex
-
OSStatus
rtos_unlock_recursive_mutex
(beken_mutex_t *mutex)¶ Releases the lock on a recursive mutex.
Releases a currently held lock on a mutex. If another thread is waiting on the mutex lock, then it will be resumed.
- Return
kNoErr : on success.
kGeneralErr : if an error occurred
- Parameters
mutex
: : a pointer to the mutex handle to be unlocked
-
OSStatus
rtos_init_queue
(beken_queue_t *queue, const char *name, uint32_t message_size, uint32_t number_of_messages)¶ Initialises a FIFO queue.
- Return
kNoErr : on success.
kGeneralErr : if an error occurred
- Parameters
queue
: : a pointer to the queue handle to be initialisedname
: : a text string name for the queue (NULL is allowed)message_size
: : size in bytes of objects that will be held in the queuenumber_of_messages
: : depth of the queue - i.e. max number of objects in the queue
-
OSStatus
rtos_push_to_queue
(beken_queue_t *queue, void *message, uint32_t timeout_ms)¶ Pushes an object onto a queue (to the back)
- Return
kNoErr : on success.
kGeneralErr : if an error or timeout occurred
- Parameters
queue
: : a pointer to the queue handlemessage
: : the object to be added to the queue. Size is assumed to be the size specified in rtos_init_queuetimeout_ms:
: the number of milliseconds to wait before returning
-
OSStatus
rtos_push_to_queue_front
(beken_queue_t *queue, void *message, uint32_t timeout_ms)¶ Pushes an object to front of the queue.
- Return
kNoErr : on success.
kGeneralErr : if an error or timeout occurred
- Parameters
queue
: : a pointer to the queue handlemessage
: : the object to be added to the queue. Size is assumed to be the size specified in rtos_init_queuetimeout_ms:
: the number of milliseconds to wait before returning
-
OSStatus
rtos_pop_from_queue
(beken_queue_t *queue, void *message, uint32_t timeout_ms)¶ Pops an object off a queue.
- Return
kNoErr : on success.
kGeneralErr : if an error or timeout occurred
- Parameters
queue
: : a pointer to the queue handlemessage
: : pointer to a buffer that will receive the object being popped off the queue. Size is assumed to be the size specified in rtos_init_queue , hence you must ensure the buffer is long enough or memory corruption will resulttimeout_ms:
: the number of milliseconds to wait before returning
-
OSStatus
rtos_deinit_queue
(beken_queue_t *queue)¶ De-initialise a queue created with rtos_init_queue.
- Return
kNoErr : on success.
kGeneralErr : if an error occurred
- Parameters
queue
: : a pointer to the queue handle
-
BOOL
rtos_is_queue_empty
(beken_queue_t *queue)¶ Check if a queue is empty.
- Return
true : queue is empty.
false : queue is not empty.
- Parameters
queue
: : a pointer to the queue handle
-
BOOL
rtos_is_queue_full
(beken_queue_t *queue)¶ Check if a queue is full.
- Return
true : queue is empty.
false : queue is not empty.
- Parameters
queue
: : a pointer to the queue handle
-
uint32_t
rtos_get_time
(void)¶ Gets time in miiliseconds since RTOS start.
- Attention
: Since this is only 32 bits, it will roll over every 49 days, 17 hours.
- Return
Time in milliseconds since RTOS started.
-
uint64_t
rtos_get_time_us
(void)¶ Gets time in microsecond since RTOS start.
- Attention
: Since this is only 32 bits, it will roll over every 49 days, 17 hours.
- Return
Time in milliseconds since RTOS started.
-
OSStatus
rtos_init_oneshot_timer
(beken2_timer_t *timer, uint32_t time_ms, timer_2handler_t function, void *larg, void *rarg)¶ Deinitialization a RTOS oneshot timer.
- Attention
Timer does not start running until beken_start_timer is called
- Return
kNoErr : on success.
kGeneralErr : if an error occurred
- Parameters
timer
: : a pointer to the timer handle to be initialisedtime_ms
: : Timer period in millisecondsfunction
: : the callback handler function that is called each time the timer expireslarg
: : an argument that will be passed to the callback functionrarg
: : an argument that will be passed to the callback function
-
OSStatus
rtos_deinit_oneshot_timer
(beken2_timer_t *timer)¶ De-initialise a RTOS oneshot timer.
- Return
kNoErr : on success.
kGeneralErr : if an error occurred
- Parameters
timer
: : a pointer to the timer handle to be initialised
-
OSStatus
rtos_deinit_oneshot_timer_block
(beken2_timer_t *timer)¶ De-initialise a RTOS timer with block way.
- Return
kNoErr : on success.
kGeneralErr : if an error occurred
- Parameters
timer
: : a pointer to the timer handle to be initialised
-
OSStatus
rtos_stop_oneshot_timer
(beken2_timer_t *timer)¶ stop a RTOS oneshot timer
- Return
kNoErr : on success.
kGeneralErr : if an error occurred
- Parameters
timer
: : a pointer to the timer handle to be initialised
-
BOOL
rtos_is_oneshot_timer_running
(beken2_timer_t *timer)¶ whether oneshot_timer is running
- Return
kNoErr : on success.
kGeneralErr : if an error occurred
- Parameters
timer
: : a pointer to the timer handle to be initialised
-
OSStatus
rtos_start_oneshot_timer
(beken2_timer_t *timer)¶ start a RTOS oneshot timer
- Return
kNoErr : on success.
kGeneralErr : if an error occurred
- Parameters
timer
: : a pointer to the timer handle to be initialised
-
BOOL
rtos_is_oneshot_timer_init
(beken2_timer_t *timer)¶ whether oneshot_timer is inited
- Return
kNoErr : on success.
kGeneralErr : if an error occurred
- Parameters
timer
: : a pointer to the timer handle to be initialised
-
OSStatus
rtos_oneshot_reload_timer
(beken2_timer_t *timer)¶ Reloads oneshot_timer is inited that has expired.
- Return
kNoErr : on success.
kGeneralErr : if an error occurred
- Parameters
timer
: : a pointer to the timer handle to be initialised
-
OSStatus
rtos_change_period_1
(beken2_timer_t *timer, uint32_t time_ms)¶ change timeout for a RTOS oneshot timer that has expired
- Return
kNoErr : on success.
kGeneralErr : if an error occurred
- Parameters
timer
: : a pointer to the timer handle to be initialised
-
OSStatus
rtos_init_timer
(beken_timer_t *timer, uint32_t time_ms, timer_handler_t function, void *arg)¶ Initialize a RTOS timer.
- Attention
Timer does not start running until beken_start_timer is called
- Return
kNoErr : on success.
kGeneralErr : if an error occurred
- Parameters
timer
: : a pointer to the timer handle to be initialisedtime_ms
: : Timer period in millisecondsfunction
: : the callback handler function that is called each time the timer expiresarg
: : an argument that will be passed to the callback function
-
OSStatus
rtos_start_timer
(beken_timer_t *timer)¶ Starts a RTOS timer running.
- Attention
Timer must have been previously initialised with rtos_init_timer
- Return
kNoErr : on success.
kGeneralErr : if an error occurred
- Parameters
timer
: : a pointer to the timer handle to start
-
OSStatus
rtos_change_period
(beken_timer_t *timer, uint32_t time_ms)¶ change timeout for a RTOS oneshot timer that has expired
- Return
kNoErr : on success.
kGeneralErr : if an error occurred
- Parameters
timer
: : a pointer to the timer handle to be initialised
-
OSStatus
rtos_stop_timer
(beken_timer_t *timer)¶ Stops a running RTOS timer.
- Attention
Timer must have been previously started with rtos_init_timer
- Return
kNoErr : on success.
kGeneralErr : if an error occurred
- Parameters
timer
: : a pointer to the timer handle to stop
-
OSStatus
rtos_reload_timer
(beken_timer_t *timer)¶ Reloads a RTOS timer that has expired.
- Attention
This is usually called in the timer callback handler, to reschedule the timer for the next period.
- Return
kNoErr : on success.
kGeneralErr : if an error occurred
- Parameters
timer
: : a pointer to the timer handle to reload
-
OSStatus
rtos_deinit_timer
(beken_timer_t *timer)¶ De-initialise a RTOS timer.
- Attention
Deletes a RTOS timer created with rtos_init_timer
- Return
kNoErr : on success.
kGeneralErr : if an error occurred
- Parameters
timer
: : a pointer to the RTOS timer handle
-
OSStatus
rtos_deinit_timer_block
(beken_timer_t *timer)¶ De-initialise a RTOS timer with black way.
- Attention
Deletes a RTOS timer created with rtos_init_timer
- Return
kNoErr : on success.
kGeneralErr : if an error occurred
- Parameters
timer
: : a pointer to the RTOS timer handle
-
BOOL
rtos_is_timer_init
(beken_timer_t *timer)¶ Check if an RTOS timer is running.
- Return
true : if running.
false : if not running
- Parameters
timer
: : a pointer to the RTOS timer handle
-
BOOL
rtos_is_timer_running
(beken_timer_t *timer)¶ whether oneshot_timer is running
- Return
kNoErr : on success.
kGeneralErr : if an error occurred
- Parameters
timer
: : a pointer to the timer handle to be initialised