mirror of
https://github.com/logicog/RTLPlayground.git
synced 2026-08-30 14:52:51 +08:00
Merge pull request #143 from feelfree69/flashsize_web
Show flash_size to web interface and console
This commit is contained in:
@@ -17,6 +17,7 @@
|
|||||||
// #define DEBUG
|
// #define DEBUG
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
|
||||||
|
|
||||||
#define L2_MAX_TRANSFER 30
|
#define L2_MAX_TRANSFER 30
|
||||||
|
|
||||||
#pragma codeseg BANK1
|
#pragma codeseg BANK1
|
||||||
@@ -96,6 +97,10 @@ void itoa_html(uint8_t v)
|
|||||||
char_to_html('0' + (v % 10));
|
char_to_html('0' + (v % 10));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void string_to_html(register char *s)
|
||||||
|
{
|
||||||
|
while (*s) char_to_html(*s++);
|
||||||
|
}
|
||||||
|
|
||||||
uint16_t stat_content(void)
|
uint16_t stat_content(void)
|
||||||
{
|
{
|
||||||
@@ -234,6 +239,9 @@ void send_basic_info(void)
|
|||||||
slen += strtox(outbuf + slen, BUILD_DATE);
|
slen += strtox(outbuf + slen, BUILD_DATE);
|
||||||
slen += strtox(outbuf + slen, "\",\"hw_ver\":\"");
|
slen += strtox(outbuf + slen, "\",\"hw_ver\":\"");
|
||||||
slen += strtox(outbuf + slen, machine.machine_name);
|
slen += strtox(outbuf + slen, machine.machine_name);
|
||||||
|
slen += strtox(outbuf + slen, "\",\"flash_size\":\"");
|
||||||
|
string_to_html(get_flash_size_str());
|
||||||
|
|
||||||
slen += strtox(outbuf + slen, "\",\"sfp_slot_0\":\"");
|
slen += strtox(outbuf + slen, "\",\"sfp_slot_0\":\"");
|
||||||
send_sfp_info(0);
|
send_sfp_info(0);
|
||||||
char_to_html('"');
|
char_to_html('"');
|
||||||
|
|||||||
@@ -131,6 +131,7 @@ void memset(register __xdata uint8_t *dst, register __xdata uint8_t v, register
|
|||||||
uint16_t strlen(register __code const char *s);
|
uint16_t strlen(register __code const char *s);
|
||||||
uint16_t strlen_x(register __xdata const char *s);
|
uint16_t strlen_x(register __xdata const char *s);
|
||||||
uint16_t strtox(register __xdata uint8_t *dst, register __code const char *s);
|
uint16_t strtox(register __xdata uint8_t *dst, register __code const char *s);
|
||||||
|
uint16_t strcpy(register __xdata uint8_t *dst, register const char *s);
|
||||||
void tcpip_output(void);
|
void tcpip_output(void);
|
||||||
uint8_t read_flash(uint8_t bank, __code uint8_t *addr);
|
uint8_t read_flash(uint8_t bank, __code uint8_t *addr);
|
||||||
void get_random_32(void);
|
void get_random_32(void);
|
||||||
|
|||||||
+23
-9
@@ -9,7 +9,9 @@
|
|||||||
|
|
||||||
__xdata uint8_t dio_enabled;
|
__xdata uint8_t dio_enabled;
|
||||||
__xdata struct flash_region_t flash_region;
|
__xdata struct flash_region_t flash_region;
|
||||||
|
|
||||||
__xdata uint32_t flash_size;
|
__xdata uint32_t flash_size;
|
||||||
|
__xdata uint8_t flash_capacity_code;
|
||||||
|
|
||||||
// For the flash commands, see e.g. Windbond W25Q32JV datasheet
|
// For the flash commands, see e.g. Windbond W25Q32JV datasheet
|
||||||
#define CMD_WRITE_STATUS 0x01
|
#define CMD_WRITE_STATUS 0x01
|
||||||
@@ -134,6 +136,19 @@ void flash_read_uid(void)
|
|||||||
flash_configure_mmio();
|
flash_configure_mmio();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
__code char* get_flash_size_str(void)
|
||||||
|
{
|
||||||
|
switch (flash_capacity_code) {
|
||||||
|
case 0x12: return "256 KB";
|
||||||
|
case 0x13: return "512 KB";
|
||||||
|
case 0x14: return "1 MB";
|
||||||
|
case 0x15: return "2 MB";
|
||||||
|
case 0x16: return "4 MB";
|
||||||
|
case 0x17: return "8 MB";
|
||||||
|
case 0x18: return "16 MB";
|
||||||
|
default: return "unknown";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void flash_read_jedecid(void)
|
void flash_read_jedecid(void)
|
||||||
{
|
{
|
||||||
@@ -150,17 +165,16 @@ void flash_read_jedecid(void)
|
|||||||
SFR_FLASH_EXEC_GO = 1;
|
SFR_FLASH_EXEC_GO = 1;
|
||||||
while(SFR_FLASH_EXEC_BUSY);
|
while(SFR_FLASH_EXEC_BUSY);
|
||||||
|
|
||||||
print_string("Maufacturer ID: 0x");
|
print_string("Flash information:\n");
|
||||||
|
print_string(" Manufacturer ID: 0x");
|
||||||
print_byte(SFR_FLASH_DATA0);
|
print_byte(SFR_FLASH_DATA0);
|
||||||
print_string("\nMemory Type: 0x");
|
print_string("\n Memory Type: 0x");
|
||||||
print_byte(SFR_FLASH_DATA8);
|
print_byte(SFR_FLASH_DATA8);
|
||||||
print_string("\nCapacity: 0x");
|
print_string("\n Capacity: 0x");
|
||||||
uint8_t cap = SFR_FLASH_DATA16;
|
flash_capacity_code = SFR_FLASH_DATA16;
|
||||||
flash_size = 1UL << cap;
|
flash_size = 1UL << flash_capacity_code;
|
||||||
print_byte(cap);
|
print_byte(flash_capacity_code);
|
||||||
print_string(" = ");
|
print_string(" = "); print_string(get_flash_size_str()); write_char('\n');
|
||||||
print_long(flash_size);
|
|
||||||
print_string(" Bytes\n");
|
|
||||||
|
|
||||||
flash_configure_mmio();
|
flash_configure_mmio();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,4 +10,6 @@ void flash_read_security(void);
|
|||||||
void flash_sector_erase(void);
|
void flash_sector_erase(void);
|
||||||
void flash_read_bulk(__xdata uint8_t *dst);
|
void flash_read_bulk(__xdata uint8_t *dst);
|
||||||
void flash_write_bytes(__xdata uint8_t *ptr);
|
void flash_write_bytes(__xdata uint8_t *ptr);
|
||||||
|
__code char* get_flash_size_str(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+8
-7
@@ -240,6 +240,7 @@ uint16_t strtox(register __xdata uint8_t *dst, register __code const char *s)
|
|||||||
return dst - b;
|
return dst - b;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
uint16_t strlen(register __code const char *s)
|
uint16_t strlen(register __code const char *s)
|
||||||
{
|
{
|
||||||
uint16_t l = 0;
|
uint16_t l = 0;
|
||||||
@@ -1872,17 +1873,13 @@ void check_and_flash_update_image(void)
|
|||||||
{
|
{
|
||||||
flash_read_jedecid(); // This initializes also __xdata flash_size variable
|
flash_read_jedecid(); // This initializes also __xdata flash_size variable
|
||||||
|
|
||||||
print_long(flash_size); print_string(" flash size detected.\n");
|
print_string(get_flash_size_str()); print_string(" flash size detected. (1 MB is needed for image updating)\n");
|
||||||
print_long(FIRMWARE_UPLOAD_START*2); print_string(" bytes needed for update.\n");
|
|
||||||
if (flash_size < FIRMWARE_UPLOAD_START*2) {
|
if (flash_size < FIRMWARE_UPLOAD_START*2) {
|
||||||
print_string("Flash too small for updating; skipping update check\n");
|
print_string("Flash too small for updating; skipping update check\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
print_string("Flash size ok.\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
print_string("Checking for update image in flash... ");
|
||||||
// Check if an update image is in flash
|
// Check if an update image is in flash
|
||||||
flash_region.addr = FIRMWARE_UPLOAD_START;
|
flash_region.addr = FIRMWARE_UPLOAD_START;
|
||||||
flash_region.len = 0x100;
|
flash_region.len = 0x100;
|
||||||
@@ -1895,7 +1892,7 @@ void check_and_flash_update_image(void)
|
|||||||
__xdata uint16_t i = 0;
|
__xdata uint16_t i = 0;
|
||||||
__xdata uint16_t j = 0;
|
__xdata uint16_t j = 0;
|
||||||
__xdata uint8_t * __xdata bptr;
|
__xdata uint8_t * __xdata bptr;
|
||||||
print_string("Identified update image. Checking integrity");
|
print_string("found update image! Checking integrity");
|
||||||
flash_init(0); // Re-initialize flash for non-DIO operation, otherwise flashing will fail
|
flash_init(0); // Re-initialize flash for non-DIO operation, otherwise flashing will fail
|
||||||
set_sys_led_state(SYS_LED_FAST);
|
set_sys_led_state(SYS_LED_FAST);
|
||||||
crc_value = 0x0000;
|
crc_value = 0x0000;
|
||||||
@@ -1951,6 +1948,10 @@ void check_and_flash_update_image(void)
|
|||||||
dest += 0x1000;
|
dest += 0x1000;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
print_string("no update image found.\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void main(void)
|
void main(void)
|
||||||
|
|||||||
Reference in New Issue
Block a user