30#if CFG_TUD_ENABLED && ( CFG_TUSB_MCU == OPT_MCU_MSP430x5xx )
59#define XFER_CTL_BASE(_ep, _dir) &xfer_status[_ep][_dir]
74#define EP_REGS(epnum, dir) ((ep_regs_t) ((uintptr_t)&USBOEPCNF_1 + 64*dir + 8*(epnum - 1)))
86 USBOEPCNF_0 |= (UBME | USBIIE);
87 USBIEPCNF_0 |= (UBME | USBIIE);
114 bool unlocked = (USBKEYPID == 0xA528) ?
true :
false;
116 if(!unlocked) USBKEYPID = USBKEY;
127 if(!unlocked) USBKEYPID = 0;
134 (void) rhport; (void) rh_init;
148 USBPWRCTL &= ~(VUOVLIE | VBONIE | VBOFFIE | VUOVLIFG | VBONIFG | VBOFFIFG);
156 if(USBPWRCTL & USBBGVBV) {
157 USBPWRCTL |= VBOFFIE;
180 __bic_SR_register(GIE);
195 __bis_SR_register(GIE);
202 __bic_SR_register(GIE);
210 USBPWRCTL &= ~(VUOVLIE | VBONIE | VBOFFIE);
212 __bis_SR_register(GIE);
301 uint8_t buf_base = (128 * (epnum - 1) + 64 * dir) >> 3;
325 USBOEPIE |= (1 << epnum);
329 USBIEPIE |= (1 << epnum);
337 (void) rhport; (void) ep_addr;
358 xfer->queued_len = 0;
359 xfer->short_packet =
false;
388 USBIEPIFG |= (1 << epnum);
407 xfer->queued_len = 0;
408 xfer->short_packet =
false;
418 USBIEPIFG |= (1 << epnum);
437 USBOEPCNF_0 |= STALL;
442 USBIEPCNF_0 |= STALL;
463 USBOEPCNF_0 &= ~STALL;
467 USBIEPCNF_0 &= ~STALL;
505 xfer_size = USBOEPCNT_0 & 0x0F;
513 uint16_t to_recv_size;
515 if(remaining <= xfer->max_size) {
517 to_recv_size = (xfer_size > remaining) ? remaining : xfer_size;
521 to_recv_size = (xfer_size >
xfer->max_size) ?
xfer->max_size : xfer_size;
527 volatile uint8_t * ep_buf = (ep_num == 0) ? &USBOEP0BUF : (&USBSTABUFF + (
ep_regs[
BBAX] << 3));
537 volatile uint8_t * ep0out_buf = &USBOEP0BUF;
538 for(uint16_t i = 0; i < to_recv_size; i++)
540 base[i] = ep0out_buf[i];
545 volatile uint8_t * ep_buf = &USBSTABUFF + (
ep_regs[
BBAX] << 3);
546 for(uint16_t i = 0; i < to_recv_size ; i++)
553 xfer->queued_len += xfer_size;
555 xfer->short_packet = (xfer_size <
xfer->max_size);
594 xfer->queued_len += xfer_size;
595 if(xfer_size < xfer->max_size)
598 xfer->short_packet =
true;
603 volatile uint8_t * ep0in_buf = &USBIEP0BUF;
604 for(uint16_t i = 0; i < xfer_size; i++)
606 ep0in_buf[i] = base[i];
609 USBIEPCNT_0 = (USBIEPCNT_0 & 0xF0) + xfer_size;
615 volatile uint8_t * ep_buf = &USBSTABUFF + (
ep_regs[
BBAX] << 3);
625 for(
int i = 0; i < xfer_size; i++)
638 volatile uint8_t * setup_buf = &USBSUBLK;
640 for(
int i = 0; i < 8; i++)
657 USBIEPCNF_0 &= ~UBME;
658 USBOEPCNF_0 &= ~UBME;
665#if CFG_TUSB_OS == OPT_OS_NONE
666TU_ATTR_ALWAYS_INLINE
static inline void tu_delay(uint32_t ms) {
669 volatile uint32_t cycles = (25000 * ms) >> 2;
676#define tu_delay(ms) osal_task_delay(ms)
686 if(USBPWRCTL & USBBGVBV) {
687 USBPWRCTL |= VBOFFIE;
688 USBPLLDIVB = USBPLLDIVB;
692 USBPLLCTL |= (UPLLEN | UPFDEN);
694 uint16_t attempts = 0;
699 }
while ((attempts < 10) && (USBPLLIR != 0));
704 .
role = TUSB_ROLE_DEVICE,
711 USBPLLCTL &= ~(UPLLEN | UPFDEN);
725 uint8_t setup_status = USBIFG & SETUPIFG;
737 uint16_t curr_vector;
738 #if __GNUC__ > 9 || (__GNUC__ == 9 && __GNUC_MINOR__ > 2)
739 asm volatile (
"mov %1, %0"
743 curr_vector = USBVECINT;
757 case USBVECINT_PWR_VBUSOn:
758 case USBVECINT_PWR_VBUSOff: {
761 USBPWRCTL &= ~(VBONIE | VBOFFIE);
767 event.event_id = USBD_EVENT_FUNC_CALL;
794 case USBVECINT_SETUP_PACKET_RECEIVED:
797 case USBVECINT_INPUT_ENDPOINT0:
802 case USBVECINT_OUTPUT_ENDPOINT0:
807 case USBVECINT_INPUT_ENDPOINT1:
808 case USBVECINT_INPUT_ENDPOINT2:
809 case USBVECINT_INPUT_ENDPOINT3:
810 case USBVECINT_INPUT_ENDPOINT4:
811 case USBVECINT_INPUT_ENDPOINT5:
812 case USBVECINT_INPUT_ENDPOINT6:
813 case USBVECINT_INPUT_ENDPOINT7:
815 uint8_t ep = ((curr_vector - USBVECINT_INPUT_ENDPOINT1) >> 1) + 1;
820 case USBVECINT_OUTPUT_ENDPOINT1:
821 case USBVECINT_OUTPUT_ENDPOINT2:
822 case USBVECINT_OUTPUT_ENDPOINT3:
823 case USBVECINT_OUTPUT_ENDPOINT4:
824 case USBVECINT_OUTPUT_ENDPOINT5:
825 case USBVECINT_OUTPUT_ENDPOINT6:
826 case USBVECINT_OUTPUT_ENDPOINT7:
828 uint8_t ep = ((curr_vector - USBVECINT_OUTPUT_ENDPOINT1) >> 1) + 1;
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_setup_received(uint8_t rhport, uint8_t const *setup, bool in_isr)
void dcd_event_handler(dcd_event_t const *event, bool in_isr)
static TU_ATTR_ALWAYS_INLINE void dcd_event_bus_reset(uint8_t rhport, tusb_speed_t speed, bool in_isr)
static EPx_REGS *const ep_regs[EP_MAX]
static void receive_packet(uint8_t ep_num)
bool dcd_edpt_xfer_fifo(uint8_t rhport, uint8_t ep_addr, tu_fifo_t *ff, uint16_t total_bytes)
void dcd_edpt_stall(uint8_t rhport, uint8_t ep_addr)
void dcd_edpt_close(uint8_t rhport, uint8_t ep_addr)
static void bus_reset(void)
static volatile uint16_t usbpwrctl_mirror
static void handle_setup_packet(void)
void dcd_int_handler(uint8_t rhport)
void dcd_disconnect(uint8_t rhport)
xfer_ctl_t xfer_status[8][2]
static volatile uint8_t usbie_mirror
static void handle_bus_power_event(void *param)
volatile uint8_t * ep_regs_t
void dcd_edpt_close_all(uint8_t rhport)
void dcd_int_disable(uint8_t rhport)
void dcd_edpt_clear_stall(uint8_t rhport, uint8_t ep_addr)
static volatile uint16_t usboepie_mirror
void dcd_connect(uint8_t rhport)
bool dcd_edpt_open(uint8_t rhport, tusb_desc_endpoint_t const *desc_edpt)
bool dcd_edpt_xfer(uint8_t rhport, uint8_t ep_addr, uint8_t *buffer, uint16_t total_bytes)
static TU_ATTR_ALWAYS_INLINE void tu_delay(uint32_t ms)
void dcd_edpt0_status_complete(uint8_t rhport, tusb_control_request_t const *request)
static void transmit_packet(uint8_t ep_num)
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 volatile uint16_t usbiepie_mirror
static void enable_functional_reset(const bool enable)
void dcd_int_enable(uint8_t rhport)
void dcd_remote_wakeup(uint8_t rhport)
void dcd_sof_enable(uint8_t rhport, bool en)
xfer_td_t xfer[EP_CBI_COUNT+1][2]
AUDIO Channel Cluster Descriptor (4.1)
uint8_t bmAttributes
See: audio_clock_source_attribute_t.
uint16_t tu_fifo_write_n(tu_fifo_t *f, const void *data, uint16_t n)
This function will write n elements into the array index specified by the write pointer and increment...
uint16_t tu_fifo_read_n(tu_fifo_t *f, void *buffer, uint16_t n)
This function will read n elements from the array index specified by the read pointer and increment t...
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)
CFG_TUH_MEM_ALIGN tusb_control_request_t request