INTERCONNECT (Internal digital routing)¶
-
group
group_hal_interconnect
High level interface to the Cypress digital routing.
Features
Facilities for runtime manipulation of the on chip routing. The following types of connections are supported:
Connection from a peripheral to a pin. (A dedicated connection must exist between the pin and the peripheral; see the device datasheet for more details)
Connecting two peripherals in hardware using the on-chip trigger signaling
Quick Start
cyhal_connect_pin can be used to connect a pin to a peripheral.(A dedicated connection must exist between the pin and the peripheral; see the device datasheet for more details)
cyhal_disconnect_pin can be used to disconnect a pin from a peripheral. The drive mode will be reset to High-Z after disconnecting
Code Snippets
Snippet 1: Connecting a pin to TCPWM block
The following code snippet demonstrates connecting a GPIO pin to an active TCPWM block on a device using the cyhal_connect_pin. It is assumed that the TCPWM is already configured and active.
// Find out the resource block that connects the specified pins from the provided resource pin // mapping table cyhal_pin_map_tcpwm_line. This example connects the pin to the TCPWM line pin const cyhal_resource_pin_mapping_t* map = _CYHAL_UTILS_GET_RESOURCE(P2_4, cyhal_pin_map_tcpwm_line); // Obtain the GPIO pin resource cyhal_resource_inst_t pin_rsc = _cyhal_utils_get_gpio_resource(P2_4); // Reserve the resource in hardware manager to prevent other HAL blocks from using it cy_rslt_t status = cyhal_hwmgr_reserve(&pin_rsc); if (CY_RSLT_SUCCESS == status) { // The resource is free, connect it to the block status = cyhal_connect_pin(map); if (CY_RSLT_SUCCESS != status) { cyhal_hwmgr_free(&pin_rsc); } }
Snippet 2: Connecting a Timer output signal to a DMA input signal
The following code snippet demonstrates configuring and connecting a Timer which will overflow every 2 seconds and, in doing so, trigger a DMA channel start.
cyhal_source_t timer_source; cyhal_dma_t dma; cyhal_timer_t timer; uint32_t src_arr[] = { 100, 200 }; uint32_t dst_arr[] = { 0, 0 }; const cyhal_timer_cfg_t timer_cfg = { .compare_value = 0, .period = 20000, .direction = CYHAL_TIMER_DIR_UP, .is_compare = false, .is_continuous = true, .value = 0 }; const cyhal_dma_cfg_t dma_cfg = { .src_addr = (uint32_t)src_arr, .src_increment = 1, .dst_addr = (uint32_t)dst_arr, .dst_increment = 1, .transfer_width = 32, .length = 2, .burst_size = 0, .action = CYHAL_DMA_TRANSFER_FULL, }; // Configure simple dma transfer from src_arr to dst_arr cyhal_dma_init(&dma, CYHAL_DMA_PRIORITY_DEFAULT, CYHAL_DMA_DIRECTION_MEM2MEM); cyhal_dma_configure(&dma, &dma_cfg); // Setup timer to run continously, overflowing every 2 seconds cyhal_timer_init(&timer, NC, NULL); cyhal_timer_configure(&timer, &timer_cfg); cyhal_timer_set_frequency(&timer, 10000); // Connect timer overflow trigger to DMA start cyhal_timer_enable_output(&timer, CYHAL_TIMER_OUTPUT_OVERFLOW, &timer_source); cyhal_dma_connect_digital(&dma, timer_source, CYHAL_DMA_INPUT_TRIGGER_ALL_ELEMENTS); // Once timer is started, a DMA transfer will be triggered every 2 seconds (when the timer // overflows) until the connection is disabled. cyhal_timer_start(&timer); // Disable the connection cyhal_timer_disable_output(&timer, CYHAL_TIMER_OUTPUT_OVERFLOW); cyhal_dma_disconnect_digital(&dma, timer_source, CYHAL_DMA_INPUT_TRIGGER_ALL_ELEMENTS); cyhal_timer_free(&timer); cyhal_dma_free(&dma);
Functions
-
cy_rslt_t
cyhal_connect_pin
(const cyhal_resource_pin_mapping_t *pin_connection)¶ Connect a pin to a peripheral terminal.
This will route a direct connection from the pin to the peripheral. Any previous direct connection from the pin will be overriden.
See
Snippet 1: Connecting a pin to TCPWM block- Parameters
pin_connection – [in] The pin and target peripheral terminal to be connected
- Returns
The status of the connect request
-
cy_rslt_t
cyhal_disconnect_pin
(cyhal_gpio_t pin)¶ Disconnect a peripheral from a pin.
This will also reset the pin’s drive mode to High-Z.
- Parameters
pin – [in] The pin to be disconnected
- Returns
The status of the disconnect request