@@ -209,7 +209,7 @@ static void dcd_pma_alloc_reset(void);
209
209
static uint16_t dcd_pma_alloc (uint8_t ep_addr , size_t length );
210
210
static void dcd_pma_free (uint8_t ep_addr );
211
211
static void dcd_ep_free (uint8_t ep_addr );
212
- static uint8_t dcd_ep_alloc (tusb_desc_endpoint_t const * p_endpoint_desc );
212
+ static uint8_t dcd_ep_alloc (uint8_t ep_addr , uint8_t ep_type );
213
213
static bool dcd_write_packet_memory (uint16_t dst , const void * __restrict src , size_t wNBytes );
214
214
static bool dcd_read_packet_memory (void * __restrict dst , uint16_t src , size_t wNBytes );
215
215
@@ -758,13 +758,15 @@ static uint16_t dcd_pma_alloc(uint8_t ep_addr, size_t length)
758
758
TU_ASSERT (length <= epXferCtl -> pma_alloc_size , 0xFFFF ); // Verify no larger than previous alloc
759
759
return epXferCtl -> pma_ptr ;
760
760
}
761
-
761
+
762
+ open_ep_count ++ ;
763
+
762
764
uint16_t addr = ep_buf_ptr ;
763
765
ep_buf_ptr = (uint16_t )(ep_buf_ptr + length ); // increment buffer pointer
764
-
766
+
765
767
// Verify no overflow
766
768
TU_ASSERT (ep_buf_ptr <= PMA_LENGTH , 0xFFFF );
767
-
769
+
768
770
epXferCtl -> pma_ptr = addr ;
769
771
epXferCtl -> pma_alloc_size = length ;
770
772
//TU_LOG2("dcd_pma_alloc(%x,%x)=%x\r\n",ep_addr,length,addr);
@@ -802,29 +804,28 @@ static void dcd_pma_free(uint8_t ep_addr)
802
804
/***
803
805
* Allocate hardware endpoint
804
806
*/
805
- static uint8_t dcd_ep_alloc (tusb_desc_endpoint_t const * p_endpoint_desc )
807
+ static uint8_t dcd_ep_alloc (uint8_t ep_addr , uint8_t ep_type )
806
808
{
807
- uint8_t const epnum = tu_edpt_number (p_endpoint_desc -> bEndpointAddress );
808
- uint8_t const dir = tu_edpt_dir (p_endpoint_desc -> bEndpointAddress );
809
- uint8_t const eptype = p_endpoint_desc -> bmAttributes .xfer ;
809
+ uint8_t const epnum = tu_edpt_number (ep_addr );
810
+ uint8_t const dir = tu_edpt_dir (ep_addr );
810
811
811
812
for (uint8_t i = 0 ; i < STFSDEV_EP_COUNT ; i ++ )
812
813
{
813
814
// If EP of current direction is not allocated
814
815
// Except for ISO endpoint, both direction should be free
815
816
if (!ep_alloc_status [i ].allocated [dir ] &&
816
- (eptype != TUSB_XFER_ISOCHRONOUS || !ep_alloc_status [i ].allocated [dir ^ 1 ]))
817
+ (ep_type != TUSB_XFER_ISOCHRONOUS || !ep_alloc_status [i ].allocated [dir ^ 1 ]))
817
818
{
818
819
// Check if EP number is the same
819
820
if (ep_alloc_status [i ].ep_num == 0xFF ||
820
821
ep_alloc_status [i ].ep_num == epnum )
821
822
{
822
823
// One EP pair has to be the same type
823
824
if (ep_alloc_status [i ].ep_type == 0xFF ||
824
- ep_alloc_status [i ].ep_type == eptype )
825
+ ep_alloc_status [i ].ep_type == ep_type )
825
826
{
826
827
ep_alloc_status [i ].ep_num = epnum ;
827
- ep_alloc_status [i ].ep_type = eptype ;
828
+ ep_alloc_status [i ].ep_type = ep_type ;
828
829
ep_alloc_status [i ].allocated [dir ] = true;
829
830
830
831
return i ;
@@ -871,7 +872,7 @@ static void dcd_ep_free(uint8_t ep_addr)
871
872
bool dcd_edpt_open (uint8_t rhport , tusb_desc_endpoint_t const * p_endpoint_desc )
872
873
{
873
874
(void )rhport ;
874
- uint8_t const epnum = dcd_ep_alloc (p_endpoint_desc );
875
+ uint8_t const epnum = dcd_ep_alloc (p_endpoint_desc -> bEndpointAddress , p_endpoint_desc -> bmAttributes . xfer );
875
876
uint8_t const dir = tu_edpt_dir (p_endpoint_desc -> bEndpointAddress );
876
877
const uint16_t buffer_size = pcd_aligned_buffer_size (tu_edpt_packet_size (p_endpoint_desc ));
877
878
uint16_t pma_addr ;
@@ -900,8 +901,6 @@ bool dcd_edpt_open (uint8_t rhport, tusb_desc_endpoint_t const * p_endpoint_desc
900
901
TU_ASSERT (false);
901
902
}
902
903
903
- open_ep_count ++ ;
904
-
905
904
pcd_set_eptype (USB , epnum , wType );
906
905
pcd_set_ep_address (USB , epnum , tu_edpt_number (p_endpoint_desc -> bEndpointAddress ));
907
906
// Be normal, for now, instead of only accepting zero-byte packets (on control endpoint)
@@ -983,6 +982,56 @@ void dcd_edpt_close (uint8_t rhport, uint8_t ep_addr)
983
982
dcd_pma_free (ep_addr );
984
983
}
985
984
985
+ bool dcd_edpt_iso_alloc (uint8_t rhport , uint8_t ep_addr , uint16_t largest_packet_size )
986
+ {
987
+ (void )rhport ;
988
+
989
+ TU_ASSERT (largest_packet_size <= 1024 );
990
+
991
+ uint8_t const epnum = dcd_ep_alloc (ep_addr , TUSB_XFER_ISOCHRONOUS );
992
+ const uint16_t buffer_size = pcd_aligned_buffer_size (largest_packet_size );
993
+
994
+ /* Create a packet memory buffer area. For isochronous endpoints,
995
+ * use the same buffer as the double buffer, essentially disabling double buffering */
996
+ dcd_pma_alloc (ep_addr , buffer_size );
997
+
998
+ xfer_ctl_ptr (ep_addr )-> epnum = epnum ;
999
+
1000
+ return true;
1001
+ }
1002
+
1003
+ bool dcd_edpt_iso_activate (uint8_t rhport , tusb_desc_endpoint_t const * p_endpoint_desc )
1004
+ {
1005
+ (void )rhport ;
1006
+ uint8_t const epnum = xfer_ctl_ptr (p_endpoint_desc -> bEndpointAddress )-> epnum ;
1007
+ uint8_t const dir = tu_edpt_dir (p_endpoint_desc -> bEndpointAddress );
1008
+ const uint16_t packet_size = tu_edpt_packet_size (p_endpoint_desc );
1009
+ uint16_t pma_addr ;
1010
+
1011
+ /* Disable endpoint */
1012
+ pcd_set_ep_tx_status (USB , epnum , USB_EP_TX_DIS );
1013
+ pcd_set_ep_rx_status (USB , epnum , USB_EP_RX_DIS );
1014
+
1015
+ pcd_set_eptype (USB , epnum , USB_EP_ISOCHRONOUS );
1016
+ pcd_set_ep_address (USB , epnum , tu_edpt_number (p_endpoint_desc -> bEndpointAddress ));
1017
+ // Be normal, for now, instead of only accepting zero-byte packets (on control endpoint)
1018
+ // or being double-buffered (bulk endpoints)
1019
+ pcd_clear_ep_kind (USB ,0 );
1020
+
1021
+ pma_addr = xfer_ctl_ptr (p_endpoint_desc -> bEndpointAddress )-> pma_ptr ;
1022
+
1023
+ * pcd_ep_tx_address_ptr (USB , epnum ) = pma_addr ;
1024
+ pcd_clear_tx_dtog (USB , epnum );
1025
+
1026
+ * pcd_ep_rx_address_ptr (USB , epnum ) = pma_addr ;
1027
+ pcd_set_ep_rx_bufsize (USB , epnum , packet_size );
1028
+ pcd_clear_rx_dtog (USB , epnum );
1029
+
1030
+ xfer_ctl_ptr (p_endpoint_desc -> bEndpointAddress )-> max_packet_size = packet_size ;
1031
+
1032
+ return true;
1033
+ }
1034
+
986
1035
// Currently, single-buffered, and only 64 bytes at a time (max)
987
1036
988
1037
static void dcd_transmit_packet (xfer_ctl_t * xfer , uint16_t ep_ix )
0 commit comments