forked from ROMEO/obsw
lwip without any alloc and sending and receiving UDP via slip
This commit is contained in:
@ -32,12 +32,8 @@
|
|||||||
#ifndef LWIP_LWIPOPTS_H
|
#ifndef LWIP_LWIPOPTS_H
|
||||||
#define LWIP_LWIPOPTS_H
|
#define LWIP_LWIPOPTS_H
|
||||||
|
|
||||||
#ifdef LWIP_OPTTEST_FILE
|
|
||||||
#include "lwipopts_test.h"
|
|
||||||
#else /* LWIP_OPTTEST_FILE */
|
|
||||||
|
|
||||||
#define LWIP_IPV4 1
|
#define LWIP_IPV4 1
|
||||||
#define LWIP_IPV6 1
|
#define LWIP_IPV6 0
|
||||||
|
|
||||||
#define NO_SYS 1
|
#define NO_SYS 1
|
||||||
#define LWIP_SOCKET (NO_SYS==0)
|
#define LWIP_SOCKET (NO_SYS==0)
|
||||||
@ -74,7 +70,7 @@
|
|||||||
#define LWIP_NETIF_STATUS_CALLBACK 1
|
#define LWIP_NETIF_STATUS_CALLBACK 1
|
||||||
#define LWIP_NETIF_EXT_STATUS_CALLBACK 1
|
#define LWIP_NETIF_EXT_STATUS_CALLBACK 1
|
||||||
|
|
||||||
#define LWIP_DEBUG
|
//#define LWIP_DEBUG
|
||||||
|
|
||||||
#ifdef LWIP_DEBUG
|
#ifdef LWIP_DEBUG
|
||||||
|
|
||||||
@ -320,8 +316,6 @@ a lot of data that needs to be copied, this should be set high. */
|
|||||||
|
|
||||||
#endif /* PPP_SUPPORT */
|
#endif /* PPP_SUPPORT */
|
||||||
|
|
||||||
#endif /* LWIP_OPTTEST_FILE */
|
|
||||||
|
|
||||||
|
|
||||||
// Disable slip task
|
// Disable slip task
|
||||||
#define SLIP_USE_RX_THREAD 0
|
#define SLIP_USE_RX_THREAD 0
|
||||||
|
@ -6,7 +6,7 @@ target_sources(${TARGET_NAME} PUBLIC
|
|||||||
src/asm_vectors.S
|
src/asm_vectors.S
|
||||||
src/open.c
|
src/open.c
|
||||||
src/xil_exception.c
|
src/xil_exception.c
|
||||||
src/sbrk.c
|
#src/sbrk.c
|
||||||
src/xl2cc_counter.c
|
src/xl2cc_counter.c
|
||||||
src/xil_cache.c
|
src/xil_cache.c
|
||||||
src/xil_spinlock.c
|
src/xil_spinlock.c
|
||||||
@ -48,5 +48,5 @@ target_sources(${TARGET_NAME} PUBLIC
|
|||||||
src/outbyte.c
|
src/outbyte.c
|
||||||
src/unlink.c
|
src/unlink.c
|
||||||
src/abort.c
|
src/abort.c
|
||||||
src/_sbrk.c
|
#src/_sbrk.c
|
||||||
)
|
)
|
@ -2,6 +2,7 @@
|
|||||||
#include "lwip/init.h"
|
#include "lwip/init.h"
|
||||||
#include "lwip/sio.h"
|
#include "lwip/sio.h"
|
||||||
#include "lwip/timeouts.h"
|
#include "lwip/timeouts.h"
|
||||||
|
#include "lwip/udp.h"
|
||||||
|
|
||||||
#include "queue.h"
|
#include "queue.h"
|
||||||
#include "task.h"
|
#include "task.h"
|
||||||
@ -83,13 +84,42 @@ void handleUARTInt(void *) {
|
|||||||
/* Clear the interrupt status. */
|
/* Clear the interrupt status. */
|
||||||
XUartPs_WriteReg(STDIN_BASEADDRESS, XUARTPS_ISR_OFFSET, IsrStatus);
|
XUartPs_WriteReg(STDIN_BASEADDRESS, XUARTPS_ISR_OFFSET, IsrStatus);
|
||||||
|
|
||||||
|
/* directly yield if sending to the queue woke something in ourselves */
|
||||||
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
|
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct udp_pcb *udpecho_raw_pcb;
|
||||||
|
|
||||||
|
static void
|
||||||
|
udpecho_raw_recv(void *arg, struct udp_pcb *upcb, struct pbuf *p,
|
||||||
|
const ip_addr_t *addr, u16_t port)
|
||||||
|
{
|
||||||
|
LWIP_UNUSED_ARG(arg);
|
||||||
|
if (p != NULL) {
|
||||||
|
/* send received packet back to sender */
|
||||||
|
udp_sendto(upcb, p, addr, port);
|
||||||
|
/* free the pbuf */
|
||||||
|
pbuf_free(p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t data[] = {'1','2','3','4','5'};
|
||||||
|
|
||||||
void lwip_main(void *) {
|
void lwip_main(void *) {
|
||||||
|
|
||||||
|
struct pbuf* tx = pbuf_alloc_reference(data, sizeof(data), PBUF_REF);
|
||||||
|
|
||||||
|
ip_addr_t addr = IPADDR4_INIT_BYTES(10,0,0,13);
|
||||||
|
|
||||||
|
udp_sendto(udpecho_raw_pcb, tx, &addr, 1177);
|
||||||
|
|
||||||
|
pbuf_free(tx);
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
// slipif_rxbyte_input() is private, so we use slipif_poll and implement
|
// slipif_rxbyte_input() is private, so we use slipif_poll and implement
|
||||||
// sio_tryread()
|
// sio_tryread()
|
||||||
|
// sio_tryread() will do a blocking read with a timeout, so we get to check
|
||||||
|
// the timeouts even if no data is incoming
|
||||||
slipif_poll(&netif);
|
slipif_poll(&netif);
|
||||||
sys_check_timeouts();
|
sys_check_timeouts();
|
||||||
}
|
}
|
||||||
@ -116,7 +146,9 @@ u32_t sio_tryread(sio_fd_t fd, u8_t *data, u32_t len) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef LWIP_DEBUG
|
||||||
const char *lwip_strerr(err_t err) { return "Dafuq i know? I am a NOSYS"; }
|
const char *lwip_strerr(err_t err) { return "Dafuq i know? I am a NOSYS"; }
|
||||||
|
#endif
|
||||||
|
|
||||||
u32_t sys_now(void) { return xTaskGetTickCount() * portTICK_PERIOD_MS; }
|
u32_t sys_now(void) { return xTaskGetTickCount() * portTICK_PERIOD_MS; }
|
||||||
|
|
||||||
@ -147,7 +179,19 @@ void testIp() {
|
|||||||
netif_set_link_up(&netif);
|
netif_set_link_up(&netif);
|
||||||
netif_set_up(&netif);
|
netif_set_up(&netif);
|
||||||
|
|
||||||
vTaskDelay(pdMS_TO_TICKS(2000));
|
udpecho_raw_pcb = udp_new_ip_type(IPADDR_TYPE_ANY);
|
||||||
|
if (udpecho_raw_pcb != NULL) {
|
||||||
|
err_t err;
|
||||||
|
|
||||||
|
err = udp_bind(udpecho_raw_pcb, IP_ANY_TYPE, 7);
|
||||||
|
if (err == ERR_OK) {
|
||||||
|
udp_recv(udpecho_raw_pcb, udpecho_raw_recv, NULL);
|
||||||
|
} else {
|
||||||
|
/* TODO */
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
/* TODO */
|
||||||
|
}
|
||||||
|
|
||||||
/* Install the UART Interrupt handler. */
|
/* Install the UART Interrupt handler. */
|
||||||
BaseType_t xStatus =
|
BaseType_t xStatus =
|
||||||
@ -183,28 +227,4 @@ void testIp() {
|
|||||||
simple case. */
|
simple case. */
|
||||||
4, /* The priority assigned to the task. */
|
4, /* The priority assigned to the task. */
|
||||||
xStack, &xTaskBuffer);
|
xStack, &xTaskBuffer);
|
||||||
|
|
||||||
// puts("socket");
|
|
||||||
|
|
||||||
// int serverSocket = socket(AF_INET, SOCK_DGRAM, 0);
|
|
||||||
// if (serverSocket == -1) {
|
|
||||||
// puts("socket failed");
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// sockaddr_in serverAddr;
|
|
||||||
|
|
||||||
// memset(&serverAddr, 0, sizeof(serverAddr));
|
|
||||||
|
|
||||||
// serverAddr.sin_family = AF_INET;
|
|
||||||
// serverAddr.sin_port = htons(0xcafe);
|
|
||||||
// serverAddr.sin_addr.s_addr = inet_addr("10.0.0.13");
|
|
||||||
|
|
||||||
// uint8_t data[] = {1, 2, 3, 4, 5, 6, 7};
|
|
||||||
|
|
||||||
// puts("send");
|
|
||||||
|
|
||||||
// sendto(serverSocket, data, sizeof(data), 0, (sockaddr *)&serverAddr,
|
|
||||||
// sizeof(serverAddr));
|
|
||||||
// puts("send done");
|
|
||||||
}
|
}
|
Reference in New Issue
Block a user