Erste version der Software für der Prototyp

Committer:
borlanic
Date:
Fri Mar 30 14:07:05 2018 +0000
Revision:
4:75df35ef4fb6
Parent:
0:380207fcb5c1
commentar

Who changed what in which revision?

UserRevisionLine numberNew contents of line
borlanic 0:380207fcb5c1 1 /* mbed Microcontroller Library
borlanic 0:380207fcb5c1 2 * Copyright (c) 2006-2013 ARM Limited
borlanic 0:380207fcb5c1 3 *
borlanic 0:380207fcb5c1 4 * Licensed under the Apache License, Version 2.0 (the "License");
borlanic 0:380207fcb5c1 5 * you may not use this file except in compliance with the License.
borlanic 0:380207fcb5c1 6 * You may obtain a copy of the License at
borlanic 0:380207fcb5c1 7 *
borlanic 0:380207fcb5c1 8 * http://www.apache.org/licenses/LICENSE-2.0
borlanic 0:380207fcb5c1 9 *
borlanic 0:380207fcb5c1 10 * Unless required by applicable law or agreed to in writing, software
borlanic 0:380207fcb5c1 11 * distributed under the License is distributed on an "AS IS" BASIS,
borlanic 0:380207fcb5c1 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
borlanic 0:380207fcb5c1 13 * See the License for the specific language governing permissions and
borlanic 0:380207fcb5c1 14 * limitations under the License.
borlanic 0:380207fcb5c1 15 */
borlanic 0:380207fcb5c1 16 #ifndef MBED_TIMER_H
borlanic 0:380207fcb5c1 17 #define MBED_TIMER_H
borlanic 0:380207fcb5c1 18
borlanic 0:380207fcb5c1 19 #include "platform/platform.h"
borlanic 0:380207fcb5c1 20 #include "hal/ticker_api.h"
borlanic 0:380207fcb5c1 21 #include "platform/NonCopyable.h"
borlanic 0:380207fcb5c1 22 #include "platform/mbed_power_mgmt.h"
borlanic 0:380207fcb5c1 23
borlanic 0:380207fcb5c1 24 namespace mbed {
borlanic 0:380207fcb5c1 25 /** \addtogroup drivers */
borlanic 0:380207fcb5c1 26
borlanic 0:380207fcb5c1 27 /** A general purpose timer
borlanic 0:380207fcb5c1 28 *
borlanic 0:380207fcb5c1 29 * @note Synchronization level: Interrupt safe
borlanic 0:380207fcb5c1 30 *
borlanic 0:380207fcb5c1 31 * Example:
borlanic 0:380207fcb5c1 32 * @code
borlanic 0:380207fcb5c1 33 * // Count the time to toggle a LED
borlanic 0:380207fcb5c1 34 *
borlanic 0:380207fcb5c1 35 * #include "mbed.h"
borlanic 0:380207fcb5c1 36 *
borlanic 0:380207fcb5c1 37 * Timer timer;
borlanic 0:380207fcb5c1 38 * DigitalOut led(LED1);
borlanic 0:380207fcb5c1 39 * int begin, end;
borlanic 0:380207fcb5c1 40 *
borlanic 0:380207fcb5c1 41 * int main() {
borlanic 0:380207fcb5c1 42 * timer.start();
borlanic 0:380207fcb5c1 43 * begin = timer.read_us();
borlanic 0:380207fcb5c1 44 * led = !led;
borlanic 0:380207fcb5c1 45 * end = timer.read_us();
borlanic 0:380207fcb5c1 46 * printf("Toggle the led takes %d us", end - begin);
borlanic 0:380207fcb5c1 47 * }
borlanic 0:380207fcb5c1 48 * @endcode
borlanic 0:380207fcb5c1 49 * @ingroup drivers
borlanic 0:380207fcb5c1 50 */
borlanic 0:380207fcb5c1 51 class Timer : private NonCopyable<Timer> {
borlanic 0:380207fcb5c1 52
borlanic 0:380207fcb5c1 53 public:
borlanic 0:380207fcb5c1 54 Timer();
borlanic 0:380207fcb5c1 55 Timer(const ticker_data_t *data);
borlanic 0:380207fcb5c1 56 ~Timer();
borlanic 0:380207fcb5c1 57
borlanic 0:380207fcb5c1 58 /** Start the timer
borlanic 0:380207fcb5c1 59 */
borlanic 0:380207fcb5c1 60 void start();
borlanic 0:380207fcb5c1 61
borlanic 0:380207fcb5c1 62 /** Stop the timer
borlanic 0:380207fcb5c1 63 */
borlanic 0:380207fcb5c1 64 void stop();
borlanic 0:380207fcb5c1 65
borlanic 0:380207fcb5c1 66 /** Reset the timer to 0.
borlanic 0:380207fcb5c1 67 *
borlanic 0:380207fcb5c1 68 * If it was already counting, it will continue
borlanic 0:380207fcb5c1 69 */
borlanic 0:380207fcb5c1 70 void reset();
borlanic 0:380207fcb5c1 71
borlanic 0:380207fcb5c1 72 /** Get the time passed in seconds
borlanic 0:380207fcb5c1 73 *
borlanic 0:380207fcb5c1 74 * @returns Time passed in seconds
borlanic 0:380207fcb5c1 75 */
borlanic 0:380207fcb5c1 76 float read();
borlanic 0:380207fcb5c1 77
borlanic 0:380207fcb5c1 78 /** Get the time passed in milli-seconds
borlanic 0:380207fcb5c1 79 *
borlanic 0:380207fcb5c1 80 * @returns Time passed in milli seconds
borlanic 0:380207fcb5c1 81 */
borlanic 0:380207fcb5c1 82 int read_ms();
borlanic 0:380207fcb5c1 83
borlanic 0:380207fcb5c1 84 /** Get the time passed in micro-seconds
borlanic 0:380207fcb5c1 85 *
borlanic 0:380207fcb5c1 86 * @returns Time passed in micro seconds
borlanic 0:380207fcb5c1 87 */
borlanic 0:380207fcb5c1 88 int read_us();
borlanic 0:380207fcb5c1 89
borlanic 0:380207fcb5c1 90 /** An operator shorthand for read()
borlanic 0:380207fcb5c1 91 */
borlanic 0:380207fcb5c1 92 operator float();
borlanic 0:380207fcb5c1 93
borlanic 0:380207fcb5c1 94 /** Get in a high resolution type the time passed in micro-seconds.
borlanic 0:380207fcb5c1 95 */
borlanic 0:380207fcb5c1 96 us_timestamp_t read_high_resolution_us();
borlanic 0:380207fcb5c1 97
borlanic 0:380207fcb5c1 98 protected:
borlanic 0:380207fcb5c1 99 us_timestamp_t slicetime();
borlanic 0:380207fcb5c1 100 int _running; // whether the timer is running
borlanic 0:380207fcb5c1 101 us_timestamp_t _start; // the start time of the latest slice
borlanic 0:380207fcb5c1 102 us_timestamp_t _time; // any accumulated time from previous slices
borlanic 0:380207fcb5c1 103 const ticker_data_t *_ticker_data;
borlanic 0:380207fcb5c1 104 bool _lock_deepsleep; // flag which indicates if deep-sleep should be disabled
borlanic 0:380207fcb5c1 105 };
borlanic 0:380207fcb5c1 106
borlanic 0:380207fcb5c1 107 } // namespace mbed
borlanic 0:380207fcb5c1 108
borlanic 0:380207fcb5c1 109 #endif