# Scheduler

## Overview

The scheduler is called in the main loop of the user application using the BLE_Kernel_Process() function.

IMPORTANT: For maximum stability, ensure that the user application calls BLE_Kernel_Process() at least once during each Bluetooth connection interval. For more information, see Baseband and Kernel Functions.

In the user application’s main loop, the kernel checks if the event field is non-null, and executes the event handlers for which the corresponding event bit is set.

## Requirements

### Scheduling Algorithm

The "Scheduling Algorithm" figure shows how the scheduler handles messages. The message handler pops messages from the message queue, passes them to the pre-defined message handler, and then handles either releasing or saving those messages based on the responses from those handlers.

Figure: Scheduling Algorithm

### Save Service

The Save service can save a message (i.e., store it in memory without it being consumed). If the task state changes after a message is received, the scheduler tries to handle the saved message before scheduling any other signals.