<div dir="ltr"><p class="MsoNormal" style="direction:ltr"><span style="font-size:9.5pt;font-family:Arial,sans-serif;background-image:initial;background-repeat:initial">Hi all,</span><span style="font-size:12pt;font-family:"Times New Roman",serif"></span></p>
<p class="MsoNormal" style="direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:9.5pt;font-family:Arial,sans-serif"> </span></p>
<p class="MsoNormal" style="direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:9.5pt;font-family:Arial,sans-serif">I'm trying to write a kernel device driver for a Freescale imx6
processor based board.</span></p>
<p class="MsoNormal" style="direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:9.5pt;font-family:Arial,sans-serif">This driver is using spi to communicate with a radio module
(using linux spi.c).</span></p>
<p class="MsoNormal" style="direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:9.5pt;font-family:Arial,sans-serif">I managed to wr/rd from the module, however once I'm trying to
read more than 64 bytes I'm getting coruppted data. here are some details:</span></p>
<p class="MsoNormal" style="direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:9.5pt;font-family:Arial,sans-serif"> </span></p>
<p class="MsoNormal" style="margin-bottom:12pt;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:9.5pt;font-family:Arial,sans-serif"><br>
The SPI reading process goes as follows:<br>
<br>
1. Interrupt function is invoked from SPI device via
dedicated GPIO line.<br>
<br>
2. The interrupt function performs asynchronous SPI
read in the following order:<br>
<br>
2.1 radio_trx_end_callback is called, as it is the registered call
back function.<br>
<br>
2.2 radio_trx_end_callback calls hal_frame_read function
which prepares spi_message and spi_transfer structures and fill them
with relevant data: 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 message, but trying to read more than 64 bytes in one transaction
causes the 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>
__________________________</span></p>
<p class="MsoNormal" style="margin-left:18pt;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:"Times New Roman",serif">uint8_t rx_buf[200];</span></p>
<p class="MsoNormal" style="margin-left:18pt;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:"Times New Roman",serif">uint8_t reg[200] = {HAL_TRX_CMD_FR,
0xff, 0xff};</span></p>
<p class="MsoNormal" style="margin-left:18pt;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:"Times New Roman",serif">struct spi_transfer transfer;</span></p>
<p class="MsoNormal" style="margin-left:18pt;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:"Times New Roman",serif">struct spi_message spi_msg;</span></p>
<p class="MsoNormal" style="margin-left:18pt;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:"Times New Roman",serif"> </span></p>
<p class="MsoNormal" style="margin-left:18pt;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:"Times New Roman",serif">// interrupt function</span></p>
<p class="MsoNormal" style="margin-left:18pt;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:"Times New Roman",serif">//-----------------------------------------------------------------------------------------------------------------------</span></p>
<p class="MsoNormal" style="margin-left:18pt;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:"Times New Roman",serif">static irq_handler_t
radio_trx_end_callback(unsigned int irq, void *dev_id, struct pt_regs *regs)</span></p>
<p class="MsoNormal" style="margin-left:18pt;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:"Times New Roman",serif">{</span></p>
<p class="MsoNormal" style="margin-left:18pt;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:"Times New Roman",serif"> hal_frame_read(irq,
dev_id);</span></p>
<p class="MsoNormal" style="margin-left:18pt;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:"Times New Roman",serif"> return
(irq_handler_t) IRQ_HANDLED; // Announce that the
IRQ has been handled correctly</span></p>
<p class="MsoNormal" style="margin-left:18pt;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:"Times New Roman",serif">}</span></p>
<p class="MsoNormal" style="margin-left:18pt;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:"Times New Roman",serif"> </span></p>
<p class="MsoNormal" style="margin-left:18pt;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:"Times New Roman",serif">//read function</span></p>
<p class="MsoNormal" style="margin-left:18pt;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:"Times New Roman",serif">//-----------------------------------------------------------------------------------------------------------------------</span></p>
<p class="MsoNormal" style="margin-left:18pt;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:"Times New Roman",serif">void hal_frame_read(unsigned int irq,
void *dev_id)</span></p>
<p class="MsoNormal" style="margin-left:18pt;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:"Times New Roman",serif">{</span></p>
<p class="MsoNormal" style="margin-left:18pt;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:"Times New Roman",serif">
int status;</span></p>
<p class="MsoNormal" style="margin-left:18pt;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:"Times New Roman",serif">
spi_device->irq = irq;</span></p>
<p class="MsoNormal" style="margin-left:18pt;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:"Times New Roman",serif">
spi_message_init(&spi_msg);</span></p>
<p class="MsoNormal" style="margin-left:18pt;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:"Times New Roman",serif">
spi_msg.spi = spi_device;</span></p>
<p class="MsoNormal" style="margin-left:18pt;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:"Times New Roman",serif">
spi_msg.complete = rf_rx_completion_handler;</span></p>
<p class="MsoNormal" style="margin-left:18pt;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:"Times New Roman",serif">
spi_msg.context = NULL;</span></p>
<p class="MsoNormal" style="margin-left:18pt;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:"Times New Roman",serif">
memset((uint8_t*)&transfer, 0, sizeof(transfer));</span></p>
<p class="MsoNormal" style="direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:"Times New Roman",serif"> </span></p>
<p class="MsoNormal" style="margin-left:18pt;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:"Times New Roman",serif">
memset(rx_buf, 0xFF, sizeof(rx_buf));</span></p>
<p class="MsoNormal" style="margin-left:18pt;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:"Times New Roman",serif">
memset(reg, 0xFF, sizeof(reg));</span></p>
<p class="MsoNormal" style="margin-left:18pt;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:"Times New Roman",serif">
reg[0] = HAL_TRX_CMD_FR;</span></p>
<p class="MsoNormal" style="margin-left:18pt;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:"Times New Roman",serif">
transfer.tx_buf = reg;</span></p>
<p class="MsoNormal" style="margin-left:18pt;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:"Times New Roman",serif">
transfer.len =64;</span></p>
<p class="MsoNormal" style="margin-left:18pt;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:"Times New Roman",serif">
transfer.rx_buf = rx_buf;</span></p>
<p class="MsoNormal" style="margin-left:18pt;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:"Times New Roman",serif">
spi_message_add_tail(&transfer, &spi_msg);</span></p>
<p class="MsoNormal" style="margin-left:18pt;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:"Times New Roman",serif"> </span></p>
<p class="MsoNormal" style="margin-left:18pt;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:"Times New Roman",serif">
memset(rx_buf, 0x0, sizeof(rx_buf));</span></p>
<p class="MsoNormal" style="margin-left:18pt;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:"Times New Roman",serif">
status = spi_async(spi_device, &spi_msg);</span></p>
<p class="MsoNormal" style="margin-left:18pt;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:"Times New Roman",serif"> return;</span></p>
<p class="MsoNormal" style="margin-left:18pt;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:"Times New Roman",serif">}</span></p>
<p class="MsoNormal" style="margin-left:18pt;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:"Times New Roman",serif"> </span></p>
<p class="MsoNormal" style="margin-left:18pt;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:"Times New Roman",serif">//read completion handler</span></p>
<p class="MsoNormal" style="margin-left:18pt;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:"Times New Roman",serif">//-----------------------------------------------------------------------------------------------------------------------</span></p>
<p class="MsoNormal" style="margin-left:18pt;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:"Times New Roman",serif">static void
rf_rx_completion_handler(void *arg)</span></p>
<p class="MsoNormal" style="margin-left:18pt;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:"Times New Roman",serif">{</span></p>
<p class="MsoNormal" style="margin-left:18pt;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:"Times New Roman",serif">
int ii;</span></p>
<p class="MsoNormal" style="margin-left:18pt;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:"Times New Roman",serif"> </span></p>
<p class="MsoNormal" style="margin-left:18pt;text-indent:18pt;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:"Times New Roman",serif">//print the received message</span></p>
<p class="MsoNormal" style="margin-left:18pt;text-indent:18pt;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:"Times New Roman",serif">printk("\npure message:
rx_buf [1]-2=%02X\n ", rx_buf [1]-2);</span></p>
<p class="MsoNormal" style="margin-left:18pt;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:"Times New Roman",serif">
for (ii=0; ii< rx_buf [1]-2; ii++)</span></p>
<p class="MsoNormal" style="margin-left:18pt;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:"Times New Roman",serif">
printk("%02X ", rx_buf [2+ii]);</span></p>
<p class="MsoNormal" style="margin-left:18pt;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:"Times New Roman",serif"> </span></p>
<p class="MsoNormal" style="margin-left:18pt;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:"Times New Roman",serif"> </span></p>
<p class="MsoNormal" style="margin-left:18pt;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:"Times New Roman",serif">
printk("\nframe len=%X actual len=%X
status=%i\n",spi_msg.frame_length, spi_msg.actual_length, spi_msg.status);</span></p>
<p class="MsoNormal" style="margin-left:18pt;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:"Times New Roman",serif"> </span></p>
<p class="MsoNormal" style="margin-left:18pt;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:"Times New Roman",serif">
send_up_rf_event_to_workque(TRX_END_EVENT);</span></p>
<p class="MsoNormal" style="margin-left:18pt;direction:ltr;background-image:initial;background-repeat:initial"><span style="font-size:12pt;font-family:"Times New Roman",serif">}</span></p></div>