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

cpu/nrf5x: unified rtt driver

This commit is contained in:
Hauke Petersen 2017-04-03 18:16:43 +02:00
parent 3943d08b46
commit e1dde6b456
13 changed files with 175 additions and 346 deletions

View File

@ -68,18 +68,13 @@ static const timer_conf_t timer_config[] = {
/** @} */
/**
* @name Real time counter configuration
* @name Real time counter configuration
* @{
*/
#define RTT_NUMOF (1U)
#define RTT_IRQ_PRIO 1
#define RTT_DEV NRF_RTC1
#define RTT_IRQ RTC1_IRQn
#define RTT_ISR isr_rtc1
#define RTT_MAX_VALUE (0xffffff)
#define RTT_FREQUENCY (10) /* in Hz */
#define RTT_PRESCALER (3275U) /* run with 10 Hz */
#define RTT_DEV (1) /* NRF_RTC1 */
#define RTT_MAX_VALUE (0x00ffffff)
#define RTT_FREQUENCY (1024)
/** @} */
/**

View File

@ -74,18 +74,13 @@ static const timer_conf_t timer_config[] = {
/** @} */
/**
* @name Real time counter configuration
* @name Real time counter configuration
* @{
*/
#define RTT_NUMOF (1U)
#define RTT_IRQ_PRIO 1
#define RTT_DEV NRF_RTC1
#define RTT_IRQ RTC1_IRQn
#define RTT_ISR isr_rtc1
#define RTT_MAX_VALUE (0xffffff)
#define RTT_FREQUENCY (10) /* in Hz */
#define RTT_PRESCALER (3275U) /* run with 10 Hz */
#define RTT_DEV (1) /* NRF_RTC1 */
#define RTT_MAX_VALUE (0x00ffffff)
#define RTT_FREQUENCY (1024)
/** @} */
/**

View File

@ -74,18 +74,13 @@ static const timer_conf_t timer_config[] = {
/** @} */
/**
* @name Real time counter configuration
* @name Real time counter configuration
* @{
*/
#define RTT_NUMOF (1U)
#define RTT_IRQ_PRIO 1
#define RTT_DEV NRF_RTC1
#define RTT_IRQ RTC1_IRQn
#define RTT_ISR isr_rtc1
#define RTT_MAX_VALUE (0xffffff)
#define RTT_FREQUENCY (10) /* in Hz */
#define RTT_PRESCALER (3275U) /* run with 10 Hz */
#define RTT_DEV (1) /* NRF_RTC1 */
#define RTT_MAX_VALUE (0x00ffffff)
#define RTT_FREQUENCY (1024)
/** @} */
/**

View File

@ -56,18 +56,13 @@ static const timer_conf_t timer_config[] = {
/** @} */
/**
* @name Real time counter configuration
* @name Real time counter configuration
* @{
*/
#define RTT_NUMOF (1U)
#define RTT_IRQ_PRIO 1
#define RTT_DEV NRF_RTC1
#define RTT_IRQ RTC1_IRQn
#define RTT_ISR isr_rtc1
#define RTT_MAX_VALUE (0xffffff)
#define RTT_FREQUENCY (10) /* in Hz */
#define RTT_PRESCALER (3275U) /* run with 10 Hz */
#define RTT_DEV (1) /* NRF_RTC1 */
#define RTT_MAX_VALUE (0x00ffffff)
#define RTT_FREQUENCY (1024)
/** @} */
/**

View File

@ -64,12 +64,9 @@ static const timer_conf_t timer_config[] = {
* @{
*/
#define RTT_NUMOF (1U)
#define RTT_DEV NRF_RTC1
#define RTT_IRQ RTC1_IRQn
#define RTT_ISR isr_rtc1
#define RTT_MAX_VALUE (0xffffff)
#define RTT_FREQUENCY (10) /* in Hz */
#define RTT_PRESCALER (3275U) /* run with 10 Hz */
#define RTT_DEV (1) /* NRF_RTC1 */
#define RTT_MAX_VALUE (0x00ffffff)
#define RTT_FREQUENCY (1024)
/** @} */
/**

View File

@ -64,12 +64,9 @@ static const timer_conf_t timer_config[] = {
* @{
*/
#define RTT_NUMOF (1U)
#define RTT_DEV NRF_RTC1
#define RTT_IRQ RTC1_IRQn
#define RTT_ISR isr_rtc1
#define RTT_MAX_VALUE (0xffffff)
#define RTT_FREQUENCY (10) /* in Hz */
#define RTT_PRESCALER (3275U) /* run with 10 Hz */
#define RTT_DEV (1) /* NRF_RTC1 */
#define RTT_MAX_VALUE (0x00ffffff)
#define RTT_FREQUENCY (1024)
/** @} */
/**

View File

@ -59,18 +59,13 @@ static const timer_conf_t timer_config[] = {
/** @} */
/**
* @name Real time counter configuration
* @name Real time counter configuration
* @{
*/
#define RTT_NUMOF (1U)
#define RTT_IRQ_PRIO 1
#define RTT_DEV NRF_RTC1
#define RTT_IRQ RTC1_IRQn
#define RTT_ISR isr_rtc1
#define RTT_MAX_VALUE (0xffffff)
#define RTT_FREQUENCY (10) /* in Hz */
#define RTT_PRESCALER (3275U) /* run with 10 Hz */
#define RTT_DEV (1) /* NRF_RTC1 */
#define RTT_MAX_VALUE (0x00ffffff)
#define RTT_FREQUENCY (1024)
/** @} */
/**

View File

@ -58,18 +58,13 @@ static const timer_conf_t timer_config[] = {
/** @} */
/**
* @name Real time counter configuration
* @name Real time counter configuration
* @{
*/
#define RTT_NUMOF (1U)
#define RTT_IRQ_PRIO 1
#define RTT_DEV NRF_RTC1
#define RTT_IRQ RTC1_IRQn
#define RTT_ISR isr_rtc1
#define RTT_MAX_VALUE (0xffffff)
#define RTT_FREQUENCY (10) /* in Hz */
#define RTT_PRESCALER (3275U) /* run with 10 Hz */
#define RTT_DEV (1) /* NRF_RTC1 */
#define RTT_MAX_VALUE (0x00ffffff)
#define RTT_FREQUENCY (1024)
/** @} */
/**

View File

@ -68,18 +68,13 @@ static const timer_conf_t timer_config[] = {
/** @} */
/**
* @name Real time counter configuration
* @name Real time counter configuration
* @{
*/
#define RTT_NUMOF (1U)
#define RTT_IRQ_PRIO 1
#define RTT_DEV NRF_RTC1
#define RTT_IRQ RTC1_IRQn
#define RTT_ISR isr_rtc1
#define RTT_MAX_VALUE (0xffffff)
#define RTT_FREQUENCY (10) /* in Hz */
#define RTT_PRESCALER (3275U) /* run with 10 Hz */
#define RTT_DEV (1) /* NRF_RTC1 */
#define RTT_MAX_VALUE (0x00ffffff)
#define RTT_FREQUENCY (1024)
/** @} */
/**

View File

@ -66,18 +66,13 @@ static const timer_conf_t timer_config[] = {
/** @} */
/**
* @name Real time counter configuration
* @name Real time counter configuration
* @{
*/
#define RTT_NUMOF (1U)
#define RTT_IRQ_PRIO 1
#define RTT_DEV NRF_RTC1
#define RTT_IRQ RTC1_IRQn
#define RTT_ISR isr_rtc1
#define RTT_MAX_VALUE (0xffffff)
#define RTT_FREQUENCY (10) /* in Hz */
#define RTT_PRESCALER (3275U) /* run with 10 Hz */
#define RTT_DEV (1) /* NRF_RTC1 */
#define RTT_MAX_VALUE (0x00ffffff)
#define RTT_FREQUENCY (1024)
/** @} */
/**

View File

@ -1,135 +0,0 @@
/*
* Copyright (C) 2014 Freie Universität Berlin
*
* This file is subject to the terms and conditions of the GNU Lesser General
* Public License v2.1. See the file LICENSE in the top level directory for more
* details.
*/
/**
* @ingroup cpu_nrf51822
* @{
*
* @file
* @brief Real-time timer driver implementation
*
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
*
* @}
*/
#include <stdlib.h>
#include <stdio.h>
#include "cpu.h"
#include "board.h"
#include "periph_conf.h"
#include "periph/rtt.h"
/* guard file in case no RTC device was specified */
#if RTT_NUMOF
/*
* @brief Callback for the active alarm
*/
static rtt_cb_t alarm_cb;
/**
* @brief Argument for the active alarm callback
*/
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();
/* configure interrupt */
NVIC_SetPriority(RTT_IRQ, RTT_IRQ_PRIO);
NVIC_EnableIRQ(RTT_IRQ);
/* set prescaler */
RTT_DEV->PRESCALER = RTT_PRESCALER;
/* enable the low-frequency clock */
NRF_CLOCK->TASKS_LFCLKSTART = 1;
/* start the actual RTT thing */
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;
}
void rtt_set_counter(uint32_t counter)
{
(void) counter;
/* not supported for the NRF51822? -> could not find out how to do this */
}
void rtt_set_alarm(uint32_t alarm, rtt_cb_t cb, void *arg)
{
alarm_cb = cb;
alarm_arg = arg;
RTT_DEV->CC[0] = (alarm & RTT_MAX_VALUE);
RTT_DEV->INTENSET = RTC_INTENSET_COMPARE0_Msk;
}
uint32_t rtt_get_alarm(void)
{
return RTT_DEV->CC[0];
}
void rtt_clear_alarm(void)
{
RTT_DEV->INTENCLR = RTC_INTENSET_COMPARE0_Msk;
}
void rtt_poweron(void)
{
RTT_DEV->POWER = 1;
}
void rtt_poweroff(void)
{
RTT_DEV->POWER = 0;
}
void RTT_ISR(void)
{
if (RTT_DEV->EVENTS_COMPARE[0] == 1) {
RTT_DEV->EVENTS_COMPARE[0] = 0;
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);
}
cortexm_isr_end();
}
#endif /* RTT_NUMOF */

