diff options
| author | HiFiPhile <[email protected]> | 2024-04-08 21:44:14 +0200 |
|---|---|---|
| committer | HiFiPhile <[email protected]> | 2024-04-08 21:44:14 +0200 |
| commit | adc7a78fd6fbdccbe5f586391997052f2becd149 (patch) | |
| tree | 68108df608468572c43c1e65c578f6954aecf69f /src/class/vendor | |
| parent | 9570836cece0beb6c61f1cc97e5de25dac136394 (diff) | |
| parent | 42decf28f1bf7512a4c3e7402c9daf83ee241191 (diff) | |
Merge branch 'master' of github.com:HiFiPhile/tinyusb into vendor_fifo
Diffstat (limited to 'src/class/vendor')
| -rw-r--r-- | src/class/vendor/vendor_device.c | 48 | ||||
| -rw-r--r-- | src/class/vendor/vendor_device.h | 1 |
2 files changed, 43 insertions, 6 deletions
diff --git a/src/class/vendor/vendor_device.c b/src/class/vendor/vendor_device.c index fe746eda0..dcd629965 100644 --- a/src/class/vendor/vendor_device.c +++ b/src/class/vendor/vendor_device.c @@ -202,27 +202,63 @@ uint32_t tud_vendor_n_write_available (uint8_t itf) //--------------------------------------------------------------------+ // USBD Driver API //--------------------------------------------------------------------+ -void vendord_init(void) -{ +void vendord_init(void) { tu_memclr(_vendord_itf, sizeof(_vendord_itf)); - for(uint8_t i=0; i<CFG_TUD_VENDOR; i++) - { + for(uint8_t i=0; i<CFG_TUD_VENDOR; i++) { #if CFG_TUD_VENDOR_RX_BUFSIZE > 0 || CFG_TUD_VENDOR_TX_BUFSIZE > 0 vendord_interface_t* p_itf = &_vendord_itf[i]; #endif // config fifo #if CFG_TUD_VENDOR_RX_BUFSIZE > 0 tu_fifo_config(&p_itf->rx_ff, p_itf->rx_ff_buf, CFG_TUD_VENDOR_RX_BUFSIZE, 1, false); - tu_fifo_config_mutex(&p_itf->rx_ff, NULL, osal_mutex_create(&p_itf->rx_ff_mutex)); + + #if OSAL_MUTEX_REQUIRED + osal_mutex_t mutex_rd = osal_mutex_create(&p_itf->rx_ff_mutex); + TU_ASSERT(mutex_rd,); + tu_fifo_config_mutex(&p_itf->rx_ff, NULL, mutex_rd); + #endif #endif #if CFG_TUD_VENDOR_TX_BUFSIZE > 0 tu_fifo_config(&p_itf->tx_ff, p_itf->tx_ff_buf, CFG_TUD_VENDOR_TX_BUFSIZE, 1, false); - tu_fifo_config_mutex(&p_itf->tx_ff, osal_mutex_create(&p_itf->tx_ff_mutex), NULL); + + #if OSAL_MUTEX_REQUIRED + osal_mutex_t mutex_wr = osal_mutex_create(&p_itf->tx_ff_mutex); + TU_ASSERT(mutex_wr,); + tu_fifo_config_mutex(&p_itf->tx_ff, mutex_wr, NULL); + #endif #endif } } +bool vendord_deinit(void) { +#if OSAL_MUTEX_REQUIRED + #if CFG_TUD_VENDOR_RX_BUFSIZE > 0 + for(uint8_t i=0; i<CFG_TUD_VENDOR; i++) { + vendord_interface_t* p_itf = &_vendord_itf[i]; + osal_mutex_t mutex_rd = p_itf->rx_ff.mutex_rd; + + if (mutex_rd) { + osal_mutex_delete(mutex_rd); + tu_fifo_config_mutex(&p_itf->rx_ff, NULL, NULL); + } + } + #endif + #if CFG_TUD_VENDOR_TX_BUFSIZE > 0 + for(uint8_t i=0; i<CFG_TUD_VENDOR; i++) { + vendord_interface_t* p_itf = &_vendord_itf[i]; + osal_mutex_t mutex_wr = p_itf->tx_ff.mutex_wr; + + if (mutex_wr) { + osal_mutex_delete(mutex_wr); + tu_fifo_config_mutex(&p_itf->tx_ff, NULL, NULL); + } + } + #endif +#endif + return true; +} + void vendord_reset(uint8_t rhport) { (void) rhport; diff --git a/src/class/vendor/vendor_device.h b/src/class/vendor/vendor_device.h index 1e973b153..4a0cc3151 100644 --- a/src/class/vendor/vendor_device.h +++ b/src/class/vendor/vendor_device.h @@ -161,6 +161,7 @@ static inline uint32_t tud_vendor_write_available (void) // Internal Class Driver API //--------------------------------------------------------------------+ void vendord_init(void); +bool vendord_deinit(void); void vendord_reset(uint8_t rhport); uint16_t vendord_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t max_len); bool vendord_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t xferred_bytes); |
