/* * app_enet_open_close.c * * Created on: 1 мар. 2023 г. * Author: sychev * Файл реализует функции объявленные в сгенеренном файле * ti_enet_open_close.h и вызываемые в сгенеренном файле ti_enet_open_close.с */ #include #include #include #define ETH_TYPES_MAC_PORT_MAX (2u) /// Количество mac-портов /// Сгенеренные файлы #include #include 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); phyCfg->phyAddr = boardPhyCfg->phyAddr; 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; } }