rtems_binary_semaphore_post from IRQ handler

Chris Johns chrisj at rtems.org
Sun May 5 22:19:34 UTC 2019


On 6/5/19 1:55 am, Ярослав Лещинский wrote:
> 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. 

What type of fatal error are you seeing?

Chris

> 
> I'll be really appreciate for any suggestions.
> 
> BRs, Yaroslav.
> 
> On Wed, 17 Apr 2019 at 16:25, Ярослав Лещинский <midniwalker at gmail.com
> <mailto: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*
> 
> _______________________________________________
> users mailing list
> users at rtems.org
> http://lists.rtems.org/mailman/listinfo/users
> 



More information about the users mailing list