Components

cancel
Showing results for 
Search instead for 
Did you mean: 

FPGA Semaphore IP

Please provide feedback, comments, and questions on the FPGA Semaphore IP in this thread.

Message Edited by Christian L on 10-27-2008 10:31 AM
authored by
Christian L, CLA
Systems Engineering Manager - Automotive and Transportation
NI - Austin, TX


  
0 Kudos
Message 1 of 3
(8,870 Views)

Hi,

 

This doesn't seem to work properly when a timeout is enabled on the semaphore. It works in the provided example as the timeout is zero and the semaphore is polled in a loop.

 

For example: if process A has aquired the semaphore and then process B tries to aquire it before A has released it. The semaphore VI will be held by process B as the FIFO function inside it will not finish executing for the duration of the timeout. This means that process A can not release the semaphore as it can't access the semaphore VI untill it has timed out where it was called in process B.

 

Also I dont understand why a FIFO was used in the semaphore as a single boolen output on the semaphore VI which could be set to false when the semaphore is not available. I assume it was used for the timout behaviour but I'm pretty sure that doesn't work.

 

Happy to be corrected Smiley Wink,

Steve.

Message 2 of 3
(8,100 Views)

Steve,

 

You are correct. Using a timeout other than 0 will cause the multiple instances of the non-reentrant VI to block each other. This was an oversight during development.

 

Unfortuantely there is not a very simple solution to this problem. So if you can live with a 0 timeout I would use the current solution. If you want to add support for timeout here are two possible ideas that I'm evaluating.

 

Using a Named FIFO from the Project (subVI example attached)

 

  • Create a Single Element Boolean Target-Scoped FIFO (use Flip-Flops for the Implementation) in the project.
  • Add a FIFO Name control to the front panel of the Semaphore subVI. Connect it to the terminal connector pane of the subVI.
  • On the diagram of the subVI, remove the VI scoped FIFO, and wire the FIFO name control to the input on each of the FIFO nodes.
  • Make the Semaphore subVI reentrant so that multiple instances do not block one another.
  • In the calling VI, create FIFO Name constants on the diagram. In the constants, select the FIFO from your project and wire them to the semaphore subVIs.

This will allow multiple instances of the semaphore subVI to run in parallel and still use the same FIFO. The FIFO is used for the timeout behavior and to guarantee that only one instance of the subVI can get the semaphore at the same time. In addition this method will allow you to have multiple independent semaphores by creating a project FIFO for each one.

 

Use a Reentrant Semaphore API VI and Non-Reentrant FGV SubVI

 

This method requires two levels of subVIs. The semaphore API level is a reentrant VI that provides the same API as it does now. This level implements the timeout behavior by polling a non-reentrant FGV subVI which uses a feedback node to store the current state of the semaphore. The non-reentrant FGV returns immediately and can only be called by one instance of the semaphore API VI at a time.

 

I would prefer to user a single cycle timed loop in the sempahore API VI, but this is not possible when creating multiple instances of this VI and calling into the same non-reentrant subVI. So you will need to use a While loop at this level which will not give you tick level resolution for the timeout. However it should achieve microsecond resoltion easily.

authored by
Christian L, CLA
Systems Engineering Manager - Automotive and Transportation
NI - Austin, TX


  
0 Kudos
Message 3 of 3
(8,081 Views)