2 Replies Latest reply on Apr 19, 2020 9:26 PM by AH_96

    Is CapSense_IsBusy() guaranteed to return false eventually?

    MiAr_4610906

      In the examples and on community posts, I see code like the following for reading a sensor:

       

      uint32_t proximityScan()

      {

        CapSense_SetupWidget(CapSense_PROXIMITY_WDGT_ID);

        CapSense_Scan();

       

        while (CapSense_IsBusy()) {}

       

        CapSense_ProcessWidget(CapSense_PROXIMITY_WDGT_ID);

       

        uint32_t result =

          CapSense_IsProximitySensorActive(

            CapSense_PROXIMITY_WDGT_ID,

            CapSense_PROXIMITY_SNS0_ID);

       

        return result;

      }

       

      Is the CapSense_IsBusy() function guaranteed to return false eventually? Is there a maximum wait time? Should we be checking a counter or a timer in the loop to avoid an endless loop?

        • 1. Re: Is CapSense_IsBusy() guaranteed to return false eventually?
          MoTa_728816

          Hi,

           

          IMHO, it is not guaranteed.

          So most of the samples I've seen have structure like below:

           

          ==================

          int main()

          {

               ....

              for ( ; ; )  {

                   if (CapSense_NOT_BUSY == CapSense_IsBusy()) {

                      /* do CapSense things here */

                   }

                  // other works here

              }

          }

          ==================

           

          So the samples you have seen with

            while (CapSense_IsBusy()) {}

           

          seems to be dangerous to me.

          If the application is mission-critical, I would add a timeout in side the while loop

          for example.

          =====================

              timeout_count = 0 ;

              while (capsense_IsBusy()) {

                    timeout_count++ ;

                    if (timeout_count > MAX_ALLOWABLE_TIMEOUT) {

                            return result_with_error_value ;

                    }

               }

          =====================

                          

          moto

          • 2. Re: Is CapSense_IsBusy() guaranteed to return false eventually?
            AH_96

            Hi MiAr_4610906

             

            There are a few cases when CapSense_IsBusy will not return false. They are:

            1. CapSense block is not started by calling CapSense_Start()

            2. CapSense Interrupts are masked by some other function.

            3. Global interrupts are not disabled.


            These are things that can be fixed in the firmware and once it is working, it will return false at the end of scan.

             

            You can also add a timeout functionality as MoTa_728816 suggested. The timeout period must be twice the scan time of the sensors. You can check the scan time by going to CapSense configurator > Advanced tab > Scan order.

             

            Thanks,
            Hari

            1 of 1 people found this helpful