samples: bluetooth: iso_receive: Convert to new k_work API
Converts the sample to the new k_work API, and introduces a blink boolean to catch cancel failures. Signed-off-by: Trond Einar Snekvik <Trond.Einar.Snekvik@nordicsemi.no>
This commit is contained in:
parent
27a4c91ac5
commit
1649f2fc4a
1 changed files with 17 additions and 7 deletions
|
@ -46,15 +46,20 @@ static K_SEM_DEFINE(sem_big_sync_lost, 0, 1);
|
||||||
#define BLINK_ONOFF K_MSEC(500)
|
#define BLINK_ONOFF K_MSEC(500)
|
||||||
|
|
||||||
static struct device const *dev;
|
static struct device const *dev;
|
||||||
static struct k_delayed_work blink_work;
|
static struct k_work_delayable blink_work;
|
||||||
static bool led_is_on;
|
static bool led_is_on;
|
||||||
|
static bool blink;
|
||||||
|
|
||||||
static void blink_timeout(struct k_work *work)
|
static void blink_timeout(struct k_work *work)
|
||||||
{
|
{
|
||||||
|
if (!blink) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
led_is_on = !led_is_on;
|
led_is_on = !led_is_on;
|
||||||
gpio_pin_set(dev, PIN, (int)led_is_on);
|
gpio_pin_set(dev, PIN, (int)led_is_on);
|
||||||
|
|
||||||
k_delayed_work_submit(&blink_work, BLINK_ONOFF);
|
k_work_schedule(&blink_work, BLINK_ONOFF);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -288,7 +293,7 @@ void main(void)
|
||||||
}
|
}
|
||||||
printk("done.\n");
|
printk("done.\n");
|
||||||
|
|
||||||
k_delayed_work_init(&blink_work, blink_timeout);
|
k_work_init_delayable(&blink_work, blink_timeout);
|
||||||
#endif /* HAS_LED */
|
#endif /* HAS_LED */
|
||||||
|
|
||||||
/* Initialize the Bluetooth Subsystem */
|
/* Initialize the Bluetooth Subsystem */
|
||||||
|
@ -320,8 +325,9 @@ void main(void)
|
||||||
#if defined(HAS_LED)
|
#if defined(HAS_LED)
|
||||||
printk("Start blinking LED...\n");
|
printk("Start blinking LED...\n");
|
||||||
led_is_on = false;
|
led_is_on = false;
|
||||||
|
blink = true;
|
||||||
gpio_pin_set(dev, PIN, (int)led_is_on);
|
gpio_pin_set(dev, PIN, (int)led_is_on);
|
||||||
k_delayed_work_submit(&blink_work, BLINK_ONOFF);
|
k_work_reschedule(&blink_work, BLINK_ONOFF);
|
||||||
#endif /* HAS_LED */
|
#endif /* HAS_LED */
|
||||||
|
|
||||||
printk("Waiting for periodic advertising...\n");
|
printk("Waiting for periodic advertising...\n");
|
||||||
|
@ -417,7 +423,11 @@ big_sync_create:
|
||||||
|
|
||||||
#if defined(HAS_LED)
|
#if defined(HAS_LED)
|
||||||
printk("Stop blinking LED.\n");
|
printk("Stop blinking LED.\n");
|
||||||
k_delayed_work_cancel(&blink_work);
|
blink = false;
|
||||||
|
/* If this fails, we'll exit early in the handler because blink
|
||||||
|
* is false.
|
||||||
|
*/
|
||||||
|
k_work_cancel_delayable(&blink_work);
|
||||||
|
|
||||||
/* Keep LED on */
|
/* Keep LED on */
|
||||||
led_is_on = true;
|
led_is_on = true;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue