static void calc_stereo_freq(gint16 dest[2][256], gint16 src[2][512], gint nch) { calc_freq(dest[0], src[0]); if(nch == 2) calc_freq(dest[1], src[1]); else memcpy(dest[1], dest[0], 256 * sizeof(gint16)); }
void tim1_up_tim10_isr(void) { //oscilloscope flag: start of interrupt gpio_set(GPIOD, GPIO11); //Clear the update interrupt flag timer_clear_flag(TIM1, TIM_SR_UIF); calc_freq(); // /* ORIGINAL if (center_aligned_state==FIRST_HALF) { //oscilloscope flag: start of First HALF gpio_set(GPIOB, GPIO15); voltage_measure (ADC1,ADC_CHANNEL1); } else { //oscilloscope flag: start of second half gpio_set(GPIOD, GPIO9); DTC_SVM(); collecting_floating_data(); colllecting_flux_linkage(); gpio_clear(GPIOD, GPIO11); } //oscilloscope flag: start of halves //gpio_clear(GPIOB, GPIO15); //oscilloscope flag: end of interrupt gpio_clear(GPIOD, GPIO9); }
static void calc_mono_freq(gint16 dest[2][256], gint16 src[2][512], gint nch) { gint i; gint16 *d, *sl, *sr, tmp[512]; if(nch == 1) calc_freq(dest[0], src[0]); else { d = tmp; sl = src[0]; sr = src[1]; for(i = 0; i < 512; i++) { *(d++) = (*(sl++) + *(sr++)) >> 1; } calc_freq(dest[0], tmp); } }
void freq_main(void) { cli(); counter_init(); gate_init(); stop(); reset(); ff_clr(); key_init(); setup_timers(); setup_interrupts(); adc_init(); sti(); /*clear counter*/ TCNT2= 0; TCNT0= 0; TCNT1= 0xFF00; T0_ovc = T1_ovc =0; start(); //fast clear screen... post_display(filter());//really result while(1) { key_process(); keep_live(); mode = read_adc_mode(); update_lcd_status(); if(is_stop()&&soft_stop){ calc_freq(); post_display(filter());//really result c_live() ; //mark succeufull .. if(loop>=(ST)){ //never clear reset(); } loop=0; start(); } } }
static uint8_t square(float t, uint8_t freq_msb, uint8_t freq_lsb, int volume, int duty) { const uint8_t duty_table[4][8] = { {0,0,0,0,0,0,0,1}, {1,0,0,0,0,0,0,1}, {1,0,0,0,0,1,1,1}, {0,1,1,1,1,1,1,0}, }; float freq = calc_freq(freq_msb, freq_lsb); uint32_t idx = (uint32_t)(t * freq * 8); return volume * duty_table[duty][idx % 8]; }
static uint8_t wave(float t, audio_t *audio) { const uint8_t shift_table[] = { 4, 0, 1, 2 }; // The wave frequency is half that of the other channels. float freq = calc_freq(audio->wave.freq_msb, audio->wave.freq_lsb) / 2.0f; uint32_t idx = (uint32_t)(t * freq * 32); uint8_t sample = audio->wave_table[idx % 32]; uint8_t shift = shift_table[audio->wave.volume_code]; uint8_t value = sample >> shift; return value; }
int main(int argc, char *argv[]) { int n, m, *freq; char text[NUM], *dict; PHT p = NULL; PCode pc = NULL; scanf("%s", &text); n = strlen(text); m = calc_freq(text, &freq, &dict, n); huffman(&p, freq, dict, m); get_code(&pc, p, m); show_result(pc, m); return 0; }
int fs_bind_freq(fs_query_state *qs, fs_query *q, int block, rasqal_triple *t) { int ret = 100; #if DEBUG_OPTIMISER char dir = 'X'; #endif if (!fs_opt_is_const(q->bb[block], t->subject) && !fs_opt_is_const(q->bb[block], t->predicate) && !fs_opt_is_const(q->bb[block], t->object) && !fs_opt_is_const(q->bb[block], t->origin)) { #if DEBUG_OPTIMISER dir = '?'; #endif ret = INT_MAX; } else if (!fs_opt_is_const(q->bb[block], t->subject) && !fs_opt_is_const(q->bb[block], t->object)) { #if DEBUG_OPTIMISER dir = '?'; #endif ret = INT_MAX - 100; } else if (qs->freq_s && fs_opt_num_vals(q->bb[block], t->subject) == 1 && fs_opt_num_vals(q->bb[block], t->predicate) == 1) { #if DEBUG_OPTIMISER dir = 's'; #endif ret = calc_freq(q, block, qs->freq_s, t->subject, t->predicate); } else if (qs->freq_o && fs_opt_num_vals(q->bb[block], t->object) == 1 && fs_opt_num_vals(q->bb[block], t->predicate) == 1) { #if DEBUG_OPTIMISER dir = 'o'; #endif ret = calc_freq(q, block, qs->freq_o, t->object, t->predicate) + q->segments * 50; } else if (qs->freq_s && fs_opt_num_vals(q->bb[block], t->subject) == 1) { #if DEBUG_OPTIMISER dir = 's'; #endif ret = calc_freq(q, block, qs->freq_s, t->subject, NULL); } else if (qs->freq_o && fs_opt_num_vals(q->bb[block], t->object) == 1) { #if DEBUG_OPTIMISER dir = 'o'; #endif ret = calc_freq(q, block, qs->freq_s, t->object, NULL) + q->segments * 50; /* cluases for if we have no freq data */ } else if (fs_opt_num_vals(q->bb[block], t->subject) < 1000000 && fs_opt_num_vals(q->bb[block], t->predicate) < 100 && fs_opt_num_vals(q->bb[block], t->object) == INT_MAX) { #if DEBUG_OPTIMISER dir = 's'; #endif ret = fs_opt_num_vals(q->bb[block], t->subject) * fs_opt_num_vals(q->bb[block], t->predicate); if (!fs_opt_is_bound(q->bb[block], t->subject) && !fs_opt_is_bound(q->bb[block], t->predicate) && !fs_opt_is_bound(q->bb[block], t->object)) { ret *= (fs_binding_length(q->bb[block]) * 100); } } else if (fs_opt_num_vals(q->bb[block], t->object) < 1000000 && fs_opt_num_vals(q->bb[block], t->predicate) < 100 && fs_opt_num_vals(q->bb[block], t->subject) == INT_MAX) { #if DEBUG_OPTIMISER dir = 'o'; #endif ret = fs_opt_num_vals(q->bb[block], t->predicate) * fs_opt_num_vals(q->bb[block], t->object); if (!fs_opt_is_bound(q->bb[block], t->subject) && !fs_opt_is_bound(q->bb[block], t->predicate) && !fs_opt_is_bound(q->bb[block], t->object)) { ret *= (fs_binding_length(q->bb[block]) * 100); } } #if DEBUG_OPTIMISER if (q->flags & FS_QUERY_EXPLAIN) { printf("freq(%c, ", dir); rasqal_triple_print(t, stdout); printf(") = %d\n", ret); } #endif return ret; }
int main() { XStatus status; u16 sw, oldSw =0xFFFF; // 0xFFFF is invalid --> makes sure the PWM freq is updated 1st time int rotcnt, oldRotcnt = 0x1000; bool done = false; bool hw_switch = 0; init_platform(); // initialize devices and set up interrupts, etc. status = do_init(); if (status != XST_SUCCESS) { PMDIO_LCD_setcursor(1,0); PMDIO_LCD_wrstring("****** ERROR *******"); PMDIO_LCD_setcursor(2,0); PMDIO_LCD_wrstring("INIT FAILED- EXITING"); exit(XST_FAILURE); } // initialize the global variables timestamp = 0; pwm_freq = INITIAL_FREQUENCY; pwm_duty = INITIAL_DUTY_CYCLE; clkfit = 0; new_perduty = false; // start the PWM timer and kick of the processing by enabling the Microblaze interrupt PWM_SetParams(&PWMTimerInst, pwm_freq, pwm_duty); PWM_Start(&PWMTimerInst); microblaze_enable_interrupts(); // display the greeting PMDIO_LCD_setcursor(1,0); PMDIO_LCD_wrstring("ECE544 Project 1"); PMDIO_LCD_setcursor(2,0); PMDIO_LCD_wrstring(" by Rehan Iqbal "); NX4IO_setLEDs(0x0000FFFF); delay_msecs(2000); NX4IO_setLEDs(0x00000000); // write the static text to the display PMDIO_LCD_clrd(); PMDIO_LCD_setcursor(1,0); PMDIO_LCD_wrstring("G|FR: DCY: %"); PMDIO_LCD_setcursor(2,0); PMDIO_LCD_wrstring("D|FR: DCY: %"); // turn off the LEDs and clear the seven segment display NX4IO_setLEDs(0x00000000); NX410_SSEG_setAllDigits(SSEGLO, CC_BLANK, CC_BLANK, CC_BLANK, CC_BLANK, DP_NONE); NX410_SSEG_setAllDigits(SSEGHI, CC_BLANK, CC_BLANK, CC_BLANK, CC_BLANK, DP_NONE); // main loop do { // check rotary encoder pushbutton to see if it's time to quit if (PMDIO_ROT_isBtnPressed()) { done = true; } else { new_perduty = false; // get the switches and mask out all but the switches that determine the PWM timer frequency sw &= PWM_FREQ_MSK; sw = NX4IO_getSwitches(); if (sw != oldSw) { // check the status of sw[2:0] and assign appropriate PWM output frequency switch (sw & 0x07) { case 0x00: pwm_freq = PWM_FREQ_100HZ; break; case 0x01: pwm_freq = PWM_FREQ_1KHZ; break; case 0x02: pwm_freq = PWM_FREQ_10KHZ; break; case 0x03: pwm_freq = PWM_FREQ_50KHZ; break; case 0x04: pwm_freq = PWM_FREQ_100KHZ; break; case 0x05: pwm_freq = PWM_FREQ_500KHZ; break; case 0x06: pwm_freq = PWM_FREQ_1MHZ; break; case 0x07: pwm_freq = PWM_FREQ_5MHZ; break; } // check the status of sw[3] and assign to global variable hw_switch = (sw & 0x08); // update global variable indicating there are new changes oldSw = sw; new_perduty = true; } // read rotary count and handle duty cycle changes // limit duty cycle to 0% to 99% PMDIO_ROT_readRotcnt(&rotcnt); if (rotcnt != oldRotcnt) { // show the rotary count in hex on the seven segment display NX4IO_SSEG_putU16Hex(SSEGLO, rotcnt); // change the duty cycle pwm_duty = MAX(1, MIN(rotcnt, 99)); oldRotcnt = rotcnt; new_perduty = true; } // update generated frequency and duty cycle if (new_perduty) { u32 freq, dutycycle; unsigned int detect_freq = 0x00; unsigned int detect_duty = 0x00; // set the new PWM parameters - PWM_SetParams stops the timer status = PWM_SetParams(&PWMTimerInst, pwm_freq, pwm_duty); if (status == XST_SUCCESS) { PWM_GetParams(&PWMTimerInst, &freq, &dutycycle); update_lcd(freq, dutycycle, 1); // check if sw[3] is high or low (HWDET / SWDET) // pass functions different args depending on which mode is selected if (hw_switch) { detect_freq = calc_freq(hw_high_count, hw_low_count, hw_switch); detect_duty = calc_duty(hw_high_count, hw_low_count); } else { detect_freq = calc_freq(sw_high_count, sw_low_count, hw_switch); detect_duty = calc_duty(sw_high_count, sw_low_count); } // update the LCD display with detected frequency & duty cycle update_lcd(detect_freq, detect_duty, 2); PWM_Start(&PWMTimerInst); } } } } while (!done); // wait until rotary encoder button is released do { delay_msecs(10); } while (PMDIO_ROT_isBtnPressed()); // we're done, say goodbye xil_printf("\nThat's All Folks!\n\n"); PMDIO_LCD_setcursor(1,0); PMDIO_LCD_wrstring("That's All Folks"); PMDIO_LCD_setcursor(2,0); PMDIO_LCD_wrstring(" "); NX410_SSEG_setAllDigits(SSEGHI, CC_BLANK, CC_B, CC_LCY, CC_E, DP_NONE); NX410_SSEG_setAllDigits(SSEGLO, CC_B, CC_LCY, CC_E, CC_BLANK, DP_NONE); delay_msecs(5000); // turn the lights out PMDIO_LCD_clrd(); NX410_SSEG_setAllDigits(SSEGHI, CC_BLANK, CC_BLANK, CC_BLANK, CC_BLANK, DP_NONE); NX410_SSEG_setAllDigits(SSEGLO, CC_BLANK, CC_BLANK, CC_BLANK, CC_BLANK, DP_NONE); NX4IO_RGBLED_setDutyCycle(RGB1, 0, 0, 0); NX4IO_RGBLED_setChnlEn(RGB1, false, false, false); // exit gracefully cleanup_platform(); exit(0); }
static void cpufreq_interactive_timer(unsigned long data) { u64 now; unsigned int delta_time; u64 cputime_speedadj; int cpu_load; struct cpufreq_interactive_cpuinfo *pcpu = &per_cpu(cpuinfo, data); unsigned int new_freq; unsigned int loadadjfreq; unsigned int index; unsigned long flags; unsigned long mod_min_sample_time; int i, max_load; unsigned int max_freq; unsigned int boosted_freq; struct cpufreq_interactive_cpuinfo *picpu; if (!down_read_trylock(&pcpu->enable_sem)) return; if (!pcpu->governor_enabled) goto exit; spin_lock_irqsave(&pcpu->load_lock, flags); now = update_load(data); delta_time = (unsigned int)(now - pcpu->cputime_speedadj_timestamp); cputime_speedadj = pcpu->cputime_speedadj; spin_unlock_irqrestore(&pcpu->load_lock, flags); if (WARN_ON_ONCE(!delta_time)) goto rearm; spin_lock_irqsave(&pcpu->target_freq_lock, flags); do_div(cputime_speedadj, delta_time); loadadjfreq = (unsigned int)cputime_speedadj * 100; cpu_load = loadadjfreq / pcpu->target_freq; pcpu->prev_load = cpu_load; boosted_freq = max(hispeed_freq, pcpu->policy->min); if (cpu_load >= go_hispeed_load) { if (pcpu->target_freq < boosted_freq) { new_freq = boosted_freq; } else { new_freq = calc_freq(pcpu, cpu_load); if (new_freq < boosted_freq) new_freq = boosted_freq; } } else { new_freq = calc_freq(pcpu, cpu_load); if (new_freq > boosted_freq && pcpu->target_freq < boosted_freq) new_freq = boosted_freq; if (sync_freq && new_freq < sync_freq) { max_load = 0; max_freq = 0; for_each_online_cpu(i) { picpu = &per_cpu(cpuinfo, i); if (i == data || picpu->prev_load < up_threshold_any_cpu_load) continue; max_load = max(max_load, picpu->prev_load); max_freq = max(max_freq, picpu->target_freq); } if (max_freq > up_threshold_any_cpu_freq || max_load >= up_threshold_any_cpu_load) new_freq = sync_freq; } }