Contiki-NG
Toggle main menu visibility
Loading...
Searching...
No Matches
rtimer-arch.c
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2012, Texas Instruments Incorporated - http://www.ti.com/
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
*
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
* \addtogroup cc2538-rtimer
33
* @{
34
*
35
* \file
36
* Implementation of the arch-specific rtimer functions for the cc2538
37
*
38
*/
39
#include "contiki.h"
40
#include "
sys/rtimer.h
"
41
#include "
dev/nvic.h
"
42
#include "
dev/smwdthrosc.h
"
43
#include "
cpu.h
"
44
#include "
lpm.h
"
45
46
#include <stdint.h>
47
/*---------------------------------------------------------------------------*/
48
static
volatile
rtimer_clock_t next_trigger;
49
/*---------------------------------------------------------------------------*/
50
/**
51
* \brief We don't need to explicitly initialise anything but this
52
* routine is required by the API.
53
*
54
* The Sleep Timer starts ticking automatically as soon as the device
55
* turns on. We don't need to turn on interrupts before the first call
56
* to rtimer_arch_schedule()
57
*/
58
void
59
rtimer_arch_init
(
void
)
60
{
61
return
;
62
}
63
/*---------------------------------------------------------------------------*/
64
void
65
rtimer_arch_schedule
(rtimer_clock_t t)
66
{
67
rtimer_clock_t now;
68
69
/* STLOAD must be 1 */
70
while
((REG(
SMWDTHROSC_STLOAD
) &
SMWDTHROSC_STLOAD_STLOAD
) != 1);
71
72
INTERRUPTS_DISABLE
();
73
74
now =
RTIMER_NOW
();
75
76
/*
77
* New value must be 5 ticks in the future. The ST may tick once while we're
78
* writing the registers. We play it safe here and we add a bit of leeway
79
*/
80
if
(!RTIMER_CLOCK_LT(now, t - RTIMER_GUARD_TIME)) {
81
t = now + RTIMER_GUARD_TIME;
82
}
83
84
/* ST0 latches ST[1:3] and must be written last */
85
REG(
SMWDTHROSC_ST3
) = (t >> 24) & 0x000000FF;
86
REG(
SMWDTHROSC_ST2
) = (t >> 16) & 0x000000FF;
87
REG(
SMWDTHROSC_ST1
) = (t >> 8) & 0x000000FF;
88
REG(
SMWDTHROSC_ST0
) = t & 0x000000FF;
89
90
INTERRUPTS_ENABLE
();
91
92
/* Store the value. The LPM module will query us for it */
93
next_trigger = t;
94
95
NVIC_EnableIRQ(
SMT_IRQn
);
96
}
97
/*---------------------------------------------------------------------------*/
98
rtimer_clock_t
99
rtimer_arch_next_trigger
()
100
{
101
return
next_trigger;
102
}
103
/*---------------------------------------------------------------------------*/
104
/**
105
* \brief Returns the current real-time clock time
106
* \return The current rtimer time in ticks
107
*/
108
rtimer_clock_t
109
rtimer_arch_now
()
110
{
111
rtimer_clock_t rv;
112
113
/* SMWDTHROSC_ST0 latches ST[1:3] and must be read first */
114
rv = REG(
SMWDTHROSC_ST0
);
115
rv |= (REG(
SMWDTHROSC_ST1
) << 8);
116
rv |= (REG(
SMWDTHROSC_ST2
) << 16);
117
rv |= (REG(
SMWDTHROSC_ST3
) << 24);
118
119
return
rv;
120
}
121
/*---------------------------------------------------------------------------*/
122
/**
123
* \brief The rtimer ISR
124
*
125
* Interrupts are only turned on when we have an rtimer task to schedule
126
* Once the interrupt fires, the task is called and then interrupts no
127
* longer get acknowledged until the next task needs scheduled.
128
*/
129
void
130
rtimer_isr
()
131
{
132
/*
133
* If we were in PM1+, call the wake-up sequence first. This will make sure
134
* that the 32MHz OSC is selected as the clock source. We need to do this
135
* before calling the next rtimer_task, since the task may need the RF.
136
*/
137
lpm_exit();
138
139
next_trigger = 0;
140
141
NVIC_ClearPendingIRQ(
SMT_IRQn
);
142
NVIC_DisableIRQ(
SMT_IRQn
);
143
144
rtimer_run_next
();
145
}
146
/*---------------------------------------------------------------------------*/
147
/** @} */
lpm.h
Header file with register, macro and function declarations for the cc2538 low power module.
cpu.h
Header file with prototypes for interrupt control on the cc2538 Cortex-M3 micro.
SMT_IRQn
@ SMT_IRQn
SM Timer Interrupt.
Definition
cc2538_cm3.h:113
INTERRUPTS_DISABLE
#define INTERRUPTS_DISABLE()
Disables all CPU interrupts.
Definition
cpu.h:54
INTERRUPTS_ENABLE
#define INTERRUPTS_ENABLE()
Enables all CPU interrupts.
Definition
cpu.h:51
rtimer_arch_next_trigger
rtimer_clock_t rtimer_arch_next_trigger()
Get the time of the next scheduled rtimer trigger.
Definition
rtimer-arch.c:99
rtimer_isr
void rtimer_isr()
The rtimer ISR.
Definition
rtimer-arch.c:130
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
SMWDTHROSC_ST0
#define SMWDTHROSC_ST0
ST count/compare value 0.
Definition
smwdthrosc.h:51
SMWDTHROSC_ST3
#define SMWDTHROSC_ST3
ST count/compare value 3.
Definition
smwdthrosc.h:54
SMWDTHROSC_ST1
#define SMWDTHROSC_ST1
ST count/compare value 1.
Definition
smwdthrosc.h:52
SMWDTHROSC_ST2
#define SMWDTHROSC_ST2
ST count/compare value 2.
Definition
smwdthrosc.h:53
SMWDTHROSC_STLOAD
#define SMWDTHROSC_STLOAD
Compare value load status.
Definition
smwdthrosc.h:55
SMWDTHROSC_STLOAD_STLOAD
#define SMWDTHROSC_STLOAD_STLOAD
STx upload status signal.
Definition
smwdthrosc.h:89
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
RTIMER_NOW
#define RTIMER_NOW()
Get the current clock time.
Definition
rtimer.h:191
nvic.h
Header file for the ARM Nested Vectored Interrupt Controller.
rtimer.h
Header file for the real-time timer module.
smwdthrosc.h
Header file with register declarations and bit masks for the cc2538 Sleep Timer and Watchdog.
arch
cpu
cc2538
rtimer-arch.c
Generated on
for Contiki-NG by
1.17.0