I am currently tasked with programming the NRF52810 to boot up upon a button press and then sit and wait for further button presses to trigger various functionality including sending out a few second PWM pulse and beginning to stream BLE advertisements.
As a very novice with firmware development, my boss informed me that triggering larger blocks of code during an interrupt (i.e the button press if I understand the button event handler correctly) can be a bad idea as it might cause a hang up in the system by blocking the execution of essential code. He instead suggested using simple flags that are set during the button presses that then tell a loop in main() to execute that same code instead.
My questions, and issues, are:
1) Is this technique of setting flags and leaving the execution to a loop in main() advised for performing the type of tasks I've mentioned such as BLE advertising and PWM?
2) If so, how would that be done? The example project I'm using is ble_peripheral/ble_app_blinky/pca10040/s132/ses and is where I've tried doing things with this technique. I've added the following after the idle_state_handle() call but from my debugging I'm not seeing the loop actually loop, I think I'm misunderstanding something:
// Enter main loop. for (;;) { idle_state_handle(); if (begin_advertising) { advertising_start(); } if (activate_motor) { pwm_motor_start(); } }
Thank you and I'll try to be prompt to answer any comments!