Exemplo n.º 1
0
/**
 * This function sends the current waveform value for each channel
 * to the appropriate output port. Checks are made to ensure frequency
 * and waveform values are up to date.
 */
void MbedSynth::send_vals(void) 
{
    if (freqChange == TRUE) {
      set_freq(newFreq); // Set new frequency
      freqChange = FALSE; // Reset freqChange
    }
     
    ledPin->write(!ledPin->read()); //debug
    acc_inc(); // Increment phase accumulator
    waveIndex = phaseAcc >> 24; // Get address into wavetable    
    
    if (noteOn == TRUE)
      synthPin->write((waveTable[waveIndex])/((float)(SAMP_NUM-1)));
}
Exemplo n.º 2
0
int v4l2_set_frequency(void** session_data, int frequency){
  fm_v4l2_data* session;
  int ret;

  ALOGI("%s:\n", __FUNCTION__);
  session = get_session_data(session_data);

  session->freq = get_proprietary_freq( frequency, session->fact);
  ret= set_freq(session->fd,  session->freq);
  if (ret < 0)
      return -1;

  return frequency;
}
Exemplo n.º 3
0
static void v4l_set_input(struct context *cnt, struct video_dev *viddev, unsigned char *map, int width, int height,
                          unsigned short input, unsigned short norm, int skip, unsigned long freq)
{

    if (input != viddev->input || norm != viddev->norm || freq != viddev->freq) {
        int dummy;
        unsigned long frequnits = freq;

        
        if ((dummy = set_input(viddev, input)) == -1)
            return;

        viddev->input = dummy;
        
        if ((dummy = set_input_format(viddev, norm)) == -1)
            return;
        
        viddev->norm = dummy;
        
        if ((viddev->tuner_device != NULL) && (viddev->input == IN_TV) && (frequnits > 0)) {
            if (set_freq(viddev, freq) == -1)
                return;
        }

        // FIXME
        /*
        if (setup_pixelformat(viddev) == -1) {
            motion_log(LOG_ERR, 1, "ioctl (VIDIOCSFREQ)");
            return
        }
        */

        /*
        if (set_geometry(viddev, width, height) == -1)
            return;
        */     
            
        v4l_picture_controls(cnt, viddev);

        viddev->freq = freq;

        /* skip a few frames if needed */
        for (dummy = 0; dummy < skip; dummy++)
            v4l_next(viddev, map, width, height);

    } else {
        /* No round robin - we only adjust picture controls */
        v4l_picture_controls(cnt, viddev);
    }
}
Exemplo n.º 4
0
void radio_chip_set_freq(u8 mode,bool disp_pro)
{
    xd_u8 freq_step =0;

    set_brightness_all_on();

    freq_step = Current_Band.Tune_Step;
	
    if (mode == FM_FRE_INC)
    {
        frequency=frequency+freq_step;
		
	 if (frequency > REG_MAX_FREQ)
	     frequency = REG_MIN_FREQ;		
    }
    else if (mode == FM_FRE_DEC)
    {
        frequency=frequency-freq_step;
		
	 if (frequency < REG_MIN_FREQ)
	      frequency =REG_MAX_FREQ;		
    }
    else{
		
	    if (frequency > REG_MAX_FREQ)
	        frequency = REG_MAX_FREQ;
		
	    if (frequency < REG_MIN_FREQ)
	        frequency =REG_MIN_FREQ;
    }
	
    set_freq(frequency);
	
    if(disp_pro)	
	Disp_Con(DISP_FREQ);			

#if 1//def SAVE_BAND_FREQ_INFO
#ifdef FM_UART_ENABLE
    printf("------->- set_radio_freq    fre:%4u   \r\n",frequency);
#endif
    save_radio_freq(frequency,cur_sw_fm_band*2+MEM_FREQ_BASE);
#endif
    set_sys_vol(my_music_vol);	

}
Exemplo n.º 5
0
int v4l2_scan (void ** session_data, enum fmradio_seek_direction_t direction){
   fm_v4l2_data* session;
   int increment, rate, freqi, ret;

   ALOGI("%s:\n", __FUNCTION__);
   session = get_session_data(session_data);

   session->scan_band_run=SCAN_RUN;
   if (direction==FMRADIO_SEEK_DOWN)
     increment = -  session->grid;
   else                                      //FMRADIO_SEEK_UP
     increment =  session->grid;

  freqi = session->freq + increment;         //drop the current frequency
  ALOGI("Starting scanning...\n");
  while (session->scan_band_run==SCAN_RUN){

      ret= set_freq(session->fd, freqi);
      if (ret<0)
          return -1;

      usleep(LOCKTIME);                       // let it lock on
      rate= get_signal_strength( session->fd,  &session->vt);
      if (rate < 0)
         return -1;

      ALOGI("final rate %d > %d \n", rate , session->threshold);

      if (rate >  session->threshold){
      ALOGI("Found freq, %d\n", freqi);
      session->scan_band_run=SCAN_STOP;
      session->freq = freqi;
      return get_standard_freq(freqi, session->fact);
      }

      freqi +=  increment;
      if ( freqi >  session->high_freq)
         freqi =  session->low_freq;
      if ( freqi <  session->low_freq)
          freqi =  session->high_freq;
  }
  ALOGI("End scan\n");
  return 0;
}
Exemplo n.º 6
0
void main()
{
	u16 resultat;
	u8 compteur=0;

	init_picstar();

	init_adc(); // code de l'exercise 2

	// initialiser le pwm sur RC2
	init_pwm(); // code a développer

	// initialise l'écran lcd
    init_lcd();
	set_backlight(ON);
	
	while(1)
	{
	u16 tmp;

	resultat=get_adc0();

#ifdef ACTIVER_MOTEUR
	set_pwm(1,resultat); // pwm duty = potentiometre
	lcd_gotoxy(0,0);
	fprintf(_H_USER,"HELLO WORLD %3u      ", compteur & 0xff);
	lcd_gotoxy(0,1);
	fprintf(_H_USER,"ADC= %u  ",resultat);
#else // si non activer le son
	if((resultat+=PLIMITE)>255)resultat=255;
	set_freq(1,resultat);

	lcd_gotoxy(0,0);
	fprintf(_H_USER,"ADC= %u ", resultat);
	lcd_gotoxy(0,1);
	// calcul de la frequence en 10khz
	tmp=120000L/16/resultat;
	fprintf(_H_USER,"Freq=%u.%1u khz ",tmp/10 & 0xff, tmp%10 &0xff);
#endif


	delay_ms(10);
	} // end while
}// fin of program
Exemplo n.º 7
0
void preset_move(int dir)
{
	int preset;

	if (station_info_num <= 0) return;

	preset = find_station_info(get_freq());
	if (preset >= 0) {
		if (dir) {
			if (++preset >= station_info_num) preset = 0;
		}
		else {
			if (--preset < 0) preset = station_info_num - 1;
		}
	}
	else preset = 1; 

	set_freq(station_info[preset].freq, HCC_DEFAULT, SNC_DEFAULT, FORCED_MONO, 0, 0);
}
Exemplo n.º 8
0
void fp_node::merge(fp_node *right_node)
{
	// merges two nodes
	// w.r.t. this node is left node an in node is right node

	// adapt frequency and interval
	set_freq( get_freq() + right_node->get_freq());
	set_max( right_node->get_max() );

	// merge children
	fp_nodelist &right_childs = right_node->get_childs();

	fp_nodelist::iterator left_it = m_childs.begin();
	fp_nodelist::iterator right_it = right_childs.begin();

	while (right_it != right_childs.end()){
		if ((left_it == m_childs.end()) || (*right_it)->left_of(*(*left_it))) {
			add_child(*right_it);
			fp_nodelist::iterator tmpit = right_it;
			right_it++;
			right_childs.erase(tmpit);
		} else if ((*left_it)->contains(*(*right_it))) {
			(*left_it)->merge(*right_it); // recursive step
			fp_nodelist::iterator tmpit = right_it;
			right_it++;
			right_childs.erase(tmpit);
		} else if ((*right_it)->contains(*(*left_it))) {
			(*right_it)->merge(*left_it);
			fp_nodelist::iterator tmpit = left_it;
			left_it++;
			m_childs.erase(tmpit);
		} else {
			left_it++;
		}
	}

	// cleanup right node
	delete right_node;
}
Exemplo n.º 9
0
int search(int dir, int mode, int forced_mono)
{
	unsigned char radio[5] = {0};
	double freq;

	freq = get_freq();

	if (dir) freq += 0.1;
	else freq -= 0.1;

	if (freq >= 108.0 || freq <= 76.0)
		return -1;

	frequencyB = 4 * (freq * 1000000 + 225000) / 32768; //calculating PLL word
	frequencyH = frequencyB >> 8;
	frequencyH = frequencyH | 0x40; // triggers search
	frequencyL = frequencyB & 0xFF;

	//nothing to set in array #2 as up is the normal search direction
	radio[0] = frequencyH; //FREQUENCY H
	radio[0] |= 0x80; // MUTE
	radio[1] = frequencyL; //FREQUENCY L
	radio[2] = 0x10; // high side LO injection is on,.
	radio[2] |= (mode & 0x03) << 5; // high side LO injection is on,.
	if (dir) radio[2] |= 0x80;	// search up/down
	if (forced_mono) radio[2] |= 0x08; 
	radio[3] = 0x10; // Xtal is 32.768 kHz
	//if (freq < 87.5) radio[3] |= 0x20;
	if (HCC_DEFAULT) radio[3] |= 0x04;
	if (SNC_DEFAULT) radio[3] |= 0x02;
	radio[4] = 0x40; // deemphasis is 75us in Korea and US

	write(fd, radio, 5);

	wait_ready();
	set_freq(get_freq(), HCC_DEFAULT, SNC_DEFAULT, forced_mono, 0, 0); // unmute
	
	return 0;
}
Exemplo n.º 10
0
/*!
 * \brief Boot the kernel.
 * - Set priorities
 * - Set clock
 * - Set os frequency,
 * - Start allocator
 * - Create the idle process. Allocator though will
 * not give heap though before pkernel_run().
 *
 * \param __kmsize The pkernels size (aka the idle process stack size).
 * \param clk The CPU clock used by application.
 * \param os_f The OS freq requested by application.
 *
 * \return 0(proc_idle's pid) on success.
 */
