1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

sys/xtimer: Remove dependency to core_msg

When module `core_msg` is not used, `xtimer` now no longer provides the features
related to messages. This allows using `xtimer` without `core_msg`.
This commit is contained in:
Marian Buschsieweke 2019-03-21 15:05:21 +01:00
parent 8a877b58df
commit cd1ce6b98d
No known key found for this signature in database
GPG Key ID: 61F64C6599B1539F
3 changed files with 111 additions and 99 deletions

View File

@ -29,10 +29,14 @@
#ifndef XTIMER_H
#define XTIMER_H
#include <stdbool.h>
#include <stdint.h>
#include "timex.h"
#ifdef MODULE_CORE_MSG
#include "msg.h"
#endif /* MODULE_CORE_MSG */
#include "mutex.h"
#include "kernel_types.h"
#include "board.h"
#include "periph_conf.h"
@ -207,42 +211,6 @@ static inline void xtimer_spin(xtimer_ticks32_t ticks);
*/
static inline void xtimer_periodic_wakeup(xtimer_ticks32_t *last_wakeup, uint32_t period);
/**
* @brief Set a timer that sends a message
*
* This function sets a timer that will send a message @p offset ticks
* from now.
*
* The message struct specified by msg parameter will not be copied, e.g., it
* needs to point to valid memory until the message has been delivered.
*
* @param[in] timer timer struct to work with.
* Its xtimer_t::target and xtimer_t::long_target
* fields need to be initialized with 0 on first use.
* @param[in] offset microseconds from now
* @param[in] msg ptr to msg that will be sent
* @param[in] target_pid pid the message will be sent to
*/
static inline void xtimer_set_msg(xtimer_t *timer, uint32_t offset, msg_t *msg, kernel_pid_t target_pid);
/**
* @brief Set a timer that sends a message, 64bit version
*
* This function sets a timer that will send a message @p offset microseconds
* from now.
*
* The message struct specified by msg parameter will not be copied, e.g., it
* needs to point to valid memory until the message has been delivered.
*
* @param[in] timer timer struct to work with.
* Its xtimer_t::target and xtimer_t::long_target
* fields need to be initialized with 0 on first use.
* @param[in] offset microseconds from now
* @param[in] msg ptr to msg that will be sent
* @param[in] target_pid pid the message will be sent to
*/
static inline void xtimer_set_msg64(xtimer_t *timer, uint64_t offset, msg_t *msg, kernel_pid_t target_pid);
/**
* @brief Set a timer that wakes up a thread
*
@ -321,28 +289,6 @@ static inline void xtimer_set64(xtimer_t *timer, uint64_t offset_us);
*/
void xtimer_remove(xtimer_t *timer);
/**
* @brief receive a message blocking but with timeout
*
* @param[out] msg pointer to a msg_t which will be filled in case of
* no timeout
* @param[in] timeout timeout in microseconds relative
*
* @return < 0 on error, other value otherwise
*/
static inline int xtimer_msg_receive_timeout(msg_t *msg, uint32_t timeout);
/**
* @brief receive a message blocking but with timeout, 64bit version
*
* @param[out] msg pointer to a msg_t which will be filled in case of no
* timeout
* @param[in] timeout timeout in microseconds relative
*
* @return < 0 on error, other value otherwise
*/
static inline int xtimer_msg_receive_timeout64(msg_t *msg, uint64_t timeout);
/**
* @brief Convert microseconds to xtimer ticks
*
@ -469,6 +415,66 @@ int xtimer_mutex_lock_timeout(mutex_t *mutex, uint64_t us);
*/
void xtimer_set_timeout_flag(xtimer_t *t, uint32_t timeout);
#ifdef MODULE_CORE_MSG
/**
* @brief Set a timer that sends a message
*
* This function sets a timer that will send a message @p offset ticks
* from now.
*
* The message struct specified by msg parameter will not be copied, e.g., it
* needs to point to valid memory until the message has been delivered.
*
* @param[in] timer timer struct to work with.
* Its xtimer_t::target and xtimer_t::long_target
* fields need to be initialized with 0 on first use.
* @param[in] offset microseconds from now
* @param[in] msg ptr to msg that will be sent
* @param[in] target_pid pid the message will be sent to
*/
static inline void xtimer_set_msg(xtimer_t *timer, uint32_t offset, msg_t *msg, kernel_pid_t target_pid);
/**
* @brief Set a timer that sends a message, 64bit version
*
* This function sets a timer that will send a message @p offset microseconds
* from now.
*
* The message struct specified by msg parameter will not be copied, e.g., it
* needs to point to valid memory until the message has been delivered.
*
* @param[in] timer timer struct to work with.
* Its xtimer_t::target and xtimer_t::long_target
* fields need to be initialized with 0 on first use.
* @param[in] offset microseconds from now
* @param[in] msg ptr to msg that will be sent
* @param[in] target_pid pid the message will be sent to
*/
static inline void xtimer_set_msg64(xtimer_t *timer, uint64_t offset, msg_t *msg, kernel_pid_t target_pid);
/**
* @brief receive a message blocking but with timeout
*
* @param[out] msg pointer to a msg_t which will be filled in case of
* no timeout
* @param[in] timeout timeout in microseconds relative
*
* @return < 0 on error, other value otherwise
*/
static inline int xtimer_msg_receive_timeout(msg_t *msg, uint32_t timeout);
/**
* @brief receive a message blocking but with timeout, 64bit version
*
* @param[out] msg pointer to a msg_t which will be filled in case of no
* timeout
* @param[in] timeout timeout in microseconds relative
*
* @return < 0 on error, other value otherwise
*/
static inline int xtimer_msg_receive_timeout64(msg_t *msg, uint64_t timeout);
#endif
/**
* @brief xtimer backoff value
*

View File

@ -84,12 +84,14 @@ int _xtimer_set_absolute(xtimer_t *timer, uint32_t target);
void _xtimer_set(xtimer_t *timer, uint32_t offset);
void _xtimer_set64(xtimer_t *timer, uint32_t offset, uint32_t long_offset);
void _xtimer_periodic_wakeup(uint32_t *last_wakeup, uint32_t period);
void _xtimer_set_msg(xtimer_t *timer, uint32_t offset, msg_t *msg, kernel_pid_t target_pid);
void _xtimer_set_msg64(xtimer_t *timer, uint64_t offset, msg_t *msg, kernel_pid_t target_pid);
void _xtimer_set_wakeup(xtimer_t *timer, uint32_t offset, kernel_pid_t pid);
void _xtimer_set_wakeup64(xtimer_t *timer, uint64_t offset, kernel_pid_t pid);
#ifdef MODULE_CORE_MSG
int _xtimer_msg_receive_timeout(msg_t *msg, uint32_t ticks);
int _xtimer_msg_receive_timeout64(msg_t *msg, uint64_t ticks);
void _xtimer_set_msg(xtimer_t *timer, uint32_t offset, msg_t *msg, kernel_pid_t target_pid);
void _xtimer_set_msg64(xtimer_t *timer, uint64_t offset, msg_t *msg, kernel_pid_t target_pid);
#endif /* MODULE_CORE_MSG */
/**
* @brief Sleep for the given number of ticks
@ -210,16 +212,6 @@ static inline void xtimer_periodic_wakeup(xtimer_ticks32_t *last_wakeup, uint32_
_xtimer_periodic_wakeup(&last_wakeup->ticks32, _xtimer_ticks_from_usec(period));
}
static inline void xtimer_set_msg(xtimer_t *timer, uint32_t offset, msg_t *msg, kernel_pid_t target_pid)
{
_xtimer_set_msg(timer, _xtimer_ticks_from_usec(offset), msg, target_pid);
}
static inline void xtimer_set_msg64(xtimer_t *timer, uint64_t offset, msg_t *msg, kernel_pid_t target_pid)
{
_xtimer_set_msg64(timer, _xtimer_ticks_from_usec64(offset), msg, target_pid);
}
static inline void xtimer_set_wakeup(xtimer_t *timer, uint32_t offset, kernel_pid_t pid)
{
_xtimer_set_wakeup(timer, _xtimer_ticks_from_usec(offset), pid);
@ -241,6 +233,7 @@ static inline void xtimer_set64(xtimer_t *timer, uint64_t period_us)
_xtimer_set64(timer, ticks, ticks >> 32);
}
#ifdef MODULE_CORE_MSG
static inline int xtimer_msg_receive_timeout(msg_t *msg, uint32_t timeout)
{
return _xtimer_msg_receive_timeout(msg, _xtimer_ticks_from_usec(timeout));
@ -251,6 +244,17 @@ static inline int xtimer_msg_receive_timeout64(msg_t *msg, uint64_t timeout)
return _xtimer_msg_receive_timeout64(msg, _xtimer_ticks_from_usec64(timeout));
}
static inline void xtimer_set_msg(xtimer_t *timer, uint32_t offset, msg_t *msg, kernel_pid_t target_pid)
{
_xtimer_set_msg(timer, _xtimer_ticks_from_usec(offset), msg, target_pid);
}
static inline void xtimer_set_msg64(xtimer_t *timer, uint64_t offset, msg_t *msg, kernel_pid_t target_pid)
{
_xtimer_set_msg64(timer, _xtimer_ticks_from_usec64(offset), msg, target_pid);
}
#endif /* MODULE_CORE_MSG */
static inline xtimer_ticks32_t xtimer_ticks_from_usec(uint32_t usec)
{
xtimer_ticks32_t ticks;

View File

@ -139,6 +139,7 @@ out:
*last_wakeup = target;
}
#ifdef MODULE_CORE_MSG
static void _callback_msg(void* arg)
{
msg_t *msg = (msg_t*)arg;
@ -166,35 +167,6 @@ void _xtimer_set_msg64(xtimer_t *timer, uint64_t offset, msg_t *msg, kernel_pid_
_xtimer_set64(timer, offset, offset >> 32);
}
static void _callback_wakeup(void* arg)
{
thread_wakeup((kernel_pid_t)((intptr_t)arg));
}
void _xtimer_set_wakeup(xtimer_t *timer, uint32_t offset, kernel_pid_t pid)
{
timer->callback = _callback_wakeup;
timer->arg = (void*) ((intptr_t)pid);
_xtimer_set(timer, offset);
}
void _xtimer_set_wakeup64(xtimer_t *timer, uint64_t offset, kernel_pid_t pid)
{
timer->callback = _callback_wakeup;
timer->arg = (void*) ((intptr_t)pid);
_xtimer_set64(timer, offset, offset >> 32);
}
void xtimer_now_timex(timex_t *out)
{
uint64_t now = xtimer_usec_from_ticks64(xtimer_now64());
out->seconds = div_u64_by_1000000(now);
out->microseconds = now - (out->seconds * US_PER_SEC);
}
/* Prepares the message to trigger the timeout.
* Additionally, the xtimer_t struct gets initialized.
*/
@ -236,6 +208,36 @@ int _xtimer_msg_receive_timeout(msg_t *msg, uint32_t timeout_ticks)
_xtimer_set_msg(&t, timeout_ticks, &tmsg, sched_active_pid);
return _msg_wait(msg, &tmsg, &t);
}
#endif /* MODULE_CORE_MSG */
static void _callback_wakeup(void* arg)
{
thread_wakeup((kernel_pid_t)((intptr_t)arg));
}
void _xtimer_set_wakeup(xtimer_t *timer, uint32_t offset, kernel_pid_t pid)
{
timer->callback = _callback_wakeup;
timer->arg = (void*) ((intptr_t)pid);
_xtimer_set(timer, offset);
}
void _xtimer_set_wakeup64(xtimer_t *timer, uint64_t offset, kernel_pid_t pid)
{
timer->callback = _callback_wakeup;
timer->arg = (void*) ((intptr_t)pid);
_xtimer_set64(timer, offset, offset >> 32);
}
void xtimer_now_timex(timex_t *out)
{
uint64_t now = xtimer_usec_from_ticks64(xtimer_now64());
out->seconds = div_u64_by_1000000(now);
out->microseconds = now - (out->seconds * US_PER_SEC);
}
static void _mutex_timeout(void *arg)
{