dnx RTOS 2.2.0 "Eagle"
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
IRQ Driver

Detailed Description

Description

Driver handles external IRQ controller.

Supported architectures

Details

Meaning of major and minor numbers

The major device number select IRQ controller. The most microcontrollers have only one IRQ controller so the major number in the most cases should be set to 0 (e.g. stm32f1 architecture). The minor number selects IRQ line. For stm32f1 architecture range is from 0 to 15.

Numeration restrictions

Number of IRQ controllers and IRQ lines determines range of major and minor numbers.

Driver initialization

To initialize driver the following code can be used:

driver_init("IRQ", 0, 0, "/dev/button0");
driver_init("IRQ", 0, 1, "/dev/button1");

Driver release

To release driver the following code can be used:

driver_release("IRQ", 0, 0);
driver_release("IRQ", 0, 1);

Driver configuration

Driver can be configured by using Configtool or ioctl() function. Configuration example:

#include <stdio.h>
#include <sys/ioctl.h>
// ...
FILE *irq = fopen("/dev/button0", "r+");
if (irq) {
if (ioctl(fileno(irq), IOCTL_IRQ__CONFIGURE, &cfg) == 0) {
puts("Configuration success");
} else {
perror("ioctl()");
}
fclose(irq);
} else {
perror("/dev/button0");
}
// ...

Data write

Operation not supported.

Data read

Operation not supported.

IRQ catch

Each application can catch selected interrupt. In this case the ioctl() function should be used. Example:

#include <stdio.h>
#include <sys/ioctl.h>
// ...
FILE *irq = fopen("/dev/button0", "r+");
if (!irq) {
abort();
}
// ...
// interrupt catch
u32_t timeout = 2000; // 2s timeout
if (ioctl(fileno(irq), IOCTL_IRQ__CATCH, &timeout) == 0) {
puts("Interrupt caught!");
// ...
} else {
puts("Interrupt timeout!");
// ...
}
// ...

IRQ software trigger

Not all architectures are able to trigger external interrupt by software. If selected architecture can do that the following example is valid:

#include <stdio.h>
#include <sys/ioctl.h>
// ...
FILE *irq = fopen("/dev/button0", "r+");
if (!irq) {
abort();
}
// ...
// interrupt trigger
if (ioctl(fileno(irq), IOCTL_IRQ__TRIGGER) == 0) {
puts("Interrupt triggered!");
// ...
} else {
puts("Error occurred");
}
// ...

Macros

#define IOCTL_IRQ__CATCH   _IOW(IRQ, 0, const u32_t*)
 Wait for selected interrupt number. More...
 
#define IOCTL_IRQ__TRIGGER   _IO(IRQ, 1)
 Software interrupt trigger. More...
 
#define IOCTL_IRQ__CONFIGURE   _IOW(IRQ, 2, const IRQ_config_t*)
 Set IRQ configuration. More...
 

Enumerations

enum  IRQ_config_t
 

Macro Definition Documentation

#define IOCTL_IRQ__CATCH   _IOW(IRQ, 0, const u32_t*)
Parameters
[WR]u32_t* timeout in milliseconds
Returns
On success 0 is returned, otherwise -1 and errno code is set
#define IOCTL_IRQ__CONFIGURE   _IOW(IRQ, 2, const IRQ_config_t*)
Parameters
[WR]IRQ_config_t * IRQ trigger configuration
Returns
On success 0 is returned, otherwise -1 and errno code is set
#define IOCTL_IRQ__TRIGGER   _IO(IRQ, 1)
Returns
On success 0 is returned, otherwise -1 and errno code is set

Enumeration Type Documentation

Type represent IRQ trigger selecteion.

Enumerator
IRQ_CONFIG__IRQ_DISABLED 

IRQ disabled.

IRQ_CONFIG__TRIGGER_ON_FALLING_EDGE 

IRQ triggered on falling edge.

IRQ_CONFIG__TRIGGER_ON_RISING_EDGE 

IRQ triggered on rising edge.

IRQ_CONFIG__TRIGGER_ON_BOTH_EDGES 

IRQ triggered on both edges.

IRQ_CONFIG__TRIGGER_ON_LOW_LEVEL 

IRQ triggered on low level.

IRQ_CONFIG__TRIGGER_ON_HIGH_LEVEL 

IRQ triggered on high level.