فهرست منبع

remove shark_uart.c

Signed-off-by: huhui <huhui@sharkgulf.com>
huhui 5 سال پیش
والد
کامیت
58781a903e

+ 78 - 0
Application/bsp/shark_bkp.c

@@ -0,0 +1,78 @@
+#include "shark_bkp.h"
+
+static uint8_t g_bkp_first = 0;
+void shark_bkp_init(void){
+	if (POWER_FIRSTFLAG_VALUE != bkp_read_data(POWER_FIRSTFLAG_REG)){
+		/* enable PMU and BKPI clocks */
+		rcu_periph_clock_enable(RCU_BKPI);
+		rcu_periph_clock_enable(RCU_PMU);
+		/* allow access to BKP domain */
+		pmu_backup_write_enable();
+
+		/* reset backup domain */
+		bkp_deinit();
+		rcu_osci_on(RCU_IRC40K);
+		rcu_osci_stab_wait(RCU_IRC40K);
+		bkp_write_data(POWER_FIRSTFLAG_REG, POWER_FIRSTFLAG_VALUE);
+		g_bkp_first = 1;
+	}else{
+        /* allow access to BKP domain */
+		rcu_periph_clock_enable(RCU_BKPI);
+        rcu_periph_clock_enable(RCU_PMU);
+        pmu_backup_write_enable();
+		g_bkp_first = 0;
+	}
+}
+
+bool shark_bkp_first_startup(void){
+
+	if(g_bkp_first == 1)
+		return TRUE;
+	else
+		return FALSE;
+}
+
+bool shark_bkp_btrace_valid(void){
+	if( bkp_read_data(BACK_TRACE_MAIGC_REG) == BACK_TRACE_MAIGC_VALUE)
+		return TRUE;
+	else
+		return FALSE;
+}
+
+void shark_bkp_save_backtrace(uint32_t *backtrace, uint32_t stack_over, uint32_t stack_dep, uint16_t line){
+	uint16_t value = ((stack_over << 8) & 0xFF00) | (stack_dep & 0x00FF);
+	uint32_t index;
+	bkp_data_register_enum trace_reg = BACK_TRACE_CALLTRACE_START_REG;
+	
+	bkp_write_data(BACK_TRACE_MAIGC_REG, BACK_TRACE_MAIGC_VALUE);
+	bkp_write_data(BACK_TRACE_INFO_REG, value);
+
+	for (index = 0; index < stack_dep; index ++){
+		uint32_t value = (backtrace[index] >> 16) & 0xFFFF;
+		bkp_write_data(trace_reg, (uint16_t)value);
+		trace_reg ++;
+		value = backtrace[index] & 0xFFFF;
+		bkp_write_data(trace_reg, (uint16_t)value);
+		trace_reg ++;
+	}
+	bkp_write_data(BACK_TRACE_LINE_REG, line);
+}
+
+
+void shark_bkp_get_backtrace(uint32_t *backtrace, uint32_t *stack_over, uint32_t *stack_dep, uint16_t *line){
+	uint16_t value = bkp_read_data(BACK_TRACE_INFO_REG);
+	uint32_t index;
+	*stack_over = (value >> 8) & 0xFF;
+	*stack_dep = value & 0xFF;
+	*stack_dep = *stack_dep > 16 ? 16 : *stack_dep;
+	bkp_data_register_enum trace_reg = BACK_TRACE_CALLTRACE_START_REG;
+	for (index = 0; index < *stack_dep; index++){
+		uint32_t t_h = bkp_read_data(trace_reg);
+		trace_reg ++;
+		uint32_t t_l = bkp_read_data(trace_reg);
+		trace_reg ++;
+		backtrace[index] = (t_h << 16 & 0xFFFF0000) | (t_l & 0xFFFF);
+	}
+	*line = bkp_read_data(BACK_TRACE_LINE_REG);
+}
+

+ 33 - 0
Application/bsp/shark_bkp.h

@@ -0,0 +1,33 @@
+#ifndef _Shark_BKP_H__
+#define _Shark_BKP_H__
+#include <stdio.h>
+
+#if defined (GD32F30X_HD) || defined (GD32F30X_XD) || defined (GD32F30X_CL)
+#include "gd32f30x.h"
+#elif defined GD32E10x
+#include "gd32e10x.h"
+#include <stdbool.h>
+#define bkp_write_data bkp_data_write
+#define bkp_read_data bkp_data_read
+#endif
+
+
+#define POWER_FIRSTFLAG_REG BKP_DATA_0
+#define POWER_FIRSTFLAG_VALUE 0x5AA5
+
+#define BACK_TRACE_MAIGC_REG BKP_DATA_1
+#define BACK_TRACE_MAIGC_VALUE 0x55AA
+
+#define BACK_TRACE_INFO_REG BKP_DATA_2
+
+#define BACK_TRACE_CALLTRACE_START_REG BKP_DATA_3
+
+#define BACK_TRACE_LINE_REG ((bkp_data_register_enum)(BACK_TRACE_CALLTRACE_START_REG + 16))
+
+void shark_bkp_init(void);
+bool shark_bkp_first_startup(void);
+bool shark_bkp_btrace_valid(void);
+void shark_bkp_save_backtrace(uint32_t *backtrace, uint32_t stack_over, uint32_t stack_dep, uint16_t line);
+void shark_bkp_get_backtrace(uint32_t *backtrace, uint32_t *stack_over, uint32_t *stack_dep, uint16_t *line);
+#endif /* _Shark_BKP_H__ */
+

+ 283 - 0
Application/bsp/shark_rtc.c

