30.12.2014 Views

QDK PIC24/dsPIC-C30 - Quantum Leaps

QDK PIC24/dsPIC-C30 - Quantum Leaps

QDK PIC24/dsPIC-C30 - Quantum Leaps

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>QDK</strong><br />

<strong>PIC24</strong>/<strong>dsPIC</strong>-<strong>C30</strong><br />

www.state-machine.com/pic<br />

4.4.2 Task Preemption Test<br />

The next interesting test is verifying that tasks can preempt each other. You set a breakpoint anywhere in<br />

the Philosopher state machine code. You run the application until the breakpoint is hit. After this<br />

happens, you remove the original breakpoint and place another breakpoint at the very next machine<br />

instruction (use the Disassembly window). You also place a breakpoint inside the _INT0Interrupt()<br />

interrupt handler and on the first instruction at the first instruction of the QK_schedule_() function. Next<br />

you trigger the INT0 interrupt per the instructions given earlier. You hit the Run button.<br />

The pass criteria of this test are as follows:<br />

1. The first breakpoint hit is the one inside the _INT0Interrupt() function, which means that INT0 ISR<br />

preempted the Philospher task.<br />

2. The second breakpoint hit is the one in QK_schedule_() function, which means that the QK<br />

scheduler is activated before the control returns to the preempted Philosopher task.<br />

3. After hitting the breakpoint in QK_schedule_() function, you must first disable the Timer2 interrupts<br />

by clearing bit #7 in the IEC0 register at address 0x0094, in the “File Registers” window, in the similar<br />

way as you set the bit #0 in the IFS0 register to trigger INT0.<br />

4. Next, you single step into the QK_schedule_(). (NOTE: you might want to close the “File Registers”<br />

window to speed up the single stepping.) You verify that the scheduler invokes a state handler of the<br />

Table state machine. This proves that the Table task preempts the Philosopher task.<br />

5. After this you free-run the application and verify that the next breakpoint hit is the one inside the<br />

Philosopher state machine. This validates that the preempted task continues executing only after<br />

the preempting task (the Table state machine) completes.<br />

4.4.3 Other Tests<br />

Other interesting tests that you can perform include changing priority of the INT0 ISR to be lower than the<br />

priority of Timer2 ISR to verify that the QK scheduler is still called only after all interrupts complete.<br />

In yet another test you could post an event to Philosopher active object rather than Table active object<br />

from the INT0 ISR to verify that the QK scheduler will not preempt the Philosopher task by itself. Rather<br />

the extra event will be queued and the Philosopher task will process the queued event only after<br />

completing the current event processing.<br />

Copyright © <strong>Quantum</strong> <strong>Leaps</strong>, LLC. All Rights Reserved.<br />

25 of 35

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!