Commit 4410efc1 authored by Damien George's avatar Damien George

stm32/network_wiznet5k: Add ability to trace Ethernet TX and RX frames.

Via: nic.config(trace=2|4)
parent 69cb24a2
......@@ -32,12 +32,16 @@
#if MICROPY_PY_WIZNET5K && MICROPY_PY_LWIP
#include "lib/netutils/netutils.h"
#include "drivers/wiznet5k/ethernet/socket.h"
#include "lwip/err.h"
#include "lwip/dns.h"
#include "lwip/dhcp.h"
#include "netif/etharp.h"
#define TRACE_ETH_TX (0x0002)
#define TRACE_ETH_RX (0x0004)
/*******************************************************************************/
// Wiznet5k Ethernet driver in MACRAW mode
......@@ -48,6 +52,7 @@ typedef struct _wiznet5k_obj_t {
mp_hal_pin_obj_t cs;
mp_hal_pin_obj_t rst;
uint8_t eth_frame[1514];
uint32_t trace_flags;
struct netif netif;
struct dhcp dhcp_struct;
} wiznet5k_obj_t;
......@@ -176,6 +181,9 @@ STATIC uint16_t wiznet5k_recv_ethernet(wiznet5k_obj_t *self) {
STATIC err_t wiznet5k_netif_output(struct netif *netif, struct pbuf *p) {
wiznet5k_obj_t *self = netif->state;
pbuf_copy_partial(p, self->eth_frame, p->tot_len, 0);
if (self->trace_flags & TRACE_ETH_TX) {
netutils_ethernet_trace(MP_PYTHON_PRINTER, p->tot_len, self->eth_frame, NETUTILS_TRACE_IS_TX | NETUTILS_TRACE_NEWLINE);
}
wiznet5k_send_ethernet(self, p->tot_len, self->eth_frame);
return ERR_OK;
}
......@@ -223,6 +231,9 @@ STATIC void wiznet5k_lwip_poll(void *self_in, struct netif *netif) {
wiznet5k_obj_t *self = self_in;
uint16_t len;
while ((len = wiznet5k_recv_ethernet(self)) > 0) {
if (self->trace_flags & TRACE_ETH_RX) {
netutils_ethernet_trace(MP_PYTHON_PRINTER, len, self->eth_frame, NETUTILS_TRACE_NEWLINE);
}
struct pbuf *p = pbuf_alloc(PBUF_RAW, len, PBUF_POOL);
if (p != NULL) {
pbuf_take(p, self->eth_frame, len);
......@@ -260,6 +271,7 @@ STATIC mp_obj_t wiznet5k_make_new(const mp_obj_type_t *type, size_t n_args, size
wiznet5k_obj.spi = spi;
wiznet5k_obj.cs = cs;
wiznet5k_obj.rst = rst;
wiznet5k_obj.trace_flags = 0;
// Return wiznet5k object
return MP_OBJ_FROM_PTR(&wiznet5k_obj);
......@@ -381,7 +393,22 @@ STATIC mp_obj_t wiznet5k_config(size_t n_args, const mp_obj_t *args, mp_map_t *k
if (n_args != 1) {
mp_raise_TypeError("can't specify pos and kw args");
}
mp_raise_ValueError("unknown config param");
for (size_t i = 0; i < kwargs->alloc; ++i) {
if (MP_MAP_SLOT_IS_FILLED(kwargs, i)) {
mp_map_elem_t *e = &kwargs->table[i];
switch (mp_obj_str_get_qstr(e->key)) {
case MP_QSTR_trace: {
self->trace_flags = mp_obj_get_int(e->value);
break;
}
default:
mp_raise_ValueError("unknown config param");
}
}
}
return mp_const_none;
}
}
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(wiznet5k_config_obj, 1, wiznet5k_config);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment