以太網(wǎng)PHY驅(qū)動軟件配置
這里以Renesas提供的RZ/T2M工程樣例“RZT2M_EtherCAT_RSK_rev0100”為例對PHY驅(qū)動的軟件配置流程進行說明。此工程樣例可以在Renesas提供的開發(fā)版上運行和調(diào)試。開發(fā)套件的使用文件《r20ut4939eg0050-rskrzt2m-usermanual_c.pdf》可以上Renesas官方網(wǎng)站上獲取,開發(fā)板也可以申請購買或者是借用。
驅(qū)動配置的入口
void hal_entry (void)
{
fsp_err_t err;
/* TODO: add your own code here */
/* Initialize EtherCAT SSC Port */
err = RM_ETHERCAT_SSC_PORT_Open(gp_ethercat_ssc_port->p_ctrl, gp_ethercat_ssc_port->p_cfg);
if(FSP_SUCCESS != err)
{
__BKPT(0); /* Can't continue the stack */
}
...
}
進入RM_ETHERCAT_SSC_PORT_Open(), 這個EtherCAT接口配置函數(shù)之后,可以看到EtherCAT Slave Controller的一些初始化配置,其中就包括了PHY的初始化:
/* Open Ether-Phy Driver */
for (i = 0; BSP_FEATURE_ESC_MAX_PORTS > i; i++)
{
p_ether_PHY_instance = (ether_PHY_instance_t *) p_extend->p_ether_PHY_instance[i];
if (NULL != p_ether_PHY_instance)
{
err = p_ether_PHY_instance->p_api->open(p_ether_PHY_instance->p_ctrl, p_ether_PHY_instance->p_cfg);
}
if (FSP_SUCCESS == err)
{
opened_PHY[i] = 1;
}
else
{
break;
}
}
PHY驅(qū)動配置相關(guān)數(shù)據(jù)結(jié)構(gòu)解析
這里初始化的一個PHY實例是:
p_ether_PHY_instance,它是一個ether_PHY_instance_t類型的變量。
typedef struct st_ether_PHY_instance
{
ether_PHY_ctrl_t * p_ctrl; ///< Pointer to the control structure for this instance
? ?ether_PHY_cfg_t const * p_cfg; ? ? ///< Pointer to the configuration structure for this instance
? ?ether_PHY_api_t const * p_api; ? ? ///< Pointer to the API structure for this instance
} ether_PHY_instance_t;
其中ether_PHY_ctrl_t是指向PHY實例的控制結(jié)構(gòu)體;
ether_PHY_cfg_t是指向?qū)嵗渲玫慕Y(jié)構(gòu)體指針;
ether_PHY_api_t是實例配置過程中需要調(diào)用到的函數(shù)方法所組成的結(jié)構(gòu)體指針;
這個PHY的實例是在調(diào)用RM_ETHERCAT_SSC_PORT_Open()函數(shù)的時候形參傳遞進來的,也就是gp_ethercat_ssc_port。
ethercat_ssc_port_instance_t const * gp_ethercat_ssc_port = &g_ethercat_ssc_port0;
而gp_ethercat_ssc_port這個ethercat_ssc_port_instance_t類型的全局指針是指向一個常量,也就是下面代碼中的g_ethercat_ssc_port0。
/* Instance structure to use this module. */
const ethercat_ssc_port_instance_t g_ethercat_ssc_port0 =
{
.p_ctrl = &g_ethercat_ssc_port0_ctrl,
.p_cfg = &g_ethercat_ssc_port0_cfg,
.p_api = &g_ethercat_ssc_port_on_ethercat_ssc_port
};
可以看到g_ethercat_ssc_port0是一個常量結(jié)構(gòu)體,它的成員變量分別是:
g_ethercat_ssc_port0_ctrl指向ethercat_ssc_port0控制結(jié)構(gòu)體指針;
g_ethercat_ssc_port0_cfg指向ethercat_ssc_port0配置結(jié)構(gòu)體指針;
g_ethercat_ssc_port_on_ethercat_ssc_port指向ethercat_ssc_port0配置方法的結(jié)構(gòu)指針。
看到這里是不是有一種似成相識的感覺?g_ethercat_ssc_port0是對ethercat_ssc_port0這個外設(shè)的驅(qū)動的描述體,與前面PHY驅(qū)運的描述體“p_ether_PHY_instance”結(jié)構(gòu)上很相似,其實工程樣例中所有的外設(shè)驅(qū)動都可以使用類似的結(jié)構(gòu)體去完成相應(yīng)的初始化。比如說timer驅(qū)動描述結(jié)構(gòu)體:
/** This structure encompasses everything that is needed to use an instance of this interface. */
typedef struct st_timer_instance
{
timer_ctrl_t * p_ctrl; ///< Pointer to the control structure for this instance
? ?timer_cfg_t const * p_cfg; ? ? ? ? ///< Pointer to the configuration structure for this instance
? ?timer_api_t const * p_api; ? ? ? ? ///< Pointer to the API structure for this instance
} timer_instance_t;
這種相似的驅(qū)動描述體其實就是工程樣例驅(qū)動代碼部分的大致框架所在,撐握了這個脈絡(luò)即可以方便的看懂其它外設(shè)驅(qū)動的代碼,也可以在以后的驅(qū)動開發(fā)過程中參考這種框架,提升代的通用性和可讀性。
我們知道PHY的驅(qū)動是ethercat_ssc_port0外設(shè)驅(qū)動的子模塊。因為要在RZ/T2M這個芯片上使能EtherCAT功能塊,除了要完成芯片本身相關(guān)外設(shè)的初始化之外,還要完成與之對應(yīng)的PHY的初始化。那么兩者是如何關(guān)聯(lián)在一起的呢?我們繼續(xù)解讀g_ethercat_ssc_port0這個全局結(jié)構(gòu)體。可以看到g_ethercat_ssc_port0_cfg所指向的內(nèi)容是配置ethercat_ssc_port0的描述體,如下所示:
/** Configuration parameters. */ typedef struct st_ethercat_ssc_port_cfg { uint32_t reset_hold_time; ///< PHY Reset signal hold time (ms) ? ?uint32_t reset_wait_time; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?///< Wait time after PHY reset relase (us) ? ?uint32_t offset_address; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ///< PHY offset PHYsical address ? ?IRQn_Type esc_cat_irq; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ///< EtherCAT IRQ interrupt number ? ?uint8_t ? esc_cat_ipl; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ///< EtherCAT interrupt priority ? ?IRQn_Type esc_sync0_irq; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?///< EtherCAT Sync0 IRQ interrupt number ? ?uint8_t ? esc_sync0_ipl; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ///< EtherCAT Sync0 interrupt priority ? ?IRQn_Type esc_sync1_irq; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?///< EtherCAT Sync1 IRQ interrupt number ? ?uint8_t ? esc_sync1_ipl; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ///< EtherCAT Sync1 interrupt priority ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?///< Callback provided when an ISR occurs ? ?void (* p_callback)(ethercat_ssc_port_callback_args_t * p_args); ? ?timer_instance_t const * p_timer_instance; ? ? ? ? ? ? ? ? ? ///< Pointer to Timer instance ? ?/** Placeholder for user data. ?Passed to the user callback in ethercat_ssc_port_callback_args_t. */ ? ?void const * p_context; ? ?void const * p_extend; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ///< Placeholder for user extension. } ethercat_ssc_port_cfg_t;
對PHY的復(fù)位信號保持時間有描述,還有對EtherCAT中斷有作描述,在此不展開討論。其中p_extend成員是用戶用于擴展控制的占位符。這也正是PHY驅(qū)動與ethercat_ssc_port0驅(qū)動關(guān)聯(lián)的關(guān)鍵所在。代碼賦于這個占位符是一個指向擴展配置的結(jié)構(gòu)體指針。具體可以看看這個結(jié)構(gòu)體的內(nèi)容如下:
/** Extended configuration */
typedef struct s_ethercat_ssc_port_extend_cfg
{
ethercat_ssc_port_eeprom_size_t eeprom_size; ///< EEPROM memory size
? ?ethercat_ssc_port_txc_delay_t ? txc0; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ///< Port 0 TXC delay time
? ?ethercat_ssc_port_txc_delay_t ? txc1; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ///< Port 1 TXC delay time
? ?ethercat_ssc_port_txc_delay_t ? txc2; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ///< Port 2 TXC delay time
? ?ether_PHY_instance_t const * p_ether_PHY_instance[BSP_FEATURE_ESC_MAX_PORTS];
///< Pointer to ETHER_PHY instance
} ethercat_ssc_port_extend_cfg_t;
const ethercat_ssc_port_extend_cfg_t g_ethercat_ssc_port0_ext_cfg =
{
? ?.eeprom_size ? ? ? ? ? ? = ETHERCAT_SSC_PORT_EEPROM_SIZE_UNDER_32KBIT,
? ?.txc0 ? ? ? ? ? ? ? ? ? ?= ETHERCAT_SSC_PORT_TXC_DELAY_00NS,
? ?.txc1 ? ? ? ? ? ? ? ? ? ?= ETHERCAT_SSC_PORT_TXC_DELAY_00NS,
? ?.txc2 ? ? ? ? ? ? ? ? ? ?= ETHERCAT_SSC_PORT_TXC_DELAY_00NS,
? ?.p_ether_PHY_instance[0] =
#define FSP_NOT_DEFINED (1)
#if (FSP_NOT_DEFINED == g_ether_PHY0)
? ? ? ? ? ? ? ? ? ?NULL,
#else
? ? ? ? ? ? ? ? ? ?&g_ether_PHY0,
#endif
? ?.p_ether_PHY_instance[1] =
#if (FSP_NOT_DEFINED == g_ether_PHY1)
? ? ? ? ? ? ? ? ? ?NULL,
#else
? ? ? ? ? ? ? ? ? ?&g_ether_PHY1,
#endif
? ?.p_ether_PHY_instance[2] =
#if (FSP_NOT_DEFINED == FSP_NOT_DEFINED)
? ? ? ? ? ? ? ? ? ?NULL,
#else
? ? ? ? ? ? ? ? ? ?&FSP_NOT_DEFINED,
#endif
};
里面就對應(yīng)有ether_PHY_instance_t類體的初始化值,這值的類型正好是PHY實例所對應(yīng)的描體結(jié)構(gòu)體如下代碼所示,所以關(guān)聯(lián)就產(chǎn)生了。
typedef struct st_ether_PHY_instance
{
ether_PHY_ctrl_t * p_ctrl; ///< Pointer to the control structure for this instance
? ?ether_PHY_cfg_t const * p_cfg; ? ? ///< Pointer to the configuration structure for this instance
? ?ether_PHY_api_t const * p_api; ? ? ///< Pointer to the API structure for this instance
} wh wether_PHY_instance_t;
審核編輯:劉清
-
驅(qū)動器
+關(guān)注
關(guān)注
54文章
9031瀏覽量
153676 -
PHY
+關(guān)注
關(guān)注
2文章
331瀏覽量
53836 -
工業(yè)以太網(wǎng)
+關(guān)注
關(guān)注
10文章
674瀏覽量
43660 -
ssc
+關(guān)注
關(guān)注
0文章
26瀏覽量
11779 -
ethercat
+關(guān)注
關(guān)注
19文章
1400瀏覽量
43699
發(fā)布評論請先 登錄
工業(yè)以太網(wǎng)的可靠之選:DP83822低功耗耐用型以太網(wǎng)PHY
DP83TC811S-Q1:汽車以太網(wǎng)PHY的卓越之選
DP83826:確定性、低延遲工業(yè)以太網(wǎng)PHY的卓越之選
汽車以太網(wǎng)PHY新秀:DP83TG721-Q1深度解析
移植網(wǎng)絡(luò)PHY芯片驅(qū)動,如何融入 rt-thread 的網(wǎng)絡(luò)體系,并添加新的以太網(wǎng)類型的報文?
?基于DP83TC812-Q1的汽車以太網(wǎng)PHY技術(shù)解析
Texas Instruments DP83867-EVM-AM以太網(wǎng)PHY附加板數(shù)據(jù)手冊
Analog Devices Inc. ADIN1110低功耗10BASE-T1L以太網(wǎng)MAC-PHY數(shù)據(jù)手冊
Microchip LAN9211-ABZJ 集成 10/100 以太網(wǎng) PHY的以太網(wǎng)控制器
ADIN1300低延遲和低功耗10 Mbps、100 Mbps和1 Gbps以太網(wǎng)PHY技術(shù)手冊
ADIN1200可靠的工業(yè)低功耗10 Mbps和100 Mbps以太網(wǎng)PHY技術(shù)手冊
愛普生SG2520CAA有源晶振賦能車身以太網(wǎng) PHY
國產(chǎn)芯片替代方案:解析沁恒以太網(wǎng)PHY芯片
AN4754-將Microchip橋接控制器與外部以太網(wǎng)PHY搭配使用
EE-315:更改Blackfin處理器以太網(wǎng)驅(qū)動程序中的PHY

以太網(wǎng)PHY硬件連接 以太網(wǎng)PHY驅(qū)動軟件配置介紹
評論