Kinetis SDK v.1.3 API Reference Manual  Rev. 0
Freescale Semiconductor, Inc.
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages

Overview

This section describes the programming interface of the XBAR Peripheral driver.

Overview

The XBAR peripheral driver configures the XBAR (Inter-Peripheral Crossbar Switch) and handles initialization and configuration of the XBAR module.

CMP Driver model building

XBAR driver has two parts:

Initialization

To initialize the XBAR driver, a state structure has to be passed into the initialization function. This block of memory keeps pointers to user's callback functions and parameters to these functions. The XBAR module is initialized by calling the XBAR_DRV_Init() function.

Call diagram

  1. Call the "XBAR_DRV_Init()" function to initialize the XBAR module. A state structure of the "xbar_state_t" type has to be defined and passed into this function.
  2. Optionally, call the "XBAR_DRV_ConfigOutControl()" function to set the active edge features, such interrupts or DMA requests. A configuration structure of the "xbar_control_config_t" type is required.
  3. Optionally, call the "XBAR_DRV_InstallCallback" function to install user's callback function. A pointer to the function of the "xbar_callback_t" type and pointer to a void parameter is required. When the XBAR is configured to enable the interrupt, the installed callback function is called after the interrupt event occurs.
  4. Call the "XBAR_DRV_ConfigSignalConnection" function to connect the desired signals.
  5. Finally, the XBAR works properly.

These are the examples to initialize and configure the XBAR driver for typical use cases.

Interrupt Mode:

// xbat_test.c //
#include <stdio.h>
#include <stdlib.h>
#include "board.h"
#include "fsl_debug_console.h"
#include "fsl_xbar_driver.h"
void configure_xbar_test_pins(void);
/* User's callback function
void xbar_callback(void * param);
int main (void)
{
hardware_init();
dbg_uart_init();
printf("XBAR PD TEST: Start...\r\n");
configure_xbar_test_pins();
xbar_state_t xbarStateStruct;
/* Init the XBAR module
XBAR_DRV_Init(&xbarStateStruct);
uint32_t outIndex = 0;
/* Configurate am interrupt request on XBAR output 0 and install callback function
xbar_control_config_t xbarConfigStruct;
xbarConfigStruct.activeEdge = kXbarEdgeFalling;
xbarConfigStruct.intDmaReq = kXbarReqIen;
char msg[] = "The button is pressed";
XBAR_DRV_ConfigOutControl(outIndex, &xbarConfigStruct);
XBAR_DRV_InstallCallback(outIndex, xbar_callback, msg);
/* Configurate interperipheral signal connections.
XBAR_DRV_ConfigSignalConnection(kXbaraInputXBAR_IN2, kXbaraOutputXB_OUT6);
XBAR_DRV_ConfigSignalConnection(kXbaraInputXBAR_IN2, kXbaraOutputDMAreqOrInt);
while(1);
XBAR_DRV_Deinit();
printf("XBAR PD Test ");
printf("Succeed\r\n");
}
void xbar_callback(void * param){
char * strin = (char *)param;
printf("%s\n", strin);
}
void configure_xbar_test_pins(void){
PORT_HAL_SetMuxMode(PORTF_BASE, 1u, kPortMuxAlt3);
PORT_HAL_SetMuxMode(PORTD_BASE, 0u, kPortMuxAlt3);
}

Polling Mode:

// xbar_test_polling.c //
#include <stdio.h>
#include <stdlib.h>
#include "board.h"
#include "fsl_debug_console.h"
#include "fsl_xbar_driver.h"
void configure_xbar_test_pins(void);
int main (void)
{
hardware_init();
dbg_uart_init();
printf("XBAR PD TEST: Start...\r\n");
configure_xbar_test_pins();
xbar_state_t xbarStateStruct;
/* Init the XBAR module
XBAR_DRV_Init(&xbarStateStruct);
uint32_t outIndex = 0;
/* Configurate an interrupt request on XBAR output 0
xbar_control_config_t xbarConfigStruct;
xbarConfigStruct.activeEdge = kXbarEdgeRising;
xbarConfigStruct.intDmaReq = kXbarReqDis;
XBAR_DRV_ConfigOutControl(outIndex, &xbarConfigStruct);
/* Configurate interperipheral signal connections.
XBAR_DRV_ConfigSignalConnection(kXbaraInputXBAR_IN2, kXbaraOutputXB_OUT6);
XBAR_DRV_ConfigSignalConnection(kXbaraInputXBAR_IN2, kXbaraOutputDMAreqOrInt);
while(1)
{
if(XBAR_DRV_GetEdgeDetectionStatus(outIndex))
{
printf("The button is pressed\n");
XBAR_DRV_ClearEdgeDetectionStatus(outIndex);
}
}
XBAR_DRV_Deinit();
printf("XBAR PD Test ");
printf("Succeed\r\n");
}
void configure_xbar_test_pins(void){
PORT_HAL_SetMuxMode(PORTF_BASE, 1u, kPortMuxAlt3);
PORT_HAL_SetMuxMode(PORTD_BASE, 0u, kPortMuxAlt3);
}

Data Structures

struct  xbar_control_config_t
 Defines the configuration structure of the XBAR control register. More...
 
struct  xbar_state_t
 Internal driver state information. More...
 

Macros

#define XBARA_MODULE   0U
 Macro defines XBARA module number.
 
#define XBARB_MODULE   1U
 Macro defines XBARB module number.
 

Typedefs

typedef void(* xbar_callback_t )(void *param)
 Defines the type of the user-defined callback function. More...
 

Enumerations

enum  xbar_ien_den_req_t {
  kXbarReqDis = 0U,
  kXbarReqIen = 1U,
  kXbarReqDen = 2U
}
 Defines the XBAR DMA and interrupt configurations. More...
 

Functions

xbar_status_t XBAR_DRV_Init (xbar_state_t *xbarStatePtr)
 Initializes the XBAR modules. More...
 
void XBAR_DRV_Deinit (void)
 Deinitializes the XBAR module. More...
 
xbar_status_t XBAR_DRV_ConfigSignalConnection (xbar_input_signal_t input, xbar_output_signal_t output)
 Configures connection between the selected XBAR_IN[*] input and the XBAR_OUT[*] output signal. More...
 
xbar_status_t XBAR_DRV_ConfigOutControl (uint32_t outIndex, const xbar_control_config_t *controlConfigPtr)
 Configures the XBAR control register. More...
 
bool XBAR_DRV_GetEdgeDetectionStatus (uint32_t outIndex)
 Gets the active edge detection status. More...
 
xbar_status_t XBAR_DRV_ClearEdgeDetectionStatus (uint32_t outIndex)
 Clears the status flag of the edge detection status flag for a desired XBAR_OUT. More...
 
xbar_status_t XBAR_DRV_InstallCallback (uint32_t outIndex, xbar_callback_t userCallback, void *callbackParam)
 Installs the callback function for the XBAR module. More...
 
void XBAR_DRV_IRQHandler (void)
 Driver-defined ISR in the XBAR module. More...
 

Variables

XBARA_Type *const g_xbaraBase []
 Table of base addresses for XBAR instances. More...
 
const IRQn_Type g_xbarIrqId []
 Table to save XBAR IRQ enumeration numbers defined in the CMSIS header file. More...
 
xbar_active_edge_t xbar_control_config_t::activeEdge
 Active edge to be detected. More...
 
xbar_ien_den_req_t xbar_control_config_t::intDmaReq
 Selects DMA/Interrupt request. More...
 
xbar_callback_t xbar_state_t::userCallbackFunct [FSL_FEATURE_XBARA_INTERRUPT_COUNT]
 Keep the user-defined callback function. More...
 
void * xbar_state_t::xbarCallbackParam [FSL_FEATURE_XBARA_INTERRUPT_COUNT]
 XBAR callback parameter pointer. More...
 

Data Structure Documentation

struct xbar_control_config_t

This structure keeps the configuration of XBAR control register for one output. Control registers are available only for a few outputs. Not every XBAR module has control registers.

Data Fields

xbar_active_edge_t activeEdge
 Active edge to be detected. More...
 
xbar_ien_den_req_t intDmaReq
 Selects DMA/Interrupt request. More...
 
struct xbar_state_t

The contents of this structure are internal to the driver and should not be modified by users.

Data Fields

xbar_callback_t userCallbackFunct [FSL_FEATURE_XBARA_INTERRUPT_COUNT]
 Keep the user-defined callback function. More...
 
void * xbarCallbackParam [FSL_FEATURE_XBARA_INTERRUPT_COUNT]
 XBAR callback parameter pointer. More...
 

Typedef Documentation

typedef void(* xbar_callback_t)(void *param)

A prototype for the callback function registered into the XBAR driver.

Enumeration Type Documentation

Defines the XBAR DMA and interrupt configurations.

Enumerator
kXbarReqDis 

Interrupt and DMA are disabled.

kXbarReqIen 

Interrupt enabled, DMA disabled.

kXbarReqDen 

DMA enabled, interrupt disabled.

Function Documentation

xbar_status_t XBAR_DRV_Init ( xbar_state_t xbarStatePtr)

This function initializes the XBAR module to a reset state.

Parameters
xbarStatePtrXBAR input signal.
Returns
An error code or kStatus_XBAR_Success.
void XBAR_DRV_Deinit ( void  )

This function clears all configurations and shuts down the XBAR by disabling interrupt and the clock signal to the modules.

xbar_status_t XBAR_DRV_ConfigSignalConnection ( xbar_input_signal_t  input,
xbar_output_signal_t  output 
)

This function configures which XBAR input is connected to the selected XBAR output. If more than one XBAR module is available, only the inputs and outputs from the same module can be connected.

Example:

// Configure connection between XBARA_OUT16(CMP0) output and XBARA_IN1(VDD) input.
status = XBARA_HAL_ConfigSignalConnection(kXbaraInputVDD, kXbaraOutputCMP0);
switch (status)
{
//...
}
Parameters
inputXBAR input signal.
outputXBAR output signal.
Returns
An error code or kStatus_XBAR_Success.
xbar_status_t XBAR_DRV_ConfigOutControl ( uint32_t  outIndex,
const xbar_control_config_t controlConfigPtr 
)

This function configures an XBAR control register. The active edge detection and the DMA/IRQ function on the corresponding XBAR output can be set.

Example:

// Set the DMA function on XBAR_OUT2 to rising and falling active edges.
controlOut2.intDmaReq = kXbarReqDen;
status = XBAR_DRV_ConfigOutControl(2, controlOut2);
switch (status)
{
//...
}
Parameters
outIndexXBAR output number.
controlConfigPtrPointer to structure that keeps configuration of control register.
Returns
An error code or kStatus_XBAR_Success.
bool XBAR_DRV_GetEdgeDetectionStatus ( uint32_t  outIndex)

This function gets the active edge detect status of the desired XBAR_OUT. If the active edge occurs, the return value is asserted. When the interrupt or the DMA functionality is enabled for the XBAR_OUTx, this field is 1 when the interrupt or DMA request is asserted and 0 when the interrupt or DMA request has been cleared.

Parameters
outIndexXBAR output number.
Returns
Assertion of edge detection status.
xbar_status_t XBAR_DRV_ClearEdgeDetectionStatus ( uint32_t  outIndex)

This function clears the status flag of edge detection status flag of the XBAR_OUTx.

Parameters
outIndexXBAR output number.
Returns
An error code or kStatus_XBAR_Success.
xbar_status_t XBAR_DRV_InstallCallback ( uint32_t  outIndex,
xbar_callback_t  userCallback,
void *  callbackParam 
)

This function installs the user-defined callback. When the XBAR interrupt request is configured, the callback is executed inside the ISR.

Parameters
outIndexXBAR output number.
userCallbackUser-defined callback function.
callbackParamThe XBAR callback parameter pointer.
Returns
An error code or kStatus_XBAR_Success.
void XBAR_DRV_IRQHandler ( void  )

This function is the driver-defined ISR in the XBAR module. It includes the process for interrupt mode defined by the driver. Currently, it is called inside the system-defined ISR.

Variable Documentation

XBARA_Type* const g_xbaraBase[]
const IRQn_Type g_xbarIrqId[]
xbar_active_edge_t xbar_control_config_t::activeEdge
xbar_ien_den_req_t xbar_control_config_t::intDmaReq
xbar_callback_t xbar_state_t::userCallbackFunct[FSL_FEATURE_XBARA_INTERRUPT_COUNT]
void* xbar_state_t::xbarCallbackParam[FSL_FEATURE_XBARA_INTERRUPT_COUNT]