A Real
Time Operating System for the PIC – Epilog
Since
writing these articles I have been tidying up the code and using it further for
my own applications so I thought it would be a good idea to build a fresh
version of the code and highlight some of the changes I have made since the
first article was published.
Relative Addressing Option
Firstly, thanks to a
little gem of advice from Tim I have reduced code size and more importantly
reduced the overhead of the BRTOS considerably.
The complier has a directive SMALL_MICRO_MODEL
= On/Off When On, this directive instructs
the compiler to use relative addressing for loops and branches etc rather than
absolute addressing. You have to be
careful where you use it as if your loop is too long or you have a jump or
branch outside the range of the relative address it will not work. Whilst the compiler does not check for an out
of range address the assembler does and it will report back the problem.
Try
removing these directives and see what a difference it makes.
Note.
Now you have the optimiser, the compiler will do it all for you OPTIMISER_LEVEL = 2 (Tim)
Serial Receive timer (RxTMR)
The RxTMR
used to run as a 1 Hz task continuously, it now is only added when serial data
is being received and is removed either on timeout or when a record has been
processed.
Serial Out under Interrupts is now a Macro
I have changed the subroutine which copies
the data string to the Serial Output buffer into a Macro command. This makes it a little more like using the
native HSerOut command although it only applies to
data strings at present. To use the
Macro you simply write HISerOut StringArray where StringArray
is the variable name of the string array you want to send to the serial port.
Adding Macros to the IDE Parameter Hints
To make it a really professional job you
can add parameter hints for your macro’s. These are contained in a text file called
USER.MCD. I have added hints for all the
Macros used in BRTOS. To install them
copy the attached USER.MCD to your ProtonIDE
directory, then restart the IDE. (Note –
if you have already produced macro’s of your own and
have created your own USER.MCD either add this file to your file or swap it
after saving your original).
Menu Operation
I have changed the way the menu code works
slightly to make it more uniform. The
change involves including the default display (i.e. menu off) mode within the
menu structure. The menus behave exactly
the same as they always did but now you return to the default display via the
same jump table as all the other menu entries.
Optimisation
I have broken the day of week calculation
in the RTC file down into separate elements.
Whilst this makes the Basic code longer it reduces the code produced by
over 100 bytes. In fact I have been through
much of the other code and wherever possible tried to reduce each line to
simple commands reducing the Inline commands to a minimum. Its amazing how much code you can save doing
this.
ADDImmd, ADDTask, REMTask, REPTask, POSTask macros have been optimized. They do not now pass the parameter via the
stack but now place them directly in the required variables. This saves pushing and popping Byte and Word
variables every time they are called.
Bugs
I have corrected a bug in Task
Manager. If you changed the task list
from within a task and the task rate of the task you changed was different from
the current active task any tasks at the same rate of the current task would
not get executed. It sounds very subtle
but extremely confusing if you stumble across it. I could have just left it and put a
restriction on not changing tasks from within a task but it only required a
Push and a Pop to solve it.
BRTOS
Task Monitor
I have attempted to make the comms more rugged so that it will recover from more error
situations rather than leaving you stranded.
It is still not perfect but as this is a tool for development I think it
is adequate under most situations.
I have also changed the way the Options
dialog works when setting up network addresses and port numbers – hopefully
it’s a little more intuitive.
Finally sorted the situation where task
monitor was started by the IDE and the IDE closed before Task Monitor was
closed.
Attached
Files
The attached files comprise the whole
package:
BRTOS_Clock_Demo.zip is the Proton source for all BRTOS as
described.
BRTOS_Task_Monitor_VB_Install.zip is the installation program for the VB
DLLs required – it does not include the application just the support files.
BRTOS_Task_Manager_PluginInstall.exe will install the BRTOS Task Monitor
application in the IDE plug in directory under JGBTools.
Run the VB install first to install the VB
support components then run the Plugin Install
program.
To see the task monitor, run the IDE,
click on the Plugin icon and select JGBTools, BRTOS Task Monitor.
user.mcd replace this file to get highlighting and
context help on the macros unless you are using the file already in which case copy
the contents in your existing copy.
Have fun
JohnB