rtems_binary_semaphore_post from IRQ handler

Ярослав Лещинский midniwalker at gmail.com
Wed Apr 17 13:25:23 UTC 2019


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*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rtems.org/pipermail/users/attachments/20190417/6bc77eda/attachment.html>


More information about the users mailing list