Shop OBEX P1 Docs P2 Docs Learn Events
How do I implement a cog watchdog — Parallax Forums

How do I implement a cog watchdog

BillDerBillDer Posts: 33
edited 2010-01-20 00:22 in Propeller 1
I am using BS2 function's "debugin" to get input. However, I would like it to time out if the user doesn't enter their name.
inside the code it has a reference to implement a cog watchdog, using the example... but I don't see the example.
Does anyone know how to do this?
Thanks in advance

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2010-01-18 19:27
    It's much easier to modify DEBUGIN so it uses a timeout based on the system clock. You don't really need a separate cog. DEBUGIN uses SERIN_CHAR which has the following two lines:
        waitpeq(Mode << PIN, |< PIN, 0)                        ' Wait for idle
        waitpne(Mode << PIN, |< PIN, 0)                        ' WAit for
    


    These are used because they put the cog running them into a low power state, saving power. They're equivalent to the following loops:
        repeat until (Mode << PIN) & |< PIN                    ' Wait for idle
        repeat while (Mode << PIN) & |< PIN                  ' Wait for beginning of start bit
    


    To add a timeout, define another local variable "time" after "BR" in the declaration of SERIN_CHAR and define a constant "timeOut" at the beginning of the object in one of the CON sections like "timeOut = 10000" for a 10 second timeout between characters. You'd then do:
        waitpeq(Mode << PIN, |< PIN, 0)                        ' This could still be used since it waits for idle
        time := CNT                                                      ' Save start of timeout period
        repeat while (Mode << PIN) & |< PIN                  ' Wait for beginning of start bit
            if (CNT - time) > timeOut*(CLKFREQ/1000)      ' Has timeout (in milliseconds) expired?
                return -1                                                   ' Return a -1 to indicate that a timeout occurred
    


    Note that you also have to modify the SERIN_DEC, SERIN_STR, and other SERIN_ routines to use a -1 as a buffer terminator in addition to a return (13) code or they'll store the -1 in the buffer (as a 255) and keep calling SERIN_CHAR which will continue to timeout thus filling up the buffer.

    Also note that the timeout is limited to about 50 seconds with an 80MHz system clock.
  • BillDerBillDer Posts: 33
    edited 2010-01-20 00:22
    Thank you, that was exactly what I needed to know. I was a little worried about modifying the bs2 code, but I see how it works now.
    Thanks again!!!
Sign In or Register to comment.