Skip to content

Commit 0cec693

Browse files
MarGasioreknordicjm
authored andcommitted
samples: nfc: block on semaphore instead of k_cpu_atomic_idle
Replace k_cpu_atomic_idle() with semaphore blocking in order to allow idle thread take care of power management. Related ticket: KRKNWK-21438 Signed-off-by: Marcin Gasiorek <marcin.gasiorek@nordicsemi.no>
1 parent 531d9d6 commit 0cec693

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,10 @@ Networking samples
502502
NFC samples
503503
-----------
504504

505-
|no_changes_yet_note|
505+
* :ref:`writable_ndef_msg` sample:
506+
507+
* Fixed a power consumption issue.
508+
The main loop now blocks on a semaphore instead of using the :c:func:`k_cpu_atomic_idle` function, allowing the idle thread to handle power management after the read or write tag.
506509

507510
nRF5340 samples
508511
---------------

samples/nfc/writable_ndef_msg/src/main.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ static atomic_t op_flags;
4444
static uint8_t flash_buf[CONFIG_NDEF_FILE_SIZE]; /**< Buffer for flash update. */
4545
static uint8_t flash_buf_len; /**< Length of the flash buffer. */
4646

47+
static K_SEM_DEFINE(nfc_write_sem, 0, 1);
48+
4749
static void flash_buffer_prepare(size_t data_length)
4850
{
4951
if (atomic_cas(&op_flags, FLASH_WRITE_FINISHED,
@@ -52,6 +54,7 @@ static void flash_buffer_prepare(size_t data_length)
5254
memcpy(flash_buf, ndef_msg_buf, sizeof(flash_buf));
5355

5456
atomic_set(&op_flags, FLASH_BUF_PREP_FINISHED);
57+
k_sem_give(&nfc_write_sem);
5558
} else {
5659
printk("Flash update pending. Discarding new data...\n");
5760
}
@@ -119,8 +122,6 @@ static int board_init(void)
119122
*/
120123
int main(void)
121124
{
122-
printk("Starting Nordic NFC Writable NDEF Message sample\n");
123-
124125
/* Configure LED-pins as outputs. */
125126
if (board_init() < 0) {
126127
printk("Cannot initialize board!\n");
@@ -170,6 +171,7 @@ int main(void)
170171
printk("Starting NFC Writable NDEF Message sample\n");
171172

172173
while (true) {
174+
k_sem_take(&nfc_write_sem, K_FOREVER);
173175
if (atomic_cas(&op_flags, FLASH_BUF_PREP_FINISHED,
174176
FLASH_WRITE_STARTED)) {
175177
if (ndef_file_update(flash_buf, flash_buf_len) < 0) {
@@ -180,8 +182,6 @@ int main(void)
180182

181183
atomic_set(&op_flags, FLASH_WRITE_FINISHED);
182184
}
183-
184-
k_cpu_atomic_idle(irq_lock());
185185
}
186186

187187
fail:

0 commit comments

Comments
 (0)