
Event Multitasking - 2
Between each program statement CAM BASIC checks to see if any interrupt flags are set. If so, it branches to the line
number that was specified for that interrupt. The maximum time to service an interrupt is the length of the command
previous to the interrupt. This is called maximum latency time. It ranges from about 0.2 m illiseconds to 2 milliseconds.
There are a fe w exceptions. The IN PUT and INP UT KEYP AD$ statements w ill ignore inter rupts until the inp ut is
received. The DELAY statement will prevent a response to an interrupt until the delay period. If the serial output buffer
becomes full, and there are still more characters to put in the buffer, interrupts will not be serviced until all the characters
are in the buffer.
Interrupt Priorities
CAMBASIC does not have an interrupt priority scheme. However, you can lock out a response to an interrupt for critical
program segments with the LOCK com mand.
CAMBASIC allows nesting of interrupts. That means an interrupt service routine can interrupt another interrupt service
routine. If there ar e two inter rupt routines, A and B, and A has partly exec uted when B interrupts, B w ill execute to
conclusion and then A will finish. Thus, the routine that occurred last, in effect, has the highest priority.
Since the sequence of the incoming data must be preserved, ON COM$ interrupts are internally stacked in CAMBASIC,
such that each ON COM $ interrupt w ill be handled in its entirety before the next one occurs. Other types of interrupts,
such as ON TICK, can be nested inside an ON COM $ interrupt.
Event Multitasking does not have a priority system.
COM$ TASKING
ON COM$ defines a program branch when a task defined by the CONFIG C OM$ statement becomes valid. The syntax
is:
ON COM$ channel GOSUB line or label
ON COM$ channel GOSUB
After defining all the parameters with CON FIG COM$ the ON COM $ activates the task. You can deactivate the task by
executing the same sta temen t but without a line n umbe r after GO SUB.
Channel 1 is COM 1 and Channel 2 is COM 2.
COM$ Example:
In the following example, the program will branch when 8 characters have been received. The XON and protocol
functions are disabled. All characters will be echoed.
10 CONFIG COM$ 1,0,8,0,1
20 ON COM$ 1 GOSUB 80
30 ..your program goes here
.
.
80 PRINT COM$(1)
90 RETURN
NOTE: If a serial reception error occurs, the program will branch to line 80 regardless of the number of
characters received. You can use the SYS(6) or SYS(7) function to determine the cause of the error.
Commentaires sur ces manuels