📄 ciotimer.c
字号:
trigger (load) */ sysClkRunning = TRUE; /* don't unmask the CIO interrupt if no system clocks are running */ if (sysClkRunning || sysAuxClkRunning) { CIO->ctrl = ZCIO_MIC; /* Master Interrupt Control */ junk = CIO->ctrl; CIO->ctrl = ZCIO_MIC; /* Master Interrupt Control */ CIO->ctrl = ZCIO_MIC_MIE | junk; /* Master Interrupt Enable */ } }/********************************************************************************* sysClkRateGet - get the system clock rate** This routine returns the system clock rate.** RETURNS: The number of ticks per second of the system clock.** SEE ALSO: sysClkEnable(), sysClkRateSet()*/int sysClkRateGet (void) { return (sysClkTicksPerSecond); }/********************************************************************************* sysClkRateSet - set the system clock rate** This routine sets the interrupt rate of the system clock.* It is called by usrRoot() in usrConfig.c.** NOTE: Since the CIO contains only a 16-bit counter, if the time constant * exceeds 65535, the counter uses 32 ticks/sec. A value less than 32 ticks/sec.* does not increase the tick period beyond 32ms.** RETURNS: OK, or ERROR if the tick rate is invalid.** SEE ALSO: sysClkEnable(), sysClkRateGet()*/STATUS sysClkRateSet ( int ticksPerSecond /* number of clock interrupts per second */ ) { if (ticksPerSecond < SYS_CLK_RATE_MIN || ticksPerSecond > SYS_CLK_RATE_MAX) return (ERROR); sysClkTicksPerSecond = ticksPerSecond; if (sysClkRunning) { sysClkDisable (); sysClkEnable (); } return (OK); }/********************************************************************************* sysAuxClkInt - handle an auxiliary clock interrupt** This routine handles auxiliary clock interrupts by calling* the routine installed by sysClkConnect().** The auxiliary clock is driven by Counter/Timer 2 of the CIO.** RETURNS: N/A** SEE ALSO: sysAuxClkConnect()** NOMANUAL*/void sysAuxClkInt (void) { /* reset IUS and IP, don't gate */ CIO->ctrl = ZCIO_CT2CS; CIO->ctrl = ZCIO_CS_CLIPIUS | ZCIO_CS_GCB; /* call auxiliary clock service routine */ if (sysAuxClkRoutine != NULL) (*sysAuxClkRoutine) (sysAuxClkArg); }/********************************************************************************* sysAuxClkConnect - connect a routine to the auxiliary clock interrupt** This routine specifies the interrupt service routine to be called at each* auxiliary clock interrupt. It does not enable auxiliary clock* interrupts.** RETURNS: OK, always. ** SEE ALSO: intConnect(), sysAuxClkEnable(), sysAuxClkDisconnect(),* sysAuxClkInt()*/STATUS sysAuxClkConnect ( FUNCPTR routine, /* routine called at each aux. clock interrupt */ int arg /* argument with which to call routine */ ) { /* * Assumes that the interrupt from the CIO has already been * connected. */ sysAuxClkRoutine = routine; sysAuxClkArg = arg; return (OK); }/********************************************************************************* sysAuxClkDisable - turn off auxiliary clock interrupts** This routine disables auxiliary clock interrupts.** RETURNS: N/A** SEE ALSO: sysAuxClkEnable()*/void sysAuxClkDisable (void) { volatile unsigned char junk; if (!sysAuxClkRunning) return; /* mask CIO interrupts to ensure that the CIO access state machine is not corrupted */ CIO->ctrl = ZCIO_MIC; /* Master Interrupt Control */ junk = CIO->ctrl; CIO->ctrl = ZCIO_MIC; /* Master Interrupt Control */ CIO->ctrl = (~ZCIO_MIC_MIE) & junk; /* Master Interrupt Disable */ /* Disable Timer 2 interrupts from the CIO */ junk = CIO->ctrl; /* reset the CIO state machine */ CIO->ctrl = ZCIO_CT2CS; CIO->ctrl = ZCIO_CS_CLIE; /* clear Interrupt Enable Gate Counter */ sysAuxClkRunning = FALSE; /* don't unmask the CIO interrupt if no system clocks are running */ if (sysClkRunning || sysAuxClkRunning) { CIO->ctrl = ZCIO_MIC; /* Master Interrupt Control */ junk = CIO->ctrl; CIO->ctrl = ZCIO_MIC; /* Master Interrupt Control */ CIO->ctrl = ZCIO_MIC_MIE | junk; /* Master Interrupt Enable */ } }/********************************************************************************* sysAuxClkEnable - turn on auxiliary clock interrupts** This routine enables auxiliary clock interrupts.** NOTE: To calculate the time constant of the CIO Timer 1, use the following* formula:* .CS* "CIO_CLK" PCLK ticks 1 timer tick 1 sec* -------------------- x ------------ x --------------------* 1 sec 2 PCLK ticks sysClkTicksPerSecond* .CE* The result is the number of timer ticks it takes to achieve the desired* number of ticks/sec. This number is calculated as a long integer,* however, the CIO uses a 16-bit time constant. If the result is greater* than 65535, the time constant is set to 65535. A time constant of 65535* is almost 32 milliseconds (31.47 ticks/sec.).** CIO_CLK is defined in ep960jx.h.** NOTE: Timers are clocked at a rate of 1/2 of PCLK. ** RETURNS: N/A** SEE ALSO: sysAuxClkConnect(), sysAuxClkDisable(), sysAuxClkRateSet(),* .I "Zilog Z8536 CIO Counter/Timer Technical Manual"*/void sysAuxClkEnable (void) { long num_ticks = 0; /* number of ticks needed */ volatile unsigned char junk; if (sysAuxClkRunning) return; /* mask CIO interrupts to ensure that the CIO access state machine is not corrupted */ CIO->ctrl = ZCIO_MIC; /* Master Interrupt Control */ junk = CIO->ctrl; CIO->ctrl = ZCIO_MIC; /* Master Interrupt Control */ CIO->ctrl = (~ZCIO_MIC_MIE) & junk; /* Master Interrupt Disable */ /* Disable Timer 2 interrupts from the CIO */ junk = CIO->ctrl; /* reset the CIO state machine */ CIO->ctrl = ZCIO_CT2CS; CIO->ctrl = ZCIO_CS_CLIE; /* clear Interrupt Enable Gate Counter */ /* set up the CIO Time Constant registers based on the value of sysAuxClkTicksPerSecond */ if (sysAuxClkTicksPerSecond < AUX_CLK_RATE_MIN) num_ticks = 0x0ffff; else if (sysAuxClkTicksPerSecond > AUX_CLK_RATE_MAX) num_ticks = 0x01; else num_ticks = (long) (CIO_CLK / (2 * sysAuxClkTicksPerSecond)); /* Set up Counter/Timer 2 Mode */ CIO->ctrl = ZCIO_CT2MS; CIO->ctrl = ZCIO_CTMS_CSC; /* continuous cycle no external signals used pulse output */ /* Load time constant into Counter/timer 2's TC registers */ CIO->ctrl = ZCIO_CT2TCMSB; /* Timer 2 time constant MSB */ CIO->ctrl = (num_ticks >> 8) & 0x0ff; CIO->ctrl = ZCIO_CT2TCLSB; /* Timer 2 time constant LSB */ CIO->ctrl = num_ticks & 0x0ff; CIO->ctrl = ZCIO_CT2CS; CIO->ctrl = ZCIO_CS_CLIPIUS; /* clear IP and IUS, gate */ CIO->ctrl = ZCIO_MCC; junk = CIO->ctrl; CIO->ctrl = ZCIO_MCC; CIO->ctrl = junk | 0x20; /* enable Timer 2 */ CIO->ctrl = ZCIO_CT2CS; CIO->ctrl = ZCIO_CS_SIE | ZCIO_CS_GCB | ZCIO_CS_TCB; /* enable int. no gate trigger (load) */ sysAuxClkRunning = TRUE; /* don't unmask the CIO interrupt if no system clocks are running */ if (sysClkRunning || sysAuxClkRunning) { CIO->ctrl = ZCIO_MIC; /* Master Interrupt Control */ junk = CIO->ctrl; CIO->ctrl = ZCIO_MIC; /* Master Interrupt Control */ CIO->ctrl = ZCIO_MIC_MIE | junk; /* Master Interrupt Disable */ } }/********************************************************************************* sysAuxClkRateGet - get the auxiliary clock rate** This routine returns the interrupt rate of the auxiliary clock.** RETURNS: Number of ticks per second of the auxiliary clock.** SEE ALSO: sysAuxClkEnable(), sysAuxClkRateSet()*/int sysAuxClkRateGet (void) { return (sysAuxClkTicksPerSecond); }/********************************************************************************* sysAuxClkRateSet - set the auxiliary clock rate** This routine sets the interrupt rate of the auxiliary clock. It does not* enable auxiliary clock interrupts. ** RETURNS: OK, or ERROR if the tick rate is invalid.** SEE ALSO: sysAuxClkEnable(), sysAuxClkRateGet()*/STATUS sysAuxClkRateSet ( int ticksPerSecond /* number of clock interrupts per second */ ) { if (ticksPerSecond < AUX_CLK_RATE_MIN || ticksPerSecond > AUX_CLK_RATE_MAX) return (ERROR); sysAuxClkTicksPerSecond = ticksPerSecond; if (sysAuxClkRunning) { sysAuxClkDisable (); sysAuxClkEnable (); } return (OK); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -