lib_printf.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. // Copyright 2016 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. /**
  15. * @file lib_printf.c
  16. *
  17. * This file contains library-specific printf functions
  18. * used by WiFi libraries in the `lib` directory.
  19. * These function are used to catch any output which gets printed
  20. * by libraries, and redirect it to ESP_LOG macros.
  21. *
  22. * Eventually WiFi libraries will use ESP_LOG functions internally
  23. * and these definitions will be removed.
  24. */
  25. #include <stdio.h>
  26. #include <stdlib.h>
  27. #include "esp_log.h"
  28. #include "esp_attr.h"
  29. #define VPRINTF_STACK_BUFFER_SIZE 80
  30. static int lib_printf(const char* tag, const char* format, va_list arg)
  31. {
  32. char temp[VPRINTF_STACK_BUFFER_SIZE];
  33. int len = vsnprintf(temp, sizeof(temp) - 1, format, arg);
  34. temp[sizeof(temp) - 1] = 0;
  35. int i;
  36. for (i = len - 1; i >= 0; --i) {
  37. if (temp[i] != '\n' && temp[i] != '\r' && temp[i] != ' ') {
  38. break;
  39. }
  40. temp[i] = 0;
  41. }
  42. if (i > 0) {
  43. ESP_EARLY_LOGI(tag, "%s", temp);
  44. }
  45. va_end(arg);
  46. return len;
  47. }
  48. int phy_printf(const char* format, ...)
  49. {
  50. va_list arg;
  51. va_start(arg, format);
  52. int res = lib_printf("phy", format, arg);
  53. va_end(arg);
  54. return res;
  55. }
  56. int rtc_printf(const char* format, ...)
  57. {
  58. // librtc.a printf temporary disabled due to UART baud rate switching bug.
  59. return 0;
  60. }
  61. int wpa_printf(const char* format, ...)
  62. {
  63. va_list arg;
  64. va_start(arg, format);
  65. int res = lib_printf("wpa", format, arg);
  66. va_end(arg);
  67. return res;
  68. }
  69. int wpa2_printf(const char* format, ...)
  70. {
  71. va_list arg;
  72. va_start(arg, format);
  73. int res = lib_printf("wpa2", format, arg);
  74. va_end(arg);
  75. return res;
  76. }
  77. int wps_printf(const char* format, ...)
  78. {
  79. va_list arg;
  80. va_start(arg, format);
  81. int res = lib_printf("wps", format, arg);
  82. va_end(arg);
  83. return res;
  84. }
  85. int pp_printf(const char* format, ...)
  86. {
  87. va_list arg;
  88. va_start(arg, format);
  89. int res = lib_printf("pp", format, arg);
  90. va_end(arg);
  91. return res;
  92. }
  93. int sc_printf(const char* format, ...)
  94. {
  95. va_list arg;
  96. va_start(arg, format);
  97. int res = lib_printf("smartconfig", format, arg);
  98. va_end(arg);
  99. return res;
  100. }
  101. int core_printf(const char* format, ...)
  102. {
  103. va_list arg;
  104. va_start(arg, format);
  105. int res = lib_printf("core", format, arg);
  106. va_end(arg);
  107. return res;
  108. }
  109. int net80211_printf(const char* format, ...)
  110. {
  111. va_list arg;
  112. va_start(arg, format);
  113. int res = lib_printf("net80211", format, arg);
  114. va_end(arg);
  115. return res;
  116. }
  117. int coexist_printf(const char* format, ...)
  118. {
  119. va_list arg;
  120. va_start(arg, format);
  121. int res = lib_printf("coexist", format, arg);
  122. va_end(arg);
  123. return res;
  124. }
  125. int mesh_printf(const char* format, ...)
  126. {
  127. va_list arg;
  128. va_start(arg, format);
  129. int res = lib_printf("mesh", format, arg);
  130. va_end(arg);
  131. return res;
  132. }