mbed library sources. Supersedes mbed-src.

Dependents:   Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more

Committer:
AnnaBridge
Date:
Wed Feb 20 22:31:08 2019 +0000
Revision:
189:f392fc9709a3
mbed library release version 165

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AnnaBridge 189:f392fc9709a3 1 /* mbed Microcontroller Library
AnnaBridge 189:f392fc9709a3 2 * Copyright (c) 2006-2013 ARM Limited
AnnaBridge 189:f392fc9709a3 3 * SPDX-License-Identifier: Apache-2.0
AnnaBridge 189:f392fc9709a3 4 *
AnnaBridge 189:f392fc9709a3 5 * Licensed under the Apache License, Version 2.0 (the "License");
AnnaBridge 189:f392fc9709a3 6 * you may not use this file except in compliance with the License.
AnnaBridge 189:f392fc9709a3 7 * You may obtain a copy of the License at
AnnaBridge 189:f392fc9709a3 8 *
AnnaBridge 189:f392fc9709a3 9 * http://www.apache.org/licenses/LICENSE-2.0
AnnaBridge 189:f392fc9709a3 10 *
AnnaBridge 189:f392fc9709a3 11 * Unless required by applicable law or agreed to in writing, software
AnnaBridge 189:f392fc9709a3 12 * distributed under the License is distributed on an "AS IS" BASIS,
AnnaBridge 189:f392fc9709a3 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
AnnaBridge 189:f392fc9709a3 14 * See the License for the specific language governing permissions and
AnnaBridge 189:f392fc9709a3 15 * limitations under the License.
AnnaBridge 189:f392fc9709a3 16 */
AnnaBridge 189:f392fc9709a3 17 #ifndef MBED_TIMEOUT_H
AnnaBridge 189:f392fc9709a3 18 #define MBED_TIMEOUT_H
AnnaBridge 189:f392fc9709a3 19
AnnaBridge 189:f392fc9709a3 20 #include "drivers/Ticker.h"
AnnaBridge 189:f392fc9709a3 21 #include "platform/NonCopyable.h"
AnnaBridge 189:f392fc9709a3 22 #include "platform/mbed_power_mgmt.h"
AnnaBridge 189:f392fc9709a3 23
AnnaBridge 189:f392fc9709a3 24 namespace mbed {
AnnaBridge 189:f392fc9709a3 25 /** \addtogroup drivers */
AnnaBridge 189:f392fc9709a3 26
AnnaBridge 189:f392fc9709a3 27 /** A Timeout is used to call a function at a point in the future
AnnaBridge 189:f392fc9709a3 28 *
AnnaBridge 189:f392fc9709a3 29 * You can use as many separate Timeout objects as you require.
AnnaBridge 189:f392fc9709a3 30 *
AnnaBridge 189:f392fc9709a3 31 * @note Synchronization level: Interrupt safe
AnnaBridge 189:f392fc9709a3 32 *
AnnaBridge 189:f392fc9709a3 33 * Example:
AnnaBridge 189:f392fc9709a3 34 * @code
AnnaBridge 189:f392fc9709a3 35 * // Blink until timeout.
AnnaBridge 189:f392fc9709a3 36 *
AnnaBridge 189:f392fc9709a3 37 * #include "mbed.h"
AnnaBridge 189:f392fc9709a3 38 *
AnnaBridge 189:f392fc9709a3 39 * Timeout timeout;
AnnaBridge 189:f392fc9709a3 40 * DigitalOut led(LED1);
AnnaBridge 189:f392fc9709a3 41 *
AnnaBridge 189:f392fc9709a3 42 * int on = 1;
AnnaBridge 189:f392fc9709a3 43 *
AnnaBridge 189:f392fc9709a3 44 * void attimeout() {
AnnaBridge 189:f392fc9709a3 45 * on = 0;
AnnaBridge 189:f392fc9709a3 46 * }
AnnaBridge 189:f392fc9709a3 47 *
AnnaBridge 189:f392fc9709a3 48 * int main() {
AnnaBridge 189:f392fc9709a3 49 * timeout.attach(&attimeout, 5);
AnnaBridge 189:f392fc9709a3 50 * while(on) {
AnnaBridge 189:f392fc9709a3 51 * led = !led;
AnnaBridge 189:f392fc9709a3 52 * wait(0.2);
AnnaBridge 189:f392fc9709a3 53 * }
AnnaBridge 189:f392fc9709a3 54 * }
AnnaBridge 189:f392fc9709a3 55 * @endcode
AnnaBridge 189:f392fc9709a3 56 * @ingroup drivers
AnnaBridge 189:f392fc9709a3 57 */
AnnaBridge 189:f392fc9709a3 58 class Timeout : public Ticker, private NonCopyable<Timeout> {
AnnaBridge 189:f392fc9709a3 59
AnnaBridge 189:f392fc9709a3 60 #if !defined(DOXYGEN_ONLY)
AnnaBridge 189:f392fc9709a3 61 protected:
AnnaBridge 189:f392fc9709a3 62 virtual void handler();
AnnaBridge 189:f392fc9709a3 63 #endif
AnnaBridge 189:f392fc9709a3 64 };
AnnaBridge 189:f392fc9709a3 65
AnnaBridge 189:f392fc9709a3 66 } // namespace mbed
AnnaBridge 189:f392fc9709a3 67
AnnaBridge 189:f392fc9709a3 68 #endif