PebbleOS
Loading...
Searching...
No Matches
Interrupt controller

Secondary interrupt controller class. More...

Data Structures

struct  pbl_intc_ops
 Interrupt controller driver operations, called with interrupts locked. More...
 
struct  pbl_intc_line
 Runtime state of a line. More...
 
struct  pbl_intc
 An interrupt controller. More...
 
struct  pbl_irq_spec
 An interrupt line, as used by a consumer. More...
 

Macros

#define PBL_INTC_STATE_DEFINE(sym, _num_irqs)
 Define the class state of interrupt controller sym, for the driver's define macro.
 
#define PBL_INTC_INIT(sym, _name, _init, _parent, _ops)
 Initializer for the struct pbl_intc of controller sym.
 
#define PBL_IRQ_SPEC(_intc, _hwirq, _type)   {.intc = (_intc), .hwirq = (_hwirq), .type = (_type)}
 Initializer for a struct pbl_irq_spec.
 

Typedefs

typedef void(* pbl_intc_handler_t) (void *arg)
 Line handler, called in ISR context.
 

Functions

static bool pbl_irq_spec_is_connected (const struct pbl_irq_spec *spec)
 Check whether an interrupt line is connected.
 
int pbl_intc_request (const struct pbl_irq_spec *spec, pbl_intc_handler_t handler, void *arg)
 Install the handler of a line and set its trigger type.
 
int pbl_intc_free (const struct pbl_irq_spec *spec)
 Disable a line and remove its handler.
 
int pbl_intc_enable (const struct pbl_irq_spec *spec)
 Enable a requested line.
 
int pbl_intc_disable (const struct pbl_irq_spec *spec)
 Disable a requested line.
 
void pbl_intc_dispatch (const struct pbl_intc *intc, uint32_t hwirq)
 Run the handler of a pending line, for the controller driver.
 

Variables

const struct pbl_device_class pbl_intc_class
 Class of the interrupt controllers.
 

Trigger types

Physical trigger of a line, as wired on the board.

#define PBL_IRQ_TYPE_EDGE_RISING   1U
 Rising edge.
 
#define PBL_IRQ_TYPE_EDGE_FALLING   2U
 Falling edge.
 
#define PBL_IRQ_TYPE_EDGE_BOTH   (PBL_IRQ_TYPE_EDGE_RISING | PBL_IRQ_TYPE_EDGE_FALLING)
 Both edges.
 
#define PBL_IRQ_TYPE_LEVEL_HIGH   4U
 High level.
 
#define PBL_IRQ_TYPE_LEVEL_LOW   8U
 Low level.
 

Detailed Description

Secondary interrupt controller class.

A secondary interrupt controller, a GPIO port or a peripheral that funnels several interrupt sources into one SoC line, is a struct pbl_intc device. SoC lines themselves are bound at build time with PBL_IRQ_CONNECT() (see Interrupts) and are not part of this class.

A consumer holds a struct pbl_irq_spec naming the controller, the line on it and its trigger type, as wired on the board, and lists the controller among its device dependencies. It requests the line once and enables it while it wants interrupts:

static void prv_int1_handler(void *arg) {
// ISR context
}
pbl_intc_request(&dev->int1, prv_int1_handler, dev);
pbl_intc_enable(&dev->int1);
#define SF32LB_GPIO1_INTC
Interrupt controller of port GPIO1.
Definition sf32lb.h:48
int pbl_intc_enable(const struct pbl_irq_spec *spec)
Enable a requested line.
#define PBL_IRQ_TYPE_EDGE_RISING
Rising edge.
Definition intc.h:46
int pbl_intc_request(const struct pbl_irq_spec *spec, pbl_intc_handler_t handler, void *arg)
Install the handler of a line and set its trigger type.
#define PBL_IRQ_SPEC(_intc, _hwirq, _type)
Initializer for a struct pbl_irq_spec.
Definition intc.h:144

The controller driver calls pbl_intc_dispatch() from its SoC interrupt handler for each pending line.


Data Structure Documentation

◆ pbl_intc_line

struct pbl_intc_line

Runtime state of a line.

Data Fields
void * arg Handler argument.
bool enabled Whether the line is enabled.
pbl_intc_handler_t handler Handler, NULL if the line is free.
uint8_t type Trigger type.

◆ pbl_intc

struct pbl_intc

An interrupt controller.

Data Fields
struct pbl_device dev Device.
struct pbl_intc_line * lines State of each line.
uint16_t num_irqs Number of lines.
const struct pbl_intc_ops * ops Driver operations.

◆ pbl_irq_spec

struct pbl_irq_spec

An interrupt line, as used by a consumer.

Data Fields
uint16_t hwirq Line number on the controller.
const struct pbl_intc * intc Controller, NULL if not connected.
uint8_t type Trigger type.

Macro Definition Documentation

◆ PBL_INTC_INIT