View File

@ -1,127 +0,0 @@
/*
* Copyright (C) 2015 Jan Wagner <mail@jwagner.eu>
* 2016 Freie Universität Berlin
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
/**
* @ingroup cpu_nrf52
* @{
*
* @file
* @brief Implementation of the peripheral real-time timer interface
*
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
* @author Jan Wagner <mail@jwagner.eu>
*
* @}
*/
#include <stdlib.h>
#include "cpu.h"
#include "board.h"
#include "periph_conf.h"
#include "periph/rtt.h"
/*
* @brief Callback for the active alarm
*/
static rtt_cb_t alarm_cb;
/**
* @brief Argument for the active alarm callback
*/
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)
{
/* configure interrupt */
NVIC_EnableIRQ(RTT_IRQ);
/* set prescaler */
RTT_DEV->PRESCALER = RTT_PRESCALER;
/* enable the low-frequency clock */
NRF_CLOCK->TASKS_LFCLKSTART = 1;
/* start the actual RTT thing */
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;
}
void rtt_set_counter(uint32_t counter)
{
(void) counter;
/* not supported by the nRF52 */
}
void rtt_set_alarm(uint32_t alarm, rtt_cb_t cb, void *arg)
{
alarm_cb = cb;
alarm_arg = arg;
RTT_DEV->CC[0] = (alarm & RTT_MAX_VALUE);
RTT_DEV->INTENSET = RTC_INTENSET_COMPARE0_Msk;
}
uint32_t rtt_get_alarm(void)
{
return RTT_DEV->CC[0];
}
void rtt_clear_alarm(void)
{
RTT_DEV->INTENCLR = RTC_INTENSET_COMPARE0_Msk;
}
void rtt_poweron(void)
{
RTT_DEV->TASKS_START = 1;
}
void rtt_poweroff(void)
{
RTT_DEV->TASKS_STOP = 1;
}
void RTT_ISR(void)
{
if (RTT_DEV->EVENTS_COMPARE[0] == 1) {
RTT_DEV->EVENTS_COMPARE[0] = 0;
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);
}
cortexm_isr_end();
}

