ticker.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * The MIT License (MIT)
  3. *
  4. * Copyright (c) 2013-2016 The MicroPython-on-micro:bit Developers:
  5. * Damien P. George (@dpgeorge)
  6. * Nicholas H. Tollervey (@ntoll)
  7. * Matthew Else (@matthewelse)
  8. * Alan M. Jackson (@alanmjackson)
  9. * Mark Shannon (@markshannon)
  10. * Larry Hastings (@larryhastings)
  11. * Mariia Koroliuk (@marichkakorolyuk)
  12. * Andrew Mulholland (@gbaman)
  13. * Joe Glancy (@JoeGlancy)
  14. *
  15. * Permission is hereby granted, free of charge, to any person obtaining a copy
  16. * of this software and associated documentation files (the "Software"), to deal
  17. * in the Software without restriction, including without limitation the rights
  18. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  19. * copies of the Software, and to permit persons to whom the Software is
  20. * furnished to do so, subject to the following conditions:
  21. *
  22. * The above copyright notice and this permission notice shall be included in
  23. * all copies or substantial portions of the Software.
  24. *
  25. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  26. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  27. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  28. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  29. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  30. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  31. * THE SOFTWARE.
  32. */
  33. #ifndef __MICROPY_INCLUDED_LIB_TICKER_H__
  34. #define __MICROPY_INCLUDED_LIB_TICKER_H__
  35. /*************************************
  36. * 62.5kHz (16µs cycle time) ticker.
  37. ************************************/
  38. #include "nrf.h"
  39. typedef void (*callback_ptr)(void);
  40. typedef int32_t (*ticker_callback_ptr)(void);
  41. void ticker_init0(void);
  42. void ticker_start(void);
  43. void ticker_stop(void);
  44. int clear_ticker_callback(uint32_t index);
  45. int set_ticker_callback(uint32_t index, ticker_callback_ptr func, int32_t initial_delay_us);
  46. void ticker_register_low_pri_callback(callback_ptr callback);
  47. #define CYCLES_PER_MICROSECONDS 16
  48. #define MICROSECONDS_PER_TICK 16
  49. #define CYCLES_PER_TICK (CYCLES_PER_MICROSECONDS*MICROSECONDS_PER_TICK)
  50. // This must be an integer multiple of MICROSECONDS_PER_TICK
  51. #define MICROSECONDS_PER_MACRO_TICK 6000
  52. #define MILLISECONDS_PER_MACRO_TICK 6
  53. #endif // __MICROPY_INCLUDED_LIB_TICKER_H__