mcf51cn_ostimer.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. * Copyright 2012 by Embedded Technologies s.r.o
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. * 3. Neither the name of the copyright holders nor the names of
  14. * contributors may be used to endorse or promote products derived
  15. * from this software without specific prior written permission.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  18. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  19. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  20. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  21. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  22. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  23. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  24. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  25. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  26. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  27. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  28. * SUCH DAMAGE.
  29. *
  30. * For additional information see http://www.ethernut.de/
  31. */
  32. #include <arch/m68k.h>
  33. #include <cfg/os.h>
  34. #include <cfg/clock.h>
  35. #include <dev/irqreg.h>
  36. #include <sys/timer.h>
  37. /*!
  38. * \addtogroup xgNutArchM68kMCF51CNOsTimer
  39. */
  40. /*@{*/
  41. #ifndef NUT_TICK_FREQ
  42. /*!
  43. * \brief System timer interrupt frequency.
  44. *
  45. * Specifies the number of interrupts per second, typically 1000.
  46. * In order to reduce overhead, you may choose lower values. Note,
  47. * that Nut/OS API timer values are given in milliseconds. Thus,
  48. * lower values will reduce the available resolution, while
  49. * larger values may not provide any benefit.
  50. */
  51. #define NUT_TICK_FREQ 1000UL
  52. #endif
  53. /*!
  54. * \brief Initialize system timer.
  55. *
  56. * Applications must not call this function.
  57. *
  58. * It is automatically called by Nut/OS during initialization to register
  59. * the system timer interrupt handler. It is an essential part of the
  60. * hardware dependant code and must be available for any platform that is
  61. * running Nut/OS.
  62. *
  63. * The number of system timer interrupts is define by \ref NUT_TICK_FREQ.
  64. *
  65. * Timer interrupts are enabled when this function returns.
  66. *
  67. * \param handler This routine should be called each time, when a
  68. * system timer interrupt occurs.
  69. */
  70. void NutRegisterTimer(void (*handler) (void *))
  71. {
  72. // JS TODO NutRegisterTimer
  73. }
  74. #ifndef NUT_CPU_FREQ
  75. /*!
  76. * \brief Return the specified clock frequency.
  77. *
  78. * Applications must not call this function, but use NutClockGet()
  79. * instead.
  80. *
  81. * Simple implementations may not provide this function, in which case
  82. * \ref NUT_CPU_FREQ must define the CPU frequency in Hertz. This can
  83. * be done in the Configurator.
  84. *
  85. * \param idx This zero based index specifies the clock to retrieve. The
  86. * number of available hardware clocks depends on the target
  87. * harware and is specified by NUT_HWCLK_MAX + 1. Typically
  88. * \ref NUT_HWCLK_CPU is used to retrieve the current CPU
  89. * clock. Additional indices may be available to retrieve one
  90. * or more peripheral clocks or a special slow clock.
  91. *
  92. * \return Clock frequency in Hertz.
  93. */
  94. uint32_t NutArchClockGet(int idx)
  95. {
  96. // JS TODO NutArchClockGet
  97. return 16 * 1024 * 1024;
  98. }
  99. #endif
  100. /*!
  101. * \brief Return the number of system ticks per second.
  102. *
  103. * This routine is used by Nut/OS to convert tick counts into
  104. * milliseconds.
  105. *
  106. * Applications typically do not deal with system ticks. Instead,
  107. * they use milliseconds to specify timeouts or call NutGetMillis()
  108. * and NutGetSeconds() to retrieve an elapsed time.
  109. *
  110. * \return System tick frequency in Hertz, typically the value of
  111. * \ref NUT_TICK_FREQ.
  112. */
  113. uint32_t NutGetTickClock(void)
  114. {
  115. return NUT_TICK_FREQ;
  116. }
  117. /*!
  118. * \brief Calculate system ticks for a given number of milliseconds.
  119. *
  120. * This routine is used by Nut/OS to retrieve the number of system
  121. * ticks for a given timeout.
  122. *
  123. * \param ms Number of milliseconds.
  124. *
  125. * \return Number of system ticks. The resolution is limited to the
  126. * granularity of the system timer.
  127. */
  128. uint32_t NutTimerMillisToTicks(uint32_t ms)
  129. {
  130. return (ms * NutGetTickClock()) / 1000;
  131. }
  132. /*@}*/