Pre-Emptive Multi-Threading / Tasking Demo - Can Switch at 1MHz !
78rpm
Posts: 264
*** EDITED 30th Nov Oct *** See bottom of post
*** EDITED 30th Nov Oct Again*** See bottom of post
*** EDITED 31st Oct *** See bottom of post + new files
This is a small demonstration of multi-threading / tasking on a Propeller 2.
Thanks to Seairth and Electrodude for some assistance.
***EDIT 30th Nov Oct ***
I have just realised WAITX blocks interrupts!!!
I am now in the process of recoding the WAITX to GETCT1 and CMP sequences. I will post the new version
when I have finished the edit.
***EDIT 30th Nov Oct Again***
New file attached 5KB. The first one, 4KB, is still valid if you DO NOT use the WAITX.
The new file uses software counters. The new speed tops out at a little above 900KHz for switching and the LEDs are noticably slow.
*** EDIT 31st Oct ***
The bugs have been sorted and new files are attached. The maximum switching frequency is back up to 1MHz, but the switching overhead is too much.
First file, 78rpm_task_switcher.spin is the basic framework.
Second file, 78rpm_task_switcher_sftcnt.spin has four software counters to show something useful and that the tasks do return from interrupt with their C and Z flags in the correct state.
*** EDITED 30th Nov Oct Again*** See bottom of post
*** EDITED 31st Oct *** See bottom of post + new files
This is a small demonstration of multi-threading / tasking on a Propeller 2.
Thanks to Seairth and Electrodude for some assistance.
Test program to demonstrate a simple pre-emptive multi-threading / tasking. by 78rpm Output can be directed to the OUTA or the OUTB ports, change the DIRECTION_OUT register and the TASKS_OUT in the CON section below. Changing SWITCHING_FREQUENCY allows the interrupt frequency to be defined. Currently set to 1KHz. Even a switching frequency of 1MHz is possible with this small demonstration. There are four task which have conditional execution directed by the state of the Z (Zero) flag and the C (Carry) flag, of a WAITX period and SETB in the output register. Task Z C 0 1 1 1 1 0 2 0 1 3 0 0 This task switching demonstration is written not to emphasise the conditional execution of instructions, but to prove that the Z and C flags are preserved in the return address save at special function register IRET1. The tasks will only exercise their outputs with the specific Z and C states.
***EDIT 30th Nov Oct ***
I have just realised WAITX blocks interrupts!!!
I am now in the process of recoding the WAITX to GETCT1 and CMP sequences. I will post the new version
when I have finished the edit.
***EDIT 30th Nov Oct Again***
New file attached 5KB. The first one, 4KB, is still valid if you DO NOT use the WAITX.
The new file uses software counters. The new speed tops out at a little above 900KHz for switching and the LEDs are noticably slow.
*** EDIT 31st Oct ***
The bugs have been sorted and new files are attached. The maximum switching frequency is back up to 1MHz, but the switching overhead is too much.
First file, 78rpm_task_switcher.spin is the basic framework.
Second file, 78rpm_task_switcher_sftcnt.spin has four software counters to show something useful and that the tasks do return from interrupt with their C and Z flags in the correct state.
Comments
On the Prop2-Hot, there was a 'PASSCNT D/#' instruction which would loop to itself until some GETCNT target was passed. That is what we need in your case, to make code as simple as possible.
For the moment I have substituted software counters to keep the demonstration code small.
See top post for new file.
For some reason I though it was November! I will change that in my top post.
Additionally, the bugs have been ironed out with input from Seairth and Chip. The switching speed is now back up to a maximum of 1MHz, but it is really too slow to use.
New files are posted in the top post.