View File

@ -0,0 +1,137 @@
/*
* Copyright (C) 2014-2017 Freie Universität Berlin
* 2015 Jan Wagner <mail@jwagner.eu>
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
/**
* @ingroup cpu_nrf5x_common
* @{
*
* @file
* @brief RTT implementation for NRF5x CPUs
*
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
* @author Jan Wagner <mail@jwagner.eu>
*
* @}
*/
#include "cpu.h"
#include "nrf_clock.h"
#include "periph/rtt.h"
/* get the IRQ configuration */
#if (RTT_DEV == 1)
#define DEV NRF_RTC1
#define ISR isr_rtc1
#define IRQn RTC1_IRQn
#elif (RTT_DEV == 2)
#define DEV NRF_RTC2
#define ISR isr_rtc2
#define IRQn RTC2_IRQn
#else
#error "RTT configuration: invalid or no RTC device specified (RTT_DEV)"
#endif
#define LFCLK_FREQ (32768U)
/* allocate memory for callbacks and their args */
static rtt_cb_t alarm_cb;
static void *alarm_arg;
static rtt_cb_t overflow_cb;
static void *overflow_arg;
void rtt_init(void)
{
/* enable the low-frequency clock */
clock_start_lf();
/* make sure device is powered */
#ifdef CPU_FAM_NRF51
DEV->POWER = 1;
#endif
/* stop the RTT during configuration */
DEV->TASKS_STOP = 1;
/* configure interrupt */
NVIC_EnableIRQ(IRQn);
/* set prescaler */
DEV->PRESCALER = (LFCLK_FREQ / RTT_FREQUENCY) - 1;
/* start the actual RTT thing */
DEV->TASKS_START = 1;
}
void rtt_set_overflow_cb(rtt_cb_t cb, void *arg)
{
overflow_cb = cb;
overflow_arg = arg;
DEV->INTENSET = RTC_INTENSET_OVRFLW_Msk;
}
void rtt_clear_overflow_cb(void)
{
DEV->INTENCLR = RTC_INTENCLR_OVRFLW_Msk;
}
uint32_t rtt_get_counter(void)
{
return DEV->COUNTER;
}
void rtt_set_counter(uint32_t counter)
{
(void) counter;
/* not supported by the nRF5x */
}
void rtt_set_alarm(uint32_t alarm, rtt_cb_t cb, void *arg)
{
alarm_cb = cb;
alarm_arg = arg;
DEV->CC[0] = (alarm & RTT_MAX_VALUE);
DEV->INTENSET = RTC_INTENSET_COMPARE0_Msk;
}
uint32_t rtt_get_alarm(void)
{
return DEV->CC[0];
}
void rtt_clear_alarm(void)
{
DEV->INTENCLR = RTC_INTENSET_COMPARE0_Msk;
}
void rtt_poweron(void)
{
#ifdef CPU_FAM_NRF51
DEV->POWER = 1;
#endif
DEV->TASKS_START = 1;
}
void rtt_poweroff(void)
{
DEV->TASKS_STOP = 1;
#ifdef CPU_FAM_NRF51
DEV->POWER = 0;
#endif
}
void ISR(void)
{
if (DEV->EVENTS_COMPARE[0] == 1) {
DEV->EVENTS_COMPARE[0] = 0;
DEV->INTENCLR = RTC_INTENSET_COMPARE0_Msk;
alarm_cb(alarm_arg);
}
if (DEV->EVENTS_OVRFLW == 1) {
DEV->EVENTS_OVRFLW = 0;
overflow_cb(overflow_arg);
}
cortexm_isr_end();
}