Is CapSense_IsBusy() guaranteed to return false eventually?

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
MiAr_4610906
Level 1
Level 1

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?

0 Likes
1 Solution
Hari
Moderator
Moderator
Moderator
750 replies posted 500 replies posted 250 solutions authored

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

View solution in original post

2 Replies
MotooTanaka
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

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

0 Likes
Hari
Moderator
Moderator
Moderator
750 replies posted 500 replies posted 250 solutions authored

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