mirror of
https://github.com/hathach/tinyusb.git
synced 2025-01-17 05:32:55 +08:00
replace dcd_edpt_(clear)stall by usbd_edpt_(clear)stall
- remove dcd_edpt_stalled() from dcd porting
This commit is contained in:
parent
4722376654
commit
1e9848d917
@ -147,9 +147,9 @@ The arguments are:
|
||||
* the result of the transfer. Failure isn't handled yet.
|
||||
* `true` to note the call is from an interrupt handler.
|
||||
|
||||
##### dcd_edpt_stall / dcd_edpt_stalled / dcd_edpt_clear_stall
|
||||
##### dcd_edpt_stall / dcd_edpt_clear_stall
|
||||
|
||||
Stalling is one way an endpoint can indicate failure such as when an unsupported command is transmitted. The trio of `dcd_edpt_stall`, `dcd_edpt_stalled`, `dcd_edpt_clear_stall` help manage the stall state of all endpoints.
|
||||
Stalling is one way an endpoint can indicate failure such as when an unsupported command is transmitted. The pair of `dcd_edpt_stall`, `dcd_edpt_clear_stall` help manage the stall state of all endpoints.
|
||||
|
||||
## Woohoo!
|
||||
|
||||
|
@ -412,7 +412,7 @@ bool mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t
|
||||
p_msc->stage = MSC_STAGE_STATUS;
|
||||
|
||||
tud_msc_set_sense(p_cbw->lun, SCSI_SENSE_ILLEGAL_REQUEST, 0x20, 0x00); // Sense = Invalid Command Operation
|
||||
dcd_edpt_stall(rhport, p_msc->ep_in);
|
||||
usbd_edpt_stall(rhport, p_msc->ep_in);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -512,7 +512,7 @@ bool mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t
|
||||
if ( p_msc->stage == MSC_STAGE_STATUS )
|
||||
{
|
||||
// Either endpoints is stalled, need to wait until it is cleared by host
|
||||
if ( dcd_edpt_stalled(rhport, p_msc->ep_in) || dcd_edpt_stalled(rhport, p_msc->ep_out) )
|
||||
if ( usbd_edpt_stalled(rhport, p_msc->ep_in) || usbd_edpt_stalled(rhport, p_msc->ep_out) )
|
||||
{
|
||||
// simulate an transfer complete with adjusted parameters --> this driver callback will fired again
|
||||
dcd_event_xfer_complete(rhport, p_msc->ep_out, 0, XFER_RESULT_SUCCESS, false);
|
||||
@ -573,7 +573,7 @@ static void proc_read10_cmd(uint8_t rhport, mscd_interface_t* p_msc)
|
||||
p_csw->status = MSC_CSW_STATUS_FAILED;
|
||||
|
||||
tud_msc_set_sense(p_cbw->lun, SCSI_SENSE_ILLEGAL_REQUEST, 0x20, 0x00); // Sense = Invalid Command Operation
|
||||
dcd_edpt_stall(rhport, p_msc->ep_in);
|
||||
usbd_edpt_stall(rhport, p_msc->ep_in);
|
||||
}
|
||||
else if ( nbytes == 0 )
|
||||
{
|
||||
@ -599,7 +599,7 @@ static void proc_write10_cmd(uint8_t rhport, mscd_interface_t* p_msc)
|
||||
p_csw->status = MSC_CSW_STATUS_FAILED;
|
||||
|
||||
tud_msc_set_sense(p_cbw->lun, SCSI_SENSE_DATA_PROTECT, 0x27, 0x00); // Sense = Write protected
|
||||
dcd_edpt_stall(rhport, p_msc->ep_out);
|
||||
usbd_edpt_stall(rhport, p_msc->ep_out);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -102,7 +102,6 @@ void dcd_set_config (uint8_t rhport, uint8_t config_num);
|
||||
* - busy : Check if endpoint transferring is complete (TODO remove)
|
||||
* - stall : stall endpoint
|
||||
* - clear_stall : clear stall
|
||||
* - stalled : check if stalled ( TODO remove )
|
||||
*------------------------------------------------------------------*/
|
||||
bool dcd_edpt_open (uint8_t rhport, tusb_desc_endpoint_t const * p_endpoint_desc);
|
||||
bool dcd_edpt_xfer (uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t total_bytes);
|
||||
@ -110,7 +109,6 @@ bool dcd_edpt_busy (uint8_t rhport, uint8_t ep_addr);
|
||||
|
||||
void dcd_edpt_stall (uint8_t rhport, uint8_t ep_addr);
|
||||
void dcd_edpt_clear_stall (uint8_t rhport, uint8_t ep_addr);
|
||||
bool dcd_edpt_stalled (uint8_t rhport, uint8_t ep_addr);
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
/* Event Function
|
||||
|
@ -44,9 +44,11 @@
|
||||
typedef struct {
|
||||
uint8_t config_num;
|
||||
|
||||
uint8_t itf2drv[16]; // map interface number to driver (0xff is invalid)
|
||||
uint8_t ep2drv[8][2]; // map endpoint to driver ( 0xff is invalid )
|
||||
uint8_t itf2drv[16]; // map interface number to driver (0xff is invalid)
|
||||
uint8_t ep2drv[8][2]; // map endpoint to driver ( 0xff is invalid )
|
||||
|
||||
uint8_t ep_busy_mask[2]; // bit mask for busy endpoint
|
||||
uint8_t ep_stall_mask[2]; // bit mask for stalled endpoint
|
||||
}usbd_device_t;
|
||||
|
||||
static usbd_device_t _usbd_dev = { 0 };
|
||||
@ -379,7 +381,7 @@ static bool process_control_request(uint8_t rhport, tusb_control_request_t const
|
||||
{
|
||||
case TUSB_REQ_GET_STATUS:
|
||||
{
|
||||
uint16_t status = dcd_edpt_stalled(rhport, tu_u16_low(p_request->wIndex)) ? 0x0001 : 0x0000;
|
||||
uint16_t status = usbd_edpt_stalled(rhport, tu_u16_low(p_request->wIndex)) ? 0x0001 : 0x0000;
|
||||
usbd_control_xfer(rhport, p_request, &status, 2);
|
||||
}
|
||||
break;
|
||||
@ -392,7 +394,7 @@ static bool process_control_request(uint8_t rhport, tusb_control_request_t const
|
||||
|
||||
case TUSB_REQ_SET_FEATURE:
|
||||
// only endpoint feature is halted/stalled
|
||||
dcd_edpt_stall(rhport, tu_u16_low(p_request->wIndex));
|
||||
usbd_edpt_stall(rhport, tu_u16_low(p_request->wIndex));
|
||||
usbd_control_status(rhport, p_request);
|
||||
break;
|
||||
|
||||
@ -650,4 +652,35 @@ void usbd_defer_func(osal_task_func_t func, void* param, bool in_isr)
|
||||
dcd_event_handler(&event, in_isr);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// USBD Endpoint API
|
||||
//--------------------------------------------------------------------+
|
||||
void usbd_edpt_stall(uint8_t rhport, uint8_t ep_addr)
|
||||
{
|
||||
uint8_t const epnum = tu_edpt_number(ep_addr);
|
||||
uint8_t const dir = tu_edpt_dir(ep_addr);
|
||||
|
||||
dcd_edpt_stall(rhport, ep_addr);
|
||||
_usbd_dev.ep_stall_mask[dir] = tu_bit_set(_usbd_dev.ep_stall_mask[dir], epnum);
|
||||
}
|
||||
|
||||
void usbd_edpt_clear_stall(uint8_t rhport, uint8_t ep_addr)
|
||||
{
|
||||
uint8_t const epnum = tu_edpt_number(ep_addr);
|
||||
uint8_t const dir = tu_edpt_dir(ep_addr);
|
||||
|
||||
dcd_edpt_clear_stall(rhport, ep_addr);
|
||||
_usbd_dev.ep_stall_mask[dir] = tu_bit_clear(_usbd_dev.ep_stall_mask[dir], epnum);
|
||||
}
|
||||
|
||||
bool usbd_edpt_stalled(uint8_t rhport, uint8_t ep_addr)
|
||||
{
|
||||
(void) rhport;
|
||||
|
||||
uint8_t const epnum = tu_edpt_number(ep_addr);
|
||||
uint8_t const dir = tu_edpt_dir(ep_addr);
|
||||
|
||||
return tu_bit_test(_usbd_dev.ep_stall_mask[dir], epnum);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -38,7 +38,6 @@
|
||||
// INCLUDE
|
||||
//--------------------------------------------------------------------+
|
||||
#include <common/tusb_common.h>
|
||||
#include "osal/osal.h"
|
||||
#include "device/dcd.h"
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
|
@ -52,6 +52,11 @@ bool usbd_control_status(uint8_t rhport, tusb_control_request_t const * request)
|
||||
// Stall control endpoint (both IN and OUT) until new setup packet arrived
|
||||
void usbd_control_stall(uint8_t rhport);
|
||||
|
||||
|
||||
void usbd_edpt_stall(uint8_t rhport, uint8_t ep_addr);
|
||||
void usbd_edpt_clear_stall(uint8_t rhport, uint8_t ep_addr);
|
||||
bool usbd_edpt_stalled(uint8_t rhport, uint8_t ep_addr);
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
/* Helper
|
||||
*------------------------------------------------------------------*/
|
||||
|
@ -189,20 +189,6 @@ bool dcd_edpt_xfer (uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t
|
||||
return true;
|
||||
}
|
||||
|
||||
bool dcd_edpt_stalled (uint8_t rhport, uint8_t ep_addr)
|
||||
{
|
||||
(void) rhport;
|
||||
|
||||
// control is never got halted
|
||||
if ( ep_addr == 0 ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
uint8_t const epnum = tu_edpt_number(ep_addr);
|
||||
UsbDeviceEndpoint* ep = &USB->DEVICE.DeviceEndpoint[epnum];
|
||||
return (tu_edpt_dir(ep_addr) == TUSB_DIR_IN ) ? ep->EPINTFLAG.bit.STALL1 : ep->EPINTFLAG.bit.STALL0;
|
||||
}
|
||||
|
||||
void dcd_edpt_stall (uint8_t rhport, uint8_t ep_addr)
|
||||
{
|
||||
(void) rhport;
|
||||
|
@ -193,20 +193,6 @@ bool dcd_edpt_xfer (uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t
|
||||
return true;
|
||||
}
|
||||
|
||||
bool dcd_edpt_stalled (uint8_t rhport, uint8_t ep_addr)
|
||||
{
|
||||
(void) rhport;
|
||||
|
||||
// control is never got halted
|
||||
if ( ep_addr == 0 ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
uint8_t const epnum = tu_edpt_number(ep_addr);
|
||||
UsbDeviceEndpoint* ep = &USB->DEVICE.DeviceEndpoint[epnum];
|
||||
return (tu_edpt_dir(ep_addr) == TUSB_DIR_IN ) ? ep->EPINTFLAG.bit.STALL1 : ep->EPINTFLAG.bit.STALL0;
|
||||
}
|
||||
|
||||
void dcd_edpt_stall (uint8_t rhport, uint8_t ep_addr)
|
||||
{
|
||||
(void) rhport;
|
||||
|
@ -279,17 +279,6 @@ bool dcd_edpt_xfer (uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t
|
||||
return true;
|
||||
}
|
||||
|
||||
bool dcd_edpt_stalled (uint8_t rhport, uint8_t ep_addr)
|
||||
{
|
||||
(void) rhport;
|
||||
|
||||
// control is never got halted
|
||||
if ( ep_addr == 0 ) return false;
|
||||
|
||||
uint8_t const epnum = tu_edpt_number(ep_addr);
|
||||
return (tu_edpt_dir(ep_addr) == TUSB_DIR_IN ) ? NRF_USBD->HALTED.EPIN[epnum] : NRF_USBD->HALTED.EPOUT[epnum];
|
||||
}
|
||||
|
||||
void dcd_edpt_stall (uint8_t rhport, uint8_t ep_addr)
|
||||
{
|
||||
(void) rhport;
|
||||
|
@ -182,14 +182,6 @@ void dcd_edpt_stall(uint8_t rhport, uint8_t ep_addr)
|
||||
_dcd.ep[ep_id][0].stall = 1;
|
||||
}
|
||||
|
||||
bool dcd_edpt_stalled(uint8_t rhport, uint8_t ep_addr)
|
||||
{
|
||||
(void) rhport;
|
||||
|
||||
uint8_t const ep_id = ep_addr2id(ep_addr);
|
||||
return _dcd.ep[ep_id][0].stall;
|
||||
}
|
||||
|
||||
void dcd_edpt_clear_stall(uint8_t rhport, uint8_t ep_addr)
|
||||
{
|
||||
(void) rhport;
|
||||
|
@ -344,14 +344,6 @@ void dcd_edpt_clear_stall(uint8_t rhport, uint8_t ep_addr)
|
||||
sie_write(SIE_CMDCODE_ENDPOINT_SET_STATUS+ep_id, 1, 0);
|
||||
}
|
||||
|
||||
bool dcd_edpt_stalled (uint8_t rhport, uint8_t ep_addr)
|
||||
{
|
||||
(void) rhport;
|
||||
|
||||
uint8_t const ep_state = sie_read(SIE_CMDCODE_ENDPOINT_SELECT + ep_addr2idx(ep_addr));
|
||||
return (ep_state & SIE_SELECT_ENDPOINT_STALL_MASK) ? true : false;
|
||||
}
|
||||
|
||||
static bool control_xact(uint8_t rhport, uint8_t dir, uint8_t * buffer, uint8_t len)
|
||||
{
|
||||
(void) rhport;
|
||||
|
@ -201,14 +201,6 @@ void dcd_edpt_stall(uint8_t rhport, uint8_t ep_addr)
|
||||
LPC_USB[rhport]->ENDPTCTRL[epnum] |= ENDPTCTRL_MASK_STALL << (dir ? 16 : 0);
|
||||
}
|
||||
|
||||
bool dcd_edpt_stalled (uint8_t rhport, uint8_t ep_addr)
|
||||
{
|
||||
uint8_t const epnum = tu_edpt_number(ep_addr);
|
||||
uint8_t const dir = tu_edpt_dir(ep_addr);
|
||||
|
||||
return LPC_USB[rhport]->ENDPTCTRL[epnum] & (ENDPTCTRL_MASK_STALL << (dir ? 16 : 0));
|
||||
}
|
||||
|
||||
void dcd_edpt_clear_stall(uint8_t rhport, uint8_t ep_addr)
|
||||
{
|
||||
uint8_t const epnum = tu_edpt_number(ep_addr);
|
||||
|
@ -70,9 +70,6 @@ void dcd_edpt_stall (uint8_t rhport, uint8_t ep_addr)
|
||||
{}
|
||||
void dcd_edpt_clear_stall (uint8_t rhport, uint8_t ep_addr)
|
||||
{}
|
||||
bool dcd_edpt_stalled (uint8_t rhport, uint8_t ep_addr)
|
||||
{
|
||||
return false;}
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -299,30 +299,6 @@ bool dcd_edpt_xfer (uint8_t rhport, uint8_t ep_addr, uint8_t * buffer, uint16_t
|
||||
return true;
|
||||
}
|
||||
|
||||
bool dcd_edpt_stalled (uint8_t rhport, uint8_t ep_addr)
|
||||
{
|
||||
(void) rhport;
|
||||
USB_OTG_OUTEndpointTypeDef * out_ep = OUT_EP_BASE;
|
||||
USB_OTG_INEndpointTypeDef * in_ep = IN_EP_BASE;
|
||||
|
||||
// control is never got halted
|
||||
if(ep_addr == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
uint8_t const epnum = tu_edpt_number(ep_addr);
|
||||
uint8_t const dir = tu_edpt_dir(ep_addr);
|
||||
bool stalled = false;
|
||||
|
||||
if(dir == TUSB_DIR_IN) {
|
||||
stalled = (in_ep[epnum].DIEPCTL & USB_OTG_DIEPCTL_STALL_Msk);
|
||||
} else {
|
||||
stalled = (out_ep[epnum].DOEPCTL & USB_OTG_DOEPCTL_STALL_Msk);
|
||||
}
|
||||
|
||||
return stalled;
|
||||
}
|
||||
|
||||
// TODO: The logic for STALLing and disabling an endpoint is very similar
|
||||
// (send STALL versus NAK handshakes back). Refactor into resuable function.
|
||||
void dcd_edpt_stall (uint8_t rhport, uint8_t ep_addr)
|
||||
|
@ -11,7 +11,7 @@ TOP := $(patsubst %/tools/top.mk,%,$(THIS_MAKEFILE))
|
||||
|
||||
TOP := $(shell realpath $(TOP))
|
||||
|
||||
$(info Top directory is $(TOP))
|
||||
#$(info Top directory is $(TOP))
|
||||
|
||||
CURRENT_PATH := $(shell realpath --relative-to=$(TOP) `pwd`)
|
||||
$(info Path from top is $(CURRENT_PATH))
|
||||
#$(info Path from top is $(CURRENT_PATH))
|
||||
|
Loading…
x
Reference in New Issue
Block a user