diff --git a/FreeRTOS/Source/portable/esp8266/port.c b/FreeRTOS/Source/portable/esp8266/port.c index 0aaed7b..42cb36a 100644 --- a/FreeRTOS/Source/portable/esp8266/port.c +++ b/FreeRTOS/Source/portable/esp8266/port.c @@ -99,7 +99,7 @@ portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE SET_STKREG( XT_STK_A0, 0 ); /* to terminate GDB backtrace */ SET_STKREG( XT_STK_A1, (uint32_t)sp + XT_STK_FRMSZ ); /* physical top of stack frame */ SET_STKREG( XT_STK_A2, pvParameters ); /* parameters */ - SET_STKREG( XT_STK_EXIT, _xt_user_exit ); /* user exception exit dispatcher */ + SET_STKREG( XT_STK_EXIT, sdk__xt_user_exit ); /* user exception exit dispatcher */ /* Set initial PS to int level 0, EXCM disabled ('rfe' will enable), user mode. */ SET_STKREG( XT_STK_PS, PS_UM | PS_EXCM ); @@ -139,19 +139,19 @@ void PendSV(enum SVC_ReqType req) * after a Blob SV requests a soft interrupt by calling * PendSV(SVC_MACLayer). */ -extern portBASE_TYPE MacIsrSigPostDefHdl(void); +extern portBASE_TYPE sdk_MacIsrSigPostDefHdl(void); void SV_ISR(void) { portBASE_TYPE xHigherPriorityTaskWoken=pdFALSE ; if(pending_maclayer_sv) { - xHigherPriorityTaskWoken = MacIsrSigPostDefHdl(); + xHigherPriorityTaskWoken = sdk_MacIsrSigPostDefHdl(); pending_maclayer_sv = 0; } if( xHigherPriorityTaskWoken || pending_soft_sv) { - _xt_timer_int1(); + sdk__xt_timer_int1(); pending_soft_sv = 0; } } @@ -175,14 +175,14 @@ void xPortSysTickHandle (void) portBASE_TYPE xPortStartScheduler( void ) { _xt_isr_attach(ETS_SOFT_INUM, SV_ISR); - _xt_isr_unmask(1< $@" + $(Q) $(OBJCOPY) --redefine-syms $(word 2,$^) --weaken $< $@ + + +# Generate a regex to match symbols we don't want to rename, by parsing +# a list of symbol names +$(BUILD_DIR)sdklib/norename.match: $(ROOT)lib/symbols_norename.txt | $(BUILD_DIR)sdklib + grep -v "^#" $< | sed ':begin;$!N;s/\n/\\|/;tbegin' > $@ + +# Generate list of symbols to rename from a single library. Uses grep & sed. +$(BUILD_DIR)sdklib/%.rename: $(ROOT)lib/%.a $(BUILD_DIR)sdklib/norename.match + $(vecho) "Building symbol list for $< -> $@" + $(Q) $(NM) --defined $< | grep ' T ' | sed -r 's/(.+) T (.+)/\2 sdk_\2/' | grep -v `cat $(BUILD_DIR)sdklib/norename.match` > $@ + +# Build master list of all SDK-defined symbols to rename +$(BUILD_DIR)sdklib/allsymbols.rename: $(patsubst %.a,%.rename,$(SDK_PROCESSED_LIBS)) + cat $^ > $@ + + ## Include components (this is where the actual compiler sections are generated) $(foreach component,$(COMPONENTS), $(eval include $(ROOT)/$(component)/component.mk)) @@ -167,16 +204,16 @@ target_ROOT=$(TARGET_DIR) $(eval $(call component_compile_rules,target)) # final linking step to produce .elf -$(TARGET_OUT): $(COMPONENT_ARS) +$(TARGET_OUT): $(COMPONENT_ARS) $(SDK_PROCESSED_LIBS) $(vecho) "LD $@" - $(Q) $(LD) $(LD_SCRIPT) $(LDFLAGS) -Wl,--start-group $(LIB_ARGS) $(COMPONENT_ARS) -Wl,--end-group -o $@ + $(Q) $(LD) $(LD_SCRIPT) $(LDFLAGS) -Wl,--start-group $(SDK_LIB_ARGS) $(LIB_ARGS) $(COMPONENT_ARS) -Wl,--end-group -o $@ -$(BUILD_DIR) $(FW_BASE): +$(BUILD_DIR) $(FW_BASE) $(BUILD_DIR)sdklib: $(Q) mkdir -p $@ $(FW_FILE_1) $(FW_FILE_2): $(TARGET_OUT) $(FW_BASE) $(vecho) "FW $@" - $(ESPTOOL) elf2image $< -o $(FW_BASE) + $(ESPTOOL) elf2image --entry-symbol $(ENTRY_SYMBOL) $< -o $(FW_BASE) flash: $(FW_FILE_1) $(FW_FILE_2) $(ESPTOOL) -p $(ESPPORT) --baud $(ESPBAUD) write_flash $(FW_1) $(FW_FILE_1) $(FW_2) $(FW_FILE_2) @@ -196,3 +233,7 @@ rebuild: clean: $(Q) rm -rf $(BUILD_DIR) $(Q) rm -rf $(FW_BASE) + +# prevent "intermediate" files from being deleted +.SECONDARY: + diff --git a/examples/http_get/main.c b/examples/http_get/main.c index fc12910..6af7e34 100644 --- a/examples/http_get/main.c +++ b/examples/http_get/main.c @@ -109,17 +109,17 @@ void http_get_task(void *pvParameters) void user_init(void) { - uart_div_modify(0, UART_CLK_FREQ / 115200); - printf("SDK version:%s\n", system_get_sdk_version()); + sdk_uart_div_modify(0, UART_CLK_FREQ / 115200); + printf("SDK version:%s\n", sdk_system_get_sdk_version()); - struct station_config config = { + struct sdk_station_config config = { .ssid = WIFI_SSID, .password = WIFI_PASS, }; /* required to call wifi_set_opmode before station_set_config */ - wifi_set_opmode(STATION_MODE); - wifi_station_set_config(&config); + sdk_wifi_set_opmode(STATION_MODE); + sdk_wifi_station_set_config(&config); xTaskCreate(&http_get_task, (signed char *)"get_task", 256, NULL, 2, NULL); } diff --git a/include/esp8266.h b/include/esp8266.h new file mode 100644 index 0000000..a58a9be --- /dev/null +++ b/include/esp8266.h @@ -0,0 +1,33 @@ +/* esp8266.h + * + * ESP-specific SoC-level addresses, macros, etc. + * Part of esp-open-rtos + * + * Copyright (C) 2105 Superhouse Automation Pty Ltd + * BSD Licensed as described in the file LICENSE + */ +#include + +#ifndef _ESP8266_H +#define _ESP8266_H + +/* Use this macro to store constant values in IROM flash instead + of having them loaded into rodata (which resides in DRAM) + + Unlike the ESP8266 SDK you don't need an attribute like this for + standard functions. They're stored in flash by default. But + variables need them. + + Important to note: IROM flash can only be accessed via 32-bit word + aligned reads. It's up to the user of this attribute to ensure this. +*/ +#define IROM __attribute__((section(".irom0"))) const + + +/* Register addresses + + ESPTODO: break this out to its own header file and clean it up, add other regs, etc. +*/ +static volatile __attribute__((unused)) uint32_t *ESP_REG_WDT = (uint32_t *)0x60000900; + +#endif diff --git a/include/espressif/esp_misc.h b/include/espressif/esp_misc.h index 68d9724..d8ce65e 100644 --- a/include/espressif/esp_misc.h +++ b/include/espressif/esp_misc.h @@ -18,9 +18,9 @@ #define IPSTR "%d.%d.%d.%d" -void os_delay_us(uint16_t us); +void sdk_os_delay_us(uint16_t us); -void os_install_putc1(void (*p)(char c)); -void os_putc(char c); +void sdk_os_install_putc1(void (*p)(char c)); +void sdk_os_putc(char c); #endif diff --git a/include/espressif/esp_softap.h b/include/espressif/esp_softap.h index c2bbe42..44f06cc 100644 --- a/include/espressif/esp_softap.h +++ b/include/espressif/esp_softap.h @@ -6,7 +6,7 @@ #ifndef __ESP_SOFTAP_H__ #define __ESP_SOFTAP_H__ -struct softap_config { +struct sdk_softap_config { uint8_t ssid[32]; uint8_t password[64]; uint8_t ssid_len; @@ -17,7 +17,7 @@ struct softap_config { uint16_t beacon_interval; }; -bool wifi_softap_get_config(struct softap_config *config); -bool wifi_softap_set_config(struct softap_config *config); +bool sdk_wifi_softap_get_config(struct sdk_softap_config *config); +bool sdk_wifi_softap_set_config(struct sdk_softap_config *config); #endif diff --git a/include/espressif/esp_sta.h b/include/espressif/esp_sta.h index 779242f..8b9059a 100644 --- a/include/espressif/esp_sta.h +++ b/include/espressif/esp_sta.h @@ -1,6 +1,8 @@ /* * Copyright (C) 2013 -2014 Espressif System * + * + * Adapted from BSD licensed esp_iot_rtos_sdk v0.9.9 */ #ifndef __ESP_STA_H__ @@ -8,27 +10,27 @@ #include "queue.h" -struct station_config { +struct sdk_station_config { uint8_t ssid[32]; uint8_t password[64]; uint8_t bssid_set; uint8_t bssid[6]; }; -bool wifi_station_get_config(struct station_config *config); -bool wifi_station_set_config(struct station_config *config); +bool sdk_wifi_station_get_config(struct sdk_station_config *config); +bool sdk_wifi_station_set_config(struct sdk_station_config *config); -bool wifi_station_connect(void); -bool wifi_station_disconnect(void); +bool sdk_wifi_station_connect(void); +bool sdk_wifi_station_disconnect(void); -struct scan_config { +struct sdk_scan_config { uint8_t *ssid; uint8_t *bssid; uint8_t channel; uint8_t show_hidden; }; -struct bss_info { +struct sdk_bss_info { STAILQ_ENTRY(bss_info) next; uint8_t bssid[6]; @@ -46,14 +48,14 @@ typedef enum { SCAN_PENDING, SCAN_BUSY, SCAN_CANCEL, -} scan_status_t; +} sdk_scan_status_t; -typedef void (* scan_done_cb_t)(void *arg, scan_status_t status); +typedef void (* sdk_scan_done_cb_t)(void *arg, sdk_scan_status_t status); -bool wifi_station_scan(struct scan_config *config, scan_done_cb_t cb); +bool sdk_wifi_station_scan(struct sdk_scan_config *config, sdk_scan_done_cb_t cb); -uint8_t wifi_station_get_auto_connect(void); -bool wifi_station_set_auto_connect(uint8_t set); +uint8_t sdk_wifi_station_get_auto_connect(void); +bool sdk_wifi_station_set_auto_connect(uint8_t set); enum { STATION_IDLE = 0, @@ -64,6 +66,6 @@ enum { STATION_GOT_IP }; -uint8_t wifi_station_get_connect_status(void); +uint8_t sdk_wifi_station_get_connect_status(void); #endif diff --git a/include/espressif/esp_system.h b/include/espressif/esp_system.h index be3e6a0..265bc8c 100644 --- a/include/espressif/esp_system.h +++ b/include/espressif/esp_system.h @@ -6,14 +6,14 @@ #ifndef __ESP_SYSTEM_H__ #define __ESP_SYSTEM_H__ -enum rst_reason { +enum sdk_rst_reason { DEFAULT_RST = 0, WDT_RST = 1, EXCEPTION_RST = 2, SOFT_RST = 3 }; -struct rst_info{ +struct sdk_rst_info{ uint32_t reason; uint32_t exccause; uint32_t epc1; @@ -24,26 +24,26 @@ struct rst_info{ uint32_t rtn_addr; }; -struct rst_info* system_get_rst_info(void); +struct rst_info* sdk_system_get_rst_info(void); -const char* system_get_sdk_version(void); +const char* sdk_system_get_sdk_version(void); -void system_restore(void); -void system_restart(void); -void system_deep_sleep(uint32_t time_in_us); +void sdk_system_restore(void); +void sdk_system_restart(void); +void sdk_system_deep_sleep(uint32_t time_in_us); -uint32_t system_get_time(void); +uint32_t sdk_system_get_time(void); -void system_print_meminfo(void); -uint32_t system_get_free_heap_size(void); -uint32_t system_get_chip_id(void); +void sdk_system_print_meminfo(void); +uint32_t sdk_system_get_free_heap_size(void); +uint32_t sdk_system_get_chip_id(void); -uint32_t system_rtc_clock_cali_proc(void); -uint32_t system_get_rtc_time(void); +uint32_t sdk_system_rtc_clock_cali_proc(void); +uint32_t sdk_system_get_rtc_time(void); -bool system_rtc_mem_read(uint8_t src, void *dst, uint16_t n); -bool system_rtc_mem_write(uint8_t dst, const void *src, uint16_t n); +bool sdk_system_rtc_mem_read(uint8_t src, void *dst, uint16_t n); +bool sdk_system_rtc_mem_write(uint8_t dst, const void *src, uint16_t n); -void system_uart_swap(void); +void sdk_system_uart_swap(void); #endif diff --git a/include/espressif/esp_timer.h b/include/espressif/esp_timer.h index 8ba6295..6f05547 100644 --- a/include/espressif/esp_timer.h +++ b/include/espressif/esp_timer.h @@ -7,16 +7,16 @@ #define __ESP_TIMER_H__ /* timer related */ -typedef void os_timer_func_t(void *timer_arg); +typedef void sdk_os_timer_func_t(void *timer_arg); typedef struct _os_timer_t { struct _os_timer_t *timer_next; void *freerots_handle; uint32_t timer_expire; uint32_t timer_period; - os_timer_func_t *timer_func; + sdk_os_timer_func_t *timer_func; bool timer_repeat_flag; void *timer_arg; -} os_timer_t; +} sdk_os_timer_t; #endif diff --git a/include/espressif/esp_wifi.h b/include/espressif/esp_wifi.h index 08824d6..e2274f1 100644 --- a/include/espressif/esp_wifi.h +++ b/include/espressif/esp_wifi.h @@ -1,6 +1,9 @@ /* * Copyright (C) 2013 -2014 Espressif System * + * Adapted from BSD licensed esp_iot_rtos_sdk v0.9.9 + * + * Functions declared in this header are defined in libmain.a */ #ifndef __ESP_WIFI_H__ @@ -23,8 +26,8 @@ typedef enum _auth_mode { AUTH_MAX } AUTH_MODE; -uint8_t wifi_get_opmode(void); -bool wifi_set_opmode(uint8_t opmode); +uint8_t sdk_wifi_get_opmode(void); +bool sdk_wifi_set_opmode(uint8_t opmode); enum { STATION_IF = 0, @@ -38,29 +41,29 @@ struct ip_info { struct ip_addr gw; }; -bool wifi_get_ip_info(uint8_t if_index, struct ip_info *info); -bool wifi_set_ip_info(uint8_t if_index, struct ip_info *info); -bool wifi_get_macaddr(uint8_t if_index, uint8_t *macaddr); -bool wifi_set_macaddr(uint8_t if_index, uint8_t *macaddr); +bool sdk_wifi_get_ip_info(uint8_t if_index, struct ip_info *info); +bool sdk_wifi_set_ip_info(uint8_t if_index, struct ip_info *info); +bool sdk_wifi_get_macaddr(uint8_t if_index, uint8_t *macaddr); +bool sdk_wifi_set_macaddr(uint8_t if_index, uint8_t *macaddr); -uint8_t wifi_get_channel(void); -bool wifi_set_channel(uint8_t channel); +uint8_t sdk_wifi_get_channel(void); +bool sdk_wifi_set_channel(uint8_t channel); -void wifi_status_led_install(uint8_t gpio_id, uint32_t gpio_name, uint8_t gpio_func); +void sdk_wifi_status_led_install(uint8_t gpio_id, uint32_t gpio_name, uint8_t gpio_func); -void wifi_promiscuous_enable(uint8_t promiscuous); +void sdk_wifi_promiscuous_enable(uint8_t promiscuous); -typedef void (* wifi_promiscuous_cb_t)(uint8_t *buf, uint16_t len); +typedef void (* sdk_wifi_promiscuous_cb_t)(uint8_t *buf, uint16_t len); -void wifi_set_promiscuous_rx_cb(wifi_promiscuous_cb_t cb); +void sdk_wifi_set_promiscuous_rx_cb(sdk_wifi_promiscuous_cb_t cb); -enum phy_mode { +enum sdk_phy_mode { PHY_MODE_11B = 1, PHY_MODE_11G = 2, PHY_MODE_11N = 3 }; -enum phy_mode wifi_get_phy_mode(void); -bool wifi_set_phy_mode(enum phy_mode mode); +enum phy_mode sdk_wifi_get_phy_mode(void); +bool sdk_wifi_set_phy_mode(enum sdk_phy_mode mode); #endif diff --git a/include/espressif/sdk_prototypes.h b/include/espressif/sdk_prototypes.h index 2817a72..4b5e3df 100644 --- a/include/espressif/sdk_prototypes.h +++ b/include/espressif/sdk_prototypes.h @@ -1,6 +1,11 @@ -/* This source file contains function prototypes for functions defined +/* sdk_prototypes.h + + This source file contains function prototypes for functions defined in the remaining "binary blob" ESP IoT RTOS SDK libraries. Sorted by which library they appear in. + + Function names here have the 'sdk_' prefix that is put on all binary library functions + by the Open RTOS SDK. */ #ifndef SDK_PROTOTYPES_H #define SDK_PROTOTYPES_H @@ -18,18 +23,28 @@ struct ip_addr; uart_no = 0 or 1 for which UART new_divisor = Calculated in the form UART_CLK_FREQ / BAUD */ -void uart_div_modify(uint32_t uart_no, uint32_t new_divisor); +void sdk_uart_div_modify(uint32_t uart_no, uint32_t new_divisor); + +/* Read a single character from the UART. + */ +char sdk_uart_rx_one_char(void); + +/* Write a single character to the UART. + */ +void sdk_os_putc(char c); /* Called when an IP gets set on the "station" (client) interface. */ -void system_station_got_ip_set(struct ip_addr *ip_addr, struct ip_addr *sn_mask, struct ip_addr *gw_addr); +void sdk_system_station_got_ip_set(struct ip_addr *ip_addr, struct ip_addr *sn_mask, struct ip_addr *gw_addr); /* This is a no-op wrapper around ppRecycleRxPkt, which is defined in libpp.a It's called when a pbuf is freed, and allows pp to reuse the 'eb' pointer to ESP-specific pbuf data. (See esp-lwip pbuf.h) */ -void system_pp_recycle_rx_pkt(void *eb); +void sdk_system_pp_recycle_rx_pkt(void *eb); + +const char* sdk_system_get_sdk_version(void); #endif diff --git a/include/espressif/spi_flash.h b/include/espressif/spi_flash.h index b4761f4..719c045 100644 --- a/include/espressif/spi_flash.h +++ b/include/espressif/spi_flash.h @@ -10,15 +10,15 @@ typedef enum { SPI_FLASH_RESULT_OK, SPI_FLASH_RESULT_ERR, SPI_FLASH_RESULT_TIMEOUT -} SpiFlashOpResult; +} sdk_SpiFlashOpResult; #define SPI_FLASH_SEC_SIZE 4096 -uint32_t spi_flash_get_id(void); -SpiFlashOpResult spi_flash_read_status(uint32_t *status); -SpiFlashOpResult spi_flash_write_status(uint32_t status_value); -SpiFlashOpResult spi_flash_erase_sector(uint16_t sec); -SpiFlashOpResult spi_flash_write(uint32_t des_addr, uint32_t *src_addr, uint32_t size); -SpiFlashOpResult spi_flash_read(uint32_t src_addr, uint32_t *des_addr, uint32_t size); +uint32_t sdk_spi_flash_get_id(void); +sdk_SpiFlashOpResult sdk_spi_flash_read_status(uint32_t *status); +sdk_SpiFlashOpResult sdk_spi_flash_write_status(uint32_t status_value); +sdk_SpiFlashOpResult sdk_spi_flash_erase_sector(uint16_t sec); +sdk_SpiFlashOpResult sdk_spi_flash_write(uint32_t des_addr, uint32_t *src_addr, uint32_t size); +sdk_SpiFlashOpResult sdk_spi_flash_read(uint32_t src_addr, uint32_t *des_addr, uint32_t size); #endif diff --git a/ld/eagle.app.v6.ld b/ld/eagle.app.v6.ld index daeff21..538a6c5 100644 --- a/ld/eagle.app.v6.ld +++ b/ld/eagle.app.v6.ld @@ -1,4 +1,8 @@ -/* This linker script generated from xt-genldscripts.tpp for LSP . */ +/* This linker script generated from xt-genldscripts.tpp for LSP . + + Modified for esp open RTOS, this linker script is no longer the same as the esp_iot_rtos_sdk one. +*/ + /* Linker Script for ld -N */ MEMORY { @@ -19,12 +23,12 @@ PHDRS /* Default entry point: */ -ENTRY(call_user_start) -EXTERN(_DebugExceptionVector) -EXTERN(_DoubleExceptionVector) -EXTERN(_KernelExceptionVector) -EXTERN(_NMIExceptionVector) -EXTERN(_UserExceptionVector) +ENTRY(sdk_call_user_start) +EXTERN(sdk__DebugExceptionVector) +EXTERN(sdk__DoubleExceptionVector) +EXTERN(sdk__KernelExceptionVector) +EXTERN(sdk__NMIExceptionVector) +EXTERN(sdk__UserExceptionVector) PROVIDE(_memmap_vecbase_reset = 0x40000000); /* Various memory-map dependent cache attribute settings: */ _memmap_cacheattr_wb_base = 0x00000110; diff --git a/lib/libhal.a b/lib/libhal.a deleted file mode 100644 index 728a018..0000000 Binary files a/lib/libhal.a and /dev/null differ diff --git a/lib/symbols_norename.txt b/lib/symbols_norename.txt new file mode 100644 index 0000000..8d762b4 --- /dev/null +++ b/lib/symbols_norename.txt @@ -0,0 +1,6 @@ +# this is a stop-gap to avoid renaming some useful libc +# symbols to sdk_xxx +puts +printf +putchar +atoi diff --git a/lwip/esp_interface.c b/lwip/esp_interface.c index 034c1b6..6f37b5a 100644 --- a/lwip/esp_interface.c +++ b/lwip/esp_interface.c @@ -47,7 +47,7 @@ #include "netif/etharp.h" /* declared in libnet80211.a */ -int8_t ieee80211_output_pbuf(struct netif *ifp, struct pbuf* pb); +int8_t sdk_ieee80211_output_pbuf(struct netif *ifp, struct pbuf* pb); static err_t low_level_output(struct netif *netif, struct pbuf *p) @@ -55,7 +55,7 @@ low_level_output(struct netif *netif, struct pbuf *p) struct pbuf *q; for(q = p; q != NULL; q = q->next) { - ieee80211_output_pbuf(netif, q); + sdk_ieee80211_output_pbuf(netif, q); } LINK_STATS_INC(link.xmit); diff --git a/lwip/include/arch/cc.h b/lwip/include/arch/cc.h index 507409c..fe10d25 100644 --- a/lwip/include/arch/cc.h +++ b/lwip/include/arch/cc.h @@ -35,6 +35,14 @@ /* include ESP SDK prototypes as they're used in some LWIP routines */ #include "espressif/sdk_prototypes.h" +/* ESP8266 SDK Interface + + The lwip-esp stack is designed to be also compatible with other ESP8266 SDKs, + so we can't use our 'sdk_' prefixes there +*/ +#define system_station_got_ip_set sdk_system_station_got_ip_set +#define system_pp_recycle_rx_pkt sdk_system_pp_recycle_rx_pkt + /* Include some files for defining library routines */ #include /* printf, fflush, FILE */ #include /* abort */ diff --git a/lwip/include/arch/sys_arch.h b/lwip/include/arch/sys_arch.h index 3daf87b..ac616c9 100644 --- a/lwip/include/arch/sys_arch.h +++ b/lwip/include/arch/sys_arch.h @@ -37,6 +37,8 @@ #include "queue.h" #include "semphr.h" +/* MBOX primitives */ + #define SYS_MBOX_NULL ( ( xQueueHandle ) NULL ) #define SYS_SEM_NULL ( ( xSemaphoreHandle ) NULL ) #define SYS_DEFAULT_THREAD_STACK_DEPTH configMINIMAL_STACK_SIZE