|
@@ -2,13 +2,39 @@
|
|
|
#include "luat_base.h"
|
|
#include "luat_base.h"
|
|
|
#include "luat_log.h"
|
|
#include "luat_log.h"
|
|
|
#include "luat_uart.h"
|
|
#include "luat_uart.h"
|
|
|
|
|
+#include "luat_malloc.h"
|
|
|
#include "printf.h"
|
|
#include "printf.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
|
|
+#include "FreeRTOS.h"
|
|
|
|
|
+#include "queue.h"
|
|
|
|
|
+#include "task.h"
|
|
|
|
|
+
|
|
|
|
|
+typedef struct log_msg {
|
|
|
|
|
+ char* buff;
|
|
|
|
|
+}log_msg_t;
|
|
|
|
|
+
|
|
|
|
|
+static QueueHandle_t xQueue = NULL;
|
|
|
|
|
+
|
|
|
static uint8_t luat_log_uart_port = 0;
|
|
static uint8_t luat_log_uart_port = 0;
|
|
|
static uint8_t luat_log_level_cur = LUAT_LOG_DEBUG;
|
|
static uint8_t luat_log_level_cur = LUAT_LOG_DEBUG;
|
|
|
|
|
|
|
|
|
|
+void luat_log_thread_task(void* args) {
|
|
|
|
|
+ log_msg_t msg = {0};
|
|
|
|
|
+ while (1) {
|
|
|
|
|
+ if (pdTRUE == xQueueReceive(xQueue, &msg, -1)) {
|
|
|
|
|
+ printf("%s", msg.buff);
|
|
|
|
|
+ luat_heap_free(msg.buff);
|
|
|
|
|
+ };
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+void luat_log_init_win32(void) {
|
|
|
|
|
+ xQueue = xQueueCreate(1024, sizeof(void*));
|
|
|
|
|
+ xTaskCreate( luat_log_thread_task, "log", 1024*2, NULL, 23, NULL );
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
void luat_log_set_uart_port(int port) {
|
|
void luat_log_set_uart_port(int port) {
|
|
|
luat_log_uart_port = port;
|
|
luat_log_uart_port = port;
|
|
|
}
|
|
}
|
|
@@ -19,11 +45,15 @@ void luat_print(const char* _str) {
|
|
|
|
|
|
|
|
void luat_nprint(char *s, size_t l) {
|
|
void luat_nprint(char *s, size_t l) {
|
|
|
//luat_uart_write(luat_log_uart_port, s, l);
|
|
//luat_uart_write(luat_log_uart_port, s, l);
|
|
|
- for (size_t i = 0; i < l; i++)
|
|
|
|
|
- {
|
|
|
|
|
- putc(*(s++), stdout);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
|
|
+ char* buff = luat_heap_malloc(l + 1);
|
|
|
|
|
+ if (buff == NULL)
|
|
|
|
|
+ return;
|
|
|
|
|
+ memcpy(buff, s, l);
|
|
|
|
|
+ buff[l] = 0x00;
|
|
|
|
|
+ log_msg_t msg = {
|
|
|
|
|
+ .buff = buff
|
|
|
|
|
+ };
|
|
|
|
|
+ xQueueSendFromISR(xQueue, &msg, NULL);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void luat_log_set_level(int level) {
|
|
void luat_log_set_level(int level) {
|
|
@@ -35,7 +65,7 @@ int luat_log_get_level() {
|
|
|
#define LOGLOG_SIZE 1024
|
|
#define LOGLOG_SIZE 1024
|
|
|
void luat_log_log(int level, const char* tag, const char* _fmt, ...) {
|
|
void luat_log_log(int level, const char* tag, const char* _fmt, ...) {
|
|
|
if (luat_log_level_cur > level) return;
|
|
if (luat_log_level_cur > level) return;
|
|
|
- char buff[LOGLOG_SIZE];
|
|
|
|
|
|
|
+ char buff[LOGLOG_SIZE] = {0};
|
|
|
char *tmp = (char *)buff;
|
|
char *tmp = (char *)buff;
|
|
|
switch (level)
|
|
switch (level)
|
|
|
{
|
|
{
|