diff --git a/arch/avr/src/at90usb/at90usb_usbdev.c b/arch/avr/src/at90usb/at90usb_usbdev.c index f4685752316..bfc5fdeed6a 100644 --- a/arch/avr/src/at90usb/at90usb_usbdev.c +++ b/arch/avr/src/at90usb/at90usb_usbdev.c @@ -34,10 +34,8 @@ #include #include #include -#include #include -#include #include #include #include @@ -254,10 +252,6 @@ struct avr_usbdev_s /* The endpoint list */ struct avr_ep_s eplist[AVR_NENDPOINTS]; - - /* Spinlock */ - - spinlock_t lock; }; /**************************************************************************** @@ -2300,16 +2294,14 @@ static int avr_epdisable(FAR struct usbdev_ep_s *ep) usbtrace(TRACE_EPDISABLE, privep->ep.eplog); - flags = spin_lock_irqsave(&g_usbdev.lock); - sched_lock(); + flags = enter_critical_section(); /* Disable the endpoint */ avr_epreset(privep, -ESHUTDOWN); g_usbdev.stalled = true; - spin_unlock_irqrestore(&g_usbdev.lock, flags); - sched_unlock(); + leave_critical_section(flags); return OK; } @@ -2455,8 +2447,7 @@ static int avr_epsubmit(FAR struct usbdev_ep_s *ep, /* Disable Interrupts */ - flags = spin_lock_irqsave(&g_usbdev.lock); - sched_lock(); + flags = enter_critical_section(); /* If we are stalled, then drop all requests on the floor */ @@ -2517,8 +2508,7 @@ static int avr_epsubmit(FAR struct usbdev_ep_s *ep, } } - spin_unlock_irqrestore(&g_usbdev.lock, flags); - sched_unlock(); + leave_critical_section(flags); return ret; } @@ -2552,11 +2542,9 @@ static int avr_epcancel(FAR struct usbdev_ep_s *ep, * all requests ... */ - flags = spin_lock_irqsave(&g_usbdev.lock); - sched_lock(); + flags = enter_critical_section(); avr_cancelrequests(privep, -ESHUTDOWN); - spin_unlock_irqrestore(&g_usbdev.lock, flags); - sched_unlock(); + leave_critical_section(flags); return OK; } @@ -2574,7 +2562,7 @@ static int avr_epstall(FAR struct usbdev_ep_s *ep, bool resume) /* STALL or RESUME the endpoint */ - flags = spin_lock_irqsave(&g_usbdev.lock); + flags = enter_critical_section(); if (resume) { /* Clear stall and reset the data toggle */ @@ -2591,7 +2579,7 @@ static int avr_epstall(FAR struct usbdev_ep_s *ep, bool resume) g_usbdev.stalled = true; } - spin_unlock_irqrestore(&g_usbdev.lock, flags); + leave_critical_section(flags); return OK; } @@ -2662,7 +2650,7 @@ static FAR struct usbdev_ep_s *avr_allocep(FAR struct usbdev_s *dev, { /* Yes.. now see if any of the request endpoints are available */ - flags = spin_lock_irqsave(&g_usbdev.lock); + flags = enter_critical_section(); /* Select the lowest bit in the set of matching, available endpoints */ @@ -2696,14 +2684,14 @@ static FAR struct usbdev_ep_s *avr_allocep(FAR struct usbdev_s *dev, /* And return the pointer to the standard endpoint structure */ - spin_unlock_irqrestore(&g_usbdev.lock, flags); + leave_critical_section(flags); return &privep->ep; } } /* Shouldn't get here */ - spin_unlock_irqrestore(&g_usbdev.lock, flags); + leave_critical_section(flags); } usbtrace(TRACE_DEVERROR(AVR_TRACEERR_NOEP), (uint16_t) epno); @@ -2728,12 +2716,12 @@ static void avr_freeep(FAR struct usbdev_s *dev, FAR struct usbdev_ep_s *ep) /* Mark the endpoint as available */ - flags = spin_lock_irqsave(&g_usbdev.lock); + flags = enter_critical_section(); epmask = (1 << privep->ep.eplog); g_usbdev.epavail |= epmask; g_usbdev.epinset &= ~epmask; g_usbdev.epoutset &= ~epmask; - spin_unlock_irqrestore(&g_usbdev.lock, flags); + leave_critical_section(flags); } /**************************************************************************** @@ -2766,11 +2754,9 @@ static int avr_wakeup(struct usbdev_s *dev) usbtrace(TRACE_DEVWAKEUP, 0); - flags = spin_lock_irqsave(&g_usbdev.lock); - sched_lock(); + flags = enter_critical_section(); avr_genwakeup(); - spin_unlock_irqrestore(&g_usbdev.lock, flags); - sched_unlock(); + leave_critical_section(flags); return OK; } @@ -2835,10 +2821,6 @@ void avr_usbinitialize(void) { usbtrace(TRACE_DEVINIT, 0); - /* Initialize driver lock */ - - spin_lock_init(&g_usbdev.lock); - /* Initialize the device state structure */ memset(&g_usbdev, 0, sizeof(struct avr_usbdev_s)); @@ -2909,8 +2891,7 @@ void avr_usbuninitialize(void) /* Disconnect device */ - flags = spin_lock_irqsave(&g_usbdev.lock); - sched_lock(); + flags = enter_critical_section(); avr_pullup(&g_usbdev.usbdev, false); g_usbdev.usbdev.speed = USB_SPEED_UNKNOWN; @@ -2922,8 +2903,7 @@ void avr_usbuninitialize(void) /* Shutdown the USB controller hardware */ avr_usbshutdown(); - spin_unlock_irqrestore(&g_usbdev.lock, flags); - sched_unlock(); + leave_critical_section(flags); } /**************************************************************************** @@ -3038,10 +3018,8 @@ void avr_pollvbus(void) { irqstate_t flags; - flags = spin_lock_irqsave(&g_usbdev.lock); - sched_lock(); + flags = enter_critical_section(); avr_genvbus(); - spin_unlock_irqrestore(&g_usbdev.lock, flags); - sched_unlock(); + leave_critical_section(flags); } #endif