forked from ROMEO/obsw
working on lwip
This commit is contained in:
@ -7,6 +7,13 @@
|
||||
#include "semphr.h"
|
||||
#include "task.h"
|
||||
|
||||
#include "lwip/init.h"
|
||||
#include "lwip/timeouts.h"
|
||||
#include "lwip/udp.h"
|
||||
#include <lwip/ip_addr.h>
|
||||
#include <lwip/netif.h>
|
||||
#include "netif/slipif.h"
|
||||
|
||||
void rust_main();
|
||||
|
||||
#include <hardware/interfaces.h>
|
||||
@ -39,15 +46,62 @@ void test_hardware() {
|
||||
write(1, buffer, read_bytes);
|
||||
}
|
||||
|
||||
|
||||
struct netif netif;
|
||||
struct slipif_priv slipif_config;
|
||||
static struct udp_pcb *udpecho_raw_pcb;
|
||||
|
||||
u32_t sys_now(void) { return xTaskGetTickCount() * portTICK_PERIOD_MS; }
|
||||
|
||||
void test_lwip() {
|
||||
lwip_init();
|
||||
|
||||
ip4_addr_t slip_addr = {PP_HTONL(LWIP_MAKEU32(10, 13, 80, 10))},
|
||||
slip_mask = {PP_HTONL(LWIP_MAKEU32(255, 255, 255, 0))},
|
||||
slip_gw = {PP_HTONL(LWIP_MAKEU32(10, 13, 80, 1))};
|
||||
|
||||
slipif_config.fd = hw_device_open("uart1", 5);
|
||||
|
||||
netif_add(&netif, &slip_addr, &slip_mask, &slip_gw, &slipif_config, slipif_init,
|
||||
netif_input);
|
||||
|
||||
netif_set_default(&netif);
|
||||
// should be done by driver, which does not do it, so we do it here
|
||||
netif_set_link_up(&netif);
|
||||
netif_set_up(&netif);
|
||||
|
||||
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) {
|
||||
return;
|
||||
}
|
||||
|
||||
ip_addr_t addr = IPADDR4_INIT_BYTES(10,13,80,1);
|
||||
|
||||
uint8_t data[] = {'1','2','3','4'};
|
||||
|
||||
struct pbuf* tx = pbuf_alloc_reference(data, sizeof(data), PBUF_REF);
|
||||
|
||||
udp_sendto(udpecho_raw_pcb,tx,&addr,1234);
|
||||
}
|
||||
}
|
||||
|
||||
// called to stop execution (either a panic or program ended)
|
||||
// to be implemented by bsp (do not return from it!)
|
||||
void done();
|
||||
|
||||
|
||||
|
||||
void init_task(void * _) {
|
||||
(void )_;
|
||||
// printf("Starting Mission\n");
|
||||
|
||||
test_hardware();
|
||||
//test_hardware();
|
||||
|
||||
test_lwip();
|
||||
|
||||
rust_main();
|
||||
|
||||
|
Reference in New Issue
Block a user