Changeset 1627

Show
Ignore:
Timestamp:
08/21/09 23:55:43 (15 years ago)
Author:
jwoithe
Message:

RME: implement initial use of shared data object for configuration data. Some rough edges remain and are being addressed.

Files:

Legend:

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

    r1624 r1627  
    5151    // device flash and adopt that.  For now (for initial testing purposes) 
    5252    // we'll go with a static state. 
    53     memset(settings, 0, sizeof(*settings)); 
    54     settings->spdif_input_mode = FF_SWPARAM_SPDIF_INPUT_COAX; 
    55     settings->spdif_output_mode = FF_SWPARAM_SPDIF_OUTPUT_COAX; 
    56     settings->clock_mode = FF_SWPARAM_CLOCK_MODE_MASTER; 
    57     settings->sync_ref = FF_SWPARAM_SYNCREF_WORDCLOCK; 
    58     settings->input_level = FF_SWPARAM_ILEVEL_LOGAIN; 
    59     settings->output_level = FF_SWPARAM_OLEVEL_HIGAIN; 
    60     settings->phones_level = FF_SWPARAM_PHONESLEVEL_HIGAIN; 
    61  
    62     // Set amplifier gains 
    63     if (m_rme_model == RME_MODEL_FIREFACE400) { 
    64         signed int i; 
    65         for (i=0; i<FF400_AMPGAIN_NUM; i++) { 
    66             set_hardware_ampgain(i, settings->amp_gains[i]); 
     53    if (shared_data==NULL || shared_data->settings_valid==0) { 
     54        memset(settings, 0, sizeof(*settings)); 
     55        settings->spdif_input_mode = FF_SWPARAM_SPDIF_INPUT_COAX; 
     56        settings->spdif_output_mode = FF_SWPARAM_SPDIF_OUTPUT_COAX; 
     57        settings->clock_mode = FF_SWPARAM_CLOCK_MODE_MASTER; 
     58        settings->sync_ref = FF_SWPARAM_SYNCREF_WORDCLOCK; 
     59        settings->input_level = FF_SWPARAM_ILEVEL_LOGAIN; 
     60        settings->output_level = FF_SWPARAM_OLEVEL_HIGAIN; 
     61        settings->phones_level = FF_SWPARAM_PHONESLEVEL_HIGAIN; 
     62 
     63        // Set amplifier gains 
     64        if (m_rme_model == RME_MODEL_FIREFACE400) { 
     65            signed int i; 
     66            for (i=0; i<FF400_AMPGAIN_NUM; i++) { 
     67                set_hardware_ampgain(i, settings->amp_gains[i]); 
     68            } 
    6769        } 
     70 
     71        if (shared_data != NULL) 
     72            shared_data->settings_valid = 1; 
    6873    } 
    6974 
     
    7883    // Also configure the TCO (Time Code Option) settings for those devices 
    7984    // which have a TCO. 
    80     if (tco_present) { 
    81         memset(tco_settings, 0, sizeof(*tco_settings)); 
    82         return write_tco_settings(tco_settings); 
    83     } 
    84  
     85    if (shared_data==NULL || shared_data->tco_settings_valid==0) { 
     86        if (tco_present) { 
     87            memset(tco_settings, 0, sizeof(*tco_settings)); 
     88            write_tco_settings(tco_settings); 
     89        } 
     90        if (shared_data != NULL) 
     91            shared_data->tco_settings_valid = 1; 
     92    } 
    8593    return 0; 
    8694} 
  • trunk/libffado/src/rme/rme_avdevice.cpp

    r1624 r1627  
    9494    debugOutput( DEBUG_LEVEL_VERBOSE, "Created Rme::Device (NodeID %d)\n", 
    9595                 getConfigRom().getNodeId() ); 
    96  
    97     settings = &settings_localobj; 
    98     tco_settings = &tco_settings_localobj; 
    99  
    100     memset(&settings, 0, sizeof(settings)); 
    101     memset(&tco_settings, 0, sizeof(tco_settings)); 
    10296} 
    10397 
     
    10599{ 
    106100    destroyMixer(); 
     101 
     102    if (shared_data != NULL) { 
     103        switch (rme_shm_close(shared_data)) { 
     104            case RSO_CLOSE: 
     105                debugOutput( DEBUG_LEVEL_VERBOSE, "Configuration shared data object closed\n"); 
     106                break; 
     107            case RSO_CLOSE_DELETE: 
     108                debugOutput( DEBUG_LEVEL_VERBOSE, "Configuration shared data object closed and deleted (no other users)\n"); 
     109                break; 
     110        } 
     111    } 
    107112} 
    108113 
     
    246251Device::discover() 
    247252{ 
     253    signed int i; 
    248254    unsigned int vendorId = getConfigRom().getNodeVendorId(); 
    249255    // See note in Device::probe() about why we use the unit version here. 
     
    270276        debugError("Unsupported model\n"); 
    271277        return false; 
     278    } 
     279 
     280    // Set up the shared data object for configuration data 
     281    i = rme_shm_open(&shared_data); 
     282    if (i == RSO_OPEN_CREATED) { 
     283        debugOutput( DEBUG_LEVEL_VERBOSE, "New configuration shared data object created\n"); 
     284    } else 
     285    if (i == RSO_OPEN_ATTACHED) { 
     286        debugOutput( DEBUG_LEVEL_VERBOSE, "Attached to existing configuration shared data object\n"); 
     287    } 
     288    if (shared_data == NULL) { 
     289        debugOutput( DEBUG_LEVEL_WARNING, "Could not create/access shared configuration memory object, using process-local storage\n"); 
     290        settings = &settings_localobj; 
     291        tco_settings = &tco_settings_localobj; 
     292        memset(settings, 0, sizeof(*settings)); 
     293        memset(tco_settings, 0, sizeof(*tco_settings)); 
     294    } else { 
     295        settings = &shared_data->settings; 
     296        tco_settings = &shared_data->tco_settings; 
    272297    } 
    273298 
  • trunk/libffado/src/rme/rme_avdevice.h

    r1624 r1627  
    3535#include "fireface_def.h" 
    3636// #include "libstreaming/rme/RmeStreamProcessor.h" 
     37 
     38#include "rme_shm.h" 
    3739 
    3840class ConfigRom; 
     
    123125    FF_TCO_settings_t *tco_settings; 
    124126 
     127    rme_shm_t *shared_data; 
    125128    FF_software_settings_t settings_localobj; 
    126129    FF_TCO_settings_t tco_settings_localobj; 
  • trunk/libffado/src/rme/rme_shm.cpp

    r1626 r1627  
    7373} 
    7474 
    75 rme_shm_t *rme_shm_open(void) { 
     75signed int rme_shm_open(rme_shm_t **shm_data) { 
    7676 
    7777    signed int shmfd, lockfd; 
    7878    rme_shm_t *data; 
    7979    signed int created = 0; 
     80 
     81    if (shm_data == NULL) { 
     82        return RSO_ERROR; 
     83    } 
     84    *shm_data = NULL; 
    8085 
    8186    lockfd = rme_shm_lock(); 
     
    8691            shmfd = shm_open(RME_SHM_NAME, O_RDWR | O_CREAT | O_EXCL, 0644); 
    8792            if (shmfd < 0) 
    88                 return NULL
     93                return RSO_ERR_SHM
    8994            else { 
    9095                ftruncate(shmfd, RME_SHM_SIZE); 
     
    9297            } 
    9398        } else 
    94             return NULL
     99            return RSO_ERR_SHM
    95100    } 
    96101 
     
    99104 
    100105    if (data == MAP_FAILED) 
    101         return NULL
     106        return RSO_ERR_MMAP
    102107 
    103108    if (created) { 
     
    107112    pthread_mutex_lock(&data->lock); 
    108113    data->ref_count++; 
    109     if (created) 
    110         data->valid++; 
    111114    pthread_mutex_unlock(&data->lock); 
    112115 
    113116    rme_shm_unlock(lockfd); 
    114117 
    115     return data; 
     118    *shm_data = data; 
     119    return created?RSO_OPEN_CREATED:RSO_OPEN_ATTACHED; 
    116120} 
    117121 
    118 void rme_shm_close(rme_shm_t *shm_data) { 
     122signed int rme_shm_close(rme_shm_t *shm_data) { 
    119123 
    120124    signed int unlink = 0; 
     
    125129    pthread_mutex_lock(&shm_data->lock); 
    126130    shm_data->ref_count--; 
    127     shm_data->valid = 0; 
    128131    unlink = (shm_data->ref_count == 0); 
    129132    pthread_mutex_unlock(&shm_data->lock); 
     
    141144 
    142145    rme_shm_unlock(lockfd); 
     146 
     147    return unlink?RSO_CLOSE_DELETE:RSO_CLOSE; 
    143148} 
  • trunk/libffado/src/rme/rme_shm.h

    r1624 r1627  
    3333typedef struct rme_shm_t { 
    3434    signed int ref_count; 
    35     signed int valid; 
     35    signed int settings_valid, tco_settings_valid; 
    3636    FF_software_settings_t settings; 
    3737    FF_TCO_settings_t tco_settings; 
     
    4040} rme_shm_t; 
    4141 
     42/* Return values from rme_shm_open().  RSO = Rme Shared Object. */ 
     43#define RSO_ERR_MMAP      -3 
     44#define RSO_ERR_SHM       -2 
     45#define RSO_ERROR         -1 
     46#define RSO_OPEN_CREATED   0 
     47#define RSO_OPEN_ATTACHED  1 
     48 
     49/* Return values from rme_shm_close() */ 
     50#define RSO_CLOSE          0 
     51#define RSO_CLOSE_DELETE   1 
     52 
    4253/* Functions */ 
    4354 
    44 rme_shm_t *rme_shm_open(void); 
    45 void rme_shm_close(rme_shm_t *shm_data); 
     55signed int rme_shm_open(rme_shm_t **shm_data); 
     56signed int rme_shm_close(rme_shm_t *shm_data); 
    4657 
    4758#endif