Contiki-NG
Toggle main menu visibility
Loading...
Searching...
No Matches
rtimer-arch.c
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2020, Toshiba BRIL
3
* Copyright (C) 2020 Yago Fontoura do Rosario <yago.rosario@hotmail.com.br>
4
* All rights reserved.
5
*
6
* Redistribution and use in source and binary forms, with or without
7
* modification, are permitted provided that the following conditions
8
* are met:
9
* 1. Redistributions of source code must retain the above copyright
10
* notice, this list of conditions and the following disclaimer.
11
* 2. Redistributions in binary form must reproduce the above copyright
12
* notice, this list of conditions and the following disclaimer in the
13
* documentation and/or other materials provided with the distribution.
14
* 3. Neither the name of the copyright holder nor the names of its
15
* contributors may be used to endorse or promote products derived
16
* from this software without specific prior written permission.
17
*
18
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
29
* OF THE POSSIBILITY OF SUCH DAMAGE.
30
*/
31
/*---------------------------------------------------------------------------*/
32
/**
33
* \addtogroup nrf
34
* @{
35
*
36
* \addtogroup nrf-sys System drivers
37
* @{
38
*
39
* \addtogroup nrf-rtimer Rtimer driver
40
* @{
41
*
42
* \file
43
* Implementation of the architecture dependent rtimer functions for the nRF
44
* \author
45
* Yago Fontoura do Rosario <yago.rosario@hotmail.com.br>
46
*
47
*/
48
/*---------------------------------------------------------------------------*/
49
#include "contiki.h"
50
51
#include "nrf.h"
52
#include "hal/nrf_timer.h"
53
54
#ifdef NRF_RTIMER_CONF_TIMER_INSTANCE
55
#define TIMER_INSTANCE NRF_RTIMER_CONF_TIMER_INSTANCE
56
#else
57
#define TIMER_INSTANCE 0
58
#endif
59
60
#if TIMER_INSTANCE == 0
61
#define NRF_RTIMER_TIMER NRF_TIMER0
62
#define NRF_RTIMER_IRQn TIMER0_IRQn
63
#define NRF_RTIMER_IRQHandler TIMER0_IRQHandler
64
#elif TIMER_INSTANCE == 1
65
#define NRF_RTIMER_TIMER NRF_TIMER1
66
#define NRF_RTIMER_IRQn TIMER1_IRQn
67
#define NRF_RTIMER_IRQHandler TIMER1_IRQHandler
68
#else
69
#error Unsupported timer for rtimer
70
#endif
71
72
/*---------------------------------------------------------------------------*/
73
void
74
rtimer_arch_init
(
void
)
75
{
76
nrf_timer_event_clear(NRF_RTIMER_TIMER, NRF_TIMER_EVENT_COMPARE0);
77
78
/* 16 MHz / 2^8 = 62500 Hz. Newer nrfx removed nrf_timer_frequency_set(). */
79
nrf_timer_prescaler_set(NRF_RTIMER_TIMER, 8);
80
nrf_timer_bit_width_set(NRF_RTIMER_TIMER, NRF_TIMER_BIT_WIDTH_32);
81
nrf_timer_mode_set(NRF_RTIMER_TIMER, NRF_TIMER_MODE_TIMER);
82
nrf_timer_int_enable(NRF_RTIMER_TIMER, NRF_TIMER_INT_COMPARE0_MASK);
83
NVIC_ClearPendingIRQ(NRF_RTIMER_IRQn);
84
NVIC_EnableIRQ(NRF_RTIMER_IRQn);
85
nrf_timer_task_trigger(NRF_RTIMER_TIMER, NRF_TIMER_TASK_START);
86
}
87
/*---------------------------------------------------------------------------*/
88
void
89
rtimer_arch_schedule
(rtimer_clock_t t)
90
{
91
/*
92
* This function schedules a one-shot event with the nRF RTC.
93
*/
94
nrf_timer_cc_set(NRF_RTIMER_TIMER, NRF_TIMER_CC_CHANNEL0, t);
95
}
96
/*---------------------------------------------------------------------------*/
97
rtimer_clock_t
98
rtimer_arch_now
()
99
{
100
nrf_timer_task_trigger(NRF_RTIMER_TIMER, NRF_TIMER_TASK_CAPTURE1);
101
return
nrf_timer_cc_get(NRF_RTIMER_TIMER, NRF_TIMER_CC_CHANNEL1);
102
}
103
/*---------------------------------------------------------------------------*/
104
void
105
NRF_RTIMER_IRQHandler(
void
)
106
{
107
if
(nrf_timer_event_check(NRF_RTIMER_TIMER, NRF_TIMER_EVENT_COMPARE0)) {
108
nrf_timer_event_clear(NRF_RTIMER_TIMER, NRF_TIMER_EVENT_COMPARE0);
109
rtimer_run_next
();
110
}
111
}
112
/*---------------------------------------------------------------------------*/
113
/**
114
* @}
115
* @}
116
* @}
117
*/
rtimer_arch_init
void rtimer_arch_init(void)
We don't need to explicitly initialise anything but this routine is required by the API.
Definition
rtimer-arch.c:59
rtimer_arch_now
rtimer_clock_t rtimer_arch_now()
Returns the current real-time clock time.
Definition
rtimer-arch.c:109
rtimer_arch_schedule
void rtimer_arch_schedule(rtimer_clock_t t)
Schedules an rtimer task to be triggered at time t.
Definition
rtimer-arch.c:65
rtimer_run_next
void rtimer_run_next(void)
Execute the next real-time task and schedule the next task, if any.
Definition
rtimer.c:78
arch
cpu
nrf
sys
rtimer-arch.c
Generated on
for Contiki-NG by
1.17.0