Shop OBEX P1 Docs P2 Docs Learn Events
SimpleIDE Question — Parallax Forums

SimpleIDE Question

ajwardajward Posts: 1,130
edited 2015-01-15 22:07 in Propeller 1
Hi All...

I have a question and I apologize if it's a dumb one!
I'm working my way through some of the C programming tutorials, specifically multicore exmples.:
/*
  Multicore Example.c
 
  Launch a function into another cog (processor) and display what it does
  to the global n variable over time.
*/

#include "simpletools.h"                      // Include simpletools

void adder(void *par);                        // Forward declaration

static volatile int t, n;                     // Global vars for cogs to share
unsigned int stack[40 + 25];                  // Stack vars for other cog

int main()                                    // main function
{
  t = 50;                                     // Set values of t & n
  n = 5000;

  // Launch adder function into another cog (processor).
  cogstart(&adder, NULL, stack, sizeof(stack));

  // Watch what the other cog is doing to the value of n.
  while(1)
  {
    print("n = %d\n", n);                     // Display result
    pause(100);                               // Wait 1/10 of a second    
  }    
}

// Function that can continue on its
// own if launched into another cog.
void adder(void *par)                         // adder keeps going on its own
{
  while(1)                                    // Endless loop
  {
    n = n + 1;                                // n + 1 each time loop repeats
    pause(t);                                 // Wait for t ms between updates
  }                            
}

In the line... void adder(void *par);... what does "*par" do. I've found that it's a read only register and I =think= it points to the location of the "adder" function, but as with many things, I'm probably completely wrong. Any wisdom would be greatly appreciated! (I'm trying to put several of the cores of the Activity Board to use on my Boe Bot)

Amanda

Comments

  • ElectrodudeElectrodude Posts: 1,658
    edited 2015-01-15 20:53
    I'm pretty sure the void* par parameter to your adder function is whatever you pass into the void* par parameter of cogstart (you currently have NULL there). There is a read-only register in PASM (and Spin) called par; that is a completely different par.

    EDIT: jazzed beat me to it
  • ajwardajward Posts: 1,130
    edited 2015-01-15 22:07
    Ah... thank you much. Mystery solved!

    Amanda
Sign In or Register to comment.