Skip to content

Commit 9603a15

Browse files
committed
feat: add uniform esp platform support
1 parent 21c262f commit 9603a15

File tree

7 files changed

+98
-17
lines changed

7 files changed

+98
-17
lines changed

Diff for: components/azure_iot/azure

Submodule azure updated 745 files

Diff for: components/azure_iot/component.mk

+7-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44

55
# Component configuration in preprocessor defines
66
CFLAGS += -DUSE_LWIP_SOCKET_FOR_AZURE_IOT
7-
7+
8+
ifdef CONFIG_TARGET_PLATFORM_ESP8266
9+
CFLAGS += -DCONFIG_FREERTOS_HZ=100
10+
endif
811

912
COMPONENT_ADD_INCLUDEDIRS := \
1013
pal \
@@ -28,8 +31,8 @@ azure/c-utility/pal/freertos/threadapi.o \
2831
azure/c-utility/pal/freertos/tickcounter.o \
2932
azure/c-utility/pal/tlsio_options.o \
3033
\
31-
pal/src/agenttime_esp32.o \
32-
pal/src/platform_esp32.o \
34+
pal/src/agenttime_esp.o \
35+
pal/src/platform_esp.o \
3336
pal/src/tlsio_openssl_compact.o \
3437
\
3538
azure/c-utility/src/xlogging.o \
@@ -64,6 +67,7 @@ azure/c-utility/src/base64.o \
6467
\
6568
\
6669
azure/iothub_client/src/iothub_client_ll.o \
70+
azure/iothub_client/src/iothub_client_core_ll.o \
6771
azure/iothub_client/src/iothub_client_ll_uploadtoblob.o \
6872
azure/iothub_client/src/iothub_client_authorization.o \
6973
azure/iothub_client/src/iothub_client_retry_control.o \

Diff for: components/azure_iot/pal/inc/socket_async_os.h

+8-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,14 @@
1111
#ifndef SOCKET_ASYNC_OS_H
1212
#define SOCKET_ASYNC_OS_H
1313

14+
#include "sdkconfig.h"
15+
16+
#ifdef CONFIG_TARGET_PLATFORM_ESP8266
17+
#include "sys/socket.h"
18+
#else
1419
#include "lwip/sockets.h"
20+
#endif
21+
1522
#include "lwip/netdb.h"
1623

17-
#endif // SOCKET_ASYNC_OS_H
24+
#endif // SOCKET_ASYNC_OS_H

Diff for: components/azure_iot/pal/src/agenttime_esp32.c renamed to components/azure_iot/pal/src/agenttime_esp.c

+7-10
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,26 @@
1111
#include "esp_event_loop.h"
1212
#include "esp_log.h"
1313
#include "esp_attr.h"
14-
#include "esp_deep_sleep.h"
1514
#include "nvs_flash.h"
1615

1716
#include "lwip/err.h"
1817
#include "azure_c_shared_utility/agenttime.h"
1918
#include "azure_c_shared_utility/xlogging.h"
19+
20+
#ifdef CONFIG_TARGET_PLATFORM_ESP8266
21+
#include "lwip/apps/sntp.h"
22+
#else
2023
#include "apps/sntp/sntp.h"
24+
#endif
25+
26+
2127

2228
void initialize_sntp(void)
2329
{
2430
printf("Initializing SNTP\n");
2531
sntp_setoperatingmode(SNTP_OPMODE_POLL);
2632
sntp_setservername(0, "pool.ntp.org");
2733
// sntp_setservername(1, "202.112.29.82"); // set sntp server after got ip address, you had better to adjust the sntp server to your area
28-
// sntp_setservername(2, "ntp.sjtu.edu.cn");
29-
// sntp_setservername(3, "0.nettime.pool.ntp.org");
30-
// sntp_setservername(4, "time-b.nist.gov");
31-
// sntp_setservername(5, "time-a.timefreq.bldrdoc.gov");
32-
// sntp_setservername(6, "time-b.timefreq.bldrdoc.gov");
33-
// sntp_setservername(7, "time-c.timefreq.bldrdoc.gov");
34-
// sntp_setservername(8, "utcnist.colorado.edu");
35-
// sntp_setservername(9, "time.nist.gov");
36-
// sntp_setservername(10, "us.pool.ntp.org");
3734
sntp_init();
3835
}
3936

