diff options
author | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2012-04-17 07:41:20 +0000 |
---|---|---|
committer | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2012-04-17 07:41:20 +0000 |
commit | c53f70238122ce394eb45aa471feebc54515b9ca (patch) | |
tree | 4c44283877424d013eda386277bee4050575e63a /os/hal | |
parent | 82d784f49832b7cf9257eca1803b43b21af7973d (diff) | |
download | ChibiOS-c53f70238122ce394eb45aa471feebc54515b9ca.tar.gz ChibiOS-c53f70238122ce394eb45aa471feebc54515b9ca.tar.bz2 ChibiOS-c53f70238122ce394eb45aa471feebc54515b9ca.zip |
Added timeout on PHY detection setting.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4105 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os/hal')
-rw-r--r-- | os/hal/platforms/STM32/mac_lld.c | 20 | ||||
-rw-r--r-- | os/hal/platforms/STM32/mac_lld.h | 17 |
2 files changed, 31 insertions, 6 deletions
diff --git a/os/hal/platforms/STM32/mac_lld.c b/os/hal/platforms/STM32/mac_lld.c index 2ddbc885a..15f9cd13c 100644 --- a/os/hal/platforms/STM32/mac_lld.c +++ b/os/hal/platforms/STM32/mac_lld.c @@ -118,14 +118,22 @@ static uint32_t mii_read(MACDriver *macp, uint32_t reg) { static void mii_find_phy(MACDriver *macp) {
uint32_t i;
- for (i = 0; i < 31; i++) {
- macp->phyaddr = i << 11;
- ETH->MACMIIDR = (i << 6) | MACMIIDR_CR;
- if ((mii_read(macp, MII_PHYSID1) == (BOARD_PHY_ID >> 16)) &&
- ((mii_read(macp, MII_PHYSID2) & 0xFFF0) == (BOARD_PHY_ID & 0xFFF0))) {
- return;
+#if STM32_MAC_PHY_TIMEOUT > 0
+ halrtcnt_t start = halGetCounterValue();
+ halrtcnt_t timeout = start + MS2RTT(STM32_MAC_PHY_TIMEOUT);
+ while (halIsCounterWithin(start, timeout)) {
+#endif
+ for (i = 0; i < 31; i++) {
+ macp->phyaddr = i << 11;
+ ETH->MACMIIDR = (i << 6) | MACMIIDR_CR;
+ if ((mii_read(macp, MII_PHYSID1) == (BOARD_PHY_ID >> 16)) &&
+ ((mii_read(macp, MII_PHYSID2) & 0xFFF0) == (BOARD_PHY_ID & 0xFFF0))) {
+ return;
+ }
}
+#if STM32_MAC_PHY_TIMEOUT > 0
}
+#endif
/* Wrong or defective board.*/
chSysHalt();
}
diff --git a/os/hal/platforms/STM32/mac_lld.h b/os/hal/platforms/STM32/mac_lld.h index 81050053c..3bedc38a2 100644 --- a/os/hal/platforms/STM32/mac_lld.h +++ b/os/hal/platforms/STM32/mac_lld.h @@ -142,6 +142,19 @@ #endif
/**
+ * @brief PHY detection timeout.
+ * @details Timeout, in milliseconds, for PHY address detection, if a PHY
+ * is not detected within the timeout then the driver halts during
+ * initialization. This setting applies only if the PHY address is
+ * not explicitly set in the board header file using
+ * @p BOARD_PHY_ADDRESS. A zero value disables the timeout and a
+ * single search path is performed.
+ */
+#if !defined(STM32_MAC_PHY_TIMEOUT) || defined(__DOXYGEN__)
+#define STM32_MAC_PHY_TIMEOUT 100
+#endif
+
+/**
* @brief ETHD1 interrupt priority level setting.
*/
#if !defined(STM32_ETH1_IRQ_PRIORITY) || defined(__DOXYGEN__)
@@ -170,6 +183,10 @@ /* Derived constants and error checks. */
/*===========================================================================*/
+#if (STM32_MAC_PHY_TIMEOUT > 0) && !HAL_IMPLEMENTS_COUNTERS
+#error "STM32_MAC_PHY_TIMEOUT requires the realtime counter service"
+#endif
+
/*===========================================================================*/
/* Driver data structures and types. */
/*===========================================================================*/
|