Skip to content

Commit

Permalink
Add i.MX8MM porting layer
Browse files Browse the repository at this point in the history
Signed-off-by: Elena Popa <[email protected]>
  • Loading branch information
elenap08 committed Nov 14, 2023
1 parent ea5e554 commit 225c349
Show file tree
Hide file tree
Showing 8 changed files with 782 additions and 0 deletions.
62 changes: 62 additions & 0 deletions cmake/iMX8MM.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#********************************************************************
# _ _ _
# _ __ | |_ _ | | __ _ | |__ ___
# | '__|| __|(_)| | / _` || '_ \ / __|
# | | | |_ _ | || (_| || |_) |\__ \
# |_| \__|(_)|_| \__,_||_.__/ |___/
#
# www.rt-labs.com
# Copyright 2021 rt-labs AB, Sweden.
# Copyright 2023 NXP
#
# This software is dual-licensed under GPLv3 and a commercial
# license. See the file LICENSE.md distributed with this software for
# full license information.
#*******************************************************************/

target_include_directories(profinet
PRIVATE
src/ports/iMX8M
)

target_sources(profinet
PRIVATE
src/ports/iMX8M/pnal.c
src/ports/iMX8M/pnal_eth.c
src/ports/iMX8M/pnal_udp.c
)

target_include_directories(pn_dev
PRIVATE
samples/pn_dev
src/ports/iMX8M
)

target_sources(pn_dev
PRIVATE
samples/pn_dev/sampleapp_common.c
samples/pn_dev/app_utils.c
samples/pn_dev/app_log.c
samples/pn_dev/app_gsdml.c
samples/pn_dev/app_data.c
src/ports/iMX8M/sampleapp_main.c
src/ports/iMX8M/sampleapp_imx8mmevk.c
)

target_link_libraries(pn_dev PRIVATE mcuxsdk-bsp)

install (FILES
src/ports/iMX8M/pnal_config.h
DESTINATION include
)

generate_bin(pn_dev)

if (BUILD_TESTING)
target_include_directories(pf_test
PRIVATE
src/ports/iMX8M
)
target_link_libraries(pf_test PRIVATE mcuxsdk-bsp)
generate_bin(pf_test)
endif()
185 changes: 185 additions & 0 deletions src/ports/iMX8M/pnal.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
/*********************************************************************
* _ _ _
* _ __ | |_ _ | | __ _ | |__ ___
* | '__|| __|(_)| | / _` || '_ \ / __|
* | | | |_ _ | || (_| || |_) |\__ \
* |_| \__|(_)|_| \__,_||_.__/ |___/
*
* www.rt-labs.com
* Copyright 2021 rt-labs AB, Sweden.
* Copyright 2023 NXP
*
* This software is dual-licensed under GPLv3 and a commercial
* license. See the file LICENSE.md distributed with this software for
* full license information.
********************************************************************/

#include "pnal.h"

#include "options.h"
#include "osal.h"
#include "osal_log.h"

#include <lwip/apps/snmp.h>
#include <lwip/netif.h>
#include <lwip/snmp.h>
#include <lwip/sys.h>

#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int pnal_set_ip_suite (
const char * interface_name,
const pnal_ipaddr_t * p_ipaddr,
const pnal_ipaddr_t * p_netmask,
const pnal_ipaddr_t * p_gw,
const char * hostname,
bool permanent)
{
ip_addr_t ip_addr;
ip_addr_t ip_mask;
ip_addr_t ip_gw;

ip_addr.addr = htonl (*p_ipaddr);
ip_mask.addr = htonl (*p_netmask);
ip_gw.addr = htonl (*p_gw);

LOCK_TCPIP_CORE();
netif_set_addr (netif_default, &ip_addr, &ip_mask, &ip_gw);
UNLOCK_TCPIP_CORE();

return 0;
}

int pnal_get_macaddress (const char * interface_name, pnal_ethaddr_t * mac_addr)
{
memcpy (mac_addr, netif_default->hwaddr, sizeof (pnal_ethaddr_t));
return 0;
}

pnal_ipaddr_t pnal_get_ip_address (const char * interface_name)
{
return htonl (netif_default->ip_addr.addr);
}

pnal_ipaddr_t pnal_get_netmask (const char * interface_name)
{
return htonl (netif_default->netmask.addr);
}

