以太網(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)體去完成相應的初始化。比如說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è)的初始化之外,還要完成與之對應的PHY的初始化。那么兩者是如何關(guān)聯(lián)在一起的呢?我們繼續(xù)解讀g_ethercat_ssc_port0這個全局結(jié)構(gòu)體??梢钥吹絞_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的復位信號保持時間有描述,還有對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 };
里面就對應有ether_PHY_instance_t類體的初始化值,這值的類型正好是PHY實例所對應的描體結(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)注
53文章
8290瀏覽量
147162 -
PHY
+關(guān)注
關(guān)注
2文章
305瀏覽量
51886 -
工業(yè)以太網(wǎng)
+關(guān)注
關(guān)注
10文章
625瀏覽量
42443 -
ssc
+關(guān)注
關(guān)注
0文章
25瀏覽量
11256 -
ethercat
+關(guān)注
關(guān)注
19文章
747瀏覽量
38912
原文標題:工業(yè)以太網(wǎng)PHY驅(qū)動適配參考文檔(4)
文章出處:【微信號:瑞薩MCU小百科,微信公眾號:瑞薩MCU小百科】歡迎添加關(guān)注!文章轉(zhuǎn)載請注明出處。
發(fā)布評論請先 登錄
相關(guān)推薦
PHY芯片向高速多端口發(fā)展,車載以太網(wǎng)PHY正在迅速起量
![<b class='flag-5'>PHY</b>芯片向高速多端口發(fā)展,車載<b class='flag-5'>以太網(wǎng)</b><b class='flag-5'>PHY</b>正在迅速起量](https://file1.elecfans.com/web2/M00/BF/FE/wKgZomXNeP2AI4qbAA1yjgABgF4416.png)
AN4754-將Microchip橋接控制器與外部以太網(wǎng)PHY搭配使用
![AN4754-將Microchip橋接控制器與外部<b class='flag-5'>以太網(wǎng)</b><b class='flag-5'>PHY</b>搭配使用](https://file.elecfans.com/web1/M00/D9/4E/pIYBAF_1ac2Ac0EEAABDkS1IP1s689.png)
EE-315:更改Blackfin處理器以太網(wǎng)驅(qū)動程序中的PHY
![EE-315:更改Blackfin處理器<b class='flag-5'>以太網(wǎng)</b><b class='flag-5'>驅(qū)動</b>程序中的<b class='flag-5'>PHY</b>](https://file.elecfans.com/web1/M00/D9/4E/pIYBAF_1ac2Ac0EEAABDkS1IP1s689.png)
用于汽車以太網(wǎng)PHY附加板的AM2x評估模塊用戶指南
![用于汽車<b class='flag-5'>以太網(wǎng)</b><b class='flag-5'>PHY</b>附加板的AM2x評估模塊用戶指南](https://file.elecfans.com/web1/M00/D9/4E/pIYBAF_1ac2Ac0EEAABDkS1IP1s689.png)
用于工業(yè)以太網(wǎng)PHY的AM2x評估模塊附加板用戶指南
![用于工業(yè)<b class='flag-5'>以太網(wǎng)</b><b class='flag-5'>PHY</b>的AM2x評估模塊附加板用戶指南](https://file.elecfans.com/web1/M00/D9/4E/pIYBAF_1ac2Ac0EEAABDkS1IP1s689.png)
以太網(wǎng)PHY PCB設(shè)計布局檢查清單
![<b class='flag-5'>以太網(wǎng)</b><b class='flag-5'>PHY</b> PCB設(shè)計布局檢查清單](https://file.elecfans.com/web1/M00/D9/4E/pIYBAF_1ac2Ac0EEAABDkS1IP1s689.png)
適用于工業(yè)應用的使用MDIO的以太網(wǎng)PHY配置
![適用于工業(yè)應用的使用MDIO的<b class='flag-5'>以太網(wǎng)</b><b class='flag-5'>PHY</b><b class='flag-5'>配置</b>](https://file.elecfans.com/web1/M00/D9/4E/pIYBAF_1ac2Ac0EEAABDkS1IP1s689.png)
利用DP83TC812-Q1以太網(wǎng)物理層 (PHY) 的完整汽車以太網(wǎng)系統(tǒng)中的設(shè)置和測量
![利用DP83TC812-Q1<b class='flag-5'>以太網(wǎng)</b>物理層 (<b class='flag-5'>PHY</b>) 的完整汽車<b class='flag-5'>以太網(wǎng)</b>系統(tǒng)中的設(shè)置和測量](https://file.elecfans.com/web1/M00/D9/4E/pIYBAF_1ac2Ac0EEAABDkS1IP1s689.png)
使用C2000 EtherCAT從站控制器的SMI進行以太網(wǎng)PHY配置
![使用C2000 EtherCAT從站控制器的SMI進行<b class='flag-5'>以太網(wǎng)</b><b class='flag-5'>PHY</b><b class='flag-5'>配置</b>](https://file.elecfans.com/web1/M00/D9/4E/pIYBAF_1ac2Ac0EEAABDkS1IP1s689.png)
如何以及何時在PROFINET系統(tǒng)中使用以太網(wǎng)PHY
![如何以及何時在PROFINET系統(tǒng)中使用<b class='flag-5'>以太網(wǎng)</b><b class='flag-5'>PHY</b>](https://file.elecfans.com/web1/M00/D9/4E/pIYBAF_1ac2Ac0EEAABDkS1IP1s689.png)
X1G004481000300低功耗晶振以太網(wǎng)PHY芯片的關(guān)鍵核心
以太網(wǎng)要怎么連接
![](https://file1.elecfans.com/web2/M00/EA/91/wKgZomZZNV6ABmUHAALQaX4H-ZI635.jpg)
車載以太網(wǎng)硬件接口VN5620設(shè)備展示與介紹#車載以太網(wǎng)
以太網(wǎng)PHY寄存器分析 以太網(wǎng)PHY驅(qū)動軟件配置
![<b class='flag-5'>以太網(wǎng)</b><b class='flag-5'>PHY</b>寄存器分析 <b class='flag-5'>以太網(wǎng)</b><b class='flag-5'>PHY</b><b class='flag-5'>驅(qū)動</b><b class='flag-5'>軟件</b><b class='flag-5'>配置</b>](https://file1.elecfans.com/web2/M00/C0/90/wKgZomXWy2-ARiuVAABF8ulvO0c810.png)
一文詳解以太網(wǎng)MAC芯片與PHY芯片
![一文詳解<b class='flag-5'>以太網(wǎng)</b>MAC芯片與<b class='flag-5'>PHY</b>芯片](https://file1.elecfans.com/web2/M00/C0/1D/wKgZomXSwkyAbWlRAAApGzAf95E167.jpg)
評論