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 ModeSynchronous Mode
Works in both Bare-Metal and Real-Time Operating Systems (RTOS) environmentWorks only in RTOS Environment
Provides Non-blocking behaviorProvides Blocking behavior. Application thread gets blocked on a semaphore until transfer request is completed.
Application Programming Interfaces (APIs) return with a valid handle which can be used to check whether transfer request is acceptedAPIs 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 Serial Peripheral Interface (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 clients. The SPI client 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