Skip to content

Commit

Permalink
library update added DMA chain
Browse files Browse the repository at this point in the history
PicoPiFi$ git submodule status
+643578e5bebd82b11bcad14e700ca9c2d7abc424 CherryUSB (v1.3.1-17-g643578e)
 6a7db34ff63345a7badec79ebea3aaef1712f374 pico-sdk (1.5.1)
PicoPiFi/pico-sdk/lib$ git submodule status
+2b49e57bd1fae85ac32ac1f41cdb7c794de335f6 btstack (v1.6.1)
+1d2227bca200e13c1d6a630032d5f6d7fca69fef cyw43-driver (v1.0.3-7-g1d2227b)
+73fcf72792a926a4e0ac8b656b29bff70552d927 lwip (STABLE-2_2_0_RELEASE-82-g73fcf727)
+cb854d5d19e05339448afb03839bee7f7e3ecd23 mbedtls (v3.6.0-607-gcb854d5d1)
+1ba88ff3ac939bbefb90e1fb2a7c4eb9a0c657f3 tinyusb (0.16.0-857-g1ba88ff3a)
  • Loading branch information
sidd-kishan committed Jul 16, 2024
1 parent 874ea20 commit f287b2b
Show file tree
Hide file tree
Showing 12 changed files with 59,332 additions and 59,101 deletions.
Binary file modified build/CMakeFiles/PicoPiFi.dir/src/main.c.obj
Binary file not shown.
Binary file modified build/CMakeFiles/PicoPiFi.dir/src/wifi_tx.c.obj
Binary file not shown.
Binary file modified build/PicoPiFi.bin
Binary file not shown.
76,824 changes: 38,483 additions & 38,341 deletions build/PicoPiFi.dis

Large diffs are not rendered by default.

Binary file modified build/PicoPiFi.elf
Binary file not shown.
2,342 changes: 1,179 additions & 1,163 deletions build/PicoPiFi.elf.map

Large diffs are not rendered by default.

39,141 changes: 19,581 additions & 19,560 deletions build/PicoPiFi.hex

Large diffs are not rendered by default.

Binary file modified build/PicoPiFi.uf2
Binary file not shown.
6 changes: 5 additions & 1 deletion src/lwip.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "hardware/watchdog.h"
#include "pico/bootrom.h"
#include "hardware/dma.h"
#include "hardware/irq.h"

// We're going to erase and reprogram a region 256k from the start of flash.
// Once done, we can access this at XIP_BASE + 256k.
Expand All @@ -21,7 +22,10 @@ extern struct pbuf *out_pkt;
extern bool link_up;
static void lwip_service_traffic(void);
void printline(int cdc,char string[],int len);
//extern int chan;
void dma_handler();
void dma_handler_2();
extern int chan;
extern int chan_2;

extern char connect_ssid[190], connect_ssid_decode[95], connect_password[190], connect_password_decode[95], retry_ms[6], enc_type[1], wifi_configuration[450], wifi_configuration_last[450];
extern int wifi_congfig_len;
18 changes: 16 additions & 2 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ uint8_t rndis_mac[6] = { 0x20, 0x89, 0x84, 0x6A, 0x96, 0xAA };
int wifi_congfig_len=0;
int eth_frame_send_success;

//int chan = 0;
int chan = 0;
int chan_2 = 0;

