DCC Safety Example
==================

Introduction
------------

This example demonstrates how to configure the DCC and use it to monitor clocks in the two supported modes (continuous and single-shot modes). It also demonstrates how to receive errors generated by DCC in the MCU and Main domain.

This example displays:

    * Initializing the ESM to detect the DCC error event(s)
    * Registration of application callback for notification of ESM error events for the MCU ESM instance
    * Configuration of one MCU DCC instance to monitor a single clock in continuous mode
    * Forcing of an error to create a DCC error event
    * Using a single MCU DCC instance to monitor 3 different clocks by cycling through them in single-shot mode
    * The above will be done using first the backup clock source (RC OSC) as reference, and then with the primary clock source as reference (HFOSC0/1)
    * The above will be repeated for a Main domain DCC instance

The following methods can be used as a trigger for the DCC error event:

    * Change ratio criterion for stable clocks
    * Use Sciclient API to change clock dividers (with ratio criterion stable) to speed up clock
    * Use Sciclient API to change clock dividers (with ratio criterion stable) to slow down clock
    * Turn off power for the monitored input clock

Use Cases
---------

    +----------+-------------------------------------+-----------+-----------+----------------------------+-----------+------------------------------+------------+---------------------+---------------------------------------+
    | Use Case | Description                         | DCC Inst  | ESM       | Input Event                | Ref Clock | Input Clock                  | Mode       | Input Trigger       | Action                                |
    +==========+=====================================+===========+===========+============================+===========+==============================+============+=====================+=======================================+
    | UC-1     | Configuration of MCU DCC instance   | MCU_DCC0  | MCU_ESM0  | MCU_DCC0_INTR_ERR_LEVEL_0  | RC OSC    | MCU_PLL1_HSDIV2_CLKO (MCAN)  | Continuous | One of the possible | Error event is logged by application. |
    |          | with Reference clock set to RC OSC  |           |           |                            |           |                              |            | methods detailed    | Print event to UART.                  |
    |          | and input clock is set to           |           |           |                            |           |                              |            | above.              | Clock is reset by using Sciclient     |
    |          | MCU_PLL1_HSDIV2_CLK0 (MCAN)         |           |           |                            |           |                              |            |                     | API to re-setup the clock, as needed. |
    |          | Error event is forced.              |           |           |                            |           |                              |            |                     |                                       |
    |          |                                     |           |           |                            |           |                              |            |                     | Error event is cleared and            |
    |          |                                     |           |           |                            |           |                              |            |                     | execution continues.                  |
    +----------+-------------------------------------+-----------+-----------+----------------------------+-----------+------------------------------+------------+---------------------+---------------------------------------+
    | UC-2     | Configuration of MCU DCC instance   | MCU_DCC0  | MCU_ESM0  | MCU_DCC0_INTR_ERR_LEVEL_0  | RC OSC    | MCU_PLL1_HSDIV2_CLKO (MCAN)  | Single-shot| No errors,          | Print pass to UART upon successful    |
    |          | with Reference clock set to RC OSC  |           |           |                            |           | MCU_PLL1_HSDIV1_CLKOUT (ADC) |            | monitoring happens  | completion.                           |
    |          | and inputs used as:                 |           |           |                            |           | MCU_SYSCLK/3                 |            | without issue.      |                                       |
    |          | MCU_PLL1_HSDIV2_CLK0 (MCAN)         |           |           |                            |           |                              |            |                     |                                       |
    |          | MCU_PLL1_HSDIV1_CLKOUT (ADC)        |           |           |                            |           |                              |            |                     |                                       |
    |          | MCU_SYSCLK/3                        |           |           |                            |           |                              |            |                     |                                       |
    |          | No error events.                    |           |           |                            |           |                              |            |                     |                                       |
    +----------+-------------------------------------+-----------+-----------+----------------------------+-----------+------------------------------+------------+---------------------+---------------------------------------+
    | UC-3     | Configuration of MCU DCC instance   | MCU_DCC0  | MCU_ESM0  | MCU_DCC0_INTR_ERR_LEVEL_0  | HFOSC0    | MCU_PLL1_HSDIV2_CLKO (MCAN)  | Continuous | One of the possible | Error event is logged by application. |
    |          | with Reference clock set to HFOSC0  |           |           |                            |           |                              |            | methods detailed    | Print event to UART.                  |
    |          | and input clock is set to           |           |           |                            |           |                              |            | above.              | Clock is reset by using Sciclient     |
    |          | MCU_PLL1_HSDIV2_CLK0 (MCAN)         |           |           |                            |           |                              |            |                     | API to re-setup the clock, as needed. |
    |          | Error event is forced.              |           |           |                            |           |                              |            |                     |                                       |
    |          |                                     |           |           |                            |           |                              |            |                     | Error event is cleared and            |
    |          |                                     |           |           |                            |           |                              |            |                     | execution continues.                  |
    +----------+-------------------------------------+-----------+-----------+----------------------------+-----------+------------------------------+------------+---------------------+---------------------------------------+
    | UC-4     | Configuration of MCU DCC instance   | MCU_DCC0  | MCU_ESM0  | MCU_DCC0_INTR_ERR_LEVEL_0  | HFOSC0    | MCU_PLL1_HSDIV2_CLKO (MCAN)  | Single-shot| No errors,          | Print pass to UART upon successful    | 
    |          | with Reference clock set to HFOSC0  |           |           |                            |           | MCU_PLL1_HSDIV1_CLKOUT (ADC) |            | monitoring happens  | completion.                           |
    |          | and inputs used as:                 |           |           |                            |           | MCU_SYSCLK/3                 |            | without issue.      |                                       |
    |          | MCU_PLL1_HSDIV2_CLK0 (MCAN)         |           |           |                            |           |                              |            |                     |                                       |
    |          | MCU_PLL1_HSDIV1_CLKOUT (ADC)        |           |           |                            |           |                              |            |                     |                                       |
    |          | MCU_SYSCLK/3                        |           |           |                            |           |                              |            |                     |                                       |
    |          | No error events.                    |           |           |                            |           |                              |            |                     |                                       |
    +----------+-------------------------------------+-----------+-----------+----------------------------+-----------+------------------------------+------------+---------------------+---------------------------------------+
    | UC-5     | Configuration of Main DCC instance  | DCC0      | ESM0      | DCC0_INTR_ERR_LEVEL_0      | RC OSC    | MAIN_PLL0_HSDIV4_CLKOUT      | Continuous | One of the possible | Error event is logged by application. |
    |          | with Reference clock set to RC OSC  |           |           |                            |           |                              |            | methods detailed    | Print event to UART.                  |
    |          | and input clock is set to           |           |           |                            |           |                              |            | above.              | Clock is reset by using Sciclient     |
    |          | MAIN_PLL0_HSDIV4_CLKOUT             |           |           |                            |           |                              |            |                     | API to re-setup the clock, as needed. |
    |          | Error event is forced.              |           |           |                            |           |                              |            |                     |                                       |
    |          |                                     |           |           |                            |           |                              |            |                     | Error event is cleared and            |
    |          |                                     |           |           |                            |           |                              |            |                     | execution continues.                  |
    +----------+-------------------------------------+-----------+-----------+----------------------------+-----------+------------------------------+------------+---------------------+---------------------------------------+
    | UC-6     | Configuration of Main DCC instance  | DCC0      | ESM0      | DCC0_INTR_ERR_LEVEL_0      | HFOSC0    | MAIN_PLL0_HSDIV4_CLKOUT      | Continuous | One of the possible | Error event is logged by application. |
    |          | with Reference clock set to HFOSC0  |           |           |                            |           |                              |            | methods detailed    | Print event to UART.                  |
    |          | and input clock is set to           |           |           |                            |           |                              |            | above.              | Clock is reset by using Sciclient     |
    |          | MAIN_PLL0_HSDIV4_CLKOUT             |           |           |                            |           |                              |            |                     | API to re-setup the clock, as needed. |
    |          | Error event is forced.              |           |           |                            |           |                              |            |                     |                                       |
    |          |                                     |           |           |                            |           |                              |            |                     | Error event is cleared and            |
    |          |                                     |           |           |                            |           |                              |            |                     | execution continues.                  |
    +----------+-------------------------------------+-----------+-----------+----------------------------+-----------+------------------------------+------------+---------------------+---------------------------------------+
    | UC-7     | Configuration of Main DCC instance  | DCC0      | ESM0      | DCC0_INTR_ERR_LEVEL_0      | RC OSC    | HFOSC1                       | Continuous | No errors.          | Print pass to UART upon successful    |
    |          | with Reference clock set to RC OSC  |           |           |                            |           |                              |            | Monitoring happens  | completion.                           |
    |          | and input clock is set to           |           |           |                            |           |                              |            | without issue.      |                                       |
    |          | HFOSC1.                             |           |           |                            |           |                              |            |                     |                                       |
    |          | No error events. Use case is stopped|           |           |                            |           |                              |            |                     |                                       |
    |          | after some time.                    |           |           |                            |           |                              |            |                     |                                       |
    +----------+-------------------------------------+-----------+-----------+----------------------------+-----------+------------------------------+------------+---------------------+---------------------------------------+
    | UC-8     | Configuration of MCU DCC instance   | DCC0      | MCU_ESM0  | MCU_DCC0_INTR_ERR_LEVEL_0  | RC OSC    | HFOSC0                       | Continuous | No errors.          | Print pass to UART upon successful    |
    |          | with Reference clock set to RC OSC  |           |           |                            |           |                              |            | Monitoring happens  | completion.                           |
    |          | and input clock is set to           |           |           |                            |           |                              |            | without issue.      |                                       |
    |          | HFOSC0.                             |           |           |                            |           |                              |            |                     |                                       |
    |          | No error events. Use case is stopped|           |           |                            |           |                              |            |                     |                                       |
    |          | after some time.                    |           |           |                            |           |                              |            |                     |                                       |
    +----------+-------------------------------------+-----------+-----------+----------------------------+-----------+------------------------------+------------+---------------------+---------------------------------------+


