Shop OBEX P1 Docs P2 Docs Learn Events
Cog ID confusion — Parallax Forums

Cog ID confusion

Hi again.
In some of my projects I need to keep track of the cogs to be able to stop them and then restart if there are problems.
Yes, I optionally I should have written the cog methods good enough to handle such kind of situations, but I'm not there yet.
But I'm a little bit on my way by using the first, startup cog to act like a watchdog, to keep watching the other cogs.

In one of my project, the first method (cog 0) starts three other cogs like this:
PUB Main                                            ' Start other routines and keep watching the status of them
    PSTCog := debug.Start(PSTBaud)                  ' Temporary, only at design time
    InitDisplay                                     ' Launch Display Cog, Get values and display on LCD and TV
    InitRF                                          ' Launch RF Cog, Receive values from remote station
    MainCog := cogid                                ' Save Main cog's ID
    repeat...

InitDisplay starts like this:
PUB InitDisplay
    DisplayCog := cognew (Display , @DisplayStack)       
                    
PUB Display | a, count 
    TVTextCog := TVtext.start(TVPin)                       ' Starts TV_Text.spin (that again starts TV.Spin in new cog)

InitRF starts like this:
PUB InitRF
    RFCog := cognew (receiveRF , @RFstack)                            ' Start RS485 routines in new cog

PUB receiveRF  |i,a , Index, startbyte, NightLight 
    dira[RFLED]~~
    dira[LightOut]~~                                         ' Night Light Pin set to output   
    FDSCog := SER.start(RX433,TX433,  %0000, 1200)
    waitcnt(80_000_000+cnt)


When debugging the Cog ID numbers I get this result:
'                                                  6 Cogs in use:            CogID:
    '                                                  Watchdog (main loop)      0
    '                                                  ├──→Debug (PST)           2
    '                                                  ├──→Init Display          2
    '                                                  │    └──→TV               6
    '                                                  └──→Init RF               3
    '                                                       └──→FDS              5

The problem here is that two cogs seems to get the same ID. I have faced the same problem in other projects too. I am not sure if this is for real or if it just "looks like". But if I need to do a cogstop, I'm not sure if I stop the right cog.
Thats my problem, and I would appreciate if any of you could give me an idea on what I'm doing wrong here.

Comments

  • Many objects return the cog ID +1 (so zero can be used to indicate the cog not running / an error / whatever). Have you checked/accommodated that?
  • You are right, that could be something. Should have known but forgot!
    Will check it out and come back with the Result.

  • Well, all three side objects adds One to the returning cog identification number, (PST, TV and FDS). That explains all the confusion. Should have seen that but guess I have to blame the fog.

    So, when updating the CogID list, adjusting for +1, all begins to make sense:
    '                                                  6 Cogs in use:            CogID:
        '                                                  Watchdog (main loop)      0
        '                                                  ├──→Debug (PST)           1
        '                                                  ├──→Init Display          2
        '                                                  │    └──→TV               5
        '                                                  └──→Init RF               3
        '                                                       └──→FDS              4
    


    Thank you, Wuerfel_21, really appreciate your fast respond.
  • Cluso99Cluso99 Posts: 18,069
    edited 2019-05-27 20:57
    In my prop OS I have a routine that checks which cogs are free if that’s any use.

    BTW If you wait a short time after starting a cog that starts another, you will get them in order.
  • Cluso99 wrote: »
    In my prop OS I have a routine that checks which cogs are free if that’s any use.

    BTW If you wait a short time after starting a cog that starts another, you will get them in order.

    Your prop OS looks very interesting, saved on my Favorite list already!
    On cogs in order, that doesn't matter for me as long as the Propeller itself keep them under control :smile:
  • Cluso99Cluso99 Posts: 18,069
    When I load the OS, a group of cogs are used to perform the I/O and the SD drivers. These are stay resident cogs and I set a map of these. At any time I can see what cogs are in use and identify which cogs do what. They just work correctly.
    IIRC the “ver” command will list the in-use cogs.
Sign In or Register to comment.