- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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