temp

Dependencies:   mbed SDFileSystem MS5607 ADXL345_I2C FATFileSystem

Committer:
IKobayashi
Date:
Mon Mar 16 23:37:42 2020 +0900
Revision:
0:c88c3b616c00
copy

Who changed what in which revision?

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