Creating USART Dynamic Drivers
MPLAB® Harmony Configurator (MHC) does not create functions for dynamic drivers as it does for static drivers. It instead uses the Universal Synchronous/Asynchronous Receiver/Transmitter (USART) driver configuration macros to create data structures (also known as objects) for each USART driver instance. These objects are passed into the dynamic driver functions to specify how the drivers are configured. This means a USART dynamic driver function can control any USART instance, depending on which instance you pass into the function.
MHC also uses USART peripheral libraries to configure the specific peripherals you selected to use for each driver instance.
USART Data Transfer Model | DMA? |
---|---|
Byte by Byte | No |
File I/O Read/Write | No |
File I/O Read/Write with Buffer Queue | No |
Buffer Queue | No |
Buffer Queue with DMA | Yes |
Unlike the USART static drivers, the dynamic drivers provide three different data transfer models:
- Byte by Byte
- Transfer data through USART driver one byte at a time.
- File I/O Read/Write
- Can process a block of data using read and write functions. Depending on the mode (blocking or non-blocking) in which the client opened the driver, the driver will either block until all of the data is transferred (only if using a Real-Time Operating System (RTOS)) or will immediately return with the number of bytes transferred.
- Buffer Queue
- Allows clients to queue data transfers for processing. The driver returns a buffer handle for a queued request. Clients can track the completion of a buffer through events and the Application Programming Interface (API.)
You configure the USART dynamic drivers using the selections provided by MHC. These drivers are created when you press MHC "Generate" button. MHC's first step in this process is to create USART driver configuration macros based on your selections.
Next, MHC uses these macros to create the USART driver initialization structures.
The last job MHC performs for you is to initialize the USART dynamic driver object structures.
Using USART Dynamic Drivers
Once the driver is initialized, it must be "opened" by a client before it can be used.
You must do the following:
- Create a handle (pointer) for a client to use with a USART driver instance.
- Open a client for a specific USART Driver instance and assign the handle to it.
Opening a Client for a USART dynamic driver
Two parameters are passed into this USART open function:
- Specific USART instance to open.
- How you want to use the USART (I/O Intent.)
The I/O Intent parameter is used for all dynamic drivers and defines how the client interacts with the driver instance. It defines the intended usage or desired behavior of the device driver.
Once this handle has been assigned to a specific USART driver instance, it must be passed into the library functions to control that instance.
Using the USART dynamic driver
You do not need to understand how MHC creates dynamic drivers to use them. If you want these details, click the following button. For a higher-level understanding of how to use USART dynamic drivers, click on the "Harmony USART Tutorial" button below.