I am attempting to develop a multitasking operating system (RTOS) in PDS. Practically it will only be suitable for the 18Series devices but it is beginning to look promising. It will be a co-operative scheduler which means each task in your program will have to Yield back to the OS at regular times. In its minimum form it will require about 700 bytes of program memory expanding to about 1800 bytes it you use all the bells and whistles.
In use it can be make writing multitasking systems very simple. Here is an example:
Code:
GoTo start
Include "RTOS Main.bas"
Include "RTOS Macros.Inc"
Dim Ctr As Byte
Symbol T_Count = OSTCBP(1)
Symbol T_LEDOut = OSTCBP(2)
Symbol T_OSCOut = OSTCBP(4)
Symbol T_Delayed = OSTCBP(5)
CountTsk:
While 1 = 1
Inc Ctr
OS_Yield
Wend
LEDOut:
While 1 = 1
PORTD = Ctr & $0F
OS_Yield
Wend
DelayedTask:
While 1 = 1
Toggle PORTA.5
OSStartTask T_OSCOut
OS_Delay 2
OSStopTask T_OSCOut
Toggle PORTA.5
OS_Delay 10
Wend
OSCOut:
While 1 = 1
PORTC = Ctr & $0F
OS_Yield
Wend
In the above I have written 4 very simple routines:
"CountTsk" increments a counter whenever it gets the opportunity.
"LEDOut" places the lower nibble of the counter onto Port C to which 4 leds are attached.
"OSCOut" does the same as LEDOut but on a different port.
"DelayedTask" Toggles a port bit, starts another routine (OSCOut) and waits for 2 ticks, when it runs again it stops the OSCOut and waits for 10 ticks.
Back to the example
|
Hi, its great to see you
visiting our forum. Why not try Proton Compiler for FREE?
Download the FREE version
of Proton Compiler, Its called Amicus18
and its available from HERE
|
Code:
OSInit ' Initialise RTOS
OSCreateTask T_Count, CountTsk, 3
OSCreateTask T_LEDOut, LEDOut, 3
OSCreateTask T_OSCOut, OSCOut, 3
OSCreateTask T_Delayed, DelayedTask, 2
OSStartTask T_Count
OSStartTask T_LEDOut
OSStartTask T_Delayed ' delayed will start and stop OSCOut
While 1 = 1
OSSched ' run scheduler continuously
Wend
This is the main program - We call OSInit which sets prepares the OS
We then register each routine as a task specifying the priority level each task should take
We start 3 of the tasks and then run the scheduler continuously.
That's it - You now have routines running at different rates controlling each other or themselves all controlled by a scheduler.
Its early stages at present and if you have read down as far as here I guess you must be a little interested. I am inviting other members who see the potential of this to join me in completing this project. The basic scheduling is written the areas now to work on are events which encompass Semaphores, and Messages. There will then be a need for quite a bit of testing and hopefully trials in some real applications.
If anyone is interested in contributing to this project please PM me and we can discuss how we might work together.