From 1ba3d9412ddc83829844e6525b4923276cd01256 Mon Sep 17 00:00:00 2001 From: Ulrich Mohr Date: Thu, 28 Sep 2023 22:52:18 +0200 Subject: [PATCH] tftp demo on uart0 (NSFZed) --- CMakeLists.txt | 1 + bsp_z7/ps7_cortexa9_0/include/xparameters.h | 4 +- .../libsrc/standalone/src/outbyte.c | 2 +- mission/testIp.cpp | 51 +++++++++++++++++-- 4 files changed, 51 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 73607d2..5542c88 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -56,6 +56,7 @@ set(lwip_SRCS ${lwipapi_SRCS} ${lwipnetif_SRCS} ${LWIP_DIR}/src/netif/slipif.c + ${LWIP_DIR}/src/apps/tftp/tftp.c ${LWIP_DIR}/contrib/ports/freertos/sys_arch.c ) add_library(lwip ${lwip_SRCS}) diff --git a/bsp_z7/ps7_cortexa9_0/include/xparameters.h b/bsp_z7/ps7_cortexa9_0/include/xparameters.h index 03046ce..8b0d2fa 100644 --- a/bsp_z7/ps7_cortexa9_0/include/xparameters.h +++ b/bsp_z7/ps7_cortexa9_0/include/xparameters.h @@ -24,8 +24,8 @@ #include "xparameters_ps.h" -#define STDIN_BASEADDRESS XPS_UART1_BASEADDR -#define STDOUT_BASEADDRESS XPS_UART1_BASEADDR +#define STDIN_BASEADDRESS XPS_UART0_BASEADDR +#define STDOUT_BASEADDRESS XPS_UART0_BASEADDR /******************************************************************/ diff --git a/bsp_z7/ps7_cortexa9_0/libsrc/standalone/src/outbyte.c b/bsp_z7/ps7_cortexa9_0/libsrc/standalone/src/outbyte.c index db60e6d..c7a3b12 100644 --- a/bsp_z7/ps7_cortexa9_0/libsrc/standalone/src/outbyte.c +++ b/bsp_z7/ps7_cortexa9_0/libsrc/standalone/src/outbyte.c @@ -15,5 +15,5 @@ void outbyte(char c); #endif void outbyte(char c) { - XUartPs_SendByte(STDOUT_BASEADDRESS, c); + //XUartPs_SendByte(STDOUT_BASEADDRESS, c); } diff --git a/mission/testIp.cpp b/mission/testIp.cpp index 1726787..c2af94e 100644 --- a/mission/testIp.cpp +++ b/mission/testIp.cpp @@ -12,11 +12,54 @@ #include #include + + #undef XUARTPS_IXR_RXOVR #define XUARTPS_IXR_RXOVR 0x00000020U /**< Rx Overrun error interrupt */ #define XUARTPS_IXR_RTRIG 0x00000001U /**< RX FIFO trigger interrupt. */ +#define UART_INT_NR XPAR_XUARTPS_0_INTR + extern "C" { + #include + + static void* +tftp_open(const char* fname, const char* mode, u8_t is_write) +{ + LWIP_UNUSED_ARG(mode); + return (void*)13; +} + +static void +tftp_close(void* handle) +{} + +static int +tftp_read(void* handle, void* buf, int bytes) +{ + memset(buf, 'x', bytes); + return bytes - 60; +} + +static int +tftp_write(void* handle, struct pbuf* p) +{ + return 0; +} + +/* For TFTP client only */ +static void +tftp_error(void* handle, int err, const char* msg, int size) +{} + +static const struct tftp_context tftp = { + tftp_open, + tftp_close, + tftp_read, + tftp_write, + tftp_error +}; + void slipif_rxbyte_input(struct netif *netif, u8_t c); void myInitDone(void *arg) { puts("init done"); } @@ -27,8 +70,6 @@ extern XScuGic xInterruptController; /* Interrupt controller instance */ /** this is based on XUartPs_InterruptHandler() in xuartps_intr.c*/ void handleUARTInt(void *) { - XUartPs_SendByte(STDOUT_BASEADDRESS, 'I'); - u32 IsrStatus; /* @@ -87,7 +128,7 @@ void testIp() { /* Install the UART Interrupt handler. */ BaseType_t xStatus = - XScuGic_Connect(&xInterruptController, XPAR_XUARTPS_1_INTR, + XScuGic_Connect(&xInterruptController, UART_INT_NR, (Xil_ExceptionHandler)handleUARTInt, nullptr); configASSERT(xStatus == XST_SUCCESS); (void)xStatus; /* Remove compiler warning if configASSERT() is not defined. */ @@ -106,7 +147,7 @@ void testIp() { XUartPs_WriteReg(STDIN_BASEADDRESS, XUARTPS_IDR_OFFSET, (~mask)); /* Enable the interrupt for the UART1 in the interrupt controller. */ - XScuGic_Enable(&xInterruptController, XPAR_XUARTPS_1_INTR); + XScuGic_Enable(&xInterruptController, UART_INT_NR); // Start task to forwad packets from ISR to IP Task xTaskCreate(forwardPackets, /* The function that implements the task. */ @@ -118,6 +159,8 @@ void testIp() { 4, /* The priority assigned to the task. */ nullptr); + tftp_init_server(&tftp); + puts("socket"); int serverSocket = socket(AF_INET, SOCK_DGRAM, 0);