@@ -25,7 +25,7 @@ static void _getHostByNameCBK(const char *name, const ip_addr_t *ipaddr, void *c
25
25
26
26
#ifdef LWIP_USE_TIMER
27
27
static void timer_cb (timer_callback_args_t * arg);
28
- #endif
28
+ #endif // LWIP_USE_TIMER
29
29
30
30
// Custom Pbuf definition used to handle RX zero copy
31
31
// TODO Move this in a separate file (understand if it is required)
@@ -40,16 +40,13 @@ static void zerocopy_pbuf_mem_free(struct pbuf *p) {
40
40
// SYS_ARCH_DECL_PROTECT(zerocopy_pbuf_free);
41
41
zerocopy_pbuf_t * zcpbuf = (zerocopy_pbuf_t *) p;
42
42
43
- // arduino::lock();
44
43
// SYS_ARCH_PROTECT(zerocopy_pbuf_free);
45
44
46
45
// FIXME pbufs may be allocated in a different memory pool, deallocate them accordingly
47
46
zcpbuf->buffer_free (zcpbuf->buffer );
48
47
zcpbuf->buffer = nullptr ;
49
48
mem_free (zcpbuf); // TODO understand if pbuf_free deletes the pbuf
50
49
// SYS_ARCH_UNPROTECT(zerocopy_pbuf_free);
51
-
52
- // arduino::unlock();
53
50
}
54
51
55
52
static inline zerocopy_pbuf_t * get_zerocopy_pbuf (uint8_t *buffer, uint32_t size, void (*buffer_free)(void *) = mem_free) {
@@ -512,7 +509,6 @@ err_t CEth::output(struct netif* ni, struct pbuf* p) {
512
509
513
510
void CEth::consume_callback (uint8_t * buffer, uint32_t len) {
514
511
// TODO understand if this callback can be moved into the base class
515
- // arduino::lock();
516
512
517
513
const uint16_t trimmed_size = len;
518
514
@@ -536,7 +532,6 @@ void CEth::consume_callback(uint8_t* buffer, uint32_t len) {
536
532
} else {
537
533
// NETIF_STATS_INCREMENT_RX_BYTES(this->stats, p->len);
538
534
}
539
- // arduino::unlock();
540
535
}
541
536
542
537
/* ########################################################################## */
@@ -556,7 +551,6 @@ int CWifiStation::begin(const IPAddress &ip, const IPAddress &nm, const IPAddres
556
551
int res = 0 ;
557
552
int time_num = 0 ;
558
553
559
- // arduino::lock();
560
554
CEspControl::getInstance ().listenForStationDisconnectEvent ([this ] (CCtrlMsgWrapper *resp) -> int {
561
555
netif_set_link_down (&this ->ni );
562
556
return ESP_CONTROL_OK;
@@ -578,10 +572,12 @@ int CWifiStation::begin(const IPAddress &ip, const IPAddress &nm, const IPAddres
578
572
time_num++;
579
573
}
580
574
575
+ CLwipIf::getInstance ().sync_timer ();
581
576
res = CEspControl::getInstance ().setWifiMode (WIFI_MODE_STA);
577
+ CLwipIf::getInstance ().enable_timer ();
578
+
582
579
CNetIf::begin (ip, nm, gw);
583
580
exit:
584
- // arduino::unlock();
585
581
return res;
586
582
}
587
583
@@ -590,8 +586,6 @@ int CWifiStation::connectToAP(const char* ssid, const char *passphrase) {
590
586
int rv = ESP_CONTROL_CTRL_ERROR; // FIXME this should be set with an error meaning AP not found
591
587
bool found = false ;
592
588
int8_t best_index = -1 ; // this index is used to find the ap with the best rssi
593
- // AccessPoint_t* best_matching_ap;
594
- // arduino::lock();
595
589
596
590
if ((rv=this ->scanForAp ()) != WL_SCAN_COMPLETED) {
597
591
goto exit;
@@ -606,62 +600,60 @@ int CWifiStation::connectToAP(const char* ssid, const char *passphrase) {
606
600
}
607
601
}
608
602
if (best_index != -1 ) {
609
- // memset(ap.ssid, 0x00, SSID_LENGTH); // I shouldn't need to zero the ssid string pointer
610
603
strncpy ((char *)ap.ssid , ssid, SSID_LENGTH);
611
- // memcpy(ap.ssid, access_points[best_index].ssid, SSID_LENGTH);
612
604
613
- // memset(ap.pwd, 0x00, PASSWORD_LENGTH);
614
605
if (passphrase != nullptr ) {
615
606
auto slen = strlen (passphrase)+1 ;
616
607
strncpy ((char *)ap.pwd , passphrase, (slen < PASSWORD_LENGTH) ? slen : PASSWORD_LENGTH);
617
- // memcpy(ap.pwd, passphrase, (slen < PASSWORD_LENGTH) ? slen : PASSWORD_LENGTH);
618
608
} else {
619
- // memset(ap.pwd, 0x00, PASSWORD_LENGTH);
620
609
ap.pwd [0 ] = ' \0 ' ;
621
610
}
622
611
623
612
memset (ap.bssid , 0x00 , BSSID_LENGTH);
624
613
memcpy (ap.bssid , access_points[best_index].bssid , BSSID_LENGTH);
625
614
626
- // arduino::lock();
627
- CEspControl::getInstance ().communicateWithEsp ();
628
-
615
+ CLwipIf::getInstance ().sync_timer ();
629
616
rv=CEspControl::getInstance ().connectAccessPoint (ap);
630
- // arduino::unlock();
631
617
632
618
if (rv == ESP_CONTROL_OK) {
633
619
CEspControl::getInstance ().getAccessPointConfig (access_point_cfg);
634
620
635
621
netif_set_link_up (&this ->ni );
636
622
}
637
- // arduino::unlock ();
623
+ CLwipIf::getInstance (). enable_timer ();
638
624
}
639
625
640
626
exit:
641
- // arduino::unlock();
642
-
643
627
return rv;
644
628
}
645
629
646
630
int CWifiStation::scanForAp () {
647
- // arduino::lock();
648
631
access_points.clear ();
649
632
633
+ CLwipIf::getInstance ().sync_timer ();
634
+
650
635
int res = CEspControl::getInstance ().getAccessPointScanList (access_points);
636
+ CLwipIf::getInstance ().enable_timer ();
637
+
651
638
if (res == ESP_CONTROL_OK) {
652
639
res = WL_SCAN_COMPLETED;
653
640
} else {
654
641
res = WL_NO_SSID_AVAIL;
655
642
}
656
643
657
- // arduino::unlock();
658
644
659
645
return res;
660
646
}
661
647
662
648
// disconnect
663
649
int CWifiStation::disconnectFromAp () {
664
- return CEspControl::getInstance ().disconnectAccessPoint ();
650
+ CLwipIf::getInstance ().sync_timer ();
651
+
652
+ auto res = CEspControl::getInstance ().disconnectAccessPoint ();
653
+
654
+ CLwipIf::getInstance ().enable_timer ();
655
+
656
+ return res;
665
657
}
666
658
667
659
err_t CWifiStation::init (struct netif * ni) {
@@ -698,7 +690,6 @@ err_t CWifiStation::output(struct netif* _ni, struct pbuf* p) {
698
690
// NETIF_STATS_INCREMENT_TX_TRANSMIT_CALLS(this->stats);
699
691
// NETIF_STATS_TX_TIME_START(this->stats);
700
692
701
- // arduino::lock();
702
693
// p may be a chain of pbufs
703
694
if (p->next != nullptr ) {
704
695
buf = (uint8_t *) malloc (size*sizeof (uint8_t ));
@@ -731,7 +722,6 @@ err_t CWifiStation::output(struct netif* _ni, struct pbuf* p) {
731
722
if (p->next != nullptr && buf != nullptr ) {
732
723
free (buf);
733
724
}
734
- // arduino::unlock();
735
725
return errval;
736
726
}
737
727
@@ -745,7 +735,6 @@ void CWifiStation::task() {
745
735
struct pbuf * p = nullptr ;
746
736
747
737
// NETIF_STATS_RX_TIME_START(this->stats);
748
- // arduino::lock();
749
738
// TODO do not perform this when not connected to an AP
750
739
if (hw_init) {
751
740
CEspControl::getInstance ().communicateWithEsp ();
@@ -779,7 +768,6 @@ void CWifiStation::task() {
779
768
buffer = CEspControl::getInstance ().getStationRx (if_num, dim);
780
769
}
781
770
// NETIF_STATS_RX_TIME_AVERAGE(this->stats);
782
- // arduino::unlock();
783
771
}
784
772
785
773
// void CWifiStation::consume_callback(uint8_t* buffer, uint32_t len) {
@@ -877,7 +865,6 @@ int CWifiSoftAp::begin(const IPAddress &ip, const IPAddress &nm, const IPAddress
877
865
int res = 0 ;
878
866
int time_num = 0 ;
879
867
880
- // arduino::lock();
881
868
CEspControl::getInstance ().listenForInitEvent ([this ] (CCtrlMsgWrapper *resp) -> int {
882
869
// Serial.println("init");
883
870
this ->hw_init = true ;
@@ -895,21 +882,23 @@ int CWifiSoftAp::begin(const IPAddress &ip, const IPAddress &nm, const IPAddress
895
882
time_num++;
896
883
}
897
884
885
+ CLwipIf::getInstance ().sync_timer ();
898
886
res = CEspControl::getInstance ().setWifiMode (WIFI_MODE_AP);
887
+ CLwipIf::getInstance ().enable_timer ();
899
888
900
889
CNetIf::begin (
901
890
default_dhcp_server_ip,
902
891
default_nm,
903
892
default_dhcp_server_ip
904
893
);
905
894
exit:
906
- // arduino::unlock();
907
895
return res;
908
896
}
909
897
910
898
// TODO scan the other access point first and then set the channel if 0
911
899
// TODO there are requirements for ssid and password
912
900
int CWifiSoftAp::startSoftAp (const char * ssid, const char * passphrase, uint8_t channel) {
901
+ CLwipIf::getInstance ().sync_timer ();
913
902
SoftApCfg_t cfg;
914
903
915
904
strncpy ((char *)cfg.ssid , ssid, SSID_LENGTH);
@@ -942,7 +931,7 @@ int CWifiSoftAp::startSoftAp(const char* ssid, const char* passphrase, uint8_t c
942
931
// wifi_status = WL_AP_FAILED;
943
932
}
944
933
945
-
934
+ CLwipIf::getInstance (). enable_timer ();
946
935
return rv;
947
936
}
948
937
@@ -980,7 +969,6 @@ err_t CWifiSoftAp::output(struct netif* _ni, struct pbuf* p) {
980
969
// NETIF_STATS_INCREMENT_TX_TRANSMIT_CALLS(this->stats);
981
970
// NETIF_STATS_TX_TIME_START(this->stats);
982
971
983
- // arduino::lock();
984
972
// p may be a chain of pbufs
985
973
if (p->next != nullptr ) {
986
974
buf = (uint8_t *) malloc (size*sizeof (uint8_t ));
@@ -1013,7 +1001,6 @@ err_t CWifiSoftAp::output(struct netif* _ni, struct pbuf* p) {
1013
1001
if (p->next != nullptr && buf != nullptr ) {
1014
1002
free (buf);
1015
1003
}
1016
- // arduino::unlock();
1017
1004
return errval;
1018
1005
}
1019
1006
@@ -1030,7 +1017,6 @@ void CWifiSoftAp::task() {
1030
1017
struct pbuf * p = nullptr ;
1031
1018
1032
1019
// NETIF_STATS_RX_TIME_START(this->stats);
1033
- // arduino::lock();
1034
1020
// TODO do not perform this when not connected to an AP
1035
1021
if (hw_init) {
1036
1022
CEspControl::getInstance ().communicateWithEsp ();
@@ -1065,7 +1051,6 @@ void CWifiSoftAp::task() {
1065
1051
buffer = CEspControl::getInstance ().getStationRx (if_num, dim);
1066
1052
}
1067
1053
// NETIF_STATS_RX_TIME_AVERAGE(this->stats);
1068
- // arduino::unlock();
1069
1054
}
1070
1055
1071
1056
const char * CWifiSoftAp::getSSID () {
@@ -1086,11 +1071,19 @@ uint8_t CWifiSoftAp::getChannel() {
1086
1071
}
1087
1072
1088
1073
int CWifiSoftAp::setLowPowerMode () {
1089
- return CEspControl::getInstance ().setPowerSaveMode (1 );
1074
+ CLwipIf::getInstance ().sync_timer ();
1075
+ auto res = CEspControl::getInstance ().setPowerSaveMode (1 );
1076
+ CLwipIf::getInstance ().enable_timer ();
1077
+
1078
+ return res;
1090
1079
}
1091
1080
1092
1081
int CWifiSoftAp::resetLowPowerMode () {
1093
- return CEspControl::getInstance ().setPowerSaveMode (1 );
1082
+ CLwipIf::getInstance ().sync_timer ();
1083
+ auto res = CEspControl::getInstance ().setPowerSaveMode (1 );
1084
+ CLwipIf::getInstance ().enable_timer ();
1085
+
1086
+ return res;
1094
1087
}
1095
1088
1096
1089
/* ##########################################################################
0 commit comments