@@ -38,6 +38,8 @@ use num_traits::FromPrimitive;
3838pub use os_adapter:: * ;
3939use smoltcp:: phy:: { Device , DeviceCapabilities , RxToken , TxToken } ;
4040
41+ const ETHERNET_FRAME_HEADER_SIZE : usize = 18 ;
42+
4143#[ cfg( feature = "mtu-1514" ) ]
4244const MTU : usize = 1514 ;
4345#[ cfg( feature = "mtu-1500" ) ]
@@ -105,15 +107,15 @@ impl WifiMode {
105107#[ derive( Debug , Clone , Copy ) ]
106108pub ( crate ) struct DataFrame < ' a > {
107109 len : usize ,
108- data : [ u8 ; 1536 ] ,
110+ data : [ u8 ; MTU + ETHERNET_FRAME_HEADER_SIZE ] ,
109111 _phantom : PhantomData < & ' a ( ) > ,
110112}
111113
112114impl < ' a > DataFrame < ' a > {
113115 pub ( crate ) fn new ( ) -> DataFrame < ' a > {
114116 DataFrame {
115117 len : 0 ,
116- data : [ 0u8 ; 1536 ] ,
118+ data : [ 0u8 ; MTU + ETHERNET_FRAME_HEADER_SIZE ] ,
117119 _phantom : Default :: default ( ) ,
118120 }
119121 }
@@ -130,10 +132,13 @@ impl<'a> DataFrame<'a> {
130132 }
131133}
132134
133- pub ( crate ) static DATA_QUEUE_RX : Mutex < RefCell < SimpleQueue < DataFrame , 5 > > > =
135+ const RX_QUEUE_SIZE : usize = crate :: CONFIG . rx_queue_size ;
136+ const TX_QUEUE_SIZE : usize = crate :: CONFIG . tx_queue_size ;
137+
138+ pub ( crate ) static DATA_QUEUE_RX : Mutex < RefCell < SimpleQueue < DataFrame , RX_QUEUE_SIZE > > > =
134139 Mutex :: new ( RefCell :: new ( SimpleQueue :: new ( ) ) ) ;
135140
136- pub ( crate ) static DATA_QUEUE_TX : Mutex < RefCell < SimpleQueue < DataFrame , 3 > > > =
141+ pub ( crate ) static DATA_QUEUE_TX : Mutex < RefCell < SimpleQueue < DataFrame , TX_QUEUE_SIZE > > > =
137142 Mutex :: new ( RefCell :: new ( SimpleQueue :: new ( ) ) ) ;
138143
139144#[ derive( Debug , Clone , Copy ) ]
@@ -174,6 +179,8 @@ pub enum WifiEvent {
174179#[ repr( i32 ) ]
175180#[ derive( Copy , Clone , Debug , PartialEq , Eq , FromPrimitive ) ]
176181pub enum InternalWifiError {
182+ ///Out of memory
183+ EspErrNoMem = 0x101 ,
177184 ///Invalid argument
178185 EspErrInvalidArg = 0x102 ,
179186 ///WiFi driver was not installed by esp_wifi_init */
@@ -528,19 +535,19 @@ static mut G_CONFIG: wifi_init_config_t = wifi_init_config_t {
528535 sha256_vector : None ,
529536 crc32 : None ,
530537 } ,
531- static_rx_buf_num : 10 ,
532- dynamic_rx_buf_num : 32 ,
533- tx_buf_type : 1 , // offset 0x78
534- static_tx_buf_num : 0 ,
535- dynamic_tx_buf_num : 32 ,
538+ static_rx_buf_num : crate :: CONFIG . static_rx_buf_num as i32 ,
539+ dynamic_rx_buf_num : crate :: CONFIG . dynamic_rx_buf_num as i32 ,
540+ tx_buf_type : 1 ,
541+ static_tx_buf_num : crate :: CONFIG . static_tx_buf_num as i32 ,
542+ dynamic_tx_buf_num : crate :: CONFIG . dynamic_tx_buf_num as i32 ,
536543 cache_tx_buf_num : 0 ,
537544 csi_enable : 1 ,
538- ampdu_rx_enable : 0 ,
539- ampdu_tx_enable : 0 ,
540- amsdu_tx_enable : 0 ,
545+ ampdu_rx_enable : crate :: CONFIG . ampdu_rx_enable as i32 ,
546+ ampdu_tx_enable : crate :: CONFIG . ampdu_tx_enable as i32 ,
547+ amsdu_tx_enable : crate :: CONFIG . amsdu_tx_enable as i32 ,
541548 nvs_enable : 0 ,
542549 nano_enable : 0 ,
543- rx_ba_win : 6 ,
550+ rx_ba_win : crate :: CONFIG . rx_ba_win as i32 ,
544551 wifi_task_core_id : 0 ,
545552 beacon_max_len : 752 ,
546553 mgmt_sbuf_num : 32 ,
@@ -608,23 +615,26 @@ unsafe extern "C" fn recv_cb(
608615 len : u16 ,
609616 eb : * mut crate :: binary:: c_types:: c_void ,
610617) -> esp_err_t {
611- critical_section:: with ( |cs| {
618+ let src = core:: slice:: from_raw_parts_mut ( buffer as * mut u8 , len as usize ) ;
619+ let packet = DataFrame :: from_bytes ( src) ;
620+
621+ let res = critical_section:: with ( |cs| {
612622 let mut queue = DATA_QUEUE_RX . borrow_ref_mut ( cs) ;
613623 if !queue. is_full ( ) {
614- let src = core:: slice:: from_raw_parts_mut ( buffer as * mut u8 , len as usize ) ;
615- let packet = DataFrame :: from_bytes ( src) ;
616624 queue. enqueue ( packet) . unwrap ( ) ;
617- esp_wifi_internal_free_rx_buffer ( eb) ;
618625
619626 #[ cfg( feature = "embassy-net" ) ]
620627 embassy:: RECEIVE_WAKER . wake ( ) ;
621628
622629 0
623630 } else {
624- esp_wifi_internal_free_rx_buffer ( eb ) ;
631+ log :: error! ( "RX QUEUE FULL" ) ;
625632 1
626633 }
627- } )
634+ } ) ;
635+ esp_wifi_internal_free_rx_buffer ( eb) ;
636+
637+ res
628638}
629639
630640#[ ram]
@@ -941,6 +951,7 @@ impl<'d> Device for WifiDevice<'d> {
941951 if !tx. is_full ( ) {
942952 Some ( WifiTxToken :: default ( ) )
943953 } else {
954+ log:: warn!( "no Tx token available" ) ;
944955 None
945956 }
946957 } )
@@ -949,7 +960,7 @@ impl<'d> Device for WifiDevice<'d> {
949960 fn capabilities ( & self ) -> smoltcp:: phy:: DeviceCapabilities {
950961 let mut caps = DeviceCapabilities :: default ( ) ;
951962 caps. max_transmission_unit = MTU ;
952- caps. max_burst_size = Some ( 1 ) ;
963+ caps. max_burst_size = Some ( crate :: CONFIG . max_burst_size ) ;
953964 caps
954965 }
955966}
0 commit comments