Contiki 3.x
rtimer-arch.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 Nordic Semiconductor. All Rights Reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * 3. Neither the name of the copyright holder nor the names of its
13  * contributors may be used to endorse or promote products derived
14  * from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
19  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
20  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
25  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
27  * OF THE POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 /**
31  * \addtogroup nrf52832
32  * @{
33  *
34  * \file
35  * Implementation of the architecture dependent rtimer functions for the nRF52
36  *
37  * \author
38  * Wojciech Bober <wojciech.bober@nordicsemi.no>
39  */
40 /*---------------------------------------------------------------------------*/
41 #include <stdint.h>
42 #include <stddef.h>
43 #include "nrf.h"
44 #include "nrf_drv_timer.h"
45 #include "app_error.h"
46 #include "contiki.h"
47 #include "platform-conf.h"
48 
49 static const nrf_drv_timer_t timer = NRF_DRV_TIMER_INSTANCE(PLATFORM_TIMER_INSTANCE_ID); /**< Timer instance used for rtimer */
50 
51 /**
52  * \brief Handler for timer events.
53  *
54  * \param event_type type of an event that should be handled
55  * \param p_context opaque data pointer passed from nrf_drv_timer_init()
56  */
57 static void
58 timer_event_handler(nrf_timer_event_t event_type, void* p_context)
59 {
60  switch (event_type) {
61  case NRF_TIMER_EVENT_COMPARE1:
63  break;
64 
65  default:
66  //Do nothing.
67  break;
68  }
69 }
70 /*---------------------------------------------------------------------------*/
71 /**
72  * \brief Initialize platform rtimer
73  */
74 void
76 {
77  ret_code_t err_code = nrf_drv_timer_init(&timer, NULL, timer_event_handler);
78  APP_ERROR_CHECK(err_code);
79  nrf_drv_timer_enable(&timer);
80 }
81 /*---------------------------------------------------------------------------*/
82 /**
83  * \brief Schedules an rtimer task to be triggered at time t
84  * \param t The time when the task will need executed.
85  *
86  * \e t is an absolute time, in other words the task will be executed AT
87  * time \e t, not IN \e t rtimer ticks.
88  *
89  * This function schedules a one-shot event with the nRF RTC.
90  */
91 void
92 rtimer_arch_schedule(rtimer_clock_t t)
93 {
94  nrf_drv_timer_compare(&timer, NRF_TIMER_CC_CHANNEL1, t, true);
95 }
96 /*---------------------------------------------------------------------------*/
97 /**
98  * \brief Returns the current real-time clock time
99  * \return The current rtimer time in ticks
100  *
101  */
102 rtimer_clock_t
104 {
105  return nrf_drv_timer_capture(&timer, NRF_TIMER_CC_CHANNEL0);
106 }
107 /*---------------------------------------------------------------------------*/
108 /**
109  * @}
110  */
A timer.
Definition: timer.h:86
static void timer_event_handler(nrf_timer_event_t event_type, void *p_context)
Handler for timer events.
Definition: rtimer-arch.c:58
#define PLATFORM_TIMER_INSTANCE_ID
nRF52 timer instance to be used for Contiki rtimer driver.
rtimer_clock_t rtimer_arch_now()
Returns the current real-time clock time.
Definition: rtimer-arch.c:116
#define NULL
The null pointer.
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:60
void rtimer_run_next(void)
Execute the next real-time task and schedule the next task, if any.
Definition: rtimer.c:92
void rtimer_arch_schedule(rtimer_clock_t t)
Schedules an rtimer task to be triggered at time t.
Definition: rtimer-arch.c:72