예제 #1
0
static void ledtrig_general_activity(struct ledtrig_t * trigger)
{
	struct ledtrig_general_pdata_t * pdat = (struct ledtrig_general_pdata_t *)trigger->priv;

	pdat->activity++;
	timer_start_now(&pdat->timer, ms_to_ktime(20));
}
예제 #2
0
static void ledtrig_heartbeat_init(struct ledtrig_t * trigger)
{
	struct ledtrig_heartbeat_data_t * dat = (struct ledtrig_heartbeat_data_t *)trigger->priv;

	if(dat)
	{
		dat->phase = 0;
		timer_init(&dat->timer, heartbeat_timer_function, trigger);
		timer_start_now(&dat->timer, ms_to_ktime(10));
	}
}
예제 #3
0
파일: clocksource.c 프로젝트: xboot/xboot
bool_t register_clocksource(struct device_t ** device, struct clocksource_t * cs)
{
	struct device_t * dev;
	irq_flags_t flags;

	if(!cs || !cs->name || !cs->read)
		return FALSE;

	dev = malloc(sizeof(struct device_t));
	if(!dev)
		return FALSE;

	cs->keeper.interval = clocksource_deferment(cs) >> 1;
	cs->keeper.last = clocksource_cycle(cs);
	cs->keeper.nsec = 0;
	seqlock_init(&cs->keeper.lock);
	timer_init(&cs->keeper.timer, clocksource_keeper_timer_function, cs);

	dev->name = strdup(cs->name);
	dev->type = DEVICE_TYPE_CLOCKSOURCE;
	dev->driver = NULL;
	dev->priv = cs;
	dev->kobj = kobj_alloc_directory(dev->name);
	kobj_add_regular(dev->kobj, "mult", clocksource_read_mult, NULL, cs);
	kobj_add_regular(dev->kobj, "shift", clocksource_read_shift, NULL, cs);
	kobj_add_regular(dev->kobj, "period", clocksource_read_period, NULL, cs);
	kobj_add_regular(dev->kobj, "deferment", clocksource_read_deferment, NULL, cs);
	kobj_add_regular(dev->kobj, "cycle", clocksource_read_cycle, NULL, cs);
	kobj_add_regular(dev->kobj, "time", clocksource_read_time, NULL, cs);

	if(!register_device(dev))
	{
		kobj_remove_self(dev->kobj);
		free(dev->name);
		free(dev);
		return FALSE;
	}

	if(__clocksource == &__cs_dummy)
	{
		spin_lock_irqsave(&__clocksource_lock, flags);
		__clocksource = cs;
		spin_unlock_irqrestore(&__clocksource_lock, flags);
	}
	timer_start_now(&cs->keeper.timer, ns_to_ktime(cs->keeper.interval));

	if(device)
		*device = dev;
	return TRUE;
}
예제 #4
0
파일: motor-gpio.c 프로젝트: xboot/xboot
static void motor_gpio_set(struct motor_t * m, int speed)
{
	struct motor_gpio_pdata_t * pdat = (struct motor_gpio_pdata_t *)m->priv;
	int restart = 0;

	if(pdat->speed != speed)
	{
		if(pdat->speed == 0)
			restart = 1;
		if(speed < -pdat->maxspeed)
			speed = -pdat->maxspeed;
		else if(speed > pdat->maxspeed)
			speed = pdat->maxspeed;
		pdat->duty = (s64_t)pdat->period * abs(speed) / pdat->maxspeed;
		pdat->speed = speed;
		if(restart != 0)
			timer_start_now(&pdat->timer, ns_to_ktime(pdat->duty));
	}
}
예제 #5
0
static void buzzer_gpio_beep(struct buzzer_t * buzzer, int frequency, int millisecond)
{
	struct buzzer_gpio_pdata_t * pdat = (struct buzzer_gpio_pdata_t *)buzzer->priv;
	struct beep_param_t * param;

	if((frequency == 0) && (millisecond == 0))
	{
		timer_cancel(&pdat->timer);
		queue_clear(pdat->beep, iteration_beep_param);
		buzzer_gpio_set(buzzer, 0);
		return;
	}

	param = malloc(sizeof(struct beep_param_t));
	if(!param)
		return;
	param->frequency = frequency;
	param->millisecond = millisecond;

	queue_push(pdat->beep, param);
	if(queue_avail(pdat->beep) == 1)
		timer_start_now(&pdat->timer, ms_to_ktime(1));
}
예제 #6
0
파일: key-gpio.c 프로젝트: kamejoko80/xboot
static void input_init(struct input_t * input)
{
	struct key_gpio_private_data_t * dat = (struct key_gpio_private_data_t *)input->priv;
	struct key_gpio_data_t * rdat = (struct key_gpio_data_t *)dat->rdat;
	int i;

	if(!dat)
		return;

	dat->state = malloc(rdat->nbutton * sizeof(int));
	if(!dat->state)
		return;

	for(i = 0; i < rdat->nbutton; i++)
	{
		gpio_set_pull(rdat->buttons[i].gpio, rdat->buttons[i].active_low ? GPIO_PULL_UP :GPIO_PULL_DOWN);
		gpio_direction_input(rdat->buttons[i].gpio);
		dat->state[i] = gpio_get_value(rdat->buttons[i].gpio);
	}

	timer_init(&dat->timer, key_gpio_timer_function, input);
	timer_start_now(&dat->timer, ms_to_ktime(100));
}