This example demonstrates use of the GPIO driver to verify the operation of interrupts for GPIO pins.
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/gpio_interrupt
List of programs
Client – application that interacts with the GPIO driver.DCM – system program that lets you dynamically create IPC channels.When you build an example for the target hardware platform, platform-specific drivers are automatically included in the solution:
BSP is a hardware platform support package (Board Support Package). Provides cross-platform configuration of peripherals for the Radxa ROCK 3A and Raspberry Pi 4 B.GPIO – GPIO support driver for the Radxa ROCK 3A and Raspberry Pi 4 B.PinCtrl – low-level pin multiplexing (pinmux) configuration driver for the Radxa ROCK 3A.Bcm2711MboxArmToVc – driver for working with the VideoCore (VC6) coprocessor via mailbox technology for Raspberry Pi 4 B.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 files are annotated to explain the purpose of these declarations.) The dynld.psl file contains the part of the security policy description that is used when dynamically linking the solution components.
Resources
The ./resources/xdl/gpio_interrupt directory contains the Client.edl file, which is the EDL description of the Client program.
Operating scenario
The example checks the functionality of interrupts for GPIO pins. The total number of pins on the card is defined by the GPIO_PIN_NUM macro. In the pinsBitmap bitmask, pins from the ExceptionPinArr array are marked as handled so that the example can properly terminate later. All pins other than those indicated in the ExceptionPinArr array are switched to the PINS_MODE state. An interrupt handler function will be registered for all pins other than those indicated in the ExceptionPinArr array.
In an endless loop, the example checks whether the pinsBitmap bitmask is equal to the DONE_BITMASK bitmask (which corresponds to the condition when an interrupt has occurred on each GPIO pin). The interrupt handler function is then called in this loop. If an interrupt occurs for the first time on a pin that is not specified in the ExceptionPinArr array, the interrupt handler function uses the GpioGetEvent() function to receive this event. The corresponding pin in the pinsBitmap bitmask is marked as handled. Interrupt detection on this pin is disabled by calling the GpioReleaseMode() function.
Keep in mind how the example may be affected by the initial state of the registers of pull-up resistors for each pin.
Some GPIO pins may also include external pull-up resistors (for example, they are on pins GPIO2 and GPIO3 in revisions 1.4 and 1.5 of the Raspberry Pi 4 B platform). If these types of resistors are present, weaker internal resistors will not allow these pins to be pulled to logical 0.
Interrupts for the GPIO_EVENT_LOW_LEVEL and GPIO_EVENT_HIGH_LEVEL events are not supported.
ExceptionPinArr is an array of GPIO pin numbers that need to be excluded from the example. This may be necessary if some pins are already being used for other functions, e.g. if pins are being used for a UART connection during debugging.
Building and running the example
The CMake system, which is included with KasperskyOS Community Edition, is used to build and run the example.
After starting the example, to generate interrupts and correctly finish the example, sequentially apply a short-duration 3.3 V voltage impulse to each of the GPIO pins (except for those specified in the ExceptionPinArr array).
See Building and running examples section.
Page top