mirror of
https://github.com/apache/nuttx.git
synced 2026-05-19 20:06:24 +08:00
arch/arm/src/nrf52: add a low-level TIMER interface
This commit is contained in:
committed by
Abdelatif Guettouche
parent
17bd5f3d1a
commit
7db61992f9
@@ -90,6 +90,10 @@ config NRF52_UART
|
||||
bool
|
||||
default n
|
||||
|
||||
config NRF52_TIMER
|
||||
bool
|
||||
default n
|
||||
|
||||
config NRF52_SPI_MASTER_WORKAROUND_1BYTE_TRANSFER
|
||||
bool "SPI Master 1 Byte transfer anomaly workaround"
|
||||
depends on NRF52_SPI_MASTER && ARCH_FAMILY_NRF52832
|
||||
@@ -181,22 +185,27 @@ config NRF52_SAADC
|
||||
|
||||
config NRF52_TIMER0
|
||||
bool "TIMER0"
|
||||
select NRF52_TIMER
|
||||
default n
|
||||
|
||||
config NRF52_TIMER1
|
||||
bool "TIMER1"
|
||||
select NRF52_TIMER
|
||||
default n
|
||||
|
||||
config NRF52_TIMER2
|
||||
bool "TIMER2"
|
||||
select NRF52_TIMER
|
||||
default n
|
||||
|
||||
config NRF52_TIMER3
|
||||
bool "TIMER3"
|
||||
select NRF52_TIMER
|
||||
default n
|
||||
|
||||
config NRF52_TIMER4
|
||||
bool "TIMER4"
|
||||
select NRF52_TIMER
|
||||
default n
|
||||
|
||||
config NRF52_RTC0
|
||||
|
||||
@@ -128,5 +128,8 @@ endif
|
||||
|
||||
ifeq ($(CONFIG_NRF52_RADIO),y)
|
||||
CHIP_CSRCS += nrf52_radio.c
|
||||
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_NRF52_TIMER),y)
|
||||
CHIP_CSRCS += nrf52_tim.c
|
||||
endif
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/**************************************************************************
|
||||
/************************************************************************************
|
||||
* arch/arm/src/nrf52/hardware/nrf52_tim.h
|
||||
*
|
||||
* Copyright (C) 2020 Gregory Nutt. All rights reserved.
|
||||
@@ -31,60 +31,81 @@
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
***************************************************************************/
|
||||
************************************************************************************/
|
||||
|
||||
#ifndef __ARCH_ARM_SRC_NRF52_HARDWARE_NRF52_TIM_H
|
||||
#define __ARCH_ARM_SRC_NRF52_HARDWARE_NRF52_TIM_H
|
||||
|
||||
/***************************************************************************
|
||||
/************************************************************************************
|
||||
* Included Files
|
||||
***************************************************************************/
|
||||
************************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include "hardware/nrf52_memorymap.h"
|
||||
|
||||
/***************************************************************************
|
||||
/************************************************************************************
|
||||
* Pre-processor Definitions
|
||||
***************************************************************************/
|
||||
************************************************************************************/
|
||||
|
||||
/* Register offsets for TIM ************************************************/
|
||||
/* TIMER constants ******************************************************************/
|
||||
|
||||
#define NRF52_TIM_TASKS_START_OFFSET 0x0000 /* Start Timer */
|
||||
#define NRF52_TIM_TASKS_STOP_OFFSET 0x0004 /* Stop Timer */
|
||||
#define NRF52_TIM_TASKS_COUNT_OFFSET 0x0008 /* Increment Timer*/
|
||||
#define NRF52_TIM_TASKS_CLEAR_OFFSET 0x000c /* Clear time */
|
||||
#define NRF52_TIM_TASKS_SHUTDOWN_OFFSET 0x0010 /* Shutdown Timer */
|
||||
#define NRF52_TIM_TASKS_CAPTURE_OFFSET(x) (0x0040 + ((x) * 0x04)) /* Capture Timer value to CC[x] */
|
||||
#define NRF52_TIM_EVENTS_COMPARE_OFFSET(x) (0x0140 + ((x) * 0x04)) /* Compare event on CC[x] */
|
||||
#define NRF52_TIM_SHORTS_OFFSET 0x0200 /* Shortcuts between local events and tasks */
|
||||
#define NRF52_TIM_INTENSET_OFFSET 0x0304 /* Enable interrupt */
|
||||
#define NRF52_TIM_MODE_OFFSET 0x0504 /* Timer mode selection */
|
||||
#define NRF52_TIM_BITMODE_OFFSET 0x0508 /* Configure the number of bits used by the Timer */
|
||||
#define NRF52_TIM_PRESCALER_OFFSET 0x0510 /* Timer prescaler register */
|
||||
#define NRF52_TIM_CC_OFFSET(x) (0x0540 + ((x) * 0x04)) /* Capture/Compare register x */
|
||||
#define TIMER_BASE_FERQUENCY (16000000)
|
||||
|
||||
/* Register offsets for TIM ************************************************/
|
||||
/* Register offsets for TIM *********************************************************/
|
||||
|
||||
#define NRF52_TIM_TASKS_START_OFFSET 0x0000 /* Start Timer */
|
||||
#define NRF52_TIM_TASKS_STOP_OFFSET 0x0004 /* Stop Timer */
|
||||
#define NRF52_TIM_TASKS_COUNT_OFFSET 0x0008 /* Increment Timer */
|
||||
#define NRF52_TIM_TASKS_CLEAR_OFFSET 0x000c /* Clear time */
|
||||
#define NRF52_TIM_TASKS_SHUTDOWN_OFFSET 0x0010 /* Shutdown Timer */
|
||||
#define NRF52_TIM_TASKS_CAPTURE_OFFSET(x) (0x0040 + ((x) * 4)) /* Capture Timer value to CC[x] */
|
||||
#define NRF52_TIM_EVENTS_COMPARE_OFFSET(x) (0x0140 + ((x) * 4)) /* Compare event on CC[x] */
|
||||
#define NRF52_TIM_SHORTS_OFFSET 0x0200 /* Shortcuts between local events and tasks */
|
||||
#define NRF52_TIM_INTENSET_OFFSET 0x0304 /* Enable interrupt */
|
||||
#define NRF52_TIM_INTCLR_OFFSET 0x0308 /* Disable interrupt */
|
||||
#define NRF52_TIM_MODE_OFFSET 0x0504 /* Timer mode selection */
|
||||
#define NRF52_TIM_BITMODE_OFFSET 0x0508 /* Configure the number of bits used by the Timer */
|
||||
#define NRF52_TIM_PRESCALER_OFFSET 0x0510 /* Timer prescaler register */
|
||||
#define NRF52_TIM_CC_OFFSET(x) (0x0540 + ((x) * 4)) /* Capture/Compare register x */
|
||||
|
||||
/* Register offsets for TIM *********************************************************/
|
||||
|
||||
/* TASKS_START Register */
|
||||
|
||||
#define TIM_TASKS_START (1 << 0) /* Bit 0: Start Timer */
|
||||
|
||||
/* TASKS_STOP Register */
|
||||
|
||||
#define TIM_TASKS_STOP (1 << 0) /* Bit 0: Stop Timer */
|
||||
|
||||
/* TASKS_COUNT Register */
|
||||
|
||||
#define TIM_TASKS_COUNT (1 << 0) /* Bit 0: Increment Timer */
|
||||
|
||||
/* TASKS_CLEAR Register */
|
||||
|
||||
#define TIM_TASKS_CLEAR (1 << 0) /* Bit 0: Clear Timer */
|
||||
|
||||
/* SHORTS Register */
|
||||
|
||||
#define TIM_SHORTS_COMPARE_CLEAR(x) (1 << (x)) /* Bits 0-5: */
|
||||
#define TIM_SHORTS_COMPARE_STOP(x) (1 << (x + 0x8)) /* Bits 8-13 */
|
||||
#define TIM_SHORTS_COMPARE_CLEAR(x) (1 << (x)) /* Bits 0-5: */
|
||||
#define TIM_SHORTS_COMPARE_STOP(x) (1 << (x + 8)) /* Bits 8-13 */
|
||||
|
||||
/* INTENSET/INTENCLR Register */
|
||||
|
||||
#define TIM_INT_COMPARE(x) (1 << (x + 0x16)) /* Bits 16-21 */
|
||||
#define TIM_INT_COMPARE(x) (1 << (x + 16)) /* Bits 16-21 */
|
||||
|
||||
/* MODE Register */
|
||||
|
||||
#define TIM_MODE_SHIFT (0) /* Bits 0-1: Timer mode */
|
||||
#define TIM_MODE_SHIFT (0) /* Bits 0-1: Timer mode */
|
||||
#define TIM_MODE_MASK (0x3 << TIM_MODE_SHIFT)
|
||||
# define TIM_MODE_TIMER (0x0 << TIM_MODE_SHIFT) /* 0: Timer mode */
|
||||
# define TIM_MODE_COUNTER (0x1 << TIM_MODE_SHIFT) /* 1: Counter mode */
|
||||
# define TIM_MODE_LPCONUTER (0x2 << TIM_MODE_SHIFT) /* 2: Low Power Counter mode */
|
||||
# define TIM_MODE_LPCOUNTER (0x2 << TIM_MODE_SHIFT) /* 2: Low Power Counter mode */
|
||||
|
||||
/* BITMODE Register */
|
||||
|
||||
#define TIM_BITMODE_SHIFT (0) /* Bits 0-1: Timer bit width */
|
||||
#define TIM_BITMODE_SHIFT (0) /* Bits 0-1: Timer bit width */
|
||||
#define TIM_BITMODE_MASK (0x3 << TIM_BITMODE_SHIFT)
|
||||
# define TIM_BITMODE_16B (0x0 << TIM_BITMODE_SHIFT) /* 0: 16 bit */
|
||||
# define TIM_BITMODE_8B (0x1 << TIM_BITMODE_SHIFT) /* 1: 8 bit */
|
||||
@@ -93,7 +114,8 @@
|
||||
|
||||
/* PRESCALER Register */
|
||||
|
||||
#define TIM_PRESCALER_SHIFT (0) /* Bits 0-3: Prescaler value */
|
||||
#define TIM_PRESCALER_MASK (0xf << TIM_PRESCALER_SHIFT)
|
||||
#define TIM_PRESCALER_SHIFT (0) /* Bits 0-3: Prescaler value */
|
||||
#define TIM_PRESCALER_MAX (0xf)
|
||||
#define TIM_PRESCALER_MASK (TIM_PRESCALER_MAX << TIM_PRESCALER_SHIFT)
|
||||
|
||||
#endif /* __ARCH_ARM_SRC_NRF52_HARDWARE_NRF52_TIM_H */
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,176 @@
|
||||
/****************************************************************************
|
||||
* arch/arm/src/nrf52/nrf52_tim.h
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __ARCH_ARM_SRC_NRF52_NRF52_TIM_H
|
||||
#define __ARCH_ARM_SRC_NRF52_NRF52_TIM_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <nuttx/irq.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Helpers ******************************************************************/
|
||||
|
||||
#define NRF52_TIM_START(d) ((d)->ops->start(d))
|
||||
#define NRF52_TIM_STOP(d) ((d)->ops->stop(d))
|
||||
#define NRF52_TIM_CLEAR(d) ((d)->ops->clear(d))
|
||||
#define NRF52_TIM_CONFIGURE(d, m, w) ((d)->ops->configure(d, m, w))
|
||||
#define NRF52_TIM_SHORTS(d, s, i, e) ((d)->ops->shorts(d, s, i, e))
|
||||
#define NRF52_TIM_COUNT(d) ((d)->ops->count(d))
|
||||
#define NRF52_TIM_SETCC(d, i, cc) ((d)->ops->setcc(d, i, cc))
|
||||
#define NRF52_TIM_GETCC(d, i, cc) ((d)->ops->setcc(d, i, cc))
|
||||
#define NRF52_TIM_SETPRE(d, pre) ((d)->ops->setpre(d, pre))
|
||||
#define NRF52_TIM_SETISR(d, hnd, arg) ((d)->ops->setisr(d, hnd, arg))
|
||||
#define NRF52_TIM_ENABLEINT(d, s) ((d)->ops->enableint(d, s))
|
||||
#define NRF52_TIM_DISABLEINT(d, s) ((d)->ops->disableint(d, s))
|
||||
#define NRF52_TIM_CHECKINT(d, s) ((d)->ops->checkint(d, s))
|
||||
#define NRF52_TIM_ACKINT(d, s) ((d)->ops->ackint(d, s))
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
/* Timer mode */
|
||||
|
||||
enum nrf52_tim_mode_e
|
||||
{
|
||||
NRF52_TIM_MODE_UNUSED = 0,
|
||||
NRF52_TIM_MODE_TIMER = 1,
|
||||
NRF52_TIM_MODE_COUNTER = 2,
|
||||
NRF52_TIM_MODE_LOWPOWER = 3,
|
||||
};
|
||||
|
||||
/* Timer bit width */
|
||||
|
||||
enum nrf52_tim_width_e
|
||||
{
|
||||
NRF52_TIM_WIDTH_16B = 0,
|
||||
NRF52_TIM_WIDTH_8B = 1,
|
||||
NRF52_TIM_WIDTH_24B = 2,
|
||||
NRF52_TIM_WIDTH_32B = 3,
|
||||
};
|
||||
|
||||
/* Timer CC index */
|
||||
|
||||
enum nrf52_tim_cc_e
|
||||
{
|
||||
NRF52_TIM_CC0 = 0,
|
||||
NRF52_TIM_CC1 = 1,
|
||||
NRF52_TIM_CC2 = 2,
|
||||
NRF52_TIM_CC3 = 3,
|
||||
NRF52_TIM_CC4 = 4,
|
||||
NRF52_TIM_CC5 = 5
|
||||
};
|
||||
|
||||
/* Timer IRQ source */
|
||||
|
||||
enum nrf52_tim_irq_e
|
||||
{
|
||||
NRF52_TIM_INT_COMPARE0 = 0,
|
||||
NRF52_TIM_INT_COMPARE1 = 1,
|
||||
NRF52_TIM_INT_COMPARE2 = 2,
|
||||
NRF52_TIM_INT_COMPARE3 = 3,
|
||||
NRF52_TIM_INT_COMPARE4 = 4,
|
||||
NRF52_TIM_INT_COMPARE5 = 5,
|
||||
};
|
||||
|
||||
/* Timer shorts type */
|
||||
|
||||
enum nrf52_tim_shorts_e
|
||||
{
|
||||
NRF52_TIM_SHORT_COMPARE_CLEAR = 1,
|
||||
NRF52_TIM_SHORT_COMPARE_STOP = 2
|
||||
};
|
||||
|
||||
/* Timer frequency prescaler */
|
||||
|
||||
enum nrf52_tim_pre_e
|
||||
{
|
||||
NRF52_TIM_PRE_16000000 = 0,
|
||||
NRF52_TIM_PRE_8000000 = 1,
|
||||
NRF52_TIM_PRE_4000000 = 2,
|
||||
NRF52_TIM_PRE_2000000 = 3,
|
||||
NRF52_TIM_PRE_1000000 = 4,
|
||||
NRF52_TIM_PRE_500000 = 5,
|
||||
NRF52_TIM_PRE_250000 = 6,
|
||||
NRF52_TIM_PRE_125000 = 7,
|
||||
NRF52_TIM_PRE_62500 = 8,
|
||||
NRF52_TIM_PRE_31250 = 9
|
||||
};
|
||||
|
||||
/* NRF52 TIM device */
|
||||
|
||||
struct nrf52_tim_dev_s
|
||||
{
|
||||
struct nrf52_tim_ops_s *ops;
|
||||
};
|
||||
|
||||
/* NRF52 TIM ops */
|
||||
|
||||
struct nrf52_tim_ops_s
|
||||
{
|
||||
/* Timer tasks */
|
||||
|
||||
CODE int (*start)(FAR struct nrf52_tim_dev_s *dev);
|
||||
CODE int (*stop)(FAR struct nrf52_tim_dev_s *dev);
|
||||
CODE int (*clear)(FAR struct nrf52_tim_dev_s *dev);
|
||||
|
||||
/* Timer configuration */
|
||||
|
||||
CODE int (*configure)(FAR struct nrf52_tim_dev_s *dev, uint8_t mode,
|
||||
uint8_t width);
|
||||
CODE int (*shorts)(FAR struct nrf52_tim_dev_s *dev, uint8_t s,
|
||||
uint8_t i, bool en);
|
||||
|
||||
/* Timer operations */
|
||||
|
||||
CODE int (*count)(FAR struct nrf52_tim_dev_s *dev);
|
||||
CODE int (*setcc)(FAR struct nrf52_tim_dev_s *dev, uint8_t i, uint32_t cc);
|
||||
CODE int (*getcc)(FAR struct nrf52_tim_dev_s *dev, uint8_t i,
|
||||
FAR uint32_t *cc);
|
||||
CODE int (*setpre)(FAR struct nrf52_tim_dev_s *dev, uint8_t pre);
|
||||
|
||||
/* Timer interrupts */
|
||||
|
||||
CODE int (*setisr)(FAR struct nrf52_tim_dev_s *dev, xcpt_t handler,
|
||||
FAR void * arg);
|
||||
CODE int (*enableint)(FAR struct nrf52_tim_dev_s *dev, uint8_t source);
|
||||
CODE int (*disableint)(FAR struct nrf52_tim_dev_s *dev, uint8_t source);
|
||||
CODE int (*checkint)(FAR struct nrf52_tim_dev_s *dev, uint8_t source);
|
||||
CODE int (*ackint)(FAR struct nrf52_tim_dev_s *dev, uint8_t source);
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
FAR struct nrf52_tim_dev_s *nrf52_tim_init(int timer);
|
||||
int nrf52_tim_deinit(FAR struct nrf52_tim_dev_s *dev);
|
||||
|
||||
#endif /* __ARCH_ARM_SRC_NRF52_NRF52_TIM_H */
|
||||
Reference in New Issue
Block a user