Пример #1
0
void h3600_battery_read_status(unsigned long data) {

	if (++data % 2) 
		h3600_micro_tx_msg(0x09,0,NULL);
	else 
		h3600_micro_tx_msg(0x06,0,NULL);

	batt_timer.expires += BATT_PERIOD;
	batt_timer.data = data;

	add_timer(&batt_timer);
}
Пример #2
0
static void micro_set_bl_intensity(int intensity)
{
	unsigned char data[3];

	//printk(KERN_ERR "h3600_micro : micro backlight send %d %d\n",micro_backlight_power,micro_backlight_brightness);
	data[0] = 0x01;
	data[1] = intensity > 0 ? 1 : 0;
	data[2] = intensity;
	h3600_micro_tx_msg(0x0D,3,data);
}
Пример #3
0
static int h3600_micro_request( int id, int len, unsigned char *data, void *user_data )
{
	unsigned long   timeout;
	int           result = 0;
	unsigned long start_time = jiffies;
	struct h3600_message_dispatch volatile *d = &g_handlers[id];

	if ( in_interrupt() ) {
		printk("%s: trying to execute id=%d in interrupt context\n", __FUNCTION__,id);
		return -ERESTARTSYS;  /* TODO: is this a good error value? */
	}

	if ( down_interruptible((struct semaphore *)&g_txdev.lock) )
		return -ERESTARTSYS;

	/* Send data stream */
	if (0) {
		int i;
		printk("%s: id=%d len=%d ", __FUNCTION__,id,len);
		for ( i = 0 ; i < len ; i++ )
			printk("0x%02x ", data[i]);
		printk("\n");
	}

	timeout = 100 * HZ / 1000;    /* 100 milliseconds (empirically derived) */
	/* Store ID and result pointer */
	g_txdev.id        = id;
	g_txdev.user_data = user_data;
	atomic_set(&(d->status), MICRO_MSG_WAITING);

	result = h3600_micro_tx_msg( id, len, data );
	if ( result )
		return result;

	if(atomic_read(&(d->status)) == MICRO_MSG_WAITING)
	{
		timeout = interruptible_sleep_on_timeout((wait_queue_head_t *)&(d->waitq), timeout);
		if(timeout)
		{
			int status = atomic_read(&(d->status));
			if(status != MICRO_MSG_SUCCESS)
			{
				if(status == MICRO_MSG_WAITING)
				{
					/* we were signalled */
					result = -EAGAIN;
				}
				else if(status == MICRO_MSG_ERROR)
				{
					printk(KERN_INFO "%s: an uknown error occured waiting for ACK for message id %6d\n", __FUNCTION__, id);
					result = -ENODATA;
				}
			}
		}
		else
		{
			/* we timed out */
			g_statistics.timeouts++;
			g_statistics.msg[id].timeouts++;
			result = -ETIME;
		}
	}
		
	g_txdev.user_data = NULL;
	up((struct semaphore *)&g_txdev.lock);

	g_statistics.msg[id].total_ack_time += (jiffies - start_time);
	return result;
}