Changeset 1629

Show
Ignore:
Timestamp:
08/27/09 05:18:06 (14 years ago)
Author:
jwoithe
Message:

RME: refine shared device configuration locking. Rename some data objects for clarity. Move frequency settings into the shared configuration object since ultimately these need to be accessible to all FFADO/RME processes. Other minor cleanups.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/libffado/src/rme/fireface_hw.cpp

    r1628 r1629  
    3434Device::multiplier_of_freq(unsigned int freq)  
    3535{ 
    36   if (freq > MIN_QUAD_SPEED) 
    37     return 4; 
    38   if (freq > MIN_DOUBLE_SPEED) 
    39     return 2; 
    40   return 1; 
     36    if (freq > MIN_QUAD_SPEED) 
     37      return 4; 
     38    if (freq > MIN_DOUBLE_SPEED) 
     39      return 2; 
     40    return 1; 
     41
     42 
     43void 
     44Device::config_lock(void) { 
     45    rme_shm_lock(dev_config); 
     46
     47 
     48void 
     49Device::config_unlock(void) { 
     50    rme_shm_unlock(dev_config); 
    4151} 
    4252 
     
    4454Device::init_hardware(void) 
    4555{ 
     56    signed int ret = 0; 
     57 
    4658    // Initialises the device's settings structure to a known state and then 
    4759    // sets the hardware to reflect this state. 
    48     // 
     60 
     61    config_lock(); 
     62 
    4963    // In time this function may read a cached device setup and initialise 
    5064    // based on that.  It may also read the device configuration from the 
    5165    // device flash and adopt that.  For now (for initial testing purposes) 
    5266    // we'll go with a static state. 
    53     if (shared_data->settings_valid==0) { 
     67    if (dev_config->settings_valid==0) { 
    5468        memset(settings, 0, sizeof(*settings)); 
    5569        settings->spdif_input_mode = FF_SWPARAM_SPDIF_INPUT_COAX; 
     
    6983        } 
    7084 
    71         shared_data->settings_valid = 1; 
     85        dev_config->settings_valid = 1; 
    7286    } 
    7387 
    7488    // A default sampling rate.  An explicit DDS frequency is not enabled 
    7589    // by default. 
    76     m_software_freq = 44100; 
    77     m_dds_freq = 0; 
     90    dev_config->software_freq = 44100; 
     91    dev_config->dds_freq = 0; 
    7892 
    7993    if (set_hardware_params(settings) != 0) 
    80         return -1; 
     94        ret = -1; 
    8195 
    8296    // Also configure the TCO (Time Code Option) settings for those devices 
    8397    // which have a TCO. 
    84     if (shared_data->tco_settings_valid==0) { 
    85         if (tco_present) { 
     98    if (ret==0 && dev_config->tco_settings_valid==0) { 
     99        if (dev_config->tco_present) { 
    86100            memset(tco_settings, 0, sizeof(*tco_settings)); 
    87101            write_tco_settings(tco_settings); 
    88102        } 
    89         shared_data->tco_settings_valid = 1; 
    90     } 
    91     return 0; 
     103        dev_config->tco_settings_valid = 1; 
     104    } 
     105 
     106    config_unlock(); 
     107 
     108    return ret; 
    92109} 
    93110 
     
    131148        return -1; 
    132149 
    133     state->is_streaming = is_streaming; 
     150    state->is_streaming = dev_config->is_streaming; 
    134151 
    135152    state->clock_mode = (settings->clock_mode == FF_SWPARAM_CLOCK_MODE_MASTER)?FF_STATE_CLOCKMODE_MASTER:FF_STATE_CLOCKMODE_AUTOSYNC; 
     
    463480{ 
    464481    // Return 1 if the hardware is streaming, 0 if not. 
    465     return is_streaming; 
     482    return dev_config->is_streaming; 
    466483} 
    467484 
     
    536553    quadlet_t tc[4] = {0, 0, 0, 0}; 
    537554 
    538     if (!tco_present) { 
     555    if (!dev_config->tco_present) { 
    539556        return -1; 
    540557    } 
  • trunk/libffado/src/rme/rme_avdevice.cpp

    r1628 r1629  
    8282    : FFADODevice( d, configRom ) 
    8383    , m_rme_model( RME_MODEL_NONE ) 
    84     , is_streaming( 0 ) 
    85     , m_dds_freq( -1 ) 
    86     , m_software_freq( -1 ) 
    87     , tco_present( 0 ) 
    8884    , num_channels( 0 ) 
    8985    , samples_per_packet( 0 ) 
     
    10096    destroyMixer(); 
    10197 
    102     if (shared_data != NULL) { 
    103         switch (rme_shm_close(shared_data)) { 
     98    if (dev_config != NULL) { 
     99        switch (rme_shm_close(dev_config)) { 
    104100            case RSO_CLOSE: 
    105101                debugOutput( DEBUG_LEVEL_VERBOSE, "Configuration shared data object closed\n"); 
     
    279275 
    280276    // Set up the shared data object for configuration data 
    281     i = rme_shm_open(&shared_data); 
     277    i = rme_shm_open(&dev_config); 
    282278    if (i == RSO_OPEN_CREATED) { 
    283279        debugOutput( DEBUG_LEVEL_VERBOSE, "New configuration shared data object created\n"); 
     
    286282        debugOutput( DEBUG_LEVEL_VERBOSE, "Attached to existing configuration shared data object\n"); 
    287283    } 
    288     if (shared_data == NULL) { 
     284    if (dev_config == NULL) { 
    289285        debugOutput( DEBUG_LEVEL_WARNING, "Could not create/access shared configuration memory object, using process-local storage\n"); 
    290         memset(&local_data_obj, 0, sizeof(local_data_obj)); 
    291         shared_data = &local_data_obj; 
    292     } 
    293     settings = &shared_data->settings; 
    294     tco_settings = &shared_data->tco_settings; 
     286        memset(&local_dev_config_obj, 0, sizeof(local_dev_config_obj)); 
     287        dev_config = &local_dev_config_obj; 
     288    } 
     289    settings = &dev_config->settings; 
     290    tco_settings = &dev_config->tco_settings; 
    295291 
    296292    // If device is FF800, check to see if the TCO is fitted 
    297293    if (m_rme_model == RME_MODEL_FIREFACE800) { 
    298         tco_present = (read_tco(NULL, 0) == 0); 
     294        dev_config->tco_present = (read_tco(NULL, 0) == 0); 
    299295    } 
    300296    debugOutput(DEBUG_LEVEL_VERBOSE, "TCO present: %s\n", 
    301       tco_present?"yes":"no"); 
    302  
    303     // Find out the device's streaming status 
    304     is_streaming = hardware_is_streaming(); 
     297      dev_config->tco_present?"yes":"no"); 
    305298 
    306299    init_hardware(); 
     
    321314    // Retrieve the current sample rate.  For practical purposes this 
    322315    // is the software rate currently in use. 
    323     return m_software_freq; 
     316    return dev_config->software_freq; 
    324317} 
    325318 
     
    341334    // multiplier as the software sample rate 
    342335    if (hardware_is_streaming()) { 
    343         if (multiplier_of_freq(dds_freq) != multiplier_of_freq(m_software_freq)) 
     336        if (multiplier_of_freq(dds_freq) != multiplier_of_freq(dev_config->software_freq)) 
    344337            return false; 
    345338    } 
    346339 
    347     m_dds_freq = dds_freq; 
     340    dev_config->dds_freq = dds_freq; 
    348341    if (settings->clock_mode == FF_STATE_CLOCKMODE_MASTER) { 
    349342        if (set_hardware_dds_freq(dds_freq) != 0) 
     
    387380        fixed_freq = state.autosync_freq; 
    388381    } else 
    389     if (m_dds_freq > 0) { 
    390         fixed_freq = m_dds_freq; 
     382    if (dev_config->dds_freq > 0) { 
     383        fixed_freq = dev_config->dds_freq; 
    391384    } else 
    392385    if (hardware_is_streaming()) { 
    393         fixed_freq = m_software_freq; 
     386        fixed_freq = dev_config->software_freq; 
    394387    } 
    395388 
     
    425418    // used to programm the hardware DDS regardless of the rate requested 
    426419    // by the software.  Otherwise we use the requested sampling rate. 
    427     if (m_dds_freq > 0) 
    428         freq = m_dds_freq; 
     420    if (dev_config->dds_freq > 0) 
     421        freq = dev_config->dds_freq; 
    429422    if (set_hardware_dds_freq(freq) != 0) 
    430423        return false; 
    431424 
    432     m_software_freq = samplingFrequency; 
     425    dev_config->software_freq = samplingFrequency; 
    433426    return true; 
    434427} 
     
    453446    } else 
    454447    if (state.is_streaming) { 
    455         unsigned int fixed_mult = multiplier_of_freq(m_software_freq); 
     448        unsigned int fixed_mult = multiplier_of_freq(dev_config->software_freq); 
    456449        for (j=0; j<3; j++) { 
    457450            frequencies.push_back(freq[j]*fixed_mult); 
  • trunk/libffado/src/rme/rme_avdevice.h

    r1628 r1629  
    112112    /* General information functions */ 
    113113    signed int getRmeModel(void) { return m_rme_model; } 
    114     signed int getTcoPresent(void) { return tco_present; } 
     114    signed int getTcoPresent(void) { return dev_config->tco_present; } 
    115115 
    116116protected: 
    117117    enum ERmeModel m_rme_model; 
    118118 
    119     signed int is_streaming; 
    120     signed int m_dds_freq;       // Optionally explicitly set hardware freq 
    121     signed int m_software_freq;  // Sampling frequency in use by software 
    122  
    123     signed int tco_present; 
    124119    FF_software_settings_t *settings; 
    125120    FF_TCO_settings_t *tco_settings; 
    126121 
    127     rme_shm_t *shared_data, local_data_obj; 
     122    rme_shm_t *dev_config, local_dev_config_obj; 
    128123 
    129124    signed int num_channels; 
     
    154149    /* Low-level hardware functions */ 
    155150    unsigned int multiplier_of_freq(unsigned int freq); 
     151    void config_lock(void); 
     152    void config_unlock(void); 
    156153    signed int init_hardware(void); 
    157154    signed int get_hardware_status(unsigned int *stat0, unsigned int *stat1); 
  • trunk/libffado/src/rme/rme_shm.cpp

    r1627 r1629  
    5454#include "rme_shm.h" 
    5555 
    56 static signed int rme_shm_lock(void) { 
     56static signed int rme_shm_lock_for_setup(void) { 
    5757signed lockfd; 
    5858 
    5959    do { 
    60         // The check for existance and shm creation are atomic so it's sav
     60        // The check for existance and shm creation are atomic so it's saf
    6161        // to use this as the basis for a global lock. 
    6262        lockfd = shm_open(RME_SHM_LOCKNAME, O_RDWR | O_CREAT | O_EXCL, 0644); 
     
    6868} 
    6969 
    70 static void rme_shm_unlock(signed int lockfd) { 
     70static void rme_shm_unlock_for_setup(signed int lockfd) { 
    7171    close(lockfd); 
    7272    shm_unlink(RME_SHM_LOCKNAME); 
     73} 
     74 
     75void rme_shm_lock(rme_shm_t *shm_data) { 
     76    pthread_mutex_lock(&shm_data->lock); 
     77} 
     78 
     79void rme_shm_unlock(rme_shm_t *shm_data) { 
     80    pthread_mutex_unlock(&shm_data->lock); 
    7381} 
    7482 
     
    8492    *shm_data = NULL; 
    8593 
    86     lockfd = rme_shm_lock(); 
     94    lockfd = rme_shm_lock_for_setup(); 
    8795 
    8896    shmfd = shm_open(RME_SHM_NAME, O_RDWR, 0644); 
     
    110118    } 
    111119 
    112     pthread_mutex_lock(&data->lock); 
     120    rme_shm_lock(data); 
    113121    data->ref_count++; 
    114     pthread_mutex_unlock(&data->lock); 
     122    rme_shm_unlock(data); 
    115123 
    116     rme_shm_unlock(lockfd); 
     124    rme_shm_unlock_for_setup(lockfd); 
    117125 
    118126    *shm_data = data; 
     
    125133    signed int lockfd; 
    126134 
    127     lockfd = rme_shm_lock(); 
     135    lockfd = rme_shm_lock_for_setup(); 
    128136 
    129     pthread_mutex_lock(&shm_data->lock); 
     137    rme_shm_lock(shm_data); 
    130138    shm_data->ref_count--; 
    131139    unlink = (shm_data->ref_count == 0); 
    132     pthread_mutex_unlock(&shm_data->lock); 
     140    rme_shm_unlock(shm_data); 
    133141 
    134142    if (unlink) { 
     
    143151        shm_unlink(RME_SHM_NAME); 
    144152 
    145     rme_shm_unlock(lockfd); 
     153    rme_shm_unlock_for_setup(lockfd); 
    146154 
    147155    return unlink?RSO_CLOSE_DELETE:RSO_CLOSE; 
  • trunk/libffado/src/rme/rme_shm.h

    r1627 r1629  
    3535    signed int settings_valid, tco_settings_valid; 
    3636    FF_software_settings_t settings; 
     37    signed int tco_present; 
    3738    FF_TCO_settings_t tco_settings; 
     39 
     40    signed int dds_freq;      // Optionally explicitly set hardware freq 
     41    signed int software_freq; // Sampling frequency in use by software 
     42 
     43    signed int is_streaming; 
    3844 
    3945    pthread_mutex_t lock; 
     
    5359/* Functions */ 
    5460 
     61void rme_shm_lock(rme_shm_t *shm_data); 
     62void rme_shm_unlock(rme_shm_t *shm_data); 
    5563signed int rme_shm_open(rme_shm_t **shm_data); 
    5664signed int rme_shm_close(rme_shm_t *shm_data);