int kinit (size_t kmsize, clock_t clk, clock_t os_f)
{
   pid_t pid;

   kSetPriority(kPendSV_IRQn, OS_PENDSV_PRI);
   kSetPriority(kSysTick_IRQn, OS_SYSTICK_PRI);

   set_clock (clk);     // Set kernel's knowledge for clocking and freq
   set_freq (os_f);
   alloc_init ();       // Init the Stack allocation table.

   // Make the idle proc
   pid = proc_newproc ((process_ptr_t)&proc_idle, kmsize, 0, 0);
   /*
    * \note
    * We make sure that we are outside off ANY process (cur_pid=-1)
    * so the idle's proc[0].tcb.sp remains untouched by PendSV until
    * our first context_switch from idle.
    */
   proc_set_current_pid(-1);
   return (int)pid; // Must be 0 (idle's pid)
}
Exemplo n.º 11
0
usb_request_status_t usb_vendor_request_set_freq(
	usb_endpoint_t* const endpoint,
	const usb_transfer_stage_t stage) 
{
	if (stage == USB_TRANSFER_STAGE_SETUP) 
	{
		usb_transfer_schedule_block(endpoint->out, &set_freq_params, sizeof(set_freq_params_t),
					    NULL, NULL);
		return USB_REQUEST_STATUS_OK;
	} else if (stage == USB_TRANSFER_STAGE_DATA) 
	{
		const uint64_t freq = set_freq_params.freq_mhz * 1000000ULL + set_freq_params.freq_hz;
		if( set_freq(freq) ) 
		{
			usb_transfer_schedule_ack(endpoint->in);
			return USB_REQUEST_STATUS_OK;
		}
		return USB_REQUEST_STATUS_STALL;
	} else
	{
		return USB_REQUEST_STATUS_OK;
	}
}
Exemplo n.º 12
0
static void time_update(void) {
	bool retry;

	do {
		retry = false;

		uint64_t freq = SDL_GetPerformanceFrequency();
		uint64_t cntr = SDL_GetPerformanceCounter();

		if(freq != prev_hires_freq) {
			log_debug("High resolution timer frequency changed: was %"PRIu64", now %"PRIu64". Saved time offset: %"PRIuTIME"", prev_hires_freq, freq, time_offset);
			time_offset = time_current;
			set_freq(freq);
			prev_hires_time = SDL_GetPerformanceCounter();
			retry = true;
			continue;
		}

		hrtime_t time_new;

		if(fast_path_mul) {
			time_new = time_offset + (cntr - prev_hires_time) * fast_path_mul;
		} else {
			time_new = time_offset + umuldiv64(cntr - prev_hires_time, HRTIME_RESOLUTION, freq);
		}

		if(time_new < time_current) {
			log_warn("BUG: time went backwards. Was %"PRIuTIME", now %"PRIuTIME". Possible cause: your OS sucks spherical objects. Attempting to correct this...", time_current, time_new);
			time_offset = time_current;
			time_current = 0;
			prev_hires_time = SDL_GetPerformanceCounter();
			retry = true;
		} else {
			time_current = time_new;
		}
	} while(retry);
}
Exemplo n.º 13
0
void
Pit::init(unsigned freq)
{
    set_freq(freq);
}
Exemplo n.º 14
0
void handler_freq(mapper_signal sig, float *pfreq)
{
    set_freq(*pfreq);
}
Exemplo n.º 15
0
/*
 * loop_config - configure the loop filter
 *
 * LOCKCLOCK: The LOOP_DRIFTINIT and LOOP_DRIFTCOMP cases are no-ops.
 */