@@ -0,0 +1,283 @@
+#include <stdio.h>
+#include <time.h>
+#include <string.h>
+
+//#include "gd32e10x.h"
+//#include "gd32e103v_eval.h"
+#include "Gd32f30x_rtc.h"
+#include "Gd32f30x_bkp.h"
+#include "qws_status.h"
+
+#include "shark_rtc.h"
+#include "FreeRTOS.h"
+#include "task.h"
+#include "shark_bkp.h"
+#define IS_LEAP_YEAR(year)      ((year % 4 == 0) && ( year % 100 != 0) || (year % 400 == 0))
+
+static uint32_t time_ticks = 0;
+#define POWER_FIRSTFLAG_REG BKP_DATA_0
+#define POWER_FIRSTFLAG_VALUE 0x5AA5
+
+unsigned char check_rtc_time()
+{
+	int rtcTime = rtc_counter_get();
+
+	if(rtcTime > YEAR_20171201_UTS  && rtcTime < YEAR_20571201_UTS)
+		return 1;
+	
+	start_uptade_local_time();
+	return 0;
+}
+
+uint32_t app_getcurrtime_utc(void)
+{		
+	if(check_rtc_time() == 1)
+		return shark_rtc_get_timestamp();
+	else
+		return 0;
+}
+
+/* get the utc readable time */
+void shark_rtc_get_local_time(uint32_t second, time_val *out){
+	struct tm *tm;
+	tm = localtime((time_t *)&second);
+
+	out->year = tm->tm_year + 1900;
+	out->month = tm->tm_mon + 1;
+	out->day = tm->tm_mday;
+	out->hour = tm->tm_hour;
+	out->minute = tm->tm_min;
+	out->second = tm->tm_sec;
+}
+
+/* get utc timestamp --> second */
+uint32_t shark_rtc_get_timestamp(void){
+	return rtc_counter_get();
+}
+
+/*tz quarter-hour ,15min ,-48~+48*/
+uint32_t shark_rtc_get_timestamp_with_time_zone(int8_t tz){
+	return (rtc_counter_get()+ tz*15*60);
+	
+}
+
+void shark_rtc_getcurrtime_loca_time(time_val*ltc)
+{	
+	if(ltc==NULL) return;
+	shark_rtc_get_local_time(shark_rtc_get_timestamp_with_time_zone(qws_status_get()->bike.qws_TZ ),ltc);
+
+}
+
+
+
+/* get utc timestamp --> macro second */
+uint64_t shark_rtc_get_timestamp_ms(void){
+	return (uint64_t)rtc_counter_get() * 1000 + ((xTaskGetTickCount() - time_ticks) / portTICK_RATE_MS)%(1000/portTICK_RATE_MS);
+}
+
+/* set rtc time, used utc timestamp, can not include time zone*/
+uint32_t calendar_to_utc(time_val *time){
+
+	struct tm utc_time;
+	struct tm my_time;
+	memset(&utc_time, 0, sizeof (struct tm));
+	memset(&my_time, 0, sizeof (struct tm));
+	
+	my_time.tm_mday = time->day;
+	my_time.tm_mon = time->month- 1;
+	my_time.tm_year = time->year - 1900;
+	my_time.tm_hour = time->hour;
+	my_time.tm_min = time->minute;
+	my_time.tm_sec = time->second;
+
+	utc_time.tm_mday = 1;
+	utc_time.tm_mon = 1 - 1;
+	utc_time.tm_year = 1970 - 1900;
+	utc_time.tm_hour = 0;
+	utc_time.tm_min = 0;
+	utc_time.tm_sec = 0;
+
+	return mktime(&my_time) - mktime(&utc_time);
+}
+
+
+void shark_rtc_set_time(time_val *time){
+	uint32_t second = calendar_to_utc(time);
+    /* wait until last write operation on RTC registers has finished */
+    rtc_lwoff_wait();
+    /* change the current time */
+    rtc_counter_set(second);
+    rtc_lwoff_wait();
+}
+
+void shark_rtc_set_time_with_utc_second(uint32_t utc_s){
+    /* wait until last write operation on RTC registers has finished */
+    rtc_lwoff_wait();
+    /* change the current time */
+    rtc_counter_set(utc_s);
+    rtc_lwoff_wait();
+}
+
+static void shark_rtc_first_init(void){
+	//keep rtc running and inited while chip reset
+	if (shark_bkp_first_startup()){
+
+		
+		/* enable PMU and BKPI clocks */
+		rcu_periph_clock_enable(RCU_BKPI);
+		rcu_periph_clock_enable(RCU_PMU);
+		/* allow access to BKP domain */
+		pmu_backup_write_enable();
+
+		/* reset backup domain */
+		bkp_deinit();
+		rcu_osci_on(RCU_IRC40K);
+		rcu_osci_stab_wait(RCU_IRC40K);
+
+		/* select RCU_RTCSRC_IRC40K as RTC clock source */
+		rcu_rtc_clock_config(RCU_RTCSRC_IRC40K);
+
+		/* enable RTC Clock */
+		rcu_periph_clock_enable(RCU_RTC);
+
+		/* wait for RTC registers synchronization */
+		rtc_register_sync_wait();
+
+		/* wait until last write operation on RTC registers has finished */
+		rtc_lwoff_wait();
+
+		rtc_interrupt_enable(RTC_INT_SECOND);
+		/* wait until last write operation on RTC registers has finished */
+		rtc_lwoff_wait();
+
+		//set 1s a tick
+		rtc_prescaler_set(40000-1);
+
+		/* wait until last write operation on RTC registers has finished */
+		rtc_lwoff_wait();
+
+		bkp_write_data(POWER_FIRSTFLAG_REG, POWER_FIRSTFLAG_VALUE);
+
+	}else{
+        /* allow access to BKP domain */
+        rcu_periph_clock_enable(RCU_PMU);
+        pmu_backup_write_enable();
+
+        rcu_osci_on(RCU_IRC40K);
+        rcu_osci_stab_wait(RCU_IRC40K);
+        
+        /* select RCU_RTCSRC_IRC40K as RTC clock source */
+        rcu_rtc_clock_config(RCU_RTCSRC_IRC40K);
+        
+        /* enable RTC Clock */
+        rcu_periph_clock_enable(RCU_RTC);
+		
+        /* wait for RTC registers synchronization */
+        rtc_register_sync_wait();
+        rtc_lwoff_wait();
+        /* enable the RTC second and alarm interrupt*/
+        rtc_interrupt_enable(RTC_INT_SECOND);
+		rtc_lwoff_wait();
+	}
+}
+
+static void shark_rtc_enable_second_irq(int enable){
+	if (enable){
+		nvic_irq_enable(RTC_IRQn, 2U, 0U);
+	}else{
+		nvic_irq_disable(RTC_IRQn);
+	}
+}
+
+void shark_rtc_init(void){
+	shark_rtc_first_init();
+	nvic_irq_enable(RTC_Alarm_IRQn , 2U, 0U);
+	exti_init(EXTI_17, EXTI_INTERRUPT, EXTI_TRIG_RISING);
+
+	exti_flag_clear(EXTI_17);
+	exti_interrupt_enable(EXTI_17);
+
+	shark_rtc_enable_second_irq(1);
+}
+
+
+int rtc_lwoff_wait_timeout(void)
+{
+	int wait_count = 0xffff;
+    /* loop until LWOFF flag is set */
+    while(RESET == (RTC_CTL & RTC_CTL_LWOFF)){
+		if (wait_count -- <= 0){
+			return -1;
+		}
+    }
+	return 0;
+}
+
+
+static int set_rtc_alarm(uint32_t sencod){
+	uint32_t current_count=0;
+	current_count = rtc_counter_get();
+	//rtc_lwoff_wait();	
+	rtc_alarm_config(current_count + sencod);
+	return rtc_lwoff_wait_timeout();
+}
+
+int shark_rtc_start_alarm(uint32_t second){
+	rtc_lwoff_wait();
+	rtc_interrupt_enable(RTC_INT_ALARM);// second means a shot here
+	rtc_lwoff_wait();
+	rtc_flag_clear(RTC_INT_SECOND ); //RTC_INT_FLAG_SECOND
+	rtc_lwoff_wait();
+	rtc_interrupt_disable(RTC_INT_SECOND);
+	rtc_lwoff_wait();
+	return set_rtc_alarm(second);
+}
+
+
+void shark_rtc_stop_alarm(void){
+	rtc_lwoff_wait();
+	rtc_interrupt_disable(RTC_INT_ALARM);
+	rtc_lwoff_wait();
+	rtc_interrupt_enable(RTC_INT_SECOND);
+	rtc_lwoff_wait();
+}
+void shark_rtc_update_alarm(uint32_t sencod){
+	set_rtc_alarm(sencod);
+}
+
+uint32_t qws_rtc_irq_times = 0;
+static alarm_handler s_handler = NULL;
+
+void shark_rtc_set_alarm_handler(alarm_handler handler){
+	s_handler = handler;
+}
+void RTC_Alarm_IRQHandler(void)
+{
+    if (rtc_flag_get(RTC_INT_ALARM) != RESET)
+	{
+       /* clear the RTC second interrupt flag*/
+      	  rtc_flag_clear(RTC_INT_ALARM);
+		if (s_handler != NULL){
+			s_handler();
+		}
+		qws_rtc_irq_times++;
+    }
+
+    exti_interrupt_flag_clear(EXTI_17);
+}
+
+
+void RTC_IRQHandler(void){
+	if (rtc_flag_get(RTC_INT_OVERFLOW /*RTC_INT_FLAG_OVERFLOW*/) != RESET)
+	{
+		/* clear the RTC overflow interrupt flag*/
+		rtc_flag_clear(RTC_INT_OVERFLOW);
+	}
+
+	if (rtc_flag_get(RTC_INT_SECOND) != RESET)
+	{
+		time_ticks = xTaskGetTickCount();
+		/* clear the RTC second interrupt flag*/
+		rtc_flag_clear(RTC_INT_SECOND);
+	}
+}

