mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-01-18 12:52:44 +01:00
Merge pull request #1960 from haukepetersen/enh_driver_rtt
drivers: added enhanced RTT driver interface
This commit is contained in:
commit
d2516b9b95
@ -32,11 +32,25 @@
|
||||
#if RTT_NUMOF
|
||||
|
||||
/*
|
||||
* callback and argument for an active alarm
|
||||
* @brief Callback for the active alarm
|
||||
*/
|
||||
static rtt_cb_t alarm_cb;
|
||||
|
||||
/**
|
||||
* @brief Argument for the active alarm callback
|
||||
*/
|
||||
static rtt_alarm_cb_t alarm_cb;
|
||||
static void *alarm_arg;
|
||||
|
||||
/**
|
||||
* @brief Callback for the overflow event
|
||||
*/
|
||||
static rtt_cb_t overflow_cb;
|
||||
|
||||
/**
|
||||
* @brief Argument for the overflow callback
|
||||
*/
|
||||
static void *overflow_arg;
|
||||
|
||||
void rtt_init(void)
|
||||
{
|
||||
rtt_poweron();
|
||||
@ -55,6 +69,18 @@ void rtt_init(void)
|
||||
RTT_DEV->TASKS_START = 1;
|
||||
}
|
||||
|
||||
void rtt_set_overflow_cb(rtt_cb_t cb, void *arg)
|
||||
{
|
||||
overflow_cb = cb;
|
||||
overflow_arg = arg;
|
||||
RTT_DEV->INTENSET = RTC_INTENSET_OVRFLW_Msk;
|
||||
}
|
||||
|
||||
void rtt_clear_overflow_cb(void)
|
||||
{
|
||||
RTT_DEV->INTENCLR = RTC_INTENCLR_OVRFLW_Msk;
|
||||
}
|
||||
|
||||
uint32_t rtt_get_counter(void)
|
||||
{
|
||||
return RTT_DEV->COUNTER;
|
||||
@ -65,7 +91,7 @@ void rtt_set_counter(uint32_t counter)
|
||||
/* not supported for the NRF51822? -> could not find out how to do this */
|
||||
}
|
||||
|
||||
void rtt_set_alarm(uint32_t alarm, rtt_alarm_cb_t cb, void *arg)
|
||||
void rtt_set_alarm(uint32_t alarm, rtt_cb_t cb, void *arg)
|
||||
{
|
||||
alarm_cb = cb;
|
||||
alarm_arg = arg;
|
||||
@ -100,6 +126,10 @@ void RTT_ISR(void)
|
||||
RTT_DEV->INTENCLR = RTC_INTENSET_COMPARE0_Msk;
|
||||
alarm_cb(alarm_arg);
|
||||
}
|
||||
if (RTT_DEV->EVENTS_OVRFLW == 1) {
|
||||
RTT_DEV->EVENTS_OVRFLW = 0;
|
||||
overflow_cb(overflow_arg);
|
||||
}
|
||||
if (sched_context_switch_request) {
|
||||
thread_yield();
|
||||
}
|
||||
|
@ -42,9 +42,15 @@ inline void _rtt_leave_config_mode(void);
|
||||
/*
|
||||
* callback and argument for an active alarm
|
||||
*/
|
||||
static rtt_alarm_cb_t alarm_cb;
|
||||
static rtt_cb_t alarm_cb;
|
||||
static void *alarm_arg;
|
||||
|
||||
/*
|
||||
* callback and argument for overflow callback
|
||||
*/
|
||||
static rtt_cb_t overflow_cb;
|
||||
static void *overflow_arg;
|
||||
|
||||
void rtt_init(void)
|
||||
{
|
||||
rtt_poweron();
|
||||
@ -69,6 +75,24 @@ void rtt_init(void)
|
||||
_rtt_leave_config_mode();
|
||||
}
|
||||
|
||||
void rtt_set_overflow_cb(rtt_cb_t cb, void *arg)
|
||||
{
|
||||
overflow_cb = cb;
|
||||
overflow_arg = arg;
|
||||
_rtt_enter_config_mode();
|
||||
/* Enable overflow interrupt */
|
||||
RTT_DEV->CRH |= RTC_CRH_OWIE;
|
||||
_rtt_leave_config_mode();
|
||||
}
|
||||
|
||||
void rtt_clear_overflow_cb(void)
|
||||
{
|
||||
_rtt_enter_config_mode();
|
||||
/* Clear overflow interrupt */
|
||||
RTT_DEV->CRH &= ~(RTC_CRH_OWIE);
|
||||
_rtt_leave_config_mode();
|
||||
}
|
||||
|
||||
uint32_t rtt_get_counter(void)
|
||||
{
|
||||
/* wait for syncronization */
|
||||
@ -97,7 +121,7 @@ uint32_t rtt_get_alarm(void)
|
||||
return (((uint32_t)RTT_DEV->ALRH << 16 ) | (uint32_t)(RTT_DEV->ALRL));
|
||||
}
|
||||
|
||||
void rtt_set_alarm(uint32_t alarm, rtt_alarm_cb_t cb, void *arg)
|
||||
void rtt_set_alarm(uint32_t alarm, rtt_cb_t cb, void *arg)
|
||||
{
|
||||
_rtt_enter_config_mode();
|
||||
|
||||
@ -169,6 +193,10 @@ void RTT_ISR(void)
|
||||
RTT_DEV->CRL &= ~(RTC_CRL_ALRF);
|
||||
alarm_cb(alarm_arg);
|
||||
}
|
||||
if (RTT_DEV->CRL & RTC_CRL_OWF) {
|
||||
RTT_DEV->CRL &= ~(RTC_CRL_OWF);
|
||||
overflow_cb(overflow_arg);
|
||||
}
|
||||
if (sched_context_switch_request) {
|
||||
thread_yield();
|
||||
}
|
||||
|
@ -16,6 +16,7 @@
|
||||
* definitions
|
||||
*
|
||||
* @author Thomas Eichinger <thomas.eichinger@fu-berlin.de>
|
||||
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
|
||||
*/
|
||||
|
||||
#ifndef __RTT_H
|
||||
@ -35,13 +36,26 @@ extern "C" {
|
||||
*
|
||||
* @param[in] arg optional argument to put the callback in the right context
|
||||
*/
|
||||
typedef void(*rtt_alarm_cb_t)(void *arg);
|
||||
typedef void(*rtt_cb_t)(void *arg);
|
||||
|
||||
/**
|
||||
* @brief Initialize RTT module
|
||||
*/
|
||||
void rtt_init(void);
|
||||
|
||||
/**
|
||||
* @brief Set a callback for the counter overflow event
|
||||
*
|
||||
* @param[in] cb Callback to execute on overflow
|
||||
* @param[in] arg Argument passed to the callback
|
||||
*/
|
||||
void rtt_set_overflow_cb(rtt_cb_t cb, void *arg);
|
||||
|
||||
/**
|
||||
* @brief Clear the overflow callback
|
||||
*/
|
||||
void rtt_clear_overflow_cb(void);
|
||||
|
||||
/**
|
||||
* @brief Get the current RTT counter.
|
||||
*
|
||||
@ -63,7 +77,7 @@ void rtt_set_counter(uint32_t counter);
|
||||
* @param[in] cb Callback executed when alarm is hit.
|
||||
* @param[in] arg Argument passed to callback when alarm is hit.
|
||||
*/
|
||||
void rtt_set_alarm(uint32_t alarm, rtt_alarm_cb_t cb, void *arg);
|
||||
void rtt_set_alarm(uint32_t alarm, rtt_cb_t cb, void *arg);
|
||||
|
||||
/**
|
||||
* @brief Get the value of a set alarm.
|
||||
|
Loading…
Reference in New Issue
Block a user