#define PBL_INTC_INIT (   sym,
  _name,
  _init,
  _parent,
  _ops 
)
Value:
{ \
.dev = PBL_DEVICE_INIT_CLASS(sym, _name, _init, _parent, nullptr, &pbl_intc_class), \
.ops = (_ops), \
.lines = sym##_intc_lines, \
.num_irqs = ARRAY_LENGTH(sym##_intc_lines), \
}
#define PBL_DEVICE_INIT_CLASS(sym, _name, _init, _parent, _deps, _cls)
Initializer for the struct pbl_device of device instance sym, in class _cls.
Definition device.h:123
const struct pbl_device_class pbl_intc_class
Class of the interrupt controllers.
#define ARRAY_LENGTH(array)
Calculate the length of an array, based on the size of the element type.
Definition size.h:18

Initializer for the struct pbl_intc of controller sym.

Parameters
symSymbol of the controller instance, with its state defined by PBL_INTC_STATE_DEFINE().
_nameName.
_initDevice init function, or NULL.
_parentParent device, or NULL.
_opsDriver operations.

◆ PBL_INTC_STATE_DEFINE

#define PBL_INTC_STATE_DEFINE (   sym,
  _num_irqs 
)
Value:
static struct pbl_intc_line sym##_intc_lines[_num_irqs]
#define PBL_DEVICE_STATE_DEFINE(sym)
Define the runtime state of device instance sym.
Definition device.h:109
Runtime state of a line.
Definition intc.h:76

Define the class state of interrupt controller sym, for the driver's define macro.

Parameters
symSymbol of the controller instance.
_num_irqsNumber of lines.

◆ PBL_IRQ_SPEC

#define PBL_IRQ_SPEC (   _intc,
  _hwirq,
  _type 
)    {.intc = (_intc), .hwirq = (_hwirq), .type = (_type)}

Initializer for a struct pbl_irq_spec.

Parameters
_intcInterrupt controller.
_hwirqLine number on the controller.
_typeTrigger type.

◆ PBL_IRQ_TYPE_EDGE_BOTH

#define PBL_IRQ_TYPE_EDGE_BOTH   (PBL_IRQ_TYPE_EDGE_RISING | PBL_IRQ_TYPE_EDGE_FALLING)

Both edges.

◆ PBL_IRQ_TYPE_EDGE_FALLING

#define PBL_IRQ_TYPE_EDGE_FALLING   2U

Falling edge.

◆ PBL_IRQ_TYPE_EDGE_RISING

#define PBL_IRQ_TYPE_EDGE_RISING   1U

Rising edge.

◆ PBL_IRQ_TYPE_LEVEL_HIGH

#define PBL_IRQ_TYPE_LEVEL_HIGH   4U

High level.

◆ PBL_IRQ_TYPE_LEVEL_LOW

#define PBL_IRQ_TYPE_LEVEL_LOW   8U

Low level.

Typedef Documentation

◆ pbl_intc_handler_t

typedef void(* pbl_intc_handler_t) (void *arg)

Line handler, called in ISR context.

Function Documentation

◆ pbl_intc_disable()

int pbl_intc_disable ( const struct pbl_irq_spec *  spec)

Disable a requested line.

Parameters
specRequested line.
Returns
0, -EINVAL if the line is not requested, or another negative errno.

◆ pbl_intc_dispatch()

void pbl_intc_dispatch ( const struct pbl_intc *  intc,
uint32_t  hwirq 
)

Run the handler of a pending line, for the controller driver.

A line without a handler is disabled.

Parameters
intcController.
hwirqPending line.

◆ pbl_intc_enable()

int pbl_intc_enable ( const struct pbl_irq_spec *  spec)

Enable a requested line.

Parameters
specRequested line.
Returns
0, -EINVAL if the line is not requested, or another negative errno.

◆ pbl_intc_free()

int pbl_intc_free ( const struct pbl_irq_spec *  spec)

Disable a line and remove its handler.

Parameters
specRequested line.
Returns
0, -EINVAL if the line is not requested, or another negative errno.

◆ pbl_intc_request()

int pbl_intc_request ( const struct pbl_irq_spec *  spec,
pbl_intc_handler_t  handler,
void *  arg 
)

Install the handler of a line and set its trigger type.

The line is left disabled.

Parameters
specLine, on a ready controller.
handlerHandler, called in ISR context.
argHandler argument.
Returns
0, -EBUSY if the line is already requested, -EINVAL for an invalid line or type, -ENOTSUP if the controller does not support the type, or another negative errno.

◆ pbl_irq_spec_is_connected()

static bool pbl_irq_spec_is_connected ( const struct pbl_irq_spec *  spec)
inlinestatic

Check whether an interrupt line is connected.

Parameters
specLine.
Returns
True if the line has a controller.

References pbl_irq_spec::intc.

Variable Documentation

◆ pbl_intc_class

const struct pbl_device_class pbl_intc_class
extern

Class of the interrupt controllers.