Various C/C++ source fixes to support newer GCC

This commit is contained in:
Kurt Sassenrath 2023-07-20 22:39:58 -07:00
parent 80f454d546
commit 09f0382e56
10 changed files with 111 additions and 35 deletions

View File

@ -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)
{

View File

@ -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).

View File

@ -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

View File

@ -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
}
}

View File

@ -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) */

View File

@ -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)
{

View File

@ -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,

View File

@ -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

View File

@ -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 */

View File

@ -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