Example Details
---------------

The example should be loaded to the hardware using the Secondary Boot Loader (SBL) from the SDK.

+---------------------+------------------------------------------------+------------------------------------------+
| Example Name        | Location                                       | Build Command                            |
+=====================+================================================+==========================================+
| dcc_app_uc1         | [sdl_install_dir]/examples/dcc/UC1/            | make dcc_app_uc1 PROFILE=release         |
+---------------------+------------------------------------------------+------------------------------------------+
| dcc_app_uc4_2       | [sdl_install_dir]/examples/dcc/UC4_2/          | make dcc_app_uc4_2 PROFILE=release       |
+---------------------+------------------------------------------------+------------------------------------------+
| dcc_app_uc3         | [sdl_install_dir]/examples/dcc/UC3/            | make dcc_app_uc3 PROFILE=release         |
+---------------------+------------------------------------------------+------------------------------------------+
| dcc_app_uc5         | [sdl_install_dir]/examples/dcc/UC5/            | make dcc_app_uc5 PROFILE=release         |
+---------------------+------------------------------------------------+------------------------------------------+
| dcc_app_uc6         | [sdl_install_dir]/examples/dcc/UC6/            | make dcc_app_uc6 PROFILE=release         |
+---------------------+------------------------------------------------+------------------------------------------+
| dcc_app_uc7         | [sdl_install_dir]/examples/dcc/UC7/            | make dcc_app_uc7 PROFILE=release         |
+---------------------+------------------------------------------------+------------------------------------------+
| dcc_app_uc8         | [sdl_install_dir]/examples/dcc/UC8/            | make dcc_app_uc8 PROFILE=release         |
+---------------------+------------------------------------------------+------------------------------------------+

