I2c_ds1307_rtc example

This example demonstrates how to work with I2C (Inter-Integrated Circuit) to control a real-time clock module based on the DS1307Z chip in KasperskyOS.

This example is intended to run only on Raspberry Pi.

Example directory in the SDK

The code of the example and build scripts are available at the following path:

/opt/KasperskyOS-Community-Edition-<platform>-<version>/examples/i2c_ds1307_rtc

List of programs

When you build an example for the target hardware platform, drivers are automatically included in the solution.

To ensure the correct operation of I2C and BSP drivers, the following conditions must be met:

Initialization description

The solution initialization description file named init.yaml is generated during the solution build process based on the ./einit/src/init.yaml.in template. Macros in @INIT_*@‌ ‌format contained in the template are automatically expanded in the resulting init.yaml file. For more details, refer to init.yaml.in template.

Security policy description

The security policy description files for a KasperskyOS-based solution are located in the ./einit/src directory.

The security.psl file contains description of the solution security policy. This file is a top-level file into which a portion of the solution security policy description in the form of the PSL file dynld.psl is included via the use declaration. (The declarations in the PSL file are annotated to explain the purpose of these declarations.) The dynld.psl file contains the part of the security policy that is used when dynamically linking the solution components.

Resources

The ./resources/xdl/i2c_ds1307_rtc directory contains the I2cClient.edl file, which is the EDL description for the I2cClient program.

Operating scenario

The I2cClient program performs the following actions:

  1. Initializes the BSP driver and applies the predefined configuration of the I2C module, which configures output multiplexing for the specified I2C channel.
  2. Initializes the I2C driver, lists the available I2C channels, and opens the I2C channel for operation.
  3. Generates a buffer with fixed test values for the date and time, and writes the prepared buffer to the real-time clock registers.
  4. Reads the current values of the real-time clock registers and compares the read data with the expected test values.
  5. Closes the I2C channel and terminates with the EXIT_SUCCESS code if the data matches, otherwise it shows the EXIT_FAILURE code.

Building and running the example

The CMake system, which is included with KasperskyOS Community Edition, is used to build and run the example.

For the example to work correctly, you must connect a DS1307Z chip-based real-time clock module to the I2C port. Diagram for connecting the DS1307Z to Raspberry Pi:

See Building and running examples section.

Page top