diff --git a/core/esp_timer.c b/core/esp_timer.c index 2110948..473e617 100644 --- a/core/esp_timer.c +++ b/core/esp_timer.c @@ -18,7 +18,7 @@ const static uint32_t IROM _TIMER_FREQS[] = { _FREQ_DIV1, _FREQ_DIV16, _FREQ_DIV256 }; /* Timer divisor index to divisor value */ -const static uint32_t IROM _TIMER_DIV_VAL[] = { 1, 16, 256 }; +const static uint32_t IROM _TIMER_DIV_VAL[] __attribute__((unused)) = { 1, 16, 256 }; void timer_set_interrupts(const timer_frc_t frc, bool enable) { diff --git a/core/include/common_macros.h b/core/include/common_macros.h index 7034787..4585c6c 100644 --- a/core/include/common_macros.h +++ b/core/include/common_macros.h @@ -39,11 +39,29 @@ /* Set bits in reg with specified mask. */ +#ifdef __cplusplus +constexpr inline auto SET_MASK_BITS(auto volatile& reg, auto mask) { + auto value = reg; + value |= mask; + reg = value; + return reg; +} +#else #define SET_MASK_BITS(reg, mask) (reg) |= (mask) +#endif /* Clear bits in reg with specified mask */ +#ifdef __cplusplus +constexpr inline auto CLEAR_MASK_BITS(auto volatile& reg, auto mask) { + auto value = reg; + value &= ~mask; + reg = value; + return reg; +} +#else #define CLEAR_MASK_BITS(reg, mask) (reg) &= ~(mask) +#endif /* Use the IRAM macro to place functions into Instruction RAM (IRAM) instead of flash (aka irom). diff --git a/core/include/debug_dumps.h b/core/include/debug_dumps.h index 8b82b84..4f739e5 100644 --- a/core/include/debug_dumps.h +++ b/core/include/debug_dumps.h @@ -21,7 +21,7 @@ void dump_heapinfo(void); Probably not useful to be called in other contexts. */ void __attribute__((noreturn)) fatal_exception_handler(uint32_t *sp, bool registers_saved_on_stack); -void __attribute__((weak, alias("fatal_exception_handler"))) +void __attribute__((noreturn)) __attribute__((weak, alias("fatal_exception_handler"))) debug_exception_handler(uint32_t *sp, bool registers_saved_on_stack); #endif diff --git a/core/include/esp/gpio.h b/core/include/esp/gpio.h index 85842aa..376d4c6 100644 --- a/core/include/esp/gpio.h +++ b/core/include/esp/gpio.h @@ -48,7 +48,13 @@ void gpio_set_pullup(uint8_t gpio_num, bool enabled, bool enabled_during_sleep); static inline void gpio_disable(const uint8_t gpio_num) { GPIO.ENABLE_OUT_CLEAR = BIT(gpio_num); +#ifdef __cplusplus + auto value = *gpio_iomux_reg(gpio_num); + value &= ~IOMUX_PIN_OUTPUT_ENABLE; + *gpio_iomux_reg(gpio_num) = value; +#else *gpio_iomux_reg(gpio_num) &= ~IOMUX_PIN_OUTPUT_ENABLE; +#endif } /* Set whether the specified pin continues to drive its output when the ESP8266 @@ -61,9 +67,21 @@ static inline void gpio_disable(const uint8_t gpio_num) static inline void gpio_set_output_on_sleep(const uint8_t gpio_num, bool enabled) { if (enabled) { +#ifdef __cplusplus + auto value = IOMUX.PIN[gpio_to_iomux(gpio_num)]; + value |= IOMUX_PIN_OUTPUT_ENABLE_SLEEP; + IOMUX.PIN[gpio_to_iomux(gpio_num)] = value; +#else IOMUX.PIN[gpio_to_iomux(gpio_num)] |= IOMUX_PIN_OUTPUT_ENABLE_SLEEP; +#endif } else { +#ifdef __cplusplus + auto value = IOMUX.PIN[gpio_to_iomux(gpio_num)]; + value &= ~IOMUX_PIN_OUTPUT_ENABLE_SLEEP; + IOMUX.PIN[gpio_to_iomux(gpio_num)] = value; +#else IOMUX.PIN[gpio_to_iomux(gpio_num)] &= ~IOMUX_PIN_OUTPUT_ENABLE_SLEEP; +#endif } } diff --git a/core/include/esp/timer.h b/core/include/esp/timer.h index fc74992..df52373 100644 --- a/core/include/esp/timer.h +++ b/core/include/esp/timer.h @@ -65,10 +65,23 @@ void timer_set_interrupts(const timer_frc_t frc, bool enable); /* Turn the timer on or off */ static inline void timer_set_run(const timer_frc_t frc, const bool run) { - if (run) + if (run) { +#ifdef __cplusplus + auto value = TIMER(frc).CTRL; + value |= TIMER_CTRL_RUN; + TIMER(frc).CTRL = value; +#else TIMER(frc).CTRL |= TIMER_CTRL_RUN; - else +#endif + } else { +#ifdef __cplusplus + auto value = TIMER(frc).CTRL; + value &= ~TIMER_CTRL_RUN; + TIMER(frc).CTRL = value; +#else TIMER(frc).CTRL &= ~TIMER_CTRL_RUN; +#endif + } } /* Get the run state of the timer (on or off) */ @@ -80,10 +93,23 @@ static inline bool timer_get_run(const timer_frc_t frc) /* Set timer auto-reload on or off */ static inline void timer_set_reload(const timer_frc_t frc, const bool reload) { - if (reload) + if (reload) { +#ifdef __cplusplus + auto value = TIMER(frc).CTRL; + value |= TIMER_CTRL_RELOAD; + TIMER(frc).CTRL = value; +#else TIMER(frc).CTRL |= TIMER_CTRL_RELOAD; - else +#endif + } else { +#ifdef __cplusplus + auto value = TIMER(frc).CTRL; + value &= ~TIMER_CTRL_RELOAD; + TIMER(frc).CTRL = value; +#else TIMER(frc).CTRL &= ~TIMER_CTRL_RELOAD; +#endif + } } /* Get the auto-reload state of the timer (on or off) */ diff --git a/core/newlib_syscalls.c b/core/newlib_syscalls.c index 50d0d30..cf83c76 100644 --- a/core/newlib_syscalls.c +++ b/core/newlib_syscalls.c @@ -29,6 +29,11 @@ #if LWIP_SOCKET_OFFSET < 3 #error Expecting a LWIP_SOCKET_OFFSET >= 3, to allow room for the standard I/O descriptors. #endif + +extern ssize_t lwip_read(int s, void *mem, size_t len); +extern ssize_t lwip_write(int s, const void *mem, size_t len); +extern int lwip_close(int s); + #define FILE_DESCRIPTOR_OFFSET (LWIP_SOCKET_OFFSET + MEMP_NUM_NETCONN) #if FILE_DESCRIPTOR_OFFSET > FD_SETSIZE #error Too many lwip sockets for the FD_SETSIZE. @@ -175,31 +180,6 @@ __attribute__((weak)) int _close_r(struct _reent *r, int fd) return -1; } -/* Stub syscall implementations follow, to allow compiling newlib functions that - pull these in via various codepaths -*/ -__attribute__((weak, alias("syscall_returns_enosys"))) -int _open_r(struct _reent *r, const char *pathname, int flags, int mode); - -__attribute__((weak, alias("syscall_returns_enosys"))) -int _unlink_r(struct _reent *r, const char *path); - -__attribute__((weak, alias("syscall_returns_enosys"))) -int _fstat_r(struct _reent *r, int fd, struct stat *buf); - -__attribute__((weak, alias("syscall_returns_enosys"))) -int _stat_r(struct _reent *r, const char *pathname, struct stat *buf); - -__attribute__((weak, alias("syscall_returns_enosys"))) -off_t _lseek_r(struct _reent *r, int fd, off_t offset, int whence); - -__attribute__((weak, alias("_gettimeofday_r"))) -int _gettimeofday_r (struct _reent *ptr, struct timeval *ptimeval, void *ptimezone) { - ptimeval->tv_sec = 0; - ptimeval->tv_usec = 0; - errno = ENOSYS; - return -1; -} /* Generic stub for any newlib syscall that fails with errno ENOSYS ("Function not implemented") and a return value equivalent to @@ -209,6 +189,31 @@ static int syscall_returns_enosys(struct _reent *r) r->_errno=ENOSYS; return -1; } +/* Stub syscall implementations follow, to allow compiling newlib functions that + pull these in via various codepaths +*/ +__attribute__((weak)) +int _open_r(struct _reent *r, const char *pathname, int flags, int mode) { return syscall_returns_enosys(r); } + +__attribute__((weak)) +int _unlink_r(struct _reent *r, const char *path) { return syscall_returns_enosys(r); } + +__attribute__((weak)) +int _fstat_r(struct _reent *r, int fd, struct stat *buf) { return syscall_returns_enosys(r); } + +__attribute__((weak)) +int _stat_r(struct _reent *r, const char *pathname, struct stat *buf) { return syscall_returns_enosys(r); } + +__attribute__((weak)) +off_t _lseek_r(struct _reent *r, int fd, off_t offset, int whence) { return syscall_returns_enosys(r); } + +__attribute__((weak)) +int _gettimeofday_r (struct _reent *ptr, struct timeval *ptimeval, void *ptimezone) { + ptimeval->tv_sec = 0; + ptimeval->tv_usec = 0; + errno = ENOSYS; + return -1; +} int getentropy(void *ptr, size_t n) { diff --git a/include/espressif/phy_info.h b/include/espressif/phy_info.h index bda23ea..f9d33e8 100644 --- a/include/espressif/phy_info.h +++ b/include/espressif/phy_info.h @@ -174,8 +174,13 @@ /* Run full RF CAL routine. RF init takes approx 200ms. */ #define RF_CAL_MODE_FULL 3 -/* Data structure that maps to the phy_info configuration block */ -typedef struct __attribute__((packed)) { +/* Data structure that maps to the phy_info configuration block. + * This was originally attributed with the ((packed)) attribute, + * but I don't currently see a reason why it needs to be. The + * structure uses only u8, so there shouldn't be any padding + * inserted. + */ +typedef struct { uint8_t _reserved00[0x05]; /* 0x00 - 0x04 */ /* This "version" field was set to 5 in the SDK phy_info, diff --git a/libc/xtensa-lx106-elf/include/stdlib.h b/libc/xtensa-lx106-elf/include/stdlib.h index 5417ac0..238ed7b 100644 --- a/libc/xtensa-lx106-elf/include/stdlib.h +++ b/libc/xtensa-lx106-elf/include/stdlib.h @@ -144,8 +144,12 @@ void qsort (void *__base, size_t __nmemb, size_t __size, __compar_fn_t _compar); int rand (void); void * realloc (void *__r, size_t __size) _NOTHROW; #if __BSD_VISIBLE +#if 0 void *reallocarray(void *, size_t, size_t) __result_use_check __alloc_size(2) __alloc_size(3); +#else +void *reallocarray(void *, size_t, size_t) __result_use_check __attribute__((alloc_size(2, 3))); +#endif void * reallocf (void *__r, size_t __size); #endif #if __BSD_VISIBLE || __XSI_VISIBLE >= 4 diff --git a/libc/xtensa-lx106-elf/include/sys/reent.h b/libc/xtensa-lx106-elf/include/sys/reent.h index 0f21c68..c0c847b 100644 --- a/libc/xtensa-lx106-elf/include/sys/reent.h +++ b/libc/xtensa-lx106-elf/include/sys/reent.h @@ -404,7 +404,7 @@ struct _reent char *_asctime_buf; /* signal info */ - void (**(_sig_func))(int); + void (**_sig_func)(int); # ifndef _REENT_GLOBAL_ATEXIT /* atexit stuff */ diff --git a/open_esplibs/libpp/pp.c b/open_esplibs/libpp/pp.c index 4439c5a..cb58424 100644 --- a/open_esplibs/libpp/pp.c +++ b/open_esplibs/libpp/pp.c @@ -18,7 +18,7 @@ static const uint32_t pp_zeros[8]; void *_ppz20(size_t n) { - return &pp_zeros; + return (void*)&pp_zeros; } #if OPEN_LIBPP_PP