diff --git a/boot.c b/boot.c index c72e24ed..53aefa8b 100644 --- a/boot.c +++ b/boot.c @@ -22,7 +22,7 @@ extern __xdata struct machine_runtime machine_detected; extern __xdata uint8_t sfr_data[4]; extern volatile __xdata uint32_t ticks; extern __xdata uint8_t tx_seq; -extern __code uint8_t * __code hex; +extern __code const uint8_t * __code const hex; diff --git a/cmd_parser.c b/cmd_parser.c index 55bba78b..bfa75b06 100644 --- a/cmd_parser.c +++ b/cmd_parser.c @@ -26,15 +26,15 @@ #pragma codeseg BANK2 #pragma constseg BANK2 -extern __code struct machine machine; +extern __code const struct machine machine; extern __xdata bool stp_enabled; -extern __code uint8_t log_to_phys_port[9]; +extern __code const uint8_t log_to_phys_port[9]; extern volatile __xdata uint32_t ticks; extern volatile __xdata uint8_t sfr_data[4]; -extern __code uint8_t * __code greeting; -extern __code uint8_t * __code hex; +extern __code const uint8_t * __code const greeting; +extern __code const uint8_t * __code const hex; extern __xdata uint8_t flash_buf[FLASH_BUF_SIZE]; extern __xdata struct flash_region_t flash_region; @@ -105,7 +105,7 @@ inline uint8_t isnumber(uint8_t l) return (l <= ('9'-'0')); } -uint8_t cmd_compare(uint8_t start, __code uint8_t * cmd) +uint8_t cmd_compare(uint8_t start, __code const uint8_t * cmd) { if (cmd_words_len == 0 || start > (cmd_words_len - 1)) { return 0; diff --git a/httpd/httpd.c b/httpd/httpd.c index 9e9bd13a..ab61ca7c 100644 --- a/httpd/httpd.c +++ b/httpd/httpd.c @@ -22,9 +22,9 @@ extern volatile __xdata uint8_t sfr_data[4]; extern volatile __xdata uint32_t ticks; extern __xdata uint8_t cmd_capture; /* owned by rtlplayground.c, see write_char_no_syslog() */ -extern __code uint8_t * __code hex; -extern __code struct f_data f_data[]; -extern __code char * __code mime_strings[]; +extern __code const uint8_t * __code const hex; +extern __code const struct f_data f_data[]; +extern __code const char * __code const mime_strings[]; extern __xdata struct flash_region_t flash_region; extern __xdata uint32_t flash_size; @@ -127,7 +127,7 @@ uint8_t find_entry(__xdata uint8_t *e) } -bool is_word(__xdata uint8_t *xdata_str_p, __code uint8_t * __xdata code_str_p) +bool is_word(__xdata uint8_t *xdata_str_p, __code const uint8_t * __xdata code_str_p) { uint8_t u, c; @@ -149,7 +149,7 @@ bool is_word(__xdata uint8_t *xdata_str_p, __code uint8_t * __xdata code_str_p) /* name must be lower-case, starting with the '\n' of the previous line's end */ -__xdata uint8_t *header_value(__xdata uint8_t *p, __code uint8_t *name) +__xdata uint8_t *header_value(__xdata uint8_t *p, __code const uint8_t *name) { uint8_t u, c; diff --git a/httpd/page_impl.c b/httpd/page_impl.c index 58624145..e7cdebe8 100644 --- a/httpd/page_impl.c +++ b/httpd/page_impl.c @@ -30,7 +30,7 @@ extern __xdata uint16_t slen; extern __xdata uint16_t management_vlan; extern __xdata uint16_t cont_len; extern __xdata uint32_t cont_addr; -extern __code uint8_t * __code hex; +extern __code const uint8_t * __code const hex; extern __xdata uip_ipaddr_t uip_hostaddr, uip_draddr, uip_netmask; extern __xdata uint8_t sfr_data[4]; @@ -47,8 +47,8 @@ extern __xdata char sfp_module_model[2][17]; extern __xdata char sfp_module_serial[2][17]; extern __xdata uint8_t sfp_options[2]; -__code uint8_t * __code HTTP_RESPONCE_JSON = "HTTP/1.1 200 OK\r\nConnection: close\r\nContent-Type: application/json\r\n\r\n"; -__code uint8_t * __code HTTP_RESPONCE_TXT = "HTTP/1.1 200 OK\r\nConnection: close\r\nContent-Type: text/plain\r\n\r\n"; +__code const uint8_t * __code const HTTP_RESPONCE_JSON = "HTTP/1.1 200 OK\r\nConnection: close\r\nContent-Type: application/json\r\n\r\n"; +__code const uint8_t * __code const HTTP_RESPONCE_TXT = "HTTP/1.1 200 OK\r\nConnection: close\r\nContent-Type: text/plain\r\n\r\n"; // Convert uint8_t to ascii HEX char push on html-buffer. void charhex_to_html(char c) @@ -127,7 +127,7 @@ void itoa16_html(uint16_t v) /* sufficient for VLAN IDs (max 4094) */ char_to_html('0' + (v % 10)); } -void string_to_html(__code char *s) +void string_to_html(__code const char *s) { while (*s) char_to_html(*s++); } diff --git a/httpd/page_impl.h b/httpd/page_impl.h index cad4cd6f..0f171042 100644 --- a/httpd/page_impl.h +++ b/httpd/page_impl.h @@ -3,7 +3,7 @@ #include -extern __code uint8_t * __code HTTP_RESPONCE_TXT; +extern __code const uint8_t * __code const HTTP_RESPONCE_TXT; bool send_counters(uint8_t phys_port); void send_status(void); diff --git a/installer/installer.c b/installer/installer.c index f86b7821..18dbdfdd 100644 --- a/installer/installer.c +++ b/installer/installer.c @@ -30,7 +30,7 @@ __xdata uint8_t buffer[0x1000]; __xdata uint8_t dio_enabled; -__code uint8_t * __code hex = "0123456789abcdef"; +__code const uint8_t * __code const hex = "0123456789abcdef"; void isr_timer0(void) __interrupt(1) { @@ -67,7 +67,7 @@ void write_char(char c) } -void print_string(__code char *p) +void print_string(__code const char *p) { while (*p) write_char(*p++); diff --git a/rtl837x_common.h b/rtl837x_common.h index 2ae75fdf..5e1373f8 100644 --- a/rtl837x_common.h +++ b/rtl837x_common.h @@ -183,13 +183,13 @@ uint16_t strlen(__code const char *s); uint16_t strcpy(__xdata uint8_t *dst, const char *s); char strcmp(__xdata const uint8_t *a, __code const uint8_t *b); #endif -void memcpyc(__xdata uint8_t *dst, __code uint8_t *src, uint16_t len); +void memcpyc(__xdata uint8_t *dst, __code const uint8_t *src, uint16_t len); uint16_t strlen_x(__xdata const char *s); uint16_t strtox(__xdata uint8_t *dst, __code const char *s); bool strstart(__xdata const uint8_t *a, __code const uint8_t *b); bool strstart_x(__xdata const uint8_t *a, __xdata const uint8_t *b); void tcpip_output(void); -uint8_t read_flash(uint8_t bank, __code uint8_t *addr); +uint8_t read_flash(uint8_t bank, __code const uint8_t *addr); void get_random_32(void); void read_reg_timer(__xdata uint32_t * tmr); bool gpio_pin_test(uint8_t pin); diff --git a/rtl837x_flash.c b/rtl837x_flash.c index 2ec5bc3f..c1357b04 100644 --- a/rtl837x_flash.c +++ b/rtl837x_flash.c @@ -171,7 +171,7 @@ void flash_read_uid(void) flash_configure_mmio(); } -__code char* get_flash_size_str(void) +__code const char* get_flash_size_str(void) { switch (flash_capacity_code) { case 0x12: return "256 KB"; diff --git a/rtl837x_flash.h b/rtl837x_flash.h index eef25b14..f7fc4790 100644 --- a/rtl837x_flash.h +++ b/rtl837x_flash.h @@ -19,7 +19,7 @@ void flash_read_security(void); void flash_sector_erase(void); void flash_read_bulk(__xdata uint8_t *dst); void flash_write_bytes(__xdata uint8_t *ptr); -__code char* get_flash_size_str(void); +__code const char* get_flash_size_str(void); #endif diff --git a/rtl837x_igmp.c b/rtl837x_igmp.c index 0a749f99..ce786e75 100644 --- a/rtl837x_igmp.c +++ b/rtl837x_igmp.c @@ -15,7 +15,7 @@ #include "rtl837x_igmp.h" #include "machine.h" -extern __code struct machine machine; +extern __code const struct machine machine; extern __xdata uint8_t igmpEnabled; #include "uip.h" diff --git a/rtl837x_init.c b/rtl837x_init.c index 6b24843b..b227e189 100644 --- a/rtl837x_init.c +++ b/rtl837x_init.c @@ -9,7 +9,7 @@ #include "boot.h" extern __xdata uint8_t sfr_data[4]; -extern __code struct machine machine; +extern __code const struct machine machine; extern __xdata struct machine_runtime machine_detected; #pragma codeseg BANK2 diff --git a/rtl837x_leds.c b/rtl837x_leds.c index d0aa498b..4811cafa 100644 --- a/rtl837x_leds.c +++ b/rtl837x_leds.c @@ -15,7 +15,7 @@ #include "rtl837x_leds.h" #include "machine.h" -extern __code struct machine machine; +extern __code const struct machine machine; #include "uip.h" @@ -261,7 +261,7 @@ void leds_setup(void) __banked sfr_data[3] = sfr_data[2] = sfr_data[1] = sfr_data[0] = 0; reg_write_m(RTL837X_REG_LED3_0_SET1); reg_write_m(RTL837X_REG_LED3_0_SET3); - __code uint8_t * __xdata lptr = &machine.led_sets[0][0]; + __code const uint8_t * __xdata lptr = &machine.led_sets[0][0]; for (__xdata uint8_t set = 0; set < 4; set++) { sfr_data[0] = *(lptr + 5); sfr_data[1] = *(lptr + 4); diff --git a/rtl837x_phy.c b/rtl837x_phy.c index 25f7e150..525e3fa2 100644 --- a/rtl837x_phy.c +++ b/rtl837x_phy.c @@ -20,7 +20,7 @@ #pragma codeseg BANK2 #pragma constseg BANK2 -extern __code uint16_t bit_mask[16]; +extern __code const uint16_t bit_mask[16]; extern __code const struct machine machine; extern __xdata struct machine_runtime machine_detected; @@ -33,7 +33,7 @@ __xdata struct phy_settings phy_settings; // Note: Adding `Swapping the RX for N-devices`-setting on the end of the array, didn't work. // Setting will apply but still no packets flow. // Settings are `0x2000, 0xc10c`, -__code uint16_t rtl8224_sds0_setttings[42] = { +__code const uint16_t rtl8224_sds0_setttings[42] = { // SDS_DATA, SDS_CMD 0x4480, 0xc842, 0x0400, 0xc9c2, diff --git a/rtl837x_port.c b/rtl837x_port.c index 0383aae3..8cb626c3 100644 --- a/rtl837x_port.c +++ b/rtl837x_port.c @@ -18,9 +18,9 @@ #pragma codeseg BANK1 #pragma constseg BANK1 -extern __code uint8_t * __code hex; -extern __code uint16_t bit_mask[16]; -extern __code struct machine machine; +extern __code const uint8_t * __code const hex; +extern __code const uint16_t bit_mask[16]; +extern __code const struct machine machine; extern __xdata uint8_t sfr_data[4]; extern __xdata uint16_t vlan_ptr; extern __xdata uint8_t vlan_names[VLAN_NAMES_SIZE]; diff --git a/rtl837x_stp.c b/rtl837x_stp.c index f7eb871b..26e14806 100644 --- a/rtl837x_stp.c +++ b/rtl837x_stp.c @@ -22,7 +22,7 @@ extern __xdata uint8_t err_status; #pragma codeseg BANK2 #pragma constseg BANK2 -extern __code struct machine machine; +extern __code const struct machine machine; extern __xdata uint8_t sfr_data[4]; extern __xdata struct machine_runtime machine_detected; @@ -35,7 +35,7 @@ extern __xdata uint8_t cmd_buffer[CMD_BUF_SIZE]; extern __xdata uint8_t cmd_words_len; extern __xdata uint8_t cmd_words_b[15]; extern __xdata char save_cmd; /* 0 while execute_config() replays the saved config */ -uint8_t cmd_compare(uint8_t start, __code uint8_t * cmd); +uint8_t cmd_compare(uint8_t start, __code const uint8_t * cmd); uint8_t atoi_byte(uint8_t idx); uint8_t cmd_parse_port_separator(uint8_t idx); extern __xdata uint8_t atoi_results_u8; diff --git a/rtlplayground.c b/rtlplayground.c index 1a2ed442..6b0bf2df 100644 --- a/rtlplayground.c +++ b/rtlplayground.c @@ -79,9 +79,9 @@ void crc16_bank1(__xdata uint8_t *v) __naked; __xdata uint8_t idle_ready; -__code uint8_t ownIP[] = { 192, 168, 2, 2 }; -__code uint8_t gatewayIP[] = { 192, 168, 2, 22}; -__code uint8_t netmask[] = { 255, 255, 255, 0}; +__code const uint8_t ownIP[] = { 192, 168, 2, 2 }; +__code const uint8_t gatewayIP[] = { 192, 168, 2, 22}; +__code const uint8_t netmask[] = { 255, 255, 255, 0}; __xdata struct uip_eth_addr uip_ethaddr; @@ -108,8 +108,8 @@ extern __xdata uint8_t gpio_last_value[8]; extern __xdata struct flash_region_t flash_region; -__code uint8_t * __code greeting = "\nA minimal prompt to explore the RTL8372:\n"; -__code uint8_t * __code hex = "0123456789abcdef"; +__code const uint8_t * __code const greeting = "\nA minimal prompt to explore the RTL8372:\n"; +__code const uint8_t * __code const hex = "0123456789abcdef"; __xdata uint8_t flash_buf[FLASH_BUF_SIZE]; @@ -126,7 +126,7 @@ __xdata bool stp_enabled; __xdata uint8_t igmpEnabled; __xdata char hostname[24]; /* device hostname, default set at boot, see rtl837x_common.h */ -__code uint16_t bit_mask[16] = { +__code const uint16_t bit_mask[16] = { 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080, 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000, 0x8000 }; @@ -349,7 +349,7 @@ int memcmp(__xdata const void *a, __xdata const void *b, uint16_t len) return 0; } -void memcpyc(__xdata uint8_t *dst, __code uint8_t *src, uint16_t len) +void memcpyc(__xdata uint8_t *dst, __code const uint8_t *src, uint16_t len) { while (len--) *dst++ = *src++; @@ -785,7 +785,7 @@ void nic_tx_packet(uint16_t ring_ptr) * Note that the address in the flash memory is not simply 0xbbaddr, because * the size of a bank is merely 0xc000. */ -uint8_t read_flash(uint8_t bank, __code uint8_t *addr) +uint8_t read_flash(uint8_t bank, __code const uint8_t *addr) { uint8_t v; uint8_t current_bank = PSBANK; diff --git a/sfp.c b/sfp.c index 1f1f6652..9866929a 100644 --- a/sfp.c +++ b/sfp.c @@ -35,12 +35,12 @@ __code enum sfp_quirk { }; struct sfp_quirk_entry { - __code char *vendor; // Set vendor or model to 0 to act as wildcard - __code char *model; + __code const char *vendor; // Set vendor or model to 0 to act as wildcard + __code const char *model; uint8_t quirks; }; -static __code struct sfp_quirk_entry sfp_quirk_table[] = { +static __code const struct sfp_quirk_entry sfp_quirk_table[] = { { "QSFPTEK", "QT-SFP+-T", SFP_QUIRK_DDM }, }; diff --git a/test/env_tables.c b/test/env_tables.c index 4d31fb65..274a67d5 100644 --- a/test/env_tables.c +++ b/test/env_tables.c @@ -90,7 +90,7 @@ struct uip_eth_addr uip_ethaddr = { .addr = { 0x02, 0x11, 0x22, 0x33, 0x44, 0x55 /* ---- leaf calls into subsystems not under test ---- */ void flash_read_bulk(uint8_t *dst) { (void)dst; } -char *get_flash_size_str(void) { return (char *)"2M"; } +const char *get_flash_size_str(void) { return "2M"; } uint8_t sfp_read_reg(uint8_t slot, uint8_t reg) { (void)slot; (void)reg; return 0; } bool gpio_pin_test(uint8_t pin) { (void)pin; return false; } void phy_read(uint8_t phy_id, uint8_t dev_id, uint16_t reg) { (void)phy_id; (void)dev_id; (void)reg; } diff --git a/test/stub/html_data.h b/test/stub/html_data.h index 6e7f0029..c15f9f26 100644 --- a/test/stub/html_data.h +++ b/test/stub/html_data.h @@ -5,7 +5,7 @@ #define FDATA_DEFS_H #include typedef enum mime_type_e { mime_HTML = 0, mime_SVG, mime_ICO, mime_PNG, mime_JS, mime_CSS, mime_TXT } mime_type_t; -struct f_data { __code char *file; uint32_t start; uint16_t len; mime_type_t mime; uint8_t gzip; }; +struct f_data { __code const char *file; uint32_t start; uint16_t len; mime_type_t mime; uint8_t gzip; }; #define FDATA_START_login_html 0x00040000UL #define FDATA_START_favicon_ico 0x00041000UL #endif diff --git a/test/test_httpd_tx.c b/test/test_httpd_tx.c index 3a82b343..6f464d2b 100644 --- a/test/test_httpd_tx.c +++ b/test/test_httpd_tx.c @@ -67,18 +67,18 @@ volatile uint8_t sfr_data[4]; volatile uint32_t ticks; uint8_t cmd_capture; uint8_t err_status; -uint8_t *hex = (uint8_t *)"0123456789abcdef"; +const uint8_t * const hex = (const uint8_t *)"0123456789abcdef"; uint16_t crc_value; -uint8_t *HTTP_RESPONCE_TXT = (uint8_t *)"HTTP/1.1 200 OK\r\n\r\n"; +const uint8_t * const HTTP_RESPONCE_TXT = (const uint8_t *)"HTTP/1.1 200 OK\r\n\r\n"; uint32_t flash_size = 0x80000; uint8_t flash_buf[FLASH_BUF_SIZE]; uint8_t rx_headers[16]; struct flash_region_t flash_region; -char *mime_strings[] = { "text/html", "image/svg+xml", "image/x-icon", +const char * const mime_strings[] = { "text/html", "image/svg+xml", "image/x-icon", "image/png", "text/javascript", "text/css", "text/plain" }; -struct f_data f_data[] = { +const struct f_data f_data[] = { { FILE_NAME, FILE_START, FILE_LEN, mime_HTML, 0 }, { 0, 0, 0, mime_HTML, 0 }, }; @@ -92,7 +92,7 @@ void flash_read_bulk(uint8_t *dst) void flash_init(uint8_t enable_dio) { (void)enable_dio; } void flash_sector_erase(void) { } void flash_write_bytes(uint8_t *ptr) { (void)ptr; } -char *get_flash_size_str(void) { return "512 kB"; } +const char *get_flash_size_str(void) { return "512 kB"; } void crc16_bank1(uint8_t *v) { (void)v; } void reset_chip(void) { } void delay(uint16_t t) { (void)t; } @@ -124,7 +124,7 @@ uint16_t strtox(uint8_t *dst, const char *s) return n; } -void memcpyc(uint8_t *dst, uint8_t *src, uint16_t len) { memcpy(dst, src, len); } +void memcpyc(uint8_t *dst, const uint8_t *src, uint16_t len) { memcpy(dst, src, len); } bool strstart(const uint8_t *a, const uint8_t *b) { diff --git a/tools/fileadder.c b/tools/fileadder.c index c9022b91..1da276ec 100644 --- a/tools/fileadder.c +++ b/tools/fileadder.c @@ -318,7 +318,7 @@ int main(int argc, char **argv) defbuf_p += snprintf(&dbuf[defbuf_p], DEF_SIZE - defbuf_p, "#include \n\n"); defbuf_p += snprintf(&dbuf[defbuf_p], DEF_SIZE - defbuf_p, "typedef enum mime_type_e {\n mime_HTML = 0,\n mime_SVG,\n mime_ICO,\n mime_PNG,\n mime_JS,\n mime_CSS,\n mime_TXT\n} mime_type_t;\n\n"); - defbuf_p += snprintf(&dbuf[defbuf_p], DEF_SIZE - defbuf_p, "struct f_data {\n __code char *file;\n uint32_t start;\n uint16_t len;\n mime_type_t mime;\n uint8_t gzip;\n};\n\n"); + defbuf_p += snprintf(&dbuf[defbuf_p], DEF_SIZE - defbuf_p, "struct f_data {\n __code const char *file;\n uint32_t start;\n uint16_t len;\n mime_type_t mime;\n uint8_t gzip;\n};\n\n"); // defbuf_p += snprintf(&dbuf[defbuf_p], DEF_SIZE - defbuf_p, "typedef uint16_t (* fcall_ptr)(void);\n\n"); ibuf_p += snprintf(&ibuf[ibuf_p], INDEX_SIZE - ibuf_p, "// This file is automatically generated, do not edit!\n\n"); @@ -326,9 +326,9 @@ int main(int argc, char **argv) ibuf_p += snprintf(&ibuf[ibuf_p], INDEX_SIZE - ibuf_p, "#include \"%s.h\"\n\n", arguments.prefix); if (arguments.bank) ibuf_p += snprintf(&ibuf[ibuf_p], INDEX_SIZE - ibuf_p, "#pragma codeseg %s\n#pragma constseg %s\n\n", arguments.bank, arguments.bank); - ibuf_p += snprintf(&ibuf[ibuf_p], INDEX_SIZE - ibuf_p, " __code char * __code mime_strings[] = {\n \"text/html\",\n \"image/svg+xml\",\n" + ibuf_p += snprintf(&ibuf[ibuf_p], INDEX_SIZE - ibuf_p, " __code const char * __code const mime_strings[] = {\n \"text/html\",\n \"image/svg+xml\",\n" " \"image/svg+xml\",\n \"image/png\",\n \"text/javascript\",\n \"text/css\",\n \"text/plain\"};\n\n"); - ibuf_p += snprintf(&ibuf[ibuf_p], INDEX_SIZE - ibuf_p, "__code struct f_data f_data[] = {\n"); + ibuf_p += snprintf(&ibuf[ibuf_p], INDEX_SIZE - ibuf_p, "__code const struct f_data f_data[] = {\n"); // fbuf_p += snprintf(&fbuf[fbuf_p], DEF_SIZE - fbuf_p, "\n__code fcall_ptr f_calls[] = {\n"); // Now that the beginning of the buffer is filled with out image, optionally resize the image diff --git a/uip/uip.h b/uip/uip.h index 5f4d8e29..1fab85ea 100644 --- a/uip/uip.h +++ b/uip/uip.h @@ -912,8 +912,8 @@ __xdata struct uip_udp_conn *uip_udp_new(__xdata uip_ipaddr_t * __xdata ripaddr, ((__xdata u16_t *)addr1)[1] == ((__xdata u16_t *)addr2)[1]) #define uip_ipaddr_cmpx(addr1, addr2) (((__xdata u16_t *)addr1)[0] == ((__xdata u16_t *)addr2)[0] && \ ((__xdata u16_t *)addr1)[1] == ((__xdata u16_t *)addr2)[1]) -#define uip_ipaddr_cmpc(addr1, addr2) (((__xdata u16_t *)addr1)[0] == ((__code u16_t *)addr2)[0] && \ - ((__xdata u16_t *)addr1)[1] == ((__code u16_t *)addr2)[1]) +#define uip_ipaddr_cmpc(addr1, addr2) (((__xdata u16_t *)addr1)[0] == ((__code const u16_t *)addr2)[0] && \ + ((__xdata u16_t *)addr1)[1] == ((__code const u16_t *)addr2)[1]) #else /* !UIP_CONF_IPV6 */ #define uip_ipaddr_cmp(addr1, addr2) (memcmp(addr1, addr2, sizeof(uip_ip6addr_t)) == 0) #endif /* !UIP_CONF_IPV6 */