Shop OBEX P1 Docs P2 Docs Learn Events
Qestions on cognew and global variables — Parallax Forums

Qestions on cognew and global variables

treborz17treborz17 Posts: 76
edited 2010-05-30 18:07 in Propeller 1
Am I correct in assuming that when I have an Application calling OBJ Driver #1, and OBJ Driver #1 calls OBJ Driver #2 and so on, that when I want all the drivers to occupy the same·cog, I have Driver #1 initiate the cognew command then all subsequent drivers will appear in the same cog as #1 unless one of them initiates another cog?

Next, I have an application defining Global Variables.· I want the variables to·end up being defined with data that is calculated by a called·OBJ Driver program.· What command or routine do I use to transfer the data calculated in the driver to the main application containing the variables?

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2010-05-29 22:33
    First of all, when you use COGNEW or COGINIT to start up a driver in a cog, the driver replaces whatever was running in that cog previously. If you use COGNEW, the driver is started in a cog that's not being used (because it's stopped). If you use COGINIT, the driver is started in the cog that you specify. Whatever is already running in that cog (if anything) is completely replaced.

    Regarding global variables ... You can either pass the address of a block of global variables to a method in the object and that method will set the global variables using the address passed (and LONG[noparse][[/noparse] ], WORD[noparse][[/noparse] ], and BYTE[noparse][[/noparse] ]) or you can have a method in the object that returns either one of the values or the address of a block of values that the calling program can copy to the global variables. A lot depends on how you generate the data to be used to initialize the global variables.
  • treborz17treborz17 Posts: 76
    edited 2010-05-30 01:28
    Thanks Mike, I just found some info, in my Prop Education Kit Objects Lab, that I had forgotton that I had, that is showing examples along the lines you suggested.· I believe if I spend a little more time with it I shouldn't have any more questions on it.·

    About the cogs, I understand what your saying about how cognew and coginit work.· What I was not sure about was if a series of OBJ Drivers -- example:

    If my custom Lcd/Ping demo·application calls Parallax Library File Debug_Lcd.spin, that I have modified to start in a new cog by a cognew command, will the two OBJ files listed in Debug_Lcd.spin be called into the same new cog that Debug_Lcd.spin was placed or will·they still be operating in the original cog that the application program is still running in?· In other words I want all of the drivers to be in a cog external to the application program.· I probably could be using more accurate teminoligy on the subject but I'm still a novice in Spin.

    Robert
  • Mike GreenMike Green Posts: 23,101
    edited 2010-05-30 01:54
    Debug_Lcd doesn't use any extra cogs the way it comes from the Object Exchange. You didn't say how you modified Debug_Lcd.

    What are you trying to accomplish? The Debug_Lcd methods execute in the cog that calls them.
  • treborz17treborz17 Posts: 76
    edited 2010-05-30 18:07
    Thanks Mike,hanks again

    My program is working, I was just curious as to how, and I have that solved now.

    Thanks again,

    Robert
Sign In or Register to comment.