mbed library sources

Dependents:   Encrypted my_mbed lklk CyaSSL_DTLS_Cellular ... more

Superseded

This library was superseded by mbed-dev - https://os.mbed.com/users/mbed_official/code/mbed-dev/.

Development branch of the mbed library sources. This library is kept in synch with the latest changes from the mbed SDK and it is not guaranteed to work.

If you are looking for a stable and tested release, please import one of the official mbed library releases:

Import librarymbed

The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Committer:
mbed_official
Date:
Thu Apr 03 11:45:06 2014 +0100
Revision:
149:1fb5f62b92bd
Parent:
targets/hal/TARGET_Freescale/TARGET_KSDK_MCUS/TARGET_KSDK_CODE/hal/rtc/fsl_rtc_hal.c@146:f64d43ff0c18
Child:
324:406fd2029f23
Synchronized with git revision 220c0bb39ceee40016e1e86350c058963d01ed42

Full URL: https://github.com/mbedmicro/mbed/commit/220c0bb39ceee40016e1e86350c058963d01ed42/

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 146:f64d43ff0c18 1 /*
mbed_official 146:f64d43ff0c18 2 * Copyright (c) 2013 - 2014, Freescale Semiconductor, Inc.
mbed_official 146:f64d43ff0c18 3 * All rights reserved.
mbed_official 146:f64d43ff0c18 4 *
mbed_official 146:f64d43ff0c18 5 * Redistribution and use in source and binary forms, with or without modification,
mbed_official 146:f64d43ff0c18 6 * are permitted provided that the following conditions are met:
mbed_official 146:f64d43ff0c18 7 *
mbed_official 146:f64d43ff0c18 8 * o Redistributions of source code must retain the above copyright notice, this list
mbed_official 146:f64d43ff0c18 9 * of conditions and the following disclaimer.
mbed_official 146:f64d43ff0c18 10 *
mbed_official 146:f64d43ff0c18 11 * o Redistributions in binary form must reproduce the above copyright notice, this
mbed_official 146:f64d43ff0c18 12 * list of conditions and the following disclaimer in the documentation and/or
mbed_official 146:f64d43ff0c18 13 * other materials provided with the distribution.
mbed_official 146:f64d43ff0c18 14 *
mbed_official 146:f64d43ff0c18 15 * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
mbed_official 146:f64d43ff0c18 16 * contributors may be used to endorse or promote products derived from this
mbed_official 146:f64d43ff0c18 17 * software without specific prior written permission.
mbed_official 146:f64d43ff0c18 18 *
mbed_official 146:f64d43ff0c18 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
mbed_official 146:f64d43ff0c18 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
mbed_official 146:f64d43ff0c18 21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
mbed_official 146:f64d43ff0c18 22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
mbed_official 146:f64d43ff0c18 23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
mbed_official 146:f64d43ff0c18 24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
mbed_official 146:f64d43ff0c18 25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
mbed_official 146:f64d43ff0c18 26 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
mbed_official 146:f64d43ff0c18 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
mbed_official 146:f64d43ff0c18 28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mbed_official 146:f64d43ff0c18 29 */
mbed_official 146:f64d43ff0c18 30
mbed_official 146:f64d43ff0c18 31 #include "fsl_rtc_hal.h"
mbed_official 146:f64d43ff0c18 32 #include "fsl_device_registers.h"
mbed_official 146:f64d43ff0c18 33
mbed_official 146:f64d43ff0c18 34 /*******************************************************************************
mbed_official 146:f64d43ff0c18 35 * Code
mbed_official 146:f64d43ff0c18 36 ******************************************************************************/
mbed_official 146:f64d43ff0c18 37
mbed_official 146:f64d43ff0c18 38
mbed_official 146:f64d43ff0c18 39 /*FUNCTION**********************************************************************
mbed_official 146:f64d43ff0c18 40 *
mbed_official 146:f64d43ff0c18 41 * Function Name : rtc_hal_init
mbed_official 146:f64d43ff0c18 42 * Description : initializes the RTC module.
mbed_official 146:f64d43ff0c18 43 * This function will first configure the oscillator load in pF, set/clear the
mbed_official 146:f64d43ff0c18 44 * 32kHz clock out to peripheral, enable/disable 32.768 kHz oscillator. After
mbed_official 146:f64d43ff0c18 45 * setting 32.768 kHz oscillator bit, wait the oscillator startup time before
mbed_official 146:f64d43ff0c18 46 * enabling the time counter to allow the 32.768 kHz clock time to stabilize.
mbed_official 146:f64d43ff0c18 47 * If devices have the wakeup pin, this function will enable/disable the wakeup
mbed_official 146:f64d43ff0c18 48 * pin. Then this function configures time prescaler, time seconds, time alarm,
mbed_official 146:f64d43ff0c18 49 * the compensation interval in seconds from 1 to 256 if requested, and the
mbed_official 146:f64d43ff0c18 50 * number of 32.768 kHz clock cycles in each second. This function also
mbed_official 146:f64d43ff0c18 51 * enable/disable the RTC interrupts as requested.
mbed_official 146:f64d43ff0c18 52 *
mbed_official 146:f64d43ff0c18 53 *END**************************************************************************/
mbed_official 146:f64d43ff0c18 54 void rtc_hal_init(rtc_hal_init_config_t * configs)
mbed_official 146:f64d43ff0c18 55 {
mbed_official 146:f64d43ff0c18 56 /* check for null pointer*/
mbed_official 146:f64d43ff0c18 57 if(NULL == configs)
mbed_official 146:f64d43ff0c18 58 {
mbed_official 146:f64d43ff0c18 59 return;
mbed_official 146:f64d43ff0c18 60 }
mbed_official 146:f64d43ff0c18 61
mbed_official 146:f64d43ff0c18 62 /* Clear to the default value */
mbed_official 146:f64d43ff0c18 63 HW_RTC_CR_WR(0x0);
mbed_official 146:f64d43ff0c18 64
mbed_official 146:f64d43ff0c18 65 /* Use the following macro masks to set the flags which enable load config
mbed_official 146:f64d43ff0c18 66 */
mbed_official 146:f64d43ff0c18 67 switch(configs->enableOscillatorLoadConfg)
mbed_official 146:f64d43ff0c18 68 {
mbed_official 146:f64d43ff0c18 69 case 2:
mbed_official 146:f64d43ff0c18 70 HW_RTC_CR_WR(BM_RTC_CR_SC2P);
mbed_official 146:f64d43ff0c18 71 break;
mbed_official 146:f64d43ff0c18 72 case 4:
mbed_official 146:f64d43ff0c18 73 HW_RTC_CR_WR(BM_RTC_CR_SC4P);
mbed_official 146:f64d43ff0c18 74 break;
mbed_official 146:f64d43ff0c18 75 case 8:
mbed_official 146:f64d43ff0c18 76 HW_RTC_CR_WR(BM_RTC_CR_SC8P);
mbed_official 146:f64d43ff0c18 77 break;
mbed_official 146:f64d43ff0c18 78 case 16:
mbed_official 146:f64d43ff0c18 79 HW_RTC_CR_WR(BM_RTC_CR_SC16P);
mbed_official 146:f64d43ff0c18 80 break;
mbed_official 146:f64d43ff0c18 81 default:
mbed_official 146:f64d43ff0c18 82 break;
mbed_official 146:f64d43ff0c18 83 }
mbed_official 146:f64d43ff0c18 84
mbed_official 146:f64d43ff0c18 85 BW_RTC_CR_CLKO((uint32_t)configs->disableClockOutToPeripheral);
mbed_official 146:f64d43ff0c18 86
mbed_official 146:f64d43ff0c18 87 /* After enabling this, will wait the oscillator startup time before enabling
mbed_official 146:f64d43ff0c18 88 * the time counter TSR[TSR] to allow the 32.768 kHz clock time to stabilize.
mbed_official 146:f64d43ff0c18 89 */
mbed_official 146:f64d43ff0c18 90 BW_RTC_CR_OSCE((uint32_t)configs->enable32kOscillator);
mbed_official 146:f64d43ff0c18 91
mbed_official 146:f64d43ff0c18 92 #if FSL_FEATURE_RTC_HAS_WAKEUP_PIN
mbed_official 146:f64d43ff0c18 93 /*! For devices that have the wakeup pin this variable will indicate if it is
mbed_official 146:f64d43ff0c18 94 * to be enabled (set to 'true') or not (set to 'false'). \n
mbed_official 146:f64d43ff0c18 95 * See the device's user manual for details depending on each device's
mbed_official 146:f64d43ff0c18 96 * specific wakeup pin feature implementation.
mbed_official 146:f64d43ff0c18 97 */
mbed_official 146:f64d43ff0c18 98 BW_RTC_CR_WPE((uint32_t)configs->enableWakeupPin);
mbed_official 146:f64d43ff0c18 99 #endif
mbed_official 146:f64d43ff0c18 100
mbed_official 146:f64d43ff0c18 101 /* write prescaler before writing to counter register*/
mbed_official 146:f64d43ff0c18 102 if(configs->prescalerAt)
mbed_official 146:f64d43ff0c18 103 {
mbed_official 146:f64d43ff0c18 104 BW_RTC_SR_TCE(0x00U); /* disable counter before configuring the prescaler*/
mbed_official 146:f64d43ff0c18 105 HW_RTC_TPR_WR(configs->prescalerAt);
mbed_official 146:f64d43ff0c18 106 }
mbed_official 146:f64d43ff0c18 107
mbed_official 146:f64d43ff0c18 108 /* write time seconds should be written before writing to counter register*/
mbed_official 146:f64d43ff0c18 109 if(configs->startSecondsCounterAt)
mbed_official 146:f64d43ff0c18 110 {
mbed_official 146:f64d43ff0c18 111 BW_RTC_SR_TCE(0x00U); /* disable time counter before configuring*/
mbed_official 146:f64d43ff0c18 112 HW_RTC_TSR_WR(configs->startSecondsCounterAt);
mbed_official 146:f64d43ff0c18 113 }
mbed_official 146:f64d43ff0c18 114
mbed_official 146:f64d43ff0c18 115 if(configs->alarmCounterAt)
mbed_official 146:f64d43ff0c18 116 {
mbed_official 146:f64d43ff0c18 117 HW_RTC_TAR_WR(configs->alarmCounterAt);
mbed_official 146:f64d43ff0c18 118 }
mbed_official 146:f64d43ff0c18 119
mbed_official 146:f64d43ff0c18 120 /* Configures the compensation interval in seconds from 1 to 256 to control
mbed_official 146:f64d43ff0c18 121 * how frequently the TCR should adjust the number of 32.768 kHz cycles in
mbed_official 146:f64d43ff0c18 122 * each second. The value written should be one less than the number of
mbed_official 146:f64d43ff0c18 123 * seconds (for example, write zero to configure for a compensation interval
mbed_official 146:f64d43ff0c18 124 * of one second). This register is double buffered and writes do not take
mbed_official 146:f64d43ff0c18 125 * affect until the end of the current compensation interval.
mbed_official 146:f64d43ff0c18 126 */
mbed_official 146:f64d43ff0c18 127 if(configs->compensationInterval)
mbed_official 146:f64d43ff0c18 128 {
mbed_official 146:f64d43ff0c18 129 BW_RTC_TCR_CIR(configs->compensationInterval);
mbed_official 146:f64d43ff0c18 130 }
mbed_official 146:f64d43ff0c18 131
mbed_official 146:f64d43ff0c18 132 /* Configures the number of 32.768 kHz clock cycles in each second. This
mbed_official 146:f64d43ff0c18 133 * register is double buffered and writes do not take affect until the end
mbed_official 146:f64d43ff0c18 134 * of the current compensation interval.\n
mbed_official 146:f64d43ff0c18 135 * \n
mbed_official 146:f64d43ff0c18 136 * 80h Time prescaler register overflows every 32896 clock cycles.\n
mbed_official 146:f64d43ff0c18 137 * ... ...\n
mbed_official 146:f64d43ff0c18 138 * FFh Time prescaler register overflows every 32769 clock cycles.\n
mbed_official 146:f64d43ff0c18 139 * 00h Time prescaler register overflows every 32768 clock cycles.\n
mbed_official 146:f64d43ff0c18 140 * 01h Time prescaler register overflows every 32767 clock cycles.\n
mbed_official 146:f64d43ff0c18 141 * ... ...\n
mbed_official 146:f64d43ff0c18 142 * 7Fh Time prescaler register overflows every 32641 clock cycles.\n
mbed_official 146:f64d43ff0c18 143 */
mbed_official 146:f64d43ff0c18 144 BW_RTC_TCR_TCR(configs->timeCompensation);
mbed_official 146:f64d43ff0c18 145
mbed_official 146:f64d43ff0c18 146 /* Set/clear any of the following bitfields to enable/disable the
mbed_official 146:f64d43ff0c18 147 * respective interrupts.\n
mbed_official 146:f64d43ff0c18 148 * TSIE: Time Seconds Interrupt Enable \n
mbed_official 146:f64d43ff0c18 149 * TAIE: Time Alarm Interrupt Enable \n
mbed_official 146:f64d43ff0c18 150 * TOIE: Time Overflow Interrupt Enable \n
mbed_official 146:f64d43ff0c18 151 * TIIE: Time Invalid Interrupt Enable \n
mbed_official 146:f64d43ff0c18 152 * \n
mbed_official 146:f64d43ff0c18 153 * For MCUs that have the Wakeup Pin only: \n
mbed_official 146:f64d43ff0c18 154 * WPON: Wakeup Pin On (see the corresponding MCU's reference manual)\n
mbed_official 146:f64d43ff0c18 155 * \n
mbed_official 146:f64d43ff0c18 156 * For MCUs that have the Monotonic Counter only: \n
mbed_official 146:f64d43ff0c18 157 * MOIE: Monotonic Overflow Interrupt Enable \n
mbed_official 146:f64d43ff0c18 158 */
mbed_official 146:f64d43ff0c18 159 rtc_hal_config_interrupts(&(configs->enableInterrupts));
mbed_official 146:f64d43ff0c18 160
mbed_official 146:f64d43ff0c18 161 #if FSL_FEATURE_RTC_HAS_MONOTONIC
mbed_official 146:f64d43ff0c18 162 if(configs->monotonicCounterAt)
mbed_official 146:f64d43ff0c18 163 {
mbed_official 146:f64d43ff0c18 164 rtc_hal_set_monotonic_counter(configs->monotonicCounterAt);
mbed_official 146:f64d43ff0c18 165 }
mbed_official 146:f64d43ff0c18 166 #endif
mbed_official 146:f64d43ff0c18 167 }
mbed_official 146:f64d43ff0c18 168
mbed_official 146:f64d43ff0c18 169 /*******************************************************************************
mbed_official 146:f64d43ff0c18 170 * EOF
mbed_official 146:f64d43ff0c18 171 ******************************************************************************/
mbed_official 146:f64d43ff0c18 172