diff options
| author | Ha Thach <[email protected]> | 2024-04-08 23:48:52 +0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-04-08 23:48:52 +0700 |
| commit | 42decf28f1bf7512a4c3e7402c9daf83ee241191 (patch) | |
| tree | 1a3ed93956a7d51d592d6ba4de6215725ec43c4c /src/class/cdc/cdc_device.c | |
| parent | d33fe38a6257bcdd60f51a57c9fd19ce2ad1f202 (diff) | |
| parent | be25a3fc20339c27803e68cb1363f89ffe7a7c67 (diff) | |
Merge pull request #1835 from MasterQ32/otg_bringup
Implements deinit functions for host/device mode switch
Diffstat (limited to 'src/class/cdc/cdc_device.c')
| -rw-r--r-- | src/class/cdc/cdc_device.c | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/src/class/cdc/cdc_device.c b/src/class/cdc/cdc_device.c index c26264e60..7ef0530ec 100644 --- a/src/class/cdc/cdc_device.c +++ b/src/class/cdc/cdc_device.c @@ -253,11 +253,39 @@ void cdcd_init(void) // In this way, the most current data is prioritized. tu_fifo_config(&p_cdc->tx_ff, p_cdc->tx_ff_buf, TU_ARRAY_SIZE(p_cdc->tx_ff_buf), 1, true); - tu_fifo_config_mutex(&p_cdc->rx_ff, NULL, osal_mutex_create(&p_cdc->rx_ff_mutex)); - tu_fifo_config_mutex(&p_cdc->tx_ff, osal_mutex_create(&p_cdc->tx_ff_mutex), NULL); + #if OSAL_MUTEX_REQUIRED + osal_mutex_t mutex_rd = osal_mutex_create(&p_cdc->rx_ff_mutex); + osal_mutex_t mutex_wr = osal_mutex_create(&p_cdc->tx_ff_mutex); + TU_ASSERT(mutex_rd != NULL && mutex_wr != NULL, ); + + tu_fifo_config_mutex(&p_cdc->rx_ff, NULL, mutex_rd); + tu_fifo_config_mutex(&p_cdc->tx_ff, mutex_wr, NULL); + #endif } } +bool cdcd_deinit(void) { + #if OSAL_MUTEX_REQUIRED + for(uint8_t i=0; i<CFG_TUD_CDC; i++) { + cdcd_interface_t* p_cdc = &_cdcd_itf[i]; + osal_mutex_t mutex_rd = p_cdc->rx_ff.mutex_rd; + osal_mutex_t mutex_wr = p_cdc->tx_ff.mutex_wr; + + if (mutex_rd) { + osal_mutex_delete(mutex_rd); + tu_fifo_config_mutex(&p_cdc->rx_ff, NULL, NULL); + } + + if (mutex_wr) { + osal_mutex_delete(mutex_wr); + tu_fifo_config_mutex(&p_cdc->tx_ff, NULL, NULL); + } + } + #endif + + return true; +} + void cdcd_reset(uint8_t rhport) { (void) rhport; |
