-
-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
149 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,26 @@ | ||
/* | ||
* emac.h | ||
/** | ||
* @file emac.h | ||
* | ||
*/ | ||
/* Copyright (C) 2024 by Arjan van Vught mailto:[email protected] | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
|
||
#ifndef EMAC_EMAC_H_ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
* @file phy.h | ||
* | ||
*/ | ||
/* Copyright (C) 2023 by Arjan van Vught mailto:[email protected] | ||
/* Copyright (C) 2023-2024 by Arjan van Vught mailto:[email protected] | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
|
@@ -30,7 +30,7 @@ | |
|
||
namespace net { | ||
enum class Link { | ||
STATE_UP, STATE_DOWN | ||
STATE_DOWN, STATE_UP | ||
}; | ||
|
||
enum class Duplex { | ||
|
@@ -59,6 +59,7 @@ struct PhyIdentifier { | |
*/ | ||
|
||
bool phy_get_id(const uint32_t nAddress, PhyIdentifier& phyIdentifier); | ||
Link phy_get_link(const uint32_t nAddress); | ||
|
||
/** | ||
* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ | |
|
||
#include <cstdint> | ||
|
||
#include "emac/phy.h" | ||
#include "emac/net_link_check.h" | ||
|
||
#include "gd32.h" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
* @file emac.cpp | ||
* | ||
*/ | ||
/* Copyright (C) 2018-2023 by Arjan van Vught mailto:[email protected] | ||
/* Copyright (C) 2018-2024 by Arjan van Vught mailto:[email protected] | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
|
@@ -54,30 +54,30 @@ | |
|
||
coherent_region *p_coherent_region = nullptr; | ||
|
||
static void adjust_link(bool duplex, uint32_t speed) { | ||
void emac_adjust_link(const net::PhyStatus phyStatus) { | ||
DEBUG_ENTRY | ||
DEBUG_PRINTF("duplex=%u, speed=%u", duplex, speed); | ||
|
||
uint32_t value = H3_EMAC->CTL0; | ||
printf("Link %s, %d, %s\n", | ||
phyStatus.link == net::Link::STATE_UP ? "Up" : "Down", | ||
phyStatus.speed == net::Speed::SPEED10 ? 10 : 100, | ||
phyStatus.duplex == net::Duplex::DUPLEX_HALF ? "HALF" : "FULL"); | ||
|
||
auto value = H3_EMAC->CTL0; | ||
|
||
if (duplex) { | ||
if (phyStatus.duplex == net::Duplex::DUPLEX_FULL) { | ||
value |= CTL0_DUPLEX_FULL_DUPLEX; | ||
} else { | ||
value &= (uint32_t)~CTL0_DUPLEX_FULL_DUPLEX; | ||
} | ||
|
||
value &= (uint32_t)~(CTL0_SPEED_MASK << CTL0_SPEED_SHIFT); | ||
|
||
switch (speed) { | ||
case 1000: | ||
break; | ||
case 100: | ||
value |= CTL0_SPEED_100M; | ||
break; | ||
case 10: | ||
switch (phyStatus.speed) { | ||
case net::Speed::SPEED10: | ||
value |= CTL0_SPEED_10M; | ||
break; | ||
default: | ||
value |= CTL0_SPEED_100M; | ||
break; | ||
} | ||
|
||
|
@@ -171,15 +171,7 @@ void __attribute__((cold)) emac_start(uint8_t macAddress[], net::Link& link) { | |
|
||
link = phyStatus.link; | ||
|
||
const bool fullDuplex = (phyStatus.duplex == net::Duplex::DUPLEX_FULL); | ||
const uint32_t speed = (phyStatus.speed == net::Speed::SPEED10 ? 10 : 100); | ||
|
||
DEBUG_PRINTF("%s, %d, %s", | ||
phyStatus.link == net::Link::STATE_UP ? "Up" : "Down", | ||
speed == 10 ? 10 : 100, | ||
fullDuplex ? "FULL" : "HALF" ); | ||
|
||
adjust_link(fullDuplex, speed); | ||
emac_adjust_link(phyStatus); | ||
|
||
#ifndef NDEBUG | ||
printf("sizeof(struct coherent_region)=%u\n", sizeof(struct coherent_region)); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
* link_handle_change.cpp | ||
* | ||
*/ | ||
/* Copyright (C) 2022 by Arjan van Vught mailto:[email protected] | ||
/* Copyright (C) 2022-2024 by Arjan van Vught mailto:[email protected] | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
|
@@ -23,22 +23,40 @@ | |
* THE SOFTWARE. | ||
*/ | ||
|
||
#include "hardware.h" | ||
#include "network.h" | ||
|
||
#include "debug.h" | ||
|
||
/** | ||
* Default implementation | ||
*/ | ||
#if !defined(PHY_ADDRESS) | ||
# define PHY_ADDRESS 1 | ||
#endif | ||
|
||
extern void emac_adjust_link(const net::PhyStatus); | ||
|
||
namespace net { | ||
void __attribute__((weak)) link_handle_change(const net::Link state) { | ||
void link_handle_change(const net::Link state) { | ||
DEBUG_PRINTF("net::Link %s", state == net::Link::STATE_UP ? "UP" : "DOWN"); | ||
|
||
if (net::Link::STATE_UP == state) { | ||
if (Network::Get()->IsDhcpUsed()) { | ||
DEBUG_PUTS("Enable DHCP"); | ||
Network::Get()->EnableDhcp(); | ||
const bool isWatchdog = Hardware::Get()->IsWatchdog(); | ||
if (isWatchdog) { | ||
Hardware::Get()->WatchdogStop(); | ||
} | ||
|
||
net::PhyStatus phyStatus; | ||
net::phy_start(PHY_ADDRESS, phyStatus); | ||
|
||
emac_adjust_link(phyStatus); | ||
|
||
Network::Get()->Start(net::Link::STATE_UP); | ||
|
||
network::mdns_announcement(); | ||
|
||
Network::Get()->Print(); | ||
|
||
if (isWatchdog) { | ||
Hardware::Get()->WatchdogInit(); | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
* net_link_check.cpp | ||
* | ||
*/ | ||
/* Copyright (C) 2022-2023 by Arjan van Vught mailto:[email protected] | ||
/* Copyright (C) 2022-2024 by Arjan van Vught mailto:[email protected] | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
|
@@ -48,13 +48,6 @@ void link_pin_poll_init() { | |
#endif | ||
|
||
net::Link link_status_read() { | ||
uint16_t nValue = 0; | ||
phy_read(PHY_ADDRESS, mmi::REG_BMSR, nValue); | ||
|
||
if (mmi::BMSR_LINKED_STATUS == (nValue & mmi::BMSR_LINKED_STATUS)) { | ||
return net::Link::STATE_UP; | ||
} | ||
|
||
return net::Link::STATE_DOWN; | ||
return net::phy_get_link(PHY_ADDRESS); | ||
} | ||
} // namespace net |
Oops, something went wrong.