//***************************************************************************** // //! Updates the CPU usage for the new timing period. //! //! This function, when called at the end of a timing period, will update the //! CPU usage. //! //! \return Returns the CPU usage percentage as a 16.16 fixed-point value. // //***************************************************************************** unsigned long CPUUsageTick(void) { unsigned long ulValue, ulUsage; // // Get the current value of the timer. // ulValue = MAP_TimerValueGet(g_pulCPUUsageTimerBase[g_ulCPUUsageTimer], TIMER_A); // // Based on the number of clock ticks accumulated by the timer during the // previous timing period, compute the CPU usage as a 16.16 fixed-point // value. // ulUsage = ((((g_ulCPUUsagePrevious - ulValue) * 6400) / g_ulCPUUsageTicks) * 1024); // // Save the previous value of the timer. // g_ulCPUUsagePrevious = ulValue; // // Return the new CPU usage value. // return(ulUsage); }
static i32 hwt32_get_current(struct hw_timer32 *hwt, u32 *current) { u32 count = 0; i32 rv = 0; switch(hwt->op_mode) { case HW_TIMER_ONE_SHOT: case HW_TIMER_PERIODIC: { /* Counting downwards to zero from the 'load' value. */ u32 loaded = MAP_TimerLoadGet(hwt->base_addr, TIMER_A); u32 value = MAP_TimerValueGet(hwt->base_addr, TIMER_A); count = (value < HWT32_ACCESS_CYCLES)? loaded : loaded - value - HWT32_ACCESS_CYCLES; } break; case HW_TIMER_MONOTONE: { struct u64_val adjusted = {0, 0}; hwt32_process_monotone_current(hwt, &adjusted); count = adjusted.lo_32; } break; default: rv = -1; break; } if(0 == rv) *current = count; return rv; }
static i32 hwt32_get_remaining(struct hw_timer32 *hwt, u32 *remaining) { u32 count = 0; i32 rv = 0; switch(hwt->op_mode) { case HW_TIMER_ONE_SHOT: case HW_TIMER_PERIODIC: /* Counting downwards to zero from the 'load' value. */ count = MAP_TimerValueGet(hwt->base_addr, TIMER_A); break; case HW_TIMER_MONOTONE: { /* Monotonic: Counter keeps ticking even after match w/ 'alarm' is done, so need some additional checks */ u32 match = MAP_TimerMatchGet(hwt->base_addr, TIMER_A); u32 value = MAP_TimerValueGet(hwt->base_addr, TIMER_A); if(MAP_TimerIntStatus(hwt->base_addr, true) && TIMER_TIMA_MATCH) rv = -1; /* HW: Match value has been attained */ else count = v1_to_v2_offset32(value, match); } break; default: rv = -1; break; } if(0 == rv) { *remaining = count > HWT32_ACCESS_CYCLES ? count - HWT32_ACCESS_CYCLES :/* Adjusted time */ 0; } return rv; }
//***************************************************************************** // //! Timer interrupt handler // //***************************************************************************** static void TimerIntHandler() { // // Clear the interrupt // MAP_TimerIntClear(TIMERA2_BASE,TIMER_CAPA_EVENT); // // Get the samples and compute the frequency // g_ulSamples[0] = g_ulSamples[1]; g_ulSamples[1] = MAP_TimerValueGet(TIMERA2_BASE,TIMER_A); g_ulFreq = (TIMER_FREQ/(g_ulSamples[0] - g_ulSamples[1])); }
static i32 hwt32_process_monotone_current(struct hw_timer32 *hwt, struct u64_val *current64) { u32 count = MAP_TimerValueGet(hwt->base_addr, TIMER_A); util_u32_data_add(count, HWT32_ACCESS_CYCLES, current64); if((current64->hi_32 != 0) && (false == hwt->sw_early_ro)) { hwt->sw_early_ro = true; hwt->n_rollovers++; } current64->hi_32 = hwt->n_rollovers; return 0; }
//***************************************************************************** // //! starts the timer //! //! \param ulBase is the base address for the timer. //! \param ulTimer selects amoung the TIMER_A or TIMER_B or TIMER_BOTH. //! //! This function //! 1. returns the timer value. //! //! \return Timer Value. // //***************************************************************************** unsigned int Timer_IF_GetCount(unsigned long ulBase, unsigned long ulTimer) { unsigned long ulCounter; ulCounter = MAP_TimerValueGet(ulBase, ulTimer); return 0xFFFFFFFF - ulCounter; }