mbed library sources. Supersedes mbed-src. RTC working even after reset

Fork of mbed-dev by mbed official

Committer:
<>
Date:
Fri Sep 02 15:07:44 2016 +0100
Revision:
144:ef7eb2e8f9f7
Parent:
0:9b334a45a8ff
This updates the lib to the mbed lib v125

Who changed what in which revision?

UserRevisionLine numberNew contents of line
<> 144:ef7eb2e8f9f7 1 /* mbed Microcontroller Library
<> 144:ef7eb2e8f9f7 2 * Copyright (c) 2006-2013 ARM Limited
<> 144:ef7eb2e8f9f7 3 *
<> 144:ef7eb2e8f9f7 4 * Licensed under the Apache License, Version 2.0 (the "License");
<> 144:ef7eb2e8f9f7 5 * you may not use this file except in compliance with the License.
<> 144:ef7eb2e8f9f7 6 * You may obtain a copy of the License at
<> 144:ef7eb2e8f9f7 7 *
<> 144:ef7eb2e8f9f7 8 * http://www.apache.org/licenses/LICENSE-2.0
<> 144:ef7eb2e8f9f7 9 *
<> 144:ef7eb2e8f9f7 10 * Unless required by applicable law or agreed to in writing, software
<> 144:ef7eb2e8f9f7 11 * distributed under the License is distributed on an "AS IS" BASIS,
<> 144:ef7eb2e8f9f7 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<> 144:ef7eb2e8f9f7 13 * See the License for the specific language governing permissions and
<> 144:ef7eb2e8f9f7 14 * limitations under the License.
<> 144:ef7eb2e8f9f7 15 */
<> 144:ef7eb2e8f9f7 16 #ifndef MBED_TICKER_H
<> 144:ef7eb2e8f9f7 17 #define MBED_TICKER_H
<> 144:ef7eb2e8f9f7 18
<> 144:ef7eb2e8f9f7 19 #include "TimerEvent.h"
<> 144:ef7eb2e8f9f7 20 #include "Callback.h"
<> 144:ef7eb2e8f9f7 21
<> 144:ef7eb2e8f9f7 22 namespace mbed {
<> 144:ef7eb2e8f9f7 23
<> 144:ef7eb2e8f9f7 24 /** A Ticker is used to call a function at a recurring interval
<> 144:ef7eb2e8f9f7 25 *
<> 144:ef7eb2e8f9f7 26 * You can use as many seperate Ticker objects as you require.
<> 144:ef7eb2e8f9f7 27 *
<> 144:ef7eb2e8f9f7 28 * @Note Synchronization level: Interrupt safe
<> 144:ef7eb2e8f9f7 29 *
<> 144:ef7eb2e8f9f7 30 * Example:
<> 144:ef7eb2e8f9f7 31 * @code
<> 144:ef7eb2e8f9f7 32 * // Toggle the blinking led after 5 seconds
<> 144:ef7eb2e8f9f7 33 *
<> 144:ef7eb2e8f9f7 34 * #include "mbed.h"
<> 144:ef7eb2e8f9f7 35 *
<> 144:ef7eb2e8f9f7 36 * Ticker timer;
<> 144:ef7eb2e8f9f7 37 * DigitalOut led1(LED1);
<> 144:ef7eb2e8f9f7 38 * DigitalOut led2(LED2);
<> 144:ef7eb2e8f9f7 39 *
<> 144:ef7eb2e8f9f7 40 * int flip = 0;
<> 144:ef7eb2e8f9f7 41 *
<> 144:ef7eb2e8f9f7 42 * void attime() {
<> 144:ef7eb2e8f9f7 43 * flip = !flip;
<> 144:ef7eb2e8f9f7 44 * }
<> 144:ef7eb2e8f9f7 45 *
<> 144:ef7eb2e8f9f7 46 * int main() {
<> 144:ef7eb2e8f9f7 47 * timer.attach(&attime, 5);
<> 144:ef7eb2e8f9f7 48 * while(1) {
<> 144:ef7eb2e8f9f7 49 * if(flip == 0) {
<> 144:ef7eb2e8f9f7 50 * led1 = !led1;
<> 144:ef7eb2e8f9f7 51 * } else {
<> 144:ef7eb2e8f9f7 52 * led2 = !led2;
<> 144:ef7eb2e8f9f7 53 * }
<> 144:ef7eb2e8f9f7 54 * wait(0.2);
<> 144:ef7eb2e8f9f7 55 * }
<> 144:ef7eb2e8f9f7 56 * }
<> 144:ef7eb2e8f9f7 57 * @endcode
<> 144:ef7eb2e8f9f7 58 */
<> 144:ef7eb2e8f9f7 59 class Ticker : public TimerEvent {
<> 144:ef7eb2e8f9f7 60
<> 144:ef7eb2e8f9f7 61 public:
<> 144:ef7eb2e8f9f7 62 Ticker() : TimerEvent() {
<> 144:ef7eb2e8f9f7 63 }
<> 144:ef7eb2e8f9f7 64
<> 144:ef7eb2e8f9f7 65 Ticker(const ticker_data_t *data) : TimerEvent(data) {
<> 144:ef7eb2e8f9f7 66 data->interface->init();
<> 144:ef7eb2e8f9f7 67 }
<> 144:ef7eb2e8f9f7 68
<> 144:ef7eb2e8f9f7 69 /** Attach a function to be called by the Ticker, specifiying the interval in seconds
<> 144:ef7eb2e8f9f7 70 *
<> 144:ef7eb2e8f9f7 71 * @param func pointer to the function to be called
<> 144:ef7eb2e8f9f7 72 * @param t the time between calls in seconds
<> 144:ef7eb2e8f9f7 73 */
<> 144:ef7eb2e8f9f7 74 void attach(Callback<void()> func, float t) {
<> 144:ef7eb2e8f9f7 75 attach_us(func, t * 1000000.0f);
<> 144:ef7eb2e8f9f7 76 }
<> 144:ef7eb2e8f9f7 77
<> 144:ef7eb2e8f9f7 78 /** Attach a member function to be called by the Ticker, specifiying the interval in seconds
<> 144:ef7eb2e8f9f7 79 *
<> 144:ef7eb2e8f9f7 80 * @param obj pointer to the object to call the member function on
<> 144:ef7eb2e8f9f7 81 * @param method pointer to the member function to be called
<> 144:ef7eb2e8f9f7 82 * @param t the time between calls in seconds
<> 144:ef7eb2e8f9f7 83 */
<> 144:ef7eb2e8f9f7 84 template<typename T, typename M>
<> 144:ef7eb2e8f9f7 85 void attach(T *obj, M method, float t) {
<> 144:ef7eb2e8f9f7 86 attach(Callback<void()>(obj, method), t);
<> 144:ef7eb2e8f9f7 87 }
<> 144:ef7eb2e8f9f7 88
<> 144:ef7eb2e8f9f7 89 /** Attach a function to be called by the Ticker, specifiying the interval in micro-seconds
<> 144:ef7eb2e8f9f7 90 *
<> 144:ef7eb2e8f9f7 91 * @param fptr pointer to the function to be called
<> 144:ef7eb2e8f9f7 92 * @param t the time between calls in micro-seconds
<> 144:ef7eb2e8f9f7 93 */
<> 144:ef7eb2e8f9f7 94 void attach_us(Callback<void()> func, timestamp_t t) {
<> 144:ef7eb2e8f9f7 95 _function.attach(func);
<> 144:ef7eb2e8f9f7 96 setup(t);
<> 144:ef7eb2e8f9f7 97 }
<> 144:ef7eb2e8f9f7 98
<> 144:ef7eb2e8f9f7 99 /** Attach a member function to be called by the Ticker, specifiying the interval in micro-seconds
<> 144:ef7eb2e8f9f7 100 *
<> 144:ef7eb2e8f9f7 101 * @param tptr pointer to the object to call the member function on
<> 144:ef7eb2e8f9f7 102 * @param mptr pointer to the member function to be called
<> 144:ef7eb2e8f9f7 103 * @param t the time between calls in micro-seconds
<> 144:ef7eb2e8f9f7 104 */
<> 144:ef7eb2e8f9f7 105 template<typename T, typename M>
<> 144:ef7eb2e8f9f7 106 void attach_us(T *obj, M method, timestamp_t t) {
<> 144:ef7eb2e8f9f7 107 attach_us(Callback<void()>(obj, method), t);
<> 144:ef7eb2e8f9f7 108 }
<> 144:ef7eb2e8f9f7 109
<> 144:ef7eb2e8f9f7 110 virtual ~Ticker() {
<> 144:ef7eb2e8f9f7 111 detach();
<> 144:ef7eb2e8f9f7 112 }
<> 144:ef7eb2e8f9f7 113
<> 144:ef7eb2e8f9f7 114 /** Detach the function
<> 144:ef7eb2e8f9f7 115 */
<> 144:ef7eb2e8f9f7 116 void detach();
<> 144:ef7eb2e8f9f7 117
<> 144:ef7eb2e8f9f7 118 protected:
<> 144:ef7eb2e8f9f7 119 void setup(timestamp_t t);
<> 144:ef7eb2e8f9f7 120 virtual void handler();
<> 144:ef7eb2e8f9f7 121
<> 144:ef7eb2e8f9f7 122 protected:
<> 144:ef7eb2e8f9f7 123 timestamp_t _delay; /**< Time delay (in microseconds) for re-setting the multi-shot callback. */
<> 144:ef7eb2e8f9f7 124 Callback<void()> _function; /**< Callback. */
<> 144:ef7eb2e8f9f7 125 };
<> 144:ef7eb2e8f9f7 126
<> 144:ef7eb2e8f9f7 127 } // namespace mbed
<> 144:ef7eb2e8f9f7 128
<> 144:ef7eb2e8f9f7 129 #endif