Changeset 1629
- Timestamp:
- 08/27/09 05:18:06 (14 years ago)
- Files:
-
- trunk/libffado/src/rme/fireface_hw.cpp (modified) (6 diffs)
- trunk/libffado/src/rme/rme_avdevice.cpp (modified) (9 diffs)
- trunk/libffado/src/rme/rme_avdevice.h (modified) (2 diffs)
- trunk/libffado/src/rme/rme_shm.cpp (modified) (6 diffs)
- trunk/libffado/src/rme/rme_shm.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/libffado/src/rme/fireface_hw.cpp
r1628 r1629 34 34 Device::multiplier_of_freq(unsigned int freq) 35 35 { 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 43 void 44 Device::config_lock(void) { 45 rme_shm_lock(dev_config); 46 } 47 48 void 49 Device::config_unlock(void) { 50 rme_shm_unlock(dev_config); 41 51 } 42 52 … … 44 54 Device::init_hardware(void) 45 55 { 56 signed int ret = 0; 57 46 58 // Initialises the device's settings structure to a known state and then 47 59 // sets the hardware to reflect this state. 48 // 60 61 config_lock(); 62 49 63 // In time this function may read a cached device setup and initialise 50 64 // based on that. It may also read the device configuration from the 51 65 // device flash and adopt that. For now (for initial testing purposes) 52 66 // we'll go with a static state. 53 if ( shared_data->settings_valid==0) {67 if (dev_config->settings_valid==0) { 54 68 memset(settings, 0, sizeof(*settings)); 55 69 settings->spdif_input_mode = FF_SWPARAM_SPDIF_INPUT_COAX; … … 69 83 } 70 84 71 shared_data->settings_valid = 1;85 dev_config->settings_valid = 1; 72 86 } 73 87 74 88 // A default sampling rate. An explicit DDS frequency is not enabled 75 89 // by default. 76 m_software_freq = 44100;77 m_dds_freq = 0;90 dev_config->software_freq = 44100; 91 dev_config->dds_freq = 0; 78 92 79 93 if (set_hardware_params(settings) != 0) 80 ret urn-1;94 ret = -1; 81 95 82 96 // Also configure the TCO (Time Code Option) settings for those devices 83 97 // 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) { 86 100 memset(tco_settings, 0, sizeof(*tco_settings)); 87 101 write_tco_settings(tco_settings); 88 102 } 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; 92 109 } 93 110 … … 131 148 return -1; 132 149 133 state->is_streaming = is_streaming;150 state->is_streaming = dev_config->is_streaming; 134 151 135 152 state->clock_mode = (settings->clock_mode == FF_SWPARAM_CLOCK_MODE_MASTER)?FF_STATE_CLOCKMODE_MASTER:FF_STATE_CLOCKMODE_AUTOSYNC; … … 463 480 { 464 481 // Return 1 if the hardware is streaming, 0 if not. 465 return is_streaming;482 return dev_config->is_streaming; 466 483 } 467 484 … … 536 553 quadlet_t tc[4] = {0, 0, 0, 0}; 537 554 538 if (! tco_present) {555 if (!dev_config->tco_present) { 539 556 return -1; 540 557 } trunk/libffado/src/rme/rme_avdevice.cpp
r1628 r1629 82 82 : FFADODevice( d, configRom ) 83 83 , m_rme_model( RME_MODEL_NONE ) 84 , is_streaming( 0 )85 , m_dds_freq( -1 )86 , m_software_freq( -1 )87 , tco_present( 0 )88 84 , num_channels( 0 ) 89 85 , samples_per_packet( 0 ) … … 100 96 destroyMixer(); 101 97 102 if ( shared_data!= NULL) {103 switch (rme_shm_close( shared_data)) {98 if (dev_config != NULL) { 99 switch (rme_shm_close(dev_config)) { 104 100 case RSO_CLOSE: 105 101 debugOutput( DEBUG_LEVEL_VERBOSE, "Configuration shared data object closed\n"); … … 279 275 280 276 // Set up the shared data object for configuration data 281 i = rme_shm_open(& shared_data);277 i = rme_shm_open(&dev_config); 282 278 if (i == RSO_OPEN_CREATED) { 283 279 debugOutput( DEBUG_LEVEL_VERBOSE, "New configuration shared data object created\n"); … … 286 282 debugOutput( DEBUG_LEVEL_VERBOSE, "Attached to existing configuration shared data object\n"); 287 283 } 288 if ( shared_data== NULL) {284 if (dev_config == NULL) { 289 285 debugOutput( DEBUG_LEVEL_WARNING, "Could not create/access shared configuration memory object, using process-local storage\n"); 290 memset(&local_d ata_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; 295 291 296 292 // If device is FF800, check to see if the TCO is fitted 297 293 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); 299 295 } 300 296 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"); 305 298 306 299 init_hardware(); … … 321 314 // Retrieve the current sample rate. For practical purposes this 322 315 // is the software rate currently in use. 323 return m_software_freq;316 return dev_config->software_freq; 324 317 } 325 318 … … 341 334 // multiplier as the software sample rate 342 335 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)) 344 337 return false; 345 338 } 346 339 347 m_dds_freq = dds_freq;340 dev_config->dds_freq = dds_freq; 348 341 if (settings->clock_mode == FF_STATE_CLOCKMODE_MASTER) { 349 342 if (set_hardware_dds_freq(dds_freq) != 0) … … 387 380 fixed_freq = state.autosync_freq; 388 381 } 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; 391 384 } else 392 385 if (hardware_is_streaming()) { 393 fixed_freq = m_software_freq;386 fixed_freq = dev_config->software_freq; 394 387 } 395 388 … … 425 418 // used to programm the hardware DDS regardless of the rate requested 426 419 // 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; 429 422 if (set_hardware_dds_freq(freq) != 0) 430 423 return false; 431 424 432 m_software_freq = samplingFrequency;425 dev_config->software_freq = samplingFrequency; 433 426 return true; 434 427 } … … 453 446 } else 454 447 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); 456 449 for (j=0; j<3; j++) { 457 450 frequencies.push_back(freq[j]*fixed_mult); trunk/libffado/src/rme/rme_avdevice.h
r1628 r1629 112 112 /* General information functions */ 113 113 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; } 115 115 116 116 protected: 117 117 enum ERmeModel m_rme_model; 118 118 119 signed int is_streaming;120 signed int m_dds_freq; // Optionally explicitly set hardware freq121 signed int m_software_freq; // Sampling frequency in use by software122 123 signed int tco_present;124 119 FF_software_settings_t *settings; 125 120 FF_TCO_settings_t *tco_settings; 126 121 127 rme_shm_t * shared_data, local_data_obj;122 rme_shm_t *dev_config, local_dev_config_obj; 128 123 129 124 signed int num_channels; … … 154 149 /* Low-level hardware functions */ 155 150 unsigned int multiplier_of_freq(unsigned int freq); 151 void config_lock(void); 152 void config_unlock(void); 156 153 signed int init_hardware(void); 157 154 signed int get_hardware_status(unsigned int *stat0, unsigned int *stat1); trunk/libffado/src/rme/rme_shm.cpp
r1627 r1629 54 54 #include "rme_shm.h" 55 55 56 static signed int rme_shm_lock (void) {56 static signed int rme_shm_lock_for_setup(void) { 57 57 signed lockfd; 58 58 59 59 do { 60 // The check for existance and shm creation are atomic so it's sa ve60 // The check for existance and shm creation are atomic so it's safe 61 61 // to use this as the basis for a global lock. 62 62 lockfd = shm_open(RME_SHM_LOCKNAME, O_RDWR | O_CREAT | O_EXCL, 0644); … … 68 68 } 69 69 70 static void rme_shm_unlock (signed int lockfd) {70 static void rme_shm_unlock_for_setup(signed int lockfd) { 71 71 close(lockfd); 72 72 shm_unlink(RME_SHM_LOCKNAME); 73 } 74 75 void rme_shm_lock(rme_shm_t *shm_data) { 76 pthread_mutex_lock(&shm_data->lock); 77 } 78 79 void rme_shm_unlock(rme_shm_t *shm_data) { 80 pthread_mutex_unlock(&shm_data->lock); 73 81 } 74 82 … … 84 92 *shm_data = NULL; 85 93 86 lockfd = rme_shm_lock ();94 lockfd = rme_shm_lock_for_setup(); 87 95 88 96 shmfd = shm_open(RME_SHM_NAME, O_RDWR, 0644); … … 110 118 } 111 119 112 pthread_mutex_lock(&data->lock);120 rme_shm_lock(data); 113 121 data->ref_count++; 114 pthread_mutex_unlock(&data->lock);122 rme_shm_unlock(data); 115 123 116 rme_shm_unlock (lockfd);124 rme_shm_unlock_for_setup(lockfd); 117 125 118 126 *shm_data = data; … … 125 133 signed int lockfd; 126 134 127 lockfd = rme_shm_lock ();135 lockfd = rme_shm_lock_for_setup(); 128 136 129 pthread_mutex_lock(&shm_data->lock);137 rme_shm_lock(shm_data); 130 138 shm_data->ref_count--; 131 139 unlink = (shm_data->ref_count == 0); 132 pthread_mutex_unlock(&shm_data->lock);140 rme_shm_unlock(shm_data); 133 141 134 142 if (unlink) { … … 143 151 shm_unlink(RME_SHM_NAME); 144 152 145 rme_shm_unlock (lockfd);153 rme_shm_unlock_for_setup(lockfd); 146 154 147 155 return unlink?RSO_CLOSE_DELETE:RSO_CLOSE; trunk/libffado/src/rme/rme_shm.h
r1627 r1629 35 35 signed int settings_valid, tco_settings_valid; 36 36 FF_software_settings_t settings; 37 signed int tco_present; 37 38 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; 38 44 39 45 pthread_mutex_t lock; … … 53 59 /* Functions */ 54 60 61 void rme_shm_lock(rme_shm_t *shm_data); 62 void rme_shm_unlock(rme_shm_t *shm_data); 55 63 signed int rme_shm_open(rme_shm_t **shm_data); 56 64 signed int rme_shm_close(rme_shm_t *shm_data);