Silly Question? Passing a pointer to a method...And then using the data at tha
Steel
Posts: 313
I have a quick question...I can't seem to figure out how to do this...
I have a method.· In that method, I call a new method in a new cog.· I pass a pointer to my main memory to the new method in the new cog.
Now how do I actually read the data at that pointer in the new method?· I can read the address...but how do I read the data?
1) Variable declared as "BYTE TX_BUFFER_LOCK"
2) In Routine "Main", I have a COGINIT command with a pointer to "TX_BUFFER_LOCK" as a parameter.
3) In Routine "Send to PC", I am set up to recieve the pointer.
4) Now what do I do to have my application read the data at the pointer, and not the pointer value itself?
Any help would be appreciated.
Shaun
[noparse][[/noparse]code]
CON
··
· _clkmode = xtal1 + pll16x················· ' Crystal and PLL settings.
· _xinfreq = 5_000_000······················ ' 5 MHz crystal.
·C_I2C1_SDA = 4
··
VAR
· long value································ ' Declare a long variable.
· Long· SPI_MASK
· BYTE TX_BUFFER_LOCK
· BYTE TX_LENGTH
· BYTE TX_BUFFER[noparse][[/noparse]256]
· BYTE X
·
·
·
OBJ
· ser··· :···· "FullDuplexSerialPlus"······· ' Serial COM object.
· I2C··· :····· "I2C_Monitor"··············· ' I2C Monitor Object
PUB MAIN
··
· TX_LENGTH := 20
· TX_BUFFER[noparse][[/noparse]0] := 00
· TX_BUFFER[noparse][[/noparse]1] := 01
· TX_BUFFER[noparse][[/noparse]2] := 02
· TX_BUFFER[noparse][[/noparse]3] := 03
· TX_BUFFER[noparse][[/noparse]4] := 04
· TX_BUFFER[noparse][[/noparse]5] := 05
· TX_BUFFER[noparse][[/noparse]6] := 06
· TX_BUFFER[noparse][[/noparse]7] := 07
· TX_BUFFER[noparse][[/noparse]8] := 08
· TX_BUFFER[noparse][[/noparse]9] := 09
·
·COGINIT(1,SEND_TO_PC(@TX_BUFFER_LOCK),800)
· REPEAT
··· TX_BUFFER_LOCK := 1
··· WAITCNT(20_000_000 + CNT)
··· TX_BUFFER_LOCK := 0
··· WAITCNT(20_000_000 + CNT)··
···
···
PRI SEND_TO_PC(LOCK_POINTER)··
····
··· SER.start(31, 30, 0, 175000)
···
··· REPEAT
········
·······
··········· 'SEND STARTBYTE··········· '' AND THEN UNLOCKS THE BUFFER FOR OTHER RESOURCES
············ SER.TX($AA)
············ SER.TX($FF)
············· 'SEND·· PACKET LENGT
··········· SER.TX(TX_LENGTH)
············ 'SEND DATA IN BUFFER
··········· REPEAT X FROM 0 TO TX_LENGTH -1
·············· SER.TX(TX_BUFFER[noparse][[/noparse]X])
··········· 'SEND ENDBYTE
·········· SER.TX($BB)
·········· SER.TX(LOCK_POINTER)
············
············ WAITCNT(300_000 + CNT)····
···
········· [noparse][[/noparse]/code]
I have a method.· In that method, I call a new method in a new cog.· I pass a pointer to my main memory to the new method in the new cog.
Now how do I actually read the data at that pointer in the new method?· I can read the address...but how do I read the data?
1) Variable declared as "BYTE TX_BUFFER_LOCK"
2) In Routine "Main", I have a COGINIT command with a pointer to "TX_BUFFER_LOCK" as a parameter.
3) In Routine "Send to PC", I am set up to recieve the pointer.
4) Now what do I do to have my application read the data at the pointer, and not the pointer value itself?
Any help would be appreciated.
Shaun
[noparse][[/noparse]code]
CON
··
· _clkmode = xtal1 + pll16x················· ' Crystal and PLL settings.
· _xinfreq = 5_000_000······················ ' 5 MHz crystal.
·C_I2C1_SDA = 4
··
VAR
· long value································ ' Declare a long variable.
· Long· SPI_MASK
· BYTE TX_BUFFER_LOCK
· BYTE TX_LENGTH
· BYTE TX_BUFFER[noparse][[/noparse]256]
· BYTE X
·
·
·
OBJ
· ser··· :···· "FullDuplexSerialPlus"······· ' Serial COM object.
· I2C··· :····· "I2C_Monitor"··············· ' I2C Monitor Object
PUB MAIN
··
· TX_LENGTH := 20
· TX_BUFFER[noparse][[/noparse]0] := 00
· TX_BUFFER[noparse][[/noparse]1] := 01
· TX_BUFFER[noparse][[/noparse]2] := 02
· TX_BUFFER[noparse][[/noparse]3] := 03
· TX_BUFFER[noparse][[/noparse]4] := 04
· TX_BUFFER[noparse][[/noparse]5] := 05
· TX_BUFFER[noparse][[/noparse]6] := 06
· TX_BUFFER[noparse][[/noparse]7] := 07
· TX_BUFFER[noparse][[/noparse]8] := 08
· TX_BUFFER[noparse][[/noparse]9] := 09
·
·COGINIT(1,SEND_TO_PC(@TX_BUFFER_LOCK),800)
· REPEAT
··· TX_BUFFER_LOCK := 1
··· WAITCNT(20_000_000 + CNT)
··· TX_BUFFER_LOCK := 0
··· WAITCNT(20_000_000 + CNT)··
···
···
PRI SEND_TO_PC(LOCK_POINTER)··
····
··· SER.start(31, 30, 0, 175000)
···
··· REPEAT
········
·······
··········· 'SEND STARTBYTE··········· '' AND THEN UNLOCKS THE BUFFER FOR OTHER RESOURCES
············ SER.TX($AA)
············ SER.TX($FF)
············· 'SEND·· PACKET LENGT
··········· SER.TX(TX_LENGTH)
············ 'SEND DATA IN BUFFER
··········· REPEAT X FROM 0 TO TX_LENGTH -1
·············· SER.TX(TX_BUFFER[noparse][[/noparse]X])
··········· 'SEND ENDBYTE
·········· SER.TX($BB)
·········· SER.TX(LOCK_POINTER)
············
············ WAITCNT(300_000 + CNT)····
···
········· [noparse][[/noparse]/code]
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Airspace V - international hangar flying!
www.airspace-v.com/ggadgets for tools & toys
Not a silly question at all. Please see the attached code in the following thread (16-Seg Test). I posted this to demonstrate 16-segment multiplexing of the PPDB displays, but the program launches the driver in another cog along with the address of the buffer to get the character values from. I hope it helps you. Take care.
http://forums.parallax.com/showthread.php?p=790643
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Engineering
SER.TX(BYTE[noparse][[/noparse]LOCK_POINTER])
Are you sure you want to use COGINIT instead of COGNEW?
I will be using coginit once there is more code in the project.
Shaun
I recommend using cognew
coginit needs to specify a certain cog. if you do coginit you have to be VERY CAREFUL about using the cog_ID !!
If ANY other part of your program uses cognew before your coginit it might happen that that cog you want to
specifiy by a certain Cog_iD was just right occupied by the cognew before.
And then your coginit stops the cog launched before by cognew and the part of the program that should run in
by the cognew will stop and be overwritten by your coginit
example
PUB main occupies cog 6
a cognew (TV-driver) occupies cog 3
your coginit uses cog_ID 5
now a new start of the propeller
it might happen PUB main occupies cog 4
cognew (TV-driver) occupies cog 5
now your coginit with cog_ID 5 stops the the tv-driver and starts your coginit-method
but no more pictures on the tv-screen
This is the reason why you should ALWAYS use cognew instead of coginit
except some special cases if a cog locks himself up and should be restartet
best regards
Stefan