+ 36 - 0
Application/bsp/shark_rtc.h

@@ -0,0 +1,36 @@
+
+
+#include <stdint.h>
+
+#ifndef _Shark_Rtc_h__
+#define _Shark_Rtc_h__
+
+typedef struct{
+	uint16_t year; 	/*YYYY*/
+	uint8_t month;
+	uint8_t day;
+	uint8_t hour;
+	uint8_t minute;
+	uint8_t second;
+}time_val;
+
+typedef void (*alarm_handler)(void);
+
+extern void shark_rtc_init(void);
+extern int shark_rtc_start_alarm(uint32_t sencod);
+extern void shark_update_alarm(uint32_t sencod);
+extern void shark_rtc_set_alarm_handler(alarm_handler handler);
+extern void shark_rtc_stop_alarm(void);
+extern void shark_rtc_set_time(time_val *time);
+extern uint32_t shark_rtc_get_timestamp(void);
+extern uint64_t shark_rtc_get_timestamp_ms(void);
+extern void shark_rtc_get_local_time(uint32_t second, time_val *out);
+extern uint32_t shark_rtc_get_timestamp_with_time_zone(int8_t tz);
+extern void shark_rtc_getcurrtime_loca_time(time_val*ltc);
+extern void shark_rtc_set_time_with_utc_second(uint32_t utc_s);
+extern uint32_t app_getcurrtime_utc(void);
+uint32_t calendar_to_utc(time_val *time);
+unsigned char check_rtc_time(void);
+extern void start_uptade_local_time(void);
+
+#endif /* _Shark_Rtc_h__ */

+ 0 - 977
Application/bsp/shark_uart.c

