Requesting watchdog awareness for FIT modules

I have the following request for FIT modules in the corresponding r_config\*.h:

#define XXX_WATCHDOG_REFRESH 0
// #define XXX_WATCHDOG_REFRESH 1
// #define XXX_WATCHDOG_REFRESH 2
// #define XXX_WATCHDOG_REFRESH 3

and with the following consuming statements inside the FIT modules:

#if XXX_WATCHDOG_REFRESH == 0
#elif XXX_WATCHDOG_REFRESH == 1
R_IWDT_Control(IWDT_CMD_REFRESH_COUNTING, NULL);
#elif XXX_WATCHDOG_REFRESH == 2
IWDT.IWDTRR = 0x00U;
IWDT.IWDTRR = 0xFFU;
#elif XXX_WATCHDOG_REFRESH == 3
WDT.WDTRR = 0x00U;
WDT.WDTRR = 0xFFU;
#endif

these defines are very helpful if one uses the [independent] watchdog, especially in time consuming functions like the Flash API or TFAT API.

Alternatively, for more flexibility, the defines in r_config\*.h can also look like:

#define XXX_WATCHDOG_REFRESH_CODE()
// #define XXX_WATCHDOG_REFRESH_CODE() R_IWDT_Control(IWDT_CMD_REFRESH_COUNTING, NULL)
// #define XXX_WATCHDOG_REFRESH_CODE() IWDT.IWDTRR = 0x00U; IWDT.IWDTRR = 0xFFU
// #define XXX_WATCHDOG_REFRESH_CODE() WDT.WDTRR = 0x00U; IWDT.IWDTRR = 0xFFU

  • Refreshing the watchdog timer is a responsibility of the application. Moving it into a driver would only cause trouble.
  • But how to handle situations where the application waits for several seconds for the result of a single driver function, e.g.: status = R_tfat_f_lseek(&file, 2147418112); However, I've already found the sensible positions and inserted the watchdog snippets into the time consuming functions.

  • In reply to architect:

    Let's say you're doing communications, you could register a callback with the module(most modules will allow this and will execute the callback when certain events, such as timeout/read/write etc., occur) and then insert your refresh watchdog in the callback. This will keep refreshing at a higher level.
  • In reply to architect:

    Your concern is valid. If the FIT driver can block for several seconds then it is a significant limitation of the function. Most FIT drivers can be used in a non-blocking manner with user defined callback functions to handle events. However FIT specifications in general do not require a driver to be non-blocking.

    Watchdog timer operation may not be feasible with the Flash API. There are portions of the flash writing operations that cannot be interrupted.
  • In reply to Gerald:

    The Flash API function calls can be easily split into those with smaller blocks, and a watchdog refresh can then be inserted in between:

    flash_err_t My_R_FLASH_Write(uint32_t srcAddress, uint32_t destAddress, uint32_t numBytes)
    {
        flash_err_t result;

        if (numBytes <= 64) return R_FLASH_Write(srcAddress, destAddress, numBytes);

    while (numBytes) {

            uint32_t n = (numBytes <= 64) ? numBytes : 64;
            if ((result = My_R_FLASH_Write(srcAddress, destAddress, n)) != FLASH_SUCCESS) return result;

        IWDT.IWDTRR = 0x00U;
        IWDT.IWDTRR = 0xFFU;

            srcAddress += n;
            destAddress += n;
            numBytes -= n;
        }

        return FLASH_SUCCESS;
    }
  • This thread will be archived due to inactivity

    Mike Clements
    RenesasRulz Moderator