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
* All rights reserved.
4
*
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions
7
* are met:
8
* 1. Redistributions of source code must retain the above copyright
9
* notice, this list of conditions and the following disclaimer.
10
* 2. Redistributions in binary form must reproduce the above copyright
11
* notice, this list of conditions and the following disclaimer in the
12
* documentation and/or other materials provided with the distribution.
13
* 3. Neither the name of the copyright holder nor the names of its
14
* contributors may be used to endorse or promote products derived
15
* from this software without specific prior written permission.
16
*
17
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
20
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
28
* OF THE POSSIBILITY OF SUCH DAMAGE.
29
*/
30
/**
31
* \addtogroup nrf52840
32
* @{
33
*
34
* \file
35
* Architecture dependent rtimer implementation header file.
36
*/
37
/*---------------------------------------------------------------------------*/
38
#include "contiki.h"
39
#include "nrf.h"
40
#include "nrf_timer.h"
41
42
#include <stdint.h>
43
#include <stddef.h>
44
/*---------------------------------------------------------------------------*/
45
/*
46
* Use Timer RTIMER_TIMER at 62500Hz. Generates 1 tick per exactly 16 usecs,
47
* which is exactly 1 .15.4 symbol period.
48
*/
49
#define TIMER_INSTANCE NRF_TIMER0
50
/*---------------------------------------------------------------------------*/
51
void
52
rtimer_arch_init
(
void
)
53
{
54
nrf_timer_event_clear(TIMER_INSTANCE, NRF_TIMER_EVENT_COMPARE0);
55
56
nrf_timer_frequency_set(TIMER_INSTANCE, NRF_TIMER_FREQ_62500Hz);
57
nrf_timer_bit_width_set(TIMER_INSTANCE, NRF_TIMER_BIT_WIDTH_32);
58
nrf_timer_mode_set(TIMER_INSTANCE, NRF_TIMER_MODE_TIMER);
59
nrf_timer_int_enable(TIMER_INSTANCE, NRF_TIMER_INT_COMPARE0_MASK);
60
NVIC_ClearPendingIRQ(TIMER0_IRQn);
61
NVIC_EnableIRQ(TIMER0_IRQn);
62
nrf_timer_task_trigger(TIMER_INSTANCE, NRF_TIMER_TASK_START);
63
}
64
/*---------------------------------------------------------------------------*/
65
/**
66
*
67
* This function schedules a one-shot event with the nRF RTC.
68
*/
69
void
70
rtimer_arch_schedule
(rtimer_clock_t t)
71
{
72
nrf_timer_cc_write(TIMER_INSTANCE, NRF_TIMER_CC_CHANNEL0, t);
73
}
74
/*---------------------------------------------------------------------------*/
75
rtimer_clock_t
76
rtimer_arch_now
()
77
{
78
nrf_timer_task_trigger(TIMER_INSTANCE, NRF_TIMER_TASK_CAPTURE1);
79
return
nrf_timer_cc_read(TIMER_INSTANCE, NRF_TIMER_CC_CHANNEL1);
80
}
81
/*---------------------------------------------------------------------------*/
82
void
83
TIMER0_IRQHandler(
void
)
84
{
85
if
(nrf_timer_event_check(TIMER_INSTANCE, NRF_TIMER_EVENT_COMPARE0)) {
86
nrf_timer_event_clear(TIMER_INSTANCE, NRF_TIMER_EVENT_COMPARE0);
87
rtimer_run_next
();
88
}
89
}
90
/*---------------------------------------------------------------------------*/
91
/**
92
* @}
93
*/
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
nrf52840
rtimer-arch.c
Generated on
for Contiki-NG by
1.17.0