6
6
//! * Different events are used to initiate transfers.
7
7
//! * No notification when the status stage is ACK'd.
8
8
9
+ use bare_metal:: Mutex ;
9
10
use core:: cell:: Cell ;
10
11
use core:: mem:: MaybeUninit ;
11
12
use core:: sync:: atomic:: { compiler_fence, Ordering } ;
12
- use cortex_m :: interrupt :: { self , CriticalSection , Mutex } ;
13
+ use critical_section :: CriticalSection ;
13
14
use usb_device:: {
14
15
bus:: { PollResult , UsbBus , UsbBusAllocator } ,
15
16
endpoint:: { EndpointAddress , EndpointType } ,
@@ -244,8 +245,8 @@ impl<T: UsbPeripheral> UsbBus for Usbd<T> {
244
245
245
246
#[ inline]
246
247
fn enable ( & mut self ) {
247
- interrupt :: free ( |cs| {
248
- let regs = self . regs ( cs) ;
248
+ critical_section :: with ( move |cs| {
249
+ let regs = self . regs ( & cs) ;
249
250
250
251
errata:: pre_enable ( ) ;
251
252
@@ -264,8 +265,8 @@ impl<T: UsbPeripheral> UsbBus for Usbd<T> {
264
265
265
266
#[ inline]
266
267
fn reset ( & self ) {
267
- interrupt :: free ( |cs| {
268
- let regs = self . regs ( cs) ;
268
+ critical_section :: with ( move |cs| {
269
+ let regs = self . regs ( & cs) ;
269
270
270
271
// TODO: Initialize ISO buffers
271
272
@@ -310,8 +311,8 @@ impl<T: UsbPeripheral> UsbBus for Usbd<T> {
310
311
311
312
// A 0-length write to Control EP 0 is a status stage acknowledging a control write xfer
312
313
if ep_addr. index ( ) == 0 && buf. is_empty ( ) {
313
- let exit = interrupt :: free ( |cs| {
314
- let regs = self . regs ( cs) ;
314
+ let exit = critical_section :: with ( move |cs| {
315
+ let regs = self . regs ( & cs) ;
315
316
316
317
let ep0_state = self . ep0_state . borrow ( cs) . get ( ) ;
317
318
@@ -349,8 +350,8 @@ impl<T: UsbPeripheral> UsbBus for Usbd<T> {
349
350
return Err ( UsbError :: BufferOverflow ) ;
350
351
}
351
352
352
- interrupt :: free ( |cs| {
353
- let regs = self . regs ( cs) ;
353
+ critical_section :: with ( move |cs| {
354
+ let regs = self . regs ( & cs) ;
354
355
let busy_in_endpoints = self . busy_in_endpoints . borrow ( cs) ;
355
356
356
357
if busy_in_endpoints. get ( ) & ( 1 << i) != 0 {
@@ -462,8 +463,8 @@ impl<T: UsbPeripheral> UsbBus for Usbd<T> {
462
463
}
463
464
464
465
let i = ep_addr. index ( ) ;
465
- interrupt :: free ( |cs| {
466
- let regs = self . regs ( cs) ;
466
+ critical_section :: with ( move |cs| {
467
+ let regs = self . regs ( & cs) ;
467
468
468
469
// Control EP 0 is special
469
470
if i == 0 {
@@ -551,8 +552,8 @@ impl<T: UsbPeripheral> UsbBus for Usbd<T> {
551
552
}
552
553
553
554
fn set_stalled ( & self , ep_addr : EndpointAddress , stalled : bool ) {
554
- interrupt :: free ( |cs| {
555
- let regs = self . regs ( cs) ;
555
+ critical_section :: with ( move |cs| {
556
+ let regs = self . regs ( & cs) ;
556
557
557
558
unsafe {
558
559
if ep_addr. index ( ) == 0 {
@@ -578,8 +579,8 @@ impl<T: UsbPeripheral> UsbBus for Usbd<T> {
578
579
}
579
580
580
581
fn is_stalled ( & self , ep_addr : EndpointAddress ) -> bool {
581
- interrupt :: free ( |cs| {
582
- let regs = self . regs ( cs) ;
582
+ critical_section :: with ( move |cs| {
583
+ let regs = self . regs ( & cs) ;
583
584
584
585
let i = ep_addr. index ( ) ;
585
586
match ep_addr. direction ( ) {
@@ -591,16 +592,16 @@ impl<T: UsbPeripheral> UsbBus for Usbd<T> {
591
592
592
593
#[ inline]
593
594
fn suspend ( & self ) {
594
- interrupt :: free ( |cs| {
595
- let regs = self . regs ( cs) ;
595
+ critical_section :: with ( move |cs| {
596
+ let regs = self . regs ( & cs) ;
596
597
regs. lowpower . write ( |w| w. lowpower ( ) . low_power ( ) ) ;
597
598
} ) ;
598
599
}
599
600
600
601
#[ inline]
601
602
fn resume ( & self ) {
602
- interrupt :: free ( |cs| {
603
- let regs = self . regs ( cs) ;
603
+ critical_section :: with ( move |cs| {
604
+ let regs = self . regs ( & cs) ;
604
605
605
606
errata:: pre_wakeup ( ) ;
606
607
@@ -609,8 +610,8 @@ impl<T: UsbPeripheral> UsbBus for Usbd<T> {
609
610
}
610
611
611
612
fn poll ( & self ) -> PollResult {
612
- interrupt :: free ( |cs| {
613
- let regs = self . regs ( cs) ;
613
+ critical_section :: with ( move |cs| {
614
+ let regs = self . regs ( & cs) ;
614
615
let busy_in_endpoints = self . busy_in_endpoints . borrow ( cs) ;
615
616
616
617
if regs. events_usbreset . read ( ) . events_usbreset ( ) . bit_is_set ( ) {
@@ -726,16 +727,16 @@ impl<T: UsbPeripheral> UsbBus for Usbd<T> {
726
727
}
727
728
728
729
fn force_reset ( & self ) -> usb_device:: Result < ( ) > {
729
- interrupt :: free ( |cs| {
730
- self . regs ( cs) . usbpullup . write ( |w| w. connect ( ) . disabled ( ) ) ;
730
+ critical_section :: with ( move |cs| {
731
+ self . regs ( & cs) . usbpullup . write ( |w| w. connect ( ) . disabled ( ) ) ;
731
732
} ) ;
732
733
733
734
// Delay for 1ms, to give the host a chance to detect this.
734
735
// We run at 64 MHz, so 64k cycles are 1ms.
735
736
cortex_m:: asm:: delay ( 64_000 ) ;
736
737
737
- interrupt :: free ( |cs| {
738
- self . regs ( cs) . usbpullup . write ( |w| w. connect ( ) . enabled ( ) ) ;
738
+ critical_section :: with ( move |cs| {
739
+ self . regs ( & cs) . usbpullup . write ( |w| w. connect ( ) . enabled ( ) ) ;
739
740
} ) ;
740
741
741
742
Ok ( ( ) )
0 commit comments