rtems_binary_semaphore_post from IRQ handler
jameszxj
jameszxj at gmail.com
Mon May 6 04:21:30 UTC 2019
From the document c-user.pdf 25.6.6,the funciton may be called from interrupt context. I have used rtems_semaphore_xxx API in UART drivers, it works fine.
RTEMS_FATAL_SOURCE_EXCEPTION should print the PC,LR ...
I think you can trace the PC pointer to see what makes the FATAL.
------------------ Original ------------------
From: "Ярослав Лещински"<midniwalker at gmail.com>;
Date: Sun, May 5, 2019 11:55 PM
To: "users"<users at rtems.org>;
Subject: Re: rtems_binary_semaphore_post from IRQ handler
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/20190506/ebdace07/attachment-0002.html>
More information about the users
mailing list