/*!
* brief Gets the ENET default configuration structure.
*
* The purpose of this API is to get the default ENET configure
* structure for ENET_QOS_Init(). User may use the initialized
* structure unchanged in ENET_QOS_Init(), or modify some fields of the
* structure before calling ENET_QOS_Init().
* Example:
code
enet_qos_config_t config;
ENET_QOS_GetDefaultConfig(&config);
endcode
* param config The ENET mac controller configuration structure pointer.
*/
void ENET_QOS_GetDefaultConfig(enet_qos_config_t *config)
{
/* Checks input parameter. */
assert(config != NULL);
/* Initializes the configure structure to zero. */
(void)memset(config, 0, sizeof(*config));
/* Sets RGMII mode, full duplex, 1000Mbps for MAC and PHY data interface. */
config->miiMode = kENET_QOS_RgmiiMode;
config->miiSpeed = kENET_QOS_MiiSpeed1000M;
config->miiDuplex = kENET_QOS_MiiFullDuplex;
/* Sets default configuration for other options. */
config->specialControl = 0;
config->multiqueueCfg = NULL;
config->pauseDuration = 0;
config->ptpConfig = NULL;
}
The struct has a member
uint32_t csrClock_Hz; /*!< CSR clock frequency in HZ. */
which is initialised there ((void)memset(config, 0, sizeof(*config));) to 0.
2. Nowhere in the code is this value changed/initailised with something else.
3. During the configuration of the HW in
the 1us timer is configured by [line 463 in fsl_enet_qos.c]
/* Set the 1us ticket. */
reg = config->csrClock_Hz / ENET_QOS_MICRSECS_ONESECOND - 1U;
base->MAC_ONEUS_TIC_COUNTER = ENET_QOS_MAC_ONEUS_TIC_COUNTER_TIC_1US_CNTR(reg);
This is using the (uninitialised 0) value for its calculation and so it doesn't set the correct 1us value but instead sets (by chance) about 17u.
The result is that all timing of off by this factor.
4: It can be fixed by adding
config.csrClock_Hz = ethernetifConfig->srcClockHz;
to any code with access to the two structs 'before'
ENET_QOS_Init() is called.
For example, adding it at line 476 in enet_ethernetif_qos.c will fix it:
ENET_QOS_GetDefaultConfig(&config);
config.csrClock_Hz = ethernetifConfig->srcClockHz; // initialse the member that will be used to define the us timer value
Regards
Mark