From 9d0b024433516187ec7024a27f816e22168fd8db Mon Sep 17 00:00:00 2001 From: Zhang Jun Hao Date: Wed, 27 Jun 2018 11:27:40 +0800 Subject: [PATCH] feat(esp8266): Refactor ets system headler file --- components/esp8266/driver/gpio.c | 2 +- components/esp8266/driver/hw_timer.c | 2 +- components/esp8266/driver/i2c_master.c | 3 +- components/esp8266/driver/spi_interface.c | 2 +- components/esp8266/driver/uart.c | 4 +- .../esp8266/include/driver/i2c_master.h | 2 +- components/esp8266/include/esp_misc.h | 93 ------------------- components/esp8266/include/esp_types.h | 25 +++++ .../include/{esp8266 => rom}/ets_sys.h | 34 +++++++ .../esp8266/source/event_default_handlers.c | 3 +- components/freertos/port/esp8266/heap_5.c | 2 +- components/freertos/port/esp8266/panic.c | 2 +- components/freertos/port/esp8266/port.c | 2 +- components/lwip/apps/dhcpserver/dhcpserver.c | 3 +- .../include/lwip/apps/dhcpserver/dhcpserver.h | 1 - components/newlib/newlib/port/syscall.c | 2 +- components/tcpip_adapter/tcpip_adapter_lwip.c | 2 +- 17 files changed, 74 insertions(+), 110 deletions(-) delete mode 100644 components/esp8266/include/esp_misc.h create mode 100644 components/esp8266/include/esp_types.h rename components/esp8266/include/{esp8266 => rom}/ets_sys.h (75%) diff --git a/components/esp8266/driver/gpio.c b/components/esp8266/driver/gpio.c index 6727ed2f..e6151ef3 100644 --- a/components/esp8266/driver/gpio.c +++ b/components/esp8266/driver/gpio.c @@ -17,7 +17,7 @@ #include "esp8266/eagle_soc.h" #include "esp8266/pin_mux_register.h" -#include "esp8266/ets_sys.h" +#include "rom/ets_sys.h" #include "FreeRTOS.h" diff --git a/components/esp8266/driver/hw_timer.c b/components/esp8266/driver/hw_timer.c index 9f4b3460..e9ad90aa 100644 --- a/components/esp8266/driver/hw_timer.c +++ b/components/esp8266/driver/hw_timer.c @@ -16,7 +16,7 @@ #include #include -#include "esp8266/ets_sys.h" +#include "rom/ets_sys.h" #include "esp8266/eagle_soc.h" #include "esp8266/timer_register.h" diff --git a/components/esp8266/driver/i2c_master.c b/components/esp8266/driver/i2c_master.c index 06883d87..c3735c26 100644 --- a/components/esp8266/driver/i2c_master.c +++ b/components/esp8266/driver/i2c_master.c @@ -15,8 +15,7 @@ #include #include -#include "esp8266/ets_sys.h" -#include "esp_misc.h" +#include "rom/ets_sys.h" #include "gpio.h" #include "i2c_master.h" diff --git a/components/esp8266/driver/spi_interface.c b/components/esp8266/driver/spi_interface.c index 0b3646ae..f044e9db 100644 --- a/components/esp8266/driver/spi_interface.c +++ b/components/esp8266/driver/spi_interface.c @@ -19,7 +19,7 @@ #include -#include "esp8266/ets_sys.h" +#include "rom/ets_sys.h" #include "esp8266/pin_mux_register.h" #include "spi_interface.h" diff --git a/components/esp8266/driver/uart.c b/components/esp8266/driver/uart.c index 418b5922..6573299a 100644 --- a/components/esp8266/driver/uart.c +++ b/components/esp8266/driver/uart.c @@ -19,9 +19,7 @@ #include "esp8266/pin_mux_register.h" #include "esp8266/uart_register.h" #include "esp8266/rom_functions.h" -#include "esp8266/ets_sys.h" - -#include "esp_misc.h" +#include "rom/ets_sys.h" #include "freertos/FreeRTOS.h" #include "freertos/task.h" diff --git a/components/esp8266/include/driver/i2c_master.h b/components/esp8266/include/driver/i2c_master.h index 7cc98abc..63b3381b 100644 --- a/components/esp8266/include/driver/i2c_master.h +++ b/components/esp8266/include/driver/i2c_master.h @@ -17,7 +17,7 @@ #include -#include "esp_misc.h" +#include "rom/ets_sys.h" #include "esp8266/pin_mux_register.h" #include "gpio.h" diff --git a/components/esp8266/include/esp_misc.h b/components/esp8266/include/esp_misc.h deleted file mode 100644 index 990f5617..00000000 --- a/components/esp8266/include/esp_misc.h +++ /dev/null @@ -1,93 +0,0 @@ -/* - * ESPRSSIF MIT License - * - * Copyright (c) 2015 - * - * Permission is hereby granted for use on ESPRESSIF SYSTEMS ESP8266 only, in which case, - * it is free of charge, to any person obtaining a copy of this software and associated - * documentation files (the "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the Software is furnished - * to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or - * substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - */ - -#ifndef __ESP_MISC_H__ -#define __ESP_MISC_H__ - -#include - -#include "lwip/ip_addr.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** \defgroup Misc_APIs Misc APIs - * @brief misc APIs - */ - -/** @addtogroup Misc_APIs - * @{ - */ - -#define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5] -#define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x" - -#define IP2STR(ipaddr) ip4_addr1_16(ipaddr), \ - ip4_addr2_16(ipaddr), \ - ip4_addr3_16(ipaddr), \ - ip4_addr4_16(ipaddr) - -#define IPSTR "%d.%d.%d.%d" - -/** - * @brief Delay function, maximum value: 65535 us. - * - * @param uint16_t us : delay time, uint: us, maximum value: 65535 us - * - * @return null - */ -void os_delay_us(uint16_t us); - -/** - * @brief Register the print output function. - * - * @attention os_install_putc1((void *)uart1_write_char) in uart_init will set - * printf to print from UART 1, otherwise, printf will start from - * UART 0 by default. - * - * @param void(*p)(char c) - pointer of print function - * - * @return null - */ -void os_install_putc1(void (*p)(char c)); - -/** - * @brief Print a character. Start from from UART0 by default. - * - * @param char c - character to be printed - * - * @return null - */ -void os_putc(char c); - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/components/esp8266/include/esp_types.h b/components/esp8266/include/esp_types.h new file mode 100644 index 00000000..547024e3 --- /dev/null +++ b/components/esp8266/include/esp_types.h @@ -0,0 +1,25 @@ +// Copyright 2010-2016 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef __ESP_TYPES_H__ +#define __ESP_TYPES_H__ + +#ifdef __GNUC__ +#include +#endif /*__GNUC__*/ +#include +#include +#include + +#endif /* __ESP_TYPES_H__ */ diff --git a/components/esp8266/include/esp8266/ets_sys.h b/components/esp8266/include/rom/ets_sys.h similarity index 75% rename from components/esp8266/include/esp8266/ets_sys.h rename to components/esp8266/include/rom/ets_sys.h index c0f9d397..8ced18f2 100644 --- a/components/esp8266/include/esp8266/ets_sys.h +++ b/components/esp8266/include/rom/ets_sys.h @@ -82,4 +82,38 @@ extern uint32_t WDEV_INTEREST_EVENT; } \ } while(0) +#define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5] +#define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x" + +/** + * @brief Delay function, maximum value: 65535 us. + * + * @param uint16_t us : delay time, uint: us, maximum value: 65535 us + * + * @return null + */ +void os_delay_us(uint16_t us); + +/** + * @brief Register the print output function. + * + * @attention os_install_putc1((void *)uart1_write_char) in uart_init will set + * printf to print from UART 1, otherwise, printf will start from + * UART 0 by default. + * + * @param void(*p)(char c) - pointer of print function + * + * @return null + */ +void os_install_putc1(void (*p)(char c)); + +/** + * @brief Print a character. Start from from UART0 by default. + * + * @param char c - character to be printed + * + * @return null + */ +void os_putc(char c); + #endif /* _ETS_SYS_H */ diff --git a/components/esp8266/source/event_default_handlers.c b/components/esp8266/source/event_default_handlers.c index aa22abaf..5ce4aaa7 100644 --- a/components/esp8266/source/event_default_handlers.c +++ b/components/esp8266/source/event_default_handlers.c @@ -16,9 +16,10 @@ #include #include +#include "rom/ets_sys.h" + #include "esp_err.h" #include "esp_wifi.h" -#include "esp_misc.h" #include "esp_event.h" #include "esp_event_loop.h" #include "esp_system.h" diff --git a/components/freertos/port/esp8266/heap_5.c b/components/freertos/port/esp8266/heap_5.c index e67d1310..0b98b2bf 100644 --- a/components/freertos/port/esp8266/heap_5.c +++ b/components/freertos/port/esp8266/heap_5.c @@ -118,7 +118,7 @@ task.h is included from an application file. */ #include "freertos/task.h" #include "esp8266/eagle_soc.h" -#include "esp8266/ets_sys.h" +#include "rom/ets_sys.h" #include "esp8266/rom_functions.h" #ifdef MEMLEAK_DEBUG diff --git a/components/freertos/port/esp8266/panic.c b/components/freertos/port/esp8266/panic.c index 1aa43026..bab9cc9a 100644 --- a/components/freertos/port/esp8266/panic.c +++ b/components/freertos/port/esp8266/panic.c @@ -16,7 +16,7 @@ #include "esp_libc.h" #include "esp8266/eagle_soc.h" -#include "esp8266/ets_sys.h" +#include "rom/ets_sys.h" #include "esp_err.h" /* diff --git a/components/freertos/port/esp8266/port.c b/components/freertos/port/esp8266/port.c index d4167226..17304b29 100644 --- a/components/freertos/port/esp8266/port.c +++ b/components/freertos/port/esp8266/port.c @@ -83,7 +83,7 @@ #include "esp_libc.h" #include "esp8266/eagle_soc.h" -#include "esp8266/ets_sys.h" +#include "rom/ets_sys.h" #include "esp8266/rom_functions.h" #define PORT_ASSERT(x) do { if (!(x)) {ets_printf("%s %u\n", "rtos_port", __LINE__); while(1){}; }} while (0) diff --git a/components/lwip/apps/dhcpserver/dhcpserver.c b/components/lwip/apps/dhcpserver/dhcpserver.c index 85e9ad20..e00505d4 100644 --- a/components/lwip/apps/dhcpserver/dhcpserver.c +++ b/components/lwip/apps/dhcpserver/dhcpserver.c @@ -17,9 +17,10 @@ #include #include "esp_libc.h" -#include "esp_misc.h" #include "esp_wifi.h" +#include "rom/ets_sys.h" + #include "sdkconfig.h" #include "lwip/inet.h" #include "lwip/err.h" diff --git a/components/lwip/include/lwip/apps/dhcpserver/dhcpserver.h b/components/lwip/include/lwip/apps/dhcpserver/dhcpserver.h index 258791f6..10186fe7 100644 --- a/components/lwip/include/lwip/apps/dhcpserver/dhcpserver.h +++ b/components/lwip/include/lwip/apps/dhcpserver/dhcpserver.h @@ -35,7 +35,6 @@ typedef struct dhcps_msg { u8_t options[312]; }dhcps_msg; -/* Defined in esp_misc.h */ typedef struct { bool enable; ip4_addr_t start_ip; diff --git a/components/newlib/newlib/port/syscall.c b/components/newlib/newlib/port/syscall.c index d0a29931..343ae6e7 100644 --- a/components/newlib/newlib/port/syscall.c +++ b/components/newlib/newlib/port/syscall.c @@ -16,7 +16,7 @@ #include #include -#include "esp8266/ets_sys.h" +#include "rom/ets_sys.h" #include "esp8266/eagle_soc.h" #include "esp8266/uart_register.h" #include "FreeRTOS.h" diff --git a/components/tcpip_adapter/tcpip_adapter_lwip.c b/components/tcpip_adapter/tcpip_adapter_lwip.c index 634d3997..0279e578 100644 --- a/components/tcpip_adapter/tcpip_adapter_lwip.c +++ b/components/tcpip_adapter/tcpip_adapter_lwip.c @@ -28,7 +28,7 @@ #include "netif/etharp.h" #include "esp_wifi.h" #include "esp_timer.h" -#include "esp_misc.h" +#include "rom/ets_sys.h" #include "dhcpserver/dhcpserver.h" #include "dhcpserver/dhcpserver_options.h" #include "net/sockio.h"