1·一个esp32作为wifi的发送,一个esp32作为wifi的接收,采用esp_80211_tx。采用80211g,每一包payload大小960bytes。
2·发送不停的地发送数据包,每60包内,数据包与数据包之间没有时间间隔。
3·接收端有一个sdio_transfer_task。接收端每接收到一包,进入wifi_sniffer_packet_handler,通知sdio_transfer_task。sdio_transfer_task向sdio从设备写入两个block。接受端esp32作为接收端主设备。
4·wifi task分配到cpu1 ,sdio_transfer_task分配到cpu0。
5·IDF:基于IDFv3.1
6·如果wifi接收与sdio没有同时工作,那么丢包率很低
代码节选:
1·接收端代码:
- void wifi_sniffer_packet_handler(void* buff, wifi_promiscuous_pkt_type_t type)
- {
- if (type != WIFI_PKT_DATA)
- return;
- const wifi_promiscuous_pkt_t *ppkt = (wifi_promiscuous_pkt_t *)buff;
- const wifi_ieee80211_packet_t *ipkt = (wifi_ieee80211_packet_t *)ppkt->payload;
- const wifi_ieee80211_mac_hdr_t *hdr = &ipkt->hdr;
- if(!((hdr->addr2[4]==0x00)&&(hdr->addr2[5]==0x00)))
- {
- return ;
- }
- if(NORMALSENDPACKETS==ipkt->payload[0])//it means it is not the retrans packet
- {
- pack_count++;
- register uint32_t i=0;
- register uint8_t pac_seq=ipkt->payload[1];
- if(pac_seq==59)
- {
- ets_printf("cb=%d\n",60-pack_count);
- pack_count=0;
- }
- xEventGroupSetBits(frame_event_group,FRAME_RECEIVED_BIT);
- }
- }
- static void sdio_transfer_task(void *pvParameters)
- {
- while(true)
- {
- xEventGroupWaitBits(frame_event_group,FRAME_RECEIVED_BIT, pdTRUE, pdTRUE,portMAX_DELAY);
- uint8_t sdiotmp[1024]
- esp_err_t user_sdmmc_write_error=sdmmc_write_sectors(card,sdiotmp,1,2);
- if(user_sdmmc_write_error)
- {
- esp_restart();
- }
- }
- }
- int32_t user_esp_wifi_80211_tx(void * data,size_t datasize,uint32_t picture_count)
- {
- wifi_internal_rate_t rate;
- // struct timeval test_promis_start;
- // struct timeval test_promis_end;
- // struct timeval promis_result_time;
- int32_t fail_count=0;
- int pack_num=datasize/PACKSIZE;
- #ifdef CHANGERTATE
- rate.fix_rate = RATE_MCS7;
- esp_wifi_internal_set_rate(100, 1, 4, &rate);
- #endif
- for(int i=0;i<pack_num;i++)
- {
- packetH[DATAOFFSET]=NORMALSENDPACKETS;
- packetH[DATAOFFSET+1]=i;
- memcpy(packetH+DATAOFFSET+2,data+i*PACKSIZE,PACKSIZE);
- int result = esp_wifi_80211_tx(WIFI_MODE_NULL, packetH, sizeof(packetH), true);
- if(result)
- {
- fail_count++;
- }
- }
- return fail_count;
- }
问题:
1·sdio与wifi接收同时工作,会增加wifi接收的丢包率吗?
2·是不是因为sdio与wifi接收同时工作,sdio输出20mhz的时钟,影响了wifi的接收灵敏度吗?
3·wifi代码不开源,wifi_sniffer_packet_handler是在wifi接收中断中执行的吗?
4·wifi中断优先级比sdio_host中断的优先级要高吗?