All of lore.kernel.org
 help / color / mirror / Atom feed
* spi_async not working, spi_sync working fine
@ 2015-06-19  9:06 Schrey, Moritz
  0 siblings, 0 replies; only message in thread
From: Schrey, Moritz @ 2015-06-19  9:06 UTC (permalink / raw)
  To: kernelnewbies

Dear All, 

I'm having trouble understanding the difference between spi_sync and spi_async: Theoretically, spi_sync waits for completion while spi_async provides completion callbacks. However, on my platform spi_async does not do anything!

I have the following code that is supposed to write a single byte. Using spi_sync works fine, calling the completion callback with spi_async also works. I just do not see anything on the connected oscilloscope screen. 

What am I missing?

Thanks in advance
Moritz



int lprf_set_WREN(void)
{
	int status, ret;
	int sync = 0;
	struct spi_message m;
	struct spi_transfer t;	
	u8 *buffer = kmalloc(sizeof(u8), GFP_KERNEL);
	memset(buffer, 0, sizeof(u8));
	
	buffer[0] = 0x06;	
	t.tx_buf = buffer;  
	t.rx_buf = NULL;
	printk(KERN_DEBUG "lprf: buffer=%p\n", buffer);
	t.len = 1;
	t.bits_per_word = 0;
	
	spi_message_init(&m);
	spi_message_add_tail(&t, &m);
	
	printk(KERN_DEBUG "lprf: lprf_set_WREN start\n");
	if (sync) {
		/* Variante A: sync */
		status = spi_sync(lp->spi, &m);	
		printk(KERN_DEBUG "lprf: lprf_set_WREN sync end. status=%d \n", status);	
	} else {
		/* Variante B: async */
		init_completion(&lp->state_complete);
		m.complete = lprf_mycomplete;
		m.context = &lp->state_complete;
		ret = spi_myvalidate(lp->spi, &m);
		if (ret) {
			printk(KERN_DEBUG "spi_myvalidate returned %d\n", ret);
			return ret;
		}
		status = spi_async_locked(lp->spi, &m);	

		if (status == 0) {
			wait_for_completion(&lp->state_complete);
			status = m.status;
		}
		printk(KERN_DEBUG "lprf: lprf_set_WREN async end status=%d m.status=%d\n", 
			status, m.status);
		m.context = NULL;
	}
	if (status)
		printk(KERN_ERR "lprf: spi_async failed at %s, %i\n", __FILE__, __LINE__);
	return status;
}

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2015-06-19  9:06 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-19  9:06 spi_async not working, spi_sync working fine Schrey, Moritz

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.