spi_async not working, spi_sync working fine

Schrey, Moritz moritz.schrey at ias.rwth-aachen.de
Fri Jun 19 05:06:57 EDT 2015


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;
}



More information about the Kernelnewbies mailing list