m68332Timer.c
上传用户:luoyougen
上传日期:2008-05-12
资源大小:23136k
文件大小:7k
源码类别:

VxWorks

开发平台:

C/C++

  1. /* m68332Timer.c - MC68332 timer library */
  2. /* Copyright 1984-1992 Wind River Systems, Inc. */
  3. #include "copyright_wrs.h"
  4. /*
  5. modification history
  6. --------------------
  7. 01a,13aug92,caf  moved clock routines from ver 01g of evs332/sysLib.c, ansified.
  8. */
  9. /*
  10. DESCRIPTION
  11. This library contains routines to manipulate the timer functions on the
  12. Motorola MC68302.  This library handles both the system clock and the auxiliary
  13. clock functions.  However, the auxiliary clock functions have no effect.
  14. The macros SYS_CLK_RATE_MIN, SYS_CLK_RATE_MAX, AUX_CLK_RATE_MIN, and
  15. AUX_CLK_RATE_MAX must be defined to provide parameter checking for the
  16. sys[Aux]ClkRateSet() routines.
  17. */
  18. /* locals */
  19. LOCAL FUNCPTR sysClkRoutine = NULL; /* routine to call on clock interrupt */
  20. LOCAL int sysClkArg = NULL; /* its argument */
  21. LOCAL int sysClkRunning = FALSE;
  22. LOCAL int sysClkConnected = FALSE;
  23. LOCAL int sysClkTicksPerSecond = 60;
  24. LOCAL int sysClkPITR = 0x182;/* 512 prescale... 60.09 Hz */
  25. LOCAL int auxClkTicksPerSecond = 60;
  26. /*******************************************************************************
  27. *
  28. * sysClkInt - handle system clock interrupts
  29. *
  30. * This routine handles system clock interrupts.
  31. *
  32. * RETURNS: N/A
  33. */
  34. LOCAL void sysClkInt (void)
  35.     {
  36.     if (sysClkRoutine != NULL)
  37.         (*sysClkRoutine) (sysClkArg);
  38.     }
  39. /*******************************************************************************
  40. *
  41. * sysClkConnect - connect a routine to the system clock interrupt
  42. *
  43. * This routine specifies the interrupt service routine to be called at each
  44. * clock interrupt.  It does not enable system clock interrupts.  Normally,
  45. * it is called from usrRoot() in usrConfig.c to connect usrClock() to the
  46. * system clock interrupt.
  47. *
  48. * RETURNS: OK, or ERROR if the routine cannot be connected to the interrupt.
  49. *
  50. * SEE ALSO: intConnect(), usrClock(), sysClkEnable()
  51. */
  52. STATUS sysClkConnect
  53.     (
  54.     FUNCPTR routine, /* routine to be called at each clock interrupt */
  55.     int     arg /* argument with which to call routine          */
  56.     )
  57.     {
  58.     sysHwInit2 (); /* XXX for now -- needs to be in usrConfig.c */
  59.     sysClkRoutine   = routine;
  60.     sysClkArg       = arg;
  61.     sysClkConnected = TRUE;
  62.     return (OK);
  63.     }
  64. /*******************************************************************************
  65. *
  66. * sysClkDisable - turn off system clock interrupts
  67. *
  68. * This routine disables system clock interrupts.
  69. *
  70. * RETURNS: N/A
  71. *
  72. * SEE ALSO: sysClkEnable()
  73. */
  74. void sysClkDisable (void)
  75.     {
  76.     if (sysClkRunning)
  77. {
  78. *M332_SIM_PICR &= ~(SIM_PICR_PIRQL_MASK); /* disable interrupts */
  79. sysClkRunning = FALSE; /* clock is stopped */
  80. }
  81.     }
  82. /*******************************************************************************
  83. *
  84. * sysClkEnable - turn on system clock interrupts
  85. *
  86. * This routine enables system clock interrupts.
  87. *
  88. * RETURNS: N/A
  89. *
  90. * SEE ALSO: sysClkConnect(), sysClkDisable(), sysClkRateSet()
  91. */
  92. void sysClkEnable (void)
  93.     {
  94.     if (!sysClkRunning)
  95. {
  96. *M332_SIM_PITR = sysClkPITR; /* set clock rate */
  97. *M332_SIM_PICR |= INT_LVL_SIM << 8; /* enable interrupts */
  98. sysClkRunning = TRUE;
  99. }
  100.     }
  101. /*******************************************************************************
  102. *
  103. * sysClkRateGet - get the system clock rate
  104. *
  105. * This routine returns the interrupt rate of the system clock.
  106. *
  107. * RETURNS: The number of ticks per second of the system clock.
  108. *
  109. * SEE ALSO: sysClkEnable(), sysClkRateSet()
  110. */
  111. int sysClkRateGet (void)
  112.     {
  113.     return (sysClkTicksPerSecond);
  114.     }
  115. /*******************************************************************************
  116. *
  117. * sysClkRateSet - set the system clock rate
  118. *
  119. * This routine sets the interrupt rate of the system clock.  It does not
  120. * enable system clock interrupts.  Normally, it is called by usrRoot() in
  121. * usrConfig.c.
  122. *
  123. * RETURNS: OK, or ERROR if the tick rate is invalid or the timer cannot be set.
  124. *
  125. * SEE ALSO: sysClkEnable(), sysClkRateGet()
  126. */
  127. STATUS sysClkRateSet
  128.     (
  129.     int ticksPerSecond /* number of clock interrupts per second */
  130.     )
  131.     {
  132.     FAST int count;
  133.     if (ticksPerSecond < SYS_CLK_RATE_MIN || ticksPerSecond > SYS_CLK_RATE_MAX)
  134.         return (ERROR);
  135.     /* round to best PITR count value using integer arithmetic */
  136.     count = ((((10 * SYS_EXTAL_FREQ) / (4 * ticksPerSecond)) + 5) / 10);
  137.     if (count < 256)
  138.         sysClkPITR = count;
  139.     else
  140. {
  141. count = ((((10 * SYS_EXTAL_FREQ) / (2048 * ticksPerSecond)) + 5) / 10);
  142.         sysClkPITR = SIM_PITR_PTP | count;
  143. }
  144.     sysClkTicksPerSecond = ticksPerSecond;
  145.     if (sysClkRunning)
  146.         {
  147.         sysClkDisable ();
  148.         sysClkEnable ();
  149.         }
  150.     return (OK);
  151.     }
  152. /*******************************************************************************
  153. *
  154. * sysAuxClkConnect - connect a routine to the auxiliary clock interrupt
  155. *
  156. * This routine specifies the interrupt service routine to be called at each
  157. * auxiliary clock interrupt.  It does not enable auxiliary clock
  158. * interrupts.
  159. *
  160. * NOTE
  161. * This routine has no effect, since there is no auxiliary clock.
  162. *
  163. * RETURNS: ERROR, since there is no auxiliary clock.
  164. *
  165. * SEE ALSO: intConnect(), sysAuxClkEnable()
  166. */
  167. STATUS sysAuxClkConnect
  168.     (
  169.     FUNCPTR routine, /* routine called at each aux. clock interrupt */
  170.     int     arg /* argument with which to call routine         */
  171.     )
  172.     {
  173.     return (ERROR);
  174.     }
  175. /*******************************************************************************
  176. *
  177. * sysAuxClkDisable - turn off auxiliary clock interrupts
  178. *
  179. * This routine disables auxiliary clock interrupts.
  180. *
  181. * NOTE:
  182. * This routine has no effect, since there is no auxiliary clock.
  183. *
  184. * RETURNS: N/A
  185. *
  186. * SEE ALSO: sysAuxClkEnable()
  187. */
  188. void sysAuxClkDisable (void)
  189.     {
  190.     }
  191. /*******************************************************************************
  192. *
  193. * sysAuxClkEnable - turn on auxiliary clock interrupts
  194. *
  195. * This routine enables auxiliary clock interrupts.
  196. *
  197. * NOTE:
  198. * This routine has no effect, since there is no auxiliary clock.
  199. *
  200. * RETURNS: N/A
  201. *
  202. * SEE ALSO: sysAuxClkConnect(), sysAuxClkDisable(), sysAuxClkRateSet()
  203. */
  204. void sysAuxClkEnable (void)
  205.     {
  206.     }
  207. /*******************************************************************************
  208. *
  209. * sysAuxClkRateGet - get the auxiliary clock rate
  210. *
  211. * This routine returns the interrupt rate of the auxiliary clock.
  212. *
  213. * NOTE:
  214. * This routine has no effect, since there is no auxiliary clock.
  215. * It does not verify the existence of the auxiliary clock.
  216. *
  217. * RETURNS: The number of ticks per second of the auxiliary clock.
  218. *
  219. * SEE ALSO: sysAuxClkEnable(), sysAuxClkRateSet()
  220. */
  221. int sysAuxClkRateGet (void)
  222.     {
  223.     return (auxClkTicksPerSecond);
  224.     }
  225. /*******************************************************************************
  226. *
  227. * sysAuxClkRateSet - set the auxiliary clock rate
  228. *
  229. * This routine sets the interrupt rate of the auxiliary clock.  It does not
  230. * enable auxiliary clock interrupts.
  231. *
  232. * NOTE:
  233. * This routine has no effect, since there is no auxiliary clock.
  234. *
  235. * RETURNS: ERROR, since there is no auxiliary clock.
  236. *
  237. * SEE ALSO: sysAuxClkEnable(), sysAuxClkRateGet()
  238. */
  239. STATUS sysAuxClkRateSet
  240.     (
  241.     int ticksPerSecond     /* number of clock interrupts per second */
  242.     )
  243.     {
  244.     return (ERROR);
  245.     }