Contiki 3.x
rtc.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014, Eistec AB.
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 contributors
14  * may be used to endorse or promote products derived from this software
15  * without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  *
29  * This file is part of the Mulle platform port of the Contiki operating system.
30  *
31  */
32 
33 /**
34  * \file
35  * Implementation of K60 RTC driver.
36  *
37  * \author
38  * Joakim Gebart <joakim.gebart@eistec.se>
39  */
40 
41 #include "rtc.h"
42 #include "K60.h"
43 #include "config-clocks.h"
44 #include "config-board.h"
45 
46 void
47 rtc_init(void)
48 {
49  /* System clock initialization, early boot */
50 
51  /* Enable clock gate for RTC module */
52  /* side note: It is ironic that we need to enable the clock gate for a clock module */
53  BITBAND_REG(SIM->SCGC6, SIM_SCGC6_RTC_SHIFT) = 1;
54 
55  /* Reset the RTC status */
56  RTC->SR = 0;
57 
58  /* Enable RTC clock, enable load capacitance as configured by config-board.h */
59  RTC->CR |= RTC_CR_OSCE_MASK | BOARD_RTC_LOAD_CAP_BITS;
60 }
61 
62 void
63 rtc_start(void) {
64  /* Enable RTC seconds counter. The RTC module has been initialized beforehand. */
65  BITBAND_REG(RTC->SR, RTC_SR_TCE_SHIFT) = 1;
66 }
67 
68 void
69 rtc_stop(void) {
70  /* Disable RTC seconds counter. */
71  BITBAND_REG(RTC->SR, RTC_SR_TCE_SHIFT) = 0;
72 }
73 
74 void
75 rtc_time_set(uint32_t seconds) {
76  /* Set the time */
77  RTC->TSR = seconds;
78 }
79 
80 uint32_t
81 rtc_time_get(void) {
82  return RTC->TSR;
83 }
84 
85 void
86 rtc_alarm_set(uint32_t alarm_time) {
87  RTC->TAR = alarm_time;
88 }
K60 clock configuration defines.
void rtc_stop(void)
Stop the RTC seconds counter.
Definition: rtc.c:69
#define SIM
Peripheral SIM base pointer.
Definition: MK60D10.h:7650
void rtc_init(void)
Initialize the RTC hardware.
Definition: rtc.c:47
Board configuration defines for Mulle platform.
K60 hardware register header wrapper.
uint32_t rtc_time_get(void)
Get the current time.
Definition: rtc.c:81
void rtc_start(void)
Enable the RTC seconds counter.
Definition: rtc.c:63
#define RTC
Peripheral RTC base pointer.
Definition: MK60D10.h:6872
void rtc_time_set(uint32_t seconds)
Set the time.
Definition: rtc.c:75
#define BOARD_RTC_LOAD_CAP_BITS
RTC crystal load capacitance configuration bits.
Definition: config-board.h:157
void rtc_alarm_set(uint32_t alarm_time)
Set alarm time.
Definition: rtc.c:86
#define BITBAND_REG(Reg, Bit)
Macro to access a single bit of a peripheral register (bit band region 0x40000000 to 0x400FFFFF) usin...
Definition: MK60D10.h:71