static gint cb_panel_release(GtkWidget* widget, GdkEventButton* ev, gpointer data) { unsigned int cpu; for ( cpu=0; cpu<ncpu; ++cpu ) { if (slider_in_motion[cpu]) { if (slider_userspace_enable) { if (controls_coupled) { unsigned int icpu; for ( icpu=0; icpu<ncpu; ++icpu ) { governor_userspace(icpu); } } else { governor_userspace(cpu); } } if (controls_coupled) { unsigned int icpu; for ( icpu=0; icpu<ncpu; ++icpu ) { /* no bug: slider_value is from cpu and not from icpu */ set_frequency(icpu, (unsigned long)(slider_value[cpu]*khz_max)); } } else { set_frequency(cpu, (unsigned long)(slider_value[cpu]*khz_max)); } } slider_in_motion[cpu] = NULL; } return TRUE; }
static int run_test(int calibration, double freq_base, double freq_step) { struct sample samples[SAMPLES]; double intercept, slope, stddev1, max1, stddev2, max2; double freq_error1, freq_error2; int i; set_frequency(freq_base); for (i = 0; i < 10; i++) usleep(1e6 * MEAN_SAMPLE_INTERVAL / 10); reset_ntp_error(); set_frequency(freq_base + freq_step); for (i = 0; i < 10; i++) usleep(rand() % 2000000 * STEP_INTERVAL / 10); set_frequency(freq_base); for (i = 0; i < SAMPLES; i++) { usleep(rand() % 2000000 * MEAN_SAMPLE_INTERVAL); get_sample(&samples[i]); } if (calibration) { regress(samples, SAMPLES, &intercept, &slope, &stddev1, &max1); mono_freq_offset = slope; printf("CLOCK_MONOTONIC_RAW frequency offset: %11.3f ppm\n", 1e6 * mono_freq_offset); return 0; } regress(samples, SAMPLES / 2, &intercept, &slope, &stddev1, &max1); freq_error1 = slope * (1.0 - mono_freq_offset) - mono_freq_offset - freq_base; regress(samples + SAMPLES / 2, SAMPLES / 2, &intercept, &slope, &stddev2, &max2); freq_error2 = slope * (1.0 - mono_freq_offset) - mono_freq_offset - freq_base; printf("%6.0f %+10.3f %6.0f %7.0f %+10.3f %6.0f %7.0f\t", 1e6 * freq_step, 1e6 * freq_error1, 1e9 * stddev1, 1e9 * max1, 1e6 * freq_error2, 1e9 * stddev2, 1e9 * max2); if (fabs(freq_error2) > MAX_FREQ_ERROR || stddev2 > MAX_STDDEV) { printf("[FAIL]\n"); return 1; } printf("[OK]\n"); return 0; }
int lv24020lp_set(int setting, int value) { int val = 1; mutex_lock(&tuner_mtx); switch(setting) { case RADIO_SLEEP: set_sleep(value); break; case RADIO_FREQUENCY: set_frequency(value); break; case RADIO_SCAN_FREQUENCY: /* TODO: really implement this */ set_frequency(value); val = lp24020lp_tuned(); break; case RADIO_MUTE: if (value) lv24020lp_write_clear(RADIO_CTRL3, AMUTE_L); else lv24020lp_write_set(RADIO_CTRL3, AMUTE_L); break; case RADIO_REGION: { const struct fm_region_data *rd = &fm_region_data[value]; if (rd->deemphasis == 75) lv24020lp_write_set(AUDIO_CTRL2, DEEMP); else lv24020lp_write_clear(AUDIO_CTRL2, DEEMP); break; } case RADIO_FORCE_MONO: if (value) lv24020lp_write_set(STEREO_CTRL, ST_M); else lv24020lp_write_clear(STEREO_CTRL, ST_M); break; default: value = -1; } mutex_unlock(&tuner_mtx); return val; }
int main(void) { #ifdef MANUAL int can_change_state = 1; #endif unsigned long freq = MAX_FREQ / 256; init_io(); init_timer(freq); while (1) { #ifdef MANUAL if (can_change_state && (BUTTON_PRESSED)) { _delay_ms(20); if (BUTTON_PRESSED) // debouncing check { freq += (MAX_FREQ / 256); if (freq > HUMAN_AUDIBLE_MAX_FREQ) { freq = MAX_FREQ / 256; } set_frequency(freq); can_change_state = 0; } } else { _delay_ms(20); if (BUTTON_RELEASED) // debouncing check { can_change_state = 1; } } #else _delay_ms(100); freq += (MAX_FREQ / 256); if (freq > HUMAN_AUDIBLE_MAX_FREQ) { freq = MAX_FREQ / 256; } set_frequency(freq); #endif } return 0; }
/** Interrupt handler for SS03 * Mapped to PE2 **/ void ADC0SS3_Handler(void) { uint16_t lux1; lux1 = ADC0->SSFIFO3; //read lux value of SS03 if (playing_hbd) { if(lux1 < MIN_LUX) pitch_adjust = 1; else if (190 <= lux1 && lux1 < 300) pitch_adjust = 2; else pitch_adjust = 3; } else { if(lux1 < MIN_LUX) frequency = (MIN_LUX*MIN_LUX)/100; else if (lux1 > MAX_LUX) frequency = (MAX_LUX*MAX_LUX)/100; else frequency = (lux1*lux1)/100; } set_frequency(frequency); set_volume(volume); ADC0->ISC |= (1UL << 3); NVIC->ICPR[0] = (1UL << 17); //Clear pending bit in NVIC for IRQ#17 ADC0 }
/** Handler for TIMER1B interrupt * Used for playing hbd song **/ void TIMER1B_Handler(void) { uint32_t note; static uint32_t current_note = 0; // If we stopped wanting to play hbd, then disable TIMER1B and reset current note to 0 if (!playing_hbd) { TIMER1->CTL &= ~(1UL << 8); //Disable TIMER1B if not playing hbd TIMER1->ICR = (1UL << 8); // Clear interrupt at GPTM to de-assert IRQ#22 signal NVIC->ICPR[0] = (1UL << 22); //Clear pending bit in NVIC for IRQ#22 TIMER1B current_note = 0; return; } // If happy birthday has not finished playing, advance to next note if (current_note < numberOfElements) { note = hbd_notes[current_note++]-1; frequency = notes[note]*pitch_adjust; } else { // turn off for one, then restart the song frequency = 0; current_note = 0; } set_frequency(frequency); set_volume(volume); TIMER1->ICR = (1UL << 8); // Clear interrupt at GPTM to de-assert IRQ#22 signal NVIC->ICPR[0] = (1UL << 22); //Clear pending bit in NVIC for IRQ#22 TIMER1B }
END_TEST START_TEST(test_three) { pbs_attribute f; pbs_attribute t; memset(&f,0,sizeof(f)); decode_frequency(&f,NULL,NULL,"1000",0); memset(&t,0,sizeof(t)); decode_frequency(&t,NULL,NULL,"1000MHz",0); fail_unless(comp_frequency(&t,&f)==0); memset(&f,0,sizeof(f)); decode_frequency(&f,NULL,NULL,"1100",0); memset(&t,0,sizeof(t)); decode_frequency(&t,NULL,NULL,"100MHz",0); fail_unless(comp_frequency(&t,&f)==-1); fail_unless(comp_frequency(&f,&t)==1); set_frequency(&f,&t,SET); fail_unless(comp_frequency(&t,&f)==0); }
void beep(const ComType com, const Beep *data) { // Disable morse code beeping BC->morse_pos = MAX_MORSE_LENGTH; BC->morse_duration = 0; BC->morse_buzz = false; // Only set frequency if there will be a beep if(data->duration != BEEP_DURATION_OFF) { set_frequency(frequency_to_frequency_value(data->frequency)); } // Disable beep if it's currently on, but should be off if(BC->beep_duration != BEEP_DURATION_OFF && data->duration == BEEP_DURATION_OFF) { PIN_ENABLE.pio->PIO_CODR = PIN_ENABLE.mask; } BC->beep_duration = data->duration; // Enable beep if it should be on if(BC->beep_duration != BEEP_DURATION_OFF) { PIN_ENABLE.pio->PIO_SODR = PIN_ENABLE.mask; } BA->com_return_setter(com, data); }
int initialize_espeak(struct synth_t *s) { int rate; /* initialize espeak */ rate = espeak_Initialize(AUDIO_OUTPUT_PLAYBACK, 50, NULL, 0); if (rate < 0) { fprintf(stderr, "Unable to initialize espeak.\n"); return -1; } /* We need a callback in acsint mode, but not in speakup mode. */ if (espeakup_mode == ESPEAKUP_MODE_ACSINT) espeak_SetSynthCallback(acsint_callback); /* Setup initial voice parameters */ if (defaultVoice) { set_voice(s, defaultVoice); free(defaultVoice); defaultVoice = NULL; } set_frequency(s, defaultFrequency, ADJ_SET); set_pitch(s, defaultPitch, ADJ_SET); set_rate(s, defaultRate, ADJ_SET); set_volume(s, defaultVolume, ADJ_SET); espeak_SetParameter(espeakCAPITALS, 0, 0); return 0; }
int main(int argc, char **argv) { double freq_base, freq_step; int i, j, fails = 0; init_test(); printf("Checking response to frequency step:\n"); printf(" Step 1st interval 2nd interval\n"); printf(" Freq Dev Max Freq Dev Max\n"); for (i = 2; i >= 0; i--) { for (j = 0; j < 5; j++) { freq_base = (rand() % (1 << 24) - (1 << 23)) / 65536e6; freq_step = 10e-6 * (1 << (6 * i)); fails += run_test(0, freq_base, freq_step); } } set_frequency(0.0); if (fails) ksft_exit_fail(); ksft_exit_pass(); }
/* frequency in MHz */ void setup(float frequency) { control.id = V4L2_CID_AUDIO_MUTE; control.value = 0; if (ioctl(fd, VIDIOC_S_CTRL, &control) < 0) { perror("ioctl: set: mute off"); fprintf(stderr, "We can't continue without turns mute to off. Aborting.\n"); exit(1); } if (ioctl(fd, VIDIOC_G_TUNER, &tuner) < 0) { perror("ioctl: set: get tuner"); fprintf(stderr, "We can't continue without a tuner. Aborting.\n"); exit(1); } set_frequency(frequency); control.id = V4L2_CID_AUDIO_VOLUME; control.value = 15; if (ioctl(fd, VIDIOC_S_CTRL, &control) < 0) { perror("ioctl: set volume"); fprintf(stderr, "Using the default volume level.\n"); } }
static int pm_fm_resume(struct poseidon *p) { logpm(p); poseidon_check_mode_radio(p); set_frequency(p, p->radio_data.fm_freq); pm_alsa_resume(p); return 0; }
void AIOP_PWM_Out::set_frequency_for_all(uint16_t hz) { QASSERT(m_is_initialized); for (uint8_t i = 0; i < MAX_CHANNEL_COUNT; i++) { set_frequency(i, hz); } }
void MPU9250_SPI::set_bus_frequency(unsigned ®_speed) { /* Set the desired speed */ set_frequency(MPU9250_IS_HIGH_SPEED(reg_speed) ? MPU9250_HIGH_SPI_BUS_SPEED : MPU9250_LOW_SPI_BUS_SPEED); /* Isoolate the register on return */ reg_speed = MPU9250_REG(reg_speed); }
void calibrate(const ComType com, const Calibrate *data) { __disable_irq(); PIN_ENABLE.pio->PIO_SODR = PIN_ENABLE.mask; uint32_t tick_sum = 0; uint16_t tick_last = 0; for(uint16_t freq = 0; freq <= FREQUENCY_VALUE_SUM_MAX; freq+=8) { set_frequency(freq); SLEEP_MS(1); while(!(PIN_FEEDBACK.pio->PIO_PDSR & PIN_FEEDBACK.mask)) { __NOP(); } while(PIN_FEEDBACK.pio->PIO_PDSR & PIN_FEEDBACK.mask) { __NOP(); } tick_last = SysTick->VAL; SLEEP_US(1); while(!(PIN_FEEDBACK.pio->PIO_PDSR & PIN_FEEDBACK.mask)) { uint16_t tick_next = SysTick->VAL; if(tick_last < tick_next) { tick_sum += FEEDBACK_TICK_MAX - tick_next + tick_last; } else { tick_sum += tick_last - tick_next; } tick_last = tick_next; } SLEEP_US(1); do { uint16_t tick_next = SysTick->VAL; if(tick_last < tick_next) { tick_sum += FEEDBACK_TICK_MAX - tick_next + tick_last; } else { tick_sum += tick_last - tick_next; } tick_last = tick_next; } while(PIN_FEEDBACK.pio->PIO_PDSR & PIN_FEEDBACK.mask); uint16_t real_freq = (BOARD_MCK+tick_sum/2)/tick_sum; BC->frequency_match[freq/8] = real_freq; tick_sum = 0; } PIN_ENABLE.pio->PIO_CODR = PIN_ENABLE.mask; save_calibration(); __enable_irq(); CalibrateReturn cr; cr.header = data->header; cr.header.length = sizeof(CalibrateReturn); cr.calibration = true; BA->send_blocking_with_timeout(&cr, sizeof(CalibrateReturn), com); }
static void queue_process_entry(struct synth_t *s) { espeak_ERROR error; static struct espeak_entry_t *current = NULL; if (current != queue_peek(synth_queue)) { if (current) free_espeak_entry(current); current = (struct espeak_entry_t *) queue_remove(synth_queue); } pthread_mutex_unlock(&queue_guard); if (current->cmd != CMD_PAUSE && paused_espeak) { reinitialize_espeak(s); } switch (current->cmd) { case CMD_SET_FREQUENCY: error = set_frequency(s, current->value, current->adjust); break; case CMD_SET_PITCH: error = set_pitch(s, current->value, current->adjust); break; case CMD_SET_PUNCTUATION: error = set_punctuation(s, current->value, current->adjust); break; case CMD_SET_RATE: error = set_rate(s, current->value, current->adjust); break; case CMD_SET_VOICE: error = EE_OK; break; case CMD_SET_VOLUME: error = set_volume(s, current->value, current->adjust); break; case CMD_SPEAK_TEXT: s->buf = current->buf; s->len = current->len; error = speak_text(s); break; case CMD_PAUSE: if (!paused_espeak) { espeak_Cancel(); espeak_Terminate(); paused_espeak = 1; } break; default: break; } if (error == EE_OK) { free_espeak_entry(current); current = NULL; } }
void set_speed(struct wave * const wave, midi_value_t speed) { // Scale range from [0..127] to [15..300] bpm fixed_t freq = fixed_from_int(speed); freq /= 127; freq *= 285; freq += fixed_from_int(15); freq /= 60; set_frequency(wave, freq); }
/***************************************************************** * \brief public wrapper for set_frequency * \parameter frequency frequency in MHz * \return 1 if success,0 - otherwise */ int radio_set_freq(struct stream *stream, float frequency) { radio_priv_t* priv=(radio_priv_t*)stream->priv; if (set_frequency(priv,frequency)!=STREAM_OK) { return 0; } if (get_frequency(priv,&frequency)!=STREAM_OK) { return 0; } mp_tmsg(MSGT_RADIO, MSGL_INFO, "[radio] Current frequency: %.2f\n",frequency); return 1; }
uint16_t MPU9250::read_reg16(unsigned reg) { uint8_t cmd[3] = { (uint8_t)(reg | DIR_READ), 0, 0 }; // general register transfer at low clock speed set_frequency(MPU9250_LOW_BUS_SPEED); transfer(cmd, cmd, sizeof(cmd)); return (uint16_t)(cmd[1] << 8) | cmd[2]; }
uint8_t MPU9250::read_reg(unsigned reg, uint32_t speed) { uint8_t cmd[2] = { (uint8_t)(reg | DIR_READ), 0}; // general register transfer at low clock speed set_frequency(speed); transfer(cmd, cmd, sizeof(cmd)); return cmd[1]; }
static int fm_set_freq(struct file *file, void *priv, struct v4l2_frequency *argp) { struct poseidon *p = file->private_data; p->file_for_stream = file; #ifdef CONFIG_PM p->pm_suspend = pm_fm_suspend; p->pm_resume = pm_fm_resume; #endif return set_frequency(p, argp->frequency); }
void tap_tempo_task(void) { static uint8_t taps = 0; static uint8_t buffer_index = 0; // Increment counter static uint16_t counter = 0; ++counter; if (!tap_arrived) { if (counter < 400) { return; } // Reset after timeout set_led(LED_RED, false); counter = 0; taps = 0; buffer_index = 0; return; } tap_arrived = false; // Increment tap counter to buffer size if (taps < TAP_TEMPO_BUFFER_SIZE) { ++taps; } if (taps == 1) { set_led(LED_RED, true); } else { // Register tap interval with cyclic buffer static fixed_t tap_tempo_buffer[TAP_TEMPO_BUFFER_SIZE] = {0, }; fixed_t tap_frequency = fixed_from_int(TAP_TEMPO_TASK_FREQUENCY) / counter; tap_tempo_buffer[buffer_index] = tap_frequency; ++buffer_index; buffer_index %= TAP_TEMPO_BUFFER_SIZE; // Compute average fixed_t average = 0; for (int i=0; i<taps; i++) { average += tap_tempo_buffer[i]; } average /= taps; // Set wave frequency set_frequency(tap_tempo_wave, average); } // Reset counter counter = 0; }
/***************************************************************** * \brief public wrapper for set_frequency * \parameter frequency frequency in MHz * \return 1 if success,0 - otherwise */ int radio_set_freq(struct stream_st *stream, float frequency){ radio_priv_t* priv=(radio_priv_t*)stream->priv; if (set_frequency(priv,frequency)!=STREAM_OK){ return 0; } if (get_frequency(priv,&frequency)!=STREAM_OK){ return 0; } mp_msg(MSGT_RADIO, MSGL_INFO, MSGTR_RADIO_CurrentFreq,frequency); return 1; }
void MPU9250::write_reg(unsigned reg, uint8_t value) { uint8_t cmd[2]; cmd[0] = reg | DIR_WRITE; cmd[1] = value; // general register transfer at low clock speed set_frequency(MPU9250_LOW_BUS_SPEED); transfer(cmd, nullptr, sizeof(cmd)); }
SimpleTimer::SimpleTimer(int _hz) { /* How long has the system been running? */ seconds = 0; ticks = 0; /* ticks since last "seconds" update. */ /* At what frequency do we update the ticks counter? */ /* hz = 18; */ /* Actually, by defaults it is 18.22Hz. In this way, a 16-bit counter wraps around every hour. */ set_frequency(_hz); }
ControlInput::ControlInput(const char* name, uint32_t stackSize, uint8_t priority, uint32_t eeprom_size) : ApplicationModule(name, stackSize, priority, eeprom_size) { messenger.subscribe(REQUEST_CONTROLINPUTS_REPORT); messenger.subscribe(CALIBRATE_CONTROLINPUT); messenger.subscribe(SHIFT_OF_CONTROL_REPORT); control_socket.control_mode = CONTROLMODE_MANUAL_THROTTLE; set_frequency(50); }
void init_timer(unsigned long freq) { DDRD |= (1 << PD7); // OC2 is PD7 set_frequency(freq); /* * Setting the Timer/Counter2 in CTC (Clear Timer on Compare) (non-PWM) for * controlling frequency of waveforms, directly by the compare register & * Toggling on Match to generate square wave for a particular frequency. * Output would come on OC2/PD7 (Pin 21). */ TCCR2 = (1 << WGM21) | (0 << WGM20) | (1 << COM20) | PRESCALER; }
void PTS::set_frequency_ttls(state& the_state) { // find the frequency informations... // and exchange the phase informations analogout* pts_aout=NULL; /* find a analogout section with suitable id */ state::iterator i=the_state.begin(); while(i!=the_state.end()) { analogout* aout=dynamic_cast<analogout*>(*i); if (aout!=NULL && aout->id==id) { if (pts_aout==NULL) { /* save the informations */ pts_aout=aout; } else { fprintf(stderr, "found another pts decade section, ignoring\n"); delete aout; } /* remove the analog out section */ the_state.erase(i++); } else ++i; } /* state members loop */ /* now, add the ttl information*/ if (pts_aout!=NULL) { phase_add_ttls(the_state, pts_aout->phase); if (pts_aout->frequency!=0) { if (frequency==0) { set_frequency(pts_aout->frequency); } /* different frequencies are forbidden */ else if (frequency!=pts_aout->frequency) { fprintf(stderr, "ignoring frequency %g at analogout %d\n",pts_aout->frequency,id); } } delete pts_aout; } else { /* because we use transparent mode, we have to set phase everywhere */ phase_add_ttls(the_state, phase); } }
/** Initializes PWM signal on PE4 for output to speaker **/ void PWM_init(void) { SYSCTL->RCGC0 |= (1UL << 20); //SYSCTL->RCGC2 |= (1UL << 4); // Cannot configure this AND RCGCGPIO GPIOE->AFSEL |= (1UL << 4); // Alternate function GPIOE->PCTL |= (0x4 << 16); // Select M0PWM4 SYSCTL->RCC |= (1 << 20); // Use PWM divider SYSCTL->RCC |= (0x7 << 17); // Divider set to divide by 64 PWM0->_2_CTL = 0x0UL; // Immediate update to parameters PWM0->_2_GENA = 0x8CUL; // Drive PWM high when counter matches LOAD, drive low when matches CMPA set_frequency(frequency); set_volume(volume); PWM0->_2_CTL = 0x1UL; // enabled PWM module 0, generator 2 PWM0->ENABLE |= (1UL << 4); // enable PWM module 0 }
void Channel::play(SoundData * data, int loop) { stop(); id = data->id; data->load(&sound); if (sound == NULL) { std::cout << "Ignored play" << std::endl; return; } set_volume(volume); set_pan(pan); if (frequency != 0) set_frequency(frequency); sound->set_loop(loop == 0); if (loop > 1) std::cout << "Invalid number of loops (" << loop << ")" << std::endl; sound->play(); }