1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-07-16 00:43:00 +03:00

Add typedef for putc1, fn_putc1_t. (#6550)

* Add typedef for putc1, fn_putc1_t.
Replaced relevant usage of `(void *)` with `fn_putc1_t`.
Correct usage of `ets_putc()`, returning 0, in libc_replacement.cpp
This PR assumes PR https://github.com/esp8266/Arduino/pull/6489#issue-315018841 has merged and removes `uart_buff_switch` from `umm_performance.cpp`
Updated method of defining `_rom_putc1` to be more acceptable (I hope) to the new compiler.

* Use PROVIDE to expose ROM function entry point, ets_uart_putc1.
Added comments to ets_putc() and ets_uart_putc1() to explain their
differences. Change prototype of ets_putc() to conform with fp_putc_t.
Updated _isr_safe_printf_P to use new definition, ets_uart_putc1.
This commit is contained in:
M Hightower
2019-09-27 14:23:16 -07:00
committed by Earle F. Philhower, III
parent ff1e8e92d1
commit 831d6431bc
6 changed files with 49 additions and 27 deletions

View File

@ -108,8 +108,7 @@ void __wrap_system_restart_local() {
else
rst_info.reason = s_user_reset_reason;
// TODO: ets_install_putc1 definition is wrong in ets_sys.h, need cast
ets_install_putc1((void *)&uart_write_char_d);
ets_install_putc1(&uart_write_char_d);
if (s_panic_line) {
ets_printf_P(PSTR("\nPanic %S:%d %S"), s_panic_file, s_panic_line, s_panic_func);

View File

@ -100,7 +100,8 @@ int ICACHE_RAM_ATTR _putc_r(struct _reent* r, int c, FILE* file) __attribute__((
int ICACHE_RAM_ATTR _putc_r(struct _reent* r, int c, FILE* file) {
(void) r;
if (file->_file == STDOUT_FILENO) {
return ets_putc(c);
ets_putc(c);
return c;
}
return EOF;
}

View File

@ -899,8 +899,8 @@ void
uart_set_debug(int uart_nr)
{
s_uart_debug_nr = uart_nr;
void (*func)(char) = NULL;
switch(s_uart_debug_nr)
fp_putc_t func = NULL;
switch(s_uart_debug_nr)
{
case UART0:
func = &uart0_write_char;
@ -929,7 +929,7 @@ uart_set_debug(int uart_nr)
} else {
system_set_os_print(0);
}
ets_install_putc1((void *) func);
ets_install_putc1(func);
}
}

View File

@ -39,25 +39,8 @@ bool ICACHE_FLASH_ATTR get_umm_get_perf_data(struct _UMM_TIME_STATS *p, size_t s
Objective: To be able to print "last gasp" diagnostic messages
when interrupts are disabled and w/o availability of heap resources.
*/
// ROM _putc1, ignores CRs and sends CR/LF for LF, newline.
// Always returns character sent.
int constexpr (*_rom_putc1)(int) = (int (*)(int))0x40001dcc;
void uart_buff_switch(uint8_t);
int _isr_safe_printf_P(const char *fmt, ...) __attribute__((format(printf, 1, 2)));
int ICACHE_RAM_ATTR _isr_safe_printf_P(const char *fmt, ...) {
#ifdef DEBUG_ESP_PORT
#define VALUE(x) __STRINGIFY(x)
// Preprocessor and compiler together will optimize away the if.
if (strcmp("Serial1", VALUE(DEBUG_ESP_PORT)) == 0) {
uart_buff_switch(1U);
} else {
uart_buff_switch(0U);
}
#else
uart_buff_switch(0U); // Side effect, clears RX FIFO
#endif
/*
To use ets_strlen() and ets_memcpy() safely with PROGMEM, flash storage,
the PROGMEM address must be word (4 bytes) aligned. The destination
@ -71,7 +54,7 @@ int ICACHE_RAM_ATTR _isr_safe_printf_P(const char *fmt, ...) {
ets_memcpy(ram_buf, fmt, buf_len);
va_list argPtr;
va_start(argPtr, fmt);
int result = ets_vprintf(_rom_putc1, ram_buf, argPtr);
int result = ets_vprintf(ets_uart_putc1, ram_buf, argPtr);
va_end(argPtr);
return result;
}