Shop OBEX P1 Docs P2 Docs Learn Events
Appear to be missing something using simpleterm_close and -open. — Parallax Forums

Appear to be missing something using simpleterm_close and -open.

edited 2016-06-28 18:21 in Propeller 1
So in my main cog, I start
void initSerialOut()
{
  printMessage("Starting serial out on cog...");

  simpleterm_close();   
  start_serial_output(queuevga, 1);

  printMessage("We still have control here....");
}

and start_serial_output looks like
void start_serial_output(struct queue_str *queueptr, uint8_t isDebug)
{
  // initialize serial output structure. 
  struct serial_out_structure *pSerialOut = malloc(sizeof(serial_out_structure));

  pSerialOut->pQueue  = queueptr;
  pSerialOut->isDebug = isDebug;

  // start the cog and store its id in the structure. 
  unsigned int serial_out_stack[SERIAL_OUT_STACK_SIZE];

  int cogId = cogstart(start_serial_output_cog, (void *)pSerialOut, &serial_out_stack, sizeof(&serial_out_stack));
  pSerialOut->cogID = cogId;
}


start_serial_output_cog looks like:
/**
 * Called as a function pointer starting the cog. 
*/
void start_serial_output_cog(void *pSerialOut)
{
  // open serial port stream for this cog. 
  simpleterm_open();
  print("Picked up terminal control in the serial output cog.");
  
  struct serial_out_structure *pSerialOutStruct = (struct serial_out_structure *)pSerialOut;
  
  // start the fetch - execute loop.
  serialOutputLoop(pSerialOutStruct);
}

Question:
The text "Picked up terminal control in the serial output cog." is not displayed on the serial terminal. The text "We still have control here...." however, is. So for some reason it would appear that transferring control of the serial port went wrong? Anybody any idea what it could be?

Edit:
I did try the example 'Print from other core', and this worked.. As far as I can tell, I'm doing essentially the same...

Comments

  • This may or may not be the only problem in your code, but certainly defining another cog's stack as a local variable will not end well for you. serial_out_stack will be deallocated as soon as start_serial_output() returns. Either make that a static variable in the function, or declare it as global.
  • Owww.. Thanks for the pointer. :)

    Unfortunatly it didn't solve the problem at hand.
  • I'm not familiar with simpleterm_open, but reading the docs, I don't see any explicit mention of multi-cog use. For that reason, I would make an explicit call to simpleterm_close prior to opening on another cog.

    Aside from that, I don't have any other suggestions without seeing the remainder of your code.
  • The 'simpleterm_close', I'm calling from the first snippet of code. (in initSerialOut).

    The simpleterm calls themselves, I've got from the example 'Print from other core' in the Learn directory of the SimpleIDE:
    
    #include "simpletools.h"                    // Library include
    
    void other();                               // Forward declaration
    int *otherCog;                              // Global pointer for cog_run return
    
    int main()                                  // Main function
    {
      print("Cog 0 has the Talking Stick first... \n");
    
      simpleterm_close();                       // Close SimpleIDE Terminal for this core
      otherCog = cog_run(other, 128);           // Run other function in another core
    }
    
    void other()                                // other function definition
    {
      simpleterm_open();                        // Open SimpleIDE Terminal for this core
      print("...and now the other cog has it. \n");
    
      simpleterm_close();                       // Close SimpleIDE Terminal
      cog_end(otherCog);                        // Shut down this core
    }
    

    Testing this, it appears to work as expected.

    The rest of my code is... involved.. 18 .c and .h files compiling to nearly 31KB of binary..
    Guess I'll have to just figure it out then..

    Thanks for the help so far.
  • Have you tried bumping your stack size?
Sign In or Register to comment.