- fix F411 F334 systeminit when HSI used - portinout always read IDR regardless of port direction

Fork of mbed-src by mbed official

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Timer.cpp Source File

Timer.cpp

00001 /* mbed Microcontroller Library
00002  * Copyright (c) 2006-2013 ARM Limited
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 #include "Timer.h"
00017 #include "us_ticker_api.h"
00018 
00019 namespace mbed {
00020 
00021 Timer::Timer() : _running(), _start(), _time() {
00022     reset();
00023 }
00024 
00025 void Timer::start() {
00026     _start = us_ticker_read();
00027     _running = 1;
00028 }
00029 
00030 void Timer::stop() {
00031     _time += slicetime();
00032     _running = 0;
00033 }
00034 
00035 int Timer::read_us() {
00036     return _time + slicetime();
00037 }
00038 
00039 float Timer::read() {
00040     return (float)read_us() / 1000000.0f;
00041 }
00042 
00043 int Timer::read_ms() {
00044     return read_us() / 1000;
00045 }
00046 
00047 int Timer::slicetime() {
00048     if (_running) {
00049         return us_ticker_read() - _start;
00050     } else {
00051         return 0;
00052     }
00053 }
00054 
00055 void Timer::reset() {
00056     _start = us_ticker_read();
00057     _time = 0;
00058 }
00059 
00060 #ifdef MBED_OPERATORS
00061 Timer::operator float() {
00062     return read();
00063 }
00064 #endif
00065 
00066 } // namespace mbed