Merge remote-tracking branch 'upstream/master' into CCRX_Port
This commit is contained in:
@@ -368,7 +368,7 @@ static bool config_get_report_desc(uint8_t dev_addr, tusb_control_request_t cons
|
||||
|
||||
// Get Report Descriptor
|
||||
// using usbh enumeration buffer since report descriptor can be very long
|
||||
TU_ASSERT( hid_itf->report_desc_len <= CFG_TUH_ENUMERATION_BUFSZIE );
|
||||
TU_ASSERT( hid_itf->report_desc_len <= CFG_TUH_ENUMERATION_BUFSIZE );
|
||||
|
||||
TU_LOG2("HID Get Report Descriptor\r\n");
|
||||
tusb_control_request_t const new_request =
|
||||
|
||||
@@ -197,9 +197,11 @@ uint32_t tud_midi_n_stream_read(uint8_t itf, uint8_t cable_num, void* buffer, ui
|
||||
|
||||
bool tud_midi_n_packet_read (uint8_t itf, uint8_t packet[4])
|
||||
{
|
||||
midid_interface_t* p_midi = &_midid_itf[itf];
|
||||
uint32_t num_read = tu_fifo_read_n(&p_midi->rx_ff, packet, 4);
|
||||
_prep_out_transaction(p_midi);
|
||||
midid_interface_t* midi = &_midid_itf[itf];
|
||||
TU_VERIFY(midi->ep_out);
|
||||
|
||||
uint32_t const num_read = tu_fifo_read_n(&midi->rx_ff, packet, 4);
|
||||
_prep_out_transaction(midi);
|
||||
return (num_read == 4);
|
||||
}
|
||||
|
||||
@@ -234,7 +236,7 @@ static uint32_t write_flush(midid_interface_t* midi)
|
||||
uint32_t tud_midi_n_stream_write(uint8_t itf, uint8_t cable_num, uint8_t const* buffer, uint32_t bufsize)
|
||||
{
|
||||
midid_interface_t* midi = &_midid_itf[itf];
|
||||
TU_VERIFY(midi->itf_num, 0);
|
||||
TU_VERIFY(midi->ep_in, 0);
|
||||
|
||||
midid_stream_t* stream = &midi->stream_write;
|
||||
|
||||
@@ -351,9 +353,7 @@ uint32_t tud_midi_n_stream_write(uint8_t itf, uint8_t cable_num, uint8_t const*
|
||||
bool tud_midi_n_packet_write (uint8_t itf, uint8_t const packet[4])
|
||||
{
|
||||
midid_interface_t* midi = &_midid_itf[itf];
|
||||
if (midi->itf_num == 0) {
|
||||
return 0;
|
||||
}
|
||||
TU_VERIFY(midi->ep_in);
|
||||
|
||||
if (tu_fifo_remaining(&midi->tx_ff) < 4) return false;
|
||||
|
||||
@@ -435,6 +435,7 @@ uint16_t midid_open(uint8_t rhport, tusb_desc_interface_t const * desc_itf, uint
|
||||
}
|
||||
|
||||
p_midi->itf_num = desc_midi->bInterfaceNumber;
|
||||
(void) p_midi->itf_num;
|
||||
|
||||
// next descriptor
|
||||
drv_len += tu_desc_len(p_desc);
|
||||
|
||||
@@ -86,8 +86,8 @@ typedef struct
|
||||
.depth = _depth, \
|
||||
.item_size = sizeof(_type), \
|
||||
.overwritable = _overwritable, \
|
||||
.max_pointer_idx = 2*(_depth)-1, \
|
||||
.non_used_index_space = UINT16_MAX - (2*(_depth)-1), \
|
||||
.max_pointer_idx = 2*(_depth)-1, \
|
||||
}
|
||||
|
||||
#define TU_FIFO_DEF(_name, _depth, _type, _overwritable) \
|
||||
|
||||
@@ -130,7 +130,7 @@ CFG_TUSB_MEM_SECTION usbh_device_t _usbh_devices[CFG_TUSB_HOST_DEVICE_MAX+1];
|
||||
OSAL_QUEUE_DEF(OPT_MODE_HOST, _usbh_qdef, CFG_TUH_TASK_QUEUE_SZ, hcd_event_t);
|
||||
static osal_queue_t _usbh_q;
|
||||
|
||||
CFG_TUSB_MEM_SECTION CFG_TUSB_MEM_ALIGN static uint8_t _usbh_ctrl_buf[CFG_TUH_ENUMERATION_BUFSZIE];
|
||||
CFG_TUSB_MEM_SECTION CFG_TUSB_MEM_ALIGN static uint8_t _usbh_ctrl_buf[CFG_TUH_ENUMERATION_BUFSIZE];
|
||||
|
||||
//------------- Helper Function Prototypes -------------//
|
||||
static bool enum_new_device(hcd_event_t* event);
|
||||
@@ -907,7 +907,7 @@ static bool enum_get_9byte_config_desc_complete(uint8_t dev_addr, tusb_control_r
|
||||
// Use offsetof to avoid pointer to the odd/misaligned address
|
||||
memcpy(&total_len, (uint8_t*) desc_config + offsetof(tusb_desc_configuration_t, wTotalLength), 2);
|
||||
|
||||
TU_ASSERT(total_len <= CFG_TUH_ENUMERATION_BUFSZIE);
|
||||
TU_ASSERT(total_len <= CFG_TUH_ENUMERATION_BUFSIZE);
|
||||
|
||||
// Get full configuration descriptor
|
||||
TU_LOG2("Get Configuration Descriptor\r\n");
|
||||
|
||||
@@ -50,7 +50,7 @@ typedef struct
|
||||
static usbh_control_xfer_t _ctrl_xfer;
|
||||
|
||||
//CFG_TUSB_MEM_SECTION CFG_TUSB_MEM_ALIGN
|
||||
//static uint8_t _tuh_ctrl_buf[CFG_TUH_ENUMERATION_BUFSZIE];
|
||||
//static uint8_t _tuh_ctrl_buf[CFG_TUH_ENUMERATION_BUFSIZE];
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// MACRO TYPEDEF CONSTANT ENUM DECLARATION
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
#if TUSB_OPT_DEVICE_ENABLED && \
|
||||
(CFG_TUSB_MCU == OPT_MCU_SAMD11 || CFG_TUSB_MCU == OPT_MCU_SAMD21 || \
|
||||
CFG_TUSB_MCU == OPT_MCU_SAMD51 || CFG_TUSB_MCU == OPT_MCU_SAME5X || \
|
||||
CFG_TUSB_MCU == OPT_MCU_SAML22)
|
||||
CFG_TUSB_MCU == OPT_MCU_SAML22 || CFG_TUSB_MCU == OPT_MCU_SAML21)
|
||||
|
||||
#include "sam.h"
|
||||
#include "device/dcd.h"
|
||||
@@ -125,7 +125,7 @@ void dcd_int_disable(uint8_t rhport)
|
||||
}
|
||||
|
||||
#elif CFG_TUSB_MCU == OPT_MCU_SAMD11 || CFG_TUSB_MCU == OPT_MCU_SAMD21 || \
|
||||
CFG_TUSB_MCU == OPT_MCU_SAML22
|
||||
CFG_TUSB_MCU == OPT_MCU_SAML22 || CFG_TUSB_MCU == OPT_MCU_SAML21
|
||||
|
||||
void dcd_int_enable(uint8_t rhport)
|
||||
{
|
||||
|
||||
@@ -108,13 +108,21 @@ static inline uint32_t NVIC_GetEnableIRQ(IRQn_Type IRQn)
|
||||
}
|
||||
#endif
|
||||
|
||||
// check if we are in ISR
|
||||
TU_ATTR_ALWAYS_INLINE static inline bool is_in_isr(void)
|
||||
{
|
||||
return (SCB->ICSR & SCB_ICSR_VECTACTIVE_Msk) ? true : false;
|
||||
}
|
||||
|
||||
// helper to start DMA
|
||||
// TODO use Cortex M4 LDREX and STREX command (atomic) to have better mutex access to EasyDMA
|
||||
// since current implementation does not 100% guarded against race condition
|
||||
static void edpt_dma_start(volatile uint32_t* reg_startep)
|
||||
{
|
||||
// Only one dma can be active
|
||||
if ( _dcd.dma_pending )
|
||||
{
|
||||
if (SCB->ICSR & SCB_ICSR_VECTACTIVE_Msk)
|
||||
if (is_in_isr())
|
||||
{
|
||||
// Called within ISR, use usbd task to defer later
|
||||
usbd_defer_func( (osal_task_func_t) edpt_dma_start, (void*) reg_startep, true );
|
||||
@@ -159,6 +167,17 @@ static void edpt_dma_end(void)
|
||||
_dcd.dma_pending = 0;
|
||||
}
|
||||
|
||||
// helper to set TASKS_EP0STATUS / TASKS_EP0RCVOUT since they also need EasyDMA
|
||||
// However TASKS_EP0STATUS doesn't trigger any DMA transfer and got ENDED event subsequently
|
||||
// Therefore dma_running state will be corrected right away
|
||||
void start_ep0_task(volatile uint32_t* reg_task)
|
||||
{
|
||||
edpt_dma_start(reg_task);
|
||||
|
||||
// correct the dma_running++ in dma start
|
||||
if (_dcd.dma_pending) _dcd.dma_pending--;
|
||||
}
|
||||
|
||||
// helper getting td
|
||||
static inline xfer_td_t* get_td(uint8_t epnum, uint8_t dir)
|
||||
{
|
||||
@@ -407,21 +426,18 @@ bool dcd_edpt_xfer (uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t
|
||||
|
||||
if ( control_status )
|
||||
{
|
||||
// Status Phase also requires Easy DMA has to be available as well !!!!
|
||||
// However TASKS_EP0STATUS doesn't trigger any DMA transfer and got ENDED event subsequently
|
||||
// Therefore dma_running state will be corrected right away
|
||||
edpt_dma_start(&NRF_USBD->TASKS_EP0STATUS);
|
||||
if (_dcd.dma_pending) _dcd.dma_pending--; // correct the dma_running++ in dma start
|
||||
// Status Phase also requires EasyDMA has to be available as well !!!!
|
||||
start_ep0_task(&NRF_USBD->TASKS_EP0STATUS);
|
||||
|
||||
// The nRF doesn't interrupt on status transmit so we queue up a success response.
|
||||
dcd_event_xfer_complete(0, ep_addr, 0, XFER_RESULT_SUCCESS, false);
|
||||
dcd_event_xfer_complete(0, ep_addr, 0, XFER_RESULT_SUCCESS, is_in_isr());
|
||||
}
|
||||
else if ( dir == TUSB_DIR_OUT )
|
||||
{
|
||||
if ( epnum == 0 )
|
||||
{
|
||||
// Accept next Control Out packet
|
||||
NRF_USBD->TASKS_EP0RCVOUT = 1;
|
||||
// Accept next Control Out packet. TASKS_EP0RCVOUT also require EasyDMA
|
||||
start_ep0_task(&NRF_USBD->TASKS_EP0RCVOUT);
|
||||
}else
|
||||
{
|
||||
if ( xfer->data_received )
|
||||
@@ -581,12 +597,6 @@ void dcd_int_handler(uint8_t rhport)
|
||||
}
|
||||
}
|
||||
|
||||
if ( int_status & EDPT_END_ALL_MASK )
|
||||
{
|
||||
// DMA complete move data from SRAM -> Endpoint
|
||||
edpt_dma_end();
|
||||
}
|
||||
|
||||
// Setup tokens are specific to the Control endpoint.
|
||||
if ( int_status & USBD_INTEN_EP0SETUP_Msk )
|
||||
{
|
||||
@@ -607,6 +617,12 @@ void dcd_int_handler(uint8_t rhport)
|
||||
}
|
||||
}
|
||||
|
||||
if ( int_status & EDPT_END_ALL_MASK )
|
||||
{
|
||||
// DMA complete move data from SRAM -> Endpoint
|
||||
edpt_dma_end();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
/* Control/Bulk/Interrupt (CBI) Transfer
|
||||
*
|
||||
@@ -655,8 +671,15 @@ void dcd_int_handler(uint8_t rhport)
|
||||
{
|
||||
if ( epnum == 0 )
|
||||
{
|
||||
// Accept next Control Out packet
|
||||
NRF_USBD->TASKS_EP0RCVOUT = 1;
|
||||
// Accept next Control Out packet. TASKS_EP0RCVOUT also require EasyDMA
|
||||
if ( _dcd.dma_pending )
|
||||
{
|
||||
// use usbd task to defer later
|
||||
usbd_defer_func( (osal_task_func_t) start_ep0_task, (void*) &NRF_USBD->TASKS_EP0RCVOUT, true );
|
||||
}else
|
||||
{
|
||||
start_ep0_task(&NRF_USBD->TASKS_EP0RCVOUT);
|
||||
}
|
||||
}else
|
||||
{
|
||||
// nRF auto accept next Bulk/Interrupt OUT packet
|
||||
@@ -973,7 +996,7 @@ void tusb_hal_nrf_power_event (uint32_t event)
|
||||
|
||||
hfclk_disable();
|
||||
|
||||
dcd_event_bus_signal(0, DCD_EVENT_UNPLUGGED, (SCB->ICSR & SCB_ICSR_VECTACTIVE_Msk) ? true : false);
|
||||
dcd_event_bus_signal(0, DCD_EVENT_UNPLUGGED, is_in_isr());
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
@@ -61,6 +61,7 @@
|
||||
#define OPT_MCU_SAME5X 203 ///< MicroChip SAM E5x
|
||||
#define OPT_MCU_SAMD11 204 ///< MicroChip SAMD11
|
||||
#define OPT_MCU_SAML22 205 ///< MicroChip SAML22
|
||||
#define OPT_MCU_SAML21 206 ///< MicroChip SAML21
|
||||
|
||||
// STM32
|
||||
#define OPT_MCU_STM32F0 300 ///< ST STM32F0
|
||||
@@ -278,8 +279,8 @@
|
||||
#error there is no benefit enable hub with max device is 1. Please disable hub or increase CFG_TUSB_HOST_DEVICE_MAX
|
||||
#endif
|
||||
|
||||
#ifndef CFG_TUH_ENUMERATION_BUFSZIE
|
||||
#define CFG_TUH_ENUMERATION_BUFSZIE 256
|
||||
#ifndef CFG_TUH_ENUMERATION_BUFSIZE
|
||||
#define CFG_TUH_ENUMERATION_BUFSIZE 256
|
||||
#endif
|
||||
|
||||
//------------- CLASS -------------//
|
||||
|
||||
Reference in New Issue
Block a user