lan8742.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  1. /**
  2. ******************************************************************************
  3. * @file lan8742.c
  4. * @author MCD Application Team
  5. * @brief This file provides a set of functions needed to manage the LAN742
  6. * PHY devices.
  7. ******************************************************************************
  8. * @attention
  9. *
  10. * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.
  11. * All rights reserved.</center></h2>
  12. *
  13. * This software component is licensed by ST under BSD 3-Clause license,
  14. * the "License"; You may not use this file except in compliance with the
  15. * License. You may obtain a copy of the License at:
  16. * opensource.org/licenses/BSD-3-Clause
  17. *
  18. ******************************************************************************
  19. */
  20. /* Includes ------------------------------------------------------------------*/
  21. #include "lan8742.h"
  22. /** @addtogroup BSP
  23. * @{
  24. */
  25. /** @addtogroup Component
  26. * @{
  27. */
  28. /** @defgroup LAN8742 LAN8742
  29. * @{
  30. */
  31. /* Private typedef -----------------------------------------------------------*/
  32. /* Private define ------------------------------------------------------------*/
  33. /** @defgroup LAN8742_Private_Defines LAN8742 Private Defines
  34. * @{
  35. */
  36. #define LAN8742_SW_RESET_TO ((uint32_t)500U)
  37. #define LAN8742_INIT_TO ((uint32_t)2000U)
  38. #define LAN8742_MAX_DEV_ADDR ((uint32_t)31U)
  39. /**
  40. * @}
  41. */
  42. /* Private macro -------------------------------------------------------------*/
  43. /* Private variables ---------------------------------------------------------*/
  44. /* Private function prototypes -----------------------------------------------*/
  45. /* Private functions ---------------------------------------------------------*/
  46. /** @defgroup LAN8742_Private_Functions LAN8742 Private Functions
  47. * @{
  48. */
  49. /**
  50. * @brief Register IO functions to component object
  51. * @param pObj: device object of LAN8742_Object_t.
  52. * @param ioctx: holds device IO functions.
  53. * @retval LAN8742_STATUS_OK if OK
  54. * LAN8742_STATUS_ERROR if missing mandatory function
  55. */
  56. int32_t LAN8742_RegisterBusIO(lan8742_Object_t *pObj, lan8742_IOCtx_t *ioctx)
  57. {
  58. if(!pObj || !ioctx->ReadReg || !ioctx->WriteReg || !ioctx->GetTick)
  59. {
  60. return LAN8742_STATUS_ERROR;
  61. }
  62. pObj->IO.Init = ioctx->Init;
  63. pObj->IO.DeInit = ioctx->DeInit;
  64. pObj->IO.ReadReg = ioctx->ReadReg;
  65. pObj->IO.WriteReg = ioctx->WriteReg;
  66. pObj->IO.GetTick = ioctx->GetTick;
  67. return LAN8742_STATUS_OK;
  68. }
  69. /**
  70. * @brief Initialize the lan8742 and configure the needed hardware resources
  71. * @param pObj: device object LAN8742_Object_t.
  72. * @retval LAN8742_STATUS_OK if OK
  73. * LAN8742_STATUS_ADDRESS_ERROR if cannot find device address
  74. * LAN8742_STATUS_READ_ERROR if connot read register
  75. * LAN8742_STATUS_WRITE_ERROR if connot write to register
  76. * LAN8742_STATUS_RESET_TIMEOUT if cannot perform a software reset
  77. */
  78. int32_t LAN8742_Init(lan8742_Object_t *pObj)
  79. {
  80. uint32_t tickstart = 0, regvalue = 0, addr = 0;
  81. int32_t status = LAN8742_STATUS_OK;
  82. if(pObj->Is_Initialized == 0)
  83. {
  84. if(pObj->IO.Init != 0)
  85. {
  86. /* GPIO and Clocks initialization */
  87. pObj->IO.Init();
  88. }
  89. /* for later check */
  90. pObj->DevAddr = LAN8742_MAX_DEV_ADDR + 1;
  91. /* Get the device address from special mode register */
  92. for(addr = 0; addr <= LAN8742_MAX_DEV_ADDR; addr ++)
  93. {
  94. if(pObj->IO.ReadReg(addr, LAN8742_SMR, &regvalue) < 0)
  95. {
  96. status = LAN8742_STATUS_READ_ERROR;
  97. /* Can't read from this device address
  98. continue with next address */
  99. continue;
  100. }
  101. if((regvalue & LAN8742_SMR_PHY_ADDR) == addr)
  102. {
  103. pObj->DevAddr = addr;
  104. status = LAN8742_STATUS_OK;
  105. break;
  106. }
  107. }
  108. if(pObj->DevAddr > LAN8742_MAX_DEV_ADDR)
  109. {
  110. status = LAN8742_STATUS_ADDRESS_ERROR;
  111. }
  112. /* if device address is matched */
  113. if(status == LAN8742_STATUS_OK)
  114. {
  115. /* set a software reset */
  116. if(pObj->IO.WriteReg(pObj->DevAddr, LAN8742_BCR, LAN8742_BCR_SOFT_RESET) >= 0)
  117. {
  118. /* get software reset status */
  119. if(pObj->IO.ReadReg(pObj->DevAddr, LAN8742_BCR, &regvalue) >= 0)
  120. {
  121. tickstart = pObj->IO.GetTick();
  122. /* wait until software reset is done or timeout occured */
  123. while(regvalue & LAN8742_BCR_SOFT_RESET)
  124. {
  125. if((pObj->IO.GetTick() - tickstart) <= LAN8742_SW_RESET_TO)
  126. {
  127. if(pObj->IO.ReadReg(pObj->DevAddr, LAN8742_BCR, &regvalue) < 0)
  128. {
  129. status = LAN8742_STATUS_READ_ERROR;
  130. break;
  131. }
  132. }
  133. else
  134. {
  135. status = LAN8742_STATUS_RESET_TIMEOUT;
  136. break;
  137. }
  138. }
  139. }
  140. else
  141. {
  142. status = LAN8742_STATUS_READ_ERROR;
  143. }
  144. }
  145. else
  146. {
  147. status = LAN8742_STATUS_WRITE_ERROR;
  148. }
  149. }
  150. }
  151. if(status == LAN8742_STATUS_OK)
  152. {
  153. tickstart = pObj->IO.GetTick();
  154. /* Wait for 2s to perform initialization */
  155. while((pObj->IO.GetTick() - tickstart) <= LAN8742_INIT_TO)
  156. {
  157. }
  158. pObj->Is_Initialized = 1;
  159. }
  160. return status;
  161. }
  162. /**
  163. * @brief De-Initialize the lan8742 and it's hardware resources
  164. * @param pObj: device object LAN8742_Object_t.
  165. * @retval None
  166. */
  167. int32_t LAN8742_DeInit(lan8742_Object_t *pObj)
  168. {
  169. if(pObj->Is_Initialized)
  170. {
  171. if(pObj->IO.DeInit != 0)
  172. {
  173. if(pObj->IO.DeInit() < 0)
  174. {
  175. return LAN8742_STATUS_ERROR;
  176. }
  177. }
  178. pObj->Is_Initialized = 0;
  179. }
  180. return LAN8742_STATUS_OK;
  181. }
  182. /**
  183. * @brief Disable the LAN8742 power down mode.
  184. * @param pObj: device object LAN8742_Object_t.
  185. * @retval LAN8742_STATUS_OK if OK
  186. * LAN8742_STATUS_READ_ERROR if connot read register
  187. * LAN8742_STATUS_WRITE_ERROR if connot write to register
  188. */
  189. int32_t LAN8742_DisablePowerDownMode(lan8742_Object_t *pObj)
  190. {
  191. uint32_t readval = 0;
  192. int32_t status = LAN8742_STATUS_OK;
  193. if(pObj->IO.ReadReg(pObj->DevAddr, LAN8742_BCR, &readval) >= 0)
  194. {
  195. readval &= ~LAN8742_BCR_POWER_DOWN;
  196. /* Apply configuration */
  197. if(pObj->IO.WriteReg(pObj->DevAddr, LAN8742_BCR, readval) < 0)
  198. {
  199. status = LAN8742_STATUS_WRITE_ERROR;
  200. }
  201. }
  202. else
  203. {
  204. status = LAN8742_STATUS_READ_ERROR;
  205. }
  206. return status;
  207. }
  208. /**
  209. * @brief Enable the LAN8742 power down mode.
  210. * @param pObj: device object LAN8742_Object_t.
  211. * @retval LAN8742_STATUS_OK if OK
  212. * LAN8742_STATUS_READ_ERROR if connot read register
  213. * LAN8742_STATUS_WRITE_ERROR if connot write to register
  214. */
  215. int32_t LAN8742_EnablePowerDownMode(lan8742_Object_t *pObj)
  216. {
  217. uint32_t readval = 0;
  218. int32_t status = LAN8742_STATUS_OK;
  219. if(pObj->IO.ReadReg(pObj->DevAddr, LAN8742_BCR, &readval) >= 0)
  220. {
  221. readval |= LAN8742_BCR_POWER_DOWN;
  222. /* Apply configuration */
  223. if(pObj->IO.WriteReg(pObj->DevAddr, LAN8742_BCR, readval) < 0)
  224. {
  225. status = LAN8742_STATUS_WRITE_ERROR;
  226. }
  227. }
  228. else
  229. {
  230. status = LAN8742_STATUS_READ_ERROR;
  231. }
  232. return status;
  233. }
  234. /**
  235. * @brief Start the auto negotiation process.
  236. * @param pObj: device object LAN8742_Object_t.
  237. * @retval LAN8742_STATUS_OK if OK
  238. * LAN8742_STATUS_READ_ERROR if connot read register
  239. * LAN8742_STATUS_WRITE_ERROR if connot write to register
  240. */
  241. int32_t LAN8742_StartAutoNego(lan8742_Object_t *pObj)
  242. {
  243. uint32_t readval = 0;
  244. int32_t status = LAN8742_STATUS_OK;
  245. if(pObj->IO.ReadReg(pObj->DevAddr, LAN8742_BCR, &readval) >= 0)
  246. {
  247. readval |= LAN8742_BCR_AUTONEGO_EN;
  248. /* Apply configuration */
  249. if(pObj->IO.WriteReg(pObj->DevAddr, LAN8742_BCR, readval) < 0)
  250. {
  251. status = LAN8742_STATUS_WRITE_ERROR;
  252. }
  253. }
  254. else
  255. {
  256. status = LAN8742_STATUS_READ_ERROR;
  257. }
  258. return status;
  259. }
  260. /**
  261. * @brief Get the link state of LAN8742 device.
  262. * @param pObj: Pointer to device object.
  263. * @param pLinkState: Pointer to link state
  264. * @retval LAN8742_STATUS_LINK_DOWN if link is down
  265. * LAN8742_STATUS_AUTONEGO_NOTDONE if Auto nego not completed
  266. * LAN8742_STATUS_100MBITS_FULLDUPLEX if 100Mb/s FD
  267. * LAN8742_STATUS_100MBITS_HALFDUPLEX if 100Mb/s HD
  268. * LAN8742_STATUS_10MBITS_FULLDUPLEX if 10Mb/s FD
  269. * LAN8742_STATUS_10MBITS_HALFDUPLEX if 10Mb/s HD
  270. * LAN8742_STATUS_READ_ERROR if connot read register
  271. * LAN8742_STATUS_WRITE_ERROR if connot write to register
  272. */
  273. int32_t LAN8742_GetLinkState(lan8742_Object_t *pObj)
  274. {
  275. uint32_t readval = 0;
  276. /* Read Status register */
  277. if(pObj->IO.ReadReg(pObj->DevAddr, LAN8742_BSR, &readval) < 0)
  278. {
  279. return LAN8742_STATUS_READ_ERROR;
  280. }
  281. /* Read Status register again */
  282. if(pObj->IO.ReadReg(pObj->DevAddr, LAN8742_BSR, &readval) < 0)
  283. {
  284. return LAN8742_STATUS_READ_ERROR;
  285. }
  286. if((readval & LAN8742_BSR_LINK_STATUS) == 0)
  287. {
  288. /* Return Link Down status */
  289. return LAN8742_STATUS_LINK_DOWN;
  290. }
  291. /* Check Auto negotiaition */
  292. if(pObj->IO.ReadReg(pObj->DevAddr, LAN8742_BCR, &readval) < 0)
  293. {
  294. return LAN8742_STATUS_READ_ERROR;
  295. }
  296. if((readval & LAN8742_BCR_AUTONEGO_EN) != LAN8742_BCR_AUTONEGO_EN)
  297. {
  298. if(((readval & LAN8742_BCR_SPEED_SELECT) == LAN8742_BCR_SPEED_SELECT) && ((readval & LAN8742_BCR_DUPLEX_MODE) == LAN8742_BCR_DUPLEX_MODE))
  299. {
  300. return LAN8742_STATUS_100MBITS_FULLDUPLEX;
  301. }
  302. else if ((readval & LAN8742_BCR_SPEED_SELECT) == LAN8742_BCR_SPEED_SELECT)
  303. {
  304. return LAN8742_STATUS_100MBITS_HALFDUPLEX;
  305. }
  306. else if ((readval & LAN8742_BCR_DUPLEX_MODE) == LAN8742_BCR_DUPLEX_MODE)
  307. {
  308. return LAN8742_STATUS_10MBITS_FULLDUPLEX;
  309. }
  310. else
  311. {
  312. return LAN8742_STATUS_10MBITS_HALFDUPLEX;
  313. }
  314. }
  315. else /* Auto Nego enabled */
  316. {
  317. if(pObj->IO.ReadReg(pObj->DevAddr, LAN8742_PHYSCSR, &readval) < 0)
  318. {
  319. return LAN8742_STATUS_READ_ERROR;
  320. }
  321. /* Check if auto nego not done */
  322. if((readval & LAN8742_PHYSCSR_AUTONEGO_DONE) == 0)
  323. {
  324. return LAN8742_STATUS_AUTONEGO_NOTDONE;
  325. }
  326. if((readval & LAN8742_PHYSCSR_HCDSPEEDMASK) == LAN8742_PHYSCSR_100BTX_FD)
  327. {
  328. return LAN8742_STATUS_100MBITS_FULLDUPLEX;
  329. }
  330. else if ((readval & LAN8742_PHYSCSR_HCDSPEEDMASK) == LAN8742_PHYSCSR_100BTX_HD)
  331. {
  332. return LAN8742_STATUS_100MBITS_HALFDUPLEX;
  333. }
  334. else if ((readval & LAN8742_PHYSCSR_HCDSPEEDMASK) == LAN8742_PHYSCSR_10BT_FD)
  335. {
  336. return LAN8742_STATUS_10MBITS_FULLDUPLEX;
  337. }
  338. else
  339. {
  340. return LAN8742_STATUS_10MBITS_HALFDUPLEX;
  341. }
  342. }
  343. }
  344. /**
  345. * @brief Set the link state of LAN8742 device.
  346. * @param pObj: Pointer to device object.
  347. * @param pLinkState: link state can be one of the following
  348. * LAN8742_STATUS_100MBITS_FULLDUPLEX if 100Mb/s FD
  349. * LAN8742_STATUS_100MBITS_HALFDUPLEX if 100Mb/s HD
  350. * LAN8742_STATUS_10MBITS_FULLDUPLEX if 10Mb/s FD
  351. * LAN8742_STATUS_10MBITS_HALFDUPLEX if 10Mb/s HD
  352. * @retval LAN8742_STATUS_OK if OK
  353. * LAN8742_STATUS_ERROR if parameter error
  354. * LAN8742_STATUS_READ_ERROR if connot read register
  355. * LAN8742_STATUS_WRITE_ERROR if connot write to register
  356. */
  357. int32_t LAN8742_SetLinkState(lan8742_Object_t *pObj, uint32_t LinkState)
  358. {
  359. uint32_t bcrvalue = 0;
  360. int32_t status = LAN8742_STATUS_OK;
  361. if(pObj->IO.ReadReg(pObj->DevAddr, LAN8742_BCR, &bcrvalue) >= 0)
  362. {
  363. /* Disable link config (Auto nego, speed and duplex) */
  364. bcrvalue &= ~(LAN8742_BCR_AUTONEGO_EN | LAN8742_BCR_SPEED_SELECT | LAN8742_BCR_DUPLEX_MODE);
  365. if(LinkState == LAN8742_STATUS_100MBITS_FULLDUPLEX)
  366. {
  367. bcrvalue |= (LAN8742_BCR_SPEED_SELECT | LAN8742_BCR_DUPLEX_MODE);
  368. }
  369. else if (LinkState == LAN8742_STATUS_100MBITS_HALFDUPLEX)
  370. {
  371. bcrvalue |= LAN8742_BCR_SPEED_SELECT;
  372. }
  373. else if (LinkState == LAN8742_STATUS_10MBITS_FULLDUPLEX)
  374. {
  375. bcrvalue |= LAN8742_BCR_DUPLEX_MODE;
  376. }
  377. else
  378. {
  379. /* Wrong link status parameter */
  380. status = LAN8742_STATUS_ERROR;
  381. }
  382. }
  383. else
  384. {
  385. status = LAN8742_STATUS_READ_ERROR;
  386. }
  387. if(status == LAN8742_STATUS_OK)
  388. {
  389. /* Apply configuration */
  390. if(pObj->IO.WriteReg(pObj->DevAddr, LAN8742_BCR, bcrvalue) < 0)
  391. {
  392. status = LAN8742_STATUS_WRITE_ERROR;
  393. }
  394. }
  395. return status;
  396. }
  397. /**
  398. * @brief Enable loopback mode.
  399. * @param pObj: Pointer to device object.
  400. * @retval LAN8742_STATUS_OK if OK
  401. * LAN8742_STATUS_READ_ERROR if connot read register
  402. * LAN8742_STATUS_WRITE_ERROR if connot write to register
  403. */
  404. int32_t LAN8742_EnableLoopbackMode(lan8742_Object_t *pObj)
  405. {
  406. uint32_t readval = 0;
  407. int32_t status = LAN8742_STATUS_OK;
  408. if(pObj->IO.ReadReg(pObj->DevAddr, LAN8742_BCR, &readval) >= 0)
  409. {
  410. readval |= LAN8742_BCR_LOOPBACK;
  411. /* Apply configuration */
  412. if(pObj->IO.WriteReg(pObj->DevAddr, LAN8742_BCR, readval) < 0)
  413. {
  414. status = LAN8742_STATUS_WRITE_ERROR;
  415. }
  416. }
  417. else
  418. {
  419. status = LAN8742_STATUS_READ_ERROR;
  420. }
  421. return status;
  422. }
  423. /**
  424. * @brief Disable loopback mode.
  425. * @param pObj: Pointer to device object.
  426. * @retval LAN8742_STATUS_OK if OK
  427. * LAN8742_STATUS_READ_ERROR if connot read register
  428. * LAN8742_STATUS_WRITE_ERROR if connot write to register
  429. */
  430. int32_t LAN8742_DisableLoopbackMode(lan8742_Object_t *pObj)
  431. {
  432. uint32_t readval = 0;
  433. int32_t status = LAN8742_STATUS_OK;
  434. if(pObj->IO.ReadReg(pObj->DevAddr, LAN8742_BCR, &readval) >= 0)
  435. {
  436. readval &= ~LAN8742_BCR_LOOPBACK;
  437. /* Apply configuration */
  438. if(pObj->IO.WriteReg(pObj->DevAddr, LAN8742_BCR, readval) < 0)
  439. {
  440. status = LAN8742_STATUS_WRITE_ERROR;
  441. }
  442. }
  443. else
  444. {
  445. status = LAN8742_STATUS_READ_ERROR;
  446. }
  447. return status;
  448. }
  449. /**
  450. * @brief Enable IT source.
  451. * @param pObj: Pointer to device object.
  452. * @param Interrupt: IT source to be enabled
  453. * should be a value or a combination of the following:
  454. * LAN8742_WOL_IT
  455. * LAN8742_ENERGYON_IT
  456. * LAN8742_AUTONEGO_COMPLETE_IT
  457. * LAN8742_REMOTE_FAULT_IT
  458. * LAN8742_LINK_DOWN_IT
  459. * LAN8742_AUTONEGO_LP_ACK_IT
  460. * LAN8742_PARALLEL_DETECTION_FAULT_IT
  461. * LAN8742_AUTONEGO_PAGE_RECEIVED_IT
  462. * @retval LAN8742_STATUS_OK if OK
  463. * LAN8742_STATUS_READ_ERROR if connot read register
  464. * LAN8742_STATUS_WRITE_ERROR if connot write to register
  465. */
  466. int32_t LAN8742_EnableIT(lan8742_Object_t *pObj, uint32_t Interrupt)
  467. {
  468. uint32_t readval = 0;
  469. int32_t status = LAN8742_STATUS_OK;
  470. if(pObj->IO.ReadReg(pObj->DevAddr, LAN8742_IMR, &readval) >= 0)
  471. {
  472. readval |= Interrupt;
  473. /* Apply configuration */
  474. if(pObj->IO.WriteReg(pObj->DevAddr, LAN8742_IMR, readval) < 0)
  475. {
  476. status = LAN8742_STATUS_WRITE_ERROR;
  477. }
  478. }
  479. else
  480. {
  481. status = LAN8742_STATUS_READ_ERROR;
  482. }
  483. return status;
  484. }
  485. /**
  486. * @brief Disable IT source.
  487. * @param pObj: Pointer to device object.
  488. * @param Interrupt: IT source to be disabled
  489. * should be a value or a combination of the following:
  490. * LAN8742_WOL_IT
  491. * LAN8742_ENERGYON_IT
  492. * LAN8742_AUTONEGO_COMPLETE_IT
  493. * LAN8742_REMOTE_FAULT_IT
  494. * LAN8742_LINK_DOWN_IT
  495. * LAN8742_AUTONEGO_LP_ACK_IT
  496. * LAN8742_PARALLEL_DETECTION_FAULT_IT
  497. * LAN8742_AUTONEGO_PAGE_RECEIVED_IT
  498. * @retval LAN8742_STATUS_OK if OK
  499. * LAN8742_STATUS_READ_ERROR if connot read register
  500. * LAN8742_STATUS_WRITE_ERROR if connot write to register
  501. */
  502. int32_t LAN8742_DisableIT(lan8742_Object_t *pObj, uint32_t Interrupt)
  503. {
  504. uint32_t readval = 0;
  505. int32_t status = LAN8742_STATUS_OK;
  506. if(pObj->IO.ReadReg(pObj->DevAddr, LAN8742_IMR, &readval) >= 0)
  507. {
  508. readval &= ~Interrupt;
  509. /* Apply configuration */
  510. if(pObj->IO.WriteReg(pObj->DevAddr, LAN8742_IMR, readval) < 0)
  511. {
  512. status = LAN8742_STATUS_WRITE_ERROR;
  513. }
  514. }
  515. else
  516. {
  517. status = LAN8742_STATUS_READ_ERROR;
  518. }
  519. return status;
  520. }
  521. /**
  522. * @brief Clear IT flag.
  523. * @param pObj: Pointer to device object.
  524. * @param Interrupt: IT flag to be cleared
  525. * should be a value or a combination of the following:
  526. * LAN8742_WOL_IT
  527. * LAN8742_ENERGYON_IT
  528. * LAN8742_AUTONEGO_COMPLETE_IT
  529. * LAN8742_REMOTE_FAULT_IT
  530. * LAN8742_LINK_DOWN_IT
  531. * LAN8742_AUTONEGO_LP_ACK_IT
  532. * LAN8742_PARALLEL_DETECTION_FAULT_IT
  533. * LAN8742_AUTONEGO_PAGE_RECEIVED_IT
  534. * @retval LAN8742_STATUS_OK if OK
  535. * LAN8742_STATUS_READ_ERROR if connot read register
  536. */
  537. int32_t LAN8742_ClearIT(lan8742_Object_t *pObj, uint32_t Interrupt)
  538. {
  539. uint32_t readval = 0;
  540. int32_t status = LAN8742_STATUS_OK;
  541. if(pObj->IO.ReadReg(pObj->DevAddr, LAN8742_ISFR, &readval) < 0)
  542. {
  543. status = LAN8742_STATUS_READ_ERROR;
  544. }
  545. return status;
  546. }
  547. /**
  548. * @brief Get IT Flag status.
  549. * @param pObj: Pointer to device object.
  550. * @param Interrupt: IT Flag to be checked,
  551. * should be a value or a combination of the following:
  552. * LAN8742_WOL_IT
  553. * LAN8742_ENERGYON_IT
  554. * LAN8742_AUTONEGO_COMPLETE_IT
  555. * LAN8742_REMOTE_FAULT_IT
  556. * LAN8742_LINK_DOWN_IT
  557. * LAN8742_AUTONEGO_LP_ACK_IT
  558. * LAN8742_PARALLEL_DETECTION_FAULT_IT
  559. * LAN8742_AUTONEGO_PAGE_RECEIVED_IT
  560. * @retval 1 IT flag is SET
  561. * 0 IT flag is RESET
  562. * LAN8742_STATUS_READ_ERROR if connot read register
  563. */
  564. int32_t LAN8742_GetITStatus(lan8742_Object_t *pObj, uint32_t Interrupt)
  565. {
  566. uint32_t readval = 0;
  567. int32_t status = 0;
  568. if(pObj->IO.ReadReg(pObj->DevAddr, LAN8742_ISFR, &readval) >= 0)
  569. {
  570. status = ((readval & Interrupt) == Interrupt);
  571. }
  572. else
  573. {
  574. status = LAN8742_STATUS_READ_ERROR;
  575. }
  576. return status;
  577. }
  578. /**
  579. * @}
  580. */
  581. /**
  582. * @}
  583. */
  584. /**
  585. * @}
  586. */
  587. /**
  588. * @}
  589. */
  590. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/