void printline(int cdc,char string[],int len){
char buf[2048];
Expand Down Expand Up @@ -150,7 +151,20 @@ int main(void)
absolute_time_t scan_time = nil_time;
bool scan_in_progress = false;
next_wifi_try = nil_time;
//chan = dma_claim_unused_channel(false);
chan = dma_claim_unused_channel(false);
dma_channel_set_irq0_enabled(chan, true);

// Configure the processor to run dma_handler() when DMA IRQ 0 is asserted
irq_set_exclusive_handler(DMA_IRQ_0, dma_handler);
irq_set_enabled(DMA_IRQ_0, true);

chan_2 = dma_claim_unused_channel(false);
dma_channel_set_irq1_enabled(chan_2, true);

// Configure the processor to run dma_handler() when DMA IRQ 0 is asserted
irq_set_exclusive_handler(DMA_IRQ_1, dma_handler_2);
irq_set_enabled(DMA_IRQ_1, true);

while (1) {
if (!link_up) {
if (absolute_time_diff_us(get_absolute_time(), scan_time) < 0) {
Expand Down
100 changes: 67 additions & 33 deletions src/wifi_tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include "usbd_rndis.h"

struct pbuf *out_pkt;
struct pbuf *out_pkt_dma;
struct pbuf *out_pkt_dma_2;
bool link_up = false;


Expand Down Expand Up @@ -71,38 +73,70 @@ void cyw43_cb_tcpip_set_link_down(cyw43_t *self, int itf) {
}

void cyw43_cb_process_ethernet(void *cb_data, int itf, size_t len, const uint8_t *buf) {
//int chan = dma_claim_unused_channel(true);
//if (len <= 1600) {
out_pkt = pbuf_alloc(PBUF_RAW, len, PBUF_POOL);
//memcpy(out_pkt->payload, buf, len);
//pbuf_take(out_pkt, buf, len);
/*
int transfer = (len%2==0)?(len/2):((len+1)/2);
dma_channel_config c = dma_channel_get_default_config(chan);
channel_config_set_transfer_data_size(&c, DMA_SIZE_16);
channel_config_set_read_increment(&c, true);
channel_config_set_write_increment(&c, true);
/*if((dma_hw->ch[chan].ctrl_trig & DMA_CH0_CTRL_TRIG_BUSY_BITS)&&(dma_hw->ch[chan_2].ctrl_trig & DMA_CH0_CTRL_TRIG_BUSY_BITS)){
} else*/ if(!(dma_hw->ch[chan].ctrl_trig & DMA_CH0_CTRL_TRIG_BUSY_BITS)) {
out_pkt_dma = pbuf_alloc(PBUF_RAW, len, PBUF_POOL);
//memcpy(out_pkt->payload, buf, len);
//pbuf_take(out_pkt, buf, len);
int transfer = (len%2==0)?(len/2):((len+1)/2);
dma_channel_config c = dma_channel_get_default_config(chan);
channel_config_set_transfer_data_size(&c, DMA_SIZE_16);
channel_config_set_read_increment(&c, true);
channel_config_set_write_increment(&c, true);

dma_channel_configure(
chan, // Channel to be configured
&c, // The configuration we just created
out_pkt->payload,// The initial write address
buf, // The initial read address
transfer, // Number of transfers; in this case each is 1 byte.
true // Start immediately.
);
*/
out_pkt->payload = buf;
int ret = usbd_rndis_eth_tx(out_pkt);
if (0 != ret) {
ret = ERR_BUF;
}
// We could choose to go and do something else whilst the DMA is doing its
// thing. In this case the processor has nothing else to do, so we just
// wait for the DMA to finish.
//dma_channel_wait_for_finish_blocking(chan);

pbuf_free(out_pkt);
//out_pkt = NULL;
//}
dma_channel_configure(
chan, // Channel to be configured
&c, // The configuration we just created
out_pkt_dma->payload,// The initial write address
buf, // The initial read address
transfer, // Number of transfers; in this case each is 1 byte.
true // Start immediately.
);
}
else if(!(dma_hw->ch[chan_2].ctrl_trig & DMA_CH0_CTRL_TRIG_BUSY_BITS)){
out_pkt_dma_2 = pbuf_alloc(PBUF_RAW, len, PBUF_POOL);
//memcpy(out_pkt->payload, buf, len);
//pbuf_take(out_pkt, buf, len);
int transfer_2 = (len%2==0)?(len/2):((len+1)/2);
dma_channel_config c_2 = dma_channel_get_default_config(chan_2);
channel_config_set_transfer_data_size(&c_2, DMA_SIZE_16);
channel_config_set_read_increment(&c_2, true);
channel_config_set_write_increment(&c_2, true);

dma_channel_configure(
chan_2, // Channel to be configured
&c_2, // The configuration we just created
out_pkt_dma_2->payload,// The initial write address
buf, // The initial read address
transfer_2, // Number of transfers; in this case each is 1 byte.
true // Start immediately.
);
} else {
out_pkt = pbuf_alloc(PBUF_RAW, len, PBUF_POOL);
out_pkt->payload = buf;
int ret = usbd_rndis_eth_tx(out_pkt);
//if (0 != ret) {
// ret = ERR_BUF;
//}
pbuf_free(out_pkt);
}
}

void dma_handler() {
int ret = usbd_rndis_eth_tx(out_pkt_dma);
if (0 != ret) {
ret = ERR_BUF;
}
pbuf_free(out_pkt_dma);
dma_hw->ints0 = 1u << chan;
}

void dma_handler_2() {
int ret = usbd_rndis_eth_tx(out_pkt_dma_2);
if (0 != ret) {
ret = ERR_BUF;
}
pbuf_free(out_pkt_dma_2);
dma_hw->ints1 = 1u << chan_2;
}

0 comments on commit f287b2b

Please sign in to comment.