void
loop_config(
	int	item,
	double	freq
	)
{
	int	i;
	double	ftemp;

#ifdef DEBUG
	if (debug > 1)
		printf("loop_config: item %d freq %f\n", item, freq);
#endif
	switch (item) {

	/*
	 * We first assume the kernel supports the ntp_adjtime()
	 * syscall. If that syscall works, initialize the kernel time
	 * variables. Otherwise, continue leaving no harm behind.
	 */
	case LOOP_DRIFTINIT:
#ifndef LOCKCLOCK
#ifdef KERNEL_PLL
		if (mode_ntpdate)
			break;

		start_kern_loop();
#endif /* KERNEL_PLL */

		/*
		 * Initialize frequency if given; otherwise, begin frequency
		 * calibration phase.
		 */
		ftemp = init_drift_comp / 1e6;
		if (ftemp > NTP_MAXFREQ)
			ftemp = NTP_MAXFREQ;
		else if (ftemp < -NTP_MAXFREQ)
			ftemp = -NTP_MAXFREQ;
		set_freq(ftemp);
		if (freq_set)
			rstclock(EVNT_FSET, 0);
		else
			rstclock(EVNT_NSET, 0);
		loop_started = TRUE;
#endif /* LOCKCLOCK */
		break;

	case LOOP_KERN_CLEAR:
#if 0		/* XXX: needs more review, and how can we get here? */
#ifndef LOCKCLOCK
# ifdef KERNEL_PLL
		if (pll_control && kern_enable) {
			memset((char *)&ntv, 0, sizeof(ntv));
			ntv.modes = MOD_STATUS;
			ntv.status = STA_UNSYNC;
			ntp_adjtime(&ntv);
			sync_status("kernel time sync disabled",
				pll_status,
				ntv.status);
		   }
# endif /* KERNEL_PLL */
#endif /* LOCKCLOCK */
#endif
		break;

	/*
	 * Tinker command variables for Ulrich Windl. Very dangerous.
	 */
	case LOOP_ALLAN:	/* Allan intercept (log2) (allan) */
		allan_xpt = (u_char)freq;
		break;

	case LOOP_CODEC:	/* audio codec frequency (codec) */
		clock_codec = freq / 1e6;
		break;

	case LOOP_PHI:		/* dispersion threshold (dispersion) */
		clock_phi = freq / 1e6;
		break;

	case LOOP_FREQ:		/* initial frequency (freq) */
		init_drift_comp = freq;
		freq_set++;
		break;

	case LOOP_HUFFPUFF:	/* huff-n'-puff length (huffpuff) */
		if (freq < HUFFPUFF)
			freq = HUFFPUFF;
		sys_hufflen = (int)(freq / HUFFPUFF);
		sys_huffpuff = emalloc(sizeof(sys_huffpuff[0]) *
		    sys_hufflen);
		for (i = 0; i < sys_hufflen; i++)
			sys_huffpuff[i] = 1e9;
		sys_mindly = 1e9;
		break;

	case LOOP_PANIC:	/* panic threshold (panic) */
		clock_panic = freq;
		break;

	case LOOP_MAX:		/* step threshold (step) */
		clock_max_fwd = clock_max_back = freq;
		if (freq == 0 || freq > 0.5)
			select_loop(FALSE);
		break;

	case LOOP_MAX_BACK:	/* step threshold (step) */
		clock_max_back = freq;
		/*
		 * Leave using the kernel discipline code unless both
		 * limits are massive.  This assumes the reason to stop
		 * using it is that it's pointless, not that it goes wrong.
		 */
		if (  (clock_max_back == 0 || clock_max_back > 0.5)
		   || (clock_max_fwd  == 0 || clock_max_fwd  > 0.5))
			select_loop(FALSE);
		break;

	case LOOP_MAX_FWD:	/* step threshold (step) */
		clock_max_fwd = freq;
		if (  (clock_max_back == 0 || clock_max_back > 0.5)
		   || (clock_max_fwd  == 0 || clock_max_fwd  > 0.5))
			select_loop(FALSE);
		break;

	case LOOP_MINSTEP:	/* stepout threshold (stepout) */
		if (freq < CLOCK_MINSTEP)
			clock_minstep = CLOCK_MINSTEP;
		else
			clock_minstep = freq;
		break;

	case LOOP_TICK:		/* tick increment (tick) */
		set_sys_tick_precision(freq);
		break;

	case LOOP_LEAP:		/* not used, fall through */
	default:
		msyslog(LOG_NOTICE,
		    "loop_config: unsupported option %d", item);
	}
}
static int lirc_ioctl(struct inode *node, struct file *filep, unsigned int cmd,
		      unsigned long arg)
{
	int result;
	unsigned long value;
	unsigned int ivalue;
	unsigned int multiplier = 1;
	unsigned int mask = 0;
	int i;

	switch (cmd) {
	case LIRC_SET_TRANSMITTER_MASK:
		if (!(hardware.features&LIRC_CAN_SET_TRANSMITTER_MASK))
			return -ENOIOCTLCMD;
		result = get_user(ivalue, (unsigned int *) arg);
		if (result)
			return result;
		for (i = 0; i < MAX_CHANNELS; i++) {
			multiplier = multiplier * 0x10;
			mask |= multiplier;
		}
		if (ivalue >= mask)
			return MAX_CHANNELS;
		set_tx_channels(ivalue);
		return 0;
		break;

	case LIRC_GET_SEND_MODE:
		if (!(hardware.features & LIRC_CAN_SEND_MASK))
			return -ENOIOCTLCMD;

		result = put_user(LIRC_SEND2MODE
				(hardware.features & LIRC_CAN_SEND_MASK),
				(unsigned long *) arg);
		if (result)
			return result;
		break;

	case LIRC_SET_SEND_MODE:
		if (!(hardware.features&LIRC_CAN_SEND_MASK))
			return -ENOIOCTLCMD;

		result = get_user(value, (unsigned long *)arg);
		if (result)
			return result;
		break;

	case LIRC_GET_LENGTH:
		return -ENOSYS;
		break;

	case LIRC_SET_SEND_DUTY_CYCLE:
		dprintk(KERN_WARNING LIRC_DRIVER_NAME
					": SET_SEND_DUTY_CYCLE\n");

		if (!(hardware.features&LIRC_CAN_SET_SEND_DUTY_CYCLE))
			return -ENOIOCTLCMD;

		result = get_user(ivalue, (unsigned int *)arg);
		if (result)
			return result;
		if (ivalue <= 0 || ivalue > 100)
			return -EINVAL;

		/* TODO: */
		dprintk(LIRC_DRIVER_NAME
			": set_send_duty_cycle not yet supported\n");

		return 0;
		break;

	case LIRC_SET_SEND_CARRIER:
		dprintk(KERN_WARNING LIRC_DRIVER_NAME ": SET_SEND_CARRIER\n");

		if (!(hardware.features & LIRC_CAN_SET_SEND_CARRIER))
			return -ENOIOCTLCMD;

		result = get_user(ivalue, (unsigned int *)arg);
		if (result)
			return result;
		if (ivalue > 500000 || ivalue < 24000)
			return -EINVAL;
		if (ivalue != freq) {
			freq = ivalue;
			set_freq();
		}
		return 0;
		break;

	default:
		return -ENOIOCTLCMD;
	}
	return 0;
}
Exemplo n.º 17
0
int main(int argc, char *argv[])
{
	double freq;
	size_t len;
	int hcc = HCC_DEFAULT, snc = SNC_DEFAULT;
	int forced_mono = FORCED_MONO, mode = SEARCH_MODE_DEFAULT;

	prog_name = basename(argv[0]);

	//open access to the board, send error msg if fails
	if((fd = wiringPiI2CSetup(dID)) < 0) {
		fprintf(stderr, "error opening i2c channel\n");
		exit(1);
	}

	get_station_info();

	if (argc < 2) {
		if ((freq = get_tuned_freq())) {
			set_freq(freq, HCC_DEFAULT, SNC_DEFAULT, FORCED_MONO, 0, 0);
			print_status();
			printf("HCC: %s, SNC: %s\n", HCC_DEFAULT ? "On" : "Off", SNC_DEFAULT ? "On" : "Off");
		}
		else usage();
		exit(0);
	}

	len = strlen(argv[1]);
	if (!strncmp(argv[1], "scan", len)) {
		if (argc > 2) {
			mode = atoi(argv[2]);
			if (mode < 1) mode  = 1;
			else if (mode > 3) mode = 3;
			if (argc > 3) {
				len = strlen(argv[3]);
				if (!strncmp(argv[3], "mono", len)) forced_mono = 1;
				else forced_mono = 0;
			}
		}
		freq_scan(mode, forced_mono);
	}
	else if (!strncmp(argv[1], "status", len)) {
		print_status();
	}
	else if (!strncmp(argv[1], "next", len)) {
		preset_move(1);
		print_status();
	}
	else if (!strncmp(argv[1], "prev", len)) {
		preset_move(0);
		print_status();
	}
	else if (!strncmp(argv[1], "stereo", len)) {
		set_freq(get_freq(), HCC_DEFAULT, SNC_DEFAULT, 0, 0, 0);
	}
	else if (!strncmp(argv[1], "mono", len)) {
		set_freq(get_freq(), HCC_DEFAULT, SNC_DEFAULT, 1, 0, 0);
	}
	else if (!strncmp(argv[1], "up", len) || !strncmp(argv[1], "down", len)) {
		int dir;
		if (!strncmp(argv[1], "up", len)) dir = 1;
		else dir = 0;
		if (argc > 2) {
			mode = atoi(argv[2]);
			if (mode < 1) mode  = 1;
			else if (mode > 3) mode = 3;
			if (argc > 3) {
				len = strlen(argv[3]);
				if (!strncmp(argv[3], "mono", len)) forced_mono = 1;
				else forced_mono = 0;
			}
		}
		search(dir, mode, forced_mono);
		print_status();
		save_freq(get_freq());
	}
	else if (!strncmp(argv[1], "stepup", len)) {
		freq = get_freq() + 0.1;
		if (freq < 76.0 || freq > 108.0) exit(2);
		set_freq(get_freq()+0.1, HCC_DEFAULT, SNC_DEFAULT, FORCED_MONO, 0, 0);
		print_status();
		save_freq(get_freq());
	}
	else if (!strncmp(argv[1], "stepdown", len)) {
		freq = get_freq() - 0.1;
		if (freq < 76.0 || freq > 108.0) exit(2);
		set_freq(freq, HCC_DEFAULT, SNC_DEFAULT, FORCED_MONO, 0, 0);
		print_status();
		save_freq(get_freq());
	}
	else if (!strncmp(argv[1], "mute", len)) {
		set_freq(get_freq(), HCC_DEFAULT, SNC_DEFAULT, FORCED_MONO, 1, 0);
	}
	else if (!strncmp(argv[1], "unmute", len)) {
		set_freq(get_freq(), HCC_DEFAULT, SNC_DEFAULT, FORCED_MONO, 0, 0);
	}
	else if (!strncmp(argv[1], "off", len)) {
		set_freq(get_freq(), HCC_DEFAULT, SNC_DEFAULT, FORCED_MONO, 0, 1);
	}
	else if (!strncmp(argv[1], "on", len)) {
		set_freq(get_freq(), HCC_DEFAULT, SNC_DEFAULT, FORCED_MONO, 0, 0);
	}
	else {
		int preset;

		freq = strtod(argv[1], NULL);
		preset = (int)freq - 1;

		if ((freq >= 76.0 && freq <= 108.0) || (preset >= 0 && preset < station_info_num)) {
			if (freq >= 76.0 && freq <= 108.0) freq = strtod(argv[1], NULL);
			else freq = station_info[preset].freq;

			if (argc > 2) {
				if (atoi(argv[2]) != 0) hcc = 1;
				else hcc = 0;
				if (argc > 3) {
					if (atoi(argv[3]) != 0) snc = 1;
					else snc = 0;
					if (argc > 4) {
						len = strlen(argv[4]);
						if (!strncmp(argv[4], "mono", len)) forced_mono = 1;
						else forced_mono = 0;
					}
				}
			}
			set_freq(freq, hcc, snc, forced_mono, 0, 0);
			print_status();
			printf("HCC: %s, SNC: %s\n", hcc ? "On" : "Off", snc ? "On" : "Off");
		}
		else usage();
	}

	close(fd);
	return 0;
}
Exemplo n.º 18
0
int v4l2_full_scan (void ** session_data, int ** found_freqs, int ** signal_strenghts){
  fm_v4l2_data* session;
  int founded, i, ret;
  int freqi, rate;
  int *temp_freq, *temp_strenght;

  ALOGI("%s:\n", __FUNCTION__);
  session = get_session_data(session_data);

  session->scan_band_run=SCAN_RUN;

  temp_freq = (int *) malloc(sizeof(int) *MAX_FREQS);
  temp_strenght = (int *) malloc(sizeof(int) *MAX_FREQS);
  if (temp_freq == NULL || temp_strenght==NULL){
    ALOGE("error on allocate");
    return -1;
  }

  ALOGI("Starting full scanning...low freq:%d, high freq:%d\n", session->low_freq, session->high_freq);

  for (freqi =  session->low_freq, founded=0 ; ((freqi < session->high_freq)  && (founded < MAX_FREQS) && (session->scan_band_run==SCAN_RUN)) ; freqi += session->grid){

      ret = set_freq(session->fd, freqi);
      if (ret<0)
         return -1;

      usleep(LOCKTIME);		/* let it lock on */
      rate= get_signal_strength(session->fd, &session->vt);
      if (rate < 0)
          return -1;

      ALOGI("final rate %d > %d \n", rate ,session->threshold);

      if (rate > session->threshold){
          ALOGI("Founded index %d, freq %d\n", founded, freqi);
          temp_freq[founded]= freqi;
          temp_strenght[founded]= rate;
          founded++;
      }
  }

  *found_freqs = (int *) malloc(sizeof(int) * founded);
  *signal_strenghts = (int *) malloc(sizeof(int) * founded);
  if (*found_freqs == NULL || *signal_strenghts==NULL){
    ALOGE("error on allocate");
    return -1;
  }

  //copy founded frequencies
  for (i=0; i<founded; i++){
      (*found_freqs)[i] = get_standard_freq(temp_freq[i], session->fact);
      (*signal_strenghts)[i] = temp_strenght[i];
      ALOGI("Copied index %d, freq %d, signal %d\n",i, (*found_freqs)[i], (*signal_strenghts)[i] );
  }

  ALOGI("End full scan\n");
  free(temp_freq);
  free(temp_strenght);
  session->scan_band_run=SCAN_STOP;

  return i;
}
Exemplo n.º 19
0
int
main(int argc, char * argv[])
{
	struct timeval timeout;
	fd_set fdset;
	int nfds;
	struct pidfh *pfh = NULL;
	const char *pidfile = NULL;
	int freq, curfreq, initfreq, *freqs, i, j, *mwatts, numfreqs, load;
	int minfreq = -1, maxfreq = -1;
	int ch, mode, mode_ac, mode_battery, mode_none, idle, to;
	uint64_t mjoules_used;
	size_t len;

	/* Default mode for all AC states is adaptive. */
	mode_ac = mode_none = MODE_HIADAPTIVE;
	mode_battery = MODE_ADAPTIVE;
	cpu_running_mark = DEFAULT_ACTIVE_PERCENT;
	cpu_idle_mark = DEFAULT_IDLE_PERCENT;
	poll_ival = DEFAULT_POLL_INTERVAL;
	mjoules_used = 0;
	vflag = 0;

	/* User must be root to control frequencies. */
	if (geteuid() != 0)
		errx(1, "must be root to run");

	while ((ch = getopt(argc, argv, "a:b:i:m:M:n:p:P:r:v")) != -1)
		switch (ch) {
		case 'a':
			parse_mode(optarg, &mode_ac, ch);
			break;
		case 'b':
			parse_mode(optarg, &mode_battery, ch);
			break;
		case 'i':
			cpu_idle_mark = atoi(optarg);
			if (cpu_idle_mark < 0 || cpu_idle_mark > 100) {
				warnx("%d is not a valid percent",
				    cpu_idle_mark);
				usage();
			}
			break;
		case 'm':
			minfreq = atoi(optarg);
			if (minfreq < 0) {
				warnx("%d is not a valid CPU frequency",
				    minfreq);
				usage();
			}
			break;
		case 'M':
			maxfreq = atoi(optarg);
			if (maxfreq < 0) {
				warnx("%d is not a valid CPU frequency",
				    maxfreq);
				usage();
			}
			break;
		case 'n':
			parse_mode(optarg, &mode_none, ch);
			break;
		case 'p':
			poll_ival = atoi(optarg);
			if (poll_ival < 5) {
				warnx("poll interval is in units of ms");
				usage();
			}
			break;
		case 'P':
			pidfile = optarg;
			break;
		case 'r':
			cpu_running_mark = atoi(optarg);
			if (cpu_running_mark <= 0 || cpu_running_mark > 100) {
				warnx("%d is not a valid percent",
				    cpu_running_mark);
				usage();
			}
			break;
		case 'v':
			vflag = 1;
			break;
		default:
			usage();
		}

	mode = mode_none;

	/* Poll interval is in units of ms. */
	poll_ival *= 1000;

	/* Look up various sysctl MIBs. */
	len = 2;
	if (sysctlnametomib("kern.cp_times", cp_times_mib, &len))
		err(1, "lookup kern.cp_times");
	len = 4;
	if (sysctlnametomib("dev.cpu.0.freq", freq_mib, &len))
		err(EX_UNAVAILABLE, "no cpufreq(4) support -- aborting");
	len = 4;
	if (sysctlnametomib("dev.cpu.0.freq_levels", levels_mib, &len))
		err(1, "lookup freq_levels");

	/* Check if we can read the load and supported freqs. */
	if (read_usage_times(NULL))
		err(1, "read_usage_times");
	if (read_freqs(&numfreqs, &freqs, &mwatts, minfreq, maxfreq))
		err(1, "error reading supported CPU frequencies");
	if (numfreqs == 0)
		errx(1, "no CPU frequencies in user-specified range");

	/* Run in the background unless in verbose mode. */
	if (!vflag) {
		pid_t otherpid;

		pfh = pidfile_open(pidfile, 0600, &otherpid);
		if (pfh == NULL) {
			if (errno == EEXIST) {
				errx(1, "powerd already running, pid: %d",
				    otherpid);
			}
			warn("cannot open pid file");
		}
		if (daemon(0, 0) != 0) {
			warn("cannot enter daemon mode, exiting");
			pidfile_remove(pfh);
			exit(EXIT_FAILURE);

		}
		pidfile_write(pfh);
	}

	/* Decide whether to use ACPI or APM to read the AC line status. */
	acline_init();

	/*
	 * Exit cleanly on signals.
	 */
	signal(SIGINT, handle_sigs);
	signal(SIGTERM, handle_sigs);

	freq = initfreq = curfreq = get_freq();
	i = get_freq_id(curfreq, freqs, numfreqs);
	if (freq < 1)
		freq = 1;

	/*
	 * If we are in adaptive mode and the current frequency is outside the
	 * user-defined range, adjust it to be within the user-defined range.
	 */
	acline_read();
	if (acline_status > SRC_UNKNOWN)
		errx(1, "invalid AC line status %d", acline_status);
	if ((acline_status == SRC_AC &&
	    (mode_ac == MODE_ADAPTIVE || mode_ac == MODE_HIADAPTIVE)) ||
	    (acline_status == SRC_BATTERY &&
	    (mode_battery == MODE_ADAPTIVE || mode_battery == MODE_HIADAPTIVE)) ||
	    (acline_status == SRC_UNKNOWN &&
	    (mode_none == MODE_ADAPTIVE || mode_none == MODE_HIADAPTIVE))) {
		/* Read the current frequency. */
		len = sizeof(curfreq);
		if (sysctl(freq_mib, 4, &curfreq, &len, NULL, 0) != 0) {
			if (vflag)
				warn("error reading current CPU frequency");
		}
		if (curfreq < freqs[numfreqs - 1]) {
			if (vflag) {
				printf("CPU frequency is below user-defined "
				    "minimum; changing frequency to %d "
				    "MHz\n", freqs[numfreqs - 1]);
			}
			if (set_freq(freqs[numfreqs - 1]) != 0) {
				warn("error setting CPU freq %d",
				    freqs[numfreqs - 1]);
			}
		} else if (curfreq > freqs[0]) {
			if (vflag) {
				printf("CPU frequency is above user-defined "
				    "maximum; changing frequency to %d "
				    "MHz\n", freqs[0]);
			}
			if (set_freq(freqs[0]) != 0) {
				warn("error setting CPU freq %d",
				    freqs[0]);
			}
		}
	}

	idle = 0;
	/* Main loop. */
	for (;;) {
		FD_ZERO(&fdset);
		if (devd_pipe >= 0) {
			FD_SET(devd_pipe, &fdset);
			nfds = devd_pipe + 1;
		} else {
			nfds = 0;
		}
		if (mode == MODE_HIADAPTIVE || idle < 120)
			to = poll_ival;
		else if (idle < 360)
			to = poll_ival * 2;
		else
			to = poll_ival * 4;
		timeout.tv_sec = to / 1000000;
		timeout.tv_usec = to % 1000000;
		select(nfds, &fdset, NULL, &fdset, &timeout);

		/* If the user requested we quit, print some statistics. */
		if (exit_requested) {
			if (vflag && mjoules_used != 0)
				printf("total joules used: %u.%03u\n",
				    (u_int)(mjoules_used / 1000),
				    (int)mjoules_used % 1000);
			break;
		}

		/* Read the current AC status and record the mode. */
		acline_read();
		switch (acline_status) {
		case SRC_AC:
			mode = mode_ac;
			break;
		case SRC_BATTERY:
			mode = mode_battery;
			break;
		case SRC_UNKNOWN:
			mode = mode_none;
			break;
		default:
			errx(1, "invalid AC line status %d", acline_status);
		}

		/* Read the current frequency. */
		if (idle % 32 == 0) {
			if ((curfreq = get_freq()) == 0)
				continue;
			i = get_freq_id(curfreq, freqs, numfreqs);
		}
		idle++;
		if (vflag) {
			/* Keep a sum of all power actually used. */
			if (mwatts[i] != -1)
				mjoules_used +=
				    (mwatts[i] * (poll_ival / 1000)) / 1000;
		}

		/* Always switch to the lowest frequency in min mode. */
		if (mode == MODE_MIN) {
			freq = freqs[numfreqs - 1];
			if (curfreq != freq) {
				if (vflag) {
					printf("now operating on %s power; "
					    "changing frequency to %d MHz\n",
					    modes[acline_status], freq);
				}
				idle = 0;
				if (set_freq(freq) != 0) {
					warn("error setting CPU freq %d",
					    freq);
					continue;
				}
			}
			continue;
		}

		/* Always switch to the highest frequency in max mode. */
		if (mode == MODE_MAX) {
			freq = freqs[0];
			if (curfreq != freq) {
				if (vflag) {
					printf("now operating on %s power; "
					    "changing frequency to %d MHz\n",
					    modes[acline_status], freq);
				}
				idle = 0;
				if (set_freq(freq) != 0) {
					warn("error setting CPU freq %d",
					    freq);
					continue;
				}
			}
			continue;
		}

		/* Adaptive mode; get the current CPU usage times. */
		if (read_usage_times(&load)) {
			if (vflag)
				warn("read_usage_times() failed");
			continue;
		}

		if (mode == MODE_ADAPTIVE) {
			if (load > cpu_running_mark) {
				if (load > 95 || load > cpu_running_mark * 2)
					freq *= 2;
				else
					freq = freq * load / cpu_running_mark;
				if (freq > freqs[0])
					freq = freqs[0];
			} else if (load < cpu_idle_mark &&
			    curfreq * load < freqs[get_freq_id(
			    freq * 7 / 8, freqs, numfreqs)] *
			    cpu_running_mark) {
				freq = freq * 7 / 8;
				if (freq < freqs[numfreqs - 1])
					freq = freqs[numfreqs - 1];
			}
		} else { /* MODE_HIADAPTIVE */
			if (load > cpu_running_mark / 2) {
				if (load > 95 || load > cpu_running_mark)
					freq *= 4;
				else
					freq = freq * load * 2 / cpu_running_mark;
				if (freq > freqs[0] * 2)
					freq = freqs[0] * 2;
			} else if (load < cpu_idle_mark / 2 &&
			    curfreq * load < freqs[get_freq_id(
			    freq * 31 / 32, freqs, numfreqs)] *
			    cpu_running_mark / 2) {
				freq = freq * 31 / 32;
				if (freq < freqs[numfreqs - 1])
					freq = freqs[numfreqs - 1];
			}
		}
		if (vflag) {
		    printf("load %3d%%, current freq %4d MHz (%2d), wanted freq %4d MHz\n",
			load, curfreq, i, freq);
		}
		j = get_freq_id(freq, freqs, numfreqs);
		if (i != j) {
			if (vflag) {
				printf("changing clock"
				    " speed from %d MHz to %d MHz\n",
				    freqs[i], freqs[j]);
			}
			idle = 0;
			if (set_freq(freqs[j]))
				warn("error setting CPU frequency %d",
				    freqs[j]);
		}
	}
	if (set_freq(initfreq))
		warn("error setting CPU frequency %d", initfreq);
	free(freqs);
	free(mwatts);
	devd_close();
	if (!vflag)
		pidfile_remove(pfh);

	exit(0);
}
Exemplo n.º 20
0
static int
set_new_event( int t )
{
    int ptr;
    unsigned char *data;
    int count;
    int follower;
    __GETMDX;

    data = mdx->data;
    ptr = mdx->track[t].current_mml_ptr;
    count = 0;
    follower = 0;

#if 0
    if ( ptr+1 <= mdx->length && t>7 ) {
        fprintf(stderr,"%2d %2x %2x\n",t,data[ptr],data[ptr+1]);
        fflush(stderr);
    }
#endif

    if ( data[ptr] <= MDX_MAX_REST ) {  /* rest */
        note_off(t);
        count = data[ptr]+1;
        mdx->track[t].gate = count+1;
        follower=0;

    } else if ( data[ptr] <= MDX_MAX_NOTE ) { /* note */
        note_on( t, data[ptr]);
        count = data[ptr+1]+1;
        do_quantize( t, count );
        follower = 1;

    } else {
        switch ( data[ptr] ) {

        case MDX_SET_TEMPO:
            set_tempo( data[ptr+1] );
            follower = 1;
            break;

        case MDX_SET_OPM_REG:
            set_opm_reg( t, data[ptr+1], data[ptr+2] );
            follower = 2;
            break;

        case MDX_SET_VOICE:
            set_voice( t, data[ptr+1] );
            follower = 1;
            break;

        case MDX_SET_PHASE:
            set_phase( t, data[ptr+1] );
            follower = 1;
            break;

        case MDX_SET_VOLUME:
            set_volume( t, data[ptr+1] );
            follower = 1;
            break;

        case MDX_VOLUME_DEC:
            dec_volume( t );
            follower = 0;
            break;

        case MDX_VOLUME_INC:
            inc_volume( t );
            follower = 0;
            break;

        case MDX_SET_QUANTIZE:
            set_quantize( t, data[ptr+1] );
            follower = 1;
            break;

        case MDX_SET_KEYOFF:
            set_keyoff( t );
            follower = 0;
            break;

        case MDX_REPEAT_START:
            mdx->track[t].loop_counter[mdx->track[t].loop_depth] = data[ptr+1];
            if ( mdx->track[t].loop_depth < MDX_MAX_LOOP_DEPTH )
                mdx->track[t].loop_depth++;
            follower = 2;
            break;

        case MDX_REPEAT_END:
            if (--mdx->track[t].loop_counter[mdx->track[t].loop_depth-1] == 0 ) {
                if ( --mdx->track[t].loop_depth < 0 ) mdx->track[t].loop_depth=0;
            } else {
                if ( data[ptr+1] >= 0x80 ) {
                    ptr = ptr+2 - (0x10000-(data[ptr+1]*256 + data[ptr+2])) - 2;
                } else {
                    ptr = ptr+2 + data[ptr+1]*256 + data[ptr+2] - 2;
                }
            }
            follower = 2;
            break;

        case MDX_REPEAT_BREAK:
            if ( mdx->track[t].loop_counter[mdx->track[t].loop_depth-1] == 1 ) {
                if ( --mdx->track[t].loop_depth < 0 ) mdx->track[t].loop_depth=0;
                ptr = ptr+2 + data[ptr+1]*256 + data[ptr+2] -2 +2;
            }
            follower = 2;
            break;

        case MDX_SET_DETUNE:
            set_detune( t, data[ptr+1], data[ptr+2] );
            follower = 2;
            break;

        case MDX_SET_PORTAMENT:
            set_portament( t, data[ptr+1], data[ptr+2] );
            follower = 2;
            break;

        case MDX_DATA_END:
            if ( data[ptr+1] == 0x00 ) {
                count = -1;
                note_off(t);
                follower = 1;
            } else {
                ptr = ptr+2 - (0x10000-(data[ptr+1]*256 + data[ptr+2])) - 2;
                mdx->track[t].infinite_loop_times++;
                follower = 2;
            }
            break;

        case MDX_KEY_ON_DELAY:
            follower = 1;
            break;

        case MDX_SEND_SYNC:
            send_sync( data[ptr+1] );
            follower = 1;
            break;

        case MDX_RECV_SYNC:
            recv_sync( t );
            follower = 0;
            count = 1;
            break;

        case MDX_SET_FREQ:
            set_freq( t, data[ptr+1] );
            follower = 1;
            break;

        case MDX_SET_PLFO:
            if ( data[ptr+1] == 0x80 || data[ptr+1] == 0x81 ) {
                set_plfo_onoff( t, data[ptr+1]-0x80 );
                follower = 1;
            } else {
                set_plfo( t,
                          data[ptr+1], data[ptr+2], data[ptr+3],
                          data[ptr+4], data[ptr+5] );
                follower = 5;
            }
            break;

        case MDX_SET_ALFO:
            if ( data[ptr+1] == 0x80 || data[ptr+1] == 0x81 ) {
                set_alfo_onoff( t, data[ptr+1]-0x80 );
                follower = 1;
            } else {
                set_alfo( t,
                          data[ptr+1], data[ptr+2], data[ptr+3],
                          data[ptr+4], data[ptr+5] );
                follower = 5;
            }
            break;

        case MDX_SET_OPMLFO:
            if ( data[ptr+1] == 0x80 || data[ptr+1] == 0x81 ) {
                set_hlfo_onoff( t, data[ptr+1]-0x80 );
                follower = 1;
            } else {
                set_hlfo( t,
                          data[ptr+1], data[ptr+2], data[ptr+3],
                          data[ptr+4], data[ptr+5] );
                follower = 5;
            }
            break;

        case MDX_SET_LFO_DELAY:
            set_lfo_delay( t, data[ptr+1] );
            follower = 1;
            break;

        case MDX_SET_PCM8_MODE:
            follower = 0;
            break;

        case MDX_FADE_OUT:
            if ( data[ptr+1]==0x00 ) {
                follower = 1;
                set_fade_out( 5 );
            } else {
                follower = 2;
                set_fade_out( data[ptr+2] );
            }
            break;

        default:
            count = -1;
            break;
        }
    }

    ptr += 1+follower;
    mdx->track[t].current_mml_ptr = ptr;

    return count;
}
Exemplo n.º 21
0
static inline int radio_function(struct inode *inode, struct file *file,
				 unsigned int cmd, void *arg)
{
	struct video_device *dev = video_devdata(file);
	struct radio_device *card=dev->priv;

	switch(cmd) {
		case VIDIOC_QUERYCAP:
		{
			struct v4l2_capability *v = arg;
			memset(v,0,sizeof(*v));
			strlcpy(v->driver, "radio-maxiradio", sizeof (v->driver));
			strlcpy(v->card, "Maxi Radio FM2000 radio", sizeof (v->card));
			sprintf(v->bus_info,"ISA");
			v->version = RADIO_VERSION;
			v->capabilities = V4L2_CAP_TUNER;

			return 0;
		}
		case VIDIOC_G_TUNER:
		{
			struct v4l2_tuner *v = arg;

			if (v->index > 0)
				return -EINVAL;

			memset(v,0,sizeof(*v));
			strcpy(v->name, "FM");
			v->type = V4L2_TUNER_RADIO;

			v->rangelow=FREQ_LO;
			v->rangehigh=FREQ_HI;
			v->rxsubchans =V4L2_TUNER_SUB_MONO|V4L2_TUNER_SUB_STEREO;
			v->capability=V4L2_TUNER_CAP_LOW;
			if(get_stereo(card->io))
				v->audmode = V4L2_TUNER_MODE_STEREO;
			else
				v->audmode = V4L2_TUNER_MODE_MONO;
			v->signal=0xffff*get_tune(card->io);

			return 0;
		}
		case VIDIOC_S_TUNER:
		{
			struct v4l2_tuner *v = arg;

			if (v->index > 0)
				return -EINVAL;

			return 0;
		}
		case VIDIOC_S_FREQUENCY:
		{
			struct v4l2_frequency *f = arg;

			if (f->frequency < FREQ_LO || f->frequency > FREQ_HI)
				return -EINVAL;

			card->freq = f->frequency;
			set_freq(card->io, FREQ2BITS(card->freq));
			msleep(125);
			return 0;
		}
		case VIDIOC_G_FREQUENCY:
		{
			struct v4l2_frequency *f = arg;

			f->type = V4L2_TUNER_RADIO;
			f->frequency = card->freq;

			return 0;
		}
		case VIDIOC_QUERYCTRL:
		{
			struct v4l2_queryctrl *qc = arg;
			int i;

			for (i = 0; i < ARRAY_SIZE(radio_qctrl); i++) {
				if (qc->id && qc->id == radio_qctrl[i].id) {
					memcpy(qc, &(radio_qctrl[i]),
								sizeof(*qc));
					return (0);
				}
			}
			return -EINVAL;
		}
		case VIDIOC_G_CTRL:
		{
			struct v4l2_control *ctrl= arg;

			switch (ctrl->id) {
				case V4L2_CID_AUDIO_MUTE:
					ctrl->value=card->muted;
					return (0);
			}
			return -EINVAL;
		}
		case VIDIOC_S_CTRL:
		{
			struct v4l2_control *ctrl= arg;

			switch (ctrl->id) {
				case V4L2_CID_AUDIO_MUTE:
					card->muted = ctrl->value;
					if(card->muted)
						turn_power(card->io, 0);
					else
						set_freq(card->io, FREQ2BITS(card->freq));
					return 0;
			}
			return -EINVAL;
		}

		default:
			return v4l_compat_translate_ioctl(inode,file,cmd,arg,
							  radio_function);

	}
}
Exemplo n.º 22
0
void RadioMx146::setup()
{
  Wire.begin();   // Join the I2C bus as a master
  set_freq(RADIO_FREQUENCY); // Set the default frequency
  //set_freq(MX146_FREQUENCY_TESTING); // Set the testing frequency
}
Exemplo n.º 23
0
/*
 * loop_config - configure the loop filter
 *
 * LOCKCLOCK: The LOOP_DRIFTINIT and LOOP_DRIFTCOMP cases are no-ops.
 */
