Changeset 430

Show
Ignore:
Timestamp:
03/05/07 21:47:17 (14 years ago)
Author:
jwoithe
Message:

MOTU: more streaming update work. Rx now appears to be working correctly.
Tx makes a noise but there are regular glitches, indicating that things
aren't quite right yet (the tx timestamps are probably not tight enough).

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/streaming-rework/src/libstreaming/MotuStreamProcessor.cpp

    r428 r430  
    5252// A macro to extract specific bits from a native endian quadlet 
    5353#define get_bits(_d,_start,_len) (((_d)>>((_start)-(_len)+1)) & ((1<<(_len))-1)) 
     54 
     55// Convert an SPH timestamp as received from the MOTU to a full timestamp in ticks. 
     56static inline uint32_t sphRecvToFullTicks(uint32_t sph, uint32_t ct_now) { 
     57 
     58uint32_t timestamp = CYCLE_TIMER_TO_TICKS(sph & 0x1ffffff); 
     59uint32_t now_cycles = CYCLE_TIMER_GET_CYCLES(ct_now); 
     60 
     61uint32_t ts_sec = CYCLE_TIMER_GET_SECS(ct_now); 
     62  // If the cycles have wrapped, correct ts_sec so it represents when timestamp 
     63  // was received.  The timestamps sent by the MOTU are always 1 or two cycles  
     64  // in advance of the cycle timer (reasons unknown at this stage).  In addition, 
     65  // iso buffering can delay the arrival of packets for quite a number of cycles 
     66  // (have seen a delay >12 cycles). 
     67  if (abs(CYCLE_TIMER_GET_CYCLES(sph) - now_cycles) > 1000) { 
     68debugOutput(DEBUG_LEVEL_VERBOSE, "now=%d, ct=%d\n", now_cycles, CYCLE_TIMER_GET_CYCLES(sph)); 
     69    if (ts_sec) 
     70      ts_sec--; 
     71    else 
     72      ts_sec = 127; 
     73  } 
     74  return timestamp + ts_sec*TICKS_PER_SECOND; 
     75} 
     76 
     77// Convert a full timestamp into an SPH timestamp as required by the MOTU 
     78static inline uint32_t fullTicksToSph(uint32_t timestamp) { 
     79  return timestamp & 0x1ffffff; 
     80} 
    5481 
    5582/* transmit */ 
     
    233260        // We could (and silently junk the contents) if it turned out to be 
    234261        // more helpful. 
    235          
     262 
     263//if (!m_is_disabled && m_running) 
     264//  return RAW1394_ISO_OK; 
     265//else   
    236266        return RAW1394_ISO_DEFER; 
    237267    } 
     
    284314float ticks_per_frame = m_SyncSource->m_data_buffer->getRate(); 
    285315                for (i=0; i<n_events; i++, quadlet += dbs) { 
    286                         unsigned int ts_frame = ts; 
     316//                      unsigned int ts_frame = ts; 
     317                        unsigned int ts_frame = timestamp; 
    287318                        ts_frame += (unsigned int)((float)i * ticks_per_frame); 
    288                         *quadlet = htonl( TICKS_TO_CYCLE_TIMER(ts_frame) ); 
     319                        *quadlet = htonl( TICKS_TO_CYCLE_TIMER(ts_frame) & 0x1ffffff); 
     320if (cycle==0) { 
     321  debugOutput(DEBUG_LEVEL_VERBOSE,"%d %d %d\n", 
     322    TICKS_TO_SECS(ts_frame), 
     323    TICKS_TO_CYCLES(ts_frame), 
     324    TICKS_TO_OFFSET(ts_frame)); 
     325
     326#if TESTTONE 
     327                        // FIXME: remove this hacked in 1 kHz test signal to 
     328                        // analog-1 when testing is complete.  Note that the tone is 
     329                        // *never* added during closedown. 
     330                        if (m_closedown_count<0) { 
     331                                static signed int a_cx = 0; 
     332                                signed int val; 
     333                                val = (int)(0x7fffff*sin(1000.0*2.0*M_PI*(a_cx/24576000.0))); 
     334                                if ((a_cx+=512) >= 24576000) { 
     335                                        a_cx -= 24576000; 
     336                                } 
     337                                *(data+8+i*m_event_size+16) = (val >> 16) & 0xff; 
     338                                *(data+8+i*m_event_size+17) = (val >> 8) & 0xff; 
     339                                *(data+8+i*m_event_size+18) = val & 0xff; 
     340                        } 
     341#endif 
     342 
    289343                } 
    290344 
     
    421475     
    422476    // FIXME: check if the timestamp wraps at one second 
    423     m_data_buffer->setWrapValue(TICKS_PER_SECOND); 
     477    m_data_buffer->setWrapValue(128L*TICKS_PER_SECOND); 
    424478     
    425479    m_data_buffer->prepare(); 
     
    9711025//uint32_t first_sph = ntohl(*(quadlet_t *)(data+8+(event_length*(n_events-1)))); 
    9721026//        m_last_timestamp = ((first_sph & 0x1fff000)>>12)*3072 + (first_sph & 0xfff); 
    973         m_last_timestamp = CYCLE_TIMER_TO_TICKS(first_sph & 0x1ffffff); 
     1027//        m_last_timestamp = CYCLE_TIMER_TO_TICKS(first_sph & 0x1ffffff); 
     1028m_last_timestamp = sphRecvToFullTicks(first_sph, m_handler->getCycleTimer()); 
    9741029 
    9751030                // Signal that we're running 
     
    9971052            // set the timestamp as if there will be a sample put into 
    9981053            // the buffer by the next packet. 
    999 if (ts > TICKS_PER_SECOND) 
    1000   ts -= TICKS_PER_SECOND; 
     1054if (ts >= 128L* TICKS_PER_SECOND) 
     1055  ts -= 128L*TICKS_PER_SECOND; 
    10011056            m_data_buffer->setBufferTailTimestamp(ts); 
    10021057//debugOutput(DEBUG_LEVEL_VERBOSE,"%p, last ts=%lld, ts=%lld, lts2=%lld\n", m_data_buffer, m_last_timestamp, ts, m_last_timestamp2); 
     
    11041159    m_data_buffer->setNominalRate(m_ticks_per_frame); 
    11051160     
    1106     m_data_buffer->setWrapValue(TICKS_PER_SECOND); 
     1161    m_data_buffer->setWrapValue(128L*TICKS_PER_SECOND); 
    11071162     
    11081163    m_data_buffer->prepare();