Diff for: components/azure_iot/pal/src/platform_esp32.c renamed to components/azure_iot/pal/src/platform_esp.c

+7-1
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,16 @@
99
#include "azure_c_shared_utility/xio.h"
1010
#include "azure_c_shared_utility/tlsio_openssl.h"
1111
#include "azure_c_shared_utility/xlogging.h"
12-
#include "apps/sntp/sntp.h"
1312
#include "esp_log.h"
1413
#include "tlsio_pal.h"
1514

15+
#ifdef CONFIG_TARGET_PLATFORM_ESP8266
16+
#include "lwip/apps/sntp.h"
17+
#else
18+
#include "apps/sntp/sntp.h"
19+
#endif
20+
21+
1622
//#include "lwip/apps/sntp_time.h"
1723
#define TICK_RATE CONFIG_FREERTOS_HZ
1824

Diff for: main/azure_main.c

+63-1
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,71 @@
3030
/* FreeRTOS event group to signal when we are connected & ready to make a request */
3131
static EventGroupHandle_t wifi_event_group;
3232

33+
#ifndef BIT0
34+
#define BIT0 (0x1 << 0)
35+
#endif
3336
/* The event group allows multiple bits for each event,
3437
but we only care about one event - are we connected
3538
to the AP with an IP? */
3639
const int CONNECTED_BIT = BIT0;
3740

3841
static const char *TAG = "azure";
3942

43+
#ifdef CONFIG_TARGET_PLATFORM_ESP8266
44+
45+
/******************************************************************************
46+
* FunctionName : user_rf_cal_sector_set
47+
* Description : SDK just reversed 4 sectors, used for rf init data and paramters.
48+
* We add this function to force users to set rf cal sector, since
49+
* we don't know which sector is free in user's application.
50+
* sector map for last several sectors : ABCCC
51+
* A : rf cal
52+
* B : rf init data
53+
* C : sdk parameters
54+
* Parameters : none
55+
* Returns : rf cal sector
56+
*******************************************************************************/
57+
uint32_t user_rf_cal_sector_set(void)
58+
{
59+
flash_size_map size_map = system_get_flash_size_map();
60+
uint32_t rf_cal_sec = 0;
61+
62+
switch (size_map) {
63+
case FLASH_SIZE_4M_MAP_256_256:
64+
rf_cal_sec = 128 - 5;
65+
break;
66+
67+
case FLASH_SIZE_8M_MAP_512_512:
68+
rf_cal_sec = 256 - 5;
69+
break;
70+
71+
case FLASH_SIZE_16M_MAP_512_512:
72+
case FLASH_SIZE_16M_MAP_1024_1024:
73+
rf_cal_sec = 512 - 5;
74+
break;
75+
76+
case FLASH_SIZE_32M_MAP_512_512:
77+
case FLASH_SIZE_32M_MAP_1024_1024:
78+
rf_cal_sec = 1024 - 5;
79+
break;
80+
81+
case FLASH_SIZE_64M_MAP_1024_1024:
82+
rf_cal_sec = 2048 - 5;
83+
break;
84+
85+
case FLASH_SIZE_128M_MAP_1024_1024:
86+
rf_cal_sec = 4096 - 5;
87+
break;
88+
89+
default:
90+
rf_cal_sec = 0;
91+
break;
92+
}
93+
94+
return rf_cal_sec;
95+
}
96+
#endif
97+
4098
static esp_err_t event_handler(void *ctx, system_event_t *event)
4199
{
42100
switch(event->event_id) {
@@ -102,5 +160,9 @@ void app_main()
102160
{
103161
nvs_flash_init();
104162
initialise_wifi();
105-
xTaskCreate(&azure_task, "azure_task", 8192, NULL, 5, NULL);
163+
164+
if ( xTaskCreate(&azure_task, "azure_task", 1024 * 10, NULL, 5, NULL) != pdPASS ) {
165+
printf("create azure task failed\r\n");
166+
}
167+
106168
}

Diff for: sdkconfig.defaults

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# newlib for ESP32 and ESP8266 platform
2+
3+
CONFIG_NEWLIB_ENABLE=y
4+
CONFIG_NEWLIB_LIBRARY_LEVEL_NORMAL=y
5+
CONFIG_NEWLIB_NANO_FORMAT=

0 commit comments

Comments
 (0)