Aqui mostraremos como se utiliza Zephyr en la plataforma NXP MCUXpresso Experiencia de Desarrollo MCXN947
Primero se procede a instalar Zephyr como se muestra en el articulo anterior. Se procede a construir el siguiente codigo que implementa un demo del interfaz de Ethernet sencillo para probar una arquitectura distribuida de switch,
/*
* Copyright (c) 2020 DENX Software Engineering GmbH
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(net_dsa_sample, CONFIG_NET_DSA_LOG_LEVEL);
#include "dsa.h"
struct ud g_user_data = {0};
static void dsa_iface_find_cb(struct net_if *iface, void *user_data)
{
struct ud *ifaces = user_data;
if (net_if_l2(iface) != &NET_L2_GET_NAME(ETHERNET)) {
return;
}
if ((net_eth_get_hw_capabilities(iface) & ETHERNET_DSA_CONDUIT_PORT) &&
(ifaces->conduit == NULL)) {
ifaces->conduit = iface;
/* Get user interfaces */
for (int i = 0; i < ARRAY_SIZE(ifaces->lan); i++) {
struct net_if *user = dsa_user_get_iface(iface, i);
if (user == NULL) {
continue;
}
LOG_INF("[%d] User interface %d found.", i, net_if_get_by_iface(user));
ifaces->lan[i] = user;
}
return;
}
}
#if defined(CONFIG_NET_MGMT_EVENT)
#define EVENT_MASK (NET_EVENT_IF_UP)
static struct net_mgmt_event_callback mgmt_cb;
static void event_handler(struct net_mgmt_event_callback *cb,
uint64_t mgmt_event, struct net_if *iface)
{
ARG_UNUSED(iface);
ARG_UNUSED(cb);
if (mgmt_event == NET_EVENT_IF_UP) {
LOG_INF("Port %d is up", net_if_get_by_iface(iface));
#if defined(CONFIG_NET_DHCPV4)
net_dhcpv4_start(iface);
#endif
return;
}
}
#endif /* CONFIG_NET_MGMT_EVENT */
int main(void)
{
/* Initialize interfaces - read them to user_data */
net_if_foreach(dsa_iface_find_cb, &g_user_data);
#if defined(CONFIG_NET_MGMT_EVENT)
net_mgmt_init_event_callback(&mgmt_cb,
event_handler, EVENT_MASK);
net_mgmt_add_event_callback(&mgmt_cb);
#endif /* CONFIG_NET_MGMT_EVENT */
LOG_INF("DSA ports init - OK");
return 0;
}
desde el ambiente virtual,
(venv) DigiKey_Coffee_Cup # west build -b frdm_mcxn947/mcxn947/cpu0 samples/net/ethernet/dsa
- west build: generating a build system
Loading Zephyr default modules (Zephyr base).
...
...
En el terminal de minicom debe de observarse lo siguiente luego de west flash
elcome to minicom 2.10
OPTIONS: I18n
Port /dev/ttyACM0, 23:58:53 [U]
Press CTRL-A Z for help on special keys
[00:00:00.050,000] <inf> phy_mii: PHY (0) ID 7C121
*** Booting Zephyr OS build v4.4.0-8487-g17939cff6553 ***
[00:00:00.051,000] <inf> net_dsa_sample: DSA ports init - OK
uart:~$
....
....
Hemos completado este demo del puerto DSA del Ethernet. En este momento puede someter el siguiente comando para tener una idea del interfaz aun sin ser configurado completamente,
uart:~$ net conn
Context Iface Flags Local Remote
No connections
Handler Callback Proto Local Remote
[ 1] 0x300048c0 0x1001bc7d UDP 0.0.0.0:68 0.0.0.0:0
TCP Context Src port Dst port Send-Seq Send-Ack MSS State
No TCP connections
La plataforma bien conocida NXP MCUXpresso Experiencia de Desarrollo MCXN947 es de bajo costo pero tiene muchas aplicaciones en diversas areas, y está disponible en DigiKey. Mantenganse sintonizado para nuestro próximo artículo.
Que tenga un buen día!
