mirror of
https://github.com/hathach/tinyusb.git
synced 2025-02-07 05:54:11 +08:00
update musb fifo usage
This commit is contained in:
parent
e339702a2a
commit
7d8d364332
@ -153,10 +153,10 @@ static void pipe_read_write_packet_ff(tu_fifo_t *f, volatile void *fifo, unsigne
|
||||
ops[dir].tu_fifo_advance(f, total_len - rem);
|
||||
}
|
||||
|
||||
static void process_setup_packet(uint8_t rhport)
|
||||
{
|
||||
static void process_setup_packet(uint8_t rhport) {
|
||||
musb_regs_t* musb_regs = MUSB_REGS(rhport);
|
||||
uint32_t *p = (void*)&_dcd.setup_packet;
|
||||
volatile uint32_t *fifo_ptr = musb_dcd_ep_get_fifo_ptr(rhport, 0);
|
||||
volatile uint32_t *fifo_ptr = &musb_regs->fifo[0];
|
||||
volatile musb_ep0_regs_t* ep0_regs = musb_dcd_ep0_regs(rhport);
|
||||
p[0] = *fifo_ptr;
|
||||
p[1] = *fifo_ptr;
|
||||
@ -185,11 +185,12 @@ static bool handle_xfer_in(uint8_t rhport, uint_fast8_t ep_addr)
|
||||
return true;
|
||||
}
|
||||
|
||||
musb_regs_t* musb_regs = MUSB_REGS(rhport);
|
||||
volatile musb_epn_regs_t *regs = musb_dcd_epn_regs(rhport, epnum);
|
||||
const unsigned mps = regs->TXMAXP;
|
||||
const unsigned len = TU_MIN(mps, rem);
|
||||
void *buf = pipe->buf;
|
||||
volatile void *fifo_ptr = musb_dcd_ep_get_fifo_ptr(rhport, epnum);
|
||||
volatile void *fifo_ptr = &musb_regs->fifo[epnum];
|
||||
// TU_LOG1(" %p mps %d len %d rem %d\r\n", buf, mps, len, rem);
|
||||
if (len) {
|
||||
if (_dcd.pipe_buf_is_fifo[TUSB_DIR_IN] & TU_BIT(epnum_minus1)) {
|
||||
@ -210,6 +211,7 @@ static bool handle_xfer_out(uint8_t rhport, uint_fast8_t ep_addr)
|
||||
unsigned epnum = tu_edpt_number(ep_addr);
|
||||
unsigned epnum_minus1 = epnum - 1;
|
||||
pipe_state_t *pipe = &_dcd.pipe[tu_edpt_dir(ep_addr)][epnum_minus1];
|
||||
musb_regs_t* musb_regs = MUSB_REGS(rhport);
|
||||
volatile musb_epn_regs_t *regs = musb_dcd_epn_regs(rhport, epnum);
|
||||
// TU_LOG1(" RXCSRL%d = %x\r\n", epnum_minus1 + 1, regs->RXCSRL);
|
||||
|
||||
@ -220,7 +222,7 @@ static bool handle_xfer_out(uint8_t rhport, uint_fast8_t ep_addr)
|
||||
const unsigned vld = regs->RXCOUNT;
|
||||
const unsigned len = TU_MIN(TU_MIN(rem, mps), vld);
|
||||
void *buf = pipe->buf;
|
||||
volatile void *fifo_ptr = musb_dcd_ep_get_fifo_ptr(rhport, epnum);
|
||||
volatile void *fifo_ptr = &musb_regs->fifo[epnum];
|
||||
if (len) {
|
||||
if (_dcd.pipe_buf_is_fifo[TUSB_DIR_OUT] & TU_BIT(epnum_minus1)) {
|
||||
pipe_read_write_packet_ff(buf, fifo_ptr, len, TUSB_DIR_OUT);
|
||||
@ -262,6 +264,7 @@ static bool edpt0_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t *buffer, uint16_
|
||||
{
|
||||
(void)rhport;
|
||||
TU_ASSERT(total_bytes <= 64); /* Current implementation supports for only up to 64 bytes. */
|
||||
musb_regs_t* musb_regs = MUSB_REGS(rhport);
|
||||
volatile musb_ep0_regs_t* ep0_regs = musb_dcd_ep0_regs(rhport);
|
||||
const unsigned req = _dcd.setup_packet.bmRequestType;
|
||||
TU_ASSERT(req != REQUEST_TYPE_INVALID || total_bytes == 0);
|
||||
@ -289,7 +292,7 @@ static bool edpt0_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t *buffer, uint16_
|
||||
TU_ASSERT(total_bytes <= _dcd.remaining_ctrl);
|
||||
const unsigned rem = _dcd.remaining_ctrl;
|
||||
const unsigned len = TU_MIN(TU_MIN(rem, 64), total_bytes);
|
||||
volatile void *fifo_ptr = musb_dcd_ep_get_fifo_ptr(rhport, 0);
|
||||
volatile void *fifo_ptr = &musb_regs->fifo[0];
|
||||
if (dir_in) {
|
||||
pipe_write_packet(buffer, fifo_ptr, len);
|
||||
|
||||
@ -327,6 +330,7 @@ static bool edpt0_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t *buffer, uint16_
|
||||
|
||||
static void process_ep0(uint8_t rhport)
|
||||
{
|
||||
musb_regs_t* musb_regs = MUSB_REGS(rhport);
|
||||
volatile musb_ep0_regs_t* ep0_regs = musb_dcd_ep0_regs(rhport);
|
||||
uint_fast8_t csrl = ep0_regs->CSRL0;
|
||||
|
||||
@ -368,7 +372,7 @@ static void process_ep0(uint8_t rhport)
|
||||
const unsigned vld = ep0_regs->COUNT0;
|
||||
const unsigned rem = _dcd.pipe0.remaining;
|
||||
const unsigned len = TU_MIN(TU_MIN(rem, 64), vld);
|
||||
volatile void *fifo_ptr = musb_dcd_ep_get_fifo_ptr(rhport, 0);
|
||||
volatile void *fifo_ptr = &musb_regs->fifo[0];
|
||||
pipe_read_packet(_dcd.pipe0.buf, fifo_ptr, len);
|
||||
|
||||
_dcd.pipe0.remaining = rem - len;
|
||||
@ -383,8 +387,6 @@ static void process_ep0(uint8_t rhport)
|
||||
return;
|
||||
}
|
||||
|
||||
musb_regs_t* musb_regs = MUSB_REGS(rhport);
|
||||
|
||||
/* When CSRL0 is zero, it means that completion of sending a any length packet
|
||||
* or receiving a zero length packet. */
|
||||
if (req != REQUEST_TYPE_INVALID && !tu_edpt_dir(req)) {
|
||||
|
@ -150,16 +150,6 @@ static inline volatile musb_ep0_regs_t* musb_dcd_ep0_regs(uint8_t rhport) {
|
||||
return regs;
|
||||
}
|
||||
|
||||
static volatile void* musb_dcd_ep_get_fifo_ptr(uint8_t rhport, unsigned epnum) {
|
||||
volatile uint32_t* ptr;
|
||||
|
||||
ptr = &(musb_periph_inst[rhport]->fifo0);
|
||||
ptr += epnum;
|
||||
|
||||
return (volatile void*) ptr;
|
||||
}
|
||||
|
||||
|
||||
static inline void musb_dcd_setup_fifo(uint8_t rhport, unsigned epnum, unsigned dir_in, unsigned mps) {
|
||||
(void) mps;
|
||||
|
||||
|
@ -113,16 +113,6 @@ static inline volatile musb_ep0_regs_t* musb_dcd_ep0_regs(uint8_t rhport)
|
||||
return regs;
|
||||
}
|
||||
|
||||
static volatile void *musb_dcd_ep_get_fifo_ptr(uint8_t rhport, unsigned epnum)
|
||||
{
|
||||
if(epnum){
|
||||
return (volatile void *)(&(musb_periph_inst[rhport]->FIFO1_WORD) + (epnum - 1));
|
||||
} else {
|
||||
return (volatile void *)&(musb_periph_inst[rhport]->FIFO0_WORD);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
typedef struct {
|
||||
uint_fast16_t beg; /* offset of including first element */
|
||||
uint_fast16_t end; /* offset of excluding the last element */
|
||||
|
@ -107,22 +107,7 @@ typedef struct {
|
||||
__IO uint16_t outcount; // 0x18: OUTCOUNT
|
||||
};
|
||||
__R uint16_t rsv_0x1a_0x1f[3];
|
||||
__IO uint32_t fifo0; // 0x20: FIFO0
|
||||
__IO uint32_t fifo1; // 0x24: FIFO1
|
||||
__IO uint32_t fifo2; // 0x28: FIFO2
|
||||
__IO uint32_t fifo3; // 0x2c: FIFO3
|
||||
__IO uint32_t fifo4; // 0x30: FIFO4
|
||||
__IO uint32_t fifo5; // 0x34: FIFO5
|
||||
__IO uint32_t fifo6; // 0x38: FIFO6
|
||||
__IO uint32_t fifo7; // 0x3c: FIFO7
|
||||
__IO uint32_t fifo8; // 0x40: FIFO8
|
||||
__IO uint32_t fifo9; // 0x44: FIFO9
|
||||
__IO uint32_t fifo10; // 0x48: FIFO10
|
||||
__IO uint32_t fifo11; // 0x4c: FIFO11
|
||||
__IO uint32_t fifo12; // 0x50: FIFO12
|
||||
__IO uint32_t fifo13; // 0x54: FIFO13
|
||||
__IO uint32_t fifo14; // 0x58: FIFO14
|
||||
__IO uint32_t fifo15; // 0x5c: FIFO15
|
||||
__IO uint32_t fifo[16]; // 0x20-0x5C: FIFO 0-15
|
||||
__IO uint8_t devctl; // 0x60: DEVCTL
|
||||
__IO uint8_t misc; // 0x61: MISC
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user