4. Demonstration Example - Alert Description

This section demonstrates a possible implementation of an alert mechanism. In such cases, time accuracy is not as critical as in RTC operations and therefore SW timers, like the ones offered by freeRTOS, can be used for triggering alerts.

'Application Alerts SW FSM - Initialization Process'

Fig. 8 Application Alerts SW FSM - Initialization Process

'Application Alerts SW FSM - Main Execution Path'

Fig. 9 Application Alerts SW FSM - Main Execution Path

'Application Alerts SW FSM - Main Execution Path Continued'

Fig. 10 Application Alerts SW FSM - Main Execution Path Continued

4.1. Application Structure of Alert Functionality

  1. The key goal of this task is for the device to trigger alerts following a freeRTOS event. The code features three different alert classes: Seconds Class, Minutes Class and Hours Class. Depending on the preferred time resolution, the developer is free to choose any of the classes or a combination or all of them at the same time.

  1. So far, the provided demonstration example features two different types of alert:
    • One type of alert uses the breath timer and the white led of the chip to blink led D1 on Pro DevKit at a constant frequency. At any time, alerts can be disabled by pressing the K1 button on Pro DevKit. To enable blinking alerts, the developer should set TIME_ALERT_BREATH_TIMER_EN to ‘1’. Please note that blinking functionality is not standard feature of the alert mechanism.
    • The second type of alert, which is enabled by default, uses callback functions. The developer can define a function that is called automatically at each alert event. Please note that this callback function is the same regardless of the alert class that has been configured to trigger alerts. For this reason, the callback function passes a dedicated variable that should be used by the developer to determine the source of the alert event. For user’s convenience, the sample code exhibits macros that should be used to determine the alert source.

Code snippet of the user-defined callback function:

/*
 * User-defined callback function that is called upon an alert event.
 * Note that all alert classes will call the same function. Thus, it
 * is recommended that the developer will use \p [source] to determine
 * the source of the alert.
 */
void my_alert_cb(uint8_t source)
{

        /*
         * Check whether [Hours Class] triggered an alert.
         * Then notify [prvALERT_Task] task accordingly.
         */
        if (source & ALERT_SOURCE_HOURS_Msk) {

                // Do something...
        }

        /*
         * Check whether [Minutes Class] triggered an alert.
         * Then notify [prvALERT_Task] task accordingly.
         */
        if (source & ALERT_SOURCE_MINUTES_Msk) {

                // Do something...
        }

        /*
         * Check whether [Seconds Class] triggered an alert.
         * Then notify [prvALERT_Task] task accordingly.
         */
        if (source & ALERT_SOURCE_SECONDS_Msk) {

                // Do something...

        }
}

Note

The device must remain in active mode while the breath timer is functioning. By pressing the K1 button on Pro DevKit, LED D1 will stop blinking and the device will return to its initial state, that is extended sleep mode.