Skip to content

Commit

Permalink
tried reducing dma reconfiguration over head
Browse files Browse the repository at this point in the history
  • Loading branch information
sidd-kishan committed Jul 23, 2024
1 parent d4c2847 commit 251720d
Show file tree
Hide file tree
Showing 21 changed files with 58,819 additions and 58,823 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,4 @@ add_executable(${PROJECT_NAME} ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c ${CMAKE_CU

target_link_libraries(${PROJECT_NAME} PRIVATE pico_stdlib hardware_resets hardware_irq pico_lwip pico_multicore pico_cyw43_arch_none hardware_flash hardware_sync hardware_dma)
pico_add_extra_outputs(${PROJECT_NAME})
target_compile_definitions(${PROJECT_NAME} PRIVATE CYW43_SLEEP_CHECK_MS=1)
target_compile_definitions(${PROJECT_NAME} PRIVATE CYW43_SLEEP_CHECK_MS=3)
2 changes: 1 addition & 1 deletion build/CMakeCache.txt
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ PICO_BOOT_STAGE2_DIR:INTERNAL=/mnt/c/Users/siddk/Downloads/PicoPiFi/pico-sdk/src
PICO_CMAKE_PRELOAD_PLATFORM_DIR:INTERNAL=/mnt/c/Users/siddk/Downloads/PicoPiFi/pico-sdk/cmake/preload/platforms
PICO_CMAKE_PRELOAD_PLATFORM_FILE:INTERNAL=/mnt/c/Users/siddk/Downloads/PicoPiFi/pico-sdk/cmake/preload/platforms/rp2040.cmake
PICO_COMPILER_ASM:INTERNAL=/usr/bin/arm-none-eabi-gcc
PICO_DOXYGEN_EXCLUDE_PATHS:INTERNAL= /mnt/c/Users/siddk/Downloads/PicoPiFi/pico-sdk/src/rp2_common/cmsis /mnt/c/Users/siddk/Downloads/PicoPiFi/pico-sdk/src/rp2040/hardware_regs /mnt/c/Users/siddk/Downloads/PicoPiFi/pico-sdk/src/rp2_common/cmsis /mnt/c/Users/siddk/Downloads/PicoPiFi/pico-sdk/src/rp2040/hardware_regs /mnt/c/Users/siddk/Downloads/PicoPiFi/pico-sdk/src/rp2_common/cmsis /mnt/c/Users/siddk/Downloads/PicoPiFi/pico-sdk/src/rp2040/hardware_regs /mnt/c/Users/siddk/Downloads/PicoPiFi/pico-sdk/src/rp2_common/cmsis /mnt/c/Users/siddk/Downloads/PicoPiFi/pico-sdk/src/rp2040/hardware_regs /mnt/c/Users/siddk/Downloads/PicoPiFi/pico-sdk/src/rp2_common/cmsis /mnt/c/Users/siddk/Downloads/PicoPiFi/pico-sdk/src/rp2040/hardware_regs /mnt/c/Users/siddk/Downloads/PicoPiFi/pico-sdk/src/rp2_common/cmsis /mnt/c/Users/siddk/Downloads/PicoPiFi/pico-sdk/src/rp2040/hardware_regs /mnt/c/Users/siddk/Downloads/PicoPiFi/pico-sdk/src/rp2_common/cmsis /mnt/c/Users/siddk/Downloads/PicoPiFi/pico-sdk/src/rp2040/hardware_regs /mnt/c/Users/siddk/Downloads/PicoPiFi/pico-sdk/src/rp2_common/cmsis /mnt/c/Users/siddk/Downloads/PicoPiFi/pico-sdk/src/rp2040/hardware_regs
PICO_DOXYGEN_EXCLUDE_PATHS:INTERNAL= /mnt/c/Users/siddk/Downloads/PicoPiFi/pico-sdk/src/rp2_common/cmsis /mnt/c/Users/siddk/Downloads/PicoPiFi/pico-sdk/src/rp2040/hardware_regs /mnt/c/Users/siddk/Downloads/PicoPiFi/pico-sdk/src/rp2_common/cmsis /mnt/c/Users/siddk/Downloads/PicoPiFi/pico-sdk/src/rp2040/hardware_regs /mnt/c/Users/siddk/Downloads/PicoPiFi/pico-sdk/src/rp2_common/cmsis /mnt/c/Users/siddk/Downloads/PicoPiFi/pico-sdk/src/rp2040/hardware_regs /mnt/c/Users/siddk/Downloads/PicoPiFi/pico-sdk/src/rp2_common/cmsis /mnt/c/Users/siddk/Downloads/PicoPiFi/pico-sdk/src/rp2040/hardware_regs /mnt/c/Users/siddk/Downloads/PicoPiFi/pico-sdk/src/rp2_common/cmsis /mnt/c/Users/siddk/Downloads/PicoPiFi/pico-sdk/src/rp2040/hardware_regs /mnt/c/Users/siddk/Downloads/PicoPiFi/pico-sdk/src/rp2_common/cmsis /mnt/c/Users/siddk/Downloads/PicoPiFi/pico-sdk/src/rp2040/hardware_regs /mnt/c/Users/siddk/Downloads/PicoPiFi/pico-sdk/src/rp2_common/cmsis /mnt/c/Users/siddk/Downloads/PicoPiFi/pico-sdk/src/rp2040/hardware_regs /mnt/c/Users/siddk/Downloads/PicoPiFi/pico-sdk/src/rp2_common/cmsis /mnt/c/Users/siddk/Downloads/PicoPiFi/pico-sdk/src/rp2040/hardware_regs /mnt/c/Users/siddk/Downloads/PicoPiFi/pico-sdk/src/rp2_common/cmsis /mnt/c/Users/siddk/Downloads/PicoPiFi/pico-sdk/src/rp2040/hardware_regs /mnt/c/Users/siddk/Downloads/PicoPiFi/pico-sdk/src/rp2_common/cmsis /mnt/c/Users/siddk/Downloads/PicoPiFi/pico-sdk/src/rp2040/hardware_regs
PICO_DOXYGEN_PATHS:INTERNAL= /mnt/c/Users/siddk/Downloads/PicoPiFi/pico-sdk/src/common /mnt/c/Users/siddk/Downloads/PicoPiFi/pico-sdk/lib/cyw43-driver/src /mnt/c/Users/siddk/Downloads/PicoPiFi/pico-sdk/src/rp2_common /mnt/c/Users/siddk/Downloads/PicoPiFi/pico-sdk/src/rp2040
PICO_NO_HARDWARE:INTERNAL=0
PICO_ON_DEVICE:INTERNAL=1
Expand Down
Binary file not shown.
2 changes: 1 addition & 1 deletion build/CMakeFiles/PicoPiFi.dir/DependInfo.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ set(CMAKE_ASM_COMPILER_ID "GNU")
# Preprocessor definitions for this target.
set(CMAKE_TARGET_DEFINITIONS_ASM
"CYW43_LWIP=0"
"CYW43_SLEEP_CHECK_MS=1"
"CYW43_SLEEP_CHECK_MS=3"
"LIB_PICO_ASYNC_CONTEXT_THREADSAFE_BACKGROUND=1"
"LIB_PICO_BIT_OPS=1"
"LIB_PICO_BIT_OPS_PICO=1"
Expand Down
6 changes: 3 additions & 3 deletions build/CMakeFiles/PicoPiFi.dir/flags.make

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Binary file modified build/CMakeFiles/PicoPiFi.dir/src/main.c.obj
Binary file not shown.
Binary file modified build/CMakeFiles/PicoPiFi.dir/src/usbd_rndis.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.
75,734 changes: 37,843 additions & 37,891 deletions build/PicoPiFi.dis

Large diffs are not rendered by default.

Binary file modified build/PicoPiFi.elf
Binary file not shown.
2,652 changes: 1,333 additions & 1,319 deletions build/PicoPiFi.elf.map

Large diffs are not rendered by default.

39,161 changes: 19,574 additions & 19,587 deletions build/PicoPiFi.hex

Large diffs are not rendered by default.

Binary file modified build/PicoPiFi.uf2
Binary file not shown.
1 change: 1 addition & 0 deletions src/lwip.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ extern dma_channel_config align_cpy;
extern dma_channel_config align_cpy_tail;
extern dma_channel_config usb_cpy;

extern int dma_memset_0_flag, chan_flag, chan_2_flag, dma_usb_cpy_flag, dma_align_cpy_head_flag, dma_align_cpy_flag, dma_align_cpy_tail_flag;

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;
11 changes: 9 additions & 2 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,25 @@ int eth_frame_send_success;

int chan = 0;
dma_channel_config c;
int chan_flag = 0;
int chan_2 = 0;
dma_channel_config c_2;
int chan_2_flag = 0;
int dma_memset_0 = 0;
dma_channel_config memset_0;
int dma_memset_0_flag = 0;
int dma_align_cpy_head = 0;
dma_channel_config align_cpy_head;
int dma_align_cpy_head_flag = 0;
int dma_align_cpy = 0;
dma_channel_config align_cpy;
int dma_align_cpy_flag = 0;
int dma_align_cpy_tail = 0;
dma_channel_config align_cpy_tail;
int dma_align_cpy_tail_flag = 0;
int dma_usb_cpy = 0;
dma_channel_config usb_cpy;
int dma_usb_cpy_flag = 0;

void printline(int cdc,char string[],int len){
char buf[2048];
Expand Down Expand Up @@ -145,7 +152,7 @@ void core1(){

int main(void)
{
set_sys_clock_khz(200000, true);
//set_sys_clock_khz(200000, true);
memset(wifi_configuration_last,0,450);
memset(wifi_configuration,0,450);
memcpy(wifi_configuration, flash_target_contents, sizeof(wifi_configuration));
Expand Down Expand Up @@ -176,7 +183,7 @@ int main(void)
channel_config_set_write_increment(&c, true);

chan_2 = dma_claim_unused_channel(true);
dma_channel_set_irq0_enabled(chan_2, true);
//dma_channel_set_irq0_enabled(chan_2, true);

c_2 = dma_channel_get_default_config(chan_2);
channel_config_set_transfer_data_size(&c_2, DMA_SIZE_16);
Expand Down
26 changes: 18 additions & 8 deletions src/usbd_rndis.c
Original file line number Diff line number Diff line change
Expand Up @@ -506,14 +506,24 @@ int usbd_rndis_eth_tx(struct pbuf *p)
rndis_data_packet_t *hdr;
hdr = (rndis_data_packet_t *)g_rndis_tx_buffer;
uint16_t zerobuf[] = {0};
dma_channel_configure(
dma_memset_0, // Channel to be configured
&memset_0, // The configuration we just created
hdr,// The initial write address
zerobuf, // The initial read address
(sizeof(rndis_data_packet_t)/2)+1, // Number of transfers; in this case each is 1 byte.
true // Start immediately.
);
if(!dma_memset_0_flag){
dma_channel_configure(
dma_memset_0, // Channel to be configured
&memset_0, // The configuration we just created
hdr,// The initial write address
zerobuf, // The initial read address
(sizeof(rndis_data_packet_t)/2)+1, // Number of transfers; in this case each is 1 byte.
true // Start immediately.
);
dma_memset_0_flag = 1;
} else {
//dma_channel_start(dma_memset_0);
//dma_channel_transfer_from_buffer_now( dma_memset_0, zerobuf, (sizeof(rndis_data_packet_t)/2)+1);

dma_channel_set_read_addr(dma_memset_0, zerobuf, false);
dma_channel_set_write_addr(dma_memset_0, hdr, false);
dma_channel_set_trans_count(dma_memset_0, (sizeof(rndis_data_packet_t)%2==1)?((sizeof(rndis_data_packet_t)+1)/2):(sizeof(rndis_data_packet_t)/2), true);
}
if (g_usbd_rndis.link_status == NDIS_MEDIA_STATE_DISCONNECTED) {
return -USB_ERR_NOTCONN;
}
Expand Down
7 changes: 6 additions & 1 deletion src/wifi_tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ void cyw43_cb_process_ethernet(void *cb_data, int itf, size_t len, const uint8_t
transfer_2, // Number of transfers; in this case each is 1 byte.
true // Start immediately.
);
int ret = usbd_rndis_eth_tx(out_pkt_dma_2);
if (0 != ret) {
ret = ERR_BUF;
}
pbuf_free(out_pkt_dma_2);
} else {
out_pkt = pbuf_alloc(PBUF_RAW, len, PBUF_POOL);
out_pkt->payload = buf;
Expand All @@ -119,5 +124,5 @@ void dma_handler() {
ret = ERR_BUF;
}
pbuf_free(out_pkt_dma);
dma_hw->ints0 = 1u << chan;
dma_hw->ints0 = 1u << chan;
}
38 changes: 29 additions & 9 deletions usb_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ static inline void *usb_memcpy(void *dest, const void *src, size_t n)
leading_bytes = n;
}
//memcpy(d, s, leading_bytes);
if(!dma_align_cpy_head_flag){
dma_channel_configure(
dma_align_cpy_head, // Channel to be configured
&align_cpy_head, // The configuration we just created
Expand All @@ -205,6 +206,12 @@ static inline void *usb_memcpy(void *dest, const void *src, size_t n)
leading_bytes, // Number of transfers; in this case each is 1 byte.
true // Start immediately.
);
dma_align_cpy_head_flag = 1;
} else {
dma_channel_set_read_addr(dma_align_cpy_head, s, false);
dma_channel_set_write_addr(dma_align_cpy_head, d, false);
dma_channel_set_trans_count(dma_align_cpy_head,leading_bytes, true);
}
d += leading_bytes;
s += leading_bytes;
n -= leading_bytes;
Expand All @@ -218,15 +225,21 @@ static inline void *usb_memcpy(void *dest, const void *src, size_t n)
for (size_t i = 0; i < word_count; ++i) {
dw[i] = sw[i];
}*/
dma_channel_configure(
dma_align_cpy, // Channel to be configured
&align_cpy, // The configuration we just created
dw,// The initial write address
sw, // The initial read address
word_count, // Number of transfers; in this case each is 1 byte.
true // Start immediately.
);

if(!dma_align_cpy_flag){
dma_channel_configure(
dma_align_cpy, // Channel to be configured
&align_cpy, // The configuration we just created
dw,// The initial write address
sw, // The initial read address
word_count, // Number of transfers; in this case each is 1 byte.
true // Start immediately.
);
dma_align_cpy_flag = 1;
} else {
dma_channel_set_read_addr(dma_align_cpy, sw, false);
dma_channel_set_write_addr(dma_align_cpy, dw, false);
dma_channel_set_trans_count(dma_align_cpy,word_count, true);
}

// Update pointers and remaining byte count
d = (char *)(dw + word_count);
Expand All @@ -236,6 +249,7 @@ static inline void *usb_memcpy(void *dest, const void *src, size_t n)
// Copy remaining bytes
if (n > 0) {
//memcpy(d, s, n);
if(!dma_align_cpy_tail_flag){
dma_channel_configure(
dma_align_cpy_tail, // Channel to be configured
&align_cpy_tail, // The configuration we just created
Expand All @@ -244,6 +258,12 @@ static inline void *usb_memcpy(void *dest, const void *src, size_t n)
n, // Number of transfers; in this case each is 1 byte.
true // Start immediately.
);
dma_align_cpy_tail_flag = 1;
} else {
dma_channel_set_read_addr(dma_align_cpy_tail, s, false);
dma_channel_set_write_addr(dma_align_cpy_tail, d, false);
dma_channel_set_trans_count(dma_align_cpy_tail,n, true);
}
}
//dma_channel_wait_for_finish_blocking(dma_align_cpy);

Expand Down

0 comments on commit 251720d

Please sign in to comment.