【mbed OS5対応バージョン】データの保存、更新、取得ができるWebサービス「milkcocoa」に接続し、データのプッシュ、送信、取得ができるライブラリです。 https://mlkcca.com/
Dependents: mbed-os-example-wifi-milkcocoa MilkcocoaOsSample_Eth MilkcocoaOsSample_ESP8266 MilkcocoaOsSample_Eth_DigitalIn
OldTimer.cpp@13:61e0cc093180, 2018-03-26 (annotated)
- Committer:
- jksoft
- Date:
- Mon Mar 26 04:49:20 2018 +0000
- Revision:
- 13:61e0cc093180
- Parent:
- 9:5c195c1036da
???????????
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jksoft | 9:5c195c1036da | 1 | /* mbed Microcontroller Library |
jksoft | 9:5c195c1036da | 2 | * Copyright (c) 2006-2013 ARM Limited |
jksoft | 9:5c195c1036da | 3 | * |
jksoft | 9:5c195c1036da | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
jksoft | 9:5c195c1036da | 5 | * you may not use this file except in compliance with the License. |
jksoft | 9:5c195c1036da | 6 | * You may obtain a copy of the License at |
jksoft | 9:5c195c1036da | 7 | * |
jksoft | 9:5c195c1036da | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
jksoft | 9:5c195c1036da | 9 | * |
jksoft | 9:5c195c1036da | 10 | * Unless required by applicable law or agreed to in writing, software |
jksoft | 9:5c195c1036da | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
jksoft | 9:5c195c1036da | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
jksoft | 9:5c195c1036da | 13 | * See the License for the specific language governing permissions and |
jksoft | 9:5c195c1036da | 14 | * limitations under the License. |
jksoft | 9:5c195c1036da | 15 | */ |
jksoft | 9:5c195c1036da | 16 | #include "OldTimer.h" |
jksoft | 9:5c195c1036da | 17 | #include "hal/ticker_api.h" |
jksoft | 9:5c195c1036da | 18 | #include "hal/us_ticker_api.h" |
jksoft | 9:5c195c1036da | 19 | #include "platform/mbed_critical.h" |
jksoft | 9:5c195c1036da | 20 | |
jksoft | 9:5c195c1036da | 21 | |
jksoft | 9:5c195c1036da | 22 | OldTimer::OldTimer() : _running(), _start(), _time(), _ticker_data(get_us_ticker_data()) { |
jksoft | 9:5c195c1036da | 23 | reset(); |
jksoft | 9:5c195c1036da | 24 | } |
jksoft | 9:5c195c1036da | 25 | |
jksoft | 9:5c195c1036da | 26 | OldTimer::OldTimer(const ticker_data_t *data) : _running(), _start(), _time(), _ticker_data(data) { |
jksoft | 9:5c195c1036da | 27 | reset(); |
jksoft | 9:5c195c1036da | 28 | } |
jksoft | 9:5c195c1036da | 29 | |
jksoft | 9:5c195c1036da | 30 | void OldTimer::start() { |
jksoft | 9:5c195c1036da | 31 | core_util_critical_section_enter(); |
jksoft | 9:5c195c1036da | 32 | if (!_running) { |
jksoft | 9:5c195c1036da | 33 | _start = ticker_read_us(_ticker_data); |
jksoft | 9:5c195c1036da | 34 | _running = 1; |
jksoft | 9:5c195c1036da | 35 | } |
jksoft | 9:5c195c1036da | 36 | core_util_critical_section_exit(); |
jksoft | 9:5c195c1036da | 37 | } |
jksoft | 9:5c195c1036da | 38 | |
jksoft | 9:5c195c1036da | 39 | void OldTimer::stop() { |
jksoft | 9:5c195c1036da | 40 | core_util_critical_section_enter(); |
jksoft | 9:5c195c1036da | 41 | _time += slicetime(); |
jksoft | 9:5c195c1036da | 42 | _running = 0; |
jksoft | 9:5c195c1036da | 43 | core_util_critical_section_exit(); |
jksoft | 9:5c195c1036da | 44 | } |
jksoft | 9:5c195c1036da | 45 | |
jksoft | 9:5c195c1036da | 46 | int OldTimer::read_us() { |
jksoft | 9:5c195c1036da | 47 | return read_high_resolution_us(); |
jksoft | 9:5c195c1036da | 48 | } |
jksoft | 9:5c195c1036da | 49 | |
jksoft | 9:5c195c1036da | 50 | float OldTimer::read() { |
jksoft | 9:5c195c1036da | 51 | return (float)read_us() / 1000000.0f; |
jksoft | 9:5c195c1036da | 52 | } |
jksoft | 9:5c195c1036da | 53 | |
jksoft | 9:5c195c1036da | 54 | int OldTimer::read_ms() { |
jksoft | 9:5c195c1036da | 55 | return read_high_resolution_us() / 1000; |
jksoft | 9:5c195c1036da | 56 | } |
jksoft | 9:5c195c1036da | 57 | |
jksoft | 9:5c195c1036da | 58 | us_timestamp_t OldTimer::read_high_resolution_us() { |
jksoft | 9:5c195c1036da | 59 | core_util_critical_section_enter(); |
jksoft | 9:5c195c1036da | 60 | us_timestamp_t time = _time + slicetime(); |
jksoft | 9:5c195c1036da | 61 | core_util_critical_section_exit(); |
jksoft | 9:5c195c1036da | 62 | return time; |
jksoft | 9:5c195c1036da | 63 | } |
jksoft | 9:5c195c1036da | 64 | |
jksoft | 9:5c195c1036da | 65 | us_timestamp_t OldTimer::slicetime() { |
jksoft | 9:5c195c1036da | 66 | us_timestamp_t ret = 0; |
jksoft | 9:5c195c1036da | 67 | core_util_critical_section_enter(); |
jksoft | 9:5c195c1036da | 68 | if (_running) { |
jksoft | 9:5c195c1036da | 69 | ret = ticker_read_us(_ticker_data) - _start; |
jksoft | 9:5c195c1036da | 70 | } |
jksoft | 9:5c195c1036da | 71 | core_util_critical_section_exit(); |
jksoft | 9:5c195c1036da | 72 | return ret; |
jksoft | 9:5c195c1036da | 73 | } |
jksoft | 9:5c195c1036da | 74 | |
jksoft | 9:5c195c1036da | 75 | void OldTimer::reset() { |
jksoft | 9:5c195c1036da | 76 | core_util_critical_section_enter(); |
jksoft | 9:5c195c1036da | 77 | _start = ticker_read_us(_ticker_data); |
jksoft | 9:5c195c1036da | 78 | _time = 0; |
jksoft | 9:5c195c1036da | 79 | core_util_critical_section_exit(); |
jksoft | 9:5c195c1036da | 80 | } |
jksoft | 9:5c195c1036da | 81 | |
jksoft | 9:5c195c1036da | 82 | OldTimer::operator float() { |
jksoft | 9:5c195c1036da | 83 | return read(); |
jksoft | 9:5c195c1036da | 84 | } |
jksoft | 9:5c195c1036da | 85 |