Slot swappies and hserptr

Simmicht

Senior Member
I have a 28X2 project that is using SLOT 1 and SLOT 2.
SLOT 1 parses the scratchpad, looking for data in a XML stream which is typically 200 characters long. The XML is generated by a CleverWatts power monitor and comes is at 57600. I am capturing via back ground High Speed Serial which does the job nicely. I have a 8Mhz resonator to ensure accuracy.

I have a 4x20 LCD upon which is displayed the data from the XML.
The LCD routines are in SLOT 2.

THE PROBLEM
Most times, BUT not every time, the ptr and hserptr are 0 when the Slot 1 is run even though SLOT 1 is only called when they are different.
If I put ptr and hserprt into B0 and B1 and reset prt and hserptr from B0 and B1 at the start of SLOT 1, then all goes well.

Technical, what should happen to ptr and hserptr when a RUN x is executed? Are they preserved? Seems not ...


Basically (pun intended) the simplified code below is used.


Code:
#Slot 0
'initialize everything
RUN 2


#SLOT 1
DO 
IF hserptr=ptr THEN  'nothing left to do here
    RUN 2
ENDIF

GOSUB ParseScratchPad
LOOP



#SLOT 2
'Display data just parsed out of the XML
IF XMLValid=1 THEN
    Gosub LCDDisplayData
ENDIF

'wait for data to come in
DO
sertxd(".")

IF hserptr<>Ptr THEN
    RUN 1                  'Go and parse
ENDIF

pause 2000
LOOP
 
Last edited:

hippy

Ex-Staff (retired)
Not an authoritative answer but in my testing 'hserptr' and 'ptr' are both reset to zero on a RUN. The non-zero results may be because further bytes have been received once the RUN transfer has got under way.

In copying 'hserptr' and 'ptr' around and jumping between slots you have to be wary of bytes which may be received at that time; the background receive will write to whatever 'hserptr' points to. That is, if you receive "ABCD" that will save data in scratchpad bytes 0 to 3, leaving 'hserptr'=4. If a RUN zeroes 'hserptr' then "XY" is received before you start processing scratchpad bytes then scratchpad at that time will hold "XYCD".
 

Simmicht

Senior Member
Duh

ok that sounds reasonable, it was not very frequent (the XML appears every 6 seconds and the LCD update was every second). I might delay the swap until hserptr is stable for 100ms or so.
Thanks
 
Top