1 Reply Latest reply on Mar 14, 2019 12:13 AM by ShipingW_81

    Minimising MCWDT PDL API's waitUs

    kwwo_4075211

      Several MCWDT PDL API function calls have a waitUs argument(Enable(), Disable(), SetMatch() and ResetCounters() ). I am implementing tickless idle in FreeRTOS and I found the code using a lot of functions with a waitUs argument every time I setup the WDT_0 and WDT_1 with a new value. I am following the recommendations from the API documentation but this is the end result.

       

      #define MCWDT_THREE_LF_CLK_CYCLES_DELAY (MCWDT_TWO_LF_CLK_CYCLES_DELAY * 3 / 2)

      #define MCWDT_FOUR_LF_CLK_CYCLES_DELAY (MCWDT_TWO_LF_CLK_CYCLES_DELAY * 2)

       

          MCWDT_Unlock();

          MCWDT_Disable(CY_MCWDT_CTR0|CY_MCWDT_CTR1, MCWDT_THREE_LF_CLK_CYCLES_DELAY);

          MCWDT_SetMatch(CY_MCWDT_COUNTER0, wdt_0_match, MCWDT_THREE_LF_CLK_CYCLES_DELAY);

          MCWDT_SetMatch(CY_MCWDT_COUNTER1, wdt_1_match, MCWDT_THREE_LF_CLK_CYCLES_DELAY);

          MCWDT_ResetCounters(CY_MCWDT_CTR0|CY_MCWDT_CTR1, MCWDT_FOUR_LF_CLK_CYCLES_DELAY);

          MCWDT_Enable(CY_MCWDT_CTR0|CY_MCWDT_CTR1, MCWDT_THREE_LF_CLK_CYCLES_DELAY);

          MCWDT_Lock();

       

      As shown from the code snippet, the total amount of waitUs is now adding up to a big number. Since these functions are running one after another as shown above, I wonder if there is an opportunity to minimise the waitUs value without affect the overall function of the code?

        • 1. Re: Minimising MCWDT PDL API's waitUs
          ShipingW_81

          These functions in above code snippet need some delay to wait for taking effect after writing to the registers respectively.

          Generally, it will take up to 1 or 2 LFCLK cycles to take effect for related different bits of MCWDT registers -  MCWDT_CTLx/MCWDT_MATCHx...

          The recommended values of delay shown in respective PDL API comments are just  - actual required time + 1 LFCLK -

          to guarantee the valid function.

           

          However, you can set the parameter - waitUs as 0.

          In this case, it is the user's responsibility to check whether the selected counters were enabled/disabled/reset immediately after the function call, or it must be taken into account when changing the match values on the running counters.  Bleow APIs might be useful for such considerations.

          Cy_MCWDT_GetEnabledStatus()

          Cy_MCWDT_GetCount()