Changeset 1586

Show
Ignore:
Timestamp:
06/26/09 05:43:09 (15 years ago)
Author:
jwoithe
Message:

RME: obtain and interpret TCO status from device.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/libffado/src/rme/fireface_def.h

    r1585 r1586  
    427427#define FF_TCO1_WORD_CLOCK_INPUT_2x           FF_TCO1_WORD_CLOCK_INPUT_RATE0 
    428428#define FF_TCO1_WORD_CLOCK_INPUT_4x           FF_TCO1_WORD_CLOCK_INPUT_RATE1 
     429#define FF_TCO1_WORD_CLOCK_INPUT_MASK         (FF_TCO1_WORD_CLOCK_INPUT_RATE0|FF_TCO1_WORD_CLOCK_INPUT_RATE1) 
     430#define FF_TCO1_VIDEO_INPUT_MASK              (FF_TCO1_VIDEO_INPUT_NTSC|FF_TCO1_VIDEO_INPUT_PAL) 
    429431#define FF_TC01_LTC_FORMAT_24fps              0 
    430432#define FF_TCO1_LTC_FORMAT_25fps              FF_TCO1_LTC_FORMAT0 
     
    433435#define FF_TCO1_LTC_FORMAT_30fps              (FF_TCO1_LTC_FORMAT0|FF_TCO1_LTC_FORMAT1) 
    434436#define FF_TCO1_LTC_FORMAT_30dfps             (FF_TCO1_LTC_FORMAT0|FF_TCO1_LTC_FORMAT1|FF_TCO1_SET_DROPFRAME) 
     437#define FF_TCO1_LTC_FORMAT_MASK               (FF_TCO1_LTC_FORMAT0|FF_TCO1_LTC_FORMAT1) 
    435438 
    436439// TCO quadlet 2 
     
    489492#define FF_TCOPARAM_TERMINATION_ON            1 
    490493 
     494// The state of the TCO 
     495typedef struct { 
     496  unsigned int locked, ltc_valid; 
     497  unsigned int hours, minutes, seconds, frames; 
     498  unsigned int frame_rate; 
     499  unsigned int drop_frame; 
     500  unsigned int video_input; 
     501  unsigned int word_clock_state; 
     502  float sample_rate; 
     503} FF_TCO_state_t; 
     504 
     505// TCO state field defines 
     506#define FF_TCOSTATE_FRAMERATE_24fps           1 
     507#define FF_TCOSTATE_FRAMERATE_25fps           2 
     508#define FF_TCOSTATE_FRAMERATE_29_97fps        3 
     509#define FF_TCOSTATE_FRAMERATE_30fps           4 
     510#define FF_TCOSTATE_VIDEO_NONE                0 
     511#define FF_TCOSTATE_VIDEO_PAL                 1 
     512#define FF_TCOSTATE_VIDEO_NTSC                2 
     513#define FF_TCOSTATE_WORDCLOCK_NONE            0 
     514#define FF_TCOSTATE_WORDCLOCK_1x              1 
     515#define FF_TCOSTATE_WORDCLOCK_2x              2 
     516#define FF_TCOSTATE_WORDCLOCK_4x              3 
     517 
    491518#endif 
  • trunk/libffado/src/rme/fireface_hw.cpp

    r1585 r1586  
    258258} 
    259259 
    260 signed int Device::write_tco_settings(FF_TCO_settings_t tco_settings) 
     260signed int Device::read_tco_state(FF_TCO_state_t *tco_state) 
     261
     262    // Reads the current TCO state into the supplied state structure 
     263 
     264    quadlet_t tc[4]; 
     265    unsigned int PLL_phase; 
     266 
     267    if (read_tco(tc, 4) != 0) 
     268      return -1; 
     269 
     270    // The timecode is stored in BCD (binary coded decimal) in register 0. 
     271    tco_state->frames = (tc[0] & 0xf) + ((tc[0] & 0x30) >> 4)*10; 
     272    tco_state->seconds = ((tc[0] & 0xf00) >> 8) + ((tc[0] & 0x7000) >> 12)*10; 
     273    tco_state->minutes = ((tc[0] & 0xf0000) >> 16) + ((tc[0] & 0x700000) >> 20)*10; 
     274    tco_state->hours = ((tc[0] & 0xf000000) >> 24) + ((tc[0] & 0x30000000) >> 28)*10; 
     275 
     276    tco_state->locked = (tc[1] & FF_TCO1_TCO_lock) != 0; 
     277    tco_state->ltc_valid = (tc[1] & FF_TCO1_LTC_INPUT_VALID) != 0; 
     278 
     279    switch (tc[1] & FF_TCO1_LTC_FORMAT_MASK) { 
     280        case FF_TC01_LTC_FORMAT_24fps:  
     281          tco_state->frame_rate = FF_TCOSTATE_FRAMERATE_24fps; break; 
     282        case FF_TCO1_LTC_FORMAT_25fps:  
     283          tco_state->frame_rate = FF_TCOSTATE_FRAMERATE_25fps; break; 
     284        case FF_TC01_LTC_FORMAT_29_97fps:  
     285          tco_state->frame_rate = FF_TCOSTATE_FRAMERATE_29_97fps; break; 
     286        case FF_TCO1_LTC_FORMAT_30fps:  
     287          tco_state->frame_rate = FF_TCOSTATE_FRAMERATE_30fps; break; 
     288    } 
     289 
     290    tco_state->drop_frame = (tc[1] & FF_TCO1_SET_DROPFRAME) != 0; 
     291 
     292    switch (tc[1] & FF_TCO1_VIDEO_INPUT_MASK) { 
     293        case FF_TCO1_VIDEO_INPUT_NTSC: 
     294            tco_state->video_input = FF_TCOSTATE_VIDEO_NTSC; break; 
     295        case FF_TCO1_VIDEO_INPUT_PAL: 
     296            tco_state->video_input = FF_TCOSTATE_VIDEO_PAL; break; 
     297        default: 
     298            tco_state->video_input = FF_TCOSTATE_VIDEO_NONE; 
     299    } 
     300 
     301    if ((tc[1] & FF_TCO1_WORD_CLOCK_INPUT_VALID) == 0) { 
     302        tco_state->word_clock_state = FF_TCOSTATE_WORDCLOCK_NONE; 
     303    } else { 
     304        switch (tc[1] & FF_TCO1_WORD_CLOCK_INPUT_MASK) { 
     305            case FF_TCO1_WORD_CLOCK_INPUT_1x: 
     306                tco_state->word_clock_state = FF_TCOSTATE_WORDCLOCK_1x; break; 
     307            case FF_TCO1_WORD_CLOCK_INPUT_2x: 
     308                tco_state->word_clock_state = FF_TCOSTATE_WORDCLOCK_2x; break; 
     309            case FF_TCO1_WORD_CLOCK_INPUT_4x: 
     310                tco_state->word_clock_state = FF_TCOSTATE_WORDCLOCK_4x; break; 
     311        } 
     312    } 
     313 
     314    PLL_phase = (tc[2] & 0x7f) + ((tc[2] & 0x7f00) >> 1); 
     315    tco_state->sample_rate = (25000000.0 * 16.0)/PLL_phase; 
     316 
     317    return 0; 
     318
     319 
     320signed int Device::write_tco_settings(FF_TCO_settings_t *tco_settings) 
    261321{ 
    262322    // Writes the supplied application-level settings to the device's TCO 
     
    270330    } 
    271331 
    272     if (tco_settings.MTC) 
     332    if (tco_settings->MTC) 
    273333        tc[0] |= FF_TCO0_MTC; 
    274334 
    275     switch (tco_settings.input) { 
     335    switch (tco_settings->input) { 
    276336        case FF_TCOPARAM_INPUT_LTC: 
    277337            tc[2] |= FF_TCO2_INPUT_LTC; break; 
     
    282342    } 
    283343 
    284     switch (tco_settings.frame_rate) { 
     344    switch (tco_settings->frame_rate) { 
    285345        case FF_TCOPARAM_FRAMERATE_24fps: 
    286346            tc[1] |= FF_TC01_LTC_FORMAT_24fps; break; 
     
    297357    } 
    298358 
    299     switch (tco_settings.word_clock) { 
     359    switch (tco_settings->word_clock) { 
    300360        case FF_TCOPARAM_WORD_CLOCK_CONV_1_1: 
    301361            tc[2] |= FF_TCO2_WORD_CLOCK_CONV_1_1; break; 
     
    306366    } 
    307367 
    308     switch (tco_settings.sample_rate) { 
     368    switch (tco_settings->sample_rate) { 
    309369        case FF_TCOPARAM_SRATE_44_1: 
    310370            tc[2] |= FF_TCO2_SRATE_44_1; break; 
     
    315375    } 
    316376 
    317     switch (tco_settings.pull) { 
     377    switch (tco_settings->pull) { 
    318378        case FF_TCPPARAM_PULL_NONE: 
    319379            tc[2] |= FF_TCO2_PULL_0; break; 
     
    328388    } 
    329389 
    330     if (tco_settings.termination == FF_TCOPARAM_TERMINATION_ON) 
     390    if (tco_settings->termination == FF_TCOPARAM_TERMINATION_ON) 
    331391        tc[2] |= FF_TCO2_SET_TERMINATION; 
    332392 
  • trunk/libffado/src/rme/rme_avdevice.h

    r1584 r1586  
    120120    signed int write_tco(quadlet_t *tco_data, signed int size); 
    121121 
    122     signed int write_tco_settings(FF_TCO_settings_t tco_settings); 
     122    signed int read_tco_state(FF_TCO_state_t *tco_state); 
     123    signed int write_tco_settings(FF_TCO_settings_t *tco_settings); 
    123124     
    124125};