From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: "Jeffrey R. Carter" Newsgroups: comp.lang.ada Subject: Re: Bidirectional UART design for Ravenscar Date: Sat, 26 Aug 2017 13:04:48 +0200 Organization: Also freenews.netfront.net; news.tornevall.net; news.eternal-september.org Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Sat, 26 Aug 2017 11:00:29 -0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="64af290e39588b0b0ce7f963edec25f1"; logging-data="29628"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18cuUHxIV+x1yx7fJMRN72HVUrfrt34J2g=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 In-Reply-To: Content-Language: en-US Cancel-Lock: sha1:nTjbkZ4DMGFyppk+DD4uRgiK9Nk= Xref: news.eternal-september.org comp.lang.ada:47814 Date: 2017-08-26T13:04:48+02:00 List-Id: On 08/26/2017 12:24 AM, Simon Wright wrote: > I'm trying to implement a two-way interrupt-driven interface via a UART > with Ravenscar, and having trouble because there is one interrupt with > multiple causes; a writer must wait until transmission is possible > before putting the next character, while a reader must wait until > there's a character to be read. > > This makes it hard to write a PO with a single entry (a Ravenscar > restriction) that serves both requirements. > > It occurs to me that the interrupt handler could release one of two > suspension objects; if it's Tx_Transfer_Complete, release the SO that > the writer waits on, if it's Rx_Transfer_Complete release the reader's > SO. > > Does that seem a reasonable approach? It should work. It seems unnecessarily low level, with the additional opportunities for error that that brings. Under Ravenscar, something that conceptually would be a PO with multiple entries has to become multiple POs with 1 entry each. When the entry is just a wait/release, it can be replaced by an SO. I'd probably do an initial Ravenscar design like (really, I do the design graphically, but the graphics then translate mechanically into Ada specifications): protected type Waiter is procedure Signal; entry Wait; private -- Waiter Occurred : Boolean := False; end Waiter; Rx_Waiter : Waiter; Tx_Waiter : Waiter; protected UART_Interrupt is procedure Handle; pragma Attach_Handler (Handle, ...); end UART_Interrupt; Handle calls Rx_Waiter.Signal or Tx_Waiter.Signal. (It's been a while since I looked at Ravenscar, but I think such calls are OK. If not, then you'd have to add an entry to UART_Interrupt and have a task between it and the Waiter POs.) Then your Tx task might be loop UART.Put (Byte => Output.Next); Tx_Waiter.Wait; end loop; and your Rx task, loop Rx_Waiter.Wait; Input.Put (Byte => UART.Received); end loop; Whether the overhead of the extra POs is too much for your application depends on the timing requirements and measurement. I worked with Bo Sandén once on what would be involved in a Ravenscar solution of his Flexible-Manufacturing-System problem (I don't think it was ever published). The full-Ada solution was full of protected queues of IDs for matching available resources with tasks that needed them. For example, a Q to match available autonomous guided vehicles (AGVs) with job tasks that needed them. When an AGV was available, its ID was put on the Q. When a job needed an AGV, it blocked on the Q's Get entry until the Q was not empty, then got an AGV ID. Multiple job tasks could be blocked on the Q, which is not allowed in Ravenscar*. That simple protected Q turned into 2 protected Qs, a PO per workstation, and a helper task to connect them all. Personally, I found the single Q easier to understand and analyze, but I guess that's not true of automated tools. *Neither are the dynamically created job tasks, so the design had to be inverted from job tasks that obtain the resources needed to process them to workstation tasks that find jobs that need their services. At least 1 other Ravenscar-compliant design is possible. -- Jeff Carter "This scene's supposed to be in a saloon, but the censor cut it out. It'll play just as well this way." [in a soda fountain] Never Give a Sucker an Even Break 113