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

VxWorks

开发平台:

C/C++

  1. /* CIOTimer.c - Cyclone CVME964 Z8536 CIO timer routines */
  2. /* Copyright 1984-1997 Wind River Systems, Inc. */
  3. #include "copyright_wrs.h"
  4. /*
  5. modification history
  6. --------------------
  7. 01e,03jan97,wlf  doc: more cleanup.
  8. 01d,14jun96,wlf  doc: cleanup.
  9. 01c,17apr96,myz  lock and unlock ints at the chip level 
  10. 01b,10jan96,myz  Modified sysCIOInt, sysClkRateSet and sysAuxClkRateSet 
  11. 01a,17dec93,snc  Created as a result of partitioning/ANSIfying per vxWorks
  12.                  porting guide
  13. */
  14. /*
  15. DESCRIPTION
  16. This library contains routines to manipulate and use the Zilog Z85C36 CIO
  17. which serves as the System Clock and Auxiliary Clock source on the Cyclone
  18. CVME964.
  19. SEE ALSO:
  20. .iB "Cyclone CVME964 User's Manual"
  21. .iB "Intel 80960CA User's Manual"
  22. */
  23. #include "vxWorks.h"
  24. #include "vxLib.h"
  25. #include "sysLib.h"
  26. #include "intLib.h"
  27. #include "config.h"
  28. #include "drv/timer/z8536.h"
  29. /* forward declarations */
  30. void sysCioInt ();
  31. void  sysClkInt ();
  32. void    sysAuxClkInt ();
  33. /* globals */
  34. int     sysClkTicksPerSecond    = 60;
  35. int     sysClkRunning           = FALSE;
  36. FUNCPTR sysClkRoutine           = NULL;
  37. int     sysClkArg               = NULL;
  38. BOOL sysClkConnected = FALSE;
  39. int     sysAuxClkTicksPerSecond = 60;
  40. int     sysAuxClkRunning        = FALSE;
  41. FUNCPTR sysAuxClkRoutine        = NULL;
  42. int     sysAuxClkArg            = NULL;
  43. /*******************************************************************************
  44. *
  45. * sysCioInt - handle a system CIO interrupt
  46. *
  47. * This routine acknowledges a system CIO interrupt
  48. * and determines which CIO subsection caused it.
  49. *
  50. * EXAMPLE: An interrupt results from the expiration of a timer:
  51. *
  52. *     CIO Timer 1 - system tick clock
  53. *     CIO Timer 2 - system auxiliary clock
  54. *     CIO Timer 3 - serial EEPROM accesses
  55. *
  56. * If the interrupt resulted from the expiration of the system clock timer
  57. * (Timer 1), the system clock service routine is called.  If the interrupt
  58. * is the result of an expired auxiliary clock timer (Timer 2), the system
  59. * auxiliary clock service routine is called.
  60. *
  61. * NOTE: During CIO accesses that are required by various code segments,
  62. * CIO interrupts are masked to ensure that their servicing 
  63. * by this routine does not affect the CIO register access state machine.
  64. *
  65. * NOMANUAL
  66. */
  67. void sysCioInt (void)
  68.     {
  69.     volatile UINT8 stat;
  70.     int intHandling;
  71.     /*
  72.      * This do loop is needed to prevent edge triggered interrupt from lockup
  73.      */
  74.     do
  75.         {
  76.         intHandling = FALSE;
  77.         CIO->ctrl = ZCIO_CT1CS;
  78.         stat = CIO->ctrl;           /* get Counter/Timer1 status */
  79.         if (stat & ZCIO_CS_IP)              /* System Clock Tick */
  80.     {
  81.     intHandling = TRUE;
  82.             sysClkInt ();
  83.             }
  84.         CIO->ctrl = ZCIO_CT2CS;
  85.         stat = CIO->ctrl;           /* get Counter/Timer2 status */
  86.         if (stat & ZCIO_CS_IP)
  87.     {
  88.     intHandling = TRUE;
  89.             sysAuxClkInt ();
  90.             }
  91.         /* check  counter/timer 3  */
  92.         CIO->ctrl = ZCIO_CT3CS;
  93.         stat    = CIO->ctrl;
  94.         if (stat & ZCIO_CS_IP )
  95.             {
  96.             intHandling = TRUE;
  97.             
  98.             /* should not get a interrupt from timer 3 */
  99.             /*  simply acknowledge the clock interrupt */
  100.             CIO->ctrl = ZCIO_CT3CS;             /* C/T 3 Command and Status */
  101.             CIO->ctrl = ZCIO_CS_CLIPIUS         /* Clear IP and IUS */
  102.                         | ZCIO_CS_GCB;            /* Gate Command Bit */
  103.             }
  104.             
  105.         } while(intHandling == TRUE);
  106.     }
  107. /*******************************************************************************
  108. *
  109. * sysClkInt - handle a system clock interrupt
  110. *
  111. * This routine handles a system clock interrupt.
  112. *
  113. * The system clock is driven by CIO Counter/Timer 1.
  114. * It calls the routine installed by sysClkConnect().
  115. *
  116. * RETURNS: N/A
  117. *
  118. * SEE ALSO: sysClkConnect()
  119. *
  120. * NOMANUAL
  121. */
  122. void sysClkInt (void)
  123.     {
  124.     /* reset IUS and IP, don't gate */
  125.     CIO->ctrl = ZCIO_CT1CS;
  126.     CIO->ctrl = ZCIO_CS_CLIPIUS | ZCIO_CS_GCB;
  127.     if (sysClkRoutine != NULL)
  128. (*sysClkRoutine) (sysClkArg);
  129.     }
  130. /*******************************************************************************
  131. *
  132. * sysClkConnect - connect a routine to the system clock interrupt
  133. *
  134. * This routine specifies the interrupt service routine to be called at each
  135. * clock interrupt.  It does not enable system clock interrupts.  Normally,
  136. * it is called from usrRoot() in usrConfig.c to connect usrClock() to the
  137. * system clock interrupt.  It also specifies the interrupt service routines
  138. * for the NMI and parity interrupts and enables the parity interrupt.
  139. *
  140. * RETURNS: OK, or ERROR if the routine cannot be connected to the interrupt.
  141. *
  142. * SEE ALSO: intConnect(), usrClock(), sysClkEnable()
  143. */
  144. STATUS sysClkConnect 
  145.     (
  146.     FUNCPTR routine, /* routine called at each system clock interrupt */
  147.     int arg  /* argument with which to call routine           */
  148.     )
  149.     {
  150.     /* if the system clock interrupt is being connected for the first
  151.      * time, connected the CIO handler.
  152.      */
  153.     intConnect ((void *)VECTOR_CIO, sysCioInt, 0);
  154.     sysClkRoutine   = routine;
  155.     sysClkArg       = arg;
  156.     sysClkConnected = TRUE;
  157.     sysHwInit2();
  158.     return (OK);
  159.     }
  160. /*******************************************************************************
  161. *
  162. * sysClkDisable - turn off system clock interrupts
  163. *
  164. * This routine disables system clock interrupts.
  165. *
  166. * RETURNS: N/A
  167. *
  168. * SEE ALSO: sysClkEnable()
  169. */
  170. void sysClkDisable (void)
  171.     {
  172.     volatile unsigned char junk;
  173.     if (!sysClkRunning)
  174. return;
  175.     /* mask CIO interrupts to ensure that the CIO access state machine
  176.        is not corrupted */
  177.     
  178.     CIO->ctrl =  ZCIO_MIC;               /* Master Interrupt Control     */
  179.     junk      =  CIO->ctrl;
  180.     CIO->ctrl =  ZCIO_MIC;               /* Master Interrupt Control     */
  181.     CIO->ctrl =  (~ZCIO_MIC_MIE) & junk;   /* Master Interrupt Disable      */
  182.     /* Disable Timer 1 interrupts from the CIO */
  183.     junk = CIO->ctrl; /* reset the CIO state machine */
  184.     CIO->ctrl = ZCIO_CT1CS;
  185.     CIO->ctrl = ZCIO_CS_CLIE; /* clear Interrupt Enable
  186.    Gate Counter */
  187.     sysClkRunning = FALSE;
  188.     /* don't unmask the CIO interrupt if no system clocks are running */
  189.     if (sysClkRunning || sysAuxClkRunning)
  190.          {
  191.          CIO->ctrl =  ZCIO_MIC;            /* Master Interrupt Control     */
  192.          junk      =  CIO->ctrl;
  193.          CIO->ctrl =  ZCIO_MIC;               /* Master Interrupt Control   */
  194.          CIO->ctrl =  ZCIO_MIC_MIE | junk;   /* Master Interrupt Enable     */
  195.          }
  196.     }
  197. /*******************************************************************************
  198. *
  199. * sysClkEnable - turn on system clock interrupts
  200. *
  201. * This routine enables system clock interrupts.
  202. *
  203. * NOTE: To calculate the time constant of the CIO Timer 1, use the following
  204. * formula:
  205. * .CS
  206. * "CIO_CLK" PCLK ticks   1 timer tick     1 sec
  207. * -------------------- x ------------ x --------------------
  208. *        1 sec           2 PCLK ticks   sysClkTicksPerSecond
  209. * .CE
  210. * The result is the number of timer ticks it takes to achieve the desired
  211. * number of ticks/sec.  This number is calculated as a long, however, the
  212. * CIO uses a 16-bit time constant.  If the result is greater than 65535, the
  213. * time constant is set to 65535.  A time constant of 65535 is almost 32
  214. * milliseconds (31.47 ticks/sec.).
  215. *
  216. * CIO_CLK is defined in ep960jx.h.
  217. *
  218. * NOTE: Timers are clocked at a rate of 1/2 of PCLK.  
  219. * RETURNS: N/A
  220. *
  221. * SEE ALSO: sysClkConnect(), sysClkDisable(), sysClkRateSet(),
  222. * .I "Zilog Z8536 CIO Counter/Timer Technical Manual"
  223. */
  224. void sysClkEnable (void)
  225.     {
  226.     long num_ticks = 0; /* number of ticks needed */
  227.     volatile unsigned char junk;
  228.     /* don't do it if already enabled */
  229.     if (sysClkRunning)
  230. return;
  231.     /* mask CIO interrupts to ensure that the CIO access state machine
  232.        is not corrupted */
  233.     CIO->ctrl =  ZCIO_MIC;               /* Master Interrupt Control     */
  234.     junk      =  CIO->ctrl;
  235.     CIO->ctrl =  ZCIO_MIC;               /* Master Interrupt Control     */
  236.     CIO->ctrl =  (~ZCIO_MIC_MIE) & junk;   /* Master Interrupt Disable   */
  237.     /* Disable Timer 1 interrupts from the CIO */
  238.     junk = CIO->ctrl; /* reset the CIO state machine */
  239.     CIO->ctrl = ZCIO_CT1CS;
  240.     CIO->ctrl = ZCIO_CS_CLIE; /* clear Interrupt Enable
  241.    Gate Counter */
  242.     /* set up the CIO Time Constant registers based on the value
  243.        of sysClkTicksPerSecond */
  244.     if (sysClkTicksPerSecond < SYS_CLK_RATE_MIN)
  245. num_ticks = 0x0ffff;
  246.     else if (sysClkTicksPerSecond > SYS_CLK_RATE_MAX)
  247. num_ticks = 0x01;
  248.     else
  249.     num_ticks = (long) (CIO_CLK / (2 * sysClkTicksPerSecond));
  250.     /* Set up Counter/Timer 1 Mode */
  251.     CIO->ctrl = ZCIO_CT1MS;
  252.     CIO->ctrl = ZCIO_CTMS_CSC; /* continuous cycle
  253.    no external signals used
  254.    pulse output */
  255.     /* Load time constant into Counter/timer 1's TC registers */
  256.     CIO->ctrl = ZCIO_CT1TCMSB; /* Timer 1 time constant MSB */
  257.     CIO->ctrl = (num_ticks >> 8) & 0x0ff;
  258.     CIO->ctrl = ZCIO_CT1TCLSB; /* Timer 1 time constant LSB */
  259.     CIO->ctrl = num_ticks & 0x0ff;
  260.     CIO->ctrl = ZCIO_CT1CS;
  261.     CIO->ctrl = ZCIO_CS_CLIPIUS; /* clear IP and IUS, gate */
  262.     CIO->ctrl = ZCIO_MCC;
  263.     junk = CIO->ctrl;
  264.     CIO->ctrl = ZCIO_MCC;
  265.     CIO->ctrl = junk | 0x40; /* enable Timer 1 */
  266.     CIO->ctrl = ZCIO_CT1CS;
  267.     CIO->ctrl = ZCIO_CS_SIE |
  268.                 ZCIO_CS_GCB |
  269. ZCIO_CS_TCB; /* enable int.
  270.    no gate
  271.    trigger (load) */
  272.     sysClkRunning = TRUE;
  273.     /* don't unmask the CIO interrupt if no system clocks are running */
  274.     if (sysClkRunning || sysAuxClkRunning)
  275.         {
  276.         CIO->ctrl =  ZCIO_MIC;               /* Master Interrupt Control  */ 
  277.         junk      =  CIO->ctrl;
  278.         CIO->ctrl =  ZCIO_MIC;               /* Master Interrupt Control  */
  279.         CIO->ctrl =  ZCIO_MIC_MIE | junk;   /* Master Interrupt Enable    */
  280.         }
  281.     }
  282. /*******************************************************************************
  283. *
  284. * sysClkRateGet - get the system clock rate
  285. *
  286. * This routine returns the system clock rate.
  287. *
  288. * RETURNS: The number of ticks per second of the system clock.
  289. *
  290. * SEE ALSO: sysClkEnable(), sysClkRateSet()
  291. */
  292. int sysClkRateGet (void)
  293.     {
  294.     return (sysClkTicksPerSecond);
  295.     }
  296. /*******************************************************************************
  297. *
  298. * sysClkRateSet - set the system clock rate
  299. *
  300. * This routine sets the interrupt rate of the system clock.
  301. * It is called by usrRoot() in usrConfig.c.
  302. *
  303. * NOTE: Since the CIO contains only a 16-bit counter, if the time constant 
  304. * exceeds 65535, the counter uses 32 ticks/sec.  A value less than 32 ticks/sec.
  305. * does not increase the tick period beyond 32ms.
  306. *
  307. * RETURNS: OK, or ERROR if the tick rate is invalid.
  308. *
  309. * SEE ALSO: sysClkEnable(), sysClkRateGet()
  310. */
  311. STATUS sysClkRateSet 
  312.     (
  313.     int ticksPerSecond  /* number of clock interrupts per second */
  314.     )
  315.     {
  316.     if (ticksPerSecond < SYS_CLK_RATE_MIN || ticksPerSecond > SYS_CLK_RATE_MAX)
  317.         return (ERROR);
  318.     sysClkTicksPerSecond = ticksPerSecond;
  319.     if (sysClkRunning)
  320.         {
  321. sysClkDisable ();
  322. sysClkEnable ();
  323. }
  324.    
  325.     return (OK);
  326.     }
  327. /*******************************************************************************
  328. *
  329. * sysAuxClkInt - handle an auxiliary clock interrupt
  330. *
  331. * This routine handles auxiliary clock interrupts by calling
  332. * the routine installed by sysClkConnect().
  333. *
  334. * The auxiliary clock is driven by Counter/Timer 2 of the CIO.
  335. *
  336. * RETURNS: N/A
  337. *
  338. * SEE ALSO: sysAuxClkConnect()
  339. *
  340. * NOMANUAL
  341. */
  342. void sysAuxClkInt (void)
  343.     {
  344.     /* reset IUS and IP, don't gate */
  345.     CIO->ctrl = ZCIO_CT2CS;
  346.     CIO->ctrl = ZCIO_CS_CLIPIUS | ZCIO_CS_GCB;
  347.  
  348.     /* call auxiliary clock service routine */
  349.     if (sysAuxClkRoutine != NULL)
  350.      (*sysAuxClkRoutine) (sysAuxClkArg);
  351.     }
  352. /*******************************************************************************
  353. *
  354. * sysAuxClkConnect - connect a routine to the auxiliary clock interrupt
  355. *
  356. * This routine specifies the interrupt service routine to be called at each
  357. * auxiliary clock interrupt.  It does not enable auxiliary clock
  358. * interrupts.
  359. *
  360. * RETURNS: OK, always. 
  361. *
  362. * SEE ALSO: intConnect(), sysAuxClkEnable(), sysAuxClkDisconnect(),
  363. *      sysAuxClkInt()
  364. */
  365. STATUS sysAuxClkConnect 
  366.     (
  367.     FUNCPTR routine,    /* routine called at each aux. clock interrupt */
  368.     int     arg         /* argument with which to call routine         */
  369.     )
  370.     {
  371.     /*
  372.      * Assumes that the interrupt from the CIO has already been
  373.      * connected.
  374.      */
  375.     sysAuxClkRoutine = routine;
  376.     sysAuxClkArg = arg;
  377.     return (OK);
  378.     }
  379. /*******************************************************************************
  380. *
  381. * sysAuxClkDisable - turn off auxiliary clock interrupts
  382. *
  383. * This routine disables auxiliary clock interrupts.
  384. *
  385. * RETURNS: N/A
  386. *
  387. * SEE ALSO: sysAuxClkEnable()
  388. */
  389. void sysAuxClkDisable (void)
  390.     {
  391.     volatile unsigned char junk;
  392.     if (!sysAuxClkRunning)
  393. return;
  394.     /* mask CIO interrupts to ensure that the CIO access state machine
  395.     is not corrupted */
  396.     CIO->ctrl =  ZCIO_MIC;               /* Master Interrupt Control     */
  397.     junk      =  CIO->ctrl;
  398.     CIO->ctrl =  ZCIO_MIC;               /* Master Interrupt Control     */
  399.     CIO->ctrl =  (~ZCIO_MIC_MIE) & junk;   /* Master Interrupt Disable   */
  400.     /* Disable Timer 2 interrupts from the CIO */
  401.     junk = CIO->ctrl; /* reset the CIO state machine */
  402.     CIO->ctrl = ZCIO_CT2CS;
  403.     CIO->ctrl = ZCIO_CS_CLIE;   /* clear Interrupt Enable
  404.    Gate Counter */
  405.     sysAuxClkRunning = FALSE;
  406.     /* don't unmask the CIO interrupt if no system clocks are running */
  407.     if (sysClkRunning || sysAuxClkRunning)
  408.         {
  409.         CIO->ctrl =  ZCIO_MIC;               /* Master Interrupt Control  */
  410.         junk      =  CIO->ctrl;
  411.         CIO->ctrl =  ZCIO_MIC;               /* Master Interrupt Control */
  412.         CIO->ctrl =  ZCIO_MIC_MIE | junk;   /* Master Interrupt Enable   */
  413.         }
  414.     }
  415. /*******************************************************************************
  416. *
  417. * sysAuxClkEnable - turn on auxiliary clock interrupts
  418. *
  419. * This routine enables auxiliary clock interrupts.
  420. *
  421. * NOTE: To calculate the time constant of the CIO Timer 1, use the following
  422. * formula:
  423. * .CS
  424. * "CIO_CLK" PCLK ticks   1 timer tick     1 sec
  425. * -------------------- x ------------ x --------------------
  426. *        1 sec           2 PCLK ticks   sysClkTicksPerSecond
  427. * .CE
  428. * The result is the number of timer ticks it takes to achieve the desired
  429. * number of ticks/sec.  This number is calculated as a long integer,
  430. * however, the CIO uses a 16-bit time constant.  If the result is greater
  431. * than 65535, the time constant is set to 65535.  A time constant of 65535
  432. * is almost 32 milliseconds (31.47 ticks/sec.).
  433. *
  434. * CIO_CLK is defined in ep960jx.h.
  435. *
  436. * NOTE: Timers are clocked at a rate of 1/2 of PCLK.  
  437. *
  438. * RETURNS: N/A
  439. *
  440. * SEE ALSO: sysAuxClkConnect(), sysAuxClkDisable(), sysAuxClkRateSet(),
  441. * .I "Zilog Z8536 CIO Counter/Timer Technical Manual"
  442. */
  443. void sysAuxClkEnable (void)
  444.     {
  445.     long num_ticks = 0; /* number of ticks needed */
  446.     volatile unsigned char junk;
  447.     if (sysAuxClkRunning)
  448. return;
  449.     /* mask CIO interrupts to ensure that the CIO access state machine
  450.     is not corrupted */
  451.     CIO->ctrl =  ZCIO_MIC;               /* Master Interrupt Control     */
  452.     junk      =  CIO->ctrl;
  453.     CIO->ctrl =  ZCIO_MIC;               /* Master Interrupt Control     */
  454.     CIO->ctrl =  (~ZCIO_MIC_MIE) & junk;   /* Master Interrupt Disable   */
  455.     /* Disable Timer 2 interrupts from the CIO */
  456.     junk = CIO->ctrl; /* reset the CIO state machine */
  457.     CIO->ctrl = ZCIO_CT2CS;
  458.     CIO->ctrl = ZCIO_CS_CLIE; /* clear Interrupt Enable
  459.    Gate Counter */
  460.     /* set up the CIO Time Constant registers based on the value
  461.        of sysAuxClkTicksPerSecond */
  462.     if (sysAuxClkTicksPerSecond < AUX_CLK_RATE_MIN) 
  463.         num_ticks = 0x0ffff; 
  464.  
  465.     else if (sysAuxClkTicksPerSecond > AUX_CLK_RATE_MAX) 
  466.         num_ticks = 0x01; 
  467.  
  468.     else 
  469.         num_ticks = (long) (CIO_CLK / (2 * sysAuxClkTicksPerSecond));
  470.     /* Set up Counter/Timer 2 Mode */
  471.     CIO->ctrl = ZCIO_CT2MS;
  472.     CIO->ctrl = ZCIO_CTMS_CSC; /* continuous cycle
  473.    no external signals used
  474.    pulse output */
  475.     /* Load time constant into Counter/timer 2's TC registers */
  476.     CIO->ctrl = ZCIO_CT2TCMSB; /* Timer 2 time constant MSB */
  477.     CIO->ctrl = (num_ticks >> 8) & 0x0ff;
  478.     CIO->ctrl = ZCIO_CT2TCLSB; /* Timer 2 time constant LSB */
  479.     CIO->ctrl = num_ticks & 0x0ff;
  480.     CIO->ctrl = ZCIO_CT2CS;
  481.     CIO->ctrl = ZCIO_CS_CLIPIUS; /* clear IP and IUS, gate */
  482.     CIO->ctrl = ZCIO_MCC;
  483.     junk = CIO->ctrl;
  484.     CIO->ctrl = ZCIO_MCC;
  485.     CIO->ctrl = junk | 0x20;        /* enable Timer 2 */
  486.  
  487.     CIO->ctrl = ZCIO_CT2CS;
  488.     CIO->ctrl = ZCIO_CS_SIE |
  489.                 ZCIO_CS_GCB |
  490.         ZCIO_CS_TCB; /* enable int.
  491.    no gate
  492.    trigger (load) */
  493.     sysAuxClkRunning = TRUE;
  494.     /* don't unmask the CIO interrupt if no system clocks are running */
  495.     if (sysClkRunning || sysAuxClkRunning)
  496.         {
  497.         CIO->ctrl =  ZCIO_MIC;               /* Master Interrupt Control */
  498.         junk      =  CIO->ctrl;
  499.         CIO->ctrl =  ZCIO_MIC;               /* Master Interrupt Control */
  500.         CIO->ctrl =  ZCIO_MIC_MIE | junk;    /* Master Interrupt Disable */
  501.         }
  502.     }
  503. /*******************************************************************************
  504. *
  505. * sysAuxClkRateGet - get the auxiliary clock rate
  506. *
  507. * This routine returns the interrupt rate of the auxiliary clock.
  508. *
  509. * RETURNS: Number of ticks per second of the auxiliary clock.
  510. *
  511. * SEE ALSO: sysAuxClkEnable(), sysAuxClkRateSet()
  512. */
  513. int sysAuxClkRateGet (void)
  514.     {
  515.     return (sysAuxClkTicksPerSecond);
  516.     }
  517. /*******************************************************************************
  518. *
  519. * sysAuxClkRateSet - set the auxiliary clock rate
  520. *
  521. * This routine sets the interrupt rate of the auxiliary clock.  It does not
  522. * enable auxiliary clock interrupts.  
  523. *
  524. * RETURNS: OK, or ERROR if the tick rate is invalid.
  525. *
  526. * SEE ALSO: sysAuxClkEnable(), sysAuxClkRateGet()
  527. */
  528. STATUS sysAuxClkRateSet 
  529.     (
  530.     int ticksPerSecond  /* number of clock interrupts per second */
  531.     )
  532.     {
  533.     if (ticksPerSecond < AUX_CLK_RATE_MIN || ticksPerSecond > AUX_CLK_RATE_MAX)
  534.         return (ERROR);
  535.     sysAuxClkTicksPerSecond = ticksPerSecond;
  536.     if (sysAuxClkRunning)
  537. {
  538. sysAuxClkDisable ();
  539. sysAuxClkEnable ();
  540. }
  541.     return (OK);
  542.     }