1.1.9.4.1 DRV_USART_Initialize Function

C

SYS_MODULE_OBJ DRV_USART_Initialize
(
    const SYS_MODULE_INDEX index,
    const SYS_MODULE_INIT * const init
)

Summary

Initializes the USART instance for the specified driver index.

Description

This routine initializes the USART driver instance for the specified driver index, making it ready for clients to open and use it. The initialization data is specified by the init parameter. The initialization may fail if the number of driver objects allocated are insufficient or if the specified driver instance is already initialized. The driver instance index is independent of the USART module ID. For example, driver instance 0 can be assigned to USART2.

Precondition

None.

Parameters

ParamDescription
indexIdentifier for the instance to be initialized
initPointer to the init data structure containing any data necessary to initialize the driver.

Returns

If successful, returns a valid handle to a driver instance object. Otherwise, returns SYS_MODULE_OBJ_INVALID.

Example

// The following code snippet shows an example USART driver initialization.

SYS_MODULE_OBJ objectHandle;

const DRV_USART_PLIB_INTERFACE drvUsart0PlibAPI = {
    .readCallbackRegister = (DRV_USART_PLIB_READ_CALLBACK_REG)USART1_ReadCallbackRegister,
    .read = (DRV_USART_PLIB_READ)USART1_Read,
    .readIsBusy = (DRV_USART_PLIB_READ_IS_BUSY)USART1_ReadIsBusy,
    .readCountGet = (DRV_USART_PLIB_READ_COUNT_GET)USART1_ReadCountGet,
    .writeCallbackRegister = (DRV_USART_PLIB_WRITE_CALLBACK_REG)USART1_WriteCallbackRegister,
    .write = (DRV_USART_PLIB_WRITE)USART1_Write,
    .writeIsBusy = (DRV_USART_PLIB_WRITE_IS_BUSY)USART1_WriteIsBusy,
    .writeCountGet = (DRV_USART_PLIB_WRITE_COUNT_GET)USART1_WriteCountGet,
    .errorGet = (DRV_USART_PLIB_ERROR_GET)USART1_ErrorGet,
    .serialSetup = (DRV_USART_PLIB_SERIAL_SETUP)USART1_SerialSetup
};

const DRV_USART_INIT drvUsart0InitData = {
    .usartPlib = &drvUsart0PlibAPI,
    .numClients = DRV_USART_CLIENTS_NUMBER_IDX0,
    .clientObjPool = (uintptr_t)&drvUSART0ClientObjPool[0],
    .dmaChannelTransmit = DRV_USART_XMIT_DMA_CH_IDX0,
    .usartTransmitAddress = (void *)&(USART1_REGS->US_THR),
    .dmaChannelReceive = DRV_USART_RCV_DMA_CH_IDX0,
    .usartReceiveAddress = (void *)&(USART1_REGS->US_RHR),
    .bufferObjPoolSize = DRV_USART_QUEUE_SIZE_IDX0,
    .bufferObjPool = (uintptr_t)&drvUSART0BufferObjPool[0],
    .interruptUSART = USART1_IRQn,
    .interruptDMA = XDMAC_IRQn,
    .remapDataWidth = drvUsart0remapDataWidth,
    .remapParity = drvUsart0remapParity,
    .remapStopBits = drvUsart0remapStopBits,
    .remapError = drvUsart0remapError,
};

objectHandle = DRV_USART_Initialize(DRV_USART_INDEX_1, (SYS_MODULE_INIT*)&drvUsart0InitData);

if (objectHandle == SYS_MODULE_OBJ_INVALID)
{
    // Handle error
}

Remarks

This routine must be called before any other USART routine is called.

This routine should only be called once during system initialization. This routine will NEVER block for hardware access.