227
All the portable terminals come with a real-time kernel (µC/OS) that allows user to generate
a preemptive multi-tasking application. User can apply the real-time kernel functions to
split the application into multiple tasks that each task takes turns to gain the access to the
system resource by a priority-based schedule.
µC/OS applies the semaphore mechanism to control the access to the shared resource for
the multiple tasks. Generally, there are only three operations that can be performed on a
semaphore: CREATE, PEND, and POST. A semaphore is a key that the task has to require
so that it can continue execution. If a semaphore is already in use, the requesting task is
suspended until the semaphore is released by its current owner.
A task is an infinite loop function or a function which deletes itself when it is done
executing. Each task is assigned with an appropriate priority. The more important the task
is, the higher the priority given to it. µC/OS can manage up to 32 tasks (with priority set
from 0 to 31, the lower number, the higher priority) for the user program. The main task,
main()
, takes priority 16.
A task desiring the semaphore will perform a PEND operation. A task releases the
semaphore by performing a POST operation. If there are several tasks on the pending list,
the task with highest priority waiting for the semaphore will receive the semaphore when
the semaphore is posted. The pending list of tasks is always initially empty.
Semaphores are often overused. Disabling and enabling interrupts could do the job more
efficiently. All real-time kernels will disable interrupts during critical sections of code. You
are thus basically allowed to disable interrupts for as much time as the kernel does without
affecting interrupt latency.
The µC/OS related functions are discussed as follows.
OS_ENTER_CRITICAL
Purpose
To disable the processor's interrupt.
Syntax
void OS_ENTER_CRITICAL (void);
Example
OS_ENTER_CRITICAL();
/* user code */
OS_EXIT_CRITICAL();
Description
A critical section of code is code that needs to be treated indivisibly. Once the
section of code starts executing, it must not be interrupted.
C
H A P T E R
5
Real-Time Kernel
Содержание Optimus R
Страница 1: ...Printed on 20 March 2006 C Programming Guide Version 3 04 02 Optimus S Optimus R...
Страница 6: ......
Страница 8: ...2 C Programming Guide For Optimus S R...
Страница 12: ...6 C Programming Guide For Optimus S R The flow is illustrated as shown below...
Страница 23: ...Chapter 2 Development Environment 17 Different types signed unsigned Different types same size...
Страница 24: ...18 C Programming Guide For Optimus S R...
Страница 220: ...214 C Programming Guide For Optimus S R See Also FlashSize free_memory...
Страница 232: ...226 C Programming Guide For Optimus S R 4 11 Implementation defined Limits limits h float h Refer to limit h and float h...
Страница 238: ...232 C Programming Guide For Optimus S R...