KasperskyOS Community Edition 1.3

gpio_interrupt example

Example use of the GPIO driver.

This example lets you verify the functionality of GPIO pin interrupts. 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 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.

If you build and run this example on QEMU, an error will occur. This is the expected behavior, because there is no GPIO driver for QEMU.

If you build and run this example for Raspberry Pi 4 or Radxa ROCK 3a, an error will occur.

Example files

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

/opt/KasperskyOS-Community-Edition-<version>/examples/gpio_interrupt

Building and running example

See Building and running examples section.