Jump to main content

##

# 1.1 Driver Libraries

MPLAB Harmony device drivers (usually referred to as "drivers") provide simple, highly abstracted C-language interfaces to peripherals and other resources. A driver's interface allows applications and other client modules to easily interact with the peripheral it controls using consistent usage models.

Harmony Driver Modes

Asynchronous Mode | Synchronous Mode
--- | ---
Works in both Bare-Metal and RTOS environment | Works only in RTOS Environment
Provides Non-Blocking behavior | Provides Blocking behavior. Application thread gets blocked on a semaphore until transfer request is completed.
API's return with a valid handle which can be used to check whether transfer request is accepted | API's return true or false to indicate whether the whole transfer is completed.
For Bare-Metal a dedicated task routine is either called from SYS_Tasks() or is interrupt driven to process the data from the instance queue. For RTOS either a blocking dedicated thread is created for task routine or is interrupt driven to process the data from the instance queue. | As the Driver works in complete blocking behavior there is no task routine generated.

Driver Usage Models

- Single instance, single client

  - The driver manages a single instance of the peripheral and there is a single client (application) accessing the driver instance

- Multiple instances, single client (one client per driver instance)

  - The driver manages multiple instances of the peripheral and there is a single client to each instance of the driver.
  - For example, the SPI driver instance 0 manages SPI peripheral instance 3 and SPI driver instance 1 manages SPI peripheral instance 5

- Single instance, multiple clients

  - Multiple clients to an instance of the driver.
  - For example, there can be two application clients; one client interacting with SPI EEPROM and the second client interacting with SPI based temperature sensor, both interfaced to the same instance of SPI peripheral.

Harmony Drivers provide

- Same API for all the instances of a peripheral
  - This allows the application to remain the same when the peripheral instance is changed and across different platforms

- Support for multiple clients

  - Seamlessly handle client specific differences. Drivers allow multiple clients to a driver instance.
  - For example, there can be multiple application clients to a SPI driver instance having multiple SPI slaves. The SPI slave specific information such as clock phase, clock polarity, clock speed and chip select are all handled by the SPI driver based on the client that submitted the request

- Queue support (Asynchronous Mode)

  - Drivers allow queuing of multiple requests. Each instance of a driver has a dedicated queue.
  - The requests submitted by all the clients of the driver instance are queued in the driver instance queue.
  - Queuing allows the application to submit requests before waiting for the driver to finish the previous requests.
  - For each submitted request, the application can choose to get notified or poll the status of the submitted request using the handle provided by the driver for the submitted request

- Cache management

  - Drivers manage cache related operations on devices that have cache, thereby simplifying application development.

Harmony Driver Execution Flow