30#if CFG_TUD_ENABLED && defined(TUP_USBIP_RUSB2)
35#if TU_CHECK_MCU(OPT_MCU_RX63X, OPT_MCU_RX65X, OPT_MCU_RX72N)
37#elif TU_CHECK_MCU(OPT_MCU_RAXXX)
39 #if defined(RENESAS_CORTEX_M23)
41 #define D0FIFOSEL CFIFOSEL
42 #define D0FIFOSEL_b CFIFOSEL_b
43 #define D1FIFOSEL CFIFOSEL
44 #define D1FIFOSEL_b CFIFOSEL_b
45 #define D0FIFOCTR CFIFOCTR
46 #define D0FIFOCTR_b CFIFOCTR_b
50 #error "Unsupported MCU"
93 #if defined(BSP_MCU_GROUP_RA2A1)
94 const uint8_t pipe_idx_arr[4][2] = {
101 const uint8_t pipe_idx_arr[4][2] = {
110 const uint8_t idx_first = pipe_idx_arr[xfer_type][0];
111 const uint8_t idx_last = pipe_idx_arr[xfer_type][1];
113 for (
int i = idx_last; i >= idx_first; i--) {
122 return (
volatile uint16_t*)&(rusb->
PIPE_CTR[num - 1]);
124 return (
volatile uint16_t*)&(rusb->
DCPCTR);
130 if ((1 <= num) && (num <= 5)) {
142 const unsigned num =
_dcd.
ep[dir][epn];
172 volatile uint16_t *ff16;
173 volatile uint8_t *ff8;
176 if ( rusb2_is_highspeed_reg(rusb) ) {
178 ff16 = (
volatile uint16_t*) ((uintptr_t) fifo+2);
179 ff8 = (
volatile uint8_t *) ((uintptr_t) fifo+3);
181 ff16 = (
volatile uint16_t*) fifo;
182 ff8 = ((
volatile uint8_t*) fifo);
185 uint8_t
const* buf8 = (uint8_t
const*) buf;
206 uint8_t *p = (uint8_t*)buf;
207 volatile uint8_t *reg = (
volatile uint8_t*)fifo;
208 while (len--) *p++ = *reg;
219 uint16_t rem = total_len - count;
237 uint16_t rem = total_len - count;
262 const uint16_t len =
tu_min16(mps, rem);
263 void *buf = pipe->
buf;
270 pipe->
buf = (uint8_t*)buf + len;
275 rusb->
CFIFOCTR = RUSB2_CFIFOCTR_BVAL_Msk;
290 void *buf = pipe->
buf;
297 pipe->
buf = (uint8_t*)buf + len;
302 rusb->
CFIFOCTR = RUSB2_CFIFOCTR_BCLR_Msk;
306 if ((len < mps) || (rem == len)) {
324 rusb->
D0FIFOSEL = num | RUSB2_FIFOSEL_MBW_16BIT | (TU_BYTE_ORDER == TU_BIG_ENDIAN ? RUSB2_FIFOSEL_BIGEND : 0);
327 const uint16_t len =
tu_min16(rem, mps);
328 void *buf = pipe->
buf;
335 pipe->
buf = (uint8_t*)buf + len;
340 rusb->
D0FIFOCTR = RUSB2_CFIFOCTR_BVAL_Msk;
356 rusb->
D0FIFOSEL = num | RUSB2_FIFOSEL_MBW_8BIT;
362 void *buf = pipe->
buf;
369 pipe->
buf = (uint8_t*)buf + len;
374 rusb->
D0FIFOCTR = RUSB2_CFIFOCTR_BCLR_Msk;
381 if ((len < mps) || (rem == len)) {
392 if (0 == (rusb->
INTSTS0 & RUSB2_INTSTS0_VALID_Msk))
return;
394 rusb->
CFIFOCTR = RUSB2_CFIFOCTR_BCLR_Msk;
395 uint16_t setup_packet[4] = {
402 rusb->
INTSTS0 = ~((uint16_t) RUSB2_INTSTS0_VALID_Msk);
411 if (rusb->
CFIFOSEL & RUSB2_CFIFOSEL_ISEL_WRITE) {
427 rusb->
CFIFOSEL = RUSB2_CFIFOSEL_ISEL_WRITE | RUSB2_FIFOSEL_MBW_16BIT |
428 (TU_BYTE_ORDER == TU_BIG_ENDIAN ? RUSB2_FIFOSEL_BIGEND : 0);
429 while ( !(rusb->
CFIFOSEL & RUSB2_CFIFOSEL_ISEL_WRITE) ) {}
432 rusb->
CFIFOSEL = RUSB2_FIFOSEL_MBW_8BIT;
433 while ( rusb->
CFIFOSEL & RUSB2_CFIFOSEL_ISEL_WRITE ) {}
437 pipe->
ff = buffer_type;
448 rusb->
DCPCTR = RUSB2_PIPE_CTR_PID_BUF;
452 rusb->
DCPCTR = RUSB2_DCPCTR_CCPL_Msk | RUSB2_PIPE_CTR_PID_BUF;
462 const unsigned num =
_dcd.
ep[dir][epn];
467 pipe->
ff = buffer_type;
480 rusb->
D0FIFOCTR = RUSB2_CFIFOCTR_BVAL_Msk;
493 if (*ctr & 0x3) *ctr = RUSB2_PIPE_CTR_PID_NAK;
498 *ctr = RUSB2_PIPE_CTR_PID_BUF;
559 rusb->
CFIFOCTR = RUSB2_CFIFOCTR_BCLR_Msk;
567 volatile uint16_t *ctr = (
volatile uint16_t*)((uintptr_t) (&rusb->
PIPE_CTR[0]));
568 volatile uint16_t *tre = (
volatile uint16_t*)((uintptr_t) (&rusb->
PIPE_TR[0].
E));
570 for (
int i = 1; i <= 5; ++i) {
573 *ctr = RUSB2_PIPE_CTR_ACLRM_Msk;
580 for (
int i = 6; i <= 9; ++i) {
583 *ctr = RUSB2_PIPE_CTR_ACLRM_Msk;
589 TU_LOG3(
"Bus reset, RHST = %u\r\n", rusb->
DVSTCTR0_b.RHST);
591 switch(rusb->
DVSTCTR0 & RUSB2_DVSTCTR0_RHST_Msk) {
592 case RUSB2_DVSTCTR0_RHST_LS:
596 case RUSB2_DVSTCTR0_RHST_FS:
600 case RUSB2_DVSTCTR0_RHST_HS:
614 const uint16_t addr = rusb->
USBADDR_b.USBADDR;
641 pswi = get_psw() & 0x010000;
644 pswi = __builtin_rx_mvfc(0) & 0x010000;
645 __builtin_rx_clrpsw(
'I');
653 set_psw(get_psw() | pswi);
655 __builtin_rx_mvtc(0, __builtin_rx_mvfc(0) | pswi);
669#ifdef RUSB2_SUPPORT_HIGHSPEED
670 if ( rusb2_is_highspeed_rhport(rhport) ) {
676 uint16_t physet = (rusb->
PHYSET | RUSB2_PHYSET_PLLRESET_Msk) & ~RUSB2_PHYSET_DIRPD_Msk;
678 R_BSP_SoftwareDelay((uint32_t) 1, BSP_DELAY_UNITS_MILLISECONDS);
712 rusb->
INTENB0 = RUSB2_INTSTS0_VBINT_Msk | RUSB2_INTSTS0_BRDY_Msk | RUSB2_INTSTS0_BEMP_Msk |
713 RUSB2_INTSTS0_DVST_Msk | RUSB2_INTSTS0_CTRT_Msk | (
_dcd.
sof_enabled ? RUSB2_INTSTS0_SOFR_Msk : 0) |
714 RUSB2_INTSTS0_RESM_Msk;
749 if ( rusb2_is_highspeed_rhport(rhport)) {
785 if ( !rusb2_is_highspeed_rhport(rhport) && mps > 256) {
799 if ( rusb2_is_highspeed_rhport(rhport) ) {
808 *ctr = RUSB2_PIPE_CTR_ACLRM_Msk | RUSB2_PIPE_CTR_SQCLR_Msk;
810 unsigned cfg = (dir << 4) | epn;
813 cfg |= (RUSB2_PIPECFG_TYPE_BULK | RUSB2_PIPECFG_SHTNAK_Msk | RUSB2_PIPECFG_DBLB_Msk);
815 cfg |= RUSB2_PIPECFG_TYPE_INT;
817 cfg |= (RUSB2_PIPECFG_TYPE_ISO | RUSB2_PIPECFG_DBLB_Msk);
821 rusb->
BRDYSTS = 0x3FFu ^ TU_BIT(num);
825 *ctr = RUSB2_PIPE_CTR_PID_BUF;
836 unsigned i = TU_ARRAY_SIZE(
_dcd.
pipe);
840 if (!ep_addr)
continue;
851 const unsigned num =
_dcd.
ep[dir][epn];
876 TU_ASSERT(ff->item_size == 1);
891 const uint32_t pid = *ctr & 0x3;
892 *ctr = pid | RUSB2_PIPE_CTR_PID_STALL;
893 *ctr = RUSB2_PIPE_CTR_PID_STALL;
904 *ctr = RUSB2_PIPE_CTR_SQCLR_Msk;
907 *ctr = RUSB2_PIPE_CTR_PID_BUF;
912 *ctr = RUSB2_PIPE_CTR_PID_BUF;
923TU_ATTR_ALWAYS_INLINE
static inline unsigned __builtin_ctz(
unsigned int value) {
924 unsigned int count = 0;
925 while ((value & 1) == 0) {
940 rusb->
INTSTS0 = ~((RUSB2_INTSTS0_CTRT_Msk | RUSB2_INTSTS0_DVST_Msk | RUSB2_INTSTS0_SOFR_Msk |
941 RUSB2_INTSTS0_RESM_Msk | RUSB2_INTSTS0_VBINT_Msk) & is0) | RUSB2_INTSTS0_VALID_Msk;
944 if ( is0 & RUSB2_INTSTS0_VBINT_Msk ) {
953 if ( is0 & RUSB2_INTSTS0_RESM_Msk ) {
961 if ( (is0 & RUSB2_INTSTS0_SOFR_Msk) && rusb->
INTENB0_b.SOFE ) {
963 const uint32_t frame = rusb->
FRMNUM_b.FRNM;
971 if ( is0 & RUSB2_INTSTS0_DVST_Msk ) {
972 switch (is0 & RUSB2_INTSTS0_DVSQ_Msk) {
973 case RUSB2_INTSTS0_DVSQ_STATE_DEF:
977 case RUSB2_INTSTS0_DVSQ_STATE_ADDR:
981 case RUSB2_INTSTS0_DVSQ_STATE_SUSP0:
982 case RUSB2_INTSTS0_DVSQ_STATE_SUSP1:
983 case RUSB2_INTSTS0_DVSQ_STATE_SUSP2:
984 case RUSB2_INTSTS0_DVSQ_STATE_SUSP3:
999 if ( is0 & RUSB2_INTSTS0_CTRT_Msk ) {
1000 if ( is0 & RUSB2_INTSTS0_CTSQ_CTRL_RDATA ) {
1003 }
else if ( 0 == (is0 & RUSB2_INTSTS0_CTSQ_Msk) ) {
1010 if ( is0 & RUSB2_INTSTS0_BEMP_Msk ) {
1011 const uint16_t s = rusb->
BEMPSTS;
1019 if ( is0 & RUSB2_INTSTS0_BRDY_Msk ) {
1020 const unsigned m = rusb->
BRDYENB;
1021 unsigned s = rusb->
BRDYSTS & m;
static TU_ATTR_ALWAYS_INLINE void dcd_event_bus_signal(uint8_t rhport, dcd_eventid_t eid, bool in_isr)
static TU_ATTR_ALWAYS_INLINE void dcd_event_xfer_complete(uint8_t rhport, uint8_t ep_addr, uint32_t xferred_bytes, uint8_t result, bool in_isr)
static TU_ATTR_ALWAYS_INLINE void dcd_event_sof(uint8_t rhport, uint32_t frame_count, bool in_isr)
static TU_ATTR_ALWAYS_INLINE void dcd_event_setup_received(uint8_t rhport, uint8_t const *setup, bool in_isr)
static TU_ATTR_ALWAYS_INLINE void dcd_event_bus_reset(uint8_t rhport, tusb_speed_t speed, bool in_isr)
struct TU_ATTR_PACKED pipe_state_t
xfer_td_t xfer[EP_CBI_COUNT+1][2]
static bool process_pipe0_xfer(rusb2_reg_t *rusb, int buffer_type, uint8_t ep_addr, void *buffer, uint16_t total_bytes)
bool dcd_edpt_xfer_fifo(uint8_t rhport, uint8_t ep_addr, tu_fifo_t *ff, uint16_t total_bytes)
static bool pipe_xfer_in(rusb2_reg_t *rusb, unsigned num)
static void process_setup_packet(uint8_t rhport)
static bool process_pipe_xfer(rusb2_reg_t *rusb, int buffer_type, uint8_t ep_addr, void *buffer, uint16_t total_bytes)
static bool process_edpt_xfer(rusb2_reg_t *rusb, int buffer_type, uint8_t ep_addr, void *buffer, uint16_t total_bytes)
static void process_set_address(uint8_t rhport)
static uint16_t edpt_max_packet_size(rusb2_reg_t *rusb, unsigned num)
static bool pipe_xfer_out(rusb2_reg_t *rusb, unsigned num)
static uint16_t edpt0_max_packet_size(rusb2_reg_t *rusb)
static TU_ATTR_ALWAYS_INLINE unsigned __builtin_ctz(unsigned int value)
static uint32_t disable_interrupt(void)
static void process_bus_reset(uint8_t rhport)
void dcd_edpt_stall(uint8_t rhport, uint8_t ep_addr)
static unsigned find_pipe(unsigned xfer_type)
static volatile reg_pipetre_t * get_pipetre(rusb2_reg_t *rusb, unsigned num)
void dcd_edpt_close(uint8_t rhport, uint8_t ep_addr)
static void process_pipe0_bemp(uint8_t rhport)
void dcd_int_handler(uint8_t rhport)
static void pipe_read_packet(rusb2_reg_t *rusb, void *buf, volatile void *fifo, unsigned len)
void dcd_disconnect(uint8_t rhport)
static void pipe_write_packet(rusb2_reg_t *rusb, void *buf, volatile void *fifo, unsigned len)
static void process_status_completion(uint8_t rhport)
static void enable_interrupt(uint32_t pswi)
void dcd_edpt_close_all(uint8_t rhport)
static volatile uint16_t * ep_addr_to_pipectr(uint8_t rhport, unsigned ep_addr)
void dcd_int_disable(uint8_t rhport)
static void pipe_read_packet_ff(rusb2_reg_t *rusb, tu_fifo_t *f, volatile void *fifo, uint16_t total_len)
bool dcd_edpt_open(uint8_t rhport, tusb_desc_endpoint_t const *ep_desc)
static bool pipe0_xfer_out(rusb2_reg_t *rusb)
void dcd_edpt_clear_stall(uint8_t rhport, uint8_t ep_addr)
void dcd_connect(uint8_t rhport)
bool dcd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t *buffer, uint16_t total_bytes)
static void process_pipe_brdy(uint8_t rhport, unsigned num)
static void pipe_write_packet_ff(rusb2_reg_t *rusb, tu_fifo_t *f, volatile void *fifo, uint16_t total_len)
static volatile uint16_t * get_pipectr(rusb2_reg_t *rusb, unsigned num)
static bool pipe0_xfer_in(rusb2_reg_t *rusb)
void dcd_set_address(uint8_t rhport, uint8_t dev_addr)
bool dcd_init(uint8_t rhport, const tusb_rhport_init_t *rh_init)
static void pipe_wait_for_ready(rusb2_reg_t *rusb, unsigned num)
void dcd_int_enable(uint8_t rhport)
void dcd_remote_wakeup(uint8_t rhport)
void dcd_sof_enable(uint8_t rhport, bool en)
static TU_ATTR_ALWAYS_INLINE void rusb2_phy_init(void)
static TU_ATTR_ALWAYS_INLINE void rusb2_int_disable(uint8_t rhport)
static TU_ATTR_ALWAYS_INLINE void rusb2_module_start(uint8_t rhport, bool start)
static TU_ATTR_ALWAYS_INLINE void rusb2_int_enable(uint8_t rhport)
static TU_ATTR_ALWAYS_INLINE rusb2_reg_t * RUSB2_REG(uint8_t rhport)
TU_ATTR_PACKED_BEGIN TU_ATTR_BIT_FIELD_ORDER_BEGIN struct TU_ATTR_PACKED _ccrx_evenaccess reg_pipetre_t
volatile uint16_t PIPEBUF
volatile uint16_t BEMPSTS
struct _ccrx_evenaccess::@512::TU_ATTR_PACKED FRMNUM_b
volatile uint16_t USBINDX
struct _ccrx_evenaccess::@500::TU_ATTR_PACKED PHYSET_b
volatile uint16_t D0FIFOSEL
volatile uint16_t DVSTCTR0
volatile uint16_t PIPESEL
volatile uint16_t PIPEMAXP
struct _ccrx_evenaccess::@478::TU_ATTR_PACKED CFIFOCTR_b
volatile uint16_t CFIFOSEL
struct _ccrx_evenaccess::@530::TU_ATTR_PACKED DCPCTR_b
struct _ccrx_evenaccess::@556::TU_ATTR_PACKED LPSTS_b
struct _ccrx_evenaccess::@482::TU_ATTR_PACKED D0FIFOCTR_b
struct _ccrx_evenaccess::@516::TU_ATTR_PACKED USBADDR_b
volatile uint16_t D1FIFOSEL
volatile RUSB2_PIPE_TR_t PIPE_TR[5]
struct _ccrx_evenaccess::@502::TU_ATTR_PACKED INTSTS0_b
volatile uint16_t USBLENG
volatile uint16_t INTSTS0
volatile uint16_t PIPE_CTR[9]
volatile uint16_t PIPECFG
volatile uint16_t INTENB0
struct _ccrx_evenaccess::@488::TU_ATTR_PACKED INTENB0_b
struct _ccrx_evenaccess::@464::TU_ATTR_PACKED PLLSTA_b
struct _ccrx_evenaccess::@480::TU_ATTR_PACKED D0FIFOSEL_b
struct _ccrx_evenaccess::@528::TU_ATTR_PACKED DCPMAXP_b
struct _ccrx_evenaccess::@466::TU_ATTR_PACKED DVSTCTR0_b
struct _ccrx_evenaccess::@458::TU_ATTR_PACKED SYSCFG_b
volatile uint16_t BEMPENB
volatile uint16_t D0FIFOCTR
volatile uint32_t PHYSLEW
struct _ccrx_evenaccess::@580::TU_ATTR_PACKED DPUSR0R_FS_b
volatile uint16_t CFIFOCTR
struct _ccrx_evenaccess::@534::TU_ATTR_PACKED PIPECFG_b
volatile uint16_t BRDYSTS
struct _ccrx_evenaccess::@484::TU_ATTR_PACKED D1FIFOSEL_b
volatile uint16_t BRDYENB
AUDIO Channel Cluster Descriptor (4.1)
uint8_t bmAttributes
See: audio_clock_source_attribute_t.
ep_cmd_sts_t ep[2 *MAX_EP_PAIRS][2]
pipe_state_t pipe[2][TUP_DCD_ENDPOINT_MAX-1]
static TU_ATTR_ALWAYS_INLINE uint16_t tu_min16(uint16_t x, uint16_t y)
static TU_ATTR_ALWAYS_INLINE uint16_t tu_unaligned_read16(const void *mem)
void tu_fifo_get_write_info(tu_fifo_t *f, tu_fifo_buffer_info_t *info)
Get linear write info.
void tu_fifo_advance_write_pointer(tu_fifo_t *f, uint16_t n)
Advance write pointer - intended to be used in combination with DMA. It is possible to fill the FIFO ...
void tu_fifo_advance_read_pointer(tu_fifo_t *f, uint16_t n)
Advance read pointer - intended to be used in combination with DMA. It is possible to read from the F...
void tu_fifo_get_read_info(tu_fifo_t *f, tu_fifo_buffer_info_t *info)
Get read info.
tusb_speed_t
defined base on EHCI specs value for Endpoint Speed
static TU_ATTR_ALWAYS_INLINE uint8_t tu_edpt_number(uint8_t addr)
static TU_ATTR_ALWAYS_INLINE uint16_t tu_edpt_packet_size(tusb_desc_endpoint_t const *desc_ep)
TU_ATTR_PACKED_END TU_ATTR_BIT_FIELD_ORDER_END static TU_ATTR_ALWAYS_INLINE tusb_dir_t tu_edpt_dir(uint8_t addr)
static TU_ATTR_ALWAYS_INLINE uint8_t tu_edpt_addr(uint8_t num, uint8_t dir)