Skip to contentSkip to conversation

Interrupt Handling and sleep/wake_up

Newbie Christian Vogel 1 participant 1 message Sep 22, 2001

lore
Share & tools
lore
#0 lore raw

Hi,

-- Warning, newbie qeustion! --

currently I'm trying to write a very simple driver for the NI-GPIB-PCII card and I'm mostly copying what was linux-gpib a long time ago.

Why am I writing to this list? I think I miss some obvious solution to a problem. The problem lies within my handling of interrupts, let my try a simplified example:

The board signals arrival of new data, it's ability to accept new data or errors via the interrupt. I want my program to sleep until enough data has been accepted or an error has occured.

Unfortunately on errors the interrupt hits just before I call sleep_on_timeout() and because it's the only interrupt in this case that's being generated I have to wait until sleep_on_timeout() timeout's.

The old driver mostly uses

	while(!condition && !i++>threshold)
		udelay()

which I would like to avoid.

What would be the preferred way of doing this and what am I missing?

Some simple pseudocode follows to illustrate my point: bdIrq is the interrupt-service-routine, bdDoSomething is called via device->file-operations->read/write->... and wants to fetch something from the card or write to it.

void bdIrq(int irq,void *data, struct pt_regs *regs){
	query_board_for_status();
	if( board_has_data_available )
		readbuf[readcounter++]=inb(data_port);
	if( board_can_accept_data )
		outb(wrbuf[writecounter++],data_port);
	if( board_has_error_condition_set )
		board_has_error = 1;
	if( buffer_full_or_end_of_data || board_has_error )
		wake_up_interruptible(&irq_wqueue);
}
void bdDoSomething(){
	setup_buffers_for_interrupt_routing();
	tell_board_to_start_reading_or_writing();
	/***** BOARD THROWS ITS INTERRUPTS HERE!!! *****/
	interruptible_sleep_on_timeout(&irq_wqueue,PCIIA_SLEEP_TIMEOUT);
}

Chris

Signature · 1 line
Is it true that cannibals won't eat clowns because they taste funny?