Shop OBEX P1 Docs P2 Docs Learn Events
Silly Question? Passing a pointer to a method...And then using the data at tha — Parallax Forums

Silly Question? Passing a pointer to a method...And then using the data at tha

SteelSteel Posts: 313
edited 2009-03-14 16:51 in Propeller 1
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]

Comments

  • virtuPICvirtuPIC Posts: 193
    edited 2009-03-12 20:23
    What about the @@ operator? In the SPIN manual you find examples how to use.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Airspace V - international hangar flying!
    www.airspace-v.com/ggadgets for tools & toys
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2009-03-12 20:30
    Steel,

    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
  • JetfireJetfire Posts: 34
    edited 2009-03-12 20:31
    Use:
    SER.TX(BYTE[noparse][[/noparse]LOCK_POINTER])

    Are you sure you want to use COGINIT instead of COGNEW?
  • SteelSteel Posts: 313
    edited 2009-03-12 20:39
    Thanks, Jetfire! BYTE[noparse]/noparse was the ticket!

    I will be using coginit once there is more code in the project.

    Shaun
  • StefanL38StefanL38 Posts: 2,292
    edited 2009-03-14 16:51
    hello,
    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
Sign In or Register to comment.