Expected Output
---------------

dcc_app_uc1:

.. code:: bash

     DCC Example Test Application
     
     DCC_Test_init: Init MCU ESM complete
     
     
     SDL DCC EXAMPLE TEST: Start UC-1
     
     INSTANCE: MCU_DCC0
     Source clock: RC OSC
     Test clock: MCAN
     
     SDL DCC EXAMPLE TEST: Seed values calculation done.
     SDL DCC EXAMPLE TEST: Changing the clock ratios
     SDL DCC EXAMPLE TEST: Seed values calculation done.
     SDL DCC EXAMPLE TEST: Enabling DCC and waiting for Error interrupt
     S
     Interrupt is generated to ESM
         ESM Call back function called : instType 0x2, intType 0x1, grpChannel 0x2, index 0x16, intSrc 0x56
         Take action
     
     DL DCC EXAMPLE TEST: Changing the clock source
     SDL DCC EXAMPLE TEST: Enabling DCC and waiting for Error interrupt
     SDL DCC EXAMPLE TEST: DCC Generated Error interrupt
     SDL DCC EXAMPLE TEST: Indicating clock drift/change
     Test Name: DCC EXAMPLE TEST  PASSED
      
      All tests have passed.

     ESM Example Application

dcc_app_uc2:

.. code:: bash

     DCC EXAMPLE Test Application

     DCC_Test_init: Init MCU ESM complete


     SDL DCC TEST: Start UC-2

     INSTANCE: MCU_DCC0

     Source clock: RC OSC

     Test clock source: CBASS
     SDL DCC TEST: Seed values calculation done.
     SDL DCC TEST: DCC configured
     SDL DCC TEST: Enabling DCC and waiting for completion interrupt
     SDL DCC TEST: DCC Generated completion interrupt
     SDL DCC TEST: No Clock Drift was observed

     Test clock source: MCAN
     SDL DCC TEST: Seed values calculation done.
     SDL DCC TEST: DCC configured
     SDL DCC TEST: Enabling DCC and waiting for completion interrupt
     SDL DCC TEST: DCC Generated completion interrupt
     SDL DCC TEST: No Clock Drift was observed

     Test clock source: ADC
     SDL DCC TEST: Seed values calculation done.
     SDL DCC TEST: DCC configured
     SDL DCC TEST: Enabling DCC and waiting for completion interrupt
     SDL DCC TEST: DCC Generated completion interrupt
     SDL DCC TEST: No Clock Drift was observed

     Test Name: DCC EXAMPLE TEST  PASSED

      All tests have passed.

