Skip to content

Commit 2b84a17

Browse files
authored
Merge pull request #5584 from SiliconLabs/feature/emlib-5.3.3
Upgrade to Silicon Labs HAL
2 parents 969f8af + 1b0922e commit 2b84a17

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

104 files changed

+12866
-9290
lines changed

features/unsupported/USBDevice/targets/TARGET_Silicon_Labs/inc/em_usb.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@
4545
#define EFM32_WEAK SL_WEAK
4646
#define EFM32_ATTRIBUTE_SECTION(X) SL_ATTRIBUTE_SECTION(X)
4747

48-
#include "em_int.h"
49-
5048
#if defined( USB_USE_PRINTF )
5149
#include <stdio.h>
5250
#endif

features/unsupported/USBDevice/targets/TARGET_Silicon_Labs/src/em_usbd.c

Lines changed: 52 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#if defined( USB_DEVICE )
2828

2929
#include "em_cmu.h"
30+
#include "em_core.h"
3031
#include "em_usbtypes.h"
3132
#include "em_usbhal.h"
3233
#include "em_usbd.h"
@@ -69,9 +70,10 @@ static const char *stateNames[] =
6970
******************************************************************************/
7071
void USBD_AbortAllTransfers( void )
7172
{
72-
INT_Disable();
73+
CORE_DECLARE_IRQ_STATE;
74+
CORE_ENTER_CRITICAL();
7375
USBDHAL_AbortAllTransfers( USB_STATUS_EP_ABORTED );
74-
INT_Enable();
76+
CORE_EXIT_CRITICAL();
7577
}
7678

7779
/***************************************************************************//**
@@ -85,6 +87,7 @@ int USBD_AbortTransfer( int epAddr )
8587
{
8688
USB_XferCompleteCb_TypeDef callback;
8789
USBD_Ep_TypeDef *ep = USBD_GetEpFromAddr( epAddr );
90+
CORE_DECLARE_IRQ_STATE;
8891

8992
if ( ep == NULL )
9093
{
@@ -100,10 +103,10 @@ int USBD_AbortTransfer( int epAddr )
100103
return USB_STATUS_ILLEGAL;
101104
}
102105

103-
INT_Disable();
106+
CORE_ENTER_CRITICAL();
104107
if ( ep->state == D_EP_IDLE )
105108
{
106-
INT_Enable();
109+
CORE_EXIT_CRITICAL();
107110
return USB_STATUS_OK;
108111
}
109112

@@ -125,7 +128,7 @@ int USBD_AbortTransfer( int epAddr )
125128
callback( USB_STATUS_EP_ABORTED, ep->xferred, ep->remaining );
126129
}
127130

128-
INT_Enable();
131+
CORE_EXIT_CRITICAL();
129132
return USB_STATUS_OK;
130133
}
131134

@@ -139,9 +142,10 @@ int USBD_AbortTransfer( int epAddr )
139142
******************************************************************************/
140143
void USBD_Connect( void )
141144
{
142-
INT_Disable();
145+
CORE_DECLARE_IRQ_STATE;
146+
CORE_ENTER_CRITICAL();
143147
USBDHAL_Connect();
144-
INT_Enable();
148+
CORE_EXIT_CRITICAL();
145149
}
146150

147151
/***************************************************************************//**
@@ -154,9 +158,10 @@ void USBD_Connect( void )
154158
******************************************************************************/
155159
void USBD_Disconnect( void )
156160
{
157-
INT_Disable();
161+
CORE_DECLARE_IRQ_STATE;
162+
CORE_ENTER_CRITICAL();
158163
USBDHAL_Disconnect();
159-
INT_Enable();
164+
CORE_EXIT_CRITICAL();
160165
}
161166

162167
/***************************************************************************//**
@@ -239,6 +244,7 @@ const char *USBD_GetUsbStateName( USBD_State_TypeDef state )
239244
int USBD_Init( const USBD_Init_TypeDef *p )
240245
{
241246
USBD_Ep_TypeDef *ep;
247+
CORE_DECLARE_IRQ_STATE;
242248

243249
#if !defined( USB_CORECLK_HFRCO ) || !defined( CMU_OSCENCMD_USHFRCOEN )
244250
/* Devices supporting crystal-less USB can use HFRCO or HFXO as core clock. */
@@ -308,7 +314,7 @@ int USBD_Init( const USBD_Init_TypeDef *p )
308314
*/
309315
totalRxFifoSize += 10 + 1 + ( 2 * (MAX_NUM_OUT_EPS + 1) );
310316

311-
INT_Disable();
317+
CORE_ENTER_CRITICAL();
312318

313319
/* Enable USB clock */
314320
CMU->HFCORECLKEN0 |= CMU_HFCORECLKEN0_USB | CMU_HFCORECLKEN0_USBC;
@@ -339,7 +345,7 @@ int USBD_Init( const USBD_Init_TypeDef *p )
339345
}
340346
else
341347
{
342-
INT_Enable();
348+
CORE_EXIT_CRITICAL();
343349
DEBUG_USB_API_PUTS( "\nUSBD_Init(), FIFO setup error" );
344350
EFM_ASSERT( false );
345351
return USB_STATUS_ILLEGAL;
@@ -356,7 +362,7 @@ int USBD_Init( const USBD_Init_TypeDef *p )
356362
USBD_SetUsbState( USBD_STATE_NONE );
357363
}
358364

359-
INT_Enable();
365+
CORE_EXIT_CRITICAL();
360366
return USB_STATUS_OK;
361367
}
362368

@@ -389,6 +395,7 @@ int USBD_Init( const USBD_Init_TypeDef *p )
389395
int USBD_Read( int epAddr, void *data, int byteCount,
390396
USB_XferCompleteCb_TypeDef callback )
391397
{
398+
CORE_DECLARE_IRQ_STATE;
392399
USBD_Ep_TypeDef *ep = USBD_GetEpFromAddr( epAddr );
393400

394401
USB_PRINTF("USBD: Read addr %x, data %p, size %d, cb 0x%lx\n",
@@ -416,24 +423,25 @@ int USBD_Read( int epAddr, void *data, int byteCount,
416423
return USB_STATUS_ILLEGAL;
417424
}
418425

419-
INT_Disable();
426+
CORE_ENTER_CRITICAL();
427+
420428
if ( USBDHAL_EpIsStalled( ep ) )
421429
{
422-
INT_Enable();
430+
CORE_EXIT_CRITICAL();
423431
DEBUG_USB_API_PUTS( "\nUSBD_Read(), Endpoint is halted" );
424432
return USB_STATUS_EP_STALLED;
425433
}
426434

427435
if ( ep->state != D_EP_IDLE )
428436
{
429-
INT_Enable();
437+
CORE_EXIT_CRITICAL();
430438
DEBUG_USB_API_PUTS( "\nUSBD_Read(), Endpoint is busy" );
431439
return USB_STATUS_EP_BUSY;
432440
}
433441

434442
if ( ( ep->num > 0 ) && ( USBD_GetUsbState() != USBD_STATE_CONFIGURED ) )
435443
{
436-
INT_Enable();
444+
CORE_EXIT_CRITICAL();
437445
DEBUG_USB_API_PUTS( "\nUSBD_Read(), Device not configured" );
438446
return USB_STATUS_DEVICE_UNCONFIGURED;
439447
}
@@ -448,7 +456,7 @@ int USBD_Read( int epAddr, void *data, int byteCount,
448456
}
449457
else if ( ep->in != false )
450458
{
451-
INT_Enable();
459+
CORE_EXIT_CRITICAL();
452460
DEBUG_USB_API_PUTS( "\nUSBD_Read(), Illegal EP direction" );
453461
EFM_ASSERT( false );
454462
return USB_STATUS_ILLEGAL;
@@ -458,7 +466,7 @@ int USBD_Read( int epAddr, void *data, int byteCount,
458466
ep->xferCompleteCb = callback;
459467

460468
USBD_ArmEp( ep );
461-
INT_Enable();
469+
CORE_EXIT_CRITICAL();
462470
return USB_STATUS_OK;
463471
}
464472

@@ -477,22 +485,26 @@ int USBD_Read( int epAddr, void *data, int byteCount,
477485
******************************************************************************/
478486
int USBD_RemoteWakeup( void )
479487
{
480-
INT_Disable();
488+
CORE_DECLARE_IRQ_STATE;
489+
CORE_ENTER_CRITICAL();
481490

482491
if ( ( dev->state != USBD_STATE_SUSPENDED ) ||
483492
( dev->remoteWakeupEnabled == false ) )
484493
{
485-
INT_Enable();
494+
CORE_EXIT_CRITICAL();
486495
DEBUG_USB_API_PUTS( "\nUSBD_RemoteWakeup(), Illegal remote wakeup" );
487496
return USB_STATUS_ILLEGAL;
488497
}
489498

490499
USBDHAL_SetRemoteWakeup();
491-
INT_Enable();
500+
CORE_EXIT_CRITICAL();
501+
492502
USBTIMER_DelayMs( 10 );
493-
INT_Disable();
503+
504+
CORE_ENTER_CRITICAL();
494505
USBDHAL_ClearRemoteWakeup();
495-
INT_Enable();
506+
CORE_EXIT_CRITICAL();
507+
496508
return USB_STATUS_OK;
497509
}
498510

@@ -565,6 +577,7 @@ void USBD_SetUsbState( USBD_State_TypeDef newState )
565577
int USBD_StallEp( int epAddr )
566578
{
567579
USB_Status_TypeDef retVal;
580+
CORE_DECLARE_IRQ_STATE;
568581
USBD_Ep_TypeDef *ep = USBD_GetEpFromAddr( epAddr );
569582

570583
if ( ep == NULL )
@@ -581,9 +594,9 @@ int USBD_StallEp( int epAddr )
581594
return USB_STATUS_ILLEGAL;
582595
}
583596

584-
INT_Disable();
597+
CORE_ENTER_CRITICAL();
585598
retVal = USBDHAL_StallEp( ep );
586-
INT_Enable();
599+
CORE_EXIT_CRITICAL();
587600

588601
if ( retVal != USB_STATUS_OK )
589602
{
@@ -626,6 +639,7 @@ void USBD_Stop( void )
626639
int USBD_UnStallEp( int epAddr )
627640
{
628641
USB_Status_TypeDef retVal;
642+
CORE_DECLARE_IRQ_STATE;
629643
USBD_Ep_TypeDef *ep = USBD_GetEpFromAddr( epAddr );
630644

631645
if ( ep == NULL )
@@ -642,9 +656,9 @@ int USBD_UnStallEp( int epAddr )
642656
return USB_STATUS_ILLEGAL;
643657
}
644658

645-
INT_Disable();
659+
CORE_ENTER_CRITICAL();
646660
retVal = USBDHAL_UnStallEp( ep );
647-
INT_Enable();
661+
CORE_EXIT_CRITICAL();
648662

649663
if ( retVal != USB_STATUS_OK )
650664
{
@@ -678,6 +692,7 @@ int USBD_Write( int epAddr, void *data, int byteCount,
678692
USB_XferCompleteCb_TypeDef callback )
679693
{
680694
USBD_Ep_TypeDef *ep = USBD_GetEpFromAddr( epAddr );
695+
CORE_DECLARE_IRQ_STATE;
681696

682697
USB_PRINTF("USBD: Write addr %x, data %p, size %d, cb 0x%lx\n",
683698
epAddr, data, byteCount, (uint32_t)callback);
@@ -704,24 +719,25 @@ int USBD_Write( int epAddr, void *data, int byteCount,
704719
return USB_STATUS_ILLEGAL;
705720
}
706721

707-
INT_Disable();
722+
CORE_ENTER_CRITICAL();
723+
708724
if ( USBDHAL_EpIsStalled( ep ) )
709725
{
710-
INT_Enable();
726+
CORE_EXIT_CRITICAL();
711727
DEBUG_USB_API_PUTS( "\nUSBD_Write(), Endpoint is halted" );
712728
return USB_STATUS_EP_STALLED;
713729
}
714730

715731
if ( ep->state != D_EP_IDLE )
716732
{
717-
INT_Enable();
733+
CORE_EXIT_CRITICAL();
718734
DEBUG_USB_API_PUTS( "\nUSBD_Write(), Endpoint is busy" );
719735
return USB_STATUS_EP_BUSY;
720736
}
721737

722738
if ( ( ep->num > 0 ) && ( USBD_GetUsbState() != USBD_STATE_CONFIGURED ) )
723739
{
724-
INT_Enable();
740+
CORE_EXIT_CRITICAL();
725741
DEBUG_USB_API_PUTS( "\nUSBD_Write(), Device not configured" );
726742
return USB_STATUS_DEVICE_UNCONFIGURED;
727743
}
@@ -736,7 +752,7 @@ int USBD_Write( int epAddr, void *data, int byteCount,
736752
}
737753
else if ( ep->in != true )
738754
{
739-
INT_Enable();
755+
CORE_EXIT_CRITICAL();
740756
DEBUG_USB_API_PUTS( "\nUSBD_Write(), Illegal EP direction" );
741757
EFM_ASSERT( false );
742758
return USB_STATUS_ILLEGAL;
@@ -746,7 +762,7 @@ int USBD_Write( int epAddr, void *data, int byteCount,
746762
ep->xferCompleteCb = callback;
747763

748764
USBD_ArmEp( ep );
749-
INT_Enable();
765+
CORE_EXIT_CRITICAL();
750766
return USB_STATUS_OK;
751767
}
752768

@@ -841,6 +857,7 @@ static void USBD_ResetEndpoints(void)
841857
int USBD_AddEndpoint(int epAddr, int transferType,
842858
int maxPacketSize, int bufferMult)
843859
{
860+
CORE_DECLARE_IRQ_STATE;
844861
USBD_Ep_TypeDef *ep;
845862

846863
numEps++;
@@ -890,7 +907,7 @@ int USBD_AddEndpoint(int epAddr, int transferType,
890907
ep->num, numEps, ep->in, ep->addr, ep->type, ep->packetSize, ep->fifoSize,
891908
totalTxFifoSize, totalRxFifoSize);
892909

893-
INT_Disable();
910+
CORE_ENTER_CRITICAL();
894911
#if defined( CMU_OSCENCMD_USHFRCOEN )
895912
/* Happy Gecko workaround: disable LEM GATE mode if using ISOC endpoints. */
896913
if ( transferType == USB_EPTYPE_ISOC )
@@ -900,7 +917,7 @@ int USBD_AddEndpoint(int epAddr, int transferType,
900917
#endif
901918

902919
int ret = USBDHAL_ReconfigureFifos(totalRxFifoSize, totalTxFifoSize);
903-
INT_Enable();
920+
CORE_EXIT_CRITICAL();
904921

905922
if( ret != USB_STATUS_OK ) {
906923
return ret;

features/unsupported/USBDevice/targets/TARGET_Silicon_Labs/src/em_usbdint.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#if defined( USB_DEVICE )
2828

2929
#include "em_cmu.h"
30+
#include "em_core.h"
3031
#include "em_usbtypes.h"
3132
#include "em_usbhal.h"
3233
#include "em_usbd.h"
@@ -106,8 +107,9 @@ void USB_IRQHandler( void )
106107
{
107108
uint32_t status;
108109
bool servedVbusInterrupt = false;
110+
CORE_DECLARE_IRQ_STATE;
109111

110-
INT_Disable();
112+
CORE_ENTER_CRITICAL();
111113

112114
#if ( USB_PWRSAVE_MODE )
113115
if ( USBD_poweredDown )
@@ -192,7 +194,7 @@ void USB_IRQHandler( void )
192194
status = USBHAL_GetCoreInts();
193195
if ( status == 0 )
194196
{
195-
INT_Enable();
197+
CORE_EXIT_CRITICAL();
196198
if ( !servedVbusInterrupt )
197199
{
198200
DEBUG_USB_INT_LO_PUTS( "\nSinT" );
@@ -209,7 +211,7 @@ void USB_IRQHandler( void )
209211
HANDLE_INT( USB_GINTSTS_IEPINT )
210212
HANDLE_INT( USB_GINTSTS_OEPINT )
211213

212-
INT_Enable();
214+
CORE_EXIT_CRITICAL();
213215

214216
if ( status != 0 )
215217
{

features/unsupported/USBDevice/targets/TARGET_Silicon_Labs/src/em_usbhal.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,7 @@ USB_Status_TypeDef USBDHAL_CoreInit( uint32_t totalRxFifoSize,
199199
USB_GUSBCFG_FORCEDEVMODE;
200200
#endif
201201

202-
INT_Enable();
203202
USBTIMER_DelayMs( 50 );
204-
INT_Disable();
205203

206204
/* Set device speed */
207205
USB->DCFG = ( USB->DCFG & ~_USB_DCFG_DEVSPD_MASK ) | 3; /* Full speed PHY */
@@ -649,9 +647,7 @@ USB_Status_TypeDef USBHHAL_CoreInit( uint32_t rxFifoSize,
649647
~(GUSBCFG_WO_BITMASK | USB_GUSBCFG_FORCEDEVMODE ) ) |
650648
USB_GUSBCFG_FORCEHSTMODE;
651649

652-
INT_Enable();
653650
USBTIMER_DelayMs( 100 );
654-
INT_Disable();
655651

656652
/* Set 48 MHz PHY clock, FS/LS mode */
657653
USB->HCFG = ( USB->HCFG & ~_USB_HCFG_FSLSPCLKSEL_MASK ) |

0 commit comments

Comments
 (0)