Shop OBEX P1 Docs P2 Docs Learn Events
Access to main memory — Parallax Forums

Access to main memory

tekochiptekochip Posts: 56
edited 2007-03-28 19:00 in Propeller 1
I have an application that will have one cog running an address bus, a second cog that will run a task and would like to pass data to the first cog, and a third cog that would like to pass data to the first cog. The idea is that only one cog will handle the bus and the other cogs pass data for the first cog to place on the bus.

I have not found a way for multiple cogs to view the same address in main memory. Any VAR I declare is replicated each time the object is declared in OBJ, and if I don’t declare the object, it doesn’t have visibility in the current object.

What am I missing?

Comments

  • Paul BakerPaul Baker Posts: 6,351
    edited 2007-03-27 21:44
    You can share locations by pointer reference, you can create a helper function to retrieve the value. If you have multiple instances of the same object, place the variable in the DAT section which has exactly one instance regardless of the number of times it is declared.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
  • tekochiptekochip Posts: 56
    edited 2007-03-28 14:56
    But (and I hate starting a sentence with a conjunction) how do you do this in Assembly?

    The only way I can think of is to have one master object that starts all the others and points PAR to its global pool of memory. All globals would have to be defined in the master object.
  • Mike GreenMike Green Posts: 23,101
    edited 2007-03-28 15:10
    Paul has already described this. Let's say you have your address bus manager defined in one object. When the assembly address bus management routine is started, it is passed the address of a work area in a DAT block which will contain its parameters. There is a PUB routine that takes an address as a parameter, checks that the address bus manager isn't busy, waits if necessary, then stores its parameter in the DAT block for the address bus manager to access. Any other objects that need to setup the address bus just need to call this PUB routine and your program's initialization routine needs to call the start routine in the address bus manager object to initialize the DAT block and do a COGNEW for the assembly routine.

    If you want to do this from assembly, you'd add another PUB routine to the address bus manager object that simply returns the address of the work area in the DAT block. Whatever other objects that need to call the address bus manager would have to be passed this address by their start routines (in their PAR relative data area) and they'd have to have their own assembly version of the routine to check for an idle bus manager and set an address for it.
  • Paul BakerPaul Baker Posts: 6,351
    edited 2007-03-28 19:00
    Mike's got it, if it's assembly <-> assembly across objects, the easiest is to have the Spin portions share adresses, then either store a local copy of the pointer or directly pass the pointer as the argument to cognew when starting the assembly cogs.

    Of course the easiest is to simply have all the code which needs access to the locations in the same object and use the reference label to the value.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
Sign In or Register to comment.