<acronym id="s8ci2"><small id="s8ci2"></small></acronym>
<rt id="s8ci2"></rt><rt id="s8ci2"><optgroup id="s8ci2"></optgroup></rt>
<acronym id="s8ci2"></acronym>
<acronym id="s8ci2"><center id="s8ci2"></center></acronym>
0
  • 聊天消息
  • 系統消息
  • 評論與回復
登錄后你可以
  • 下載海量資料
  • 學習在線課程
  • 觀看技術視頻
  • 寫文章/發帖/加入社區
會員中心
創作中心

完善資料讓更多小伙伴認識你,還能領取20積分哦,立即完善>

3天內不再提示

以太網PHY硬件連接 以太網PHY驅動軟件配置介紹

瑞薩MCU小百科 ? 來源:瑞薩嵌入式小百科 ? 作者:瑞薩嵌入式小百科 ? 2024-02-20 12:18 ? 次閱讀

以太網PHY驅動軟件配置

這里以Renesas提供的RZ/T2M工程樣例“RZT2M_EtherCAT_RSK_rev0100”為例對PHY驅動的軟件配置流程進行說明。此工程樣例可以在Renesas提供的開發版上運行和調試。開發套件的使用文件《r20ut4939eg0050-rskrzt2m-usermanual_c.pdf》可以上Renesas官方網站上獲取,開發板也可以申請購買或者是借用。

驅動配置的入口

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接口配置函數之后,可以看到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驅動配置相關數據結構解析

這里初始化的一個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實例的控制結構體;

ether_PHY_cfg_t是指向實例配置的結構體指針;

ether_PHY_api_t是實例配置過程中需要調用到的函數方法所組成的結構體指針;

這個PHY的實例是在調用RM_ETHERCAT_SSC_PORT_Open()函數的時候形參傳遞進來的,也就是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是一個常量結構體,它的成員變量分別是:

g_ethercat_ssc_port0_ctrl指向ethercat_ssc_port0控制結構體指針;

g_ethercat_ssc_port0_cfg指向ethercat_ssc_port0配置結構體指針;

g_ethercat_ssc_port_on_ethercat_ssc_port指向ethercat_ssc_port0配置方法的結構指針。

看到這里是不是有一種似成相識的感覺?g_ethercat_ssc_port0是對ethercat_ssc_port0這個外設的驅動的描述體,與前面PHY驅運的描述體“p_ether_PHY_instance”結構上很相似,其實工程樣例中所有的外設驅動都可以使用類似的結構體去完成相應的初始化。比如說timer驅動描述結構體:

