<div dir="ltr"><div dir="ltr">Hello again,<div><br></div><div>still have some troubles with post/wait binary semaphore sequence. Could someone suggest what is a right way when you're working with semaphore inside interrupts.</div><div><br></div><div>I have sys call via spidev which is waiting for the binary semaphore. Semaphore released inside the interrupt. In some cases after several transmission I'm getting fatal: RTEMS_FATAL_SOURCE_EXCEPTION. </div><div><br></div><div>I'll be really appreciate for any suggestions.</div><div><br></div><div>BRs, Yaroslav.</div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, 17 Apr 2019 at 16:25, Ярослав Лещинский <<a href="mailto:midniwalker@gmail.com">midniwalker@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr">Hello,<div><br></div><div>I wrote spidev driver for stm32l4 mcu.</div><div><br></div><div>spi_trasfer function looks like:</div><div><br></div><div><div>static int spi_transfer(</div><div> spi_bus *base,</div><div> const spi_ioc_transfer *msgs,</div><div> uint32_t msg_count)</div><div>{</div><div> struct stm32l4_spi_bus *bus = (struct stm32l4_spi_bus *)base;</div><div><br></div><div> SPI_TypeDef *spix = (SPI_TypeDef *)bus->driver.spix;</div><div> enum spi_major_num num = get_spi_major_number(spix);</div><div><br></div><div> bus->msg = &msgs[0];</div><div> spi_bus_table[num] = bus;</div><div> spi_bus_table[num]->msg_count = msg_count;</div><div> spi_bus_table[num]->messages_left = msg_count;</div><div><br></div><div> int msg_error = spi_setup_trasfer(</div><div> spi_bus_table[num],</div><div> spi_bus_table[num]->msg,</div><div> spi_bus_table[num]->messages_left);</div><div><br></div><div> rtems_binary_semaphore_wait(&bus->sem);</div><div><br></div><div> return (msg_error == 0)? 0 : -EINVAL;</div><div>}</div></div><div><br></div><div>Transmission proceeded via SPI IRQ + DMA IRQ. In DMA IRQ handler after dma successfully transmitted all data I'm using rtems_binary_semaphore_post for corresponding semaphore.</div><div><br></div><div><div> bool bus_is_broken = (bus == NULL) ||</div><div> (msg_count < bus->messages_left) ||</div><div> (msg_count == 0);</div><div> int ret = 0;</div><div><br></div><div> if(bus_is_broken == true)</div><div> {</div><div> return -EINVAL;</div><div> }</div><div><br></div><div> if(msgs->cs_change == true)</div><div> {</div><div> spi_css_deselect(&bus->driver);</div><div> }</div><div><br></div><div> if(bus->messages_left > 0)</div><div> {</div><div> const size_t msg_idx = msg_count - bus->messages_left;</div><div> ret = spi_do_transfer(bus, msgs, msg_idx);</div><div><br></div><div> bus->messages_left--;</div><div><br></div><div> if(ret != 0)</div><div> {</div><div> rtems_binary_semaphore_post(&bus->sem);</div><div><br></div><div> return ret;</div><div> }</div><div> }</div><div> else</div><div> {</div><div> rtems_binary_semaphore_post(&bus->sem);</div><div> }</div><div><br></div><div> return ret;</div></div><div><br></div><div>Currently I see that semaphore was successfully posted but control was not returned to spi_transfer.</div><div><br></div><div>As I know there are can be some issues with a context switching. Does rtems_binary_semaphore_post know about where control should be returned?</div><div><br></div><div><br></div><div>Thanks.</div><div><div><br></div>-- <br><div dir="ltr" class="gmail-m_-7159841897777405912gmail_signature"><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><span><div style="font-size:12.8px"><font face="verdana, sans-serif" color="#000000">--</font></div><div style="font-size:12.8px"><font face="verdana, sans-serif" color="#000000">Kind regards,</font></div><div style="font-size:12.8px"><font face="verdana, sans-serif" color="#000000"><b>Yaroslav Leshchinsky</b></font></div></span></div></div></div></div></div></div></div></div></div></div></div>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><span><div style="font-size:12.8px"><font face="verdana, sans-serif" color="#000000">--</font></div><div style="font-size:12.8px"><font face="verdana, sans-serif" color="#000000">Kind regards,</font></div><div style="font-size:12.8px"><font face="verdana, sans-serif" color="#000000"><b>Yaroslav Leshchinsky</b></font></div></span></div></div></div></div></div>