admin管理员组文章数量:1126994
using Mongoose OS, I have a function mgos_ethernet_init, defined in app2\deps\ethernet\src\esp32\esp32_eth.c If this function returns false the device fails to boot. I am attempting to create a retry for this function and to allow boot to continue if it fails, after setting a fail flag.
Apparently this isn't a global variable?
I created this file:
#include "mgos.h"
#include "mgos_eth.h"
static int retry_count = 0;
static const int MAX_RETRIES = 2;
static const int RETRY_DELAY_MS = 500; // 5 seconds retry delay
static void retry_ethernet_init_cb(void *arg) {
if (!mgos_ethernet_init()) {
retry_count++;
if (retry_count < MAX_RETRIES) {
LOG(LL_INFO, ("Retrying Ethernet initialization attempt %d/%d.", retry_count + 1, MAX_RETRIES));
mgos_set_timer(RETRY_DELAY_MS, 0, retry_ethernet_init_cb, NULL);
} else {
LOG(LL_ERROR, ("Ethernet initialization failed after %d attempts.", MAX_RETRIES));
// Handle failure, perhaps set a flag or proceed with other initializations
}
} else {
LOG(LL_INFO, ("Ethernet initialized after retry."));
retry_count = 0;
}
}
bool mgos_deps_init(void) {
if (!mgos_ethernet_init() && retry_count == 0) {
LOG(LL_INFO, ("First Ethernet initialization failed, setting up retry."));
mgos_set_timer(RETRY_DELAY_MS, 0, retry_ethernet_init_cb, NULL);
}
// Continue with other dependency initializations
return true; // Return true to continue boot regardless of Ethernet status
}
in app2\src\custom_init.c
although mgos_ethernet_init is not defined, as shown in this compile error:
/c/mos/app2/src/custom_init.c: In function 'retry_ethernet_init_cb':
/c/mos/app2/src/custom_init.c:9:10: error: implicit declaration of function 'mgos_ethernet_init'; did you mean 'retry_ethernet_init_cb'? [-Werror=implicit-function-declaration]
if (!mgos_ethernet_init()) {
^~~~~~~~~~~~~~~~~~
retry_ethernet_init_cb
/c/mos/app2/src/custom_init.c: In function 'mgos_deps_init':
/c/mos/app2/src/custom_init.c:30:5: error: expected declaration or statement at end of input
return true; // Return true to continue boot regardless of Ethernet status
^~~~~~
cc1: all warnings being treated as errors
make[3]: *** [esp-idf/mosapp/CMakeFiles/__idf_mosapp.dir/build.make:76: esp-idf/mosapp/CMakeFiles/__idf_mosapp.dir/c/mos/app2/src/custom_init.c.obj] Error 1
make[3]: *** Waiting for unfinished jobs....
make[2]: *** [CMakeFiles/Makefile2:3195: esp-idf/mosapp/CMakeFiles/__idf_mosapp.dir/all] Error 2
make[1]: *** [Makefile:91: all] Error 2
make: *** [/mongoose-os/platforms/esp32xx/Makefile.build:220: /c/mos/app2/build/objs/app2.bin] Error 2
make: Leaving directory '/app'
Error: exit status 2
本文标签: ccalling external functions in mongoose OSsoft Eth failStack Overflow
版权声明:本文标题:c - calling external functions in mongoose OS - soft Eth fail - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736688645a1947797.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论