mirror of
https://github.com/hathach/tinyusb.git
synced 2025-01-17 05:32:55 +08:00
lpc55s69 isochronous, dummy address for endpoint buffers to prevent accidental writes
This commit is contained in:
parent
a95fb36f72
commit
16f1554a03
@ -78,8 +78,9 @@ typedef struct {
|
|||||||
|
|
||||||
// Max nbytes for each control/bulk/interrupt transfer
|
// Max nbytes for each control/bulk/interrupt transfer
|
||||||
enum {
|
enum {
|
||||||
NBYTES_CBI_FULLSPEED_MAX = 64,
|
NBYTES_CBI_FS_ISO_MAX = 1023, // FS ISO
|
||||||
NBYTES_CBI_HIGHSPEED_MAX = 32767 // can be up to all 15-bit, but only tested with 4096
|
NBYTES_CBI_FS_MAX = 64, // FS control/bulk/interrupt
|
||||||
|
NBYTES_CBI_HS_MAX = 32767 // can be up to all 15-bit, but only tested with 4096
|
||||||
};
|
};
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
@ -174,6 +175,7 @@ typedef struct
|
|||||||
// For example: LPC55s69 port1 Highspeed must be USB_RAM (0x40100000)
|
// For example: LPC55s69 port1 Highspeed must be USB_RAM (0x40100000)
|
||||||
// Use CFG_TUSB_MEM_SECTION to place it accordingly.
|
// Use CFG_TUSB_MEM_SECTION to place it accordingly.
|
||||||
CFG_TUSB_MEM_SECTION TU_ATTR_ALIGNED(256) static dcd_data_t _dcd;
|
CFG_TUSB_MEM_SECTION TU_ATTR_ALIGNED(256) static dcd_data_t _dcd;
|
||||||
|
CFG_TUSB_MEM_SECTION TU_ATTR_ALIGNED(256) static volatile uint8_t dummy[64]; // TODO temp fix to prevent accidental overwrite due to ep[][].buffer_xx.offset being 0
|
||||||
|
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
// Multiple Controllers
|
// Multiple Controllers
|
||||||
@ -225,8 +227,44 @@ static inline uint8_t ep_addr2id(uint8_t ep_addr)
|
|||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
// CONTROLLER API
|
// CONTROLLER API
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
|
|
||||||
|
static void prepare_setup_packet(uint8_t rhport)
|
||||||
|
{
|
||||||
|
if (_dcd_controller[rhport].max_speed == TUSB_SPEED_FULL )
|
||||||
|
{
|
||||||
|
_dcd.ep[0][1].buffer_fs.offset = get_buf_offset(_dcd.setup_packet);
|
||||||
|
}else
|
||||||
|
{
|
||||||
|
_dcd.ep[0][1].buffer_hs.offset = get_buf_offset(_dcd.setup_packet);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void edpt_reset(uint8_t rhport, uint8_t ep_id)
|
||||||
|
{
|
||||||
|
const uint32_t offset = get_buf_offset((void*)dummy);
|
||||||
|
tu_memclr(&_dcd.ep[ep_id], sizeof(_dcd.ep[ep_id]));
|
||||||
|
if (_dcd_controller[rhport].max_speed == TUSB_SPEED_FULL )
|
||||||
|
{
|
||||||
|
_dcd.ep[ep_id][0].buffer_fs.offset = _dcd.ep[ep_id][1].buffer_fs.offset = offset;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_dcd.ep[ep_id][0].buffer_hs.offset = _dcd.ep[ep_id][1].buffer_hs.offset = offset;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void edpt_reset_all(uint8_t rhport)
|
||||||
|
{
|
||||||
|
for (uint8_t ep_id = 0; ep_id < 2*_dcd_controller[rhport].ep_pairs; ++ep_id)
|
||||||
|
{
|
||||||
|
edpt_reset(rhport, ep_id);
|
||||||
|
}
|
||||||
|
prepare_setup_packet(rhport);
|
||||||
|
}
|
||||||
void dcd_init(uint8_t rhport)
|
void dcd_init(uint8_t rhport)
|
||||||
{
|
{
|
||||||
|
edpt_reset_all(rhport);
|
||||||
|
|
||||||
dcd_registers_t* dcd_reg = _dcd_controller[rhport].regs;
|
dcd_registers_t* dcd_reg = _dcd_controller[rhport].regs;
|
||||||
|
|
||||||
dcd_reg->EPLISTSTART = (uint32_t) _dcd.ep;
|
dcd_reg->EPLISTSTART = (uint32_t) _dcd.ep;
|
||||||
@ -310,18 +348,13 @@ void dcd_edpt_clear_stall(uint8_t rhport, uint8_t ep_addr)
|
|||||||
|
|
||||||
bool dcd_edpt_open(uint8_t rhport, tusb_desc_endpoint_t const * p_endpoint_desc)
|
bool dcd_edpt_open(uint8_t rhport, tusb_desc_endpoint_t const * p_endpoint_desc)
|
||||||
{
|
{
|
||||||
(void) rhport;
|
|
||||||
|
|
||||||
// TODO not support ISO yet
|
|
||||||
TU_VERIFY(p_endpoint_desc->bmAttributes.xfer != TUSB_XFER_ISOCHRONOUS);
|
|
||||||
|
|
||||||
//------------- Prepare Queue Head -------------//
|
//------------- Prepare Queue Head -------------//
|
||||||
uint8_t ep_id = ep_addr2id(p_endpoint_desc->bEndpointAddress);
|
uint8_t ep_id = ep_addr2id(p_endpoint_desc->bEndpointAddress);
|
||||||
|
|
||||||
// Check if endpoint is available
|
// Check if endpoint is available
|
||||||
TU_ASSERT( _dcd.ep[ep_id][0].disable && _dcd.ep[ep_id][1].disable );
|
TU_ASSERT( _dcd.ep[ep_id][0].disable && _dcd.ep[ep_id][1].disable );
|
||||||
|
|
||||||
tu_memclr(_dcd.ep[ep_id], 2*sizeof(ep_cmd_sts_t));
|
edpt_reset(rhport, ep_id);
|
||||||
_dcd.ep[ep_id][0].is_iso = (p_endpoint_desc->bmAttributes.xfer == TUSB_XFER_ISOCHRONOUS);
|
_dcd.ep[ep_id][0].is_iso = (p_endpoint_desc->bmAttributes.xfer == TUSB_XFER_ISOCHRONOUS);
|
||||||
|
|
||||||
// Enable EP interrupt
|
// Enable EP interrupt
|
||||||
@ -333,19 +366,18 @@ bool dcd_edpt_open(uint8_t rhport, tusb_desc_endpoint_t const * p_endpoint_desc)
|
|||||||
|
|
||||||
void dcd_edpt_close_all (uint8_t rhport)
|
void dcd_edpt_close_all (uint8_t rhport)
|
||||||
{
|
{
|
||||||
(void) rhport;
|
for (uint8_t ep_id = 0; ep_id < 2*_dcd_controller[rhport].ep_pairs; ++ep_id)
|
||||||
// TODO implement dcd_edpt_close_all()
|
{
|
||||||
|
_dcd.ep[ep_id][0].active = _dcd.ep[ep_id][0].active = 0; // TODO proper way is to EPSKIP then wait ep[][].active then write ep[][].disable (see table 778 in LPC55S69 Use Manual)
|
||||||
|
_dcd.ep[ep_id][0].disable = _dcd.ep[ep_id][1].disable = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void prepare_setup_packet(uint8_t rhport)
|
void dcd_edpt_close(uint8_t rhport, uint8_t ep_addr)
|
||||||
{
|
{
|
||||||
if (_dcd_controller[rhport].max_speed == TUSB_SPEED_FULL )
|
uint8_t ep_id = ep_addr2id(ep_addr);
|
||||||
{
|
_dcd.ep[ep_id][0].active = _dcd.ep[ep_id][0].active = 0; // TODO proper way is to EPSKIP then wait ep[][].active then write ep[][].disable (see table 778 in LPC55S69 Use Manual)
|
||||||
_dcd.ep[0][1].buffer_fs.offset = get_buf_offset(_dcd.setup_packet);;
|
_dcd.ep[ep_id][0].disable = _dcd.ep[ep_id][1].disable = 1;
|
||||||
}else
|
|
||||||
{
|
|
||||||
_dcd.ep[0][1].buffer_hs.offset = get_buf_offset(_dcd.setup_packet);;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void prepare_ep_xfer(uint8_t rhport, uint8_t ep_id, uint16_t buf_offset, uint16_t total_bytes)
|
static void prepare_ep_xfer(uint8_t rhport, uint8_t ep_id, uint16_t buf_offset, uint16_t total_bytes)
|
||||||
@ -354,13 +386,12 @@ static void prepare_ep_xfer(uint8_t rhport, uint8_t ep_id, uint16_t buf_offset,
|
|||||||
|
|
||||||
if (_dcd_controller[rhport].max_speed == TUSB_SPEED_FULL )
|
if (_dcd_controller[rhport].max_speed == TUSB_SPEED_FULL )
|
||||||
{
|
{
|
||||||
// TODO ISO FullSpeed can have up to 1023 bytes
|
nbytes = tu_min16(total_bytes, _dcd.ep[ep_id][0].is_iso ? NBYTES_CBI_FS_ISO_MAX : NBYTES_CBI_FS_MAX);
|
||||||
nbytes = tu_min16(total_bytes, NBYTES_CBI_FULLSPEED_MAX);
|
|
||||||
_dcd.ep[ep_id][0].buffer_fs.offset = buf_offset;
|
_dcd.ep[ep_id][0].buffer_fs.offset = buf_offset;
|
||||||
_dcd.ep[ep_id][0].buffer_fs.nbytes = nbytes;
|
_dcd.ep[ep_id][0].buffer_fs.nbytes = nbytes;
|
||||||
}else
|
}else
|
||||||
{
|
{
|
||||||
nbytes = tu_min16(total_bytes, NBYTES_CBI_HIGHSPEED_MAX);
|
nbytes = tu_min16(total_bytes, NBYTES_CBI_HS_MAX);
|
||||||
_dcd.ep[ep_id][0].buffer_hs.offset = buf_offset;
|
_dcd.ep[ep_id][0].buffer_hs.offset = buf_offset;
|
||||||
_dcd.ep[ep_id][0].buffer_hs.nbytes = nbytes;
|
_dcd.ep[ep_id][0].buffer_hs.nbytes = nbytes;
|
||||||
}
|
}
|
||||||
@ -379,7 +410,7 @@ bool dcd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t* buffer, uint16_t to
|
|||||||
tu_memclr(&_dcd.dma[ep_id], sizeof(xfer_dma_t));
|
tu_memclr(&_dcd.dma[ep_id], sizeof(xfer_dma_t));
|
||||||
_dcd.dma[ep_id].total_bytes = total_bytes;
|
_dcd.dma[ep_id].total_bytes = total_bytes;
|
||||||
|
|
||||||
prepare_ep_xfer(rhport, ep_id, get_buf_offset(buffer), total_bytes);
|
prepare_ep_xfer(rhport, ep_id, buffer ? get_buf_offset(buffer) : get_buf_offset((void*)dummy), total_bytes);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -390,6 +421,7 @@ bool dcd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t* buffer, uint16_t to
|
|||||||
static void bus_reset(uint8_t rhport)
|
static void bus_reset(uint8_t rhport)
|
||||||
{
|
{
|
||||||
tu_memclr(&_dcd, sizeof(dcd_data_t));
|
tu_memclr(&_dcd, sizeof(dcd_data_t));
|
||||||
|
edpt_reset_all(rhport);
|
||||||
|
|
||||||
// disable all non-control endpoints on bus reset
|
// disable all non-control endpoints on bus reset
|
||||||
for(uint8_t ep_id = 2; ep_id < 2*MAX_EP_PAIRS; ep_id++)
|
for(uint8_t ep_id = 2; ep_id < 2*MAX_EP_PAIRS; ep_id++)
|
||||||
@ -397,8 +429,6 @@ static void bus_reset(uint8_t rhport)
|
|||||||
_dcd.ep[ep_id][0].disable = _dcd.ep[ep_id][1].disable = 1;
|
_dcd.ep[ep_id][0].disable = _dcd.ep[ep_id][1].disable = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
prepare_setup_packet(rhport);
|
|
||||||
|
|
||||||
dcd_registers_t* dcd_reg = _dcd_controller[rhport].regs;
|
dcd_registers_t* dcd_reg = _dcd_controller[rhport].regs;
|
||||||
|
|
||||||
dcd_reg->EPINUSE = 0;
|
dcd_reg->EPINUSE = 0;
|
||||||
@ -506,23 +536,15 @@ void dcd_int_handler(uint8_t rhport)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO support suspend & resume
|
|
||||||
if (cmd_stat & CMDSTAT_SUSPEND_CHANGE_MASK)
|
if (cmd_stat & CMDSTAT_SUSPEND_CHANGE_MASK)
|
||||||
{
|
{
|
||||||
if (cmd_stat & CMDSTAT_DEVICE_SUSPEND_MASK)
|
// suspend signal, bus idle for more than 3ms
|
||||||
{ // suspend signal, bus idle for more than 3ms
|
// Note: Host may delay more than 3 ms before and/or after bus reset before doing enumeration.
|
||||||
// Note: Host may delay more than 3 ms before and/or after bus reset before doing enumeration.
|
if (cmd_stat & CMDSTAT_DEVICE_ADDR_MASK)
|
||||||
if (cmd_stat & CMDSTAT_DEVICE_ADDR_MASK)
|
{
|
||||||
{
|
dcd_event_bus_signal(rhport, (cmd_stat & CMDSTAT_DEVICE_SUSPEND_MASK) ? DCD_EVENT_SUSPEND : DCD_EVENT_RESUME, true);
|
||||||
dcd_event_bus_signal(rhport, DCD_EVENT_SUSPEND, true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// else
|
|
||||||
// { // resume signal
|
|
||||||
// dcd_event_bus_signal(rhport, DCD_EVENT_RESUME, true);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setup Receive
|
// Setup Receive
|
||||||
|
Loading…
x
Reference in New Issue
Block a user