The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
completion.h File Reference

wait for a device: sleep until its interrupt, or poll. More...

#include "common/stdint.h"
#include "kernel/time/timer.h"

Go to the source code of this file.

Data Structures

struct  completion_t

Typedefs

typedef bool(*) completion_ready_t(void *context)
 a function that reads the device status.

Functions

void completion_init (completion_t *completion, const char *name, bool use_irq)
 initialize a completion.
void completion_signal (completion_t *completion)
 the device has something to report.
bool completion_wait_until (completion_t *completion, completion_ready_t ready, void *context, uint32_t timeout_ms)
 wait until ready(context) returns true.

Detailed Description

wait for a device: sleep until its interrupt, or poll.

a driver starts a command, then calls completion_wait_until with a function that reads the device status. its interrupt handler calls completion_signal. the waiting process sleeps between interrupts, so the CPU runs other processes while the device works.

the wait polls instead of sleeping when:

  • the driver has no interrupt (use_irq is false),
  • the caller cannot sleep (before the scheduler runs, or with interrupts off),
  • the interrupt did not come: if the device is ready after a short sleep without an interrupt, the interrupt does not work, and the completion polls from then on (and says so in the kernel log).

Typedef Documentation

◆ completion_ready_t

typedef bool(*) completion_ready_t(void *context)

a function that reads the device status.

Returns
true when the command is done (or has failed).

Function Documentation

◆ completion_init()

void completion_init ( completion_t * completion,
const char * name,
bool use_irq )

initialize a completion.

call once (it registers a timed queue).

Parameters
use_irqtrue if the driver has an interrupt handler.

◆ completion_signal()

void completion_signal ( completion_t * completion)

the device has something to report.

safe in an interrupt handler.

◆ completion_wait_until()

bool completion_wait_until ( completion_t * completion,
completion_ready_t ready,
void * context,
uint32_t timeout_ms )

wait until ready(context) returns true.

Parameters
timeout_mshow long the device may take.
Returns
false if the device was not ready in time.