6
6
*
7
7
* Still researching options for printing.
8
8
*/
9
-
10
- /*
11
- Printing from the malloc routines is tricky. Since a print library
12
- might call *alloc. Then recusion may follow as each error call may fail
13
- into another error and so on.
14
-
15
- Objective: To be able to print "last gasp" diagnostic messages
16
- when interrupts are disabled and w/o availability of heap resources.
17
-
18
- Considerations:
19
- * can be called from ISR
20
- * can be called from malloc code, cannot use malloc
21
- * can be called from malloc code that was called from an ISR
22
- * can be called from with in a critical section, eg. xt_rsil(15);
23
- * this may be effectively the same as being called from an ISR?
24
-
25
- Knowns:
26
- * ets_printf - For RTOS SDK they replaced this function with one in the SDK.
27
- Most of the problems I can see with ets_printf center around not being
28
- able to maintain a port to thread context. That is you cannot have one
29
- thread using one port while another thread uses the other. In the no OS
30
- case we cannot have one area of code using one port and another area of
31
- code using the other port. Most of the ROM printf functions are not built
32
- to support this kind of usage. Things get especially dangerous when you
33
- try to use the ...external_printf stuff.
34
- * ets_vprintf - by itself is safe.
35
- * newlibc printf - not safe - lives in flash.
36
- * newlibc snprintf - not safe - lives in flash.
37
- * builtin putc1 print function - Is installed when you use
38
- ets_install_uart_printf. Which calls ets_install_putc1. The selection of UART
39
- is performed by calling uart_buff_switch with 0 for UART0 and 1 for UART1.
40
- This should work for our purpose here, if handled as follows:
41
- * call uart_buff_switch at each printf call to reselect UART
42
- * use a stack buffer to hold a copy the PROGMEM string to print from.
43
- * use ets_vprintf for printing with putc1 function.
44
- * os_printf_plus looks interesting. It is in IRAM. If no heap is available it
45
- will use up to 64 bytes of stack space to copy a PROGMEM fmt for printing.
46
- Issues:
47
- * Printing is turned off by system_set_os_print
48
- * putc1 needs to be in IRAM - this is a uart.cpp issue
49
- * Need to force system_get_free_heap_size to return 0 during critical periods.
50
- * won't work for umm_info it prints over 64 characters.
51
- * along with umm_info there are other debug messages that exceed 64 characters.
52
-
53
- Research TODO, Unknowns:
54
- * Is there a problem with the ROM "serial print functions"?
55
- Rtos SDK does not use them. igrr also didn't use them in ...postmortem.
56
- See "ets_printf" above.
57
-
58
- */
59
-
60
9
#include < stdio.h>
61
10
#include < string.h>
62
11
#include < pgmspace.h>
@@ -66,36 +15,8 @@ extern "C" {
66
15
67
16
#if defined(DEBUG_ESP_ISR)
68
17
69
- int _isr_safe_printf_P (const char *fmt, ...) __attribute__((format(printf, 1 , 2 )));
70
- // Note, _isr_safe_printf_P will not handle additional string arguments in
71
- // PROGMEM. Only the 1st parameter, fmt, is supported in PROGMEM.
72
- #define ISR_PRINTF (fmt, ...) _isr_safe_printf_P(PSTR(fmt), ##__VA_ARGS__)
73
- #define ISR_PRINTF_P (fmt, ...) _isr_safe_printf_P(fmt, ##__VA_ARGS__)
74
-
75
- // Boot ROM _putc1, ignores CRs and sends CR/LF for LF, newline.
76
- // Always returns character sent.
77
- typedef int (*fp_putc_t )(int );
78
- #define _rom_putc1 ((fp_putc_t )0x40001dcc )
79
-
80
- void uart_buff_switch (uint8_t );
81
-
82
18
int _isr_safe_printf_P (const char *fmt, ...) __attribute__((format(printf, 1 , 2 )));
83
19
int ICACHE_RAM_ATTR _isr_safe_printf_P (const char *fmt, ...) {
84
-
85
- // C This #ifdef block is obsolete if the PR for ets_putc UART selection is approved.
86
- #ifdef DEBUG_ESP_PORT
87
- #define VALUE (x ) __STRINGIFY(x)
88
- // Preprocessor and compiler together will optimize away the if.
89
- if (strcmp (" Serial1" , VALUE (DEBUG_ESP_PORT)) == 0 ) {
90
- uart_buff_switch (1U );
91
- } else {
92
- uart_buff_switch (0U );
93
- }
94
- #else
95
- uart_buff_switch (0U ); // Side effect, clears RX FIFO
96
- #endif
97
- // C - end
98
-
99
20
/*
100
21
To use ets_strlen() and ets_memcpy() safely with PROGMEM, flash storage,
101
22
the PROGMEM address must be word (4 bytes) aligned. The destination
@@ -109,10 +30,11 @@ int ICACHE_RAM_ATTR _isr_safe_printf_P(const char *fmt, ...) {
109
30
ets_memcpy (ram_buf, fmt, buf_len);
110
31
va_list argPtr;
111
32
va_start (argPtr, fmt);
112
- int result = ets_vprintf (_rom_putc1 , ram_buf, argPtr);
33
+ int result = ets_vprintf (ets_uart_putc1 , ram_buf, argPtr);
113
34
va_end (argPtr);
114
35
return result;
115
36
}
37
+
116
38
#endif
<
292D
code>117 39
118
40
};
0 commit comments