Changeset 1341

Show
Ignore:
Timestamp:
09/24/08 05:34:53 (12 years ago)
Author:
ppalmers
Message:

Add reverse mapping support to obtain system time based upon the ctr value

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/libffado-2.0/src/libieee1394/CycleTimerHelper.cpp

    r1292 r1341  
    654654} 
    655655 
     656uint64_t 
     657CycleTimerHelper::getSystemTimeForCycleTimerTicks(uint32_t ticks) 
     658{ 
     659    uint64_t retval; 
     660    struct compute_vars *my_vars; 
     661 
     662    // get pointer and copy the contents 
     663    // no locking should be needed since we have more than one 
     664    // of these vars available, and our use will always be finished before 
     665    // m_current_shadow_idx changes since this thread's priority should 
     666    // be higher than the one of the writer thread. Even if not, we only have to ensure 
     667    // that the used dataset is consistent. We can use an older dataset if it's consistent 
     668    // since it will also provide a fairly decent extrapolation. 
     669    my_vars = m_shadow_vars + m_current_shadow_idx; 
     670 
     671    // the number of ticks the request is ahead of the current CTR position 
     672    int64_t ticks_diff = diffTicks(ticks, my_vars->ticks); 
     673    // to how much time does this correspond? 
     674    double x_step_in_usec = ((double)ticks_diff) / my_vars->rate; 
     675    int64_t x_step_in_usec_int = (int64_t)x_step_in_usec; 
     676    retval = my_vars->usecs + x_step_in_usec_int; 
     677 
     678    return retval; 
     679} 
     680 
     681uint64_t 
     682CycleTimerHelper::getSystemTimeForCycleTimer(uint32_t ctr) 
     683{ 
     684    uint32_t ticks = CYCLE_TIMER_TO_TICKS(ctr); 
     685    return getSystemTimeForCycleTimerTicks(ticks); 
     686} 
     687 
    656688#else 
    657689 
     
    685717CycleTimerHelper::getCycleTimerTicks(uint64_t now) 
    686718{ 
    687     debugWarning("not implemented!\n"); 
    688     return getCycleTimerTicks(); 
     719    debugWarning("untested code\n"); 
     720    #warning Untested code 
     721    uint32_t cycle_timer; 
     722    uint64_t local_time; 
     723    readCycleTimerWithRetry(&cycle_timer, &local_time, 10); 
     724    int64_t ticks = CYCLE_TIMER_TO_TICKS(cycle_timer); 
     725 
     726    int delta_t = now - local_time; // how far ahead is the request? 
     727    ticks += delta_t * getRate(); // add ticks 
     728    if (ticks >= TICKS_PER_SECOND * 128) ticks -= TICKS_PER_SECOND * 128; 
     729    else if (ticks < 0) ticks += TICKS_PER_SECOND * 128; 
     730    return ticks; 
    689731} 
    690732 
     
    701743CycleTimerHelper::getCycleTimer(uint64_t now) 
    702744{ 
     745    return TICKS_TO_CYCLE_TIMER(getCycleTimerTicks(now)); 
     746} 
     747 
     748uint64_t 
     749CycleTimerHelper::getSystemTimeForCycleTimerTicks(uint32_t ticks) 
     750{ 
    703751    debugWarning("not implemented!\n"); 
    704     return getCycleTimer(); 
     752    return 0; 
     753
     754 
     755uint64_t 
     756CycleTimerHelper::getSystemTimeForCycleTimer(uint32_t ctr) 
     757
     758    uint32_t ticks = CYCLE_TIMER_TO_TICKS(ctr); 
     759    return getSystemTimeForCycleTimerTicks(ticks); 
    705760} 
    706761 
  • branches/libffado-2.0/src/libieee1394/CycleTimerHelper.h

    r1080 r1341  
    9898    uint32_t getCycleTimer(uint64_t now); 
    9999 
     100    /** 
     101     * @brief get the system time for a specific cycle timer value (in ticks) 
     102     * @note thread safe 
     103     */ 
     104    uint64_t getSystemTimeForCycleTimerTicks(uint32_t ticks); 
     105 
     106    /** 
     107     * @brief get the system time for a specific cycle timer value (in CTR format) 
     108     * @note thread safe 
     109     */ 
     110    uint64_t getSystemTimeForCycleTimer(uint32_t ctr); 
     111 
    100112    float getRate(); 
    101113    float getNominalRate(); 
  • branches/libffado-2.0/src/libieee1394/ieee1394service.cpp

    r1294 r1341  
    385385} 
    386386 
     387uint64_t 
     388Ieee1394Service::getSystemTimeForCycleTimerTicks(uint32_t ticks) { 
     389    return m_pCTRHelper->getSystemTimeForCycleTimerTicks(ticks); 
     390} 
     391 
     392uint64_t 
     393Ieee1394Service::getSystemTimeForCycleTimer(uint32_t ctr) { 
     394    return m_pCTRHelper->getSystemTimeForCycleTimer(ctr); 
     395} 
     396 
    387397bool 
    388398Ieee1394Service::readCycleTimerReg(uint32_t *cycle_timer, uint64_t *local_time) 
  • branches/libffado-2.0/src/libieee1394/ieee1394service.h

    r1294 r1341  
    133133     */ 
    134134    uint32_t getCycleTimer(uint64_t t); 
     135 
     136    /** 
     137     * @brief get the system time for a specific cycle timer value (in ticks) 
     138     * @note thread safe 
     139     */ 
     140    uint64_t getSystemTimeForCycleTimerTicks(uint32_t ticks); 
     141 
     142    /** 
     143     * @brief get the system time for a specific cycle timer value (in CTR format) 
     144     * @note thread safe 
     145     */ 
     146    uint64_t getSystemTimeForCycleTimer(uint32_t ctr); 
    135147 
    136148    /**