Shop OBEX P1 Docs P2 Docs Learn Events
printf problems in second cog - Page 2 — Parallax Forums

printf problems in second cog

2»

Comments

  • jazzedjazzed Posts: 11,803
    edited 2013-11-14 11:19
    TomUdale wrote: »
    #define clkset(mode, frequency) \
    do { \
      _CLKFREQ = (frequency); \
      _CLKMODE = (mode); \
      __builtin_propeller_clkset(mode); \
    } while(0)
    

    Uh-oh. Looks like I had a memory lapse. Ya, that should work as long as the clkset procedure in the data-sheet is followed.

    Need more coffee :)
  • TomUdaleTomUdale Posts: 75
    edited 2013-11-14 11:43
    Hi Jazzed,
    jazzed wrote: »
    Uh-oh. Looks like I had a memory lapse. Ya, that should work as long as the clkset procedure in the data-sheet is followed.
    Need more coffee :)

    This is a better outcome than the alternatives which were either a muddled design or a supremely non-intuitive workaround for something :)

    Cheers,

    Tom
  • TomUdaleTomUdale Posts: 75
    edited 2013-11-14 12:01
    Hi All,

    Here is the problem (pays to make your own hg clone):
    static int
    _serial_getbyte(FILE *fp)
    {
      unsigned int rxmask = fp->drvarg[0];
      unsigned int bitcycles = fp->drvarg[3];
      ...
    }
    
    
    static int _serial_fopen(FILE *fp, const char *name, const char *mode)
    {
      unsigned int baud = _baud;
      unsigned int txpin = _txpin;
      unsigned int rxpin = _rxpin;
      unsigned int bitcycles;
      ...
      bitcycles = _clkfreq / baud;
      ...
      fp->drvarg[3] = bitcycles;
      ...
    }
    

    The number of cycles per bit is calculated based on the clock frequency when the file was opened. So for stdout, that would be in the startup code before my clkset call.

    Thus if one wants to dynamically reset the clock rates, you need to also freopen the stdxxx handles of interest as well to capture the correct timings.

    Victory!

    All the best,

    Tom

    PS I got the multi-cog, interlocked SimpleSerial wrapper going. Works like a champ. I am now getting interleaved printf's from multiple cogs.
  • jazzedjazzed Posts: 11,803
    edited 2013-11-14 14:07
    Thanks Tom.

    Sounds like great progress.

    Cheers.
Sign In or Register to comment.