The use of the ADC is a good example of what is missing here.
Reading an ADC has two parts. You start the conversion then wait for the conversion to finish. The read_adc() calls does both, not good in a multitasking system. The amount of time is small here but we could just as easily be waiting for a button push.
In terms of this system we only want to bump sync[current] when the conversion is finished. As it exists the bumping in done by the THREAD_END macro. The thread should not advance past the test state/chunk unless the condition is satisfied.
THREAD_START nees to clear the noBump flag
THREAD_END should not bump the seq[] if noBump is set
Reading an ADC has two parts. You start the conversion then wait for the conversion to finish. The read_adc() calls does both, not good in a multitasking system. The amount of time is small here but we could just as easily be waiting for a button push.
In terms of this system we only want to bump sync[current] when the conversion is finished. As it exists the bumping in done by the THREAD_END macro. The thread should not advance past the test state/chunk unless the condition is satisfied.
Code:
#define AD0 0
#define SW0 1
THREAD_START(AD0) // adc related process
adc_start_conversion(0);
THREAD_BREAK
[B]if (!adc_finished(0)) noBump=FALSE;[/B]
THREAD_BREAK
peocess_adc_value():
THREAD_END(AD0)
THREAD_START(SW0) // a process using a switch
// whatever setup is required
THREAD_BREAK
[B]if (not_switch_active) noBump=FALSE;[/B]
THREAD_BREAK
// post press peocessing
THREAD_END(SW0)
THREAD_START nees to clear the noBump flag
THREAD_END should not bump the seq[] if noBump is set