Просмотр исходного кода

move irqhandler to application

tud_isr() must be called by application to forward the irqhandle to the
stack
hathach 6 лет назад
Родитель
Сommit
2d6d298302

+ 6 - 0
examples/device/board_test/Makefile

@@ -9,4 +9,10 @@ INC += \
 EXAMPLE_SOURCE += $(wildcard src/*.c)
 SRC_C += $(addprefix $(CURRENT_PATH)/, $(EXAMPLE_SOURCE))
 
+# board_test example is special example that doesn't enable device or host stack
+# This can cause some TinyUSB API missing, this hack to allow us to fill those API
+# to pass the compilation process
+CFLAGS +=	\
+	-D"tud_isr(x)= " \
+
 include ../../rules.mk

+ 10 - 0
hw/bsp/circuitplayground_express/circuitplayground_express.c

@@ -35,6 +35,14 @@
 #include "hpl_pm_config.h"
 #include "hpl/pm/hpl_pm_base.h"
 
+//--------------------------------------------------------------------+
+// Forward USB interrupt events to TinyUSB IRQ Handler
+//--------------------------------------------------------------------+
+void USB_Handler(void)
+{
+  tud_isr(0);
+}
+
 //--------------------------------------------------------------------+
 // MACRO TYPEDEF CONSTANT ENUM DECLARATION
 //--------------------------------------------------------------------+
@@ -134,6 +142,7 @@ int board_uart_write(void const * buf, int len)
 }
 
 #if CFG_TUSB_OS  == OPT_OS_NONE
+
 volatile uint32_t system_ticks = 0;
 void SysTick_Handler (void)
 {
@@ -144,4 +153,5 @@ uint32_t board_millis(void)
 {
   return system_ticks;
 }
+
 #endif

+ 17 - 15
hw/bsp/ea4088qs/ea4088qs.c

@@ -27,6 +27,23 @@
 #include "chip.h"
 #include "../board.h"
 
+//--------------------------------------------------------------------+
+// USB Interrupt Handler
+//--------------------------------------------------------------------+
+void USB_IRQHandler(void)
+{
+  #if CFG_TUSB_RHPORT0_MODE & OPT_MODE_HOST
+    tuh_isr(0);
+  #endif
+
+  #if CFG_TUSB_RHPORT0_MODE & OPT_MODE_DEVICE
+    tud_isr(0);
+  #endif
+}
+
+//--------------------------------------------------------------------+
+// MACRO TYPEDEF CONSTANT ENUM DECLARATION
+//--------------------------------------------------------------------+
 #define LED_PORT      2
 #define LED_PIN       19
 
@@ -113,21 +130,6 @@ void board_init(void)
   LPC_USB->StCtrl = 0x3;
 }
 
-//--------------------------------------------------------------------+
-// USB Interrupt Handler
-//--------------------------------------------------------------------+
-void USB_IRQHandler(void)
-{
-  #if CFG_TUSB_RHPORT0_MODE & OPT_MODE_HOST
-    tuh_isr(0);
-  #endif
-
-  #if CFG_TUSB_RHPORT0_MODE & OPT_MODE_DEVICE
-    tud_isr(0);
-  #endif
-}
-
-
 //--------------------------------------------------------------------+
 // Board porting API
 //--------------------------------------------------------------------+

+ 8 - 0
hw/bsp/feather_m0_express/feather_m0_express.c

@@ -35,6 +35,14 @@
 #include "hpl_pm_config.h"
 #include "hpl/pm/hpl_pm_base.h"
 
+//--------------------------------------------------------------------+
+// Forward USB interrupt events to TinyUSB IRQ Handler
+//--------------------------------------------------------------------+
+void USB_Handler(void)
+{
+  tud_isr(0);
+}
+
 //--------------------------------------------------------------------+
 // MACRO TYPEDEF CONSTANT ENUM DECLARATION
 //--------------------------------------------------------------------+

+ 23 - 0
hw/bsp/feather_m4_express/feather_m4_express.c

@@ -32,6 +32,29 @@
 #include "hpl/gclk/hpl_gclk_base.h"
 #include "hpl_mclk_config.h"
 
+//--------------------------------------------------------------------+
+// Forward USB interrupt events to TinyUSB IRQ Handler
+//--------------------------------------------------------------------+
+void USB_0_Handler (void)
+{
+  tud_isr(0);
+}
+
+void USB_1_Handler (void)
+{
+  tud_isr(0);
+}
+
+void USB_2_Handler (void)
+{
+  tud_isr(0);
+}
+
+void USB_3_Handler (void)
+{
+  tud_isr(0);
+}
+
 //--------------------------------------------------------------------+
 // MACRO TYPEDEF CONSTANT ENUM DECLARATION
 //--------------------------------------------------------------------+

+ 1 - 0
hw/bsp/feather_nrf52840_express/feather_nrf52840_express.c

@@ -92,6 +92,7 @@ void board_init(void)
 
   nrfx_uarte_init(&_uart_id, &uart_cfg, NULL); //uart_handler);
 
+  //------------- USB -------------//
 #if TUSB_OPT_DEVICE_ENABLED
   // Priorities 0, 1, 4 (nRF52) are reserved for SoftDevice
   // 2 is highest for application

+ 8 - 0
hw/bsp/itsybitsy_m0/itsybitsy_m0.c

@@ -35,6 +35,14 @@
 #include "hpl_pm_config.h"
 #include "hpl/pm/hpl_pm_base.h"
 
+//--------------------------------------------------------------------+
+// Forward USB interrupt events to TinyUSB IRQ Handler
+//--------------------------------------------------------------------+
+void USB_Handler(void)
+{
+  tud_isr(0);
+}
+
 //--------------------------------------------------------------------+
 // MACRO TYPEDEF CONSTANT ENUM DECLARATION
 //--------------------------------------------------------------------+

+ 23 - 0
hw/bsp/itsybitsy_m4/itsybitsy_m4.c

@@ -32,6 +32,29 @@
 #include "hpl/gclk/hpl_gclk_base.h"
 #include "hpl_mclk_config.h"
 
+//--------------------------------------------------------------------+
+// Forward USB interrupt events to TinyUSB IRQ Handler
+//--------------------------------------------------------------------+
+void USB_0_Handler (void)
+{
+  tud_isr(0);
+}
+
+void USB_1_Handler (void)
+{
+  tud_isr(0);
+}
+
+void USB_2_Handler (void)
+{
+  tud_isr(0);
+}
+
+void USB_3_Handler (void)
+{
+  tud_isr(0);
+}
+
 //--------------------------------------------------------------------+
 // MACRO TYPEDEF CONSTANT ENUM DECLARATION
 //--------------------------------------------------------------------+

+ 8 - 0
hw/bsp/metro_m0_express/metro_m0_express.c

@@ -35,6 +35,14 @@
 #include "hpl_pm_config.h"
 #include "hpl/pm/hpl_pm_base.h"
 
+//--------------------------------------------------------------------+
+// Forward USB interrupt events to TinyUSB IRQ Handler
+//--------------------------------------------------------------------+
+void USB_Handler(void)
+{
+  tud_isr(0);
+}
+
 //--------------------------------------------------------------------+
 // MACRO TYPEDEF CONSTANT ENUM DECLARATION
 //--------------------------------------------------------------------+

+ 23 - 0
hw/bsp/metro_m4_express/metro_m4_express.c

@@ -32,6 +32,29 @@
 #include "hpl/gclk/hpl_gclk_base.h"
 #include "hpl_mclk_config.h"
 
+//--------------------------------------------------------------------+
+// Forward USB interrupt events to TinyUSB IRQ Handler
+//--------------------------------------------------------------------+
+void USB_0_Handler (void)
+{
+  tud_isr(0);
+}
+
+void USB_1_Handler (void)
+{
+  tud_isr(0);
+}
+
+void USB_2_Handler (void)
+{
+  tud_isr(0);
+}
+
+void USB_3_Handler (void)
+{
+  tud_isr(0);
+}
+
 //--------------------------------------------------------------------+
 // MACRO TYPEDEF CONSTANT ENUM DECLARATION
 //--------------------------------------------------------------------+

+ 8 - 0
hw/bsp/seeeduino_xiao/seeeduino_xiao.c

@@ -35,6 +35,14 @@
 #include "hpl_pm_config.h"
 #include "hpl/pm/hpl_pm_base.h"
 
+//--------------------------------------------------------------------+
+// Forward USB interrupt events to TinyUSB IRQ Handler
+//--------------------------------------------------------------------+
+void USB_Handler(void)
+{
+  tud_isr(0);
+}
+
 //--------------------------------------------------------------------+
 // MACRO TYPEDEF CONSTANT ENUM DECLARATION
 //--------------------------------------------------------------------+

+ 1 - 1
src/device/dcd.h

@@ -89,7 +89,7 @@ typedef struct TU_ATTR_ALIGNED(4)
 void dcd_init       (uint8_t rhport);
 
 // Interrupt Handler
-void dcd_isr        (uint8_t rhport);
+void dcd_isr        (uint8_t rhport) TU_ATTR_USED;
 
 // Enable device interrupt
 void dcd_int_enable (uint8_t rhport);

+ 2 - 52
src/portable/microchip/samd/dcd_samd.c

@@ -324,7 +324,7 @@ void dcd_isr (uint8_t rhport)
 
   uint32_t int_status = USB->DEVICE.INTFLAG.reg & USB->DEVICE.INTENSET.reg;
 
-  /*------------- Interrupt Processing -------------*/
+  // Start of Frame
   if ( int_status & USB_DEVICE_INTFLAG_SOF )
   {
     USB->DEVICE.INTFLAG.reg = USB_DEVICE_INTFLAG_SOF;
@@ -357,6 +357,7 @@ void dcd_isr (uint8_t rhport)
     dcd_event_bus_signal(0, DCD_EVENT_RESUME, true);
   }
 
+  // Enable of Reset
   if ( int_status & USB_DEVICE_INTFLAG_EORST )
   {
     USB->DEVICE.INTFLAG.reg = USB_DEVICE_INTFLAG_EORST;
@@ -381,55 +382,4 @@ void dcd_isr (uint8_t rhport)
   maybe_transfer_complete();
 }
 
-#if CFG_TUSB_MCU == OPT_MCU_SAMD51
-
-/*
- *------------------------------------------------------------------*/
-/* USB_EORSM_DNRSM, USB_EORST_RST, USB_LPMSUSP_DDISC, USB_LPM_DCONN,
-USB_MSOF, USB_RAMACER, USB_RXSTP_TXSTP_0, USB_RXSTP_TXSTP_1,
-USB_RXSTP_TXSTP_2, USB_RXSTP_TXSTP_3, USB_RXSTP_TXSTP_4,
-USB_RXSTP_TXSTP_5, USB_RXSTP_TXSTP_6, USB_RXSTP_TXSTP_7,
-USB_STALL0_STALL_0, USB_STALL0_STALL_1, USB_STALL0_STALL_2,
-USB_STALL0_STALL_3, USB_STALL0_STALL_4, USB_STALL0_STALL_5,
-USB_STALL0_STALL_6, USB_STALL0_STALL_7, USB_STALL1_0, USB_STALL1_1,
-USB_STALL1_2, USB_STALL1_3, USB_STALL1_4, USB_STALL1_5, USB_STALL1_6,
-USB_STALL1_7, USB_SUSPEND, USB_TRFAIL0_TRFAIL_0, USB_TRFAIL0_TRFAIL_1,
-USB_TRFAIL0_TRFAIL_2, USB_TRFAIL0_TRFAIL_3, USB_TRFAIL0_TRFAIL_4,
-USB_TRFAIL0_TRFAIL_5, USB_TRFAIL0_TRFAIL_6, USB_TRFAIL0_TRFAIL_7,
-USB_TRFAIL1_PERR_0, USB_TRFAIL1_PERR_1, USB_TRFAIL1_PERR_2,
-USB_TRFAIL1_PERR_3, USB_TRFAIL1_PERR_4, USB_TRFAIL1_PERR_5,
-USB_TRFAIL1_PERR_6, USB_TRFAIL1_PERR_7, USB_UPRSM, USB_WAKEUP */
-void USB_0_Handler(void) {
-  dcd_isr(0);
-}
-
-/* USB_SOF_HSOF */
-void USB_1_Handler(void) {
-  dcd_isr(0);
-}
-
-// Bank zero is for OUT and SETUP transactions.
-/* USB_TRCPT0_0, USB_TRCPT0_1, USB_TRCPT0_2,
-USB_TRCPT0_3, USB_TRCPT0_4, USB_TRCPT0_5,
-USB_TRCPT0_6, USB_TRCPT0_7 */
-void USB_2_Handler(void) {
-  dcd_isr(0);
-}
-
-// Bank one is used for IN transactions.
-/* USB_TRCPT1_0, USB_TRCPT1_1, USB_TRCPT1_2,
-USB_TRCPT1_3, USB_TRCPT1_4, USB_TRCPT1_5,
-USB_TRCPT1_6, USB_TRCPT1_7 */
-void USB_3_Handler(void) {
-  dcd_isr(0);
-}
-
-#elif CFG_TUSB_MCU == OPT_MCU_SAMD21
-
-void USB_Handler(void) {
-  dcd_isr(0);
-}
-
-#endif
-
 #endif