change usbd_control_xfer_st from function to macro to prevent compiler issue with substask
This commit is contained in:
		@@ -218,21 +218,15 @@ tusb_error_t cdcd_control_request_st(uint8_t rhport, tusb_control_request_t cons
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
  OSAL_SUBTASK_BEGIN
 | 
					  OSAL_SUBTASK_BEGIN
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  tusb_error_t err;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  //------------- Class Specific Request -------------//
 | 
					  //------------- Class Specific Request -------------//
 | 
				
			||||||
  if (p_request->bmRequestType_bit.type != TUSB_REQ_TYPE_CLASS) return TUSB_ERROR_DCD_CONTROL_REQUEST_NOT_SUPPORT;
 | 
					  if (p_request->bmRequestType_bit.type != TUSB_REQ_TYPE_CLASS) return TUSB_ERROR_DCD_CONTROL_REQUEST_NOT_SUPPORT;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (CDC_REQUEST_GET_LINE_CODING == p_request->bRequest)
 | 
					  if ( (CDC_REQUEST_GET_LINE_CODING == p_request->bRequest) || (CDC_REQUEST_SET_LINE_CODING == p_request->bRequest) )
 | 
				
			||||||
  {
 | 
					  {
 | 
				
			||||||
    STASK_INVOKE( usbd_control_xfer_st(rhport, (tusb_dir_t) p_request->bmRequestType_bit.direction,
 | 
					    uint16_t len = min16_of(sizeof(cdc_line_coding_t), p_request->wLength);
 | 
				
			||||||
                                            (uint8_t*) &cdcd_line_coding[rhport], min16_of(sizeof(cdc_line_coding_t), p_request->wLength)), err );
 | 
					    usbd_control_xfer_st(rhport, p_request->bmRequestType_bit.direction, (uint8_t*) &cdcd_line_coding[rhport], len);
 | 
				
			||||||
  }
 | 
					
 | 
				
			||||||
  else if (CDC_REQUEST_SET_LINE_CODING == p_request->bRequest)
 | 
					    // TODO notify application on set line encoding
 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
    STASK_INVOKE( usbd_control_xfer_st(rhport, (tusb_dir_t) p_request->bmRequestType_bit.direction,
 | 
					 | 
				
			||||||
                                            (uint8_t*) &cdcd_line_coding[rhport], min16_of(sizeof(cdc_line_coding_t), p_request->wLength)), err );
 | 
					 | 
				
			||||||
    // TODO notify application on xfer complete
 | 
					 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  else if (CDC_REQUEST_SET_CONTROL_LINE_STATE == p_request->bRequest )
 | 
					  else if (CDC_REQUEST_SET_CONTROL_LINE_STATE == p_request->bRequest )
 | 
				
			||||||
  {
 | 
					  {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -192,8 +192,6 @@ tusb_error_t hidd_control_request_st(uint8_t rhport, tusb_control_request_t cons
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  OSAL_SUBTASK_BEGIN
 | 
					  OSAL_SUBTASK_BEGIN
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  tusb_error_t err;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  //------------- STD Request -------------//
 | 
					  //------------- STD Request -------------//
 | 
				
			||||||
  if (p_request->bmRequestType_bit.type == TUSB_REQ_TYPE_STANDARD)
 | 
					  if (p_request->bmRequestType_bit.type == TUSB_REQ_TYPE_STANDARD)
 | 
				
			||||||
  {
 | 
					  {
 | 
				
			||||||
@@ -209,7 +207,7 @@ tusb_error_t hidd_control_request_st(uint8_t rhport, tusb_control_request_t cons
 | 
				
			|||||||
      // copy to allow report descriptor not to be in USBRAM
 | 
					      // copy to allow report descriptor not to be in USBRAM
 | 
				
			||||||
      memcpy(m_hid_buffer, p_hid->p_report_desc, p_hid->report_length);
 | 
					      memcpy(m_hid_buffer, p_hid->p_report_desc, p_hid->report_length);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      STASK_INVOKE( usbd_control_xfer_st(rhport, p_request->bmRequestType_bit.direction, m_hid_buffer, p_hid->report_length), err );
 | 
					      usbd_control_xfer_st(rhport, p_request->bmRequestType_bit.direction, m_hid_buffer, p_hid->report_length);
 | 
				
			||||||
    }else
 | 
					    }else
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
      dcd_control_stall(rhport);
 | 
					      dcd_control_stall(rhport);
 | 
				
			||||||
@@ -227,14 +225,13 @@ tusb_error_t hidd_control_request_st(uint8_t rhport, tusb_control_request_t cons
 | 
				
			|||||||
                                                       &p_buffer, p_request->wLength);
 | 
					                                                       &p_buffer, p_request->wLength);
 | 
				
			||||||
      STASK_ASSERT( p_buffer != NULL && actual_length > 0 );
 | 
					      STASK_ASSERT( p_buffer != NULL && actual_length > 0 );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      STASK_INVOKE( usbd_control_xfer_st(rhport, p_request->bmRequestType_bit.direction, p_buffer, actual_length), err );
 | 
					      usbd_control_xfer_st(rhport, p_request->bmRequestType_bit.direction, p_buffer, actual_length);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    else if ( (HID_REQUEST_CONTROL_SET_REPORT == p_request->bRequest) && (p_driver->set_report_cb != NULL) )
 | 
					    else if ( (HID_REQUEST_CONTROL_SET_REPORT == p_request->bRequest) && (p_driver->set_report_cb != NULL) )
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
      //        return TUSB_ERROR_DCD_CONTROL_REQUEST_NOT_SUPPORT; // TODO test STALL control out endpoint (with mouse+keyboard)
 | 
					      //        return TUSB_ERROR_DCD_CONTROL_REQUEST_NOT_SUPPORT; // TODO test STALL control out endpoint (with mouse+keyboard)
 | 
				
			||||||
      // wValue = Report Type | Report ID
 | 
					      // wValue = Report Type | Report ID
 | 
				
			||||||
      STASK_INVOKE( usbd_control_xfer_st(rhport, p_request->bmRequestType_bit.direction, m_hid_buffer, p_request->wLength), err );
 | 
					      usbd_control_xfer_st(rhport, p_request->bmRequestType_bit.direction, m_hid_buffer, p_request->wLength);
 | 
				
			||||||
      STASK_ASSERT_ERR(err);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
      p_driver->set_report_cb(rhport, u16_high_u8(p_request->wValue), m_hid_buffer, p_request->wLength);
 | 
					      p_driver->set_report_cb(rhport, u16_high_u8(p_request->wValue), m_hid_buffer, p_request->wLength);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -153,7 +153,7 @@ tusb_error_t mscd_control_request_st(uint8_t rhport, tusb_control_request_t cons
 | 
				
			|||||||
  {
 | 
					  {
 | 
				
			||||||
    // Note: lpc11/13u need xfer data's address to be aligned 64 -> make use of scsi_data instead of using max_lun directly
 | 
					    // Note: lpc11/13u need xfer data's address to be aligned 64 -> make use of scsi_data instead of using max_lun directly
 | 
				
			||||||
    p_msc->scsi_data[0] = p_msc->max_lun;
 | 
					    p_msc->scsi_data[0] = p_msc->max_lun;
 | 
				
			||||||
    STASK_INVOKE( usbd_control_xfer_st(rhport, p_request->bmRequestType_bit.direction, p_msc->scsi_data, 1), err);
 | 
					    usbd_control_xfer_st(rhport, p_request->bmRequestType_bit.direction, p_msc->scsi_data, 1);
 | 
				
			||||||
  }else
 | 
					  }else
 | 
				
			||||||
  {
 | 
					  {
 | 
				
			||||||
    dcd_control_stall(rhport); // stall unsupported request
 | 
					    dcd_control_stall(rhport); // stall unsupported request
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -66,6 +66,7 @@
 | 
				
			|||||||
#include "tusb_verify.h"
 | 
					#include "tusb_verify.h"
 | 
				
			||||||
#include "binary.h"
 | 
					#include "binary.h"
 | 
				
			||||||
#include "tusb_error.h"
 | 
					#include "tusb_error.h"
 | 
				
			||||||
 | 
					#include "tusb_hal.h"
 | 
				
			||||||
#include "tusb_fifo.h"
 | 
					#include "tusb_fifo.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//------------- TUSB Header -------------//
 | 
					//------------- TUSB Header -------------//
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -189,8 +189,8 @@ VERIFY_STATIC(sizeof(usbd_task_event_t) <= 12, "size is not correct");
 | 
				
			|||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static osal_queue_t _usbd_q;
 | 
					static osal_queue_t     _usbd_q;
 | 
				
			||||||
static osal_semaphore_t _control_sem; // TODO may need to change to static with wrapper function
 | 
					/*static*/ osal_semaphore_t _usbd_ctrl_sem;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//--------------------------------------------------------------------+
 | 
					//--------------------------------------------------------------------+
 | 
				
			||||||
// IMPLEMENTATION
 | 
					// IMPLEMENTATION
 | 
				
			||||||
@@ -212,7 +212,7 @@ tusb_error_t usbd_init (void)
 | 
				
			|||||||
  _usbd_q = osal_queue_create(USBD_TASK_QUEUE_DEPTH, sizeof(usbd_task_event_t));
 | 
					  _usbd_q = osal_queue_create(USBD_TASK_QUEUE_DEPTH, sizeof(usbd_task_event_t));
 | 
				
			||||||
  VERIFY(_usbd_q, TUSB_ERROR_OSAL_QUEUE_FAILED);
 | 
					  VERIFY(_usbd_q, TUSB_ERROR_OSAL_QUEUE_FAILED);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  _control_sem = osal_semaphore_create(1, 0);
 | 
					  _usbd_ctrl_sem = osal_semaphore_create(1, 0);
 | 
				
			||||||
  VERIFY(_usbd_q, TUSB_ERROR_OSAL_SEMAPHORE_FAILED);
 | 
					  VERIFY(_usbd_q, TUSB_ERROR_OSAL_SEMAPHORE_FAILED);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  osal_task_create(usbd_task, "usbd", TUC_DEVICE_STACKSIZE, NULL, TUSB_CFG_OS_TASK_PRIO);
 | 
					  osal_task_create(usbd_task, "usbd", TUC_DEVICE_STACKSIZE, NULL, TUSB_CFG_OS_TASK_PRIO);
 | 
				
			||||||
@@ -310,29 +310,6 @@ static tusb_error_t usbd_main_st(void)
 | 
				
			|||||||
//--------------------------------------------------------------------+
 | 
					//--------------------------------------------------------------------+
 | 
				
			||||||
// CONTROL REQUEST
 | 
					// CONTROL REQUEST
 | 
				
			||||||
//--------------------------------------------------------------------+
 | 
					//--------------------------------------------------------------------+
 | 
				
			||||||
tusb_error_t usbd_control_xfer_st(uint8_t rhport, tusb_dir_t dir, uint8_t * buffer, uint16_t length)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
  OSAL_SUBTASK_BEGIN
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  tusb_error_t error;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  // Data
 | 
					 | 
				
			||||||
  if ( length )
 | 
					 | 
				
			||||||
  {
 | 
					 | 
				
			||||||
    dcd_control_xfer(rhport, dir, buffer, length);
 | 
					 | 
				
			||||||
    osal_semaphore_wait( _control_sem, 100, &error );
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    STASK_ASSERT_ERR( error );
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  // Status opposite direction with Zero Length
 | 
					 | 
				
			||||||
  // No need to wait for status to complete therefore
 | 
					 | 
				
			||||||
  // status phase must not call dcd_control_complete/dcd_xfer_complete
 | 
					 | 
				
			||||||
  dcd_control_status(rhport, dir);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  OSAL_SUBTASK_END
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static tusb_error_t proc_control_request_st(uint8_t rhport, tusb_control_request_t const * const p_request)
 | 
					static tusb_error_t proc_control_request_st(uint8_t rhport, tusb_control_request_t const * const p_request)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
  OSAL_SUBTASK_BEGIN
 | 
					  OSAL_SUBTASK_BEGIN
 | 
				
			||||||
@@ -351,7 +328,7 @@ static tusb_error_t proc_control_request_st(uint8_t rhport, tusb_control_request
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
      if ( len )
 | 
					      if ( len )
 | 
				
			||||||
      {
 | 
					      {
 | 
				
			||||||
        STASK_INVOKE( usbd_control_xfer_st(rhport, p_request->bmRequestType_bit.direction, (uint8_t*) buffer, len ), error );
 | 
					        usbd_control_xfer_st(rhport, p_request->bmRequestType_bit.direction, (uint8_t*) buffer, len );
 | 
				
			||||||
      }else
 | 
					      }else
 | 
				
			||||||
      {
 | 
					      {
 | 
				
			||||||
        dcd_control_stall(rhport); // stall unsupported descriptor
 | 
					        dcd_control_stall(rhport); // stall unsupported descriptor
 | 
				
			||||||
@@ -360,7 +337,7 @@ static tusb_error_t proc_control_request_st(uint8_t rhport, tusb_control_request
 | 
				
			|||||||
    else if (TUSB_REQ_GET_CONFIGURATION == p_request->bRequest )
 | 
					    else if (TUSB_REQ_GET_CONFIGURATION == p_request->bRequest )
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
      memcpy(usbd_enum_buffer, &usbd_devices[rhport].config_num, 1);
 | 
					      memcpy(usbd_enum_buffer, &usbd_devices[rhport].config_num, 1);
 | 
				
			||||||
      STASK_INVOKE( usbd_control_xfer_st(rhport, p_request->bmRequestType_bit.direction, (uint8_t*) usbd_enum_buffer, 1), error );
 | 
					      usbd_control_xfer_st(rhport, p_request->bmRequestType_bit.direction, (uint8_t*) usbd_enum_buffer, 1);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    else if ( TUSB_REQ_SET_ADDRESS == p_request->bRequest )
 | 
					    else if ( TUSB_REQ_SET_ADDRESS == p_request->bRequest )
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
@@ -533,7 +510,7 @@ void dcd_bus_event(uint8_t rhport, usbd_bus_event_type_t bus_event)
 | 
				
			|||||||
    case USBD_BUS_EVENT_RESET     :
 | 
					    case USBD_BUS_EVENT_RESET     :
 | 
				
			||||||
      memclr_(&usbd_devices[rhport], sizeof(usbd_device_info_t));
 | 
					      memclr_(&usbd_devices[rhport], sizeof(usbd_device_info_t));
 | 
				
			||||||
      osal_queue_flush(_usbd_q);
 | 
					      osal_queue_flush(_usbd_q);
 | 
				
			||||||
      osal_semaphore_reset(_control_sem);
 | 
					      osal_semaphore_reset(_usbd_ctrl_sem);
 | 
				
			||||||
      for (uint8_t class_code = TUSB_CLASS_AUDIO; class_code < USBD_CLASS_DRIVER_COUNT; class_code++)
 | 
					      for (uint8_t class_code = TUSB_CLASS_AUDIO; class_code < USBD_CLASS_DRIVER_COUNT; class_code++)
 | 
				
			||||||
      {
 | 
					      {
 | 
				
			||||||
        if ( usbd_class_drivers[class_code].close ) usbd_class_drivers[class_code].close( rhport );
 | 
					        if ( usbd_class_drivers[class_code].close ) usbd_class_drivers[class_code].close( rhport );
 | 
				
			||||||
@@ -585,7 +562,7 @@ void dcd_xfer_complete(uint8_t rhport, uint8_t ep_addr, uint32_t xferred_bytes,
 | 
				
			|||||||
    (void) succeeded;
 | 
					    (void) succeeded;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Control Transfer
 | 
					    // Control Transfer
 | 
				
			||||||
    osal_semaphore_post( _control_sem );
 | 
					    osal_semaphore_post( _usbd_ctrl_sem );
 | 
				
			||||||
  }else
 | 
					  }else
 | 
				
			||||||
  {
 | 
					  {
 | 
				
			||||||
    usbd_task_event_t task_event =
 | 
					    usbd_task_event_t task_event =
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -41,6 +41,9 @@
 | 
				
			|||||||
 extern "C" {
 | 
					 extern "C" {
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// for used by usbd_control_xfer_st() only, must not be used directly
 | 
				
			||||||
 | 
					extern osal_semaphore_t _usbd_ctrl_sem;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//--------------------------------------------------------------------+
 | 
					//--------------------------------------------------------------------+
 | 
				
			||||||
// INTERNAL API
 | 
					// INTERNAL API
 | 
				
			||||||
//--------------------------------------------------------------------+
 | 
					//--------------------------------------------------------------------+
 | 
				
			||||||
@@ -48,7 +51,25 @@ tusb_error_t usbd_init(void);
 | 
				
			|||||||
void         usbd_task( void* param);
 | 
					void         usbd_task( void* param);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Carry out Data and Status stage of control transfer
 | 
					// Carry out Data and Status stage of control transfer
 | 
				
			||||||
tusb_error_t usbd_control_xfer_st(uint8_t rhport, tusb_dir_t dir, uint8_t * buffer, uint16_t length);
 | 
					//tusb_error_t usbd_control_xfer_st(uint8_t rhport, tusb_dir_t dir, uint8_t * buffer, uint16_t length);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// Carry out Data and Status stage of control transfer
 | 
				
			||||||
 | 
					// Must be call in a subtask (_st) function
 | 
				
			||||||
 | 
					#define usbd_control_xfer_st(_rhport, _dir, _buffer, _len) \
 | 
				
			||||||
 | 
					  do {\
 | 
				
			||||||
 | 
					    if (_len) { \
 | 
				
			||||||
 | 
					      tusb_error_t err;\
 | 
				
			||||||
 | 
					      dcd_control_xfer(_rhport, _dir, _buffer, _len);\
 | 
				
			||||||
 | 
					      osal_semaphore_wait( _usbd_ctrl_sem, OSAL_TIMEOUT_NORMAL, &err );\
 | 
				
			||||||
 | 
					      STASK_ASSERT_ERR( err );\
 | 
				
			||||||
 | 
					    }\
 | 
				
			||||||
 | 
					    /* No need to wait for status to complete therefore */ \
 | 
				
			||||||
 | 
					    /* status phase must not call dcd_control_complete/dcd_xfer_complete*/ \
 | 
				
			||||||
 | 
					    dcd_control_status(_rhport, _dir);\
 | 
				
			||||||
 | 
					  }while(0)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef __cplusplus
 | 
					#ifdef __cplusplus
 | 
				
			||||||
 }
 | 
					 }
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user