Timeout.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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_TIMEOUT_H
  17. #define MBED_TIMEOUT_H
  18. #include "drivers/Ticker.h"
  19. #include "platform/NonCopyable.h"
  20. #include "platform/mbed_power_mgmt.h"
  21. namespace mbed {
  22. /** \addtogroup drivers */
  23. /** A Timeout is used to call a function at a point in the future
  24. *
  25. * You can use as many seperate Timeout objects as you require.
  26. *
  27. * @note Synchronization level: Interrupt safe
  28. *
  29. * Example:
  30. * @code
  31. * // Blink until timeout.
  32. *
  33. * #include "mbed.h"
  34. *
  35. * Timeout timeout;
  36. * DigitalOut led(LED1);
  37. *
  38. * int on = 1;
  39. *
  40. * void attimeout() {
  41. * on = 0;
  42. * }
  43. *
  44. * int main() {
  45. * timeout.attach(&attimeout, 5);
  46. * while(on) {
  47. * led = !led;
  48. * wait(0.2);
  49. * }
  50. * }
  51. * @endcode
  52. * @ingroup drivers
  53. */
  54. class Timeout : public Ticker, private NonCopyable<Timeout> {
  55. protected:
  56. virtual void handler();
  57. };
  58. } // namespace mbed
  59. #endif