Skip to content

Commit 713040d

Browse files
committed
Add typedef for putc1, fn_putc1_t.
Replaced relevent usage of `(void *)` with `fn_putc1_t`. Correct usage of `ets_putc()`, returning 0, in libc_replacement.cpp This PR assumes PR esp8266#6489 (comment) 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.
1 parent 69f3e81 commit 713040d

File tree

5 files changed

+31
-22
lines changed

5 files changed

+31
-22
lines changed

cores/esp8266/core_esp8266_postmortem.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ void __wrap_system_restart_local() {
109109
rst_info.reason = s_user_reset_reason;
110110

111111
// TODO: ets_install_putc1 definition is wrong in ets_sys.h, need cast
112-
ets_install_putc1((void *)&uart_write_char_d);
112+
ets_install_putc1(&uart_write_char_d);
113113

114114
if (s_panic_line) {
115115
ets_printf_P(PSTR("\nPanic %S:%d %S"), s_panic_file, s_panic_line, s_panic_func);

cores/esp8266/libc_replacements.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ int ICACHE_RAM_ATTR _putc_r(struct _reent* r, int c, FILE* file) __attribute__((
100100
int ICACHE_RAM_ATTR _putc_r(struct _reent* r, int c, FILE* file) {
101101
(void) r;
102102
if (file->_file == STDOUT_FILENO) {
103-
return ets_putc(c);
103+
ets_putc(c);
104+
return c;
104105
}
105106
return EOF;
106107
}

cores/esp8266/uart.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -899,7 +899,7 @@ void
899899
uart_set_debug(int uart_nr)
900900
{
901901
s_uart_debug_nr = uart_nr;
902-
void (*func)(char) = NULL;
902+
fp_putc_t func = NULL;
903903
switch(s_uart_debug_nr)
904904
{
905905
case UART0:
@@ -921,7 +921,7 @@ uart_set_debug(int uart_nr)
921921
} else {
922922
system_set_os_print(0);
923923
}
924-
ets_install_putc1((void *) func);
924+
ets_install_putc1(func);
925925
}
926926
}
927927

cores/esp8266/umm_malloc/umm_performance.cpp

+7-15
Original file line numberDiff line numberDiff line change
@@ -40,24 +40,16 @@ bool ICACHE_FLASH_ATTR get_umm_get_perf_data(struct _UMM_TIME_STATS *p, size_t s
4040
when interrupts are disabled and w/o availability of heap resources.
4141
*/
4242

43-
// ROM _putc1, ignores CRs and sends CR/LF for LF, newline.
44-
// Always returns character sent.
45-
int constexpr (*_rom_putc1)(int) = (int (*)(int))0x40001dcc;
46-
void uart_buff_switch(uint8_t);
43+
/*
44+
* ROM builtin "print character function" _putc1, ignores CRs and sends CR/LF
45+
* for LF, newline. This function is used internally by ets_uart_printf. It is
46+
* also the function that gets installed by ets_uart_install_printf through a
47+
* call to ets_install_putc1.
48+
*/
49+
#define _rom_putc1 ((fp_putc_t)0x40001dcc)
4750

4851
int _isr_safe_printf_P(const char *fmt, ...) __attribute__((format(printf, 1, 2)));
4952
int ICACHE_RAM_ATTR _isr_safe_printf_P(const char *fmt, ...) {
50-
#ifdef DEBUG_ESP_PORT
51-
#define VALUE(x) __STRINGIFY(x)
52-
// Preprocessor and compiler together will optimize away the if.
53-
if (strcmp("Serial1", VALUE(DEBUG_ESP_PORT)) == 0) {
54-
uart_buff_switch(1U);
55-
} else {
56-
uart_buff_switch(0U);
57-
}
58-
#else
59-
uart_buff_switch(0U); // Side effect, clears RX FIFO
60-
#endif
6153
/*
6254
To use ets_strlen() and ets_memcpy() safely with PROGMEM, flash storage,
6355
the PROGMEM address must be word (4 bytes) aligned. The destination

tools/sdk/include/ets_sys.h

+19-3
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,17 @@
3333
extern "C" {
3434
#endif
3535

36+
/*
37+
* This "print character function" prototype is modeled after the argument for
38+
* ets_install_putc1() found in "ESP8266_NONOS_SDK/include/osapi.h". This
39+
* deviates away from the familiar C library definition of putchar; however, it
40+
* agrees with the code we are working with. Note, in the ROM some "character
41+
* print functions" always return 0 (uart_tx_one_char and ets_putc), some return
42+
* last character printed (buildin _putc1), and some return nothing
43+
* (ets_write_char). Using a void return type safely represents them all.
44+
*/
45+
typedef void (*fp_putc_t)(char);
46+
3647
typedef uint32_t ETSSignal;
3748
typedef uint32_t ETSParam;
3849

@@ -205,15 +216,20 @@ char *ets_strstr(const char *haystack, const char *needle);
205216
int ets_sprintf(char *str, const char *format, ...) __attribute__ ((format (printf, 2, 3)));
206217
int os_snprintf(char *str, size_t size, const char *format, ...) __attribute__ ((format (printf, 3, 4)));
207218
int ets_printf(const char *format, ...) __attribute__ ((format (printf, 1, 2)));
208-
void ets_install_putc1(void* routine);
219+
void ets_install_putc1(fp_putc_t routine);
209220
void ets_isr_mask(int intr);
210221
void ets_isr_unmask(int intr);
211222
void ets_isr_attach(int intr, int_handler_t handler, void *arg);
212223
void ets_intr_lock();
213224
void ets_intr_unlock();
214225
int ets_vsnprintf(char * s, size_t n, const char * format, va_list arg) __attribute__ ((format (printf, 3, 0)));
215-
int ets_vprintf(int (*print_function)(int), const char * format, va_list arg) __attribute__ ((format (printf, 2, 0)));
216-
int ets_putc(int);
226+
int ets_vprintf(fp_putc_t print_function, const char * format, va_list arg) __attribute__ ((format (printf, 2, 0)));
227+
/*
228+
* ets_putc(), a "print character function" in ROM, prints a character to a
229+
* UART. It always returns 0. The use of this function requires a prior setup
230+
* call to uart_buff_switch() to select the UART.
231+
*/
232+
int ets_putc(char);
217233
bool ets_task(ETSTask task, uint8 prio, ETSEvent *queue, uint8 qlen);
218234
bool ets_post(uint8 prio, ETSSignal sig, ETSParam par);
219235
void ets_update_cpu_frequency(uint32_t ticks_per_us);

0 commit comments

Comments
 (0)