mirror of
https://github.com/cesanta/mongoose.git
synced 2025-08-06 13:37:34 +08:00
Improve Zephyr support
This commit is contained in:
parent
471e7ff61a
commit
806ee0f2cb
20
mongoose.c
20
mongoose.c
@ -7185,6 +7185,10 @@ MG_IRAM void single_bank_swap(char *p1, char *p2, size_t size) {
|
||||
|
||||
bool mg_ota_begin(size_t new_firmware_size) {
|
||||
s_mg_flash_stm32f.size = flash_size();
|
||||
#ifdef __ZEPHYR__
|
||||
*((uint32_t *)0xE000ED94) = 0;
|
||||
MG_DEBUG(("Jailbreak %s", *((uint32_t *)0xE000ED94) == 0 ? "successful" : "failed"));
|
||||
#endif
|
||||
return mg_ota_flash_begin(new_firmware_size, &s_mg_flash_stm32f);
|
||||
}
|
||||
|
||||
@ -7350,6 +7354,10 @@ static bool mg_stm32h5_write(void *addr, const void *buf, size_t len) {
|
||||
}
|
||||
|
||||
bool mg_ota_begin(size_t new_firmware_size) {
|
||||
#ifdef __ZEPHYR__
|
||||
*((uint32_t *)0xE000ED94) = 0;
|
||||
MG_DEBUG(("Jailbreak %s", *((uint32_t *)0xE000ED94) == 0 ? "successful" : "failed"));
|
||||
#endif
|
||||
return mg_ota_flash_begin(new_firmware_size, &s_mg_flash_stm32h5);
|
||||
}
|
||||
|
||||
@ -7554,6 +7562,10 @@ bool mg_ota_begin(size_t new_firmware_size) {
|
||||
// Using only the 1st bank (mapped to CM7)
|
||||
s_mg_flash_stm32h7.size /= 2;
|
||||
}
|
||||
#ifdef __ZEPHYR__
|
||||
*((uint32_t *)0xE000ED94) = 0;
|
||||
MG_DEBUG(("Jailbreak %s", *((uint32_t *)0xE000ED94) == 0 ? "successful" : "failed"));
|
||||
#endif
|
||||
return mg_ota_flash_begin(new_firmware_size, &s_mg_flash_stm32h7);
|
||||
}
|
||||
|
||||
@ -8806,15 +8818,19 @@ void mg_multicast_add(struct mg_connection *c, char *ip) {
|
||||
#elif MG_ENABLE_FREERTOS_TCP
|
||||
// TODO(): prvAllowIPPacketIPv4()
|
||||
#else
|
||||
// lwIP, Unix, Windows, Zephyr(, AzureRTOS ?)
|
||||
// lwIP, Unix, Windows, Zephyr 4+(, AzureRTOS ?)
|
||||
#if MG_ENABLE_LWIP && !LWIP_IGMP
|
||||
MG_ERROR(("LWIP_IGMP not defined, no multicast support"));
|
||||
#else
|
||||
#if defined(__ZEPHYR__) && ZEPHYR_VERSION_CODE < 0x40000
|
||||
MG_ERROR(("struct ip_mreq not defined"));
|
||||
#else
|
||||
struct ip_mreq mreq;
|
||||
mreq.imr_multiaddr.s_addr = inet_addr(ip);
|
||||
mreq.imr_interface.s_addr = mg_htonl(INADDR_ANY);
|
||||
setsockopt(FD(c), IPPROTO_IP, IP_ADD_MEMBERSHIP, (char *) &mreq, sizeof(mreq));
|
||||
#endif
|
||||
#endif // !Zephyr
|
||||
#endif // !lwIP
|
||||
#endif
|
||||
}
|
||||
|
||||
|
12
mongoose.h
12
mongoose.h
@ -622,6 +622,7 @@ typedef int socklen_t;
|
||||
|
||||
#if MG_ARCH == MG_ARCH_ZEPHYR
|
||||
|
||||
#include <zephyr/version.h>
|
||||
#include <zephyr/kernel.h>
|
||||
|
||||
#include <ctype.h>
|
||||
@ -1306,9 +1307,14 @@ uint32_t mg_ntohl(uint32_t net);
|
||||
#define MG_ROUND_UP(x, a) ((a) == 0 ? (x) : ((((x) + (a) -1) / (a)) * (a)))
|
||||
#define MG_ROUND_DOWN(x, a) ((a) == 0 ? (x) : (((x) / (a)) * (a)))
|
||||
|
||||
#if defined(__GNUC__)
|
||||
#if defined(__GNUC__) && defined(__arm__)
|
||||
#ifdef __ZEPHYR__
|
||||
#define MG_ARM_DISABLE_IRQ() __asm__ __volatile__("cpsid i" : : : "memory")
|
||||
#define MG_ARM_ENABLE_IRQ() __asm__ __volatile__("cpsie i" : : : "memory")
|
||||
#else
|
||||
#define MG_ARM_DISABLE_IRQ() asm volatile("cpsid i" : : : "memory")
|
||||
#define MG_ARM_ENABLE_IRQ() asm volatile("cpsie i" : : : "memory")
|
||||
#endif // !ZEPHYR
|
||||
#elif defined(__CCRH__)
|
||||
#define MG_RH850_DISABLE_IRQ() __DI()
|
||||
#define MG_RH850_ENABLE_IRQ() __EI()
|
||||
@ -1322,7 +1328,11 @@ uint32_t mg_ntohl(uint32_t net);
|
||||
#elif defined(__ARMCC_VERSION)
|
||||
#define MG_DSB() __builtin_arm_dsb(0xf)
|
||||
#elif defined(__GNUC__) && defined(__arm__) && defined(__thumb__)
|
||||
#ifdef __ZEPHYR__
|
||||
#define MG_DSB() __asm__("DSB 0xf")
|
||||
#else
|
||||
#define MG_DSB() asm("DSB 0xf")
|
||||
#endif // !ZEPHYR
|
||||
#elif defined(__ICCARM__)
|
||||
#define MG_DSB() __iar_builtin_DSB()
|
||||
#else
|
||||
|
@ -200,6 +200,10 @@ MG_IRAM void single_bank_swap(char *p1, char *p2, size_t size) {
|
||||
|
||||
bool mg_ota_begin(size_t new_firmware_size) {
|
||||
s_mg_flash_stm32f.size = flash_size();
|
||||
#ifdef __ZEPHYR__
|
||||
*((uint32_t *)0xE000ED94) = 0;
|
||||
MG_DEBUG(("Jailbreak %s", *((uint32_t *)0xE000ED94) == 0 ? "successful" : "failed"));
|
||||
#endif
|
||||
return mg_ota_flash_begin(new_firmware_size, &s_mg_flash_stm32f);
|
||||
}
|
||||
|
||||
|
@ -135,6 +135,10 @@ static bool mg_stm32h5_write(void *addr, const void *buf, size_t len) {
|
||||
}
|
||||
|
||||
bool mg_ota_begin(size_t new_firmware_size) {
|
||||
#ifdef __ZEPHYR__
|
||||
*((uint32_t *)0xE000ED94) = 0;
|
||||
MG_DEBUG(("Jailbreak %s", *((uint32_t *)0xE000ED94) == 0 ? "successful" : "failed"));
|
||||
#endif
|
||||
return mg_ota_flash_begin(new_firmware_size, &s_mg_flash_stm32h5);
|
||||
}
|
||||
|
||||
|
@ -184,6 +184,10 @@ bool mg_ota_begin(size_t new_firmware_size) {
|
||||
// Using only the 1st bank (mapped to CM7)
|
||||
s_mg_flash_stm32h7.size /= 2;
|
||||
}
|
||||
#ifdef __ZEPHYR__
|
||||
*((uint32_t *)0xE000ED94) = 0;
|
||||
MG_DEBUG(("Jailbreak %s", *((uint32_t *)0xE000ED94) == 0 ? "successful" : "failed"));
|
||||
#endif
|
||||
return mg_ota_flash_begin(new_firmware_size, &s_mg_flash_stm32h7);
|
||||
}
|
||||
|
||||
|
@ -185,15 +185,19 @@ void mg_multicast_add(struct mg_connection *c, char *ip) {
|
||||
#elif MG_ENABLE_FREERTOS_TCP
|
||||
// TODO(): prvAllowIPPacketIPv4()
|
||||
#else
|
||||
// lwIP, Unix, Windows, Zephyr(, AzureRTOS ?)
|
||||
// lwIP, Unix, Windows, Zephyr 4+(, AzureRTOS ?)
|
||||
#if MG_ENABLE_LWIP && !LWIP_IGMP
|
||||
MG_ERROR(("LWIP_IGMP not defined, no multicast support"));
|
||||
#else
|
||||
#if defined(__ZEPHYR__) && ZEPHYR_VERSION_CODE < 0x40000
|
||||
MG_ERROR(("struct ip_mreq not defined"));
|
||||
#else
|
||||
struct ip_mreq mreq;
|
||||
mreq.imr_multiaddr.s_addr = inet_addr(ip);
|
||||
mreq.imr_interface.s_addr = mg_htonl(INADDR_ANY);
|
||||
setsockopt(FD(c), IPPROTO_IP, IP_ADD_MEMBERSHIP, (char *) &mreq, sizeof(mreq));
|
||||
#endif
|
||||
#endif // !Zephyr
|
||||
#endif // !lwIP
|
||||
#endif
|
||||
}
|
||||
|
||||
|
11
src/util.h
11
src/util.h
@ -72,9 +72,14 @@ uint32_t mg_ntohl(uint32_t net);
|
||||
#define MG_ROUND_UP(x, a) ((a) == 0 ? (x) : ((((x) + (a) -1) / (a)) * (a)))
|
||||
#define MG_ROUND_DOWN(x, a) ((a) == 0 ? (x) : (((x) / (a)) * (a)))
|
||||
|
||||
#if defined(__GNUC__)
|
||||
#if defined(__GNUC__) && defined(__arm__)
|
||||
#ifdef __ZEPHYR__
|
||||
#define MG_ARM_DISABLE_IRQ() __asm__ __volatile__("cpsid i" : : : "memory")
|
||||
#define MG_ARM_ENABLE_IRQ() __asm__ __volatile__("cpsie i" : : : "memory")
|
||||
#else
|
||||
#define MG_ARM_DISABLE_IRQ() asm volatile("cpsid i" : : : "memory")
|
||||
#define MG_ARM_ENABLE_IRQ() asm volatile("cpsie i" : : : "memory")
|
||||
#endif // !ZEPHYR
|
||||
#elif defined(__CCRH__)
|
||||
#define MG_RH850_DISABLE_IRQ() __DI()
|
||||
#define MG_RH850_ENABLE_IRQ() __EI()
|
||||
@ -88,7 +93,11 @@ uint32_t mg_ntohl(uint32_t net);
|
||||
#elif defined(__ARMCC_VERSION)
|
||||
#define MG_DSB() __builtin_arm_dsb(0xf)
|
||||
#elif defined(__GNUC__) && defined(__arm__) && defined(__thumb__)
|
||||
#ifdef __ZEPHYR__
|
||||
#define MG_DSB() __asm__("DSB 0xf")
|
||||
#else
|
||||
#define MG_DSB() asm("DSB 0xf")
|
||||
#endif // !ZEPHYR
|
||||
#elif defined(__ICCARM__)
|
||||
#define MG_DSB() __iar_builtin_DSB()
|
||||
#else
|
||||
|
Loading…
Reference in New Issue
Block a user