<div dir="ltr"><div><p class="MsoNormal" style="margin:0cm 0cm 0.0001pt">Hi Daniel,</p><p class="MsoNormal" style="margin:0cm 0cm 0.0001pt">It doesn't look like it..</p><p class="MsoNormal" style="margin:0cm 0cm 0.0001pt">The interrupt is invoked (via GPIO pin) only once and it's after the entire packet is completely received.<br></p></div><div><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><br></span></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jul 6, 2016 at 7:42 PM, Daniel. <span dir="ltr"><<a href="mailto:danielhilst@gmail.com" target="_blank">danielhilst@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi, isn't it possible that your hal_frame_read be called again prior<br>
rf_rx_completion_handler is called, and because of this calling<br>
spi_message_init on a spi_message that is in spi queue yet?<br>
<br>
2016-07-06 10:25 GMT-03:00 Moti Cohen <<a href="mailto:motic.mail@gmail.com">motic.mail@gmail.com</a>>:<br>
> Hi all,<br>
><br>
><br>
><br>
> I'm trying to write a kernel device driver for a Freescale imx6 processor<br>
> based board.<br>
><br>
> This driver is using spi to communicate with a radio module (using linux<br>
> spi.c).<br>
><br>
> I managed to wr/rd from the module, however once I'm trying to read more<br>
> than 64 bytes I'm getting coruppted data. here are some details:<br>
><br>
><br>
><br>
><br>
> The SPI reading process goes as follows:<br>
><br>
> 1. Interrupt function is invoked from SPI device via dedicated GPIO<br>
> line.<br>
><br>
> 2. The interrupt function performs asynchronous SPI read in the<br>
> following order:<br>
><br>
> 2.1 radio_trx_end_callback is called, as it is the registered call back<br>
> function.<br>
><br>
> 2.2 radio_trx_end_callback calls hal_frame_read function which prepares<br>
> spi_message and spi_transfer structures and fill them with relevant data:<br>
> spi_device , data tx, transfer len , complete handler , …<br>
><br>
> 3. The read itself is done by calling to function spi_async<br>
><br>
> 4. The completion handler function is called and prints the read<br>
> message, but trying to read more than 64 bytes in one transaction causes the<br>
> read data to be corrupted.<br>
><br>
> Any idea why am I seeing this behavior ?<br>
><br>
> Is there (in Linux) any definition for the size to be read via the SPI ?<br>
><br>
> The relevant variables and functions can be seen below:<br>
><br>
> Thanks in advance for helping..<br>
><br>
> __________________________<br>
><br>
> uint8_t rx_buf[200];<br>
><br>
> uint8_t reg[200] = {HAL_TRX_CMD_FR, 0xff, 0xff};<br>
><br>
> struct spi_transfer transfer;<br>
><br>
> struct spi_message spi_msg;<br>
><br>
><br>
><br>
> // interrupt function<br>
><br>
> //-----------------------------------------------------------------------------------------------------------------------<br>
><br>
> static irq_handler_t radio_trx_end_callback(unsigned int irq, void *dev_id,<br>
> struct pt_regs *regs)<br>
><br>
> {<br>
><br>
> hal_frame_read(irq, dev_id);<br>
><br>
> return (irq_handler_t) IRQ_HANDLED; // Announce that the IRQ has<br>
> been handled correctly<br>
><br>
> }<br>
><br>
><br>
><br>
> //read function<br>
><br>
> //-----------------------------------------------------------------------------------------------------------------------<br>
><br>
> void hal_frame_read(unsigned int irq, void *dev_id)<br>
><br>
> {<br>
><br>
> int status;<br>
><br>
> spi_device->irq = irq;<br>
><br>
> spi_message_init(&spi_msg);<br>
><br>
> spi_msg.spi = spi_device;<br>
><br>
> spi_msg.complete = rf_rx_completion_handler;<br>
><br>
> spi_msg.context = NULL;<br>
><br>
> memset((uint8_t*)&transfer, 0, sizeof(transfer));<br>
><br>
><br>
><br>
> memset(rx_buf, 0xFF, sizeof(rx_buf));<br>
><br>
> memset(reg, 0xFF, sizeof(reg));<br>
><br>
> reg[0] = HAL_TRX_CMD_FR;<br>
><br>
> transfer.tx_buf = reg;<br>
><br>
> transfer.len =64;<br>
><br>
> transfer.rx_buf = rx_buf;<br>
><br>
> spi_message_add_tail(&transfer, &spi_msg);<br>
><br>
><br>
><br>
> memset(rx_buf, 0x0, sizeof(rx_buf));<br>
><br>
> status = spi_async(spi_device, &spi_msg);<br>
><br>
> return;<br>
><br>
> }<br>
><br>
><br>
><br>
> //read completion handler<br>
><br>
> //-----------------------------------------------------------------------------------------------------------------------<br>
><br>
> static void rf_rx_completion_handler(void *arg)<br>
><br>
> {<br>
><br>
> int ii;<br>
><br>
><br>
><br>
> //print the received message<br>
><br>
> printk("\npure message: rx_buf [1]-2=%02X\n ", rx_buf [1]-2);<br>
><br>
> for (ii=0; ii< rx_buf [1]-2; ii++)<br>
><br>
> printk("%02X ", rx_buf [2+ii]);<br>
><br>
><br>
><br>
><br>
><br>
> printk("\nframe len=%X actual len=%X<br>
> status=%i\n",spi_msg.frame_length, spi_msg.actual_length, spi_msg.status);<br>
><br>
><br>
><br>
> send_up_rf_event_to_workque(TRX_END_EVENT);<br>
><br>
> }<br>
><br>
><br>
> _______________________________________________<br>
> Kernelnewbies mailing list<br>
> <a href="mailto:Kernelnewbies@kernelnewbies.org">Kernelnewbies@kernelnewbies.org</a><br>
> <a href="http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies" rel="noreferrer" target="_blank">http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies</a><br>
><br>
<span class="HOEnZb"><font color="#888888"><br>
<br>
<br>
--<br>
"Do or do not. There is no try"<br>
Yoda Master<br>
</font></span></blockquote></div><br></div>