Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.arch.embedded > #21514
| From | Don Y <this@is.not.me.com> |
|---|---|
| Newsgroups | comp.arch.embedded |
| Subject | Re: What means of word 'quesue' in this RTOS description? |
| Date | 2015-07-24 14:37 -0700 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <moub5d$itk$1@speranza.aioe.org> (permalink) |
| References | <84e20976-0c3c-4776-8aa5-27eabfd9c700@googlegroups.com> <mou3vt$3fm$1@speranza.aioe.org> <4528e678-6b50-49ac-a051-b07483c172ef@googlegroups.com> |
On 7/24/2015 2:03 PM, Robert Willy wrote:
> On Friday, July 24, 2015 at 12:34:29 PM UTC-7, Don Y wrote:
>> On 7/24/2015 4:12 AM, Robert Willy wrote:
>>> The use of a queue allows the medium priority task to block until an event
>>> causes data to be available - and then immediately jump to the relevant
>>> function to handle the event. This prevents wasted processor cycles - in
>>> contrast to the infinite loop implementation whereby an event will only be
>>> processed once the loop cycles to the appropriate handler.
>>
>> So, the queue allows <something> to wait -- in an ordered fashion
>> (i.e., "I got here first! The rest of you will have to ") -- until
>> <whatever> ("data" in this case) is available.
>>
>> [The "infinite loop implementation" has to refer to the archaic
>> approach of "one big loop" that repeatedly tries to check for
>> everything and anything that might be able to "proceed" in
>> its computation.]
>>
>> It appears this P is trying to espouse the advantages of queuing
>> on an event/resource over that of repeatedly *polling* for that
>> resource/event.
>> Does this make sense in the context of your INTENDED question?
>
> Excuse me not giving full information about my question. The link for
> the except tutorial is from:
>
> http://www.freertos.org/tutorial/solution3.html
>
> below title: Concept of Operation
>
> I have thought about it, but no answer is satisfying to me.
> Thank all of you for the explanation.
From the cited link (comments from my previous post interspersed):
-----8<-----8<-----
The medium Priority Task
The medium priority task can be represented by the following pseudo code.
#define DELAY_PERIOD 4
#define FLASH_RATE 1000
void MediumPriorityTask( void *pvParameters )
{
xQueueItem Data;
TickType_t FlashTime;
InitialiseQueue();
FlashTime = xTaskGetTickCount();
for( ;; )
{
do
{
// A
if( xQueueReceive( xCommsQueue, &Data, DELAY_PERIOD ) ) {
-- Wanna bet xQueueReceive() is defined as taking a pointer to a queue
-- on which to *pend* (block) awaiting messages, a pointer to a place to copy
-- any received data EXTRACTED from that queue (when it eventually arrives)
-- and a *timeout* so the function doesn't block indefinitely?? As I said,
-- previously:
>> So, as an example, instead of checking a UART (directly *or* a FIFO/buffer
>> that the UART ISR maintains) for "available received data" which you can
>> then "process", a more elegant/efficient approach is to tell the OS
>> that you are waiting for data to be available.
>>
>> The OS then suspends your task (marks it as not ready to run so it
>> no longer consumes CPU cycles... that would be wasted repeatedly
>> checking for data that is NOT YET AVAILABLE) *at* the point where you
>> invoked "wait_for_data/event". I.e., the subroutine/function "doesn't
>> RETURN" until the condition is satisfied!
>>
>> To the programmer, this makes life easy: the OS does the "checking for
>> available data" ON BEHALF OF the task that requires it.
-- I think what you are missing is that xQueueReceive() can "hang" indefinitely
-- waiting for the arrival of data in that queue (or, at least until the
-- timeout expires, FORCING it to return). During the time while it is
-- "hung", other tasks are using the processor. *This* task isn't
-- wasting any CPU cycles doing something silly like:
-- if (!data_available) {
-- reschedule(); // i.e., yield CPU to other tasks
-- } else {
-- get_data();
-- which is what it would do in the "big loop" approach.
ProcessRS232Characters( Data.Value );
-- Having successfully returned from xQueueReceive() (an UNsuccessful return
-- would be one where some parameter was in error or the timeout expired before
-- data was available in the queue), the code now processes the data extracted
-- from the queue (i.e., made available by xQueueReceive() in the
-- buffer/variable referenced in the xQueueReceive() invocation ("&Data")
}
// B
} while ( uxQueueMessagesWaiting( xCommsQueue ) );
// C
if( ScanKeypad() ) {
UpdateLCD();
}
// D
if( ( xTaskGetTickCount() - FlashTime ) >= FLASH_RATE ) {
FlashTime = xTaskGetTickCount();
UpdateLED();
}
}
return 0;
}
Referring to the labels within the code fragment above:
A: The task first blocks waiting for a communications event. The block time is
relatively short.
B: The do-while loop executes until no data remains in the queue. This
implementation would have to be modified if data arrives too quickly for the
queue to ever be completely empty.
C: Either the queue has been emptied of all data, or no data arrived within the
specified blocking period. The maximum time that can be spent blocked waiting
for data is short enough to ensure the keypad is scanned frequently enough to
meet the specified timing constraints.
D: Check to see if it is time to flash the LED. There will be some jitter in
the frequency at which this line executes, but the LED timing requirements are
flexible enough to be met by this implementation.
-----8<-----8<-----
[IMO, flashing the LED here is a sloppy way of doing it. Instead, signal
some other task whose sole job is to flash the LED.]
Back to comp.arch.embedded | Previous | Next — Previous in thread | Find similar | Unroll thread
What means of word 'quesue' in this RTOS description? Robert Willy <rxjwg98@gmail.com> - 2015-07-24 04:12 -0700
Re: What means of word 'quesue' in this RTOS description? Les Cargill <lcargill99@comcast.com> - 2015-07-24 07:47 -0500
Re: What means of word 'quesue' in this RTOS description? Tim Wescott <seemywebsite@myfooter.really> - 2015-07-24 13:59 -0500
Re: What means of word 'quesue' in this RTOS description? Grant Edwards <invalid@invalid.invalid> - 2015-07-24 19:34 +0000
Re: What means of word 'quesue' in this RTOS description? Les Cargill <lcargill99@comcast.com> - 2015-07-24 20:52 -0500
Re: What means of word 'quesue' in this RTOS description? Tim Wescott <seemywebsite@myfooter.really> - 2015-07-24 22:18 -0500
Re: What means of word 'quesue' in this RTOS description? Les Cargill <lcargill99@comcast.com> - 2015-07-26 09:27 -0500
Re: What means of word 'quesue' in this RTOS description? Don Y <this@is.not.me.com> - 2015-07-26 08:51 -0700
Re: What means of word 'quesue' in this RTOS description? Tim Wescott <seemywebsite@myfooter.really> - 2015-07-26 16:23 -0500
Re: What means of word 'quesue' in this RTOS description? upsidedown@downunder.com - 2015-07-25 08:57 +0300
Re: What means of word 'quesue' in this RTOS description? Don Y <this@is.not.me.com> - 2015-07-24 12:34 -0700
Re: What means of word 'quesue' in this RTOS description? Robert Willy <rxjwg98@gmail.com> - 2015-07-24 14:03 -0700
Re: What means of word 'quesue' in this RTOS description? Don Y <this@is.not.me.com> - 2015-07-24 14:37 -0700
csiph-web