SPKT

Dependencies:   F746_GUI SD_PlayerSkeleton F746_SAI_IO

Committer:
phungductung
Date:
Tue Jun 04 21:37:21 2019 +0000
Revision:
0:8ede47d38d10
SPKT

Who changed what in which revision?

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