This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Peripheral event handler tips

Hi,

I am using nRF52 SDK v16 and I am wondering where one can find relevant information regarding peripheral event handlers.

Here are a few puzzles I have for now:

  • Are peripheral (e.g. timer device) event handlers running in a different thread other than the main thread?
  • What limitations one must obey when writing such even handlers?
    • is memcpy() safe to use? 
    • shall the processing be quick? how quick?
  • When will those event handlers be called? how much delay it has from the occurring of the peripheral event? 
    • can app designer have ways (e.g. IRQ priority) to control the delay to event handler?

I am asking these because when the event may happen frequently and need be handled in a timely manner.

Regards,

yf13

Parents
  • Hi,

    I'm assuming that you are talking about the callback event handlers for the peripheral drivers in the SDK?

    • The handlers are mostly called from the IRQ_handler of the hardware peripheral and will run in the interrupt context. Unless you are running an RTOS (FreeRTOS/Zephyr/etc), there is no threading in the nRF devices.
    • You cannot call blocking APIs that run at a lower or equal interrupt priority. Since you are running in an interrupt context, all lower or equal priority events are blocked while you are in the handler. This is the reason that it is recommended to exit the handler as soon as possible. How long you can stay will depend on the application.
    • The handlers will be called when there are relevant events to be passed to the application. This is very specific to each peripheral/driver. I would recommend that you check out the event type in the struct that is passed to the handler in most drivers. This will provide details on the relevant events you can expect.
      • You can typically set the priority for the driver when you initialize it. This is mainly done in the sdk_config.h file. Priority levels are documented in the softdevice specifications.

    Best regards,
    Jørgen

  • Thanks for the information.

    No I am not using any RTOS, I just use nRF SDK. So according to your explanation, these event handlers shall be mostly executed from the "interrupt" context. 

    The interrupt context bare the restrictions (of not blocking others for too long) thus should be finished as soon as possible. This means it is not proper place for extensive calculations. So maybe a typical pattern of such event handler is to queue up the data to another queue which the main context can pickup for handling? does the SDK have utility libraries proper for this scenario?

    Regards,

    yf13

Reply
  • Thanks for the information.

    No I am not using any RTOS, I just use nRF SDK. So according to your explanation, these event handlers shall be mostly executed from the "interrupt" context. 

    The interrupt context bare the restrictions (of not blocking others for too long) thus should be finished as soon as possible. This means it is not proper place for extensive calculations. So maybe a typical pattern of such event handler is to queue up the data to another queue which the main context can pickup for handling? does the SDK have utility libraries proper for this scenario?

    Regards,

    yf13

Children
No Data
Related