Application Tasks
K
A
DAK
29
3.3 Starting a Task
At startup, AMX initializes all predefined application tasks into an idle state. Once idle,
a task cannot execute until AMX receives a directive to start the task. How then does an
AMX system get off the ground?
Three AMX directives are provided to start a task. These directives are procedure calls to
AMX. The ajtrig call is used to trigger a task without a message. The ajsend call is
used to send a message to a task. The ajsenw call is used to send a message to a task and
wait for it to be received and acted upon. In response to any of these calls, AMX primes
the task for subsequent execution. In the case of ajsend or ajsenw calls, the caller's
message parameters are moved into a message envelope. The envelope is then inserted in
the destination task's mailbox at the priority level indicated by the caller.
Requests to start a task can be issued in any of the following application modules.
Restart Procedure
Application Task
Interrupt Service Procedure
Timer Procedure
The Restart Procedure provides the first opportunity to start an application task. At
startup, after all predefined tasks have been created, AMX executes all of the Restart
Procedures described in the Restart Procedure List. A Restart Procedure can be used to
request execution of one or more tasks in the system. The AMX Task Scheduler
subsequently starts the highest priority task capable of execution.
Once a task is executing, it is allowed to request the execution of any task in the system,
including itself. A task can use the ajsend or ajsenw call to send a message to another
task. The ajsenw call is only available to tasks. A task issuing an ajsenw call to AMX
suspends itself (waits) until such time as the called task has executed in response to the
call. AMX guarantees that the called task is executed in response to one caller at a time.
Requests for task execution can also be initiated in response to device interrupts. When
an interrupt occurs, the device Interrupt Service Procedure (ISP) is executed. The ISP
can issue an ajtrig call to start a particular task. It can issue an ajsend call if a message
must be sent to the task being called. Whenever an ISP requests to start a task, AMX
temporarily suspends the interrupted task, thereby leaving it in a state ready to resume
execution. The AMX Task Scheduler is then invoked to start (or return to) the highest
priority task ready for execution. It is this type of operation that permits a task to begin
execution in response to an event which is considered to be of higher priority than the
task which was running.
AMX also permits tasks to be executed at periodic intervals. For example, a periodic
application interval timer (see Chapter 5) can be started by your application. When the
timer expires, the AMX Kernel Task executes the associated application Timer
Procedure. The Timer Procedure can issue an ajtrig or ajsend call to AMX to request
execution of any given task.