Lines Matching refs:obj
73 …dioss_length_to_pdl(uint8_t user_length, cy_en_i2s_len_t *pdl_length, const _cyhal_audioss_t *obj);
250 …udioss_length_to_pdl(uint8_t user_length, cy_en_tdm_ws_t *pdl_length, const _cyhal_audioss_t *obj);
391 static void _cyhal_audioss_update_enabled_events(_cyhal_audioss_t* obj);
392 static void _cyhal_audioss_process_event(_cyhal_audioss_t *obj, uint32_t event);
394 static void _cyhal_audioss_update_rx_trigger_level(_cyhal_audioss_t* obj);
395 static uint32_t _cyhal_audioss_read_fifo(_cyhal_audioss_t *obj);
397 static cy_rslt_t _cyhal_audioss_dma_perform_rx(_cyhal_audioss_t *obj);
401 static uint32_t _cyhal_audioss_disable_events(_cyhal_audioss_t *obj, bool tx);
402 static void _cyhal_audioss_restore_events(_cyhal_audioss_t *obj, bool tx, uint32_t old_events);
404 static cy_rslt_t _cyhal_audioss_dma_perform_tx(_cyhal_audioss_t *obj);
406 static uint8_t _cyhal_audioss_rounded_word_length(_cyhal_audioss_t *obj, bool is_tx);
409 static cy_rslt_t _cyhal_audioss_populate_pdl_config(_cyhal_audioss_t *obj, _cyhal_audioss_pdl_confi…
413 static void _cyhal_audioss_reconstruct_pdl_config(_cyhal_audioss_t *obj, _cyhal_audioss_pdl_config_…
414 static cy_rslt_t _cyhal_audioss_compute_sclk_div(_cyhal_audioss_t *obj, uint32_t sample_rate_hz, ui…
415 static uint32_t _cyhal_audioss_get_num_in_fifo(_cyhal_audioss_t *obj, bool is_tx);
416 static void _cyhal_audioss_write_fifo(_cyhal_audioss_t *obj, uint32_t value);
418 cy_rslt_t _cyhal_audioss_init_clock(_cyhal_audioss_t *obj, const cyhal_clock_t* clk, bool all_mclk) in _cyhal_audioss_init_clock() argument
423 obj->clock = *clk; in _cyhal_audioss_init_clock()
430 …result = _cyhal_utils_allocate_clock(&(obj->clock), &(obj->resource), CYHAL_CLOCK_BLOCK_PERIPHERAL… in _cyhal_audioss_init_clock()
433 obj->is_clock_owned = true; in _cyhal_audioss_init_clock()
434 result = cyhal_clock_set_enabled(&(obj->clock), true, true); in _cyhal_audioss_init_clock()
440 bool any_mclk = (0u != obj->mclk_hz_tx); in _cyhal_audioss_init_clock()
442 any_mclk = any_mclk || (0u != obj->mclk_hz_rx); in _cyhal_audioss_init_clock()
444 if (CY_RSLT_SUCCESS == result && false == any_mclk && obj->clock.block != CYHAL_CLOCK_BLOCK_HF) in _cyhal_audioss_init_clock()
446 en_clk_dst_t pclk = _cyhal_audioss_clock[obj->resource.block_num]; in _cyhal_audioss_init_clock()
447 if (CY_SYSCLK_SUCCESS != _cyhal_utils_peri_pclk_assign_divider(pclk, &(obj->clock))) in _cyhal_audioss_init_clock()
448 result = obj->interface->err_clock; in _cyhal_audioss_init_clock()
455 cy_rslt_t _cyhal_audioss_init_pdl(_cyhal_audioss_t *obj, const _cyhal_audioss_pdl_config_t* pdl_con… in _cyhal_audioss_init_pdl() argument
457 cy_rslt_t result = (cy_rslt_t)Cy_I2S_Init(obj->base, pdl_config); in _cyhal_audioss_init_pdl()
465 Cy_AudioTDM_EnableTx(&obj->base->TDM_TX_STRUCT); in _cyhal_audioss_init_pdl()
469 Cy_AudioTDM_EnableRx(&obj->base->TDM_RX_STRUCT); in _cyhal_audioss_init_pdl()
476 cy_rslt_t _cyhal_audioss_init_hw(_cyhal_audioss_t *obj, const _cyhal_audioss_pdl_config_t* pdl_conf… in _cyhal_audioss_init_hw() argument
478 uint8_t tdm_inst = obj->resource.block_num; in _cyhal_audioss_init_hw()
480 obj->base = _cyhal_audioss_base[obj->resource.block_num]; in _cyhal_audioss_init_hw()
483 tdm_inst = obj->resource.channel_num; in _cyhal_audioss_init_hw()
485 …obj->base = &(_cyhal_audioss_base[obj->resource.block_num]->TDM_STRUCT[obj->resource.channel_num]); in _cyhal_audioss_init_hw()
488 cy_rslt_t result = _cyhal_audioss_init_pdl(obj, pdl_config); in _cyhal_audioss_init_hw()
493 obj->user_fifo_level_rx = pdl_config->rxFifoTriggerLevel; in _cyhal_audioss_init_hw()
495 obj->user_fifo_level_rx = pdl_config->rx_config->fifoTriggerLevel; in _cyhal_audioss_init_hw()
505 Cy_I2S_ClearTxFifo(obj->base); in _cyhal_audioss_init_hw()
509 Cy_I2S_ClearRxFifo(obj->base); in _cyhal_audioss_init_hw()
512 Cy_I2S_ClearTxFifo(obj->base); in _cyhal_audioss_init_hw()
516 …obj->pm_callback.states = (cyhal_syspm_callback_state_t)(CYHAL_SYSPM_CB_CPU_DEEPSLEEP | CYHAL_SYSP… in _cyhal_audioss_init_hw()
517 obj->pm_callback.callback = &_cyhal_audioss_pm_callback; in _cyhal_audioss_init_hw()
518 obj->pm_callback.next = NULL; in _cyhal_audioss_init_hw()
519 obj->pm_callback.args = (void*)obj; in _cyhal_audioss_init_hw()
520 …obj->pm_callback.ignore_modes = (cyhal_syspm_callback_mode_t)(CYHAL_SYSPM_BEFORE_TRANSITION | CYHA… in _cyhal_audioss_init_hw()
521 obj->pm_transition_ready = false; in _cyhal_audioss_init_hw()
523 _cyhal_syspm_register_peripheral_callback(&(obj->pm_callback)); in _cyhal_audioss_init_hw()
525 _cyhal_audioss_config_structs[tdm_inst] = obj; in _cyhal_audioss_init_hw()
531 Cy_AudioTDM_RegisterInterruptCallback(obj->base, _cyhal_audioss_irq_handler); in _cyhal_audioss_init_hw()
532 Cy_AudioTDM_EnableInterrupt(obj->base); // Enables both TX and RX in _cyhal_audioss_init_hw()
548 cy_rslt_t _cyhal_audioss_init(_cyhal_audioss_t *obj, const _cyhal_audioss_pins_t* tx_pins, const _c… in _cyhal_audioss_init() argument
550 CY_ASSERT(NULL != obj); in _cyhal_audioss_init()
552 memset(obj, 0, sizeof(_cyhal_audioss_t)); in _cyhal_audioss_init()
554 obj->resource.type = CYHAL_RSC_INVALID; in _cyhal_audioss_init()
555 obj->pin_tx_sck = CYHAL_NC_PIN_VALUE; in _cyhal_audioss_init()
556 obj->pin_tx_ws = CYHAL_NC_PIN_VALUE; in _cyhal_audioss_init()
557 obj->pin_tx_sdo = CYHAL_NC_PIN_VALUE; in _cyhal_audioss_init()
558 obj->pin_tx_mclk = CYHAL_NC_PIN_VALUE; in _cyhal_audioss_init()
560 obj->pin_rx_sck = CYHAL_NC_PIN_VALUE; in _cyhal_audioss_init()
561 obj->pin_rx_ws = CYHAL_NC_PIN_VALUE; in _cyhal_audioss_init()
562 obj->pin_rx_sdi = CYHAL_NC_PIN_VALUE; in _cyhal_audioss_init()
563 obj->pin_rx_mclk = CYHAL_NC_PIN_VALUE; in _cyhal_audioss_init()
566 obj->interface = interface; in _cyhal_audioss_init()
567 obj->channel_length_tx = config->channel_length; in _cyhal_audioss_init()
568 obj->word_length_tx = config->word_length; in _cyhal_audioss_init()
570 obj->channel_length_rx = config->channel_length; in _cyhal_audioss_init()
571 obj->word_length_rx = config->word_length; in _cyhal_audioss_init()
578 obj->is_clock_owned = false; in _cyhal_audioss_init()
580 obj->user_enabled_events = 0u; in _cyhal_audioss_init()
582 obj->callback_data.callback = NULL; in _cyhal_audioss_init()
583 obj->callback_data.callback_arg = NULL; in _cyhal_audioss_init()
584 obj->async_mode = CYHAL_ASYNC_SW; in _cyhal_audioss_init()
585 obj->async_tx_buff = NULL; in _cyhal_audioss_init()
587 obj->async_rx_buff = NULL; in _cyhal_audioss_init()
589 obj->tx_dma.resource.type = CYHAL_RSC_INVALID; in _cyhal_audioss_init()
591 obj->rx_dma.resource.type = CYHAL_RSC_INVALID; in _cyhal_audioss_init()
626 result = obj->interface->err_invalid_pin; in _cyhal_audioss_init()
658 _CYHAL_UTILS_ASSIGN_RESOURCE(obj->resource, rsc_type, tx_sck_map); in _cyhal_audioss_init()
662 result = obj->interface->err_invalid_pin; in _cyhal_audioss_init()
672 result = obj->interface->err_invalid_pin; in _cyhal_audioss_init()
676 if((obj->resource.type != CYHAL_RSC_INVALID) in _cyhal_audioss_init()
677 && (false == _cyhal_utils_map_resource_equal(&(obj->resource), rx_sck_map, false))) in _cyhal_audioss_init()
680 result = obj->interface->err_invalid_pin; in _cyhal_audioss_init()
682 _CYHAL_UTILS_ASSIGN_RESOURCE(obj->resource, rsc_type, rx_sck_map); in _cyhal_audioss_init()
687 …if(CYHAL_RSC_INVALID == obj->resource.type) /* If this happens it means neither rx nor tx was spec… in _cyhal_audioss_init()
689 result = obj->interface->err_invalid_pin; in _cyhal_audioss_init()
694 …if(NULL == mclk_map_rx || (false == _cyhal_utils_map_resource_equal(&(obj->resource), mclk_map_rx,… in _cyhal_audioss_init()
696 result = obj->interface->err_invalid_pin; in _cyhal_audioss_init()
702 …if(NULL == mclk_map_tx || (false == _cyhal_utils_map_resource_equal(&(obj->resource), mclk_map_tx,… in _cyhal_audioss_init()
704 result = obj->interface->err_invalid_pin; in _cyhal_audioss_init()
711 const uint8_t MAX_CHANNELS = _cyhal_audioss_max_channels[obj->resource.block_num]; in _cyhal_audioss_init()
715 result = obj->interface->err_invalid_arg; in _cyhal_audioss_init()
726 result = obj->interface->err_invalid_arg; in _cyhal_audioss_init()
734 result = cyhal_hwmgr_reserve(&(obj->resource)); in _cyhal_audioss_init()
741 obj->resource.type = CYHAL_RSC_INVALID; in _cyhal_audioss_init()
759 obj->pin_tx_sck = tx_pins->sck; in _cyhal_audioss_init()
764 obj->pin_tx_ws = tx_pins->ws; in _cyhal_audioss_init()
769 obj->pin_tx_sdo = tx_pins->data; in _cyhal_audioss_init()
775 … result = cyhal_gpio_configure(obj->pin_tx_sck, CYHAL_GPIO_DIR_INPUT, CYHAL_GPIO_DRIVE_NONE); in _cyhal_audioss_init()
778 … result = cyhal_gpio_configure(obj->pin_tx_ws, CYHAL_GPIO_DIR_INPUT, CYHAL_GPIO_DRIVE_NONE); in _cyhal_audioss_init()
793 obj->pin_rx_sdi = rx_pins->data; in _cyhal_audioss_init()
794 obj->pin_rx_sck = rx_pins->sck; // The SCK and WS are tied to the TX on this device in _cyhal_audioss_init()
795 obj->pin_rx_ws = rx_pins->ws; in _cyhal_audioss_init()
800 obj->pin_rx_sdi = rx_pins->data; in _cyhal_audioss_init()
805 obj->pin_rx_sck = rx_pins->sck; in _cyhal_audioss_init()
810 obj->pin_rx_ws = rx_pins->ws; in _cyhal_audioss_init()
816 … result = cyhal_gpio_configure(obj->pin_rx_sck, CYHAL_GPIO_DIR_INPUT, CYHAL_GPIO_DRIVE_NONE); in _cyhal_audioss_init()
819 … result = cyhal_gpio_configure(obj->pin_rx_ws, CYHAL_GPIO_DIR_INPUT, CYHAL_GPIO_DRIVE_NONE); in _cyhal_audioss_init()
833 result = obj->interface->err_invalid_arg; in _cyhal_audioss_init()
843 obj->pin_rx_mclk = mclk_map_rx->pin; in _cyhal_audioss_init()
844 obj->mclk_hz_rx = config->mclk_hz; in _cyhal_audioss_init()
857 obj->pin_tx_mclk = mclk_map_tx->pin; in _cyhal_audioss_init()
858 obj->mclk_hz_tx = config->mclk_hz; in _cyhal_audioss_init()
869 result = obj->interface->err_invalid_arg; in _cyhal_audioss_init()
874 if(CY_RSLT_SUCCESS == result && obj->word_length_tx > obj->channel_length_tx) in _cyhal_audioss_init()
877 result = obj->interface->err_invalid_arg; in _cyhal_audioss_init()
880 if(CY_RSLT_SUCCESS == result && obj->channel_length_tx > _CYHAL_AUDIOSS_MAX_CHANNEL_LENGTH) in _cyhal_audioss_init()
886 result = obj->interface->err_invalid_arg; in _cyhal_audioss_init()
894 result = _cyhal_audioss_init_clock(obj, clk, all_mclk); in _cyhal_audioss_init()
902 …result = _cyhal_audioss_compute_sclk_div(obj, config->sample_rate_hz, obj->mclk_hz_rx, obj->channe… in _cyhal_audioss_init()
907 …result = _cyhal_audioss_compute_sclk_div(obj, config->sample_rate_hz, obj->mclk_hz_tx, obj->channe… in _cyhal_audioss_init()
920 bool tx_en = (CYHAL_NC_PIN_VALUE != obj->pin_tx_sdo); in _cyhal_audioss_init()
921 bool tx_mclk = (CYHAL_NC_PIN_VALUE != obj->pin_tx_mclk); in _cyhal_audioss_init()
923 bool rx_en = (CYHAL_NC_PIN_VALUE != obj->pin_rx_sdi); in _cyhal_audioss_init()
924 bool rx_mclk = (CYHAL_NC_PIN_VALUE != obj->pin_rx_mclk); in _cyhal_audioss_init()
929 …result = _cyhal_audioss_populate_pdl_config(obj, &pdl_config, config, sclk_div_rx, sclk_div_tx, rx… in _cyhal_audioss_init()
934 result = _cyhal_audioss_init_hw(obj, &pdl_config); in _cyhal_audioss_init()
939 _cyhal_audioss_free(obj); in _cyhal_audioss_init()
944 cy_rslt_t _cyhal_audioss_init_cfg(_cyhal_audioss_t *obj, const _cyhal_audioss_configurator_t *cfg, … in _cyhal_audioss_init_cfg() argument
946 CY_ASSERT(NULL != obj); in _cyhal_audioss_init_cfg()
948 memset(obj, 0, sizeof(_cyhal_audioss_t)); in _cyhal_audioss_init_cfg()
949 obj->owned_by_configurator = true; in _cyhal_audioss_init_cfg()
950 obj->resource = *cfg->resource; in _cyhal_audioss_init_cfg()
951 obj->mclk_hz_tx = cfg->mclk_hz_tx; in _cyhal_audioss_init_cfg()
952 obj->interface = interface; in _cyhal_audioss_init_cfg()
954 obj->async_mode = CYHAL_ASYNC_SW; in _cyhal_audioss_init_cfg()
955 obj->tx_dma.resource.type = CYHAL_RSC_INVALID; in _cyhal_audioss_init_cfg()
957 obj->channel_length_tx = _cyhal_audioss_length_from_pdl(cfg->config->txChannelLength); in _cyhal_audioss_init_cfg()
958 obj->word_length_tx = _cyhal_audioss_length_from_pdl(cfg->config->txWordLength); in _cyhal_audioss_init_cfg()
960 obj->channel_length_rx = _cyhal_audioss_length_from_pdl(cfg->config->rxChannelLength); in _cyhal_audioss_init_cfg()
961 obj->word_length_rx = _cyhal_audioss_length_from_pdl(cfg->config->rxWordLength); in _cyhal_audioss_init_cfg()
964 obj->channel_length_tx = cfg->config->tx_config->channelSize; in _cyhal_audioss_init_cfg()
965 obj->word_length_tx = _cyhal_audioss_length_from_pdl(cfg->config->tx_config->wordSize); in _cyhal_audioss_init_cfg()
966 obj->channel_length_rx = cfg->config->rx_config->channelSize; in _cyhal_audioss_init_cfg()
967 obj->word_length_rx = _cyhal_audioss_length_from_pdl(cfg->config->rx_config->wordSize); in _cyhal_audioss_init_cfg()
969 obj->pin_tx_sck = CYHAL_NC_PIN_VALUE; in _cyhal_audioss_init_cfg()
970 obj->pin_tx_ws = CYHAL_NC_PIN_VALUE; in _cyhal_audioss_init_cfg()
971 obj->pin_tx_sdo = CYHAL_NC_PIN_VALUE; in _cyhal_audioss_init_cfg()
972 obj->pin_tx_mclk = CYHAL_NC_PIN_VALUE; in _cyhal_audioss_init_cfg()
974 obj->rx_dma.resource.type = CYHAL_RSC_INVALID; in _cyhal_audioss_init_cfg()
975 obj->pin_rx_sck = CYHAL_NC_PIN_VALUE; in _cyhal_audioss_init_cfg()
976 obj->pin_rx_ws = CYHAL_NC_PIN_VALUE; in _cyhal_audioss_init_cfg()
977 obj->pin_rx_sdi = CYHAL_NC_PIN_VALUE; in _cyhal_audioss_init_cfg()
978 obj->pin_rx_mclk = CYHAL_NC_PIN_VALUE; in _cyhal_audioss_init_cfg()
982 bool all_mclk = (0u != obj->mclk_hz_tx); /* No separate rx/tx clock selection */ in _cyhal_audioss_init_cfg()
987 cy_rslt_t result = _cyhal_audioss_init_clock(obj, cfg->clock, all_mclk); in _cyhal_audioss_init_cfg()
991 result = _cyhal_audioss_init_hw(obj, cfg->config); in _cyhal_audioss_init_cfg()
996 _cyhal_audioss_free(obj); in _cyhal_audioss_init_cfg()
1001 void _cyhal_audioss_free(_cyhal_audioss_t *obj) in _cyhal_audioss_free() argument
1003 CY_ASSERT(NULL != obj); in _cyhal_audioss_free()
1005 if(CYHAL_RSC_INVALID != obj->resource.type) in _cyhal_audioss_free()
1008 _cyhal_system_irq_t irqn = _cyhal_audioss_irq_n[obj->resource.block_num]; in _cyhal_audioss_free()
1011 _cyhal_system_irq_t irqn = _cyhal_audioss_rx_irq_n[obj->resource.block_num]; in _cyhal_audioss_free()
1013 irqn = _cyhal_audioss_tx_irq_n[obj->resource.block_num]; in _cyhal_audioss_free()
1018 _cyhal_syspm_unregister_peripheral_callback(&(obj->pm_callback)); in _cyhal_audioss_free()
1021 if(NULL != obj->base) in _cyhal_audioss_free()
1024 _cyhal_audioss_stop_rx(obj); in _cyhal_audioss_free()
1026 _cyhal_audioss_stop_tx(obj); in _cyhal_audioss_free()
1029 Cy_AudioTDM_DisableTx(&obj->base->TDM_TX_STRUCT); in _cyhal_audioss_free()
1030 Cy_AudioTDM_DisableRx(&obj->base->TDM_RX_STRUCT); in _cyhal_audioss_free()
1033 if(false == obj->owned_by_configurator) in _cyhal_audioss_free()
1035 cyhal_hwmgr_free(&(obj->resource)); in _cyhal_audioss_free()
1038 obj->base = NULL; in _cyhal_audioss_free()
1039 obj->resource.type = CYHAL_RSC_INVALID; in _cyhal_audioss_free()
1045 bool different_mclk = (obj->pin_rx_mclk != obj->pin_tx_mclk); in _cyhal_audioss_free()
1047 _cyhal_utils_release_if_used(&(obj->pin_tx_sck)); in _cyhal_audioss_free()
1048 _cyhal_utils_release_if_used(&(obj->pin_tx_ws)); in _cyhal_audioss_free()
1049 _cyhal_utils_release_if_used(&(obj->pin_tx_sdo)); in _cyhal_audioss_free()
1050 _cyhal_utils_release_if_used(&(obj->pin_tx_mclk)); in _cyhal_audioss_free()
1052 _cyhal_utils_release_if_used(&(obj->pin_rx_sck)); in _cyhal_audioss_free()
1053 _cyhal_utils_release_if_used(&(obj->pin_rx_ws)); in _cyhal_audioss_free()
1054 _cyhal_utils_release_if_used(&(obj->pin_rx_sdi)); in _cyhal_audioss_free()
1057 _cyhal_utils_release_if_used(&(obj->pin_rx_mclk)); in _cyhal_audioss_free()
1060 if(obj->is_clock_owned) in _cyhal_audioss_free()
1062 cyhal_clock_free(&(obj->clock)); in _cyhal_audioss_free()
1067 if(CYHAL_RSC_INVALID != obj->rx_dma.resource.type) in _cyhal_audioss_free()
1069 cyhal_dma_free(&obj->rx_dma); in _cyhal_audioss_free()
1073 if(CYHAL_RSC_INVALID != obj->tx_dma.resource.type) in _cyhal_audioss_free()
1075 cyhal_dma_free(&obj->tx_dma); in _cyhal_audioss_free()
1080 static uint8_t _cyhal_audioss_fifo_trigger_level(_cyhal_audioss_t* obj, bool is_tx) in _cyhal_audioss_fifo_trigger_level() argument
1085 ? (uint8_t)_FLD2VAL(I2S_TX_FIFO_CTL_TRIGGER_LEVEL, REG_I2S_TX_FIFO_CTL(obj->base)) in _cyhal_audioss_fifo_trigger_level()
1086 : (uint8_t)_FLD2VAL(I2S_RX_FIFO_CTL_TRIGGER_LEVEL, REG_I2S_RX_FIFO_CTL(obj->base)); in _cyhal_audioss_fifo_trigger_level()
1089 return (uint8_t)_FLD2VAL(I2S_TX_FIFO_CTL_TRIGGER_LEVEL, REG_I2S_TX_FIFO_CTL(obj->base)); in _cyhal_audioss_fifo_trigger_level()
1093 …DM_STRUCT_TDM_TX_STRUCT_TX_FIFO_CTL_TRIGGER_LEVEL, TDM_STRUCT_TX_FIFO_CTL(&obj->base->TDM_TX_STRUC… in _cyhal_audioss_fifo_trigger_level()
1094 …DM_STRUCT_TDM_RX_STRUCT_RX_FIFO_CTL_TRIGGER_LEVEL, TDM_STRUCT_RX_FIFO_CTL(&obj->base->TDM_RX_STRUC… in _cyhal_audioss_fifo_trigger_level()
1098 static bool _cyhal_audioss_is_direction_enabled(_cyhal_audioss_t *obj, bool is_tx) in _cyhal_audioss_is_direction_enabled() argument
1102 ? (0u != (REG_I2S_CTL(obj->base) & I2S_CTL_TX_ENABLED_Msk)) in _cyhal_audioss_is_direction_enabled()
1103 : (0u != (REG_I2S_CTL(obj->base) & I2S_CTL_RX_ENABLED_Msk)); in _cyhal_audioss_is_direction_enabled()
1106 …? (0u != (TDM_STRUCT_TX_CTL(&obj->base->TDM_TX_STRUCT) & TDM_TDM_STRUCT_TDM_TX_STRUCT_TX_CTL_ENABL… in _cyhal_audioss_is_direction_enabled()
1107 …: (0u != (TDM_STRUCT_RX_CTL(&obj->base->TDM_RX_STRUCT) & TDM_TDM_STRUCT_TDM_RX_STRUCT_RX_CTL_ENABL… in _cyhal_audioss_is_direction_enabled()
1114 static cy_rslt_t _cyhal_audioss_compute_sclk_div(_cyhal_audioss_t *obj, uint32_t sample_rate_hz, ui… in _cyhal_audioss_compute_sclk_div() argument
1130 if(obj->is_clock_owned) in _cyhal_audioss_compute_sclk_div()
1142 …cy_rslt_t freq_result = _cyhal_utils_set_clock_frequency(&(obj->clock), desired_source_freq, &SCLK… in _cyhal_audioss_compute_sclk_div()
1158 … uint32_t actual_source_freq = (0u != mclk_hz) ? mclk_hz : cyhal_clock_get_frequency(&obj->clock); in _cyhal_audioss_compute_sclk_div()
1173 return (0 == *sclk_div) ? obj->interface->err_clock : CY_RSLT_SUCCESS; in _cyhal_audioss_compute_sclk_div()
1176 cy_rslt_t _cyhal_audioss_set_sample_rate(_cyhal_audioss_t *obj, uint32_t sample_rate_hz) in _cyhal_audioss_set_sample_rate() argument
1187 _cyhal_audioss_reconstruct_pdl_config(obj, &pdl_config); in _cyhal_audioss_set_sample_rate()
1197 …cy_rslt_t result = _cyhal_audioss_compute_sclk_div(obj, sample_rate_hz, obj->mclk_hz_tx, obj->chan… in _cyhal_audioss_set_sample_rate()
1202 …result = _cyhal_audioss_compute_sclk_div(obj, sample_rate_hz, obj->mclk_hz_rx, obj->channel_length… in _cyhal_audioss_set_sample_rate()
1213 Cy_I2S_DeInit(obj->base); in _cyhal_audioss_set_sample_rate()
1215 result = _cyhal_audioss_init_pdl(obj, &pdl_config); in _cyhal_audioss_set_sample_rate()
1221 void _cyhal_audioss_enable_event(_cyhal_audioss_t *obj, uint32_t event, uint8_t intr_priority, bool… in _cyhal_audioss_enable_event() argument
1223 CY_ASSERT(NULL != obj); in _cyhal_audioss_enable_event()
1227 obj->user_enabled_events |= event; in _cyhal_audioss_enable_event()
1231 obj->user_enabled_events &= ~event; in _cyhal_audioss_enable_event()
1234 _cyhal_audioss_update_enabled_events(obj); in _cyhal_audioss_enable_event()
1236 _cyhal_system_irq_t irqn = _cyhal_audioss_irq_n[obj->resource.block_num]; in _cyhal_audioss_enable_event()
1239 _cyhal_system_irq_t irqn = _cyhal_audioss_tx_irq_n[obj->resource.block_num]; in _cyhal_audioss_enable_event()
1241 irqn = _cyhal_audioss_rx_irq_n[obj->resource.block_num]; in _cyhal_audioss_enable_event()
1246 cy_rslt_t _cyhal_audioss_start_tx(_cyhal_audioss_t *obj) in _cyhal_audioss_start_tx() argument
1248 if (obj->pm_transition_ready) in _cyhal_audioss_start_tx()
1253 Cy_I2S_EnableTx(obj->base); in _cyhal_audioss_start_tx()
1255 Cy_AudioTDM_ActivateTx(&obj->base->TDM_TX_STRUCT); in _cyhal_audioss_start_tx()
1260 cy_rslt_t _cyhal_audioss_stop_tx(_cyhal_audioss_t *obj) in _cyhal_audioss_stop_tx() argument
1263 Cy_I2S_DisableTx(obj->base); in _cyhal_audioss_stop_tx()
1266 Cy_AudioTDM_DeActivateTx(&obj->base->TDM_TX_STRUCT); in _cyhal_audioss_stop_tx()
1271 cy_rslt_t _cyhal_audioss_clear_tx(_cyhal_audioss_t *obj) in _cyhal_audioss_clear_tx() argument
1274 Cy_I2S_ClearTxFifo(obj->base); in _cyhal_audioss_clear_tx()
1279 bool was_active = _cyhal_audioss_is_tx_enabled(obj); in _cyhal_audioss_clear_tx()
1280 Cy_AudioTDM_DisableTx(&obj->base->TDM_TX_STRUCT); in _cyhal_audioss_clear_tx()
1281 Cy_AudioTDM_EnableTx(&obj->base->TDM_TX_STRUCT); in _cyhal_audioss_clear_tx()
1284 Cy_AudioTDM_ActivateTx(&obj->base->TDM_TX_STRUCT); in _cyhal_audioss_clear_tx()
1290 cy_rslt_t _cyhal_audioss_start_rx(_cyhal_audioss_t *obj) in _cyhal_audioss_start_rx() argument
1293 if (obj->pm_transition_ready) in _cyhal_audioss_start_rx()
1298 Cy_I2S_EnableRx(obj->base); in _cyhal_audioss_start_rx()
1300 Cy_AudioTDM_ActivateRx(&obj->base->TDM_RX_STRUCT); in _cyhal_audioss_start_rx()
1304 return obj->interface->err_not_supported; in _cyhal_audioss_start_rx()
1308 cy_rslt_t _cyhal_audioss_stop_rx(_cyhal_audioss_t *obj) in _cyhal_audioss_stop_rx() argument
1312 Cy_I2S_DisableRx(obj->base); in _cyhal_audioss_stop_rx()
1315 Cy_AudioTDM_DeActivateRx(&obj->base->TDM_RX_STRUCT); in _cyhal_audioss_stop_rx()
1319 return obj->interface->err_not_supported; in _cyhal_audioss_stop_rx()
1323 cy_rslt_t _cyhal_audioss_clear_rx(_cyhal_audioss_t *obj) in _cyhal_audioss_clear_rx() argument
1327 Cy_I2S_ClearRxFifo(obj->base); in _cyhal_audioss_clear_rx()
1332 bool was_active = _cyhal_audioss_is_rx_enabled(obj); in _cyhal_audioss_clear_rx()
1333 Cy_AudioTDM_DisableRx(&obj->base->TDM_RX_STRUCT); in _cyhal_audioss_clear_rx()
1334 Cy_AudioTDM_EnableRx(&obj->base->TDM_RX_STRUCT); in _cyhal_audioss_clear_rx()
1337 Cy_AudioTDM_ActivateRx(&obj->base->TDM_RX_STRUCT); in _cyhal_audioss_clear_rx()
1342 return obj->interface->err_not_supported; in _cyhal_audioss_clear_rx()
1348 static void _cyhal_audioss_read_until_empty(_cyhal_audioss_t *obj, void** buffer, size_t* length) in _cyhal_audioss_read_until_empty() argument
1354 if(obj->word_length_rx <= 8) in _cyhal_audioss_read_until_empty()
1358 while(*length > 0 && _cyhal_audioss_get_num_in_fifo(obj, false) > 0) in _cyhal_audioss_read_until_empty()
1360 *cast_buffer = (uint8_t)_cyhal_audioss_read_fifo(obj); in _cyhal_audioss_read_until_empty()
1366 else if(obj->word_length_rx <= 16) in _cyhal_audioss_read_until_empty()
1370 while(*length > 0 && _cyhal_audioss_get_num_in_fifo(obj, false) > 0) in _cyhal_audioss_read_until_empty()
1372 *cast_buffer = (uint16_t)_cyhal_audioss_read_fifo(obj); in _cyhal_audioss_read_until_empty()
1380 CY_ASSERT(obj->word_length_rx <= 32); in _cyhal_audioss_read_until_empty()
1383 while(*length > 0 && _cyhal_audioss_get_num_in_fifo(obj, false) > 0) in _cyhal_audioss_read_until_empty()
1385 *cast_buffer = _cyhal_audioss_read_fifo(obj); in _cyhal_audioss_read_until_empty()
1394 cy_rslt_t _cyhal_audioss_read(_cyhal_audioss_t *obj, void *data, size_t* length) in _cyhal_audioss_read() argument
1397 CY_ASSERT(NULL != obj); in _cyhal_audioss_read()
1398 if (obj->pm_transition_ready) in _cyhal_audioss_read()
1404 _cyhal_audioss_read_until_empty(obj, &data, &remaining); in _cyhal_audioss_read()
1410 return obj->interface->err_not_supported; in _cyhal_audioss_read()
1414 static void _cyhal_audioss_write_until_full(_cyhal_audioss_t *obj, const void** buffer, size_t *len… in _cyhal_audioss_write_until_full() argument
1420 if(obj->word_length_tx <= 8) in _cyhal_audioss_write_until_full()
1424 while(*length > 0 && _cyhal_audioss_get_num_in_fifo(obj, true) < _CYHAL_AUDIOSS_FIFO_DEPTH) in _cyhal_audioss_write_until_full()
1426 _cyhal_audioss_write_fifo(obj, *cast_buffer); in _cyhal_audioss_write_until_full()
1432 else if(obj->word_length_tx <= 16) in _cyhal_audioss_write_until_full()
1436 while(*length > 0 && _cyhal_audioss_get_num_in_fifo(obj, true) < _CYHAL_AUDIOSS_FIFO_DEPTH) in _cyhal_audioss_write_until_full()
1438 _cyhal_audioss_write_fifo(obj, *cast_buffer); in _cyhal_audioss_write_until_full()
1446 CY_ASSERT(obj->word_length_tx <= 32); in _cyhal_audioss_write_until_full()
1449 while(*length > 0 && _cyhal_audioss_get_num_in_fifo(obj, true) < _CYHAL_AUDIOSS_FIFO_DEPTH) in _cyhal_audioss_write_until_full()
1451 _cyhal_audioss_write_fifo(obj, *cast_buffer); in _cyhal_audioss_write_until_full()
1459 cy_rslt_t _cyhal_audioss_write(_cyhal_audioss_t *obj, const void *data, size_t *length) in _cyhal_audioss_write() argument
1461 CY_ASSERT(NULL != obj); in _cyhal_audioss_write()
1462 if (obj->pm_transition_ready) in _cyhal_audioss_write()
1468 _cyhal_audioss_write_until_full(obj, &data, &remaining); in _cyhal_audioss_write()
1473 bool _cyhal_audioss_is_tx_enabled(_cyhal_audioss_t *obj) in _cyhal_audioss_is_tx_enabled() argument
1475 CY_ASSERT(NULL != obj); in _cyhal_audioss_is_tx_enabled()
1478 return (0 != (CY_I2S_TX_START & Cy_I2S_GetCurrentState(obj->base))); in _cyhal_audioss_is_tx_enabled()
1480 …return (0u != (TDM_TDM_STRUCT_TDM_TX_STRUCT_TX_FIFO_CTL_ACTIVE_Msk & obj->base->TDM_TX_STRUCT.TX_F… in _cyhal_audioss_is_tx_enabled()
1484 bool _cyhal_audioss_is_tx_busy(_cyhal_audioss_t *obj) in _cyhal_audioss_is_tx_busy() argument
1486 CY_ASSERT(NULL != obj); in _cyhal_audioss_is_tx_busy()
1488 return (0 != _cyhal_audioss_get_num_in_fifo(obj, true)) || _cyhal_audioss_is_write_pending(obj); in _cyhal_audioss_is_tx_busy()
1491 bool _cyhal_audioss_is_rx_enabled(_cyhal_audioss_t *obj) in _cyhal_audioss_is_rx_enabled() argument
1494 CY_ASSERT(NULL != obj); in _cyhal_audioss_is_rx_enabled()
1496 return (0 != (CY_I2S_RX_START & Cy_I2S_GetCurrentState(obj->base))); in _cyhal_audioss_is_rx_enabled()
1498 …return (0u != (TDM_TDM_STRUCT_TDM_RX_STRUCT_RX_FIFO_CTL_ACTIVE_Msk & obj->base->TDM_RX_STRUCT.RX_F… in _cyhal_audioss_is_rx_enabled()
1501 CY_UNUSED_PARAMETER(obj); in _cyhal_audioss_is_rx_enabled()
1506 bool _cyhal_audioss_is_rx_busy(_cyhal_audioss_t *obj) in _cyhal_audioss_is_rx_busy() argument
1509 CY_ASSERT(NULL != obj); in _cyhal_audioss_is_rx_busy()
1510 return (0 != _cyhal_audioss_get_num_in_fifo(obj, false)) || _cyhal_audioss_is_read_pending(obj); in _cyhal_audioss_is_rx_busy()
1512 CY_UNUSED_PARAMETER(obj); in _cyhal_audioss_is_rx_busy()
1517 cy_rslt_t _cyhal_audioss_read_async(_cyhal_audioss_t *obj, void *rx, size_t rx_length) in _cyhal_audioss_read_async() argument
1520 CY_ASSERT(NULL != obj); in _cyhal_audioss_read_async()
1521 if (obj->pm_transition_ready) in _cyhal_audioss_read_async()
1527 obj->async_rx_buff = rx; in _cyhal_audioss_read_async()
1528 obj->async_rx_length = rx_length; in _cyhal_audioss_read_async()
1530 switch(obj->async_mode) in _cyhal_audioss_read_async()
1538 uint32_t old_events = _cyhal_audioss_disable_events(obj, false); in _cyhal_audioss_read_async()
1541 …_cyhal_audioss_read_until_empty(obj, (void**)(&obj->async_rx_buff), (size_t*)(&obj->async_rx_lengt… in _cyhal_audioss_read_async()
1542 _cyhal_audioss_update_rx_trigger_level(obj); in _cyhal_audioss_read_async()
1543 _cyhal_audioss_restore_events(obj, false, old_events); in _cyhal_audioss_read_async()
1544 if(obj->async_rx_length > 0) in _cyhal_audioss_read_async()
1546 _cyhal_audioss_update_enabled_events(obj); in _cyhal_audioss_read_async()
1550 _cyhal_audioss_process_event(obj, obj->interface->event_rx_complete); in _cyhal_audioss_read_async()
1560 _cyhal_audioss_update_rx_trigger_level(obj); in _cyhal_audioss_read_async()
1561 _cyhal_audioss_update_enabled_events(obj); in _cyhal_audioss_read_async()
1572 return obj->interface->err_not_supported; in _cyhal_audioss_read_async()
1576 static void _cyhal_audioss_reconstruct_pdl_config(_cyhal_audioss_t *obj, _cyhal_audioss_pdl_config_… in _cyhal_audioss_reconstruct_pdl_config() argument
1579 I2S_Type* base = obj->base; in _cyhal_audioss_reconstruct_pdl_config()
1598 pdl_config->rxFifoTriggerLevel = _cyhal_audioss_fifo_trigger_level(obj, false); in _cyhal_audioss_reconstruct_pdl_config()
1634 pdl_config->txFifoTriggerLevel = _cyhal_audioss_fifo_trigger_level(obj, true); in _cyhal_audioss_reconstruct_pdl_config()
1636 TDM_TX_STRUCT_Type* base_tx = &obj->base->TDM_TX_STRUCT; in _cyhal_audioss_reconstruct_pdl_config()
1637 TDM_RX_STRUCT_Type* base_rx = &obj->base->TDM_RX_STRUCT; in _cyhal_audioss_reconstruct_pdl_config()
1640 pdl_config->tx_config->enable = _cyhal_audioss_is_direction_enabled(obj, true); in _cyhal_audioss_reconstruct_pdl_config()
1655 pdl_config->tx_config->fifoTriggerLevel = _cyhal_audioss_fifo_trigger_level(obj, true); in _cyhal_audioss_reconstruct_pdl_config()
1661 pdl_config->rx_config->enable = _cyhal_audioss_is_direction_enabled(obj, false); in _cyhal_audioss_reconstruct_pdl_config()
1676 pdl_config->rx_config->fifoTriggerLevel = _cyhal_audioss_fifo_trigger_level(obj, false); in _cyhal_audioss_reconstruct_pdl_config()
1685 static cy_rslt_t _cyhal_audioss_populate_pdl_config(_cyhal_audioss_t *obj, _cyhal_audioss_pdl_confi… in _cyhal_audioss_populate_pdl_config() argument
1692 …cy_rslt_t result = _cyhal_audioss_length_to_pdl(obj->channel_length_tx, &pdl_channel_length_tx, ob… in _cyhal_audioss_populate_pdl_config()
1695 result = _cyhal_audioss_length_to_pdl(obj->word_length_tx, &pdl_word_length_tx, obj); in _cyhal_audioss_populate_pdl_config()
1701 result = _cyhal_audioss_length_to_pdl(obj->channel_length_rx, &pdl_channel_length_rx, obj); in _cyhal_audioss_populate_pdl_config()
1705 result = _cyhal_audioss_length_to_pdl(obj->word_length_rx, &pdl_word_length_rx, obj); in _cyhal_audioss_populate_pdl_config()
1776 cy_rslt_t result = _cyhal_audioss_length_to_pdl(obj->word_length_tx, &pdl_word_length_tx, obj); in _cyhal_audioss_populate_pdl_config()
1779 result = _cyhal_audioss_length_to_pdl(obj->word_length_rx, &pdl_word_length_rx, obj); in _cyhal_audioss_populate_pdl_config()
1796 pdl_config->tx_config->channelSize = obj->channel_length_tx; in _cyhal_audioss_populate_pdl_config()
1815 pdl_config->rx_config->channelSize = obj->channel_length_rx; in _cyhal_audioss_populate_pdl_config()
1834 static uint8_t _cyhal_audioss_rounded_word_length(_cyhal_audioss_t *obj, bool is_tx) in _cyhal_audioss_rounded_word_length() argument
1837 uint8_t word_length = is_tx ? obj->word_length_tx : obj->word_length_rx; in _cyhal_audioss_rounded_word_length()
1840 uint8_t word_length = obj->word_length_tx; in _cyhal_audioss_rounded_word_length()
1856 cy_rslt_t _cyhal_audioss_write_async(_cyhal_audioss_t *obj, const void *tx, size_t tx_length) in _cyhal_audioss_write_async() argument
1858 CY_ASSERT(NULL != obj); in _cyhal_audioss_write_async()
1859 if (obj->pm_transition_ready) in _cyhal_audioss_write_async()
1865 obj->async_tx_buff = tx; in _cyhal_audioss_write_async()
1866 obj->async_tx_length = tx_length; in _cyhal_audioss_write_async()
1868 switch(obj->async_mode) in _cyhal_audioss_write_async()
1876 uint32_t old_events = _cyhal_audioss_disable_events(obj, true); in _cyhal_audioss_write_async()
1879 …_cyhal_audioss_write_until_full(obj, (const void**)(&obj->async_tx_buff), (size_t *)(&obj->async_t… in _cyhal_audioss_write_async()
1880 _cyhal_audioss_restore_events(obj, true, old_events); in _cyhal_audioss_write_async()
1881 if(obj->async_tx_length > 0) in _cyhal_audioss_write_async()
1883 _cyhal_audioss_update_enabled_events(obj); in _cyhal_audioss_write_async()
1887 _cyhal_audioss_process_event(obj, obj->interface->event_tx_complete); in _cyhal_audioss_write_async()
1897 _cyhal_audioss_update_enabled_events(obj); in _cyhal_audioss_write_async()
1908 cy_rslt_t _cyhal_audioss_set_async_mode(_cyhal_audioss_t *obj, cyhal_async_mode_t mode, uint8_t dma… in _cyhal_audioss_set_async_mode() argument
1910 CY_ASSERT(NULL != obj); in _cyhal_audioss_set_async_mode()
1914 CY_ASSERT(false == _cyhal_audioss_is_read_pending(obj)); in _cyhal_audioss_set_async_mode()
1916 CY_ASSERT(false == _cyhal_audioss_is_write_pending(obj)); in _cyhal_audioss_set_async_mode()
1925 …if(_cyhal_audioss_is_direction_enabled(obj, true) && CYHAL_RSC_INVALID == obj->tx_dma.resource.typ… in _cyhal_audioss_set_async_mode()
1928 … result = cyhal_dma_init(&obj->tx_dma, CYHAL_DMA_PRIORITY_DEFAULT, CYHAL_DMA_DIRECTION_MEM2PERIPH); in _cyhal_audioss_set_async_mode()
1929 cyhal_dma_register_callback(&obj->tx_dma, &_cyhal_audioss_dma_handler_tx, obj); in _cyhal_audioss_set_async_mode()
1932 …if(_cyhal_audioss_is_direction_enabled(obj, false) && CYHAL_RSC_INVALID == obj->rx_dma.resource.ty… in _cyhal_audioss_set_async_mode()
1935 … result = cyhal_dma_init(&obj->rx_dma, CYHAL_DMA_PRIORITY_DEFAULT, CYHAL_DMA_DIRECTION_PERIPH2MEM); in _cyhal_audioss_set_async_mode()
1936 cyhal_dma_register_callback(&obj->rx_dma, &_cyhal_audioss_dma_handler_rx, obj); in _cyhal_audioss_set_async_mode()
1946 if(CYHAL_RSC_INVALID != obj->tx_dma.resource.type) in _cyhal_audioss_set_async_mode()
1949 cyhal_dma_free(&obj->tx_dma); in _cyhal_audioss_set_async_mode()
1951 obj->tx_dma.resource.type = CYHAL_RSC_INVALID; in _cyhal_audioss_set_async_mode()
1954 if(CYHAL_RSC_INVALID != obj->rx_dma.resource.type) in _cyhal_audioss_set_async_mode()
1957 cyhal_dma_free(&obj->rx_dma); in _cyhal_audioss_set_async_mode()
1959 obj->rx_dma.resource.type = CYHAL_RSC_INVALID; in _cyhal_audioss_set_async_mode()
1966 obj->async_mode = mode; in _cyhal_audioss_set_async_mode()
1967 obj->async_dma_priority = dma_priority; in _cyhal_audioss_set_async_mode()
1972 bool _cyhal_audioss_is_read_pending(_cyhal_audioss_t *obj) in _cyhal_audioss_is_read_pending() argument
1975 return (NULL != obj->async_rx_buff); in _cyhal_audioss_is_read_pending()
1977 CY_UNUSED_PARAMETER(obj); in _cyhal_audioss_is_read_pending()
1982 bool _cyhal_audioss_is_write_pending(_cyhal_audioss_t *obj) in _cyhal_audioss_is_write_pending() argument
1984 return (NULL != obj->async_tx_buff); in _cyhal_audioss_is_write_pending()
1987 cy_rslt_t _cyhal_audioss_abort_read_async(_cyhal_audioss_t *obj) in _cyhal_audioss_abort_read_async() argument
1991 obj->async_rx_buff = NULL; in _cyhal_audioss_abort_read_async()
1992 _cyhal_audioss_update_enabled_events(obj); in _cyhal_audioss_abort_read_async()
1996 return obj->interface->err_not_supported; in _cyhal_audioss_abort_read_async()
2000 cy_rslt_t _cyhal_audioss_abort_write_async(_cyhal_audioss_t *obj) in _cyhal_audioss_abort_write_async() argument
2003 obj->async_tx_buff = NULL; in _cyhal_audioss_abort_write_async()
2004 _cyhal_audioss_update_enabled_events(obj); in _cyhal_audioss_abort_write_async()
2032 …udioss_length_to_pdl(uint8_t user_length, cy_en_i2s_len_t *pdl_length, const _cyhal_audioss_t *obj) in _cyhal_audioss_length_to_pdl() argument
2057 result = obj->interface->err_invalid_arg; in _cyhal_audioss_length_to_pdl()
2090 …audioss_length_to_pdl(uint8_t user_length, cy_en_tdm_ws_t *pdl_length, const _cyhal_audioss_t *obj) in _cyhal_audioss_length_to_pdl() argument
2124 result = obj->interface->err_invalid_arg; in _cyhal_audioss_length_to_pdl()
2137 _cyhal_audioss_t* obj = _cyhal_audioss_config_structs[block]; in _cyhal_audioss_irq_handler() local
2139 uint32_t interrupt_status = Cy_I2S_GetInterruptStatusMasked(obj->base); in _cyhal_audioss_irq_handler()
2140 Cy_I2S_ClearInterrupt(obj->base, interrupt_status); in _cyhal_audioss_irq_handler()
2141 uint32_t event = obj->interface->convert_interrupt_cause(interrupt_status); in _cyhal_audioss_irq_handler()
2142 _cyhal_audioss_process_event(obj, event); in _cyhal_audioss_irq_handler()
2149 _cyhal_audioss_t* obj = _cyhal_audioss_config_structs[instance]; local
2155 _cyhal_audioss_t* obj = _cyhal_audioss_config_structs[block];
2158 uint32_t interrupt_status = Cy_AudioTDM_GetRxInterruptStatusMasked(&obj->base->TDM_RX_STRUCT);
2159 Cy_AudioTDM_ClearRxInterrupt(&obj->base->TDM_RX_STRUCT, interrupt_status);
2160 uint32_t event = obj->interface->convert_interrupt_cause(interrupt_status, false);
2161 _cyhal_audioss_process_event(obj, event);
2163 Cy_AudioTDM_EnableInterrupt(obj->base);
2170 _cyhal_audioss_t* obj = _cyhal_audioss_config_structs[instance]; local
2176 _cyhal_audioss_t* obj = _cyhal_audioss_config_structs[block];
2179 uint32_t interrupt_status = Cy_AudioTDM_GetTxInterruptStatusMasked(&obj->base->TDM_TX_STRUCT);
2180 Cy_AudioTDM_ClearTxInterrupt(&obj->base->TDM_TX_STRUCT, interrupt_status);
2181 uint32_t event = obj->interface->convert_interrupt_cause(interrupt_status, true);
2182 _cyhal_audioss_process_event(obj, event);
2184 Cy_AudioTDM_EnableInterrupt(obj->base);
2196 static void _cyhal_audioss_update_enabled_events(_cyhal_audioss_t *obj) argument
2198 uint32_t events = obj->user_enabled_events;
2199 if(NULL != obj->async_tx_buff && obj->async_tx_length > 0)
2201 events |= (obj->interface->event_mask_empty | obj->interface->event_mask_half_empty);
2204 if(NULL != obj->async_rx_buff && obj->async_rx_length > 0)
2206 events |= (obj->interface->event_mask_full | obj->interface->event_mask_half_full);
2211 uint32_t mask = obj->interface->convert_to_pdl(events);
2214 uint32_t old_mask = Cy_I2S_GetInterruptMask(obj->base) & CY_I2S_INTR_MASK;
2218 Cy_I2S_ClearInterrupt(obj->base, new_interrupts);
2220 Cy_I2S_SetInterruptMask(obj->base, mask);
2222 uint32_t tx_mask = obj->interface->convert_to_pdl(events, true);
2223 uint32_t old_tx_mask = Cy_AudioTDM_GetTxInterruptMask(&obj->base->TDM_TX_STRUCT);
2227 Cy_AudioTDM_ClearTxInterrupt(&obj->base->TDM_TX_STRUCT, new_interrupts_tx);
2228 Cy_AudioTDM_SetTxInterruptMask(&obj->base->TDM_TX_STRUCT, tx_mask);
2230 uint32_t rx_mask = obj->interface->convert_to_pdl(events, false);
2231 uint32_t old_rx_mask = Cy_AudioTDM_GetRxInterruptMask(&obj->base->TDM_RX_STRUCT);
2235 Cy_AudioTDM_ClearRxInterrupt(&obj->base->TDM_RX_STRUCT, new_interrupts_rx);
2236 Cy_AudioTDM_SetRxInterruptMask(&obj->base->TDM_RX_STRUCT, rx_mask);
2241 static void _cyhal_audioss_update_rx_trigger_level(_cyhal_audioss_t *obj) argument
2247 uint8_t trigger_level = obj->user_fifo_level_rx;
2248 if(NULL != obj->async_rx_buff
2249 && obj->async_rx_length < trigger_level
2250 && obj->async_rx_length > 0)
2252 trigger_level = obj->async_rx_length;
2259 obj->base->RX_FIFO_CTL = (uint32_t) (trigger_level << I2S_RX_FIFO_CTL_TRIGGER_LEVEL_Pos);
2261 uint32_t value = obj->base->TDM_RX_STRUCT.RX_FIFO_CTL;
2264 obj->base->TDM_RX_STRUCT.RX_FIFO_CTL = value;
2270 static uint32_t _cyhal_audioss_disable_events(_cyhal_audioss_t *obj, bool tx) argument
2274 uint32_t old_interrupt_mask = Cy_I2S_GetInterruptMask(obj->base);
2275 Cy_I2S_SetInterruptMask(obj->base, 0u);
2281 old_interrupt_mask = Cy_AudioTDM_GetTxInterruptMask(&obj->base->TDM_TX_STRUCT);
2282 Cy_AudioTDM_SetTxInterruptMask(&obj->base->TDM_TX_STRUCT, 0u);
2286 old_interrupt_mask = Cy_AudioTDM_GetRxInterruptMask(&obj->base->TDM_RX_STRUCT);
2287 Cy_AudioTDM_SetRxInterruptMask(&obj->base->TDM_RX_STRUCT, 0u);
2293 static void _cyhal_audioss_restore_events(_cyhal_audioss_t *obj, bool tx, uint32_t old_events) argument
2297 Cy_I2S_SetInterruptMask(obj->base, old_events);
2301 Cy_AudioTDM_SetTxInterruptMask(&obj->base->TDM_TX_STRUCT, old_events);
2305 Cy_AudioTDM_SetRxInterruptMask(&obj->base->TDM_RX_STRUCT, old_events);
2311 static cy_rslt_t _cyhal_audioss_dma_perform_rx(_cyhal_audioss_t *obj) argument
2315 if(cyhal_dma_is_busy(&(obj->rx_dma)))
2318 size_t transfer_size = _cyhal_audioss_fifo_trigger_level(obj, false) + 1;
2319 if (transfer_size >= obj->async_rx_length)
2321 transfer_size = obj->async_rx_length;
2323 …cyhal_dma_enable_event(&(obj->rx_dma), CYHAL_DMA_TRANSFER_COMPLETE, obj->async_dma_priority, true);
2329 .src_addr = (uint32_t)(&(obj->base->RX_FIFO_RD)),
2331 .src_addr = (uint32_t)(&(obj->base->TDM_RX_STRUCT.RX_FIFO_RD)),
2334 .dst_addr = (uint32_t)obj->async_rx_buff,
2336 .transfer_width = _cyhal_audioss_rounded_word_length(obj, false),
2341 cy_rslt_t result = cyhal_dma_configure(&(obj->rx_dma), &dma_cfg);
2344 …SCB_InvalidateDCache_by_Addr((void *)obj->async_rx_buff, transfer_size * (_cyhal_audioss_rounded_w…
2349 result = cyhal_dma_enable(&(obj->rx_dma));
2355 … size_t increment_bytes = transfer_size * (_cyhal_audioss_rounded_word_length(obj, false) / 8);
2357 obj->async_rx_buff = (void*)(((uint8_t*) obj->async_rx_buff) + increment_bytes);
2358 obj->async_rx_length -= transfer_size;
2359 _cyhal_audioss_update_rx_trigger_level(obj);
2360 _cyhal_audioss_update_enabled_events(obj);
2363 result = cyhal_dma_start_transfer(&(obj->rx_dma));
2371 static cy_rslt_t _cyhal_audioss_dma_perform_tx(_cyhal_audioss_t *obj) argument
2375 if(cyhal_dma_is_busy(&(obj->tx_dma)))
2378 CY_ASSERT(NULL != obj->async_tx_buff);
2381 size_t transfer_size = _cyhal_audioss_fifo_trigger_level(obj, true) + 1;
2382 if (transfer_size >= obj->async_tx_length)
2384 transfer_size = obj->async_tx_length;
2386 …cyhal_dma_enable_event(&(obj->tx_dma), CYHAL_DMA_TRANSFER_COMPLETE, obj->async_dma_priority, true);
2391 .src_addr = (uint32_t)obj->async_tx_buff,
2394 .dst_addr = (uint32_t)(&(obj->base->TX_FIFO_WR)),
2396 .dst_addr = (uint32_t)(&(obj->base->TDM_TX_STRUCT.TX_FIFO_WR)),
2399 .transfer_width = _cyhal_audioss_rounded_word_length(obj, true),
2404 cy_rslt_t result = cyhal_dma_configure(&(obj->tx_dma), &dma_cfg);
2407 …SCB_CleanDCache_by_Addr((void *)obj->async_tx_buff, transfer_size * (_cyhal_audioss_rounded_word_l…
2412 result = cyhal_dma_enable(&(obj->tx_dma));
2418 … size_t increment_bytes = transfer_size * (_cyhal_audioss_rounded_word_length(obj, true) / 8);
2420 obj->async_tx_buff = (void*)(((uint8_t*) obj->async_tx_buff) + increment_bytes);
2421 obj->async_tx_length -= transfer_size;
2427 _cyhal_audioss_update_enabled_events(obj);
2430 result = cyhal_dma_start_transfer(&(obj->tx_dma));
2437 static uint32_t _cyhal_audioss_get_num_in_fifo(_cyhal_audioss_t *obj, bool is_tx) argument
2441 return is_tx ? Cy_I2S_GetNumInTxFifo(obj->base) : Cy_I2S_GetNumInRxFifo(obj->base);
2444 return Cy_I2S_GetNumInTxFifo(obj->base);
2447 return is_tx ? Cy_AudioTDM_GetNumInTxFifo(&obj->base->TDM_TX_STRUCT)
2448 : Cy_AudioTDM_GetNumInRxFifo(&obj->base->TDM_RX_STRUCT);
2453 static uint32_t _cyhal_audioss_read_fifo(_cyhal_audioss_t *obj) argument
2456 return Cy_I2S_ReadRxData(obj->base);
2458 return Cy_AudioTDM_ReadRxData(&obj->base->TDM_RX_STRUCT);
2463 static void _cyhal_audioss_write_fifo(_cyhal_audioss_t *obj, uint32_t value) argument
2466 Cy_I2S_WriteTxData(obj->base, value);
2468 Cy_AudioTDM_WriteTxData(&obj->base->TDM_TX_STRUCT, value);
2480 _cyhal_audioss_t *obj = (_cyhal_audioss_t*)callback_arg; local
2481 obj->async_rx_buff = NULL;
2482 … cyhal_dma_enable_event(&obj->rx_dma, CYHAL_DMA_TRANSFER_COMPLETE, obj->async_dma_priority, false);
2483 _cyhal_audioss_process_event(obj, obj->interface->event_rx_complete);
2495 _cyhal_audioss_t *obj = (_cyhal_audioss_t*)callback_arg; local
2496 obj->async_tx_buff = NULL;
2497 … cyhal_dma_enable_event(&obj->tx_dma, CYHAL_DMA_TRANSFER_COMPLETE, obj->async_dma_priority, false);
2498 _cyhal_audioss_process_event(obj, obj->interface->event_tx_complete);
2502 static void _cyhal_audioss_process_event(_cyhal_audioss_t *obj, uint32_t event) argument
2504 if(0 != (event & (obj->interface->event_mask_empty | obj->interface->event_mask_half_empty)))
2511 if(NULL != obj->async_tx_buff && obj->async_tx_length > 0)
2513 switch(obj->async_mode)
2522 uint32_t old_events = _cyhal_audioss_disable_events(obj, true);
2526 …_cyhal_audioss_write_until_full(obj, (const void**)(&obj->async_tx_buff), (size_t *)(&obj->async_t…
2530 _cyhal_audioss_restore_events(obj, true, old_events);
2531 if(0 == obj->async_tx_length)
2534 event |= obj->interface->event_tx_complete;
2541 cy_rslt_t result = _cyhal_audioss_dma_perform_tx(obj);
2559 if(0 != (event & (obj->interface->event_mask_full | obj->interface->event_mask_half_full)))
2563 if(NULL != obj->async_rx_buff && obj->async_rx_length > 0)
2565 switch(obj->async_mode)
2574 uint32_t old_events = _cyhal_audioss_disable_events(obj, false);
2578 …_cyhal_audioss_read_until_empty(obj, (void**)(&obj->async_rx_buff), (size_t*)(&obj->async_rx_lengt…
2581 _cyhal_audioss_restore_events(obj, false, old_events);
2582 _cyhal_audioss_update_enabled_events(obj);
2583 if(0 == obj->async_rx_length)
2586 event |= obj->interface->event_rx_complete;
2592 _cyhal_audioss_dma_perform_rx(obj);
2605 …uint8_t trigger_level = (obj->base->RX_FIFO_CTL & I2S_RX_FIFO_CTL_TRIGGER_LEVEL_Msk) >> I2S_RX_FIF…
2607 …uint8_t trigger_level = (obj->base->TDM_RX_STRUCT.RX_FIFO_CTL & TDM_TDM_STRUCT_TDM_RX_STRUCT_RX_FI…
2609 if(trigger_level != obj->user_fifo_level_rx)
2611 event &= ~(obj->interface->event_mask_half_full);
2620 if(0 != (event & obj->interface->event_tx_complete))
2622 obj->async_tx_buff = NULL;
2623 _cyhal_audioss_update_enabled_events(obj);
2627 if(0 != (event & obj->interface->event_rx_complete))
2629 obj->async_rx_buff = NULL;
2630 _cyhal_audioss_update_enabled_events(obj);
2634 if(0 != (event & obj->user_enabled_events))
2636 obj->interface->invoke_user_callback(obj, event & obj->user_enabled_events);
2642 _cyhal_audioss_t *obj = (_cyhal_audioss_t *)callback_arg; local
2650 bool is_active = _cyhal_audioss_is_rx_enabled(obj)
2651 || _cyhal_audioss_is_tx_enabled(obj);
2652 …obj->pm_transition_ready = !is_active && !(_cyhal_audioss_is_read_pending(obj) || _cyhal_audioss_i…
2654 bool is_active = _cyhal_audioss_is_tx_enabled(obj);
2655 obj->pm_transition_ready = !is_active && !_cyhal_audioss_is_tx_busy(obj);
2657 return obj->pm_transition_ready;
2661 obj->pm_transition_ready = false;
2669 static cyhal_source_t _cyhal_audioss_calculate_source(_cyhal_audioss_t *obj, bool is_rx) argument
2672 …return is_rx ? _cyhal_audioss_rx_trigger[obj->resource.block_num] : _cyhal_audioss_tx_trigger[obj-…
2675 return _cyhal_audioss_tx_trigger[obj->resource.block_num];
2680 cy_rslt_t _cyhal_audioss_enable_output(_cyhal_audioss_t *obj, bool is_rx, cyhal_source_t *source) argument
2686 REG_I2S_TR_CTL(obj->base) |= I2S_TR_CTL_RX_REQ_EN_Msk;
2690 REG_I2S_TR_CTL(obj->base) |= I2S_TR_CTL_TX_REQ_EN_Msk;
2694 *source = _cyhal_audioss_calculate_source(obj, is_rx);
2699 return obj->interface->err_not_supported;
2703 cy_rslt_t _cyhal_audioss_disable_output(_cyhal_audioss_t *obj, bool is_rx) argument
2709 REG_I2S_TR_CTL(obj->base) &= ~I2S_TR_CTL_RX_REQ_EN_Msk;
2713 REG_I2S_TR_CTL(obj->base) &= ~I2S_TR_CTL_TX_REQ_EN_Msk;
2717 CY_UNUSED_PARAMETER(obj);
2724 return obj->interface->err_not_supported;