rtems_binary_semaphore_post from IRQ handler
Ярослав Лещинский
midniwalker at gmail.com
Sun May 5 15:55:56 UTC 2019
Hello again,
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.
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.
I'll be really appreciate for any suggestions.
BRs, Yaroslav.
On Wed, 17 Apr 2019 at 16:25, Ярослав Лещинский <midniwalker at gmail.com>
wrote:
> Hello,
>
> I wrote spidev driver for stm32l4 mcu.
>
> spi_trasfer function looks like:
>
> static int spi_transfer(
> spi_bus *base,
> const spi_ioc_transfer *msgs,
> uint32_t msg_count)
> {
> struct stm32l4_spi_bus *bus = (struct stm32l4_spi_bus *)base;
>
> SPI_TypeDef *spix = (SPI_TypeDef *)bus->driver.spix;
> enum spi_major_num num = get_spi_major_number(spix);
>
> bus->msg = &msgs[0];
> spi_bus_table[num] = bus;
> spi_bus_table[num]->msg_count = msg_count;
> spi_bus_table[num]->messages_left = msg_count;
>
> int msg_error = spi_setup_trasfer(
> spi_bus_table[num],
> spi_bus_table[num]->msg,
> spi_bus_table[num]->messages_left);
>
> rtems_binary_semaphore_wait(&bus->sem);
>
> return (msg_error == 0)? 0 : -EINVAL;
> }
>
> 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.
>
> bool bus_is_broken = (bus == NULL) ||
> (msg_count < bus->messages_left) ||
> (msg_count == 0);
> int ret = 0;
>
> if(bus_is_broken == true)
> {
> return -EINVAL;
> }
>
> if(msgs->cs_change == true)
> {
> spi_css_deselect(&bus->driver);
> }
>
> if(bus->messages_left > 0)
> {
> const size_t msg_idx = msg_count - bus->messages_left;
> ret = spi_do_transfer(bus, msgs, msg_idx);
>
> bus->messages_left--;
>
> if(ret != 0)
> {
> rtems_binary_semaphore_post(&bus->sem);
>
> return ret;
> }
> }
> else
> {
> rtems_binary_semaphore_post(&bus->sem);
> }
>
> return ret;
>
> Currently I see that semaphore was successfully posted but control was not
> returned to spi_transfer.
>
> 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?
>
>
> Thanks.
>
> --
> --
> Kind regards,
> *Yaroslav Leshchinsky*
>
--
--
Kind regards,
*Yaroslav Leshchinsky*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rtems.org/pipermail/users/attachments/20190505/53d92804/attachment.html>
More information about the users
mailing list