mirror of
https://github.com/espressif/ESP8266_RTOS_SDK.git
synced 2025-07-15 08:32:42 +08:00
feat(esp8266): Add "putc" and "vprintf" of version "ets_"
This commit is contained in:
@ -13,7 +13,6 @@
|
||||
// limitations under the License.
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include "esp_attr.h"
|
||||
|
||||
@ -21,16 +20,27 @@
|
||||
#include "esp8266/uart_register.h"
|
||||
#include "esp8266/rom_functions.h"
|
||||
|
||||
static void IRAM_ATTR uart_tx_one_char(char c)
|
||||
#ifndef CONFIG_ETS_PUTC_UART
|
||||
#define CONFIG_ETS_PUTC_UART 0
|
||||
#endif
|
||||
|
||||
int IRAM_ATTR ets_putc(int c)
|
||||
{
|
||||
while (1) {
|
||||
uint32_t fifo_cnt = READ_PERI_REG(UART_STATUS(0)) & (UART_TXFIFO_CNT << UART_TXFIFO_CNT_S);
|
||||
uint32_t fifo_cnt = READ_PERI_REG(UART_STATUS(CONFIG_ETS_PUTC_UART)) & (UART_TXFIFO_CNT << UART_TXFIFO_CNT_S);
|
||||
|
||||
if ((fifo_cnt >> UART_TXFIFO_CNT_S & UART_TXFIFO_CNT) < 126)
|
||||
break;
|
||||
}
|
||||
|
||||
WRITE_PERI_REG(UART_FIFO(0) , c);
|
||||
WRITE_PERI_REG(UART_FIFO(CONFIG_ETS_PUTC_UART) , c);
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
int IRAM_ATTR ets_vprintf(const char *fmt, va_list ap)
|
||||
{
|
||||
return ets_io_vprintf(ets_putc, fmt, ap);
|
||||
}
|
||||
|
||||
/* Re-write ets_printf in SDK side, since ets_printf in ROM will use a global
|
||||
@ -42,7 +52,7 @@ int IRAM_ATTR ets_printf(const char* fmt, ...)
|
||||
int ret;
|
||||
|
||||
va_start(ap, fmt);
|
||||
ret = ets_vprintf(uart_tx_one_char, fmt, ap);
|
||||
ret = ets_vprintf(fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
return ret;
|
||||
|
Reference in New Issue
Block a user