AMX Semaphore Manager
K
A
DAK
99
Task/Event Synchronization
A counting semaphore can be used to provide synchronization between a task waiting for
an event and a task, ISP or Timer Procedure in which the event is detected. The
following example assumes that a device ISP detects the event.
A task creates a counting semaphore with an initial count of zero.
The task then starts the device and waits on the semaphore. When the event of interest is
detected by the ISP, it signals to the semaphore. The Semaphore Manager grants access
to the waiting task which then resumes execution knowing that the event occurred.
#include "amx831cf.h" /* AMX C Interface Header */
static AMXID syncisp; /* ISP synchronization semaphore id */
void cdecl sttask(void)
{int status;
ajsmcre(&syncisp, 0, "SISP"); /* Create counting semaphore */
:
Start device I/O
:/* Wait 1 second for event */
status = ajsmwat(syncisp, ajtmcnv(1000), 0);
if (status == AEROK) { /* OK? */
:
Event occurred within 1 second
:
}
else if (status == AERTMO) { /* Timeout? */
:
Event did not occur within 1 second
:
}
else { /* Fatal error */
:
No such semaphore exists (who deleted it?)
:
}
ajsmdel(syncisp); /* Delete semaphore */
}