Просмотр исходного кода

support printf and add some log

Signed-off-by: FuangCao <cavan.cao@foxmail.com>
FuangCao 5 лет назад
Родитель
Сommit
ce8b3db00f
4 измененных файлов с 27 добавлено и 33 удалено
  1. 0 2
      Source/app_end_ctr.c
  2. 22 29
      Source/drv_can.c
  3. 4 1
      Source/drv_io.c
  4. 1 1
      Source/sw_build_info.h

+ 0 - 2
Source/app_end_ctr.c

@@ -934,5 +934,3 @@ void ACC12_OVER_Loader_Interrupt(void)
 	acc12_delay.count = 0;
 #endif		
 }
-
-

+ 22 - 29
Source/drv_can.c

@@ -292,7 +292,7 @@ void CAN_Config(void)
     can_parameter.auto_wake_up = DISABLE;
     can_parameter.auto_retrans = DISABLE;
     can_parameter.rec_fifo_overwrite = DISABLE;
-    can_parameter.trans_fifo_order = DISABLE;
+    can_parameter.trans_fifo_order = ENABLE;
     can_parameter.working_mode = CAN_NORMAL_MODE;
     can_parameter.resync_jump_width = CAN_BT_SJW_1TQ;
     can_parameter.time_segment_1 = CAN_BT_BS1_5TQ;
@@ -448,44 +448,37 @@ void USBD_LP_CAN0_RX0_IRQHandler(void)
 	
 }
 
+static can_trasnmit_message_struct shark_can_log_message;
 
-
-#if 1
+static void shark_can_log_flush(uint8_t dest)
+{
+	shark_can_log_message.tx_efid = 3 << 24 | 1 << 19 | 1 << 14 | SELF_ID << 7 | dest;
+	shark_can_log_message.tx_ff = CAN_FF_EXTENDED;
+	shark_can_log_message.tx_ft = CAN_FT_DATA;
+	can_message_transmit(CAN0, &shark_can_log_message);
+	shark_can_log_message.tx_dlen = 0;
+}
 
 // 
 //ÓÃÓÚϵͳµ÷ÓÃprintf
 //
-#ifdef __GNUC__
-  /* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf
-     set to 'Yes') calls __io_putchar() */
-#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
-#else
-#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
-#endif /* __GNUC__ */
-
-PUTCHAR_PROTOTYPE
+int fputc(int ch, FILE *f)
 {
-	if(work_normal)
-	{
-		can_trasnmit_message_struct can_tr_m;
-
-		memset(&can_tr_m,0x00,sizeof(can_tr_m));
-
-		can_tr_m.tx_efid = (SELF_ID << 7)|(PRINTF_TER_ID << 0);
-		can_tr_m.tx_ff = CAN_FF_EXTENDED;
-		can_tr_m.tx_ft = CAN_FT_DATA;
-		can_tr_m.tx_dlen = 1;
-		can_tr_m.tx_data[0] = (uint8_t)ch;
-
-		can_message_transmit(CAN0,&can_tr_m);
-
-		delay_1us(500);
+	if (ch == '\n') {
+		if (shark_can_log_message.tx_dlen > 0) {
+			shark_can_log_flush(0x72);
+		}
+	} else if (shark_can_log_message.tx_dlen < sizeof(shark_can_log_message.tx_data)) {
+		shark_can_log_message.tx_data[shark_can_log_message.tx_dlen] = ch;
+		shark_can_log_message.tx_dlen++;
+	} else {
+		shark_can_log_flush(0x70);
+		shark_can_log_message.tx_dlen = 1;
+		shark_can_log_message.tx_data[0] = ch;
 	}
 	
 	return ch;
 }
-
-#endif
 //********************************************************CAN-END**********************************************************
 
 

+ 4 - 1
Source/drv_io.c

@@ -68,6 +68,8 @@ void Check_S11(uint8_t on,uint8_t from)
 }
 void QD_Enable_From(uint8_t on,uint8_t from)
 {
+	printf("qd: %d %d\n", on, from);
+
 	Check_S11(on,FROM_QD);
 	QD_Enable(on);
 	QD_switch_from = from;
@@ -99,6 +101,8 @@ void ACC2_PWM(void)
 }
 void ACC2_Enable(uint8_t on)
 {
+	printf("acc2: %d\n", on);
+
 #if ACC2_USE_PWM
 	Check_S11(on,FROM_ACC12);
 	
@@ -517,4 +521,3 @@ void EXTI10_15_IRQHandler(void)
         exti_interrupt_flag_clear(EXTI_15);
     }
 }
-

+ 1 - 1
Source/sw_build_info.h

@@ -1,3 +1,3 @@
 #pragma once
 
-#define CONFIG_VERSION "PS100XX_V01_0C301517"
+#define CONFIG_VERSION "PS100XX_V01_0C301614"