pnal_ipaddr_t pnal_get_gateway (const char * interface_name)
{
/* TODO Read the actual default gateway */

pnal_ipaddr_t ip;
pnal_ipaddr_t gateway;

ip = pnal_get_ip_address (interface_name);
gateway = (ip & 0xFFFFFF00) | 0x00000001;

return gateway;
}

int pnal_get_hostname (char * hostname)
{
strcpy (hostname, netif_default->hostname);
return 0;
}

int pnal_get_ip_suite (
const char * interface_name,
pnal_ipaddr_t * p_ipaddr,
pnal_ipaddr_t * p_netmask,
pnal_ipaddr_t * p_gw,
char * hostname)
{
int ret = -1;

*p_ipaddr = pnal_get_ip_address (interface_name);
*p_netmask = pnal_get_netmask (interface_name);
*p_gw = pnal_get_gateway (interface_name);
ret = pnal_get_hostname (hostname);

return ret;
}

int pnal_get_port_statistics (
const char * interface_name,
pnal_port_stats_t * port_stats)
{
port_stats->if_in_octets = netif_default->mib2_counters.ifinoctets;
port_stats->if_in_errors = netif_default->mib2_counters.ifinerrors;
port_stats->if_in_discards = netif_default->mib2_counters.ifindiscards;
port_stats->if_out_octets = netif_default->mib2_counters.ifoutoctets;
port_stats->if_out_errors = netif_default->mib2_counters.ifouterrors;
port_stats->if_out_discards = netif_default->mib2_counters.ifoutdiscards;

return 0;
}

int pnal_get_interface_index (const char * interface_name)
{
return 0;
}

int pnal_eth_get_status (const char * interface_name, pnal_eth_status_t * status)
{
status->is_autonegotiation_supported = false;
status->is_autonegotiation_enabled = false;
status->autonegotiation_advertised_capabilities = 0;

status->operational_mau_type = PNAL_ETH_MAU_COPPER_100BaseTX_FULL_DUPLEX;
status->running = true;

return 0;
}

int pnal_save_file (
const char * fullpath,
const void * object_1,
size_t size_1,
const void * object_2,
size_t size_2)
{
return -1;
}

void pnal_clear_file (const char * fullpath)
{

}

int pnal_load_file (
const char * fullpath,
void * object_1,
size_t size_1,
void * object_2,
size_t size_2)
{
return -1;
}

uint32_t pnal_get_system_uptime_10ms (void)
{
uint32_t uptime = 0;

MIB2_COPY_SYSUPTIME_TO (&uptime);
return uptime;
}

pnal_buf_t * pnal_buf_alloc (uint16_t length)
{
return pbuf_alloc (PBUF_RAW, length, PBUF_POOL);
}

void pnal_buf_free (pnal_buf_t * p)
{
CC_ASSERT (pbuf_free (p) == 1);
}

uint8_t pnal_buf_header (pnal_buf_t * p, int16_t header_size_increment)
{
return pbuf_header (p, header_size_increment);
}
49 changes: 49 additions & 0 deletions src/ports/iMX8M/pnal_config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*********************************************************************
* _ _ _
* _ __ | |_ _ | | __ _ | |__ ___
* | '__|| __|(_)| | / _` || '_ \ / __|
* | | | |_ _ | || (_| || |_) |\__ \
* |_| \__|(_)|_| \__,_||_.__/ |___/
*
* www.rt-labs.com
* Copyright 2021 rt-labs AB, Sweden.
*
* This software is dual-licensed under GPLv3 and a commercial
* license. See the file LICENSE.md distributed with this software for
* full license information.
********************************************************************/

/**
* @file
* @brief PNAL-specific configuration
*
* This file contains definitions of configuration settings for the
* PNAL layer.
*/

#ifndef PNAL_CONFIG_H
#define PNAL_CONFIG_H

#include <stdint.h>
#include <stddef.h>

#ifdef __cplusplus
extern "C" {
#endif

typedef struct pnal_thread_cfg
{
uint32_t prio;
size_t stack_size;
} pnal_thread_cfg_t;

typedef struct pnal_cfg
{
pnal_thread_cfg_t bg_worker_thread;
} pnal_cfg_t;

#ifdef __cplusplus
}
#endif

#endif /* PNAL_CONFIG_H */
Loading

0 comments on commit 225c349

Please sign in to comment.