mirror of
https://github.com/logicog/RTLPlayground.git
synced 2026-08-30 14:52:51 +08:00
Use machine structure
This commit is contained in:
+42
-51
@@ -15,6 +15,9 @@
|
||||
#include "uip/uipopt.h"
|
||||
#include "uip/uip.h"
|
||||
#include "uip/uip_arp.h"
|
||||
#include "machine.h"
|
||||
|
||||
extern __code struct machine machine;
|
||||
|
||||
extern __xdata uint16_t crc_value;
|
||||
__xdata uint8_t crc_testbytes[10];
|
||||
@@ -56,8 +59,6 @@ __code struct uip_eth_addr uip_ethaddr = {{ 0x1c, 0x2a, 0xa3, 0x23, 0x00, 0x02 }
|
||||
__code uint8_t gatewayIP[] = { 192, 168, 2, 22};
|
||||
__code uint8_t netmask[] = { 255, 255, 255, 0};
|
||||
|
||||
__xdata uint8_t isRTL8373;
|
||||
|
||||
volatile __xdata uint32_t ticks;
|
||||
volatile __xdata uint8_t sec_counter;
|
||||
volatile __xdata uint16_t sleep_ticks;
|
||||
@@ -87,10 +88,6 @@ __xdata uint8_t uip_buf[UIP_CONF_BUFFER_SIZE+2];
|
||||
__xdata uint16_t rx_packet_vlan;
|
||||
__xdata uint8_t tx_seq;
|
||||
|
||||
__xdata uint8_t minPort;
|
||||
__xdata uint8_t maxPort;
|
||||
__xdata uint8_t nSFPPorts;
|
||||
__xdata uint8_t cpuPort;
|
||||
__xdata uint8_t stpEnabled;
|
||||
|
||||
__code uint16_t bit_mask[16] = {
|
||||
@@ -633,7 +630,7 @@ void sds_config_mac(uint8_t sds, uint8_t mode)
|
||||
case 2:
|
||||
sfr_mask_data(1, 0xfc, 0x02 << 2);
|
||||
}
|
||||
if (isRTL8373) // Set 3rd SERDES Mode to 0x2 for RTL8224
|
||||
if (machine.isRTL8373) // Set 3rd SERDES Mode to 0x2 for RTL8224
|
||||
sfr_mask_data(1, 0xfc, 0x02 << 2);
|
||||
else
|
||||
sfr_data[2] &= 0x03;
|
||||
@@ -950,36 +947,36 @@ void handle_sfp(void)
|
||||
sfp_pins_last |= 0x02;
|
||||
print_string("\n<SFP-RX LOS>\n");
|
||||
}
|
||||
#if NSFP == 2
|
||||
reg_read_m(RTL837X_REG_GPIO_32_63_INPUT);
|
||||
if ((sfp_pins_last & 0x10) && (!(sfr_data[1] & 0x04))) {
|
||||
sfp_pins_last &= ~0x10;
|
||||
print_string("\n<MODULE 2 INSERTED> ");
|
||||
// Read Reg 11: Encoding, see SFF-8472 and SFF-8024
|
||||
// Read Reg 12: Signalling rate (including overhead) in 100Mbit: 0xd: 1Gbit, 0x67:10Gbit
|
||||
delay(100); // Delay, because some modules need time to wake up
|
||||
uint8_t rate = sfp_read_reg(1, 12);
|
||||
print_string("Rate: "); print_byte(rate); // Normally 1, but 0 for DAC, can be ignored?
|
||||
print_string(" Encoding: "); print_byte(sfp_read_reg(1, 11));
|
||||
print_string("\n");
|
||||
sfp_print_info(1);
|
||||
sds_config(0, sfp_rate_to_sds_config(rate));
|
||||
}
|
||||
if ((!(sfp_pins_last & 0x10)) && (sfr_data[1] & 0x04)) {
|
||||
sfp_pins_last |= 0x10;
|
||||
print_string("\n<MODULE 2 REMOVED>\n");
|
||||
}
|
||||
if (machine.n_sfp == 2) {
|
||||
reg_read_m(RTL837X_REG_GPIO_32_63_INPUT);
|
||||
if ((sfp_pins_last & 0x10) && (!(sfr_data[1] & 0x04))) {
|
||||
sfp_pins_last &= ~0x10;
|
||||
print_string("\n<MODULE 2 INSERTED> ");
|
||||
// Read Reg 11: Encoding, see SFF-8472 and SFF-8024
|
||||
// Read Reg 12: Signalling rate (including overhead) in 100Mbit: 0xd: 1Gbit, 0x67:10Gbit
|
||||
delay(100); // Delay, because some modules need time to wake up
|
||||
uint8_t rate = sfp_read_reg(1, 12);
|
||||
print_string("Rate: "); print_byte(rate); // Normally 1, but 0 for DAC, can be ignored?
|
||||
print_string(" Encoding: "); print_byte(sfp_read_reg(1, 11));
|
||||
print_string("\n");
|
||||
sfp_print_info(1);
|
||||
sds_config(0, sfp_rate_to_sds_config(rate));
|
||||
}
|
||||
if ((!(sfp_pins_last & 0x10)) && (sfr_data[1] & 0x04)) {
|
||||
sfp_pins_last |= 0x10;
|
||||
print_string("\n<MODULE 2 REMOVED>\n");
|
||||
}
|
||||
|
||||
reg_read_m(RTL837X_REG_GPIO_00_31_INPUT);
|
||||
if ((sfp_pins_last & 0x20) && (!(sfr_data[2] & 0x08))) {
|
||||
sfp_pins_last &= ~0x20;
|
||||
print_string("\n<SFP2-RX OK>\n");
|
||||
reg_read_m(RTL837X_REG_GPIO_00_31_INPUT);
|
||||
if ((sfp_pins_last & 0x20) && (!(sfr_data[2] & 0x08))) {
|
||||
sfp_pins_last &= ~0x20;
|
||||
print_string("\n<SFP2-RX OK>\n");
|
||||
}
|
||||
if ((!(sfp_pins_last & 0x20)) && (sfr_data[2] & 0x08)) {
|
||||
sfp_pins_last |= 0x20;
|
||||
print_string("\n<SFP2-RX LOS>\n");
|
||||
}
|
||||
}
|
||||
if ((!(sfp_pins_last & 0x20)) && (sfr_data[2] & 0x08)) {
|
||||
sfp_pins_last |= 0x20;
|
||||
print_string("\n<SFP2-RX LOS>\n");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -1035,7 +1032,7 @@ void idle(void)
|
||||
print_byte(linkbits_last[2]); print_byte(linkbits_last[3]);
|
||||
print_string(">\n");
|
||||
linkbits_last_p89 = linkbits_p89;
|
||||
if (!isRTL8373 && nSFPPorts != 2) {
|
||||
if (!machine.isRTL8373 && machine.n_sfp != 2) {
|
||||
uint8_t p5 = sfr_data[2] >> 4;
|
||||
uint8_t p5_last = linkbits_last[2] >> 4;
|
||||
cpy_4(linkbits_last, sfr_data);
|
||||
@@ -1420,7 +1417,7 @@ void led_config(void)
|
||||
reg_bit_clear(0x65dc, 0x1b);
|
||||
|
||||
// Set bits 1b/1d of 0x7f8c: r7f8c:30000000 R7f8c-30000000 r7f8c:30000000 R7f8c-38000000
|
||||
if (nSFPPorts == 2) {
|
||||
if (machine.n_sfp == 2) {
|
||||
reg_bit_set(RTL837X_PIN_MUX_0, 0x1b); // R7f8c-28000000
|
||||
reg_bit_clear(RTL837X_PIN_MUX_0, 0x1c); // R7f8c-28000000
|
||||
reg_bit_set(RTL837X_PIN_MUX_0, 0x1d); // R7f8c-28000000
|
||||
@@ -1481,10 +1478,6 @@ void rtl8373_revision(void)
|
||||
void rtl8373_init(void)
|
||||
{
|
||||
print_string("\nrtl8373_init called\n");
|
||||
minPort = 0;
|
||||
maxPort = 8;
|
||||
cpuPort = 9;
|
||||
nSFPPorts = 1;
|
||||
|
||||
// r6330:00015555 R6330-00005555 r6330:00005555 R6330-00005555
|
||||
REG_SET(0x6330, 0x00005555);
|
||||
@@ -1584,21 +1577,17 @@ void rtl8373_init(void)
|
||||
void rtl8372_init(void)
|
||||
{
|
||||
print_string("\nrtl8372_init called\n");
|
||||
minPort = 3;
|
||||
maxPort = 8;
|
||||
cpuPort = 9;
|
||||
nSFPPorts = NSFP;
|
||||
|
||||
// r6330:00015555 R6330-00005555 r6330:00005555 R6330-00005555
|
||||
REG_SET(0x6330, 0x00005555);
|
||||
if (nSFPPorts == 2) {
|
||||
if (machine.n_sfp == 2) {
|
||||
print_string("Configuring 2nd SFP+ port\n");
|
||||
REG_SET(0x6330, 0x00005515);
|
||||
}
|
||||
|
||||
// r6334:00000000 R6334-000001f8 RTL8373: r6334:00000000 R6334-000000ff
|
||||
reg_read_m(0x6334); // Also in sdsMode_set
|
||||
if (nSFPPorts == 2) {
|
||||
if (machine.n_sfp == 2) {
|
||||
sfr_mask_data(0, 0, 0xf0);
|
||||
} else {
|
||||
sfr_mask_data(1, 0, 0x01); // Set bits 3-8, On RTL8373+8224 set bits 0-7
|
||||
@@ -1643,7 +1632,7 @@ void rtl8372_init(void)
|
||||
// [...]
|
||||
///
|
||||
uint16_t reg = 0x1238 + 0x300; // Port base register for the bits we set
|
||||
for (char i = minPort; i <= maxPort; i++) {
|
||||
for (char i = machine.min_port; i <= machine.max_port; i++) {
|
||||
// Bit 7 (0x40) enables replacement of the RTL-VLAN tag with an 802.1Q VLAN tag
|
||||
REG_SET(reg, 0xe77);
|
||||
reg += 0x100;
|
||||
@@ -1745,14 +1734,16 @@ void bootloader(void)
|
||||
linkbits_last[0] = linkbits_last[1] = linkbits_last[2] = linkbits_last[3] = linkbits_last_p89 = 0;
|
||||
|
||||
print_string("Detecting CPU: ");
|
||||
isRTL8373 = 0;
|
||||
reg_read_m(0x4);
|
||||
if (sfr_data[1] == 0x73) { // Register was 0x83730000
|
||||
print_string("RTL8373\n");
|
||||
isRTL8373 = 1;
|
||||
if (!machine.isRTL8373)
|
||||
print_string("INCORRECT MACHINE!");
|
||||
rtl8224_enable(); // Power on the RTL8224
|
||||
} else {
|
||||
print_string("RTL8372\n");
|
||||
if (machine.isRTL8373)
|
||||
print_string("INCORRECT MACHINE!");
|
||||
}
|
||||
|
||||
// Print SW version
|
||||
@@ -1774,7 +1765,7 @@ void bootloader(void)
|
||||
uip_ipaddr(&uip_netmask, netmask[0], netmask[1], netmask[2], netmask[3]);
|
||||
|
||||
REG_SET(0x7f94, 0x0);
|
||||
if (isRTL8373)
|
||||
if (machine.isRTL8373)
|
||||
rtl8373_init();
|
||||
else
|
||||
rtl8372_init();
|
||||
|
||||
Reference in New Issue
Block a user