Contiki-NG
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
48static const nrf_drv_timer_t timer = NRF_DRV_TIMER_INSTANCE(PLATFORM_TIMER_INSTANCE_ID); /**< Timer instance used for rtimer */
49
50/**
51 * \brief Handler for timer events.
52 *
53 * \param event_type type of an event that should be handled
54 * \param p_context opaque data pointer passed from nrf_drv_timer_init()
55 */
56static void
57timer_event_handler(nrf_timer_event_t event_type, void* p_context)
58{
59 switch (event_type) {
60 case NRF_TIMER_EVENT_COMPARE1:
62 break;
63
64 default:
65 //Do nothing.
66 break;
67 }
68}
69/*---------------------------------------------------------------------------*/
70/**
71 * \brief Initialize platform rtimer
72 */
73void
75{
76 ret_code_t err_code = nrf_drv_timer_init(&timer, NULL, timer_event_handler);
77 APP_ERROR_CHECK(err_code);
78 nrf_drv_timer_enable(&timer);
79}
80/*---------------------------------------------------------------------------*/
81/**
82 *
83 * This function schedules a one-shot event with the nRF RTC.
84 */
85void
86rtimer_arch_schedule(rtimer_clock_t t)
87{
88 nrf_drv_timer_compare(&timer, NRF_TIMER_CC_CHANNEL1, t, true);
89}
90/*---------------------------------------------------------------------------*/
91/**
92 * \brief Returns the current real-time clock time
93 * \return The current rtimer time in ticks
94 *
95 */
96rtimer_clock_t
98{
99 return nrf_drv_timer_capture(&timer, NRF_TIMER_CC_CHANNEL0);
100}
101/*---------------------------------------------------------------------------*/
102/**
103 * @}
104 */
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_clock_t rtimer_arch_now()
Returns the current real-time clock time.
Definition: rtimer-arch.c:109
void rtimer_arch_schedule(rtimer_clock_t t)
Schedules an rtimer task to be triggered at time t.
Definition: rtimer-arch.c:65
static void timer_event_handler(nrf_timer_event_t event_type, void *p_context)
Handler for timer events.
Definition: rtimer-arch.c:57
#define PLATFORM_TIMER_INSTANCE_ID
nRF52 timer instance to be used for Contiki rtimer driver.
void rtimer_run_next(void)
Execute the next real-time task and schedule the next task, if any.
Definition: rtimer.c:92
A timer.
Definition: timer.h:82