How I add a (soft) external watchdog against my application

Started by flavigny, October 11, 2012, 01:43:51 PM

Previous topic - Next topic

flavigny

hello,
I have another post pending about howto interface C with the internal watchdog of iMX233.
Here is how I bypass it:

I wrote a script derived from legacy blink_led  (blink_and_kick):
#!/bin/sh
#set led according to parameter 0:off 1:on
echo out> /sys/class/gpio/gpio65/direction
echo $1 > /sys/class/gpio/gpio65/value
‎#kick the dog
echo a > /dev/watchdog


in my C code, I add a function:
int awake(int appel,int delay) {
   static time_t timeprevious;
   static int led=1;
   // printf ("called by: #%d, wait %d\"\r\n",appel,delay);
   time_t timenow;
   int count=delay;
   while (count>=0) {
      time(&timenow);
      if (delay==0 || timenow != timeprevious) {
          count=count-1;
          // reverse the led state
          led=1-led;
          // build command
          sprintf (cmdled,"/home/root/blink_and_kick %d",led);
          system(cmdled);
          // keep time
          timeprevious=timenow;
          // wait 1"
          if (delay>0) sleep (1);
      }
    }
   return 0;
}


So if the function awake is not called during a laps (probably hearbeat 19", set at boot-time) I obtain reboot.