Explorar o código

defulat printf from uart

Signed-off-by: huhui <huhui@sharkgulf.com>
huhui %!s(int64=4) %!d(string=hai) anos
pai
achega
89098307bf
Modificáronse 4 ficheiros con 15 adicións e 15 borrados
  1. 5 1
      Applications/bsp/bsp.c
  2. 6 0
      Applications/bsp/uart.c
  3. 2 14
      Applications/libs/logger.c
  4. 2 0
      Applications/libs/logger.h

+ 5 - 1
Applications/bsp/bsp.c

@@ -1,4 +1,6 @@
 #include "bsp/bsp.h"
+#include "libs/logger.h"
+#include "bsp/uart.h"
 #include "version.h"
 
 static void wdog_enable(void);
@@ -7,7 +9,9 @@ static void sys_tick_init(void);
 void bsp_init(void){
 	wdog_enable();
 	sys_tick_init();
-
+#if LOG_UART==1
+	shark_uart_init(SHARK_UART0);
+#endif
 }
 
 static void sys_tick_init(void){

+ 6 - 0
Applications/bsp/uart.c

@@ -470,3 +470,9 @@ void shark_uart_write_bytes(uart_enum_t uart_no, u8 *buff, u16 size){
 	shark_uart_write(_shark_uart + uart_no, buff, size);
 }
 
+#if LOG_UART==1
+int fputc(int c, FILE *fp){
+	shark_uart_write_byte(_shark_uart+SHARK_UART0, (u8)c);
+	return 1;
+}
+#endif

+ 2 - 14
Applications/libs/logger.c

@@ -18,15 +18,6 @@ void set_log_level(int mod, int l){
 	level_data[index] = (level_data[index] & (~(LEVEL_MASK<<mod))) | ((l & LEVEL_MASK)<<mod);
 }
 
-static int _lock(void){
-	return 0;
-}
-
-static int _unlock(void){
-	return 0;
-}
-
-
 static void log_out(char *fmt, va_list args){
 	vprintf(fmt, args);
 	if (fmt[strlen(fmt) - 1] != '\n'){
@@ -61,14 +52,11 @@ void log_error(int mod, char *fmt, ...){
 	}
 }
 //rewrite the fputc, so that the printf,vprintf can log the info the can
+#if LOG_UART==0
 static char log_buffer[8];
 static int log_index = 0;
 int fputc(int c, FILE *fp){
 	can_id_t frame_id;
-	if (_lock() == 1){
-		return 1;
-	}
-
 	frame_id.id=0;
 	frame_id.src 	= CAN_MY_ADDRESS;
 	frame_id.type 		= ptype_indicater;
@@ -87,7 +75,7 @@ int fputc(int c, FILE *fp){
 	}else{
 		log_buffer[log_index++] = c;
 	}
-	_unlock();
 	return 1;
 }
+#endif
 

+ 2 - 0
Applications/libs/logger.h

@@ -21,6 +21,8 @@
 #define MOD_BLE      3 //for ble
 #define MOD_SYSTEM    4
 
+#define LOG_UART 1
+
 extern void set_log_level(int mod, int l);
 extern void log_debug(int mod, char *fmt, ...);
 extern void log_warning(int mod, char *fmt, ...);