diff --git a/httpd/httpd.c b/httpd/httpd.c index 78b8339..b9d6ead 100644 --- a/httpd/httpd.c +++ b/httpd/httpd.c @@ -436,6 +436,9 @@ void handle_post(void) flash_region.addr = CONFIG_START; flash_sector_erase(); } + flash_init(0); // Re-initialize flash for non-DIO operation, otherwise flashing fails + set_sys_led_state(SYS_LED_FAST); + crc_value = 0; bindex = 0; write_len = 0; diff --git a/rtl837x_common.h b/rtl837x_common.h index b51799a..0b0db2e 100644 --- a/rtl837x_common.h +++ b/rtl837x_common.h @@ -124,5 +124,6 @@ void get_random_32(void); void read_reg_timer(uint32_t * tmr); void sfp_print_info(uint8_t sfp); bool gpio_pin_test(uint8_t pin); +void set_sys_led_state(uint8_t state); #endif diff --git a/rtl837x_regs.h b/rtl837x_regs.h index 1ebd6eb..9f38fa7 100644 --- a/rtl837x_regs.h +++ b/rtl837x_regs.h @@ -9,6 +9,11 @@ #define RTL837X_REG_HW_CONF 0x6040 // Bits 4 & 5: CLOCK DIVIDER from 125MHz for Timer +#define SYS_LED_OFF 0 +#define SYS_LED_FAST 1 +#define SYS_LED_SLOW 2 +#define SYS_LED_ON 3 + #define RTL837X_REG_LED_MODE 0x6520 // Defines the LED Mode for steering the Port LEDS and the System LED // BIT 17 set: LED solid on diff --git a/rtlplayground.c b/rtlplayground.c index ba46007..041282f 100644 --- a/rtlplayground.c +++ b/rtlplayground.c @@ -1416,6 +1416,9 @@ void led_config_9xh(void) sfr_mask_data(0, 0xe0, 0xa0); reg_write_m(RTL837X_REG_LED_MODE); + // Set LED blink rate to slow during booting + set_sys_led_state(SYS_LED_SLOW); + // Disable RLDP (Realtek Loop Detection Protocol) LEDs on loop detection reg_read_m(RTL837X_REG_LED_RLDP_1); sfr_mask_data(0, 0, 0x3); @@ -1442,6 +1445,12 @@ void led_config_9xh(void) reg_write_m(RTL837X_REG_LED3_0_SET1); } +void set_sys_led_state(uint8_t state) +{ + reg_read_m(RTL837X_REG_LED_MODE); + sfr_mask_data(2, 0x03, state); + reg_write_m(RTL837X_REG_LED_MODE); +} void led_config(void) { @@ -1794,7 +1803,7 @@ void bootloader(void) // Flash controller should be initialized before any code in other banks is being fetched // See this issue: https://github.com/logicog/RTLPlayground/issues/70 print_string("\nInitializing Flash controller\n"); - flash_init(0); + flash_init(1); // Set default for SFP pins so we can start up a module already inserted sfp_pins_last = 0x33; // signal LOS and no module inserted (for both slots, even if only 1 present) @@ -1850,6 +1859,9 @@ void bootloader(void) __xdata uint8_t * __xdata bptr; print_string("Identified update image. Checking integrity..."); + flash_init(0); // Re-initialize flash for non-DIO operation, otherwise flashing will fail + set_sys_led_state(SYS_LED_FAST); + crc_value = 0x0000; for (i = 0; i < 1024; i++) { flash_region.addr = source; @@ -1910,6 +1922,8 @@ void bootloader(void) } } + set_sys_led_state(SYS_LED_SLOW); + #ifdef DEBUG // This register seems to work on the RTL8373 only if also the SDS // Is correctly configured. Therefore, we can test it, here... @@ -1955,6 +1969,8 @@ void bootloader(void) print_string("\n> "); idle_ready = 1; + set_sys_led_state(SYS_LED_ON); + // Wait for commands on serial connection // sbuf_ptr is moved forward by serial interrupt, l is the position until we have already // printed out the entered characters