mbed library for NZ32-SC151

Committer:
modtronix-com
Date:
Fri Aug 19 15:46:42 2016 +1000
Revision:
17:639ed60ce759
Parent:
1:71204b8406f2
Added tag v1.1 for changeset 076cbe3e55be

Who changed what in which revision?

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