161 lines
5.1 KiB
C
161 lines
5.1 KiB
C
/*
|
||
* app_enet_open_close.c
|
||
*
|
||
* Created on: 1 мар. 2023 г.
|
||
* Author: sychev
|
||
* Файл реализует функции объявленные в сгенеренном файле
|
||
* ti_enet_open_close.h и вызываемые в сгенеренном файле ti_enet_open_close.с
|
||
*/
|
||
#include <utils/include/enet_board.h>
|
||
#include <networking/enet/core/include/per/icssg.h>
|
||
#include <networking/enet/utils/include/enet_apputils.h>
|
||
|
||
#define ETH_TYPES_MAC_PORT_MAX (2u) /// Количество mac-портов
|
||
|
||
/// Сгенеренные файлы
|
||
#include <ti_board_config.h>
|
||
|
||
#include <stddef.h>
|
||
|
||
static void eth_macMode2MacMii(emac_mode macMode, EnetMacPort_Interface *mii);
|
||
|
||
static int32_t eth_getSubsPortIdx(Enet_Type enetType, uint32_t instId, uint32_t *subsportIdx);
|
||
|
||
/*
|
||
* Объявлена и используется в сгенеренном файле ti_enet_open_close.h
|
||
*/
|
||
void EnetApp_initLinkArgs(Enet_Type enetType,
|
||
uint32_t instId,
|
||
EnetPer_PortLinkCfg *portLinkCfg,
|
||
Enet_MacPort macPort)
|
||
{
|
||
EnetBoard_EthPort ethPort;
|
||
const EnetBoard_PhyCfg *boardPhyCfg;
|
||
IcssgMacPort_Cfg *icssgMacCfg;
|
||
EnetMacPort_LinkCfg *linkCfg = &portLinkCfg->linkCfg;
|
||
EnetMacPort_Interface *mii = &portLinkCfg->mii;
|
||
EnetPhy_Cfg *phyCfg = &portLinkCfg->phyCfg;
|
||
int32_t status = ENET_SOK;
|
||
|
||
EnetAppUtils_print("Open mac port %u\r\n", ENET_MACPORT_ID(macPort));
|
||
|
||
/* Setup board for requested Ethernet port */
|
||
ethPort.enetType = enetType;
|
||
ethPort.instId = instId;
|
||
ethPort.macPort = macPort;
|
||
ethPort.boardId = ENETBOARD_AM64X_AM243X_EVM;
|
||
eth_macMode2MacMii(RGMII, ðPort.mii);
|
||
|
||
status = EnetBoard_setupPorts(ðPort, 1U);
|
||
if (status != ENET_SOK)
|
||
{
|
||
EnetAppUtils_print("Failed to setup MAC port %u\r\n", ENET_MACPORT_ID(macPort));
|
||
EnetAppUtils_assert(false);
|
||
}
|
||
|
||
icssgMacCfg = portLinkCfg->macCfg;
|
||
IcssgMacPort_initCfg(icssgMacCfg);
|
||
icssgMacCfg->specialFramePrio = 1U;
|
||
|
||
/* Set port link params */
|
||
portLinkCfg->macPort = macPort;
|
||
|
||
mii->layerType = ethPort.mii.layerType;
|
||
mii->sublayerType = ethPort.mii.sublayerType;
|
||
mii->variantType = ENET_MAC_VARIANT_FORCED;
|
||
|
||
linkCfg->speed = ENET_SPEED_AUTO;
|
||
linkCfg->duplexity = ENET_DUPLEX_AUTO;
|
||
|
||
boardPhyCfg = EnetBoard_getPhyCfg(ðPort);
|
||
if (boardPhyCfg != NULL)
|
||
{
|
||
EnetPhy_initCfg(phyCfg);
|
||
if ((ENET_ICSSG_DUALMAC == enetType) && (2U == instId))
|
||
{
|
||
phyCfg->phyAddr = CONFIG_ENET_ICSS0_PHY1_ADDR;
|
||
}
|
||
else if ((ENET_ICSSG_DUALMAC == enetType) && (3U == instId))
|
||
{
|
||
phyCfg->phyAddr = CONFIG_ENET_ICSS0_PHY2_ADDR;
|
||
}
|
||
else if ((ENET_ICSSG_SWITCH == enetType) && (1U == instId))
|
||
{
|
||
if (macPort == ENET_MAC_PORT_1)
|
||
{
|
||
phyCfg->phyAddr = CONFIG_ENET_ICSS0_PHY1_ADDR;
|
||
}
|
||
else
|
||
{
|
||
phyCfg->phyAddr = CONFIG_ENET_ICSS0_PHY2_ADDR;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
EnetAppUtils_assert(false);
|
||
}
|
||
|
||
phyCfg->isStrapped = boardPhyCfg->isStrapped;
|
||
phyCfg->loopbackEn = false;
|
||
phyCfg->skipExtendedCfg = boardPhyCfg->skipExtendedCfg;
|
||
phyCfg->extendedCfgSize = boardPhyCfg->extendedCfgSize;
|
||
memcpy(phyCfg->extendedCfg, boardPhyCfg->extendedCfg, phyCfg->extendedCfgSize);
|
||
}
|
||
else
|
||
{
|
||
EnetAppUtils_print("No PHY configuration found for mac %u\r\n", ENET_MACPORT_ID(macPort));
|
||
EnetAppUtils_assert(false);
|
||
}
|
||
|
||
}
|
||
|
||
/*
|
||
* Объявлена и используется в сгенеренном файле ti_enet_open_close.h
|
||
*/
|
||
void EnetApp_updateIcssgInitCfg(Enet_Type enetType, uint32_t instId, Icssg_Cfg *icssgCfg)
|
||
{
|
||
EnetRm_ResCfg *resCfg;
|
||
uint32_t i;
|
||
|
||
/* Prepare init configuration for all peripherals */
|
||
EnetAppUtils_print("\nInit configs EnetType:%u, InstId :%u\r\n", enetType, instId);
|
||
EnetAppUtils_print("----------------------------------------------\r\n");
|
||
|
||
resCfg = &icssgCfg->resCfg;
|
||
|
||
/* We use software MAC address pool from apputils, but it will give same MAC address.
|
||
* Add port index to make them unique */
|
||
for (i = 0U; i < ETH_TYPES_MAC_PORT_MAX; ++i)
|
||
{
|
||
resCfg->macList.macAddress[i][ENET_MAC_ADDR_LEN - 1] += i;
|
||
}
|
||
|
||
resCfg->macList.numMacAddress = ETH_TYPES_MAC_PORT_MAX;
|
||
}
|
||
|
||
static void eth_macMode2MacMii(emac_mode macMode,
|
||
EnetMacPort_Interface *mii)
|
||
{
|
||
switch (macMode)
|
||
{
|
||
case RMII:
|
||
mii->layerType = ENET_MAC_LAYER_MII;
|
||
mii->sublayerType = ENET_MAC_SUBLAYER_REDUCED;
|
||
mii->variantType = ENET_MAC_VARIANT_NONE;
|
||
break;
|
||
|
||
case RGMII:
|
||
mii->layerType = ENET_MAC_LAYER_GMII;
|
||
mii->sublayerType = ENET_MAC_SUBLAYER_REDUCED;
|
||
mii->variantType = ENET_MAC_VARIANT_FORCED;
|
||
break;
|
||
default:
|
||
EnetAppUtils_print("Invalid MAC mode: %u\r\n", macMode);
|
||
EnetAppUtils_assert(false);
|
||
break;
|
||
}
|
||
}
|
||
|
||
|
||
|