void configure_timeout(const pstimer_t *timer, uint64_t ns) { gpt_t *gpt = (gpt_t *)timer->data; struct gpt_map *gptMap = gpt->gpt_map; /* Stop time. */ *(volatile uint32_t *)&(gptMap->tclr) = 0; /* Reset timer. */ *(volatile uint32_t *)&(gptMap->cfg) |= BIT(SOFTRESET); while ( ! *(volatile uint32_t *)&(gptMap->tistat) ); /* Wait for GPT to reset */ *(volatile uint32_t *)&(gptMap->tclr) = BIT(PRE) | (gpt->prescaler << PTV); /* Set the prescaler */ //gptMap->tclr = BIT(PRE); /* Enable the prescaler */ /* Enable interrupt on overflow. */ *(volatile uint32_t *)&(gptMap->tier) = BIT(OVF_IT_ENA); /* Set the reload value. */ *(volatile uint32_t *)&(gptMap->tldr) = ~0UL - TIMER_INTERVAL_TICKS(ns); /* Reset the read register. */ *(volatile uint32_t *)&(gptMap->tcrr) = ~0UL - TIMER_INTERVAL_TICKS(ns); /* gptMap->tpir = 232000; gptMap->tnir = 0xFFF448000; gptMap->tsicr = BIT(POSTED) | BIT(SFT); */ /* Clear pending overflows. */ *(volatile uint32_t *)&(gptMap->tisr) = BIT(OVF_IT_FLAG); // ackInterrupt(37); }
void configure_timeout(const pstimer_t *timer, uint64_t ns) { gpt_t *gpt = (gpt_t*) timer->data; /* Stop time. */ gpt->gpt_map->tclr = 0; /* Reset timer. */ gpt->gpt_map->cfg = BIT(SOFTRESET); while (!gpt->gpt_map->tistat); /* Wait for GPT to reset */ gpt->gpt_map->tclr = (gpt->prescaler << PTV); /* Set the prescaler */ gpt->gpt_map->tclr = BIT(PRE); /* Enable the prescaler */ /* Enable interrupt on overflow. */ gpt->gpt_map->tier = BIT(OVF_IT_ENA); /* Set the reload value. */ gpt->gpt_map->tldr = ~0UL - TIMER_INTERVAL_TICKS(ns); /* Reset the read register. */ gpt->gpt_map->tcrr = ~0UL - TIMER_INTERVAL_TICKS(ns); /* Clear pending overflows. */ gpt->gpt_map->tisr = BIT(OVF_IT_FLAG); }
static int dm_periodic(uint64_t ns) { /* Stop time. */ dm->tclr = 0; /* Reset timer. */ dm->cfg = TIOCP_CFG_SOFTRESET; while (dm->cfg & TIOCP_CFG_SOFTRESET); /* Enable interrupt on overflow. */ dm->tier = TIER_OVERFLOWENABLE; /* Set the reload value. */ dm->tldr = ~0UL - TIMER_INTERVAL_TICKS(ns); /* Reset the read register. */ dm->tcrr = ~0UL - TIMER_INTERVAL_TICKS(ns); /* Clear pending overflows. */ dm->tisr = TISR_OVF_FLAG; /* Set autoreload and start the timer. */ dm->tclr = TCLR_AUTORELOAD | TCLR_STARTTIMER; }
static int dm_set_timeo(const pstimer_t *timer, uint64_t ns, int tclrFlags) { dmt_t *dmt = (dmt_t*) timer->data; dmt->hw->tclr = 0; /* stop */ /* XXX handle prescaler */ /* XXX handle invalid arguments with an error return */ uint32_t ticks = TIMER_INTERVAL_TICKS(ns); if (ticks < 2) { return EINVAL; } //printf("timer %lld ns = %x ticks (cntr %x)\n", ns, ticks, (uint32_t)(~0UL - ticks)); dmt->hw->tldr = ~0UL - ticks; /* reload value */ dmt->hw->tcrr = ~0UL - ticks; /* counter */ dmt->hw->tisr = TISR_OVF_FLAG; /* ack any pending overflows */ dmt->hw->tclr = TCLR_STARTTIMER | tclrFlags; return 0; }