@@ -1,977 +0,0 @@
-#include "s600_turn_key.h"
-#include "ws2818_spi.h"
-#include "s600_uart.h"
-#include "s600_can.h"
-#include "s600_pwm.h"
-#include "s600_adc.h"
-#include "s600_dac.h"
-#include "string.h"
-#include "stdlib.h"
-
-#define S600_UART0_com					USART0
-#if CONFIG_UART_MAIN == 0
-#define S600_UART0_baudrate				500000
-#else
-#define S600_UART0_baudrate				115200
-#endif
-#define S600_UART0_tx_port				GPIOA
-#define S600_UART0_tx_pin				GPIO_PIN_9
-#define S600_UART0_rx_port				GPIOA
-#define S600_UART0_rx_pin				GPIO_PIN_10
-#define S600_UART0_irq					USART0_IRQn
-#define S600_UART0_clk					RCU_USART0
-#define S600_UART0_tx_gpio_clk			RCU_GPIOA
-#define S600_UART0_rx_gpio_clk			RCU_GPIOA
-#define S600_UART0_tx_dma				DMA0
-#define S600_UART0_tx_dma_ch			DMA_CH3
-#define S600_UART0_tx_dma_clk			RCU_DMA0
-#define S600_UART0_rx_dma				DMA0
-#define S600_UART0_rx_dma_ch			DMA_CH4
-#define S600_UART0_rx_dma_clk			RCU_DMA0
-#define S600_UART0_on_data_received		s600_uart0_received
-
-#define S600_UART1_com					USART1
-#if CONFIG_UART_MAIN == 1
-#define S600_UART1_baudrate				500000
-#else
-#define S600_UART1_baudrate				115200
-#endif
-#define S600_UART1_tx_port				GPIOA
-#define S600_UART1_tx_pin				GPIO_PIN_2
-#define S600_UART1_rx_port				GPIOA
-#define S600_UART1_rx_pin				GPIO_PIN_3
-#define S600_UART1_irq					USART1_IRQn
-#define S600_UART1_clk					RCU_USART1
-#define S600_UART1_tx_gpio_clk			RCU_GPIOA
-#define S600_UART1_rx_gpio_clk			RCU_GPIOA
-#define S600_UART1_tx_dma				DMA0
-#define S600_UART1_tx_dma_ch			DMA_CH6
-#define S600_UART1_tx_dma_clk			RCU_DMA0
-#define S600_UART1_rx_dma				DMA0
-#define S600_UART1_rx_dma_ch			DMA_CH5
-#define S600_UART1_rx_dma_clk			RCU_DMA0
-#define S600_UART1_on_data_received		s600_uart1_received
-
-#define S600_UART2_com					USART2
-#define S600_UART2_baudrate				115200
-#define S600_UART2_tx_port				GPIOB
-#define S600_UART2_tx_pin				GPIO_PIN_10
-#define S600_UART2_rx_port				GPIOB
-#define S600_UART2_rx_pin				GPIO_PIN_11
-#define S600_UART2_irq					USART2_IRQn
-#define S600_UART2_clk					RCU_USART2
-#define S600_UART2_tx_gpio_clk			RCU_GPIOB
-#define S600_UART2_rx_gpio_clk			RCU_GPIOB
-#define S600_UART2_tx_dma				DMA0
-#define S600_UART2_tx_dma_ch			DMA_CH1
-#define S600_UART2_tx_dma_clk			RCU_DMA0
-#define S600_UART2_rx_dma				DMA0
-#define S600_UART2_rx_dma_ch			DMA_CH2
-#define S600_UART2_rx_dma_clk			RCU_DMA0
-#define S600_UART2_on_data_received		s600_uart2_received
-
-#define S600_UART3_com					UART3
-#define S600_UART3_baudrate				115200
-#define S600_UART3_tx_port				GPIOC
-#define S600_UART3_tx_pin				GPIO_PIN_10
-#define S600_UART3_rx_port				GPIOC
-#define S600_UART3_rx_pin				GPIO_PIN_11
-#define S600_UART3_irq					UART3_IRQn
-#define S600_UART3_clk					RCU_UART3
-#define S600_UART3_tx_gpio_clk			RCU_GPIOC
-#define S600_UART3_rx_gpio_clk			RCU_GPIOC
-#define S600_UART3_tx_dma				DMA1
-#define S600_UART3_tx_dma_ch			DMA_CH4
-#define S600_UART3_tx_dma_clk			RCU_DMA1
-#define S600_UART3_rx_dma				DMA1
-#define S600_UART3_rx_dma_ch			DMA_CH2
-#define S600_UART3_rx_dma_clk			RCU_DMA1
-#define S600_UART3_on_data_received		s600_uart3_received
-
-#define S600_UART4_com					UART4
-#define S600_UART4_baudrate				38400
-#define S600_UART4_tx_port				GPIOC
-#define S600_UART4_tx_pin				GPIO_PIN_12
-#define S600_UART4_rx_port				GPIOD
-#define S600_UART4_rx_pin				GPIO_PIN_2
-#define S600_UART4_irq					UART4_IRQn
-#define S600_UART4_clk					RCU_UART4
-#define S600_UART4_tx_gpio_clk			RCU_GPIOC
-#define S600_UART4_rx_gpio_clk			RCU_GPIOD
-#define S600_UART4_on_data_received		s600_uart4_received
-
-// ================================================================================
-
-#define S600_UART_CACHE_SIZE \
-	((S600_UART_TX_MEM_SIZE + S600_UART_RX_MEM_SIZE) * (S600_UART_COUNT - 1) + S600_UART_MAIN_TX_MEM_SIZE + S600_UART_MAIN_RX_MEM_SIZE)
-
-#define S600_UART_DMA_ADDR(index) \
-	(S600_UART##index##_com + 0x04)
-
-#define S600_UART_DMA_CHCTL_TX(uart) \
-	DMA_CHCTL(uart->tx_dma, uart->tx_dma_ch)
-
-#define S600_UART_DMA_CHCNT_TX(uart) \
-	DMA_CHCNT(uart->tx_dma, uart->tx_dma_ch)
-
-#define S600_UART_DMA_CHMADDR_TX(uart) \
-	DMA_CHMADDR(uart->tx_dma, uart->tx_dma_ch)
-
-#define S600_UART_DMA_CHCTL_RX(uart) \
-	DMA_CHCTL(uart->rx_dma, uart->rx_dma_ch)
-
-#define S600_UART_DMA_CHCNT_RX(uart) \
-	DMA_CHCNT(uart->rx_dma, uart->rx_dma_ch)
-
-#define S600_UART_DMA_CHMADDR_RX(uart) \
-	DMA_CHMADDR(uart->rx_dma, uart->rx_dma_ch)
-
-#define S600_UART_DEVICE_INIT(index) \
-	do { \
-		s600_uarts[index].com = S600_UART##index##_com; \
-		s600_uarts[index].on_data_received = S600_UART##index##_on_data_received; \
-		byte_queue_init(&s600_uarts[index].tx_queue, s600_uarts[index].tx_cache, s600_uarts[index].tx_cache_size); \
-		byte_queue_init(&s600_uarts[index].rx_queue, s600_uarts[index].rx_cache, s600_uarts[index].rx_cache_size); \
-		rcu_periph_clock_enable(S600_UART##index##_clk); \
-		rcu_periph_clock_enable(S600_UART##index##_rx_gpio_clk); \
-		rcu_periph_clock_enable(S600_UART##index##_tx_gpio_clk); \
-		gpio_init(S600_UART##index##_tx_port, GPIO_MODE_AF_PP, GPIO_OSPEED_50MHZ, S600_UART##index##_tx_pin); \
-		gpio_init(S600_UART##index##_rx_port, GPIO_MODE_IPU, GPIO_OSPEED_50MHZ, S600_UART##index##_rx_pin); \
-		usart_deinit(S600_UART##index##_com); \
-		usart_baudrate_set(S600_UART##index##_com, S600_UART##index##_baudrate); \
-		usart_word_length_set(S600_UART##index##_com, USART_WL_8BIT); \
-		usart_stop_bit_set(S600_UART##index##_com, USART_STB_1BIT); \
-		usart_parity_config(S600_UART##index##_com, USART_PM_NONE); \
-		usart_hardware_flow_rts_config(S600_UART##index##_com, USART_RTS_DISABLE); \
-		usart_hardware_flow_cts_config(S600_UART##index##_com, USART_CTS_DISABLE); \
-		usart_receive_config(S600_UART##index##_com, USART_RECEIVE_ENABLE); \
-		usart_transmit_config(S600_UART##index##_com, USART_TRANSMIT_ENABLE); \
-	} while (0)
-
-#define S600_UART_TX_IRQ_INIT(index) \
-	do { \
-		s600_uarts[index].tx_poll = s600_uart_irq_tx; \
-		nvic_irq_enable(S600_UART##index##_irq, 0, 0); \
-	} while (0)
-
-#define S600_UART_RX_IRQ_INIT(index) \
-	do { \
-		s600_uarts[index].rx_poll = s600_uart_irq_rx; \
-		usart_interrupt_enable(S600_UART##index##_com, USART_INT_RBNE); \
-		nvic_irq_enable(S600_UART##index##_irq, 0, 0); \
-	} while (0)
-
-#if S600_UART_USE_DMA
-#define S600_UART_TX_DMA_INIT(index) \
-	do { \
-		dma_parameter_struct dma_init_struct; \
-		s600_uarts[index].tx_poll = s600_uart_dma_tx; \
-		s600_uarts[index].tx_dma = S600_UART##index##_tx_dma; \
-		s600_uarts[index].tx_dma_ch = S600_UART##index##_tx_dma_ch; \
-		rcu_periph_clock_enable(S600_UART##index##_tx_dma_clk); \
-		dma_deinit(S600_UART##index##_tx_dma, S600_UART##index##_tx_dma_ch); \
-		dma_init_struct.direction = DMA_MEMORY_TO_PERIPHERAL; \
-		dma_init_struct.memory_addr = (u32) s600_uarts[index].tx_cache; \
-		dma_init_struct.memory_inc = DMA_MEMORY_INCREASE_ENABLE; \
-		dma_init_struct.memory_width = DMA_MEMORY_WIDTH_8BIT; \
-		dma_init_struct.number = 0; \
-		dma_init_struct.periph_addr = S600_UART_DMA_ADDR(index); \
-		dma_init_struct.periph_inc = DMA_PERIPH_INCREASE_DISABLE; \
-		dma_init_struct.periph_width = DMA_PERIPHERAL_WIDTH_8BIT; \
-		dma_init_struct.priority = DMA_PRIORITY_ULTRA_HIGH; \
-		dma_init(S600_UART##index##_tx_dma, S600_UART##index##_tx_dma_ch, &dma_init_struct); \
-		dma_circulation_disable(S600_UART##index##_tx_dma, S600_UART##index##_tx_dma_ch); \
-		usart_dma_transmit_config(S600_UART##index##_com, USART_DENT_ENABLE); \
-	} while (0)
-
-#define S600_UART_RX_DMA_INIT(index) \
-	do { \
-		dma_parameter_struct dma_init_struct; \
-		s600_uarts[index].rx_poll = s600_uart_dma_rx; \
-		s600_uarts[index].rx_dma = S600_UART##index##_rx_dma; \
-		s600_uarts[index].rx_dma_ch = S600_UART##index##_rx_dma_ch; \
-		rcu_periph_clock_enable(S600_UART##index##_rx_dma_clk); \
-		dma_deinit(S600_UART##index##_rx_dma, S600_UART##index##_rx_dma_ch); \
-		dma_init_struct.direction = DMA_PERIPHERAL_TO_MEMORY; \
-		dma_init_struct.memory_addr = (u32) s600_uarts[index].rx_cache; \
-		dma_init_struct.memory_inc = DMA_MEMORY_INCREASE_ENABLE; \
-		dma_init_struct.memory_width = DMA_MEMORY_WIDTH_8BIT; \
-		dma_init_struct.number = s600_uarts[index].rx_cache_size; \
-		dma_init_struct.periph_addr = S600_UART_DMA_ADDR(index); \
-		dma_init_struct.periph_inc = DMA_PERIPH_INCREASE_DISABLE; \
-		dma_init_struct.periph_width = DMA_PERIPHERAL_WIDTH_8BIT; \
-		dma_init_struct.priority = DMA_PRIORITY_ULTRA_HIGH; \
-		dma_init(S600_UART##index##_rx_dma, S600_UART##index##_rx_dma_ch, &dma_init_struct); \
-		dma_circulation_enable(S600_UART##index##_rx_dma, S600_UART##index##_rx_dma_ch); \
-		dma_channel_enable(S600_UART##index##_rx_dma, S600_UART##index##_rx_dma_ch); \
-		usart_dma_receive_config(S600_UART##index##_com, USART_DENR_ENABLE); \
-	} while (0)
-#else
-#define S600_UART_TX_DMA_INIT(index) \
-	S600_UART_TX_IRQ_INIT(index)
-
-#define S600_UART_RX_DMA_INIT(index) \
-	S600_UART_RX_IRQ_INIT(index)
-#endif
-
-#define S600_UART_INIT_DMA(index) \
-	do { \
-		S600_UART_DEVICE_INIT(index); \
-		S600_UART_TX_DMA_INIT(index); \
-		S600_UART_RX_DMA_INIT(index); \
-	} while (0)
-
-	
-#define S600_UART_INIT_IRQ(index) \
-	do { \
-		S600_UART_DEVICE_INIT(index); \
-		S600_UART_TX_IRQ_INIT(index); \
-		S600_UART_RX_IRQ_INIT(index); \
-	} while (0)
-
-// ================================================================================
-
-static u16 s600_print_pos;
-static u8 s600_print_buff[S600_UART_FRAME_SIZE];
-
-static u16 s600_uart_index;
-static bool s600_uart_valid;
-static bool s600_uart_escape;
-static u8 s600_uart_frame[S600_UART_FRAME_SIZE];
-
-static u8 s600_uart_cache[S600_UART_CACHE_SIZE];
-
-s600_uart_device_t s600_uarts[S600_UART_COUNT];
-s600_uart_device_t *s600_uart_passthrough;
-
-// ================================================================================
-
-void s600_uart_dma_tx(s600_uart_device_t *uart)
-{
-	u32 value = S600_UART_DMA_CHCTL_TX(uart);
-
-    if (value & DMA_CHXCTL_CHEN) {
-		if (SET != dma_flag_get(uart->tx_dma, uart->tx_dma_ch, DMA_FLAG_FTF)) {
-			return;
-		}
-
-		byte_queue_skip(&uart->tx_queue, uart->tx_length);
-		S600_UART_DMA_CHCTL_TX(uart) = value & (~DMA_CHXCTL_CHEN);
-	}
-
-	uart->tx_length = byte_queue_peek(&uart->tx_queue);
-	if (uart->tx_length > 0) {
-		S600_UART_DMA_CHCNT_TX(uart) = uart->tx_length;
-		S600_UART_DMA_CHMADDR_TX(uart) = (u32) byte_queue_head(&uart->tx_queue);
-
-		dma_flag_clear(uart->tx_dma, uart->tx_dma_ch, DMA_FLAG_FTF);
-		S600_UART_DMA_CHCTL_TX(uart) = value | DMA_CHXCTL_CHEN;
-	}
-}
-
-void s600_uart_cache_data(s600_uart_device_t *uart, u8 *buff, u16 length)
-{
-#if S600_UART_USE_CACHE
-	while (length > 0) {
-		u8 remain = sizeof(uart->cache) - uart->cache_len;
-
-		uart->cache_times = S600_UART_CACHE_TIMES;
-
-		if (length < remain) {
-			memcpy(uart->cache + uart->cache_len, buff, length);
-			uart->cache_len += length;
-			break;
-		}
-
-		memcpy(uart->cache + uart->cache_len, buff, remain);
-		uart->on_data_received(uart->cache, sizeof(uart->cache));
-		uart->cache_len = 0;
-
-		length -= remain;
-		buff += remain;
-	}
-#else
-	if (length > 0) {
-		uart->on_data_received(buff, length);
-	}
-#endif
-}
-
-void s600_uart_dma_rx(s600_uart_device_t *uart)
-{
-	u16 index = uart->rx_index;
-
-	uart->rx_index = uart->rx_cache_size - S600_UART_DMA_CHCNT_RX(uart);
-
-	if (uart->rx_index < index) {
-		uart->do_cache_data(uart, uart->rx_cache + index, uart->rx_cache_size - index);
-		uart->do_cache_data(uart, uart->rx_cache, uart->rx_index);
-	} else {
-		uart->do_cache_data(uart, uart->rx_cache + index, uart->rx_index - index);
-	}
-}
-
-void s600_uart_irq_tx(s600_uart_device_t *uart)
-{
-}
-
-void s600_uart_irq_rx(s600_uart_device_t *uart)
-{
-	u8 buff[128];
-	u8 length;
-
-	length = s600_uart_read(uart, buff, sizeof(buff));
-	uart->do_cache_data(uart, buff, length);
-}
-
-void s600_uart_rx(s600_uart_device_t *uart)
-{
-	u32 com = uart->com;
-
-	while (usart_flag_get(com, USART_FLAG_RBNE) == SET) {
-		u8 value = usart_data_receive(com);
-		byte_queue_write(&uart->rx_queue, &value, 1);
-	}
-}
-
-void s600_uart_device_tx(s600_uart_device_t *uart)
-{
-	u32 com = uart->com;
-
-	if (usart_flag_get(com, USART_FLAG_TBE) == SET) {
-		u8 value;
-
-		if (byte_queue_read(&uart->tx_queue, &value, 1) > 0) {
-			usart_data_transmit(com, value);
-		} else {
-			usart_interrupt_disable(com, USART_INT_TBE);
-		}
-	}
-}
-
-void s600_uart_write(s600_uart_device_t *uart, const u8 *buff, u16 size)
-{
-	while (size > 0) {
-		u16 length = byte_queue_write(&uart->tx_queue, buff, size);
-
-		if (uart->tx_dma == 0) {
-			usart_interrupt_enable(uart->com, USART_INT_TBE);
-		}
-
-		if (length == size) {
-			break;
-		}
-
-		if (uart->tx_dma != 0) {
-			s600_uart_dma_tx(uart);
-		}
-
-		buff += length;
-		size -= length;
-	}
-}
-
-u16 s600_uart_read(s600_uart_device_t *uart, u8 *buff, u16 size)
-{
-	return byte_queue_read(&uart->rx_queue, buff, size);
-}
-
-void s600_uart_write_byte(s600_uart_device_t *uart, u8 value)
-{
-	s600_uart_write(uart, &value, 1);
-}
-
-u16 s600_uart_write_available(s600_uart_device_t *uart)
-{
-	return byte_queue_get_free(&uart->tx_queue);
-}
-
-bool s600_uart_write_full(s600_uart_device_t *uart, const u8 *buff, u16 size)
-{
-	if (s600_uart_write_available(uart) < size) {
-		return false;
-	}
-
-	s600_uart_write(uart, buff, size);
-
-	return true;
-}
-
-void s600_uart_write_byte_esc(s600_uart_device_t *uart, u8 value)
-{
-	switch (value) {
-	case CH_START:
-		s600_uart_write_byte(uart, CH_ESC);
-		value = CH_ESC_START;
-		break;
-
-	case CH_END:
-		s600_uart_write_byte(uart, CH_ESC);
-		value = CH_ESC_END;
-		break;
-
-	case CH_ESC:
-		s600_uart_write_byte(uart, CH_ESC);
-		value = CH_ESC_ESC;
-		break;
-	}
-
-	s600_uart_write_byte(uart, value);
-}
-
-void s600_uart_message_init(s600_uart_message_t *msg, const void *buff, u16 size)
-{
-	msg->buff = (u8 *) buff;
-	msg->size = size;
-}
-
-void s600_uart_write_messages(s600_uart_device_t *uart, const s600_uart_message_t *msgs, u8 count)
-{
-	const s600_uart_message_t *msg_end;
-	u16 crc = 0;
-
-#ifdef CONFIG_BOARD_M6_JIG
-	s600_uart_write_byte(uart, 0xAA);
-#endif
-
-	s600_uart_write_byte(uart, CH_START);
-
-	for (msg_end = msgs + count; msgs < msg_end; msgs++) {
-		const u8 *buff = msgs->buff;
-		const u8 *buff_end = buff + msgs->size;
-
-		while (buff < buff_end) {
-			u8 value = *buff++;
-			s600_uart_write_byte_esc(uart, value);
-			crc = s600_crc_put_byte(crc, value);
-		}
-	}
-
-	s600_uart_write_byte_esc(uart, crc);
-	s600_uart_write_byte_esc(uart, crc >> 8);
-
-	s600_uart_write_byte(uart, CH_END);
-}
-
-// ================================================================================
-
-static void s600_uart_process_cmd_can(u8 *buff, u16 length)
-{
-	s600_can_efid_t efid;
-
-	if (length < 5) {
-		return;
-	}
-
-	efid.value = s600_decode_u32(buff);
-
-	if (efid.dest == 0x00 && efid.src == 0x45) {
-		s600_can_process_frame(efid, buff + 4, length - 4);
-	} else {
-		u8 mailbox = s600_can_wait_mailbox();
-		if (mailbox != CAN_NOMAILBOX) {
-			s600_can_send_frame(mailbox, efid.value, buff + 4, length - 4);
-		}
-	}
-}
-
-static int s600_uart_process_cmd_version(u8 *buff, u16 length)
-{
-	length = sizeof(CONFIG_BOARD_NAME) - 1;
-	memcpy(buff, CONFIG_BOARD_NAME, length);
-	return length;
-}
-
-static int s600_uart_process_command(u16 command, u8 *buff, u16 length)
-{
-	return -1;
-}
-
-static s600_uart_device_t *s600_uart_get_device(int uart)
-{
-	if (uart < NELEM(s600_uarts)) {
-		return s600_uarts + uart;
-	}
-
-	return NULL;
-}
-
-static void s600_uart_passthrough_master(u8 *buff, u16 size)
-{
-	s600_uart_write(s600_uart_passthrough, buff, size);
-}
-
-static void s600_uart_passthrough_slave(u8 *buff, u16 size)
-{
-	s600_uart_write(s600_uart_get_main(), buff, size);
-}
-
-static int s600_uart_process_uart_config(u8 *buff, u16 length)
-{
-	s600_uart_device_t *uart;
-
-	if (length < 2) {
-		return -1;
-	}
-
-	uart = s600_uart_get_device(buff[0]);
-	if (uart == NULL) {
-		return -1;
-	}
-
-	if (length > 5) {
-		u32 baudrate = s600_decode_u32(buff + 2);
-		usart_baudrate_set(uart->com, baudrate);
-	}
-
-	if (buff[1]) {
-		usart_enable(uart->com);
-
-		if ((buff[1] & 0x02) != 0) {
-			s600_uart_passthrough = uart;
-			uart->on_data_received = s600_uart_passthrough_slave;
-			s600_uart_get_main()->on_data_received = s600_uart_passthrough_master;
-		}
-	} else {
-		usart_disable(uart->com);
-	}
-
-	return 0;
-}
-
-static u32 s600_uart_gpio_decode_port(u8 value)
-{
-	u8 index = value >> 5;
-	rcu_periph_clock_enable(s600_gpio_rcu_map[index]);
-	return s600_gpio_map[index];
-}
-
-static u32 s600_uart_gpio_decode_pin(u8 value)
-{
-	return 1 << (value & 0x1F);
-}
-
-static u32 s600_uart_exti_decode_port(u8 value)
-{
-	return value >> 5;
-}
-
-static u32 s600_uart_exti_decode_pin(u8 value)
-{
-	return value & 0x1F;
-}
-
-static int s600_uart_process_gpio_init(u8 *buff, u16 length)
-{
-	if (length < 6) {
-		u32 port = s600_uart_gpio_decode_port(buff[0]);
-		u32 pin = s600_uart_gpio_decode_pin(buff[0]);
-		gpio_init(port, buff[1], buff[2], pin);
-	} else {
-		gpio_pin_remap_config(s600_decode_u32(buff + 1), (ControlStatus) buff[5]);
-	}
-
-	return 1;
-}
-
-static int s600_uart_process_gpio_input_bit_get(u8 *buff, u16 length)
-{
-	u32 port = s600_uart_gpio_decode_port(buff[0]);
-	u32 pin = s600_uart_gpio_decode_pin(buff[0]);
-
-	if (length > 1) {
-		gpio_init(port, buff[1], GPIO_OSPEED_50MHZ, pin);
-	}
-
-	buff[1] = gpio_input_bit_get(port, pin);
-
-	return 2;
-}
-
-static int s600_uart_process_gpio_output_bit_set(u8 *buff, u16 length)
-{
-	u32 port = s600_uart_gpio_decode_port(buff[0]);
-	u32 pin = s600_uart_gpio_decode_pin(buff[0]);
-
-	if (length > 2) {
-		gpio_init(port, buff[2], GPIO_OSPEED_50MHZ, pin);
-	}
-
-	if (buff[1] == 0) {
-		gpio_bit_reset(port, pin);
-	} else {
-		gpio_bit_set(port, pin);
-	}
-
-	return 1;
-}
-
-static int s600_uart_process_gpio_output_bit_get(u8 *buff, u16 length)
-{
-	u32 port = s600_uart_gpio_decode_port(buff[0]);
-	u32 pin = s600_uart_gpio_decode_pin(buff[0]);
-
-	buff[1] = gpio_output_bit_get(port, pin);
-
-	return 2;
-}
-
-static int s600_uart_process_gpio_input_port_get(u8 *buff, u16 length)
-{
-	u32 port = s600_uart_gpio_decode_port(buff[0]);
-	s600_encode_u16(buff + 1, gpio_input_port_get(port));
-	return 3;
-}
-
-static int s600_uart_process_gpio_output_port_set(u8 *buff, u16 length)
-{
-	u32 port = s600_uart_gpio_decode_port(buff[0]);
-	gpio_port_write(port, s600_decode_u16(buff + 1));
-	return 1;
-}
-
-static int s600_uart_process_gpio_output_port_get(u8 *buff, u16 length)
-{
-	u32 port = s600_uart_gpio_decode_port(buff[0]);
-	s600_encode_u16(buff + 1, gpio_output_port_get(port));
-	return 3;
-}
-
-static int s600_uart_process_adc(u8 *buff, u16 length)
-{
-	return s600_adc_get_values(buff[0], buff + 1) - buff + 1;
-}
-
-static int s600_uart_process_write_dac(int index, u8 *buff, u16 length)
-{
-	length = s600_dac_write(index, buff, length);
-	s600_encode_u16(buff, length);
-	return 2;
-}
-
-static int s600_uart_process_dac_set_enable(u8 *buff, u16 length)
-{
-	u8 dac = buff[0];
-
-	if (buff[1] == 0) {
-		s600_dac_disable(dac);
-	} else {
-		s600_dac_enable(dac);
-	}
-
-	return 1;
-}
-
-static int s600_uart_process_dac_set_volume(u8 *buff, u16 length)
-{
-	s600_dac_set_volume(buff[0], buff[1]);
-	return 1;
-}
-
-static int s600_uart_process_dac_set_rate(u8 *buff, u16 length)
-{
-	s600_dac_set_rate(buff[0], s600_decode_u16(buff + 1));
-	return 1;
-}
-
-static int s600_uart_process_single_comm_config(u8 *buff, u16 length)
-{
-	if (length < 2) {
-		return -1;
-	}
-
-	if (buff[1]) {
-		u32 port, pin;
-
-		if (length < 3) {
-			return -1;
-		}
-
-		port = s600_uart_exti_decode_port(buff[2]);
-		pin = s600_uart_exti_decode_pin(buff[2]);
-		s600_turn_key_init(buff[0], port, pin);
-	} else {
-		s600_turn_key_deinit(buff[0]);
-	}
-
-	return 0;
-}
-
-static int s600_uart_process_spi_led_init(void)
-{
-	ws2818_spi_init();
-	return 0;
-}
-
-static int s600_uart_process_spi_led_commit(void)
-{
-	ws2818_commit();
-	return 0;
-}
-
-static int s600_uart_process_spi_led_clear(u8 *buff, u16 length)
-{
-	u32 color;
-	u8 index;
-	u8 count;
-
-	if (length > 0) {
-		index = buff[0];
-	} else {
-		index = 0;
-	}
-
-	if (length > 1) {
-		count = buff[1];
-	} else {
-		count = WS2818_LED_COUNT - index;
-	}
-
-	if (length < 5) {
-		color = 0x00000000;
-	} else {
-		color = s600_decode_u24(buff + 2);
-	}
-
-	ws2818_set_color_burst(index, index + count, color);
-
-	return 0;
-}
-
-static int s600_uart_process_spi_led_set_color(u8 *buff, u16 length)
-{
-	u8 index;
-
-	if (length < 1) {
-		return -1;
-	}
-
-	for (index = buff[0], buff++, length--; length >= 3; index++) {
-		ws2818_set_color(index, s600_decode_u24(buff));
-		length -= 3;
-		buff += 3;
-	}
-
-	return 0;
-}
-
-static int s600_uart_process_reg_rw(u8 *buff, u16 length)
-{
-	return 0;
-}
-
-static int s600_uart_process_mem_rw(u8 *buff, u16 length)
-{
-	return 0;
-}
-
-
-static void s600_uart_exti_notify(u8 index)
-{
-	exti_interrupt_flag_clear((exti_line_enum) BIT(index));
-	s600_uart_send_command(CMD_EXTI_NOTIFY, &index, 1);
-}
-
-
-static void s600_uart_put(struct s600_uart_device *uart, u8 *buff, u16 length)
-{
-	const u8 *buff_end;
-
-	for (buff_end = buff + length; buff < buff_end; buff++) {
-		u8 value = *buff;
-
-		switch (value) {
-		case CH_START:
-			s600_uart_index = 0;
-			s600_uart_valid = true;
-			s600_uart_escape = false;
-			break;
-
-		case CH_END:
-			if (s600_uart_valid && s600_uart_index > 0) {
-				s600_uart_process_frame(s600_uart_frame, s600_uart_index);
-				s600_uart_index = 0;
-			}
-
-			s600_uart_valid = false;
-			s600_uart_escape = false;
-			break;
-
-		case CH_ESC:
-			s600_uart_escape = true;
-			break;
-
-		default:
-			if (s600_uart_escape) {
-				s600_uart_escape = false;
-
-				switch (value) {
-				case CH_ESC_START:
-					value = CH_START;
-					break;
-
-				case CH_ESC_END:
-					value = CH_END;
-					break;
-
-				case CH_ESC_ESC:
-					value = CH_ESC;
-					break;
-
-				default:
-					s600_uart_valid = false;
-					break;
-				}
-			}
-
-			if (s600_uart_index < sizeof(s600_uart_frame)) {
-				s600_uart_frame[s600_uart_index++] = value;
-			} else {
-				s600_uart_valid = false;
-			}
-		}
-	}
-}
-
-void s600_uart_poll(void)
-{
-	int i;
-
-	for (i = 0; i < NELEM(s600_uarts); i++) {
-		s600_uart_device_t *uart = s600_uarts + i;
-		uart->tx_poll(uart);
-		uart->rx_poll(uart);
-
-#if S600_UART_USE_CACHE
-		if (uart->cache_times > 0) {
-			if (uart->cache_times == 1 && uart->cache_len > 0) {
-				uart->on_data_received(uart->cache, uart->cache_len);
-				uart->cache_len = 0;
-			}
-
-			uart->cache_times--;
-		}
-#endif
-	}
-}
-
-
-void s600_uart_print_flush(short_command_t cmd)
-{
-	s600_uart_send_command(cmd, s600_print_buff, s600_print_pos);
-	s600_print_pos = 0;
-}
-
-void s600_uart0_received(u8 *buff, u16 length)
-{
-	s600_uart_send_command(CMD_UART0, buff, length);
-}
-
-void s600_uart1_received(u8 *buff, u16 length)
-{
-	s600_uart_send_command(CMD_UART1, buff, length);
-}
-
-void s600_uart2_received(u8 *buff, u16 length)
-{
-	s600_uart_send_command(CMD_UART2, buff, length);
-}
-
-void s600_uart3_received(u8 *buff, u16 length)
-{
-	s600_uart_send_command(CMD_UART3, buff, length);
-}
-
-void s600_uart4_received(u8 *buff, u16 length)
-{
-	s600_uart_send_command(CMD_UART4, buff, length);
-}
-
-void s600_uart_rcu_config(void)
-{
-	u16 position = 0;
-	int i;
-
-	for (i = 0; i < NELEM(s600_uarts); i++) {
-		s600_uart_device_t *uart = s600_uarts + i;
-
-		if (i == CONFIG_UART_MAIN) {
-			uart->tx_cache_size = S600_UART_MAIN_TX_MEM_SIZE;
-			uart->rx_cache_size = S600_UART_MAIN_RX_MEM_SIZE;
-			uart->do_cache_data = s600_uart_put;
-		} else {
-			uart->tx_cache_size = S600_UART_TX_MEM_SIZE;
-			uart->rx_cache_size = S600_UART_RX_MEM_SIZE;
-			uart->do_cache_data = s600_uart_cache_data;
-		}
-
-		uart->tx_cache = s600_uart_cache + position;
-		uart->rx_cache = uart->tx_cache + uart->tx_cache_size;
-	}
-
-	S600_UART_INIT_DMA(0);
-	S600_UART_INIT_DMA(1);
-
-#ifdef CONFIG_BOARD_M6_CDL
-	S600_UART_INIT_IRQ(2);
-#else
-	S600_UART_INIT_DMA(2);
-#endif
-
-	S600_UART_INIT_DMA(3);
-	S600_UART_INIT_IRQ(4);
-
-	usart_enable(s600_uart_get_main()->com);
-}
-
-int fputc(int ch, FILE *f)
-{
-	if (ch == '\n') {
-		if (s600_print_pos > 0) {
-			s600_uart_print_flush(CMD_PRINT_END);
-		}
-	} else {
-		while (1) {
-			if (s600_print_pos < sizeof(s600_print_buff)) {
-				s600_print_buff[s600_print_pos] = ch;
-				s600_print_pos++;
-				break;
-			}
-
-			s600_uart_print_flush(CMD_PRINT_ADD);
-		}
-	}
-
-	return ch;
-}
-
-void USART0_IRQHandler(void)
-{
-	s600_uart_rx(s600_uarts);
-	s600_uart_device_tx(s600_uarts);
-}
-
-void USART1_IRQHandler(void)
-{
-	s600_uart_rx(s600_uarts + 1);
-	s600_uart_device_tx(s600_uarts + 1);
-}
-
-void USART2_IRQHandler(void)
-{
-	s600_uart_rx(s600_uarts + 2);
-	s600_uart_device_tx(s600_uarts + 2);
-}
-
-void UART3_IRQHandler(void)
-{
-	s600_uart_rx(s600_uarts + 3);
-	s600_uart_device_tx(s600_uarts + 3);
-}
-
-void UART4_IRQHandler(void)
-{
-	s600_uart_rx(s600_uarts + 4);
-	s600_uart_device_tx(s600_uarts + 4);
-}
-

+ 0 - 149
Application/bsp/shark_uart.h

@@ -1,149 +0,0 @@
-#pragma once
-
-#include "s600.h"
-#include "s600_can.h"
-#include "byte_queue.h"
-
-#define S600_UART_USE_DMA				1
-#define S600_UART_USE_CACHE				1
-#define S600_UART_CACHE_TIMES			200
-
-#define CH_START						0xF5
-#define CH_END							0xF6
-#define CH_ESC							0xF7
-#define CH_ESC_START					0x05
-#define CH_ESC_END						0x06
-#define CH_ESC_ESC						0x07
-
-#define S600_UART_FRAME_SIZE			2048
-
-#ifdef CONFIG_BOARD_S600
-#define S600_UART_TX_MEM_SIZE			512
-#define S600_UART_RX_MEM_SIZE			512
-#else
-#define S600_UART_TX_MEM_SIZE			1024
-#define S600_UART_RX_MEM_SIZE			1024
-#endif
-
-#define S600_UART_MAIN_TX_MEM_SIZE		2048
-#define S600_UART_MAIN_RX_MEM_SIZE		2048
-
-typedef enum {
-	CMD_CAN = 0,
-	CMD_PING,
-	CMD_VERSION,
-	CMD_PRINT_ADD,
-	CMD_PRINT_END,
-	CMD_PWM_SET_ENABLE, // 5
-	CMD_PWM_SET_VALUE,
-	CMD_UART0,
-	CMD_UART1,
-	CMD_UART2,
-	CMD_UART3, // 10
-	CMD_UART4,
-	CMD_UART_CONFIG,
-	CMD_GPIO_INIT,
-	CMD_GPIO_INPUT_BIT_GET,
-	CMD_GPIO_OUTPUT_BIT_SET, // 15
-	CMD_GPIO_OUTPUT_BIT_GET,
-	CMD_GPIO_INPUT_PORT_GET,
-	CMD_GPIO_OUTPUT_PORT_SET,
-	CMD_GPIO_OUTPUT_PORT_GET,
-	CMD_ADC, // 20
-	CMD_DAC0,
-	CMD_DAC1,
-	CMD_DAC_SET_ENABLE,
-	CMD_DAC_SET_VOLUME,
-	CMD_DAC_SET_RATE, // 25
-	CMD_SINGLE_COMM_CONFIG,
-	CMD_SINGLE_COMM_DATA,
-	CMD_SPI_LED_INIT,
-	CMD_SPI_LED_COMMIT,
-	CMD_SPI_LED_CLEAR, // 30
-	CMD_SPI_LED_SET_COLOR,
-	CMD_REG_RW,
-	CMD_MEM_RW,
-	CMD_I2C_INIT,
-	CMD_I2C_RW, // 35
-	CMD_EXTI_INIT,
-	CMD_EXTI_NOTIFY,
-} short_command_t;
-
-typedef enum {
-	S600_UART0,
-	S600_UART1,
-	S600_UART2,
-	S600_UART3,
-	S600_UART4,
-	S600_UART_COUNT
-} s600_uart_t;
-
-typedef struct s600_uart_device {
-	u32 com;
-	u32 tx_dma;
-	u32 rx_dma;
-	dma_channel_enum tx_dma_ch;
-	dma_channel_enum rx_dma_ch;
-
-#if S600_UART_USE_CACHE
-	u8 cache[64];
-	u8 cache_len;
-	u8 cache_times;
-#endif
-
-	u8 *tx_cache;
-	u8 *rx_cache;
-	u16 tx_cache_size;
-	u16 rx_cache_size;
-
-	u16 tx_length;
-	u16 rx_index;
-
-	byte_queue_t tx_queue;
-	byte_queue_t rx_queue;
-
-	void (*do_cache_data)(struct s600_uart_device *uart, u8 *buff, u16 size);
-	void (*on_data_received)(u8 *buff, u16 size);
-	void (*tx_poll)(struct s600_uart_device *uart);
-	void (*rx_poll)(struct s600_uart_device *uart);
-} s600_uart_device_t;
-
-typedef struct {
-	u8 *buff;
-	u16 size;
-} s600_uart_message_t;
-
-extern s600_uart_device_t s600_uarts[];
-
-extern void s600_uart_received(s600_uart_device_t *uart, u8 *buff, u16 length);
-extern void s600_uart0_received(u8 *buff, u16 length);
-extern void s600_uart1_received(u8 *buff, u16 length);
-extern void s600_uart2_received(u8 *buff, u16 length);
-extern void s600_uart3_received(u8 *buff, u16 length);
-extern void s600_uart4_received(u8 *buff, u16 length);
-
-void s600_uart_init(s600_uart_device_t *uart);
-void s600_uart_dma_tx(s600_uart_device_t *uart);
-void s600_uart_dma_rx(s600_uart_device_t *uart);
-void s600_uart_write(s600_uart_device_t *uart, const u8 *buff, u16 size);
-u16 s600_uart_read(s600_uart_device_t *uart, u8 *buff, u16 size);
-void s600_uart_write_byte(s600_uart_device_t *uart, u8 value);
-u16 s600_uart_write_available(s600_uart_device_t *uart);
-bool s600_uart_write_full(s600_uart_device_t *uart, const u8 *buff, u16 size);
-
-void s600_uart_message_init(s600_uart_message_t *msg, const void *buff, u16 size);
-void s600_uart_write_messages(s600_uart_device_t *uart, const s600_uart_message_t *msgs, u8 count);
-
-void s600_uart_rcu_config(void);
-void s600_uart_poll(void);
-void s600_uart_send_command(u8 cmd, const void *buff, u16 size);
-void s600_uart_send_command_u8(u8 cmd, u8 value);
-void s600_uart_send_command_bool(u8 cmd, bool value);
-
-void s600_uart_send_can_frame(const s600_can_frame_t *frame);
-void s600_uart_send_can_pack(const s600_can_pack_t *pack);
-
-__STATIC_INLINE s600_uart_device_t *s600_uart_get_main(void)
-{
-	return s600_uarts + CONFIG_UART_MAIN;
-}

+ 4 - 0
Application/libs/shark_task.c

@@ -25,6 +25,10 @@ u64 shark_get_mseconds(void)
 	return shark_mseconds;
 }
 
+u32 shark_get_seconds(void){
+	return shark_mseconds/1000;
+}
+
 static inline void shark_timer_sync(void)
 {
 	shark_task_head.time = shark_timer_head.next->time;

+ 1 - 0
Application/libs/shark_task.h

@@ -16,6 +16,7 @@ typedef struct shark_timer {
 } shark_timer_t;
 
 u64 shark_get_mseconds(void);
+u32 shark_get_seconds(void);
 void shark_timer_post(shark_timer_t *timer, u32 delay);
 void shark_timer_cancel(shark_timer_t *timer);
 void shark_task_add(shark_task_t *task);