Page 267 - Embedded Microprocessor Systems Real World Design
P. 267

Yield. Tells the RTOS that the task is finished for now and that the next task on
                     the list may be executed.
                     Define TimeSlice. Defines the number of time-slice intervals that the task will
                     be allowed to execute.
                     Allocate Memory. Requests a specified number of memory blocks.
                     Mailbox In. Receives a mailbox message. The parameters would include the task
                     number and the mailbox number.
                     Send Mail. Sends mail to a mailbox. The parameters could include the mailbox
                     number, destination task number, and priority of the message.
                     Wait On. Waits for the queue to fill, the semaphore to be active, or the mailbox
                     to receive mail.
                   Of course, this is not a comprehensive list of RTOS services, it is just an indication
                   of the kind of things an RTOS supports.
                     A few pointers if you are thinking about using an RTOS: Make sure that assump
                   tions  about  memory  are  correct.  The  Ethernet/RS232  system  assumed  that
                   transmit and receive were halfduplex. If this assumption turns out to be wrong; if
                   both buffers are ever needed simultaneously, then there will be a memory alloca-
                   tion problem. This may be a minor problem, as a task waits until the memory is
                   available. However, it can cause a lockup if the task that has the memory will not
                   release it until the task requesting memory can execute.
                     Make sure the RTOS does not bog down the system operation. While an RTOS
                   is deterministic, it still takes time to do things. Be sure this time is no problem. Also
                   make sure that task priorities do not prevent a low-priority but essential task from
                   ever executing.




                   Preemption Considerations


                   Two considerations you must keep in mind when using a preemptive RTOS are that
                   the  RTOS manages  the  operation  of  the  software and any RTOS function  can
                   perform a task switch. The idea is to get maximum use of the CPU, but it means
                   you must take things into consideration that otherwise you need not. Say you have
                   an analog-todigital converter (ADC) that requires you to read the result within 100
                   microseconds  (ms) of starting a conversion. Also say you have a solenoid that is
                   activated by the software, held for 20ms, and then turned off. The solenoid timing
                   is performed by counting interrupts from a 1 ms timer. The polling loop activates
                   the  solenoid  and  sets a variable, SOLENOID, to  20.  The  1ms ISR  decrements
                   SOLENOID as long as it is nonzero. When it decrements to zero, the solenoid is
                   turned off. After the solenoid is turned off, a pump is started. The way this might
                   work in a polled environment is:


                   248                                             Embedded Microprocessor Systems
   262   263   264   265   266   267   268   269   270   271   272