/** 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;

這種相似的驅動描述體其實就是工程樣例驅動代碼部分的大致框架所在,撐握了這個脈絡即可以方便的看懂其它外設驅動的代碼,也可以在以后的驅動開發過程中參考這種框架,提升代的通用性和可讀性。

我們知道PHY的驅動是ethercat_ssc_port0外設驅動的子模塊。因為要在RZ/T2M這個芯片上使能EtherCAT功能塊,除了要完成芯片本身相關外設的初始化之外,還要完成與之對應的PHY的初始化。那么兩者是如何關聯在一起的呢?我們繼續解讀g_ethercat_ssc_port0這個全局結構體??梢钥吹絞_ethercat_ssc_port0_cfg所指向的內容是配置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驅動與ethercat_ssc_port0驅動關聯的關鍵所在。代碼賦于這個占位符是一個指向擴展配置的結構體指針。具體可以看看這個結構體的內容如下:

/** 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實例所對應的描體結構體如下代碼所示,所以關聯就產生了。

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;





審核編輯:劉清

聲明:本文內容及配圖由入駐作者撰寫或者入駐合作網站授權轉載。文章觀點僅代表作者本人,不代表電子發燒友網立場。文章及其配圖僅供工程師學習之用,如有內容侵權或者其他違規問題,請聯系本站處理。 舉報投訴
  • 驅動器
    +關注

    關注

    51

    文章

    7532

    瀏覽量

    143451
  • PHY
    PHY
    +關注

    關注

    2

    文章

    270

    瀏覽量

    51230
  • 工業以太網
    +關注

    關注

    10

    文章

    584

    瀏覽量

    42143
  • ssc
    ssc
    +關注

    關注

    0

    文章

    24

    瀏覽量

    11106
  • ethercat
    +關注

    關注

    18

    文章

    451

    瀏覽量

    37790

原文標題:工業以太網PHY驅動適配參考文檔(4)

文章出處:【微信號:瑞薩MCU小百科,微信公眾號:瑞薩MCU小百科】歡迎添加關注!文章轉載請注明出處。

收藏 人收藏

    評論

    相關推薦

    車載以太網硬件接口VN5650--基于Network-based模式的配置過程#車載以太網 #CANoe

    車載以太網
    北匯信息POLELINK
    發布于 :2024年05月15日 17:28:47

    車載以太網接口VN5650使用場景介紹#車載以太網

    以太網
    北匯信息POLELINK
    發布于 :2024年05月11日 17:58:05

    STM32F429NI是否具備以太網MAC+PHY,無需外接PHY芯片?

    STM32F429NI是否具備以太網MAC+PHY,無需外接PHY芯片
    發表于 04-07 08:55

    車載以太網基礎培訓——車載以太網的鏈路層#車載以太網

    車載以太網
    北匯信息POLELINK
    發布于 :2023年09月19日 16:25:21

    車載以太網測試系統測試實例介紹#車載以太網

    車載以太網
    北匯信息POLELINK
    發布于 :2023年09月12日 17:27:48

    車載以太網快速入門#車載以太網

    車載以太網
    北匯信息POLELINK
    發布于 :2023年09月01日 17:54:31

    71 69_以太網PHY芯片簡介-RTL8211FD - 第3節

    以太網
    充八萬
    發布于 :2023年08月19日 22:25:07

    71 69_以太網PHY芯片簡介-RTL8211FD - 第1節

    以太網
    充八萬
    發布于 :2023年08月19日 22:23:26

    70 68_以太網PHY芯片簡介-B50610 - 第1節

    以太網
    充八萬
    發布于 :2023年08月19日 22:09:04

    更換不同的以太網PHY

    電子發燒友網站提供《更換不同的以太網PHY.pdf》資料免費下載
    發表于 07-31 14:45 ?2次下載
    更換不同的<b class='flag-5'>以太網</b><b class='flag-5'>PHY</b>

    以太網 PHY 的功能和選擇

    以太網 PHY 3具有兩個主要功能
    的頭像 發表于 07-14 15:52 ?844次閱讀
    <b class='flag-5'>以太網</b> <b class='flag-5'>PHY</b> 的功能和選擇

    一文詳解車載以太網PHY芯片

    以太網物理層(PHY)芯片系以太網傳輸的物理接口收發器。應用于通信、汽車電子、消費電子、工控等眾多領域。
    發表于 06-19 17:15 ?5096次閱讀

    以太網PHY:以“萬兆”選手上場,被“百兆”絆倒的以太網PHY領域怪談

    汽車電子領域隨著ADAS和車聯網的發展,車載網絡轉向域控制和集中控制的趨勢越來越明顯,車內通信架構將逐漸向以太網升級,汽車中以太網PHY需求量也將快速提升。傳統以太網
    的頭像 發表于 06-16 15:45 ?633次閱讀

    選擇以太網PHY時應注意哪些因素

    以太網是IEEE 802.3中規定的一種接口規范。以太網物理(PHY)層是IEEE 802.3的其中一個元素。它是一種收發器組件,用于發送和接收數據或以太網幀。在OSI模型中,
    的頭像 發表于 06-14 16:37 ?552次閱讀
    選擇<b class='flag-5'>以太網</b><b class='flag-5'>PHY</b>時應注意哪些因素

    S32K344-Q172上的以太網PHY未正確重置怎么處理?

    我有一個 NXP S32K3X4EVB-Q172 (SCH-51972 REV A),我正在嘗試使用 NXP ping 示例項目測試以太網功能和 lwIP 堆棧:lwip_s32k344。但是,我
    發表于 06-08 09:41
    亚洲欧美日韩精品久久_久久精品AⅤ无码中文_日本中文字幕有码在线播放_亚洲视频高清不卡在线观看
    <acronym id="s8ci2"><small id="s8ci2"></small></acronym>
    <rt id="s8ci2"></rt><rt id="s8ci2"><optgroup id="s8ci2"></optgroup></rt>
    <acronym id="s8ci2"></acronym>
    <acronym id="s8ci2"><center id="s8ci2"></center></acronym>