kernel: convert timer APIs to system calls

k_timer_init() registers callbacks that run in supervisor mode and is
excluded.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
This commit is contained in:
Andrew Boie 2017-09-29 16:22:28 -07:00 committed by Andrew Boie
parent b9a0578777
commit a354d49c4f
2 changed files with 71 additions and 13 deletions

View file

@ -1243,8 +1243,8 @@ extern void k_timer_init(struct k_timer *timer,
*
* @return N/A
*/
extern void k_timer_start(struct k_timer *timer,
s32_t duration, s32_t period);
__syscall void k_timer_start(struct k_timer *timer,
s32_t duration, s32_t period);
/**
* @brief Stop a timer.
@ -1262,7 +1262,7 @@ extern void k_timer_start(struct k_timer *timer,
*
* @return N/A
*/
extern void k_timer_stop(struct k_timer *timer);
__syscall void k_timer_stop(struct k_timer *timer);
/**
* @brief Read timer status.
@ -1276,7 +1276,7 @@ extern void k_timer_stop(struct k_timer *timer);
*
* @return Timer status.
*/
extern u32_t k_timer_status_get(struct k_timer *timer);
__syscall u32_t k_timer_status_get(struct k_timer *timer);
/**
* @brief Synchronize thread to timer expiration.
@ -1295,7 +1295,7 @@ extern u32_t k_timer_status_get(struct k_timer *timer);
*
* @return Timer status.
*/
extern u32_t k_timer_status_sync(struct k_timer *timer);
__syscall u32_t k_timer_status_sync(struct k_timer *timer);
/**
* @brief Get time remaining before a timer next expires.
@ -1307,7 +1307,9 @@ extern u32_t k_timer_status_sync(struct k_timer *timer);
*
* @return Remaining time (in milliseconds).
*/
static inline s32_t k_timer_remaining_get(struct k_timer *timer)
__syscall s32_t k_timer_remaining_get(struct k_timer *timer);
static inline s32_t _impl_k_timer_remaining_get(struct k_timer *timer)
{
return _timeout_remaining_get(&timer->timeout);
}
@ -1326,8 +1328,10 @@ static inline s32_t k_timer_remaining_get(struct k_timer *timer)
*
* @return N/A
*/
static inline void k_timer_user_data_set(struct k_timer *timer,
void *user_data)
__syscall void k_timer_user_data_set(struct k_timer *timer, void *user_data);
static inline void _impl_k_timer_user_data_set(struct k_timer *timer,
void *user_data)
{
timer->user_data = user_data;
}
@ -1339,7 +1343,9 @@ static inline void k_timer_user_data_set(struct k_timer *timer,
*
* @return The user data.
*/
static inline void *k_timer_user_data_get(struct k_timer *timer)
__syscall void *k_timer_user_data_get(struct k_timer *timer);
static inline void *_impl_k_timer_user_data_get(struct k_timer *timer)
{
return timer->user_data;
}

View file

@ -8,6 +8,7 @@
#include <debug/object_tracing_common.h>
#include <init.h>
#include <wait_q.h>
#include <syscall_handler.h>
extern struct k_timer _k_timer_list_start[];
extern struct k_timer _k_timer_list_end[];
@ -108,7 +109,7 @@ void k_timer_init(struct k_timer *timer,
}
void k_timer_start(struct k_timer *timer, s32_t duration, s32_t period)
void _impl_k_timer_start(struct k_timer *timer, s32_t duration, s32_t period)
{
__ASSERT(duration >= 0 && period >= 0 &&
(duration != 0 || period != 0), "invalid parameters\n");
@ -130,8 +131,25 @@ void k_timer_start(struct k_timer *timer, s32_t duration, s32_t period)
irq_unlock(key);
}
#ifdef CONFIG_USERSPACE
u32_t _handler_k_timer_start(u32_t timer, u32_t duration_p, u32_t period_p,
u32_t arg4, u32_t arg5, u32_t arg6, void *ssf)
{
s32_t duration, period;
_SYSCALL_ARG3;
void k_timer_stop(struct k_timer *timer)
duration = (s32_t)duration_p;
period = (s32_t)period_p;
_SYSCALL_VERIFY(duration >= 0 && period >= 0 &&
(duration != 0 || period != 0), ssf);
_SYSCALL_IS_OBJ(timer, K_OBJ_TIMER, 0, ssf);
_impl_k_timer_start((struct k_timer *)timer, duration, period);
return 0;
}
#endif
void _impl_k_timer_stop(struct k_timer *timer)
{
int key = irq_lock();
int inactive = (_abort_timeout(&timer->timeout) == _INACTIVE);
@ -160,8 +178,19 @@ void k_timer_stop(struct k_timer *timer)
}
}
#ifdef CONFIG_USERSPACE
u32_t _handler_k_timer_stop(u32_t timer, u32_t arg2, u32_t arg3,
u32_t arg4, u32_t arg5, u32_t arg6, void *ssf)
{
_SYSCALL_ARG1;
u32_t k_timer_status_get(struct k_timer *timer)
_SYSCALL_IS_OBJ(timer, K_OBJ_TIMER, 0, ssf);
_impl_k_timer_stop((struct k_timer *)timer);
return 0;
}
#endif
u32_t _impl_k_timer_status_get(struct k_timer *timer)
{
unsigned int key = irq_lock();
u32_t result = timer->status;
@ -172,8 +201,19 @@ u32_t k_timer_status_get(struct k_timer *timer)
return result;
}
#ifdef CONFIG_USERSPACE
u32_t _handler_k_timer_status_get(u32_t timer, u32_t arg2, u32_t arg3,
u32_t arg4, u32_t arg5, u32_t arg6,
void *ssf)
{
_SYSCALL_ARG1;
u32_t k_timer_status_sync(struct k_timer *timer)
_SYSCALL_IS_OBJ(timer, K_OBJ_TIMER, 0, ssf);
return _impl_k_timer_status_get((struct k_timer *)timer);
}
#endif
u32_t _impl_k_timer_status_sync(struct k_timer *timer)
{
__ASSERT(!_is_in_isr(), "");
@ -202,6 +242,18 @@ u32_t k_timer_status_sync(struct k_timer *timer)
return result;
}
#ifdef CONFIG_USERSPACE
u32_t _handler_k_timer_status_sync(u32_t timer, u32_t arg2, u32_t arg3,
u32_t arg4, u32_t arg5, u32_t arg6,
void *ssf)
{
_SYSCALL_ARG1;
_SYSCALL_IS_OBJ(timer, K_OBJ_TIMER, 0, ssf);
return _impl_k_timer_status_sync((struct k_timer *)timer);
}
#endif
s32_t _timeout_remaining_get(struct _timeout *timeout)
{
unsigned int key = irq_lock();