void
loop_config(
	int	item,
	double	freq
	)
{
	int i;

#ifdef DEBUG
	if (debug > 1)
		printf("loop_config: item %d freq %f\n", item, freq);
#endif
	switch (item) {

	/*
	 * We first assume the kernel supports the ntp_adjtime()
	 * syscall. If that syscall works, initialize the kernel time
	 * variables. Otherwise, continue leaving no harm behind.
	 */
	case LOOP_DRIFTINIT:
#ifndef LOCKCLOCK
#ifdef KERNEL_PLL
		if (mode_ntpdate)
			break;

		pll_control = 1;
		memset(&ntv, 0, sizeof(ntv));
		ntv.modes = MOD_BITS;
		ntv.status = STA_PLL;
		ntv.maxerror = MAXDISPERSE;
		ntv.esterror = MAXDISPERSE;
		ntv.constant = sys_poll;
#ifdef SIGSYS
		/*
		 * Use sigsetjmp() to save state and then call
		 * ntp_adjtime(); if it fails, then siglongjmp() is used
		 * to return control
		 */
		newsigsys.sa_handler = pll_trap;
		newsigsys.sa_flags = 0;
		if (sigaction(SIGSYS, &newsigsys, &sigsys)) {
			msyslog(LOG_ERR,
			    "sigaction() fails to save SIGSYS trap: %m");
			pll_control = 0;
		}
		if (sigsetjmp(env, 1) == 0)
			ntp_adjtime(&ntv);
		if ((sigaction(SIGSYS, &sigsys,
		    (struct sigaction *)NULL))) {
			msyslog(LOG_ERR,
			    "sigaction() fails to restore SIGSYS trap: %m");
			pll_control = 0;
		}
#else /* SIGSYS */
		ntp_adjtime(&ntv);
#endif /* SIGSYS */

		/*
		 * Save the result status and light up an external clock
		 * if available.
		 */
		pll_status = ntv.status;
		if (pll_control) {
#ifdef STA_NANO
			if (pll_status & STA_CLK)
				ext_enable = 1;
#endif /* STA_NANO */
			report_event(EVNT_KERN, NULL,
 		  	    "kernel time sync enabled");
		}
#endif /* KERNEL_PLL */
#endif /* LOCKCLOCK */
		break;

	/*
	 * Initialize the frequency. If the frequency file is missing or
	 * broken, set the initial frequency to zero and set the state
	 * to NSET. Otherwise, set the initial frequency to the given
	 * value and the state to FSET.
	 */
	case LOOP_DRIFTCOMP:
#ifndef LOCKCLOCK
		if (freq > NTP_MAXFREQ || freq < -NTP_MAXFREQ) {
			set_freq(0);
			rstclock(EVNT_NSET, 0);
		} else {
			set_freq(freq);
			rstclock(EVNT_FSET, 0);
		}
#endif /* LOCKCLOCK */
		break;

	/*
	 * Disable the kernel at shutdown. The microkernel just abandons
	 * ship. The nanokernel carefully cleans up so applications can
	 * see this. Note the last programmed offset and frequency are
	 * left in place.
	 */
	case LOOP_KERN_CLEAR:
#ifndef LOCKCLOCK
#ifdef KERNEL_PLL
		if (pll_control && kern_enable) {
			memset((char *)&ntv, 0, sizeof(ntv));
			ntv.modes = MOD_STATUS;
			ntv.status = STA_UNSYNC;
			ntp_adjtime(&ntv);
			report_event(EVNT_KERN, NULL,
 		  	    "kernel time sync disabledx");
		   }
#endif /* KERNEL_PLL */
#endif /* LOCKCLOCK */
		break;

	/*
	 * Tinker command variables for Ulrich Windl. Very dangerous.
	 */
	case LOOP_ALLAN:	/* Allan intercept (log2) (allan) */
		allan_xpt = (u_char)freq;
		break;

	case LOOP_CODEC:	/* audio codec frequency (codec) */
		clock_codec = freq / 1e6;
		break;
	
	case LOOP_PHI:		/* dispersion threshold (dispersion) */
		clock_phi = freq / 1e6;
		break;

	case LOOP_FREQ:		/* initial frequency (freq) */	
		set_freq(freq / 1e6);
		rstclock(EVNT_FSET, 0);
		break;

	case LOOP_HUFFPUFF:	/* huff-n'-puff length (huffpuff) */
		if (freq < HUFFPUFF)
			freq = HUFFPUFF;
		sys_hufflen = (int)(freq / HUFFPUFF);
		sys_huffpuff = (double *)emalloc(sizeof(double) *
		    sys_hufflen);
		for (i = 0; i < sys_hufflen; i++)
			sys_huffpuff[i] = 1e9;
		sys_mindly = 1e9;
		break;

	case LOOP_PANIC:	/* panic threshold (panic) */
		clock_panic = freq;
		break;

	case LOOP_MAX:		/* step threshold (step) */
		clock_max = freq;
		if (clock_max == 0 || clock_max > 0.5)
			kern_enable = 0;
		break;

	case LOOP_MINSTEP:	/* stepout threshold (stepout) */
		clock_minstep = freq; 
		break;

	case LOOP_LEAP:		/* not used */
	default:
		msyslog(LOG_NOTICE,
		    "loop_config: unsupported option %d", item);
	}
}
Exemplo n.º 24
0
static inline int radio_function(struct inode *inode, struct file *file,
				 unsigned int cmd, void *arg)
{
	struct video_device *dev = video_devdata(file);
	struct radio_device *card=dev->priv;

	switch(cmd) {
		case VIDIOCGCAP: {
			struct video_capability *v = arg;
			
			memset(v,0,sizeof(*v));
			strcpy(v->name, "Maxi Radio FM2000 radio");
			v->type=VID_TYPE_TUNER;
			v->channels=v->audios=1;
			return 0;
		}
		case VIDIOCGTUNER: {
			struct video_tuner *v = arg;
			
			if(v->tuner)
				return -EINVAL;
				
			card->stereo = 0xffff * get_stereo(card->io);
			card->tuned = 0xffff * get_tune(card->io);
			
			v->flags = VIDEO_TUNER_LOW | card->stereo;
			v->signal = card->tuned;
			
			strcpy(v->name, "FM");
			
			v->rangelow = FREQ_LO;
			v->rangehigh = FREQ_HI;
			v->mode = VIDEO_MODE_AUTO;
			
			return 0;
		}
		case VIDIOCSTUNER: {
			struct video_tuner *v = arg;
			if(v->tuner!=0)
				return -EINVAL;
			return 0;
		}
		case VIDIOCGFREQ: {
			unsigned long *freq = arg;
			
			*freq = card->freq;
			return 0;
		}
		case VIDIOCSFREQ: {
			unsigned long *freq = arg;
			
			if (*freq < FREQ_LO || *freq > FREQ_HI)
				return -EINVAL;
			card->freq = *freq;
			set_freq(card->io, FREQ2BITS(card->freq));
			msleep(125);
			return 0;
		}
		case VIDIOCGAUDIO: {	
			struct video_audio *v = arg;
			memset(v,0,sizeof(*v));
			strcpy(v->name, "Radio");
			v->flags=VIDEO_AUDIO_MUTABLE | card->muted;
			v->mode=VIDEO_SOUND_STEREO;
			return 0;		
		}
		
		case VIDIOCSAUDIO: {
			struct video_audio *v = arg;
			
			if(v->audio)
				return -EINVAL;
			card->muted = v->flags & VIDEO_AUDIO_MUTE;
			if(card->muted)
				turn_power(card->io, 0);
			else
				set_freq(card->io, FREQ2BITS(card->freq));
			return 0;
		}
		case VIDIOCGUNIT: {
			struct video_unit *v = arg;
			
			v->video=VIDEO_NO_UNIT;
			v->vbi=VIDEO_NO_UNIT;
			v->radio=dev->minor;
			v->audio=0;
			v->teletext=VIDEO_NO_UNIT;
			return 0;		
		}
		default: return -ENOIOCTLCMD;
	}
}
Exemplo n.º 25
0
static int v4l2_rx_start_func (void **data, int low_freq, int high_freq, int default_freq, int grid)
{
  char	*dev = DEFAULT_DEVICE;
  fm_v4l2_data* session;

  ALOGI("%s:\n", __FUNCTION__);
  ALOGI("low_freq %d, high_freq %d, default_freq %d, grid %d\n", low_freq, high_freq, default_freq, grid);

  session = malloc(sizeof(fm_v4l2_data));
  if (session== NULL){
      ALOGE("error on malloc");
      return -1;
  }

  memset(session, 0, sizeof(fm_v4l2_data));
  *data =  session;

  session->fd = open_dev(dev);
  if (session->fd < 0){
      ALOGE("error on open dev\n");
      return -1;
  }

  if (get_tun_radio_cap(session->fd) !=1) {
      ALOGE("error on check tunner radio capability");
      return -1;
  }

  session->vt.index=0;
  if ( get_v4l2_tuner(session->fd,  &session->vt) <0 ){
      ALOGE("error on get V4L tuner\n");
      return -1;
  }

  session->fact = get_fact(session->fd, &session->vt);
  if ( session->fact < 0) {
      ALOGE("error on get fact\n");
      return -1;
  }

  session->freq = get_proprietary_freq(default_freq, session->fact);
  session->low_freq =  get_proprietary_freq(low_freq,  session->fact);
  session->high_freq =  get_proprietary_freq(high_freq,  session->fact);
  session->grid = get_proprietary_freq(grid,  session->fact);
  session->threshold = DEFAULT_THRESHOLD;
  
  if (set_freq(session->fd, session->freq) < 0 ){
      ALOGE("error on set freq\n");
      return -1;
  }

  if (set_volume(session->fd, DEFAULT_VOLUME)<0){
      ALOGE("error on set volume\n");
      return -1;
  }

  if (set_mute(session->fd, MUTE_OFF) <0){
      ALOGE("error on mute\n");
      return -1;
  }

  return 0;
}
Exemplo n.º 26
0
/*******************************************************************************************
    Video capture routines

 - set input
 - setup_pixelformat
 - set_geometry

 - set_brightness 
 - set_chroma
 - set_contrast
 - set_channelset
 - set_channel
 - set_capture_mode

*/
static unsigned char *v4l_start(struct video_dev *viddev, int width, int height, 
                                unsigned short input, unsigned short norm, unsigned long freq)
{
    int dev_bktr = viddev->fd_bktr;
    struct sigaction act, old;
    //int dev_tunner = viddev->fd_tuner;
    /* to ensure that all device will be support the capture mode 
      _TODO_ : Autodected the best capture mode .
    */
    int dummy = 1;
//    int pixelformat = BSD_VIDFMT_I420;

    void *map;

    /* if we have choose the tuner is needed to setup the frequency */
    if ((viddev->tuner_device != NULL) && (input == IN_TV)) {
        if (!freq) {
            motion_log(LOG_ERR, 0, "%s: Not valid Frequency [%lu] for Source input [%i]",
                       __FUNCTION__, freq, input);
            return NULL;
        } else if (set_freq(viddev, freq) == -1) {
            motion_log(LOG_ERR, 0, "%s: Frequency [%lu] Source input [%i]", 
                       __FUNCTION__, freq, input);
            return NULL;
        }
    }
    
    /* FIXME if we set as input tuner , we need to set option for tuner not for bktr */

    if ((dummy = set_input(viddev, input)) == -1) {
        motion_log(LOG_ERR, 0, "%s: set input [%d]", __FUNCTION__, input);
        return NULL;
    }

    viddev->input = dummy;

    if ((dummy = set_input_format(viddev, norm)) == -1) {
        motion_log(LOG_ERR, 0, "%s: set input format [%d]", __FUNCTION__, norm);
        return NULL;
    }

    viddev->norm = dummy;

    if (set_geometry(viddev, width, height) == -1) {
        motion_log(LOG_ERR, 0, "%s: set geometry [%d]x[%d]", __FUNCTION__, width, height);
        return NULL;
    }
/*
    if (ioctl(dev_bktr, METEORSACTPIXFMT, &pixelformat) < 0) {
        motion_log(LOG_ERR, 1, "set encoding method BSD_VIDFMT_I420"); 
        return NULL;
    }


    NEEDED !? FIXME 

    if (setup_pixelformat(viddev) == -1)
        return NULL;
*/

    if (freq) {
        if (debug_level >= CAMERA_DEBUG)    
            motion_log(-1, 0, "%s: Frequency set (no implemented yet", __FUNCTION__);
    /*
     TODO missing implementation
        set_channelset(viddev);
        set_channel(viddev);
        if (set_freq (viddev, freq) == -1) {
            return NULL;
        }
    */
    }


    /* set capture mode and capture buffers */

    /* That is the buffer size for capture images ,
     so is dependent of color space of input format / FIXME */

    viddev->v4l_bufsize = (((width * height * 3 / 2)) * sizeof(unsigned char *));
    viddev->v4l_fmt = VIDEO_PALETTE_YUV420P;
    

    map = mmap((caddr_t)0, viddev->v4l_bufsize, PROT_READ|PROT_WRITE, MAP_SHARED, dev_bktr, (off_t)0);

    if (map == MAP_FAILED){
        motion_log(LOG_ERR, 1, "%s: mmap failed", __FUNCTION__);
        return NULL;
    }

    /* FIXME double buffer */ 
    if (0) {
        viddev->v4l_maxbuffer = 2;
        viddev->v4l_buffers[0] = map;
        viddev->v4l_buffers[1] = (unsigned char *)map + 0; /* 0 is not valid just a test */
        //viddev->v4l_buffers[1] = map+vid_buf.offsets[1];
    } else {
        viddev->v4l_buffers[0] = map;
        viddev->v4l_maxbuffer = 1;
    }

    viddev->v4l_curbuffer = 0;

    /* Clear the buffer */

    if (ioctl(dev_bktr, BT848SCBUF, &dummy) < 0) {
        motion_log(LOG_ERR, 1, "%s: BT848SCBUF", __FUNCTION__);
        return NULL;
    }

    /* signal handler to know when data is ready to be read() */
         
    memset(&act, 0, sizeof(act));
    sigemptyset(&act.sa_mask);
    act.sa_handler = catchsignal;
    sigaction(SIGUSR2, &act, &old);
     
    dummy = SIGUSR2;

    //viddev->capture_method = METEOR_CAP_CONTINOUS;
    //viddev->capture_method = METEOR_CAP_SINGLE;
    
    if ((viddev->capture_method == METEOR_CAP_CONTINOUS) && (ioctl(dev_bktr, METEORSSIGNAL, &dummy) < 0)) {
        motion_log(LOG_ERR, 1, "%s: METEORSSIGNAL", __FUNCTION__);
        motion_log(LOG_INFO, 0 , "%s: METEORSSIGNAL", __FUNCTION__);
        viddev->capture_method = METEOR_CAP_SINGLE;
        if (ioctl(dev_bktr, METEORCAPTUR, &viddev->capture_method) < 0) {
            motion_log(LOG_ERR, 1, "%s: METEORCAPTUR using single method "
                       "Error capturing", __FUNCTION__);
            motion_log(LOG_INFO, 0, "%s: METEORCAPTUR using single method "
                       "Error capturing", __FUNCTION__);
        }    
    } else {
        if (ioctl(dev_bktr, METEORCAPTUR, &viddev->capture_method) < 0) {
            viddev->capture_method = METEOR_CAP_SINGLE;
            if (ioctl(dev_bktr, METEORCAPTUR, &viddev->capture_method) < 0) {
                motion_log(LOG_ERR, 1, "%s: METEORCAPTUR using single method "
                           "Error capturing", __FUNCTION__);
                motion_log(LOG_INFO, 0, "%s: METEORCAPTUR using single method "
                           "Error capturing", __FUNCTION__);
            }    
        }    
    }            
        
    if (viddev->capture_method == METEOR_CAP_CONTINOUS)
        motion_log(LOG_INFO, 0, "%s: METEORCAPTUR METEOR_CAP_CONTINOUS", __FUNCTION__);    
    else        
        motion_log(LOG_INFO, 0, "%s: METEORCAPTUR METEOR_CAP_SINGLE", __FUNCTION__);
    
    // settle , sleep(1) replaced
    SLEEP(1, 0);

    /* FIXME*/
    switch (viddev->v4l_fmt) {
    case VIDEO_PALETTE_YUV420P:
        viddev->v4l_bufsize = (width * height * 3) / 2;
        break;
    case VIDEO_PALETTE_YUV422:
        viddev->v4l_bufsize = (width * height * 2);
        break;
    case VIDEO_PALETTE_RGB24:
        viddev->v4l_bufsize = (width * height * 3);
        break;
    case VIDEO_PALETTE_GREY:
        viddev->v4l_bufsize = width * height;
        break;
    }
    
    motion_log(LOG_INFO, 0, "HUE [%d]", get_hue(dev_bktr, &dummy));
    motion_log(LOG_INFO, 0, "SATURATION [%d]", get_saturation(dev_bktr, &dummy));
    motion_log(LOG_INFO, 0, "BRIGHTNESS [%d]", get_brightness(dev_bktr, &dummy));
    motion_log(LOG_INFO, 0, "CONTRAST [%d]", get_contrast(dev_bktr, &dummy));
    
    return map;
}
Exemplo n.º 27
0
int MeUsb::initHIDDevice()
{
  int irq, len, address;
  if(usbtype==USB1_0) set_freq(); //work on a lower freq, necessary for usb
  irq = get_desr(1);
#ifdef USB_DBG   
      Serial.print("get des irq: ");
      Serial.println(irq,HEX);
#endif
  if(irq==USB_INT_SUCCESS){
      len = rd_usb_data( RECV_BUFFER );
#ifdef USB_DBG   
      Serial.print("descr1 len: ");
      Serial.print(len,HEX);
      Serial.print(" type: ");
      Serial.println(p_dev_descr->bDescriptorType,HEX);
#endif
      irq = set_addr(2);
      if(irq==USB_INT_SUCCESS){
        irq = get_desr(2); // max buf 64byte, todo:config descr overflow
        if(irq==USB_INT_SUCCESS){
          len = rd_usb_data( RECV_BUFFER );
//#ifdef USB_DBG   
//          Serial.printf("descr2 len %d class %x subclass %x\r\n",len,p_cfg_descr->itf_descr.bInterfaceClass, p_cfg_descr->itf_descr.bInterfaceSubClass); // interface class should be 0x03 for HID
//          Serial.printf("num of ep %d\r\n",p_cfg_descr->itf_descr.bNumEndpoints);
//          Serial.printf("ep0 %x %x\r\n",p_cfg_descr->endp_descr[0].bLength, p_cfg_descr->endp_descr[0].bDescriptorType);
//#endif
          if(p_cfg_descr->endp_descr[0].bDescriptorType==0x21){ // skip hid des
            tmpEp = (PUSB_ENDP_DESCR)((char*)(&(p_cfg_descr->endp_descr[0]))+p_cfg_descr->endp_descr[0].bLength); // get the real ep position
          }
//#ifdef USB_DBG   
//          Serial.printf("endpoint %x %x\r\n",tmpEp->bEndpointAddress,tmpEp->bDescriptorType);
//#endif
          endp_out_addr=endp_in_addr=0;
          address =tmpEp->bEndpointAddress;  /* Address of First EndPoint */
          // actually we only care about the input end points
          if( address&0x80 ){
            endp_in_addr = address&0x0f;  /* Address of IN EndPoint */
          }else{  /* OUT EndPoint */
            endp_out_addr = address&0x0f;
            endp_out_size = p_cfg_descr->endp_descr[0].wMaxPacketSize;  /* 
            Length of Package for Received Data EndPoint */
            if( endp_out_size == 0 || endp_out_size > 64 )
              endp_out_size = 64;
          }
          // todo: some joystick with more than 2 node
          // just assume every thing is fine, bring the device up
          irq = set_config(p_cfg_descr->cfg_descr.bConfigurationvalue);
          if(irq==USB_INT_SUCCESS){
            USB_WR( CMD_SET_RETRY );  // set the retry times
            USB_WR( 0x25 );
            USB_WR( 0x85 );
            device_ready = true;
            return 1;
          }
        }
        
      }
  }
  return 0;
}
Exemplo n.º 28
0
int main(void) {
	// UDP Creation

    struct sockaddr_in si_me, si_other;

    int s, slen = sizeof(si_other) , recv_len;
    char buf[BUFLEN];
    char motor1_2, motor1_1,motor2_2, motor2_1,motor3_2, motor3_1,motor4_2, motor4_1,motor5_2, motor5_1,motor6_2, motor6_1;
    char motor1[3], motor2[3], motor3[3], motor4[3], motor5[3], motor6[3];

    //create a UDP socket
    if ((s=socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1)
    {
        die("socket");
    }

    // zero out the structure
    memset((char *) &si_me, 0, sizeof(si_me));

    si_me.sin_family = AF_INET;
    si_me.sin_port = htons(PORT);
    si_me.sin_addr.s_addr = htonl(INADDR_ANY);

    //bind socket to port
    if( bind(s , (struct sockaddr*)&si_me, sizeof(si_me) ) == -1)
    {
        die("bind");
    }

    //Set up pwms
    char freq[5];
    int i, motor_num;
	set_pwms();
	//Ask the user what the frequency should be
	printf("What should the frequency be? ");
	fflush(stdout);
	scanf("%s", freq);
	//Set all frequencies to the user input
	for(i='1';i<'7';i++){
			set_freq(i,freq);
	}
	//Activate the run file in each pwm folder
	for(i='1';i<'7';i++){
			set_run(i,"1");
	}
	//Set the duty percent to 50 for all pwms
	for(i='1';i<'7';i++){
			set_duty(i,"50");
	}
	while(1){

        //try to receive some data
        if ((recv_len = recvfrom(s, buf, BUFLEN, 0, (struct sockaddr *) &si_other, &slen)) == -1)
        {
            die("recvfrom()");
        }

        // Figure out the number of motors from first three bytes of the array received from UDP packet
        motor_num = buf[3];
        int motors[motor_num];
        // Create an array that has the duty percent for each motor in the elements
        for(i=0; i<motor_num; i++){
        	motors[i] = buf[i+4];
        	if(motors[i] > 100) motors[i] = motors[i] - 256; //Conversion for numbers that should be negative
        }
        fflush(stdout);

        //Change the percentages from -100-100 to 0-100 because that's the percentages the BeagleBone can do
        for(i=0; i<6; i++){
        	motors[i] = (motors[i] + 100)/2;
        }

        // The next bunch of if else statements convert the integer duty percent number into strings that the
        // Beaglebone can understand.  Each statement will go through the first and second digit of the integer
        // and then change them to ASCII code and put them into an array.
        if(motors[0] == 100){
        	motor1[0] = '1';
        	motor1[1] = '0';
        	motor1[2] = '0';
        	motor1[3] = '\0';
        }
        else {
            motor1_2 = motors[0]%10 + 0x30;
            motor1_1 = (motors[0]/10)%10 + 0x30;
            motor1[0] = '0';
            motor1[1] = motor1_1;
            motor1[2] = motor1_2;
            motor1[3] = '\0';
        }
        if(motors[1] == 100){
        	motor2[0] = '1';
        	motor2[1] = '0';
        	motor2[2] = '0';
            motor2[3] = '\0';
        }
        else {
            motor2_2 = motors[1]%10 + 0x30;
            motor2_1 = (motors[1]/10)%10 + 0x30;
            motor2[0] = '0';
            motor2[1] = motor2_1;
            motor2[2] = motor2_2;
            motor2[3] = '\0';
        }
        if(motors[2] == 100){
        	motor3[0] = '1';
        	motor3[1] = '0';
        	motor3[2] = '0';
            motor3[3] = '\0';
        }
        else {
            motor3_2 = motors[2]%10 + 0x30;
            motor3_1 = (motors[2]/10)%10 + 0x30;
            motor3[0] = '0';
            motor3[1] = motor3_1;
            motor3[2] = motor3_2;
            motor3[3] = '\0';
        }
        if(motors[3] == 100){
        	motor4[0] = '1';
        	motor4[1] = '0';
        	motor4[2] = '0';
        	motor4[3] = '\0';
        }
        else {
            motor4_2 = motors[3]%10 + 0x30;
            motor4_1 = (motors[3]/10)%10 + 0x30;
            motor4[0] = '0';
            motor4[1] = motor4_1;
            motor4[2] = motor4_2;
            motor4[3] = '\0';
        }
        if(motors[4] == 100){
        	motor5[0] = '1';
        	motor5[1] = '0';
        	motor5[2] = '0';
            motor5[3] = '\0';
        }
        else {
            motor5_2 = motors[4]%10 + 0x30;
            motor5_1 = (motors[4]/10)%10 + 0x30;
            motor5[0] = '0';
            motor5[1] = motor5_1;
            motor5[2] = motor5_2;
            motor5[3] = '\0';
        }
        if(motors[5] == 100){
        	motor6[0] = '1';
        	motor6[1] = '0';
        	motor6[2] = '0';
            motor6[3] = '\0';
        }
        else {
            motor6_2 = motors[5]%10 + 0x30;
            motor6_1 = (motors[5]/10)%10 + 0x30;
            motor6[0] = '0';
            motor6[1] = motor6_1;
            motor6[2] = motor6_2;
            motor6[3] = '\0';
        }

        // Print all the duty percents that were calculated
        printf("First Motor: %s\n", motor1);
        printf("Second Motor: %s\n", motor2);
        printf("Third Motor: %s\n", motor3);
        printf("Fourth Motor: %s\n", motor4);
        printf("Fifth Motor: %s\n", motor5);
        printf("Sixth Motor: %s\n\n", motor6);

        // Set the duty percent of each motor
    	set_duty('1', motor1);
    	set_duty('2', motor2);
    	set_duty('3', motor3);
    	set_duty('4', motor4);
    	set_duty('5', motor5);
    	set_duty('6', motor6);

	}

	close(s);
	return 0;
}