diff options
author | root <root@lab.panaceas.james.local> | 2019-02-22 10:45:35 +0000 |
---|---|---|
committer | root <root@lab.panaceas.james.local> | 2019-02-22 10:45:35 +0000 |
commit | 904bc0ebdb9c059b7b1d276829bad766f73dc3e9 (patch) | |
tree | 30c01ecf79b72c6953d593d2d3dccfbcd31f76cd /app/steth.c | |
parent | e761edee5e8ef7106fc8080fc386447e7956be71 (diff) | |
download | clock-904bc0ebdb9c059b7b1d276829bad766f73dc3e9.tar.gz clock-904bc0ebdb9c059b7b1d276829bad766f73dc3e9.tar.bz2 clock-904bc0ebdb9c059b7b1d276829bad766f73dc3e9.zip |
switch to stlink, blinky
Diffstat (limited to 'app/steth.c')
-rw-r--r-- | app/steth.c | 86 |
1 files changed, 44 insertions, 42 deletions
diff --git a/app/steth.c b/app/steth.c index 2603725..ead4efd 100644 --- a/app/steth.c +++ b/app/steth.c @@ -2,10 +2,6 @@ #include "steth.h" -#define FUCKED - -static int fucked; - #define AN_RETRY 6 @@ -86,13 +82,15 @@ static void phy_stat_reg (unsigned i) if (cur == last_phy[i]) return; printf (" phy:%02x %4x (was %4x +%4x -%4x)\r\n", - i, (unsigned) cur, (unsigned) last_phy[i], + i, + (unsigned) cur, (unsigned) last_phy[i], (unsigned) ((last_phy[i] ^ cur) & cur), (unsigned) ((last_phy[i] ^ cur) & last_phy[i])); last_phy[i] = cur; } + static void phy_stat (void) { unsigned i; @@ -104,7 +102,7 @@ static void phy_stat (void) static bool phy_link_an_done (uint8_t phy) { - return eth_smi_read (PHY, PHY_REG_BSR) & PHY_REG_BSR_ANDONE; + return eth_smi_read (phy, PHY_REG_BSR) & PHY_REG_BSR_ANDONE; } @@ -197,22 +195,9 @@ steth_lwip_init (struct netif *netif) return ERR_OK; } - -#ifdef FUCKED - -static void fucked_phy_reset (uint8_t phy) -{ - unsigned i; - eth_smi_write (phy, PHY_REG_BCR, PHY_REG_BCR_RESET); - - for (i = 0; (eth_smi_read (phy, PHY_REG_BCR) & PHY_REG_BCR_RESET) && (i < 1000); ++i) delay_us (1000); - -} - -static void fucked_eth_init (uint8_t phy, enum eth_clk clock) +static void my_eth_init (uint8_t phy, enum eth_clk clock) { ETH_MACMIIAR = clock; - fucked_phy_reset (phy); ETH_MACCR = ETH_MACCR_CSTF | ETH_MACCR_FES | ETH_MACCR_DM | ETH_MACCR_APCS | ETH_MACCR_RD; @@ -227,7 +212,35 @@ static void fucked_eth_init (uint8_t phy, enum eth_clk clock) (32 << ETH_DMABMR_RDP_SHIFT) | (32 << ETH_DMABMR_PBL_SHIFT) | ETH_DMABMR_PM_2_1 | ETH_DMABMR_USP; } -#endif + + + +static void phy_set_ignore_address (void) +{ + unsigned i; + + i = 0; + + while (eth_smi_read (PHY0, 0) == 0xffff) { + delay_us (1000); + i++; + + if (i > 10) break; + } + + eth_smi_write (PHY, 0x11, 0x8); + + i = 0; + + while (eth_smi_read (PHY1, 0) == 0xffff) { + delay_us (1000); + i++; + + if (i > 10) break; + } + + eth_smi_write (PHY1, 0x11, 0x8); +} static void eth_reset (void) @@ -237,21 +250,21 @@ static void eth_reset (void) printf ("Eth_reset()\r\n"); rcc_periph_reset_hold (RST_ETHMAC); - delay_ms (1); + delay_us (1000); #ifndef SYSCFG_PMC_MII_RMII_SEL #define SYSCFG_PMC_MII_RMII_SEL (1UL << 23) #endif SYSCFG_PMC |= SYSCFG_PMC_MII_RMII_SEL; - delay_ms (1); + delay_us (1000); rcc_periph_reset_release (RST_ETHMAC); - delay_ms (1); + delay_us (1000); CLEAR (NRST); delay_us (1); SET (NRST); - delay_ms (1); + delay_us (1000); TRACE; ETH_DMABMR |= ETH_DMABMR_SR; @@ -259,7 +272,7 @@ static void eth_reset (void) i = 0; while (ETH_DMABMR & ETH_DMABMR_SR) { - delay_ms (1); + delay_us (1000); i++; if (i > 1000) { @@ -270,16 +283,9 @@ static void eth_reset (void) /*MDC = HCLK / 102 (0b100) => 1.6MHz */ TRACE; -#ifdef FUCKED - fucked_eth_init (PHY, ETH_CLK_150_168MHZ); -#else - eth_init (PHY, ETH_CLK_150_168MHZ); -#endif - if (eth_smi_read (PHY, 0) == 0xffff) { - fucked = 1; - printf ("WARNING: PHY is AWOL\r\n"); - } + my_eth_init (PHY, ETH_CLK_150_168MHZ); + phy_set_ignore_address(); TRACE; phy_stat(); @@ -364,7 +370,7 @@ steth_init (void) eth_smi_write (PHY, PHY_REG_BCR, 0x2100); printf ("Waiting for link\r\n"); - while (!phy_link_isup (PHY)) { + while (!phy_link_isup (phy)) { phy_stat(); delay_ms (1000); } @@ -373,12 +379,6 @@ steth_init (void) eth_start_an(); - if (fucked) delay_ms (1000); - - - - // - //eth_start(); nvic_enable_irq (NVIC_ETH_IRQ); @@ -389,11 +389,13 @@ steth_init (void) +#if 0 static void eth_stop (void) { ETH_MACCR &= (ETH_MACCR_TE & ETH_MACCR_RE); ETH_DMAOMR &= ~ (ETH_DMAOMR_FTF | ETH_DMAOMR_ST | ETH_DMAOMR_SR); } +#endif void steth_slow_tick (void) { |