/************************************************************************************ * startHeartbeatTimer.c * * synopsis: Initializes a timer channel and uses it to put a square wave onto the * TOUT pin which is wired to an LED. * * Damon Fasching, UW Madison (510)486-5230 fasching@wisconsin.cern.ch ************************************************************************************/ #include #include #include "resources.h" #include "registerIndices.h" #include "memoryPartitions.h" #include "peripheralMap.h" #pragma CODE_SECTION(startHeartbeatTimer, "xcode"); #pragma CODE_SECTION(startUserTimer, "xcode"); TIMER_Handle hHeartbeatTimerCh; /************************************************************************************ * startHeartbeatTimer * * synopsis: Initializes the timer (timer 0) which drives the "heart-beat" LED. * * timerPeriod is the value to be loaded into the timer period register. * For TIMER_CLK_INTERNAL, the timer counter counts at the cpuClk/4 = 40 MHz on ROD. * When the counter value is reached: * 1) The value of TSTAT toggles AND * 2) The Timer Counter Register is reset. * So, at 40 MHz counting, the timer frequency is given by: * f = 40 MHz/(2*timerPeriod) * * timerPeriod f (Hz) P (s) * 0x10000000 .074 13.4 * 0x01000000 1.2 0.84 * 0x00100000 19.1 0.052 * * modifications/bugs * - Both MDSP/SDSP timer 0 TOUT now drive the green LED directly. 01.09.02 dpsf * - Timer handle is now global for access by other routines. 28.01.03 dpsf ************************************************************************************/ void startHeartbeatTimer(UINT32 period) { UINT32 timerCtl= 0x0, count= 0x0; hHeartbeatTimerCh = TIMER_open(HEARTBEAT_TIMER_CH, TIMER_OPEN_RESET); timerCtl= TIMER_CTL_RMK(TIMER_CTL_INVINP_NO, TIMER_CTL_CLKSRC_CPUOVR4, TIMER_CTL_CP_CLOCK, TIMER_CTL_HLD_NO, TIMER_CTL_GO_YES, TIMER_CTL_PWID_ONE, TIMER_CTL_DATOUT_0, TIMER_CTL_INVOUT_NO, TIMER_CTL_FUNC_TOUT); TIMER_configArgs(hHeartbeatTimerCh, timerCtl, period, count); return; } /************************************************************************************ * startUserTimer * * synopsis: If the user timer is available, starts it and returns the handle. * If it is not available, returns INV. * * modifications/bugs * - Timer was initialized in paused state, causing primitives which depend on * it to loop endlessly (..._HLD_YES). Set to HLD_NO. 08.04.02 dpsf * - This routine is now called once by the main loop, to set the timer running * endlessly at the maximum period (0xffffffff). Timing is done by calling * TIMER_getCount successively & subtracting (UINT32 will always give the * correct value: dt= 2 -0xfffffffe = 4. 15.01.03 dpsf ************************************************************************************/ TIMER_Handle startUserTimer(UINT32 period) { UINT32 timerCtl= 0x0, count= 0x0; TIMER_Handle hUserTimer; hUserTimer = TIMER_open(USER_TIMER_CH, TIMER_OPEN_RESET); if (hUserTimer != INV) { timerCtl= TIMER_CTL_RMK(TIMER_CTL_INVINP_NO, TIMER_CTL_CLKSRC_CPUOVR4, TIMER_CTL_CP_CLOCK, TIMER_CTL_HLD_NO, TIMER_CTL_GO_YES, TIMER_CTL_PWID_ONE, TIMER_CTL_DATOUT_0, TIMER_CTL_INVOUT_NO, TIMER_CTL_FUNC_GPIO); TIMER_configArgs(hUserTimer, timerCtl, period, count); } return hUserTimer; }