Contiki-NG
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 void
56 {
57  nrf_timer_event_clear(NRF_TIMER0, NRF_TIMER_EVENT_COMPARE0);
58 
59  nrf_timer_frequency_set(NRF_TIMER0, NRF_TIMER_FREQ_62500Hz);
60  nrf_timer_bit_width_set(NRF_TIMER0, NRF_TIMER_BIT_WIDTH_32);
61  nrf_timer_mode_set(NRF_TIMER0, NRF_TIMER_MODE_TIMER);
62  nrf_timer_int_enable(NRF_TIMER0, NRF_TIMER_INT_COMPARE0_MASK);
63  NVIC_ClearPendingIRQ(TIMER0_IRQn);
64  NVIC_EnableIRQ(TIMER0_IRQn);
65  nrf_timer_task_trigger(NRF_TIMER0, NRF_TIMER_TASK_START);
66 }
67 /*---------------------------------------------------------------------------*/
68 void
69 rtimer_arch_schedule(rtimer_clock_t t)
70 {
71  /*
72  * This function schedules a one-shot event with the nRF RTC.
73  */
74  nrf_timer_cc_set(NRF_TIMER0, NRF_TIMER_CC_CHANNEL0, t);
75 }
76 /*---------------------------------------------------------------------------*/
77 rtimer_clock_t
79 {
80  nrf_timer_task_trigger(NRF_TIMER0, NRF_TIMER_TASK_CAPTURE1);
81  return nrf_timer_cc_get(NRF_TIMER0, NRF_TIMER_CC_CHANNEL1);
82 }
83 /*---------------------------------------------------------------------------*/
84 void
85 TIMER0_IRQHandler(void)
86 {
87  if(nrf_timer_event_check(NRF_TIMER0, NRF_TIMER_EVENT_COMPARE0)) {
88  nrf_timer_event_clear(NRF_TIMER0, NRF_TIMER_EVENT_COMPARE0);
90  }
91 }
92 /*---------------------------------------------------------------------------*/
93 /**
94  * @}
95  * @}
96  * @}
97  */
rtimer_clock_t rtimer_arch_now()
Returns the current real-time clock time.
Definition: rtimer-arch.c:115
void rtimer_arch_schedule(rtimer_clock_t t)
Schedules an rtimer task to be triggered at time t.
Definition: rtimer-arch.c:71
void rtimer_arch_init(void)
We don&#39;t need to explicitly initialise anything but this routine is required by the API...
Definition: rtimer-arch.c:59
void rtimer_run_next(void)
Execute the next real-time task and schedule the next task, if any.
Definition: rtimer.c:92