this hurts

Dependencies:   FFT

Committer:
shyamgatech
Date:
Thu Dec 03 18:15:35 2020 +0000
Revision:
7:0d62545e6d73
Parent:
0:d6c9b09b4042
addded gui mbed code;

Who changed what in which revision?

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