dcc_app_uc3:

.. code:: bash

     DCC Example Test Application

     DCC_Test_init: Init MCU ESM complete


     INSTANCE: MCU_DCC0
     Source clock: HFOSC0
     Test clock: MCAN


     SDL DCC EXAMPLE TEST: Start UC-3
     SDL DCC EXAMPLE TEST: Seed values calculation done.
     SDL DCC EXAMPLE TEST: Changing the clock ratios
     SDL DCC EXAMPLE TEST: Seed values calculation done.
     SDL DCC EXAMPLE TEST: Enabling DCC and waiting for Error interrupt

     Interrupt is generated to ESM
         ESM Call back function called : instType 0x2, intType 0x1, grpChannel 0x2, index 0x16, intSrc 0x56
         Take action

     SDL DCC EXAMPLE TEST: DCC Generated Error interrupt
     SDL DCC EXAMPLE TEST: Indicating clock drift/change
     Test Name: DCC EXAMPLE TEST  PASSED

      All tests have passed.

dcc_app_uc4:

.. code:: bash

     DCC Example Test Application

     DCC_Test_init: Init MCU ESM complete


     SDL DCC EXAMPLE TEST: Start UC-4

     INSTANCE: MCU_DCC0

     Source clock: HFOSC0

     Test clock source: CBASS
     SDL DCC EXAMPLE TEST: Seed values calculation done.
     SDL DCC EXAMPLE TEST: DCC configured
     SDL DCC EXAMPLE TEST: Enabling DCC and waiting for completion interrupt
     SDL DCC EXAMPLE TEST: DCC Generated completion interrupt
     SDL DCC EXAMPLE TEST: No Clock Drift was observed

     Test clock source: MCAN
     SDL DCC EXAMPLE TEST: Seed values calculation done.
     SDL DCC EXAMPLE TEST: DCC configured
     SDL DCC EXAMPLE TEST: Enabling DCC and waiting for completion interrupt
     SDL DCC EXAMPLE TEST: DCC Generated completion interrupt
     SDL DCC EXAMPLE TEST: No Clock Drift was observed

     Test clock source: ADC
     SDL DCC EXAMPLE TEST: Seed values calculation done.
     SDL DCC EXAMPLE TEST: DCC configured
     SDL DCC EXAMPLE TEST: Enabling DCC and waiting for completion interrupt
     SDL DCC EXAMPLE TEST: DCC Generated completion interrupt
     SDL DCC EXAMPLE TEST: No Clock Drift was observed

     Test Name: DCC EXAMPLE TEST  PASSED

      All tests have passed.

dcc_app_uc5:

.. code:: bash

     DCC Example Test Application

     DCC_Test_init: Init MCU ESM complete


     INSTANCE: DCC0
     Source clock: RC OSC
     Test clock: MCAN


     SDL DCC EXAMPLE TEST: Start UC-5
     SDL DCC EXAMPLE TEST: Seed values calculation done.
     SDL DCC EXAMPLE TEST: Changing the clock ratios
     SDL DCC EXAMPLE TEST: Seed values calculation done.
     SDL DCC EXAMPLE TEST: Enabling DCC and waiting for Error interrupt

     Interrupt is generated to ESM
         ESM Call back function called : instType 0x3, intType 0x1, grpChannel 0x3, index 0x8, intSrc 0x68
         Take action

     SDL DCC EXAMPLE TEST: DCC Generated Error interrupt
     SDL DCC EXAMPLE TEST: Indicating clock drift/change
     Test Name: DCC EXAMPLE TEST  PASSED

      All tests have passed.

dcc_app_uc6:

.. code:: bash

     DCC Example Test Application

     DCC_Test_init: Init MCU ESM complete


     INSTANCE: DCC0
     Source clock: HFOSC0
     Test clock: MCAN


     SDL DCC EXAMPLE TEST: Start UC-6
     SDL DCC EXAMPLE TEST: Seed values calculation done.
     SDL DCC EXAMPLE TEST: Changing the clock ratios
     SDL DCC EXAMPLE TEST: Seed values calculation done.
     SDL DCC EXAMPLE TEST: Enabling DCC and waiting for Error interrupt

     Interrupt is generated to ESM
         ESM Call back function called : instType 0x3, intType 0x1, grpChannel 0x3, index 0x8, intSrc 0x68
         Take action

     SDL DCC EXAMPLE TEST: DCC Generated Error interrupt
     SDL DCC EXAMPLE TEST: Indicating clock drift/change
     Test Name: DCC EXAMPLE TEST  PASSED

      All tests have passed.

dcc_app_uc7:

.. code:: bash

     DCC Example Test Application

     DCC_Test_init: Init MCU ESM complete


     INSTANCE: DCC0
     Source clock: RC OSC
     Test clock: HFOSC1


     SDL DCC EXAMPLE TEST: Start UC-7
     SDL DCC EXAMPLE TEST: Seed values calculation done.
     SDL DCC EXAMPLE TEST: DCC configured
     SDL DCC EXAMPLE TEST: Enabling DCC
     SDL DCC EXAMPLE TEST: Waiting for some time to perform Continuous mode
     SDL DCC EXAMPLE TEST: DCC module is disabled
     Test Name: DCC EXAMPLE TEST  PASSED

      All tests have passed.

dcc_app_uc8:

.. code:: bash

     DCC Example Test Application

     DCC_Test_init: Init MCU ESM complete


     INSTANCE: MCU_DCC0
     Source clock: RC OSC
     Test clock: HFOSC0


     SDL DCC EXAMPLE TEST: Start UC-8
     SDL DCC EXAMPLE TEST: Seed values calculation done.
     SDL DCC EXAMPLE TEST: DCC configured
     SDL DCC EXAMPLE TEST: Enabling DCC
     SDL DCC EXAMPLE TEST: Waiting for some time to perform Continuous mode
     SDL DCC EXAMPLE TEST: DCC module is disabled
     Test Name: DCC EXAMPLE TEST  PASSED

      All tests have passed.

Reference
---------

`DCC User Guide <../modules/dcc.html>`_
