/************************************************************************ * DESCRIPTION: Starts TCP/IP hardware timer. delay_ms - period of timer (ms) * e.g. Time-out period = (1/FNET_CFG_SYSTEM_CLOCK_KHZ)x(1)x(124+1)x528x100 = 100 ms *************************************************************************/ fnet_return_t fnet_cpu_timer_init( fnet_time_t period_ms ) { fnet_return_t result; fnet_uint32_t timeout; /* Imstall interrupt handler and enable interrupt in NVIC. */ result = fnet_isr_vector_init(FNET_CFG_CPU_TIMER_VECTOR_NUMBER, fnet_cpu_timer_handler_top, fnet_timer_handler_bottom, FNET_CFG_CPU_TIMER_VECTOR_PRIORITY, 0u); if(result == FNET_OK) { /* Initialize the PIT timer to generate an interrupt every period_ms */ /* Enable the clock to the PIT module. Clock for PIT Timers to be enabled */ FNET_MK_SIM_SCGC6 |= FNET_MK_SIM_SCGC6_PIT_MASK; /* Enable the PIT timer module. */ FNET_MK_PIT_MCR &= ~FNET_MK_PIT_MCR_MDIS_MASK; /* Calculate the timeout value. */ timeout = period_ms * FNET_MK_PERIPH_CLOCK_KHZ; FNET_MK_PIT_LDVAL(FNET_CFG_CPU_TIMER_NUMBER) = timeout; /* Enable the timer and enable interrupts */ FNET_MK_PIT_TCTRL(FNET_CFG_CPU_TIMER_NUMBER) |= FNET_MK_PIT_TCTRL_TEN_MASK | FNET_MK_PIT_TCTRL_TIE_MASK; } return result; }
/************************************************************************ * NAME: fnet_cpu_timer_init * * DESCRIPTION: Starts TCP/IP hardware timer. delay_ms - period of timer (ms) * e.g. Time-out period = (1/FNET_CFG_SYSTEM_CLOCK_KHZ)x(1)x(124+1)x528x100 = 100 ms *************************************************************************/ int fnet_cpu_timer_init( unsigned int period_ms ) { int result; /* Install interrupt handler. */ result = fnet_isr_vector_init(FNET_TIMER_VECTOR_NUMBER, fnet_cpu_timer_handler_top, fnet_timer_handler_bottom, FNET_TIMER_INT_LEVEL); if(result == FNET_OK) { FNET_MPC_PITRTI_MCR = 0x04; FNET_MPC_PITRTI_TCTRL(FNET_TIMER_NUMBER) = 0x0; FNET_MPC_PITRTI_LDVAL(FNET_TIMER_NUMBER) = period_ms * FNET_TIMER_CLKIN_PER_MS; FNET_MPC_PITRTI_TCTRL(FNET_TIMER_NUMBER) = 0x3; } return result; }