summaryrefslogtreecommitdiff
path: root/ota-test/main
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2018-06-03 23:35:52 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2018-06-03 23:35:52 +0200
commitfadeb06d74c3d739dc1202031e1eea1374e8917e (patch)
tree2db95dbaea94299c74ab90b2fc4ce3fc44e70acf /ota-test/main
parent934bbf7d019e561209802f6a679b3672ce58ef1a (diff)
downloadmodern-esp-sandbox-fadeb06d74c3d739dc1202031e1eea1374e8917e.tar.gz
modern-esp-sandbox-fadeb06d74c3d739dc1202031e1eea1374e8917e.tar.bz2
modern-esp-sandbox-fadeb06d74c3d739dc1202031e1eea1374e8917e.tar.xz
modern-esp-sandbox-fadeb06d74c3d739dc1202031e1eea1374e8917e.zip
wip
Diffstat (limited to 'ota-test/main')
-rw-r--r--ota-test/main/component.mk4
-rw-r--r--ota-test/main/main.cpp52
-rw-r--r--ota-test/main/misc.c52
3 files changed, 108 insertions, 0 deletions
diff --git a/ota-test/main/component.mk b/ota-test/main/component.mk
new file mode 100644
index 0000000..a98f634
--- /dev/null
+++ b/ota-test/main/component.mk
@@ -0,0 +1,4 @@
+#
+# "main" pseudo-component makefile.
+#
+# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.)
diff --git a/ota-test/main/main.cpp b/ota-test/main/main.cpp
new file mode 100644
index 0000000..a64f03f
--- /dev/null
+++ b/ota-test/main/main.cpp
@@ -0,0 +1,52 @@
+#include "esp_misc.h"
+#include "esp_sta.h"
+#include "esp_system.h"
+#include "esp_wifi.h"
+#include "esp_spiffs.h"
+#include "sdkconfig.h"
+
+#include <assert.h>
+
+extern "C"
+uint32_t user_rf_cal_sector_set();
+
+extern "C"
+void user_init();
+
+enum events {
+ EVENTS_GOT_IP = (1 << 0),
+ EVENTS_LOST_IP = (1 << 1),
+};
+
+static void set_wifi_mode() {
+ if (wifi_get_opmode_default() != NULL_MODE) {
+ printf("Setting default station mode");
+ wifi_set_opmode(NULL_MODE);
+ }
+
+ wifi_set_opmode_current(NULL_MODE);
+}
+
+void main_task(void* ctx) {
+ (void) ctx;
+
+ int count = 0;
+ while (1) {
+ printf("Hello World! %d\n", count++);
+
+ vTaskDelay(pdMS_TO_TICKS(1000));
+ }
+}
+
+#define THREAD_NAME "main"
+#define THREAD_STACK_WORDS 2048
+#define THREAD_PRIO 8
+
+TaskHandle_t main_task_handle;
+void user_init() {
+ os_printf("SDK version: %s, free: %d, app build: %s\n", system_get_sdk_version(), system_get_free_heap_size(), __TIMESTAMP__);
+
+ set_wifi_mode();
+
+ assert(xTaskCreate(main_task, THREAD_NAME, THREAD_STACK_WORDS, NULL, THREAD_PRIO, &main_task_handle) == pdPASS);
+}
diff --git a/ota-test/main/misc.c b/ota-test/main/misc.c
new file mode 100644
index 0000000..1b5119b
--- /dev/null
+++ b/ota-test/main/misc.c
@@ -0,0 +1,52 @@
+#include <esp_system.h>
+
+/******************************************************************************
+ * FunctionName : user_rf_cal_sector_set
+ * Description : SDK just reversed 4 sectors, used for rf init data and paramters.
+ * We add this function to force users to set rf cal sector, since
+ * we don't know which sector is free in user's application.
+ * sector map for last several sectors : ABCCC
+ * A : rf cal
+ * B : rf init data
+ * C : sdk parameters
+ * Parameters : none
+ * Returns : rf cal sector
+*******************************************************************************/
+uint32_t user_rf_cal_sector_set()
+{
+ flash_size_map size_map = system_get_flash_size_map();
+ uint32_t rf_cal_sec = 0;
+
+ switch (size_map) {
+ case FLASH_SIZE_4M_MAP_256_256:
+ rf_cal_sec = 128 - 5;
+ break;
+
+ case FLASH_SIZE_8M_MAP_512_512:
+ rf_cal_sec = 256 - 5;
+ break;
+
+ case FLASH_SIZE_16M_MAP_512_512:
+ case FLASH_SIZE_16M_MAP_1024_1024:
+ rf_cal_sec = 512 - 5;
+ break;
+
+ case FLASH_SIZE_32M_MAP_512_512:
+ case FLASH_SIZE_32M_MAP_1024_1024:
+ rf_cal_sec = 1024 - 5;
+ break;
+ case FLASH_SIZE_64M_MAP_1024_1024:
+ rf_cal_sec = 2048 - 5;
+ break;
+ case FLASH_SIZE_128M_MAP_1024_1024:
+ rf_cal_sec = 4096 - 5;
+ break;
+ default:
+ rf_cal_sec = 0;
+ break;
+ }
+
+ return rf_cal_sec;
+}
+
+