Skip to content

Add typedef for putc1, fn_putc1_t. #6550

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Sep 27, 2019
2 changes: 1 addition & 1 deletion cores/esp8266/core_esp8266_postmortem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ void __wrap_system_restart_local() {
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);
Expand Down
3 changes: 2 additions & 1 deletion cores/esp8266/libc_replacements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions cores/esp8266/uart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -899,7 +899,7 @@ void
uart_set_debug(int uart_nr)
{
s_uart_debug_nr = uart_nr;
void (*func)(char) = NULL;
fp_putc_t func = NULL;
switch(s_uart_debug_nr)
{
case UART0:
Expand All @@ -921,7 +921,7 @@ uart_set_debug(int uart_nr)
} else {
system_set_os_print(0);
}
ets_install_putc1((void *) func);
ets_install_putc1(func);
}
}

Expand Down
22 changes: 7 additions & 15 deletions cores/esp8266/umm_malloc/umm_performance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,16 @@ bool ICACHE_FLASH_ATTR get_umm_get_perf_data(struct _UMM_TIME_STATS *p, size_t s
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);
/*
* ROM builtin "print character function" _putc1, ignores CRs and sends CR/LF
* for LF, newline. This function is used internally by ets_uart_printf. It is
* also the function that gets installed by ets_uart_install_printf through a
* call to ets_install_putc1.
*/
#define _rom_putc1 ((fp_putc_t)0x40001dcc)

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
Expand Down
22 changes: 19 additions & 3 deletions tools/sdk/include/ets_sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@
extern "C" {
#endif

/*
* This "print character function" prototype is modeled after the argument for
* ets_install_putc1() found in "ESP8266_NONOS_SDK/include/osapi.h". This
* deviates away from the familiar C library definition of putchar; however, it
* agrees with the code we are working with. Note, in the ROM some "character
* print functions" always return 0 (uart_tx_one_char and ets_putc), some return
* last character printed (buildin _putc1), and some return nothing
* (ets_write_char). Using a void return type safely represents them all.
*/
typedef void (*fp_putc_t)(char);

typedef uint32_t ETSSignal;
typedef uint32_t ETSParam;

Expand Down Expand Up @@ -205,15 +216,20 @@ char *ets_strstr(const char *haystack, const char *needle);
int ets_sprintf(char *str, const char *format, ...) __attribute__ ((format (printf, 2, 3)));
int os_snprintf(char *str, size_t size, const char *format, ...) __attribute__ ((format (printf, 3, 4)));
int ets_printf(const char *format, ...) __attribute__ ((format (printf, 1, 2)));
void ets_install_putc1(void* routine);
void ets_install_putc1(fp_putc_t routine);
void ets_isr_mask(int intr);
void ets_isr_unmask(int intr);
void ets_isr_attach(int intr, int_handler_t handler, void *arg);
void ets_intr_lock();
void ets_intr_unlock();
int ets_vsnprintf(char * s, size_t n, const char * format, va_list arg) __attribute__ ((format (printf, 3, 0)));
int ets_vprintf(int (*print_function)(int), const char * format, va_list arg) __attribute__ ((format (printf, 2, 0)));
int ets_putc(int);
int ets_vprintf(fp_putc_t print_function, const char * format, va_list arg) __attribute__ ((format (printf, 2, 0)));
/*
* ets_putc(), a "print character function" in ROM, prints a character to a
* UART. It always returns 0. The use of this function requires a prior setup
* call to uart_buff_switch() to select the UART.
*/
int ets_putc(char);
bool ets_task(ETSTask task, uint8 prio, ETSEvent *queue, uint8 qlen);
bool ets_post(uint8 prio, ETSSignal sig, ETSParam par);
void ets_update_cpu_frequency(uint32_t ticks_per_us);
Expand Down