Naze32 clone with Frysky receiver
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Timer.h 2.0KB

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