@@ -83,7 +83,7 @@ typedef enum {
83
83
// * as there are ODD and EVEN buffer -> 8*2 bdt
84
84
MBED_ALIGN (512 ) BDT bdt[NUMBER_OF_PHYSICAL_ENDPOINTS * 2]; // 512 bytes aligned!
85
85
86
- uint8_t * endpoint_buffer[NUMBER_OF_PHYSICAL_ENDPOINTS * 2 ];
86
+ uint8_t *endpoint_buffer[NUMBER_OF_PHYSICAL_ENDPOINTS * 2 ];
87
87
uint8_t ep0_buffer[2 ][MAX_PACKET_SIZE_EP0];
88
88
uint8_t ep1_buffer[2 ][MAX_PACKET_SIZE_EP1];
89
89
uint8_t ep2_buffer[2 ][MAX_PACKET_SIZE_EP2];
@@ -96,8 +96,9 @@ static ctrl_xfer_t ctrl_xfer = CTRL_XFER_READY;
96
96
97
97
static uint32_t Data1 = 0x55555555 ;
98
98
99
- static uint32_t frameNumber () {
100
- return ((USB0->FRMNUML | (USB0->FRMNUMH << 8 )) & 0x07FF );
99
+ static uint32_t frameNumber ()
100
+ {
101
+ return ((USB0->FRMNUML | (USB0->FRMNUMH << 8 )) & 0x07FF );
101
102
}
102
103
103
104
USBPhy *get_usb_phy ()
@@ -126,11 +127,11 @@ void USBPhyHw::init(USBPhyEvents *events)
126
127
NVIC_DisableIRQ (USB0_IRQn);
127
128
128
129
#if (defined(FSL_FEATURE_SOC_MPU_COUNT) && (FSL_FEATURE_SOC_MPU_COUNT > 0U))
129
- MPU->CESR = 0 ;
130
+ MPU->CESR = 0 ;
130
131
#endif
131
132
132
133
#if (defined(FSL_FEATURE_SOC_SYSMPU_COUNT) && (FSL_FEATURE_SOC_SYSMPU_COUNT > 0U))
133
- SYSMPU->CESR = 0 ;
134
+ SYSMPU->CESR = 0 ;
134
135
#endif
135
136
136
137
#if defined(TARGET_KL43Z) || defined(TARGET_K22F) || defined(TARGET_K64F)
@@ -150,9 +151,9 @@ void USBPhyHw::init(USBPhyEvents *events)
150
151
151
152
// USB Module Configuration
152
153
// Set BDT Base Register
153
- USB0->BDTPAGE1 = (uint8_t )((uint32_t )bdt>> 8 );
154
- USB0->BDTPAGE2 = (uint8_t )((uint32_t )bdt>> 16 );
155
- USB0->BDTPAGE3 = (uint8_t )((uint32_t )bdt>> 24 );
154
+ USB0->BDTPAGE1 = (uint8_t )((uint32_t )bdt >> 8 );
155
+ USB0->BDTPAGE2 = (uint8_t )((uint32_t )bdt >> 16 );
156
+ USB0->BDTPAGE3 = (uint8_t )((uint32_t )bdt >> 24 );
156
157
157
158
// Clear interrupt flag
158
159
USB0->ISTAT = 0xff ;
@@ -209,7 +210,7 @@ void USBPhyHw::connect()
209
210
void USBPhyHw::disconnect ()
210
211
{
211
212
// disable all endpoints to prevent them from nacking when disconnected
212
- for (int i = 0 ; i < 16 ; i++) {
213
+ for (int i = 0 ; i < 16 ; i++) {
213
214
USB0->ENDPOINT [i].ENDPT = 0x00 ;
214
215
}
215
216
// disable USB
@@ -259,7 +260,7 @@ void USBPhyHw::remote_wakeup()
259
260
#define ALLOW_BULK_OR_INT_ENDPOINTS (USB_EP_ATTR_ALLOW_BULK | USB_EP_ATTR_ALLOW_INT)
260
261
#define ALLOW_NO_ENDPOINTS 0
261
262
262
- const usb_ep_table_t * USBPhyHw::endpoint_table ()
263
+ const usb_ep_table_t * USBPhyHw::endpoint_table ()
263
264
{
264
265
static const usb_ep_table_t endpoint_table = {
265
266
1 , // No cost per endpoint - everything allocated up front
@@ -349,7 +350,7 @@ void USBPhyHw::ep0_write(uint8_t *buffer, uint32_t size)
349
350
// Prepare for next setup packet
350
351
endpoint_read_core (EP0OUT, MAX_PACKET_SIZE_EP0);
351
352
ctrl_xfer = CTRL_XFER_READY;
352
- }
353
+ }
353
354
endpoint_write (EP0IN, buffer, size);
354
355
355
356
// Clear suspend after the setup stage
@@ -386,7 +387,7 @@ void USBPhyHw::ep0_stall()
386
387
bool USBPhyHw::endpoint_add (usb_ep_t endpoint, uint32_t max_packet, usb_ep_type_t type)
387
388
{
388
389
uint32_t handshake_flag = 0 ;
389
- uint8_t * buf;
390
+ uint8_t *buf;
390
391
391
392
if (DESC_TO_PHY (endpoint) > NUMBER_OF_PHYSICAL_ENDPOINTS - 1 ) {
392
393
return false ;
@@ -406,21 +407,21 @@ bool USBPhyHw::endpoint_add(usb_ep_t endpoint, uint32_t max_packet, usb_ep_type_
406
407
407
408
// IN endpt -> device to host (TX)
408
409
if (DESC_EP_IN (endpoint)) {
409
- bdt[EP_BDT_IDX (log_endpoint, TX, ODD )].address = (uint32_t ) buf;
410
- bdt[EP_BDT_IDX (log_endpoint, TX, ODD )].info = 0 ;
410
+ bdt[EP_BDT_IDX (log_endpoint, TX, ODD)].address = (uint32_t ) buf;
411
+ bdt[EP_BDT_IDX (log_endpoint, TX, ODD)].info = 0 ;
411
412
bdt[EP_BDT_IDX (log_endpoint, TX, EVEN)].address = 0 ;
412
413
USB0->ENDPOINT [log_endpoint].ENDPT |= handshake_flag | // ep handshaking (not if iso endpoint)
413
414
USB_ENDPT_EPTXEN_MASK; // en TX (IN) tran
414
415
}
415
416
// OUT endpt -> host to device (RX)
416
417
else {
417
- bdt[EP_BDT_IDX (log_endpoint, RX, ODD )].byte_count = max_packet;
418
- bdt[EP_BDT_IDX (log_endpoint, RX, ODD )].address = (uint32_t ) buf;
419
- bdt[EP_BDT_IDX (log_endpoint, RX, ODD )].info = BD_DTS_MASK;
418
+ bdt[EP_BDT_IDX (log_endpoint, RX, ODD)].byte_count = max_packet;
419
+ bdt[EP_BDT_IDX (log_endpoint, RX, ODD)].address = (uint32_t ) buf;
420
+ bdt[EP_BDT_IDX (log_endpoint, RX, ODD)].info = BD_DTS_MASK;
420
421
bdt[EP_BDT_IDX (log_endpoint, RX, EVEN)].info = 0 ;
421
422
if (log_endpoint == 0 ) {
422
423
// Prepare for setup packet
423
- bdt[EP_BDT_IDX (log_endpoint, RX, ODD )].info |= BD_OWN_MASK;
424
+ bdt[EP_BDT_IDX (log_endpoint, RX, ODD)].info |= BD_OWN_MASK;
424
425
}
425
426
USB0->ENDPOINT [log_endpoint].ENDPT |= handshake_flag | // ep handshaking (not if iso endpoint)
426
427
USB_ENDPT_EPRXEN_MASK; // en RX (OUT) tran.
@@ -466,8 +467,7 @@ bool USBPhyHw::endpoint_read_core(usb_ep_t endpoint, uint32_t max_packet)
466
467
bdt[idx].byte_count = max_packet;
467
468
if ((Data1 >> DESC_TO_PHY (endpoint)) & 1 ) {
468
469
bdt[idx].info = BD_OWN_MASK | BD_DTS_MASK | BD_DATA01_MASK;
469
- }
470
- else {
470
+ } else {
471
471
bdt[idx].info = BD_OWN_MASK | BD_DTS_MASK;
472
472
}
473
473
@@ -491,7 +491,7 @@ bool USBPhyHw::endpoint_read_result_core(usb_ep_t endpoint, uint8_t *data, uint3
491
491
{
492
492
uint32_t n, sz, idx, setup = 0 ;
493
493
uint8_t not_iso;
494
- uint8_t * ep_buf;
494
+ uint8_t *ep_buf;
495
495
496
496
uint32_t log_endpoint = DESC_TO_LOG (endpoint);
497
497
@@ -542,7 +542,7 @@ bool USBPhyHw::endpoint_read_result_core(usb_ep_t endpoint, uint8_t *data, uint3
542
542
bool USBPhyHw::endpoint_write (usb_ep_t endpoint, uint8_t *data, uint32_t size)
543
543
{
544
544
uint32_t idx, n;
545
- uint8_t * ep_buf;
545
+ uint8_t *ep_buf;
546
546
547
547
if (DESC_TO_PHY (endpoint) > NUMBER_OF_PHYSICAL_ENDPOINTS - 1 ) {
548
548
return false ;
@@ -588,7 +588,7 @@ void USBPhyHw::process()
588
588
// reset interrupt
589
589
if (istat & USB_ISTAT_USBRST_MASK) {
590
590
// disable all endpt
591
- for (i = 0 ; i < 16 ; i++) {
591
+ for (i = 0 ; i < 16 ; i++) {
592
592
USB0->ENDPOINT [i].ENDPT = 0x00 ;
593
593
}
594
594
@@ -631,9 +631,10 @@ void USBPhyHw::process()
631
631
}
632
632
633
633
// stall interrupt
634
- if (istat & 1 << 7 ) {
635
- if (USB0->ENDPOINT [0 ].ENDPT & USB_ENDPT_EPSTALL_MASK)
634
+ if (istat & 1 << 7 ) {
635
+ if (USB0->ENDPOINT [0 ].ENDPT & USB_ENDPT_EPSTALL_MASK) {
636
636
USB0->ENDPOINT [0 ].ENDPT &= ~USB_ENDPT_EPSTALL_MASK;
637
+ }
637
638
USB0->ISTAT = USB_ISTAT_STALL_MASK;
638
639
}
639
640
@@ -660,9 +661,9 @@ void USBPhyHw::process()
660
661
} else {
661
662
// OUT packet
662
663
if (rx_en && (TOK_PID ((EP_BDT_IDX (num, dir, ev_odd))) == OUT_TOKEN)) {
663
- if (num == 0 )
664
+ if (num == 0 ) {
664
665
events->ep0_out ();
665
- else {
666
+ } else {
666
667
epComplete |= EP (phy_ep);
667
668
events->out (PHY_TO_DESC (phy_ep));
668
669
}
@@ -676,8 +677,7 @@ void USBPhyHw::process()
676
677
USB0->ADDR = addr & 0x7F ;
677
678
set_addr = 0 ;
678
679
}
679
- }
680
- else {
680
+ } else {
681
681
epComplete |= EP (phy_ep);
682
682
events->in (PHY_TO_DESC (phy_ep));
683
683
}
@@ -688,7 +688,7 @@ void USBPhyHw::process()
688
688
}
689
689
690
690
// sleep interrupt
691
- if (istat & 1 << 4 ) {
691
+ if (istat & 1 << 4 ) {
692
692
USB0->ISTAT = USB_ISTAT_SLEEP_MASK;
693
693
events->suspend (true );
694
694
}
@@ -713,7 +713,8 @@ void USBPhyHw::process()
713
713
NVIC_EnableIRQ (USB0_IRQn);
714
714
}
715
715
716
- void USBPhyHw::_usbisr (void ) {
716
+ void USBPhyHw::_usbisr (void )
717
+ {
717
718
NVIC_DisableIRQ (USB0_IRQn);
718
719
instance->events ->start_process ();
719
720
}
0 commit comments