mbed library sources
Dependents: frdm_kl05z_gpio_test
Fork of mbed-src by
targets/hal/TARGET_STM/TARGET_NUCLEO_F103RB/rtc_api.c@60:142c6c6f5949, 2013-12-17 (annotated)
- Committer:
- mbed_official
- Date:
- Tue Dec 17 08:45:10 2013 +0000
- Revision:
- 60:142c6c6f5949
- Child:
- 62:7731d679ae64
Synchronized with git revision 572b22395f1ebb513f4fbd423214cb39a18dc58b
Full URL: https://github.com/mbedmicro/mbed/commit/572b22395f1ebb513f4fbd423214cb39a18dc58b/
[NUCLEO_F103RB] InterruptIn, Sleep, RTC added
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 60:142c6c6f5949 | 1 | /* mbed Microcontroller Library |
mbed_official | 60:142c6c6f5949 | 2 | * Copyright (c) 2006-2013 ARM Limited |
mbed_official | 60:142c6c6f5949 | 3 | * |
mbed_official | 60:142c6c6f5949 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
mbed_official | 60:142c6c6f5949 | 5 | * you may not use this file except in compliance with the License. |
mbed_official | 60:142c6c6f5949 | 6 | * You may obtain a copy of the License at |
mbed_official | 60:142c6c6f5949 | 7 | * |
mbed_official | 60:142c6c6f5949 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
mbed_official | 60:142c6c6f5949 | 9 | * |
mbed_official | 60:142c6c6f5949 | 10 | * Unless required by applicable law or agreed to in writing, software |
mbed_official | 60:142c6c6f5949 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
mbed_official | 60:142c6c6f5949 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
mbed_official | 60:142c6c6f5949 | 13 | * See the License for the specific language governing permissions and |
mbed_official | 60:142c6c6f5949 | 14 | * limitations under the License. |
mbed_official | 60:142c6c6f5949 | 15 | */ |
mbed_official | 60:142c6c6f5949 | 16 | #include "rtc_api.h" |
mbed_official | 60:142c6c6f5949 | 17 | |
mbed_official | 60:142c6c6f5949 | 18 | static int rtc_inited = 0; |
mbed_official | 60:142c6c6f5949 | 19 | |
mbed_official | 60:142c6c6f5949 | 20 | void rtc_init(void) { |
mbed_official | 60:142c6c6f5949 | 21 | RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE); // Enable PWR and Backup clock |
mbed_official | 60:142c6c6f5949 | 22 | |
mbed_official | 60:142c6c6f5949 | 23 | PWR_BackupAccessCmd(ENABLE); // Allow access to Backup Domain |
mbed_official | 60:142c6c6f5949 | 24 | |
mbed_official | 60:142c6c6f5949 | 25 | BKP_DeInit(); // Reset Backup Domain |
mbed_official | 60:142c6c6f5949 | 26 | |
mbed_official | 60:142c6c6f5949 | 27 | // Enable LSE and wait till it's ready |
mbed_official | 60:142c6c6f5949 | 28 | RCC_LSEConfig(RCC_LSE_ON); |
mbed_official | 60:142c6c6f5949 | 29 | while (RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET) {} |
mbed_official | 60:142c6c6f5949 | 30 | |
mbed_official | 60:142c6c6f5949 | 31 | RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE); // Select LSE as RTC Clock Source |
mbed_official | 60:142c6c6f5949 | 32 | |
mbed_official | 60:142c6c6f5949 | 33 | RCC_RTCCLKCmd(ENABLE); // Enable RTC Clock |
mbed_official | 60:142c6c6f5949 | 34 | |
mbed_official | 60:142c6c6f5949 | 35 | RTC_WaitForSynchro(); // Wait for RTC registers synchronization |
mbed_official | 60:142c6c6f5949 | 36 | |
mbed_official | 60:142c6c6f5949 | 37 | RTC_WaitForLastTask(); // Wait until last write operation on RTC registers has finished |
mbed_official | 60:142c6c6f5949 | 38 | |
mbed_official | 60:142c6c6f5949 | 39 | // Set RTC period to 1 sec |
mbed_official | 60:142c6c6f5949 | 40 | // RTC period = RTCCLK/RTC_PR = (32.768 KHz)/(32767+1) |
mbed_official | 60:142c6c6f5949 | 41 | RTC_SetPrescaler(32767); |
mbed_official | 60:142c6c6f5949 | 42 | |
mbed_official | 60:142c6c6f5949 | 43 | RTC_WaitForLastTask(); // Wait until last write operation on RTC registers has finished |
mbed_official | 60:142c6c6f5949 | 44 | |
mbed_official | 60:142c6c6f5949 | 45 | rtc_inited = 1; |
mbed_official | 60:142c6c6f5949 | 46 | } |
mbed_official | 60:142c6c6f5949 | 47 | |
mbed_official | 60:142c6c6f5949 | 48 | void rtc_free(void) { |
mbed_official | 60:142c6c6f5949 | 49 | RCC_DeInit(); // Resets the RCC clock configuration to the default reset state |
mbed_official | 60:142c6c6f5949 | 50 | rtc_inited = 0; |
mbed_official | 60:142c6c6f5949 | 51 | } |
mbed_official | 60:142c6c6f5949 | 52 | |
mbed_official | 60:142c6c6f5949 | 53 | int rtc_isenabled(void) { |
mbed_official | 60:142c6c6f5949 | 54 | return rtc_inited; |
mbed_official | 60:142c6c6f5949 | 55 | } |
mbed_official | 60:142c6c6f5949 | 56 | |
mbed_official | 60:142c6c6f5949 | 57 | time_t rtc_read(void) { |
mbed_official | 60:142c6c6f5949 | 58 | return (time_t)RTC_GetCounter(); |
mbed_official | 60:142c6c6f5949 | 59 | } |
mbed_official | 60:142c6c6f5949 | 60 | |
mbed_official | 60:142c6c6f5949 | 61 | void rtc_write(time_t t) { |
mbed_official | 60:142c6c6f5949 | 62 | RTC_WaitForLastTask(); // Wait until last write operation on RTC registers has finished |
mbed_official | 60:142c6c6f5949 | 63 | RTC_SetCounter(t); // Change the current time |
mbed_official | 60:142c6c6f5949 | 64 | RTC_WaitForLastTask(); // Wait until last write operation on RTC registers has finished |
mbed_official | 60:142c6c6f5949 | 65 | } |