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: border1.nntp.dca1.giganews.com!border2.nntp.dca1.giganews.com!buffer2.nntp.dca1.giganews.com!border2.nntp.dca3.giganews.com!backlog4.nntp.dca3.giganews.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.earthlink.com!news.earthlink.com.POSTED!not-for-mail NNTP-Posting-Date: Tue, 09 Sep 2014 20:41:13 -0500 From: Dennis Lee Bieber Newsgroups: comp.lang.ada Subject: Re: STM32F4 Discovery, communication and libraries Date: Tue, 09 Sep 2014 21:41:54 -0400 Organization: IISS Elusive Unicorn Message-ID: <80av0adfkag3khjq5pjnsihtbqmgjqpkq7@4ax.com> References: <1cjwzr30b24xy.11kpydntxhfo5$.dlg@40tude.net> <929e9226-e4aa-474e-843c-68ed800eefad@googlegroups.com> <5b5583ca-c7b2-40be-9090-6253f0514db5@googlegroups.com> <7feccd2d-dcfd-405e-ae5d-e27d6662daa9@googlegroups.com> X-Newsreader: Forte Agent 6.00/32.1186 X-No-Archive: YES MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Usenet-Provider: http://www.giganews.com NNTP-Posting-Host: 108.79.221.165 X-Trace: sv3-sspz1AEQ+zjPOEJmuBBjouFnUqKqTTbtFS22khSku5o1PqUWkdWHNcXCoMSf0DZp4TZAqsaeElj4bfG!DVXe7unoSg1+3mNRGk6zWvTdz9K+sLZ2qOgUIInKxLf4xtRIh0P3XeCjYuC9JJhwdplxXLcJH0IS!IjfNE5oRYJG5I+edBEU/c9rQDgCB X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 4709 Xref: number.nntp.dca.giganews.com comp.lang.ada:188933 Date: 2014-09-09T21:41:54-04:00 List-Id: On Tue, 9 Sep 2014 14:56:19 -0700 (PDT), Roy Emmerich declaimed the following: > >Let me give a little bit of background to my thinking. Let's say at the top of every minute you want to measure ambient temperature (via analogue input), solar irradiance (via analogue input) and inverter current (via MODBUS RTU to the inverter) with my data logger. Going with a sequential mindset to start with, you will always know that with a single core (or multi-core) processor the samples will be sequential. The one sample follows the other and you have to programme things this way (e.g. iterating through an array of variables to sample). Threading (or tasking in Ada) on a single processor essentially does the same thing but the programming is done in a way that it looks like the three samples are taken at the same time (i.e. simultaneously sample ambient temperature, solar irradiance and inverter current at the top of every minute). The approach, however, is very different. > > >* thread one, here's your configuration, you take care of inverter current sampling every 5 seconds. >* thread two, here's your configuration, you take care of solar irradiance sampling every 1 second. >* thread 3, here's your configuration, you take care of diesel generator control. >* etc. > I suspect all you really need is a scheduler based on a priority queue -- in which the "priority" is really the time-of-next-event... Closest event is in front. Presuming you initialize all the devices before starting the scheduler there should not be any problem of a suddenly an event crops up that needs to go "now". loop pull front of queue (event time, device handler/callback) delay until event time call device handler/callback end loop Device handler/callback is essentially obtain reading from device log reading compute next event time for this device (current trigger time + interval) put entry on queue (where it sorts to the proper place in the multitude of items) Obviously "device handler/callback" needs to somehow incorporate the parameters for the rate computation, the particular device ID if more than one device shares the code of a handler, etc. Since the main loop doesn't pull the next item until the handler has placed its next invocation onto the queue, even a fast event rate won't vanish, it just becomes the next entry to be pulled. You might want to look at "discrete event" information. Your configuration information would contain something like: device class (handler name), device ID, offset to first event time, delta between events for each instance of a device. The event queue only needs to be large enough to hold one event from each configured device (each device only needs one pending event, and when that event is pulled and the device handler activates, it puts itself back on the queue). -- Wulfraed Dennis Lee Bieber AF6VN wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/