lanternfish
11-10-2011, 07:08 AM
My preference is to use PASM but learn SPIN I must. So I need to better understanding of BITWISE operators as used by SPIN so that I can integrate a number of objects for my current project. I have been (re)reading the manual but still can't quite get my head around the following:
From the Propeller GPS Module firmware (VPN1513GPSReceiverFirmware_v1.0.spin):
OBJ
'FS : "FloatString"
NMEA : "GPS_Str_NMEA_lite_lawkmH"
Trans : "simple_serial"
PUB Init | OK1, OK2, OK3
dira[raw]:=0
dira[_RX_FM_GPS]:=0
OK1:=Trans.init(sio,sio,9600) ' returns if COG started.
OK2:=NMEA.StartCOGs(_RX_FM_GPS,_GPS_SER_BAUD) ' returns if COG started.
(more code follows)
This line
OK1:=Trans.init(sio,sio,9600)
starts the Simple_Serial object, where rxPin and txPin = 17 and baud = 9600
PUB init(rxPin, txPin, baud): Okay
rxOkay := rxPin > -1 ' receiving? rxOkay = -1 if rxPin > -1
txOkay := txPin > -1 ' transmitting? txOkay = -1 if txPin > -1
sin := rxPin & $1F ' set rx pin
sout := txPin & $1F ' set tx pin
inverted := baud < 0 ' set inverted flag
bitTime := clkfreq / ||baud ' calculate serial bit time
return rxOkay | txOkay
which returns a value which is rxOkay OR'd with txOkay.
Q1. What should the return value be? and why.
This line:
OK2:=NMEA.StartCOGs(_RX_FM_GPS,_GPS_SER_BAUD)
starts GPS_Str_NMEA_Lite_lawKmH object, where _RX_FM_GPS = 18 and _GPS_SER_BAUD = 9600.
cog1 := GPS_UART.INIT(rX_FR_GPS,rX_FR_GPS,nmea_Baud)
'Start a SPIN interpreter in separate COG to execute the tokens of the
'"Concurent_NMEA_Receiver" SPIN procedure parallely with the other COGs
cog2 := COGNEW(Concurent_NMEA_Receiver, @nmea_Rx_Stack) + 1
oKay := cog2
This starts another Simple_Serial cog and the next line starts the NMEA receiver/parser in yet another cog.
Q2. What will the value of oKay be?
OK3:=cognew(Detect_led,@stack)
waitcnt(clkfreq+cnt) ' Wait
IF NOT (OK1 AND OK2) 'Some error occurred
NMEA.StopCOGs
OUTA[LED]:=0 'Turn on
REPEAT 'Until Power Off or Reset
What values will the line
IF NOT (OK1 AND OK2)
produce.
Q4. How many cogs are running? I count 4.
Thanks in advance for your answers.
From the Propeller GPS Module firmware (VPN1513GPSReceiverFirmware_v1.0.spin):
OBJ
'FS : "FloatString"
NMEA : "GPS_Str_NMEA_lite_lawkmH"
Trans : "simple_serial"
PUB Init | OK1, OK2, OK3
dira[raw]:=0
dira[_RX_FM_GPS]:=0
OK1:=Trans.init(sio,sio,9600) ' returns if COG started.
OK2:=NMEA.StartCOGs(_RX_FM_GPS,_GPS_SER_BAUD) ' returns if COG started.
(more code follows)
This line
OK1:=Trans.init(sio,sio,9600)
starts the Simple_Serial object, where rxPin and txPin = 17 and baud = 9600
PUB init(rxPin, txPin, baud): Okay
rxOkay := rxPin > -1 ' receiving? rxOkay = -1 if rxPin > -1
txOkay := txPin > -1 ' transmitting? txOkay = -1 if txPin > -1
sin := rxPin & $1F ' set rx pin
sout := txPin & $1F ' set tx pin
inverted := baud < 0 ' set inverted flag
bitTime := clkfreq / ||baud ' calculate serial bit time
return rxOkay | txOkay
which returns a value which is rxOkay OR'd with txOkay.
Q1. What should the return value be? and why.
This line:
OK2:=NMEA.StartCOGs(_RX_FM_GPS,_GPS_SER_BAUD)
starts GPS_Str_NMEA_Lite_lawKmH object, where _RX_FM_GPS = 18 and _GPS_SER_BAUD = 9600.
cog1 := GPS_UART.INIT(rX_FR_GPS,rX_FR_GPS,nmea_Baud)
'Start a SPIN interpreter in separate COG to execute the tokens of the
'"Concurent_NMEA_Receiver" SPIN procedure parallely with the other COGs
cog2 := COGNEW(Concurent_NMEA_Receiver, @nmea_Rx_Stack) + 1
oKay := cog2
This starts another Simple_Serial cog and the next line starts the NMEA receiver/parser in yet another cog.
Q2. What will the value of oKay be?
OK3:=cognew(Detect_led,@stack)
waitcnt(clkfreq+cnt) ' Wait
IF NOT (OK1 AND OK2) 'Some error occurred
NMEA.StopCOGs
OUTA[LED]:=0 'Turn on
REPEAT 'Until Power Off or Reset
What values will the line
IF NOT (OK1 AND OK2)
produce.
Q4. How many cogs are running? I count 4.
Thanks in advance for your answers.