<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&#39;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&#39;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">&lt;<a href="mailto:danielhilst@gmail.com" target="_blank">danielhilst@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi, isn&#39;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 &lt;<a href="mailto:motic.mail@gmail.com">motic.mail@gmail.com</a>&gt;:<br>
&gt; Hi all,<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; I&#39;m trying to write a kernel device driver for a Freescale imx6 processor<br>
&gt; based board.<br>
&gt;<br>
&gt; This driver is using spi to communicate with a radio module (using linux<br>
&gt; spi.c).<br>
&gt;<br>
&gt; I managed to wr/rd from the module, however once I&#39;m trying to read more<br>
&gt; than 64 bytes I&#39;m getting coruppted data. here are some details:<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; The SPI reading process goes as follows:<br>
&gt;<br>
&gt; 1.      Interrupt function is invoked from SPI device via dedicated GPIO<br>
&gt; line.<br>
&gt;<br>
&gt; 2.       The interrupt function performs asynchronous SPI read in the<br>
&gt; following order:<br>
&gt;<br>
&gt; 2.1   radio_trx_end_callback is called, as it is the registered call back<br>
&gt; function.<br>
&gt;<br>
&gt; 2.2   radio_trx_end_callback calls hal_frame_read function which prepares<br>
&gt; spi_message and spi_transfer structures and fill them with relevant data:<br>
&gt; spi_device , data tx, transfer len , complete handler , …<br>
&gt;<br>
&gt; 3.      The read itself  is done by calling to function spi_async<br>
&gt;<br>
&gt; 4.      The completion handler function is called and prints the read<br>
&gt; message, but trying to read more than 64 bytes in one transaction causes the<br>
&gt; read data to be corrupted.<br>
&gt;<br>
&gt; Any idea why am I seeing this behavior ?<br>
&gt;<br>
&gt; Is there (in Linux) any definition for the size to be read via the SPI ?<br>
&gt;<br>
&gt; The relevant variables and functions can be seen below:<br>
&gt;<br>
&gt; Thanks in advance for helping..<br>
&gt;<br>
&gt; __________________________<br>
&gt;<br>
&gt; uint8_t rx_buf[200];<br>
&gt;<br>
&gt; uint8_t reg[200] = {HAL_TRX_CMD_FR, 0xff, 0xff};<br>
&gt;<br>
&gt; struct spi_transfer transfer;<br>
&gt;<br>
&gt; struct spi_message  spi_msg;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; // interrupt function<br>
&gt;<br>
&gt; //-----------------------------------------------------------------------------------------------------------------------<br>
&gt;<br>
&gt; static irq_handler_t radio_trx_end_callback(unsigned int irq, void *dev_id,<br>
&gt; struct pt_regs *regs)<br>
&gt;<br>
&gt; {<br>
&gt;<br>
&gt;     hal_frame_read(irq, dev_id);<br>
&gt;<br>
&gt;     return (irq_handler_t) IRQ_HANDLED;      // Announce that the IRQ has<br>
&gt; been handled correctly<br>
&gt;<br>
&gt; }<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; //read function<br>
&gt;<br>
&gt; //-----------------------------------------------------------------------------------------------------------------------<br>
&gt;<br>
&gt; void hal_frame_read(unsigned int irq, void *dev_id)<br>
&gt;<br>
&gt; {<br>
&gt;<br>
&gt;         int status;<br>
&gt;<br>
&gt;         spi_device-&gt;irq = irq;<br>
&gt;<br>
&gt;         spi_message_init(&amp;spi_msg);<br>
&gt;<br>
&gt;         spi_msg.spi = spi_device;<br>
&gt;<br>
&gt;         spi_msg.complete = rf_rx_completion_handler;<br>
&gt;<br>
&gt;         spi_msg.context = NULL;<br>
&gt;<br>
&gt;         memset((uint8_t*)&amp;transfer, 0, sizeof(transfer));<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;         memset(rx_buf, 0xFF, sizeof(rx_buf));<br>
&gt;<br>
&gt;         memset(reg, 0xFF, sizeof(reg));<br>
&gt;<br>
&gt;         reg[0] = HAL_TRX_CMD_FR;<br>
&gt;<br>
&gt;         transfer.tx_buf = reg;<br>
&gt;<br>
&gt;         transfer.len =64;<br>
&gt;<br>
&gt;         transfer.rx_buf = rx_buf;<br>
&gt;<br>
&gt;         spi_message_add_tail(&amp;transfer, &amp;spi_msg);<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;         memset(rx_buf, 0x0, sizeof(rx_buf));<br>
&gt;<br>
&gt;         status = spi_async(spi_device, &amp;spi_msg);<br>
&gt;<br>
&gt;     return;<br>
&gt;<br>
&gt; }<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; //read completion handler<br>
&gt;<br>
&gt; //-----------------------------------------------------------------------------------------------------------------------<br>
&gt;<br>
&gt; static void rf_rx_completion_handler(void *arg)<br>
&gt;<br>
&gt; {<br>
&gt;<br>
&gt;         int ii;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; //print the received message<br>
&gt;<br>
&gt; printk(&quot;\npure message: rx_buf [1]-2=%02X\n      &quot;, rx_buf [1]-2);<br>
&gt;<br>
&gt;         for (ii=0; ii&lt; rx_buf [1]-2; ii++)<br>
&gt;<br>
&gt;                         printk(&quot;%02X &quot;, rx_buf [2+ii]);<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;         printk(&quot;\nframe len=%X actual len=%X<br>
&gt; status=%i\n&quot;,spi_msg.frame_length, spi_msg.actual_length, spi_msg.status);<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;         send_up_rf_event_to_workque(TRX_END_EVENT);<br>
&gt;<br>
&gt; }<br>
&gt;<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; Kernelnewbies mailing list<br>
&gt; <a href="mailto:Kernelnewbies@kernelnewbies.org">Kernelnewbies@kernelnewbies.org</a><br>
&gt; <a href="http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies" rel="noreferrer" target="_blank">http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies</a><br>
&gt;<br>
<span class="HOEnZb"><font color="#888888"><br>
<br>
<br>
--<br>
&quot;Do or do not. There is no try&quot;<br>
  Yoda Master<br>
</font></span></blockquote></div><br></div>