mbed library sources

Fork of mbed-src by mbed official

Committer:
mbed_official
Date:
Wed Jul 08 14:45:08 2015 +0100
Revision:
585:a1ed5b41f74f
Child:
619:034e698bc035
Synchronized with git revision 7a2b57896e0263b82f31ddc5a0ad2443615db184

Full URL: https://github.com/mbedmicro/mbed/commit/7a2b57896e0263b82f31ddc5a0ad2443615db184/

Add rtc_api.c

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 585:a1ed5b41f74f 1 /* mbed Microcontroller Library
mbed_official 585:a1ed5b41f74f 2 * Copyright (c) 2006-2013 ARM Limited
mbed_official 585:a1ed5b41f74f 3 *
mbed_official 585:a1ed5b41f74f 4 * Licensed under the Apache License, Version 2.0 (the "License");
mbed_official 585:a1ed5b41f74f 5 * you may not use this file except in compliance with the License.
mbed_official 585:a1ed5b41f74f 6 * You may obtain a copy of the License at
mbed_official 585:a1ed5b41f74f 7 *
mbed_official 585:a1ed5b41f74f 8 * http://www.apache.org/licenses/LICENSE-2.0
mbed_official 585:a1ed5b41f74f 9 *
mbed_official 585:a1ed5b41f74f 10 * Unless required by applicable law or agreed to in writing, software
mbed_official 585:a1ed5b41f74f 11 * distributed under the License is distributed on an "AS IS" BASIS,
mbed_official 585:a1ed5b41f74f 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
mbed_official 585:a1ed5b41f74f 13 * See the License for the specific language governing permissions and
mbed_official 585:a1ed5b41f74f 14 * limitations under the License.
mbed_official 585:a1ed5b41f74f 15 */
mbed_official 585:a1ed5b41f74f 16 #include "rtc_api.h"
mbed_official 585:a1ed5b41f74f 17
mbed_official 585:a1ed5b41f74f 18 time_t wiz_rtc_time;
mbed_official 585:a1ed5b41f74f 19 char rtc_enabled = 0;
mbed_official 585:a1ed5b41f74f 20
mbed_official 585:a1ed5b41f74f 21 #ifdef __cplusplus
mbed_official 585:a1ed5b41f74f 22 extern "C"{
mbed_official 585:a1ed5b41f74f 23 #endif
mbed_official 585:a1ed5b41f74f 24 void PWM3_Handler(void)
mbed_official 585:a1ed5b41f74f 25 {
mbed_official 585:a1ed5b41f74f 26
mbed_official 585:a1ed5b41f74f 27 wiz_rtc_time++;
mbed_official 585:a1ed5b41f74f 28 PWM_CH3_ClearOverflowInt();
mbed_official 585:a1ed5b41f74f 29
mbed_official 585:a1ed5b41f74f 30 }
mbed_official 585:a1ed5b41f74f 31 #ifdef __cplusplus
mbed_official 585:a1ed5b41f74f 32 }
mbed_official 585:a1ed5b41f74f 33 #endif
mbed_official 585:a1ed5b41f74f 34
mbed_official 585:a1ed5b41f74f 35
mbed_official 585:a1ed5b41f74f 36
mbed_official 585:a1ed5b41f74f 37 void rtc_init(void) {
mbed_official 585:a1ed5b41f74f 38 PWM_TimerModeInitTypeDef TimerModeStructure;
mbed_official 585:a1ed5b41f74f 39 *(volatile uint32_t *)(0x410010e0) = 0x03;
mbed_official 585:a1ed5b41f74f 40
mbed_official 585:a1ed5b41f74f 41 /* Timer mode configuration */
mbed_official 585:a1ed5b41f74f 42 TimerModeStructure.PWM_CHn_PR = 7;
mbed_official 585:a1ed5b41f74f 43 TimerModeStructure.PWM_CHn_MR = 1;
mbed_official 585:a1ed5b41f74f 44 TimerModeStructure.PWM_CHn_LR = 0xF4240;
mbed_official 585:a1ed5b41f74f 45 TimerModeStructure.PWM_CHn_UDMR = PWM_CHn_UDMR_UpCount;
mbed_official 585:a1ed5b41f74f 46 TimerModeStructure.PWM_CHn_PDMR = PWM_CHn_PDMR_Periodic;
mbed_official 585:a1ed5b41f74f 47
mbed_official 585:a1ed5b41f74f 48 PWM_TimerModeInit(PWM_CH3, &TimerModeStructure);
mbed_official 585:a1ed5b41f74f 49
mbed_official 585:a1ed5b41f74f 50 /* PWM interrupt configuration */
mbed_official 585:a1ed5b41f74f 51 PWM_IntConfig(PWM_CH3, ENABLE);
mbed_official 585:a1ed5b41f74f 52 PWM_CHn_IntConfig(PWM_CH3, PWM_CHn_IER_OIE, ENABLE);
mbed_official 585:a1ed5b41f74f 53
mbed_official 585:a1ed5b41f74f 54 /* PWM channel 0 start */
mbed_official 585:a1ed5b41f74f 55 PWM_CHn_Start(PWM_CH3);
mbed_official 585:a1ed5b41f74f 56 NVIC_SetVector(PWM3_IRQn, (uint32_t)PWM3_Handler);
mbed_official 585:a1ed5b41f74f 57 NVIC_EnableIRQ(PWM3_IRQn);
mbed_official 585:a1ed5b41f74f 58 rtc_enabled = 1;
mbed_official 585:a1ed5b41f74f 59 }
mbed_official 585:a1ed5b41f74f 60
mbed_official 585:a1ed5b41f74f 61 void rtc_free(void) {
mbed_official 585:a1ed5b41f74f 62 // [TODO]
mbed_official 585:a1ed5b41f74f 63 }
mbed_official 585:a1ed5b41f74f 64
mbed_official 585:a1ed5b41f74f 65
mbed_official 585:a1ed5b41f74f 66 int rtc_isenabled(void) {
mbed_official 585:a1ed5b41f74f 67 return rtc_enabled;
mbed_official 585:a1ed5b41f74f 68 }
mbed_official 585:a1ed5b41f74f 69
mbed_official 585:a1ed5b41f74f 70
mbed_official 585:a1ed5b41f74f 71 time_t rtc_read(void) {
mbed_official 585:a1ed5b41f74f 72 return wiz_rtc_time;
mbed_official 585:a1ed5b41f74f 73 }
mbed_official 585:a1ed5b41f74f 74
mbed_official 585:a1ed5b41f74f 75 void rtc_write(time_t t) {
mbed_official 585:a1ed5b41f74f 76 //*(volatile uint32_t *)(0x41001008) = 0x42; // timer disable, interrupt disable
mbed_official 585:a1ed5b41f74f 77 wiz_rtc_time = t;
mbed_official 585:a1ed5b41f74f 78 //*(volatile uint32_t *)(0x41001008) = 0x72; // timer enable interrupt enable
mbed_official 585:a1ed5b41f74f 79 }