kernel/timeout: Make timeout arguments an opaque type
Add a k_timeout_t type, and use it everywhere that kernel API functions were accepting a millisecond timeout argument. Instead of forcing milliseconds everywhere (which are often not integrally representable as system ticks), do the conversion to ticks at the point where the timeout is created. This avoids an extra unit conversion in some application code, and allows us to express the timeout in units other than milliseconds to achieve greater precision. The existing K_MSEC() et. al. macros now return initializers for a k_timeout_t. The K_NO_WAIT and K_FOREVER constants have now become k_timeout_t values, which means they cannot be operated on as integers. Applications which have their own APIs that need to inspect these vs. user-provided timeouts can now use a K_TIMEOUT_EQ() predicate to test for equality. Timer drivers, which receive an integer tick count in ther z_clock_set_timeout() functions, now use the integer-valued K_TICKS_FOREVER constant instead of K_FOREVER. For the initial release, to preserve source compatibility, a CONFIG_LEGACY_TIMEOUT_API kconfig is provided. When true, the k_timeout_t will remain a compatible 32 bit value that will work with any legacy Zephyr application. Some subsystems present timeout (or timeout-like) values to their own users as APIs that would re-use the kernel's own constants and conventions. These will require some minor design work to adapt to the new scheme (in most cases just using k_timeout_t directly in their own API), and they have not been changed in this patch, instead selecting CONFIG_LEGACY_TIMEOUT_API via kconfig. These subsystems include: CAN Bus, the Microbit display driver, I2S, LoRa modem drivers, the UART Async API, Video hardware drivers, the console subsystem, and the network buffer abstraction. k_sleep() now takes a k_timeout_t argument, with a k_msleep() variant provided that works identically to the original API. Most of the changes here are just type/configuration management and documentation, but there are logic changes in mempool, where a loop that used a timeout numerically has been reworked using a new z_timeout_end_calc() predicate. Also in queue.c, a (when POLL was enabled) a similar loop was needlessly used to try to retry the k_poll() call after a spurious failure. But k_poll() does not fail spuriously, so the loop was removed. Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
This commit is contained in:
parent
32bb2395c2
commit
7832738ae9
66 changed files with 440 additions and 277 deletions
|
@ -59,7 +59,7 @@ extern int z_clock_device_ctrl(struct device *device, u32_t ctrl_command,
|
|||
* treated identically: it simply indicates the kernel would like the
|
||||
* next tick announcement as soon as possible.
|
||||
*
|
||||
* Note that ticks can also be passed the special value K_FOREVER,
|
||||
* Note that ticks can also be passed the special value K_TICKS_FOREVER,
|
||||
* indicating that no future timer interrupts are expected or required
|
||||
* and that the system is permitted to enter an indefinite sleep even
|
||||
* if this could cause rollover of the internal counter (i.e. the
|
||||
|
|
159
include/kernel.h
159
include/kernel.h
|
@ -810,7 +810,7 @@ extern void k_thread_foreach_unlocked(
|
|||
* @param p3 3rd entry point parameter.
|
||||
* @param prio Thread priority.
|
||||
* @param options Thread options.
|
||||
* @param delay Scheduling delay (in milliseconds), or K_NO_WAIT (for no delay).
|
||||
* @param delay Scheduling delay, or K_NO_WAIT (for no delay).
|
||||
*
|
||||
* @return ID of new thread.
|
||||
*
|
||||
|
@ -821,7 +821,7 @@ __syscall k_tid_t k_thread_create(struct k_thread *new_thread,
|
|||
size_t stack_size,
|
||||
k_thread_entry_t entry,
|
||||
void *p1, void *p2, void *p3,
|
||||
int prio, u32_t options, s32_t delay);
|
||||
int prio, u32_t options, k_timeout_t delay);
|
||||
|
||||
/**
|
||||
* @brief Drop a thread's privileges permanently to user mode
|
||||
|
@ -926,15 +926,27 @@ void k_thread_system_pool_assign(struct k_thread *thread);
|
|||
* This API may only be called from ISRs with a K_NO_WAIT timeout.
|
||||
*
|
||||
* @param thread Thread to wait to exit
|
||||
* @param timeout non-negative upper bound time in ms to wait for the thread
|
||||
* to exit.
|
||||
* @param timeout upper bound time to wait for the thread to exit.
|
||||
* @retval 0 success, target thread has exited or wasn't running
|
||||
* @retval -EBUSY returned without waiting
|
||||
* @retval -EAGAIN waiting period timed out
|
||||
* @retval -EDEADLK target thread is joining on the caller, or target thread
|
||||
* is the caller
|
||||
*/
|
||||
__syscall int k_thread_join(struct k_thread *thread, s32_t timeout);
|
||||
__syscall int k_thread_join(struct k_thread *thread, k_timeout_t timeout);
|
||||
|
||||
/**
|
||||
* @brief Put the current thread to sleep.
|
||||
*
|
||||
* This routine puts the current thread to sleep for @a duration,
|
||||
* specified as a k_timeout_t object.
|
||||
*
|
||||
* @param timeout Desired duration of sleep.
|
||||
*
|
||||
* @return Zero if the requested time has elapsed or the number of milliseconds
|
||||
* left to sleep, if thread was woken up by \ref k_wakeup call.
|
||||
*/
|
||||
__syscall s32_t k_sleep(k_timeout_t timeout);
|
||||
|
||||
/**
|
||||
* @brief Put the current thread to sleep.
|
||||
|
@ -946,7 +958,10 @@ __syscall int k_thread_join(struct k_thread *thread, s32_t timeout);
|
|||
* @return Zero if the requested time has elapsed or the number of milliseconds
|
||||
* left to sleep, if thread was woken up by \ref k_wakeup call.
|
||||
*/
|
||||
__syscall s32_t k_sleep(s32_t ms);
|
||||
static inline s32_t k_msleep(s32_t ms)
|
||||
{
|
||||
return k_sleep(Z_TIMEOUT_MS(ms));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Put the current thread to sleep with microsecond resolution.
|
||||
|
@ -1531,7 +1546,7 @@ const char *k_thread_state_str(k_tid_t thread_id);
|
|||
*
|
||||
* @return Timeout delay value.
|
||||
*/
|
||||
#define K_NO_WAIT 0
|
||||
#define K_NO_WAIT Z_TIMEOUT_NO_WAIT
|
||||
|
||||
/**
|
||||
* @brief Generate timeout delay from milliseconds.
|
||||
|
@ -1543,7 +1558,7 @@ const char *k_thread_state_str(k_tid_t thread_id);
|
|||
*
|
||||
* @return Timeout delay value.
|
||||
*/
|
||||
#define K_MSEC(ms) (ms)
|
||||
#define K_MSEC(ms) Z_TIMEOUT_MS(ms)
|
||||
|
||||
/**
|
||||
* @brief Generate timeout delay from seconds.
|
||||
|
@ -1589,7 +1604,7 @@ const char *k_thread_state_str(k_tid_t thread_id);
|
|||
*
|
||||
* @return Timeout delay value.
|
||||
*/
|
||||
#define K_FOREVER (-1)
|
||||
#define K_FOREVER Z_FOREVER
|
||||
|
||||
/**
|
||||
* @}
|
||||
|
@ -1617,7 +1632,7 @@ struct k_timer {
|
|||
void (*stop_fn)(struct k_timer *timer);
|
||||
|
||||
/* timer period */
|
||||
s32_t period;
|
||||
k_timeout_t period;
|
||||
|
||||
/* timer status */
|
||||
u32_t status;
|
||||
|
@ -1639,7 +1654,6 @@ struct k_timer {
|
|||
.wait_q = Z_WAIT_Q_INIT(&obj.wait_q), \
|
||||
.expiry_fn = expiry, \
|
||||
.stop_fn = stop, \
|
||||
.period = 0, \
|
||||
.status = 0, \
|
||||
.user_data = 0, \
|
||||
_OBJECT_TRACING_INIT \
|
||||
|
@ -1727,13 +1741,13 @@ extern void k_timer_init(struct k_timer *timer,
|
|||
* using the new duration and period values.
|
||||
*
|
||||
* @param timer Address of timer.
|
||||
* @param duration Initial timer duration (in milliseconds).
|
||||
* @param period Timer period (in milliseconds).
|
||||
* @param duration Initial timer duration.
|
||||
* @param period Timer period.
|
||||
*
|
||||
* @return N/A
|
||||
*/
|
||||
__syscall void k_timer_start(struct k_timer *timer,
|
||||
s32_t duration, s32_t period);
|
||||
k_timeout_t duration, k_timeout_t period);
|
||||
|
||||
/**
|
||||
* @brief Stop a timer.
|
||||
|
@ -2189,14 +2203,14 @@ extern int k_queue_merge_slist(struct k_queue *queue, sys_slist_t *list);
|
|||
* @note Can be called by ISRs, but @a timeout must be set to K_NO_WAIT.
|
||||
*
|
||||
* @param queue Address of the queue.
|
||||
* @param timeout Non-negative waiting period to obtain a data item (in
|
||||
* milliseconds), or one of the special values K_NO_WAIT and
|
||||
* @param timeout Non-negative waiting period to obtain a data item
|
||||
* or one of the special values K_NO_WAIT and
|
||||
* K_FOREVER.
|
||||
*
|
||||
* @return Address of the data item if successful; NULL if returned
|
||||
* without waiting, or waiting period timed out.
|
||||
*/
|
||||
__syscall void *k_queue_get(struct k_queue *queue, s32_t timeout);
|
||||
__syscall void *k_queue_get(struct k_queue *queue, k_timeout_t timeout);
|
||||
|
||||
/**
|
||||
* @brief Remove an element from a queue.
|
||||
|
@ -2358,7 +2372,7 @@ struct z_futex_data {
|
|||
* @param futex Address of the futex.
|
||||
* @param expected Expected value of the futex, if it is different the caller
|
||||
* will not wait on it.
|
||||
* @param timeout Non-negative waiting period on the futex, in milliseconds, or
|
||||
* @param timeout Non-negative waiting period on the futex, or
|
||||
* one of the special values K_NO_WAIT or K_FOREVER.
|
||||
* @retval -EACCES Caller does not have read access to futex address.
|
||||
* @retval -EAGAIN If the futex value did not match the expected parameter.
|
||||
|
@ -2368,7 +2382,8 @@ struct z_futex_data {
|
|||
* should check the futex's value on wakeup to determine if it needs
|
||||
* to block again.
|
||||
*/
|
||||
__syscall int k_futex_wait(struct k_futex *futex, int expected, s32_t timeout);
|
||||
__syscall int k_futex_wait(struct k_futex *futex, int expected,
|
||||
k_timeout_t timeout);
|
||||
|
||||
/**
|
||||
* @brief Wake one/all threads pending on a futex
|
||||
|
@ -2529,7 +2544,7 @@ struct k_fifo {
|
|||
* @note Can be called by ISRs, but @a timeout must be set to K_NO_WAIT.
|
||||
*
|
||||
* @param fifo Address of the FIFO queue.
|
||||
* @param timeout Waiting period to obtain a data item (in milliseconds),
|
||||
* @param timeout Waiting period to obtain a data item,
|
||||
* or one of the special values K_NO_WAIT and K_FOREVER.
|
||||
*
|
||||
* @return Address of the data item if successful; NULL if returned
|
||||
|
@ -2689,7 +2704,7 @@ struct k_lifo {
|
|||
* @note Can be called by ISRs, but @a timeout must be set to K_NO_WAIT.
|
||||
*
|
||||
* @param lifo Address of the LIFO queue.
|
||||
* @param timeout Waiting period to obtain a data item (in milliseconds),
|
||||
* @param timeout Waiting period to obtain a data item,
|
||||
* or one of the special values K_NO_WAIT and K_FOREVER.
|
||||
*
|
||||
* @return Address of the data item if successful; NULL if returned
|
||||
|
@ -2827,8 +2842,8 @@ __syscall int k_stack_push(struct k_stack *stack, stack_data_t data);
|
|||
*
|
||||
* @param stack Address of the stack.
|
||||
* @param data Address of area to hold the value popped from the stack.
|
||||
* @param timeout Non-negative waiting period to obtain a value (in
|
||||
* milliseconds), or one of the special values K_NO_WAIT and
|
||||
* @param timeout Waiting period to obtain a value,
|
||||
* or one of the special values K_NO_WAIT and
|
||||
* K_FOREVER.
|
||||
*
|
||||
* @retval 0 Element popped from stack.
|
||||
|
@ -2837,7 +2852,7 @@ __syscall int k_stack_push(struct k_stack *stack, stack_data_t data);
|
|||
* @req K-STACK-001
|
||||
*/
|
||||
__syscall int k_stack_pop(struct k_stack *stack, stack_data_t *data,
|
||||
s32_t timeout);
|
||||
k_timeout_t timeout);
|
||||
|
||||
/**
|
||||
* @brief Statically define and initialize a stack
|
||||
|
@ -3142,8 +3157,7 @@ extern void k_delayed_work_init(struct k_delayed_work *work,
|
|||
*
|
||||
* @param work_q Address of workqueue.
|
||||
* @param work Address of delayed work item.
|
||||
* @param delay Non-negative delay before submitting the work item (in
|
||||
* milliseconds).
|
||||
* @param delay Delay before submitting the work item
|
||||
*
|
||||
* @retval 0 Work item countdown started.
|
||||
* @retval -EINVAL Work item is being processed or has completed its work.
|
||||
|
@ -3152,7 +3166,7 @@ extern void k_delayed_work_init(struct k_delayed_work *work,
|
|||
*/
|
||||
extern int k_delayed_work_submit_to_queue(struct k_work_q *work_q,
|
||||
struct k_delayed_work *work,
|
||||
s32_t delay);
|
||||
k_timeout_t delay);
|
||||
|
||||
/**
|
||||
* @brief Cancel a delayed work item.
|
||||
|
@ -3228,8 +3242,7 @@ static inline void k_work_submit(struct k_work *work)
|
|||
* @note Can be called by ISRs.
|
||||
*
|
||||
* @param work Address of delayed work item.
|
||||
* @param delay Non-negative delay before submitting the work item (in
|
||||
* milliseconds).
|
||||
* @param delay Delay before submitting the work item
|
||||
*
|
||||
* @retval 0 Work item countdown started.
|
||||
* @retval -EINVAL Work item is being processed or has completed its work.
|
||||
|
@ -3237,7 +3250,7 @@ static inline void k_work_submit(struct k_work *work)
|
|||
* @req K-DWORK-001
|
||||
*/
|
||||
static inline int k_delayed_work_submit(struct k_delayed_work *work,
|
||||
s32_t delay)
|
||||
k_timeout_t delay)
|
||||
{
|
||||
return k_delayed_work_submit_to_queue(&k_sys_work_q, work, delay);
|
||||
}
|
||||
|
@ -3299,7 +3312,7 @@ extern void k_work_poll_init(struct k_work_poll *work,
|
|||
* @param work Address of delayed work item.
|
||||
* @param events An array of pointers to events which trigger the work.
|
||||
* @param num_events The number of events in the array.
|
||||
* @param timeout Non-negative timeout after which the work will be scheduled
|
||||
* @param timeout Timeout after which the work will be scheduled
|
||||
* for execution even if not triggered.
|
||||
*
|
||||
*
|
||||
|
@ -3311,7 +3324,7 @@ extern int k_work_poll_submit_to_queue(struct k_work_q *work_q,
|
|||
struct k_work_poll *work,
|
||||
struct k_poll_event *events,
|
||||
int num_events,
|
||||
s32_t timeout);
|
||||
k_timeout_t timeout);
|
||||
|
||||
/**
|
||||
* @brief Submit a triggered work item to the system workqueue.
|
||||
|
@ -3337,7 +3350,7 @@ extern int k_work_poll_submit_to_queue(struct k_work_q *work_q,
|
|||
* @param work Address of delayed work item.
|
||||
* @param events An array of pointers to events which trigger the work.
|
||||
* @param num_events The number of events in the array.
|
||||
* @param timeout Non-negative timeout after which the work will be scheduled
|
||||
* @param timeout Timeout after which the work will be scheduled
|
||||
* for execution even if not triggered.
|
||||
*
|
||||
* @retval 0 Work item started watching for events.
|
||||
|
@ -3347,7 +3360,7 @@ extern int k_work_poll_submit_to_queue(struct k_work_q *work_q,
|
|||
static inline int k_work_poll_submit(struct k_work_poll *work,
|
||||
struct k_poll_event *events,
|
||||
int num_events,
|
||||
s32_t timeout)
|
||||
k_timeout_t timeout)
|
||||
{
|
||||
return k_work_poll_submit_to_queue(&k_sys_work_q, work,
|
||||
events, num_events, timeout);
|
||||
|
@ -3455,8 +3468,8 @@ __syscall int k_mutex_init(struct k_mutex *mutex);
|
|||
* completes immediately and the lock count is increased by 1.
|
||||
*
|
||||
* @param mutex Address of the mutex.
|
||||
* @param timeout Non-negative waiting period to lock the mutex (in
|
||||
* milliseconds), or one of the special values K_NO_WAIT and
|
||||
* @param timeout Waiting period to lock the mutex,
|
||||
* or one of the special values K_NO_WAIT and
|
||||
* K_FOREVER.
|
||||
*
|
||||
* @retval 0 Mutex locked.
|
||||
|
@ -3464,7 +3477,7 @@ __syscall int k_mutex_init(struct k_mutex *mutex);
|
|||
* @retval -EAGAIN Waiting period timed out.
|
||||
* @req K-MUTEX-002
|
||||
*/
|
||||
__syscall int k_mutex_lock(struct k_mutex *mutex, s32_t timeout);
|
||||
__syscall int k_mutex_lock(struct k_mutex *mutex, k_timeout_t timeout);
|
||||
|
||||
/**
|
||||
* @brief Unlock a mutex.
|
||||
|
@ -3550,16 +3563,15 @@ __syscall int k_sem_init(struct k_sem *sem, unsigned int initial_count,
|
|||
* @note Can be called by ISRs, but @a timeout must be set to K_NO_WAIT.
|
||||
*
|
||||
* @param sem Address of the semaphore.
|
||||
* @param timeout Non-negative waiting period to take the semaphore (in
|
||||
* milliseconds), or one of the special values K_NO_WAIT and
|
||||
* K_FOREVER.
|
||||
* @param timeout Waiting period to take the semaphore,
|
||||
* or one of the special values K_NO_WAIT and K_FOREVER.
|
||||
*
|
||||
* @retval 0 Semaphore taken.
|
||||
* @retval -EBUSY Returned without waiting.
|
||||
* @retval -EAGAIN Waiting period timed out.
|
||||
* @req K-SEM-001
|
||||
*/
|
||||
__syscall int k_sem_take(struct k_sem *sem, s32_t timeout);
|
||||
__syscall int k_sem_take(struct k_sem *sem, k_timeout_t timeout);
|
||||
|
||||
/**
|
||||
* @brief Give a semaphore.
|
||||
|
@ -3803,8 +3815,8 @@ int k_msgq_cleanup(struct k_msgq *msgq);
|
|||
*
|
||||
* @param msgq Address of the message queue.
|
||||
* @param data Pointer to the message.
|
||||
* @param timeout Non-negative waiting period to add the message (in
|
||||
* milliseconds), or one of the special values K_NO_WAIT and
|
||||
* @param timeout Non-negative waiting period to add the message,
|
||||
* or one of the special values K_NO_WAIT and
|
||||
* K_FOREVER.
|
||||
*
|
||||
* @retval 0 Message sent.
|
||||
|
@ -3812,7 +3824,7 @@ int k_msgq_cleanup(struct k_msgq *msgq);
|
|||
* @retval -EAGAIN Waiting period timed out.
|
||||
* @req K-MSGQ-002
|
||||
*/
|
||||
__syscall int k_msgq_put(struct k_msgq *msgq, void *data, s32_t timeout);
|
||||
__syscall int k_msgq_put(struct k_msgq *msgq, void *data, k_timeout_t timeout);
|
||||
|
||||
/**
|
||||
* @brief Receive a message from a message queue.
|
||||
|
@ -3824,8 +3836,8 @@ __syscall int k_msgq_put(struct k_msgq *msgq, void *data, s32_t timeout);
|
|||
*
|
||||
* @param msgq Address of the message queue.
|
||||
* @param data Address of area to hold the received message.
|
||||
* @param timeout Non-negative waiting period to receive the message (in
|
||||
* milliseconds), or one of the special values K_NO_WAIT and
|
||||
* @param timeout Waiting period to receive the message,
|
||||
* or one of the special values K_NO_WAIT and
|
||||
* K_FOREVER.
|
||||
*
|
||||
* @retval 0 Message received.
|
||||
|
@ -3833,7 +3845,7 @@ __syscall int k_msgq_put(struct k_msgq *msgq, void *data, s32_t timeout);
|
|||
* @retval -EAGAIN Waiting period timed out.
|
||||
* @req K-MSGQ-002
|
||||
*/
|
||||
__syscall int k_msgq_get(struct k_msgq *msgq, void *data, s32_t timeout);
|
||||
__syscall int k_msgq_get(struct k_msgq *msgq, void *data, k_timeout_t timeout);
|
||||
|
||||
/**
|
||||
* @brief Peek/read a message from a message queue.
|
||||
|
@ -4042,8 +4054,8 @@ extern void k_mbox_init(struct k_mbox *mbox);
|
|||
*
|
||||
* @param mbox Address of the mailbox.
|
||||
* @param tx_msg Address of the transmit message descriptor.
|
||||
* @param timeout Non-negative waiting period for the message to be received (in
|
||||
* milliseconds), or one of the special values K_NO_WAIT
|
||||
* @param timeout Waiting period for the message to be received,
|
||||
* or one of the special values K_NO_WAIT
|
||||
* and K_FOREVER. Once the message has been received,
|
||||
* this routine waits as long as necessary for the message
|
||||
* to be completely processed.
|
||||
|
@ -4054,7 +4066,7 @@ extern void k_mbox_init(struct k_mbox *mbox);
|
|||
* @req K-MBOX-002
|
||||
*/
|
||||
extern int k_mbox_put(struct k_mbox *mbox, struct k_mbox_msg *tx_msg,
|
||||
s32_t timeout);
|
||||
k_timeout_t timeout);
|
||||
|
||||
/**
|
||||
* @brief Send a mailbox message in an asynchronous manner.
|
||||
|
@ -4085,9 +4097,8 @@ extern void k_mbox_async_put(struct k_mbox *mbox, struct k_mbox_msg *tx_msg,
|
|||
* @param rx_msg Address of the receive message descriptor.
|
||||
* @param buffer Address of the buffer to receive data, or NULL to defer data
|
||||
* retrieval and message disposal until later.
|
||||
* @param timeout Non-negative waiting period for a message to be received (in
|
||||
* milliseconds), or one of the special values K_NO_WAIT
|
||||
* and K_FOREVER.
|
||||
* @param timeout Waiting period for a message to be received,
|
||||
* or one of the special values K_NO_WAIT and K_FOREVER.
|
||||
*
|
||||
* @retval 0 Message received.
|
||||
* @retval -ENOMSG Returned without waiting.
|
||||
|
@ -4095,7 +4106,7 @@ extern void k_mbox_async_put(struct k_mbox *mbox, struct k_mbox_msg *tx_msg,
|
|||
* @req K-MBOX-002
|
||||
*/
|
||||
extern int k_mbox_get(struct k_mbox *mbox, struct k_mbox_msg *rx_msg,
|
||||
void *buffer, s32_t timeout);
|
||||
void *buffer, k_timeout_t timeout);
|
||||
|
||||
/**
|
||||
* @brief Retrieve mailbox message data into a buffer.
|
||||
|
@ -4137,8 +4148,8 @@ extern void k_mbox_data_get(struct k_mbox_msg *rx_msg, void *buffer);
|
|||
* @param rx_msg Address of a receive message descriptor.
|
||||
* @param pool Address of memory pool, or NULL to discard data.
|
||||
* @param block Address of the area to hold memory pool block info.
|
||||
* @param timeout Non-negative waiting period to wait for a memory pool block
|
||||
* (in milliseconds), or one of the special values K_NO_WAIT
|
||||
* @param timeout Time to wait for a memory pool block,
|
||||
* or one of the special values K_NO_WAIT
|
||||
* and K_FOREVER.
|
||||
*
|
||||
* @retval 0 Data retrieved.
|
||||
|
@ -4148,7 +4159,8 @@ extern void k_mbox_data_get(struct k_mbox_msg *rx_msg, void *buffer);
|
|||
*/
|
||||
extern int k_mbox_data_block_get(struct k_mbox_msg *rx_msg,
|
||||
struct k_mem_pool *pool,
|
||||
struct k_mem_block *block, s32_t timeout);
|
||||
struct k_mem_block *block,
|
||||
k_timeout_t timeout);
|
||||
|
||||
/** @} */
|
||||
|
||||
|
@ -4282,9 +4294,8 @@ __syscall int k_pipe_alloc_init(struct k_pipe *pipe, size_t size);
|
|||
* @param bytes_to_write Size of data (in bytes).
|
||||
* @param bytes_written Address of area to hold the number of bytes written.
|
||||
* @param min_xfer Minimum number of bytes to write.
|
||||
* @param timeout Non-negative waiting period to wait for the data to be written
|
||||
* (in milliseconds), or one of the special values K_NO_WAIT
|
||||
* and K_FOREVER.
|
||||
* @param timeout Waiting period to wait for the data to be written,
|
||||
* or one of the special values K_NO_WAIT and K_FOREVER.
|
||||
*
|
||||
* @retval 0 At least @a min_xfer bytes of data were written.
|
||||
* @retval -EIO Returned without waiting; zero data bytes were written.
|
||||
|
@ -4294,7 +4305,7 @@ __syscall int k_pipe_alloc_init(struct k_pipe *pipe, size_t size);
|
|||
*/
|
||||
__syscall int k_pipe_put(struct k_pipe *pipe, void *data,
|
||||
size_t bytes_to_write, size_t *bytes_written,
|
||||
size_t min_xfer, s32_t timeout);
|
||||
size_t min_xfer, k_timeout_t timeout);
|
||||
|
||||
/**
|
||||
* @brief Read data from a pipe.
|
||||
|
@ -4306,9 +4317,8 @@ __syscall int k_pipe_put(struct k_pipe *pipe, void *data,
|
|||
* @param bytes_to_read Maximum number of data bytes to read.
|
||||
* @param bytes_read Address of area to hold the number of bytes read.
|
||||
* @param min_xfer Minimum number of data bytes to read.
|
||||
* @param timeout Non-negative waiting period to wait for the data to be read
|
||||
* (in milliseconds), or one of the special values K_NO_WAIT
|
||||
* and K_FOREVER.
|
||||
* @param timeout Waiting period to wait for the data to be read,
|
||||
* or one of the special values K_NO_WAIT and K_FOREVER.
|
||||
*
|
||||
* @retval 0 At least @a min_xfer bytes of data were read.
|
||||
* @retval -EINVAL invalid parameters supplied
|
||||
|
@ -4319,7 +4329,7 @@ __syscall int k_pipe_put(struct k_pipe *pipe, void *data,
|
|||
*/
|
||||
__syscall int k_pipe_get(struct k_pipe *pipe, void *data,
|
||||
size_t bytes_to_read, size_t *bytes_read,
|
||||
size_t min_xfer, s32_t timeout);
|
||||
size_t min_xfer, k_timeout_t timeout);
|
||||
|
||||
/**
|
||||
* @brief Write memory block to a pipe.
|
||||
|
@ -4441,8 +4451,8 @@ extern int k_mem_slab_init(struct k_mem_slab *slab, void *buffer,
|
|||
*
|
||||
* @param slab Address of the memory slab.
|
||||
* @param mem Pointer to block address area.
|
||||
* @param timeout Non-negative waiting period to wait for operation to complete
|
||||
* (in milliseconds). Use K_NO_WAIT to return without waiting,
|
||||
* @param timeout Non-negative waiting period to wait for operation to complete.
|
||||
* Use K_NO_WAIT to return without waiting,
|
||||
* or K_FOREVER to wait as long as necessary.
|
||||
*
|
||||
* @retval 0 Memory allocated. The block address area pointed at by @a mem
|
||||
|
@ -4453,7 +4463,7 @@ extern int k_mem_slab_init(struct k_mem_slab *slab, void *buffer,
|
|||
* @req K-MSLAB-002
|
||||
*/
|
||||
extern int k_mem_slab_alloc(struct k_mem_slab *slab, void **mem,
|
||||
s32_t timeout);
|
||||
k_timeout_t timeout);
|
||||
|
||||
/**
|
||||
* @brief Free memory allocated from a memory slab.
|
||||
|
@ -4565,8 +4575,8 @@ struct k_mem_pool {
|
|||
* @param pool Address of the memory pool.
|
||||
* @param block Pointer to block descriptor for the allocated memory.
|
||||
* @param size Amount of memory to allocate (in bytes).
|
||||
* @param timeout Non-negative waiting period to wait for operation to complete
|
||||
* (in milliseconds). Use K_NO_WAIT to return without waiting,
|
||||
* @param timeout Waiting period to wait for operation to complete.
|
||||
* Use K_NO_WAIT to return without waiting,
|
||||
* or K_FOREVER to wait as long as necessary.
|
||||
*
|
||||
* @retval 0 Memory allocated. The @a data field of the block descriptor
|
||||
|
@ -4576,7 +4586,7 @@ struct k_mem_pool {
|
|||
* @req K-MPOOL-002
|
||||
*/
|
||||
extern int k_mem_pool_alloc(struct k_mem_pool *pool, struct k_mem_block *block,
|
||||
size_t size, s32_t timeout);
|
||||
size_t size, k_timeout_t timeout);
|
||||
|
||||
/**
|
||||
* @brief Allocate memory from a memory pool with malloc() semantics
|
||||
|
@ -4890,9 +4900,8 @@ extern void k_poll_event_init(struct k_poll_event *event, u32_t type,
|
|||
*
|
||||
* @param events An array of pointers to events to be polled for.
|
||||
* @param num_events The number of events in the array.
|
||||
* @param timeout Non-negative waiting period for an event to be ready (in
|
||||
* milliseconds), or one of the special values K_NO_WAIT and
|
||||
* K_FOREVER.
|
||||
* @param timeout Waiting period for an event to be ready,
|
||||
* or one of the special values K_NO_WAIT and K_FOREVER.
|
||||
*
|
||||
* @retval 0 One or more events are ready.
|
||||
* @retval -EAGAIN Waiting period timed out.
|
||||
|
@ -4907,7 +4916,7 @@ extern void k_poll_event_init(struct k_poll_event *event, u32_t type,
|
|||
*/
|
||||
|
||||
__syscall int k_poll(struct k_poll_event *events, int num_events,
|
||||
s32_t timeout);
|
||||
k_timeout_t timeout);
|
||||
|
||||
/**
|
||||
* @brief Initialize a poll signal object.
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#ifdef CONFIG_USERSPACE
|
||||
#include <sys/atomic.h>
|
||||
#include <zephyr/types.h>
|
||||
#include <sys_clock.h>
|
||||
|
||||
struct sys_mutex {
|
||||
/* Currently unused, but will be used to store state for fast mutexes
|
||||
|
@ -54,7 +55,8 @@ static inline void sys_mutex_init(struct sys_mutex *mutex)
|
|||
*/
|
||||
}
|
||||
|
||||
__syscall int z_sys_mutex_kernel_lock(struct sys_mutex *mutex, s32_t timeout);
|
||||
__syscall int z_sys_mutex_kernel_lock(struct sys_mutex *mutex,
|
||||
k_timeout_t timeout);
|
||||
|
||||
__syscall int z_sys_mutex_kernel_unlock(struct sys_mutex *mutex);
|
||||
|
||||
|
@ -69,7 +71,7 @@ __syscall int z_sys_mutex_kernel_unlock(struct sys_mutex *mutex);
|
|||
* completes immediately and the lock count is increased by 1.
|
||||
*
|
||||
* @param mutex Address of the mutex, which may reside in user memory
|
||||
* @param timeout Waiting period to lock the mutex (in milliseconds),
|
||||
* @param timeout Waiting period to lock the mutex,
|
||||
* or one of the special values K_NO_WAIT and K_FOREVER.
|
||||
*
|
||||
* @retval 0 Mutex locked.
|
||||
|
@ -78,7 +80,7 @@ __syscall int z_sys_mutex_kernel_unlock(struct sys_mutex *mutex);
|
|||
* @retval -EACCESS Caller has no access to provided mutex address
|
||||
* @retval -EINVAL Provided mutex not recognized by the kernel
|
||||
*/
|
||||
static inline int sys_mutex_lock(struct sys_mutex *mutex, s32_t timeout)
|
||||
static inline int sys_mutex_lock(struct sys_mutex *mutex, k_timeout_t timeout)
|
||||
{
|
||||
/* For now, make the syscall unconditionally */
|
||||
return z_sys_mutex_kernel_lock(mutex, timeout);
|
||||
|
@ -126,7 +128,7 @@ static inline void sys_mutex_init(struct sys_mutex *mutex)
|
|||
k_mutex_init(&mutex->kernel_mutex);
|
||||
}
|
||||
|
||||
static inline int sys_mutex_lock(struct sys_mutex *mutex, s32_t timeout)
|
||||
static inline int sys_mutex_lock(struct sys_mutex *mutex, k_timeout_t timeout)
|
||||
{
|
||||
return k_mutex_lock(&mutex->kernel_mutex, timeout);
|
||||
}
|
||||
|
|
|
@ -110,7 +110,7 @@ int sys_sem_give(struct sys_sem *sem);
|
|||
* This routine takes @a sem.
|
||||
*
|
||||
* @param sem Address of the sys_sem.
|
||||
* @param timeout Waiting period to take the sys_sem (in milliseconds),
|
||||
* @param timeout Waiting period to take the sys_sem,
|
||||
* or one of the special values K_NO_WAIT and K_FOREVER.
|
||||
*
|
||||
* @retval 0 sys_sem taken.
|
||||
|
@ -118,7 +118,7 @@ int sys_sem_give(struct sys_sem *sem);
|
|||
* @retval -ETIMEDOUT Waiting period timed out.
|
||||
* @retval -EACCES Caller does not have enough access.
|
||||
*/
|
||||
int sys_sem_take(struct sys_sem *sem, s32_t timeout);
|
||||
int sys_sem_take(struct sys_sem *sem, k_timeout_t timeout);
|
||||
|
||||
/**
|
||||
* @brief Get sys_sem's value
|
||||
|
|
|
@ -28,6 +28,59 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @addtogroup clock_apis
|
||||
* @{
|
||||
*/
|
||||
|
||||
typedef u32_t k_ticks_t;
|
||||
|
||||
#define K_TICKS_FOREVER ((k_ticks_t) -1)
|
||||
|
||||
#ifndef CONFIG_LEGACY_TIMEOUT_API
|
||||
|
||||
typedef struct {
|
||||
k_ticks_t ticks;
|
||||
} k_timeout_t;
|
||||
|
||||
/**
|
||||
* @brief Compare timeouts for equality
|
||||
*
|
||||
* The k_timeout_t object is an opaque struct that should not be
|
||||
* inspected by application code. This macro exists so that users can
|
||||
* test timeout objects for equality with known constants
|
||||
* (e.g. K_NO_WAIT and K_FOREVER) when implementing their own APIs in
|
||||
* terms of Zephyr timeout constants.
|
||||
*
|
||||
* @return True if the timeout objects are identical
|
||||
*/
|
||||
#define K_TIMEOUT_EQ(a, b) ((a).ticks == (b).ticks)
|
||||
|
||||
#define Z_TIMEOUT_NO_WAIT ((k_timeout_t) {})
|
||||
#define Z_TIMEOUT_TICKS(t) ((k_timeout_t) { .ticks = (t) })
|
||||
#define Z_FOREVER Z_TIMEOUT_TICKS(K_TICKS_FOREVER)
|
||||
#define Z_TIMEOUT_MS(t) Z_TIMEOUT_TICKS(k_ms_to_ticks_ceil32(MAX(t, 0)))
|
||||
#define Z_TIMEOUT_US(t) Z_TIMEOUT_TICKS(k_us_to_ticks_ceil32(MAX(t, 0)))
|
||||
#define Z_TIMEOUT_NS(t) Z_TIMEOUT_TICKS(k_ns_to_ticks_ceil32(MAX(t, 0)))
|
||||
#define Z_TIMEOUT_CYC(t) Z_TIMEOUT_TICKS(k_cyc_to_ticks_ceil32(MAX(t, 0)))
|
||||
|
||||
#else
|
||||
|
||||
/* Legacy timeout API */
|
||||
typedef s32_t k_timeout_t;
|
||||
#define K_TIMEOUT_EQ(a, b) ((a) == (b))
|
||||
#define Z_TIMEOUT_NO_WAIT 0
|
||||
#define Z_TIMEOUT_TICKS(t) k_ticks_to_ms_ceil32(t)
|
||||
#define Z_FOREVER K_TICKS_FOREVER
|
||||
#define Z_TIMEOUT_MS(t) (t)
|
||||
#define Z_TIMEOUT_US(t) ((t) * 1000)
|
||||
#define Z_TIMEOUT_NS(t) ((t) * 1000000)
|
||||
#define Z_TIMEOUT_CYC(t) k_cyc_to_ms_ceil32(MAX((t), 0))
|
||||
|
||||
#endif
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef CONFIG_TICKLESS_KERNEL
|
||||
extern int _sys_clock_always_on;
|
||||
extern void z_enable_sys_clock(void);
|
||||
|
@ -53,8 +106,6 @@ extern void z_enable_sys_clock(void);
|
|||
/* number of nanoseconds per second */
|
||||
#define NSEC_PER_SEC ((NSEC_PER_USEC) * (USEC_PER_MSEC) * (MSEC_PER_SEC))
|
||||
|
||||
#define k_msleep(ms) k_sleep(ms)
|
||||
#define K_TIMEOUT_EQ(a, b) ((a) == (b))
|
||||
|
||||
/* kernel clocks */
|
||||
|
||||
|
@ -132,6 +183,8 @@ s64_t z_tick_get(void);
|
|||
#define z_tick_get_32() (0)
|
||||
#endif
|
||||
|
||||
u64_t z_timeout_end_calc(k_timeout_t timeout);
|
||||
|
||||
/* timeouts */
|
||||
|
||||
struct _timeout;
|
||||
|
|
|
@ -27,7 +27,8 @@ static inline void z_init_timeout(struct _timeout *t)
|
|||
sys_dnode_init(&t->node);
|
||||
}
|
||||
|
||||
void z_add_timeout(struct _timeout *to, _timeout_func_t fn, s32_t ticks);
|
||||
void z_add_timeout(struct _timeout *to, _timeout_func_t fn,
|
||||
k_timeout_t timeout);
|
||||
|
||||
int z_abort_timeout(struct _timeout *to);
|
||||
|
||||
|
@ -43,7 +44,7 @@ static inline void z_init_thread_timeout(struct _thread_base *thread_base)
|
|||
|
||||
extern void z_thread_timeout(struct _timeout *to);
|
||||
|
||||
static inline void z_add_thread_timeout(struct k_thread *th, s32_t ticks)
|
||||
static inline void z_add_thread_timeout(struct k_thread *th, k_timeout_t ticks)
|
||||
{
|
||||
z_add_timeout(&th->base.timeout, z_thread_timeout, ticks);
|
||||
}
|
||||
|
@ -63,12 +64,17 @@ s32_t z_timeout_remaining(struct _timeout *timeout);
|
|||
|
||||
/* Stubs when !CONFIG_SYS_CLOCK_EXISTS */
|
||||
#define z_init_thread_timeout(t) do {} while (false)
|
||||
#define z_add_thread_timeout(th, to) do {} while (false && to && (void *)th)
|
||||
#define z_abort_thread_timeout(t) (0)
|
||||
#define z_is_inactive_timeout(t) 0
|
||||
#define z_get_next_timeout_expiry() (K_FOREVER)
|
||||
#define z_get_next_timeout_expiry() (K_TICKS_FOREVER)
|
||||
#define z_set_timeout_expiry(t, i) do {} while (false)
|
||||
|
||||
static inline void z_add_thread_timeout(struct k_thread *th, k_timeout_t ticks)
|
||||
{
|
||||
ARG_UNUSED(th);
|
||||
ARG_UNUSED(ticks);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue