Need help to understand about SPIN ...
MacTuxLin
Posts: 821
Hi All,
Newbie question again. I have solved the problem but I just don't understand why. Appreciate to help see why it is so before I make major errors as I continue my coding. Thanks in advance.
I'll place my question in the code so it is easier to see my confusion ?????
Newbie question again. I have solved the problem but I just don't understand why. Appreciate to help see why it is so before I make major errors as I continue my coding. Thanks in advance.
I'll place my question in the code so it is easier to see my confusion ?????
'Main File
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
OBJ
svG : "servoGen"
VAR
byte startGReg[64]
byte startGInputFile[13]
byte startGOutputFile[13]
PUB Main
'Clear Reg
bytefill(@startGReg, 0, 77)
'Set init reg
startGReg[0] := $34
startGReg[1] := $44
'Input Filename
startGInputFile := String("inputfil.log")
startGOutputFile := String("outputfi.log")
'Start servoGen
svG.Start(@startGReg, startGInputFile) '<--Does it means for Strings, I cannot put @
'Run other objs
repeat
'File: servoGen
OBJ
dbg : "FullDuplexSerial"
VAR
long servoGenStack[128]
PUB Start(startRegAdd, startFileAdd) : goodToGo
dbg.Start(31, 30, 0, 115200)
waitcnt(clkfreq*2 + cnt)
goodToGo := cognew(servoGenCog(startRegAdd, startFileAdd), @servoGenStack)
return
PUB servoGenCog(startRegAdd, startFileAdd)
'Testing data
dbg.Tx(0)
dbg.Bin(byte[startRegAdd][0], 8)
dbg.Tx(13)
dbg.Bin(byte[startRegAdd][1], 8)
dbg.Tx(13)
dbg.Str(String("InputFile: "))
dbg.Str(startFileAdd)
dbg.Tx(13)
dbg.Str(String("OutputFile: "))
dbg.Str(startFileAdd+13)
dbg.Tx(13)
waitcnt(clkfreq*10 + cnt)
repeat 'other code
return

Comments
When you assign that String to a variable, you're assigning the address to that variable, which you are then passing into your start method. So, if you added the @ to the second parameter, you would instead be sending the address of the address variable (startGInputFile) in memory and not the address of the value ("inputfil.log") in memory.
Bill
looks like it is designed to hold a file name 8 for name, period, 3 for extension, 1 for $00
> startGInputFile := String("inputfil.log")
String returns the address of where "inputfil.log" is stored. So startGInputFile should be a long to hold an address
John Abshier
Sorry, one more question. So does it mean I don't need to care where the actual string is stored in hub RAM? If so, is it better to declare all string variables after other variables?
Thank you.
John Abshier
PS. First 8 global longs are accessed faster than the rest.
As are the first 8 local longs starting from RESULT.