|
@@ -2,33 +2,38 @@
|
|
#include "_string.h"
|
|
#include "_string.h"
|
|
#include "app_scheduler.h"
|
|
#include "app_scheduler.h"
|
|
|
|
|
|
-static uint32_t rx_pin=RX_PIN_NUMBER;
|
|
|
|
-static uint32_t tx_pin=TX_PIN_NUMBER;
|
|
|
|
|
|
+static uint32_t rx_pin = RX_PIN_NUMBER;
|
|
|
|
+static uint32_t tx_pin = TX_PIN_NUMBER;
|
|
static custome_event user_uart_event;
|
|
static custome_event user_uart_event;
|
|
|
|
|
|
-user_uart_s usr_uart={
|
|
|
|
- .uart_init_stat=false,
|
|
|
|
- .uart_work=UART_STR,
|
|
|
|
- .uart_rx_stat=false, //uart接收完成标志
|
|
|
|
- .uart_re_Byte={0}, //模块返回信息存储
|
|
|
|
- .uart_re_addr_count=0, //存储位置计数
|
|
|
|
- .uart_re_addr=usr_uart.uart_re_Byte, //当前保存的位置
|
|
|
|
- .uart_re_addr_begin=usr_uart.uart_re_Byte, //当前区域的首地址
|
|
|
|
- .uart_re_array={usr_uart.uart_re_Byte,0,0,0,0,0,0,0,0,0}, //存放的内存地址位置
|
|
|
|
- .uart_re_count_array={0}, //存放的数据数量
|
|
|
|
- .uart_re_point=0, //当前存放内存数组位置
|
|
|
|
-
|
|
|
|
- .modbus_receive={0},
|
|
|
|
- .modbus_len=0,
|
|
|
|
- .modbus_rec=false,
|
|
|
|
- .m_modbus_rec_func=NULL,
|
|
|
|
-
|
|
|
|
- .hex_receive=NULL,
|
|
|
|
- .hex_pro=false,
|
|
|
|
- .hex_len=0,
|
|
|
|
- .hex_size=0,
|
|
|
|
- .hex_rec=false,
|
|
|
|
- .m_hex_rec_func=NULL,
|
|
|
|
|
|
+user_uart_s usr_uart = {
|
|
|
|
+ .uart_init_stat = false,
|
|
|
|
+#ifdef MODUBS_USED
|
|
|
|
+ .recv_modbus_size = 9,
|
|
|
|
+ .modbus_receive = NULL,
|
|
|
|
+ .modbus_len = 0,
|
|
|
|
+ .modbus_rec = false,
|
|
|
|
+ .m_modbus_rec_func = NULL,
|
|
|
|
+#endif
|
|
|
|
+#ifdef UART_STR_USED
|
|
|
|
+ .uart_work = UART_STR,
|
|
|
|
+ .uart_rx_stat = false, //uart接收完成标志
|
|
|
|
+ .uart_re_Byte = {0}, //模块返回信息存储
|
|
|
|
+ .uart_re_addr_count = 0, //存储位置计数
|
|
|
|
+ .uart_re_addr = usr_uart.uart_re_Byte, //当前保存的位置
|
|
|
|
+ .uart_re_addr_begin = usr_uart.uart_re_Byte, //当前区域的首地址
|
|
|
|
+ .uart_re_array = {usr_uart.uart_re_Byte,0,0,0,0,0,0,0,0,0}, //存放的内存地址位置
|
|
|
|
+ .uart_re_count_array = {0}, //存放的数据数量
|
|
|
|
+ .uart_re_point = 0, //当前存放内存数组位置
|
|
|
|
+#endif
|
|
|
|
+#ifdef UART_HEX_USED
|
|
|
|
+ .hex_receive = NULL,
|
|
|
|
+ .hex_pro = false,
|
|
|
|
+ .hex_len = 0,
|
|
|
|
+ .hex_size = 0,
|
|
|
|
+ .hex_rec = false,
|
|
|
|
+ .m_hex_rec_func = NULL,
|
|
|
|
+#endif
|
|
};
|
|
};
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -39,7 +44,7 @@ user_uart_s usr_uart={
|
|
static void UartSendChar(uint8_t ch)
|
|
static void UartSendChar(uint8_t ch)
|
|
{
|
|
{
|
|
uint32_t err_code;
|
|
uint32_t err_code;
|
|
- if(usr_uart.uart_init_stat!=true)
|
|
|
|
|
|
+ if(usr_uart.uart_init_stat != true)
|
|
{
|
|
{
|
|
uart_open();
|
|
uart_open();
|
|
}
|
|
}
|
|
@@ -65,7 +70,7 @@ void UartSendHex(uint8_t *hex,uint16_t len,bool space)
|
|
UartSendChar(_get_HexChar(*hex>>4));
|
|
UartSendChar(_get_HexChar(*hex>>4));
|
|
UartSendChar(_get_HexChar(*hex&0x0F));
|
|
UartSendChar(_get_HexChar(*hex&0x0F));
|
|
hex++;
|
|
hex++;
|
|
- if(space==true)
|
|
|
|
|
|
+ if(space == true)
|
|
{
|
|
{
|
|
UartSendChar(' ');
|
|
UartSendChar(' ');
|
|
}
|
|
}
|
|
@@ -74,12 +79,60 @@ void UartSendHex(uint8_t *hex,uint16_t len,bool space)
|
|
|
|
|
|
void UartSendString(char *pBuffer)
|
|
void UartSendString(char *pBuffer)
|
|
{
|
|
{
|
|
- while(*pBuffer!='\0'){
|
|
|
|
|
|
+ while(*pBuffer != '\0'){
|
|
UartSendChar(*pBuffer);
|
|
UartSendChar(*pBuffer);
|
|
pBuffer++;
|
|
pBuffer++;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+#ifdef MODUBS_USED
|
|
|
|
+void Modbus_Set_Init(uint8_t size)
|
|
|
|
+{
|
|
|
|
+ usr_uart.uart_work = UART_MODBUS;
|
|
|
|
+ usr_uart.modbus_rec = false;
|
|
|
|
+ usr_uart.modbus_len = 0;
|
|
|
|
+ if(usr_uart.modbus_receive == NULL)
|
|
|
|
+ {
|
|
|
|
+ usr_uart.recv_modbus_size = size;
|
|
|
|
+ usr_uart.modbus_receive = malloc(usr_uart.recv_modbus_size+2);
|
|
|
|
+ }
|
|
|
|
+ else if(usr_uart.recv_modbus_size != size){
|
|
|
|
+ usr_uart.recv_modbus_size = size;
|
|
|
|
+ usr_uart.modbus_receive = realloc(usr_uart.modbus_receive, usr_uart.recv_modbus_size+2);
|
|
|
|
+ }
|
|
|
|
+ memset(usr_uart.modbus_receive,0,usr_uart.recv_modbus_size+2);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void Modbus_Data_Init(void)
|
|
|
|
+{
|
|
|
|
+ usr_uart.modbus_rec = false;
|
|
|
|
+ usr_uart.modbus_len = 0;
|
|
|
|
+ memset(usr_uart.modbus_receive,0,usr_uart.recv_modbus_size+2);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static void Modbus_Data_Pro(uint8_t temp)
|
|
|
|
+{
|
|
|
|
+ if(usr_uart.modbus_rec == false)
|
|
|
|
+ {
|
|
|
|
+ usr_uart.modbus_receive[usr_uart.modbus_len++] = temp;
|
|
|
|
+ if(usr_uart.modbus_len >= usr_uart.recv_modbus_size)
|
|
|
|
+ {
|
|
|
|
+ usr_uart.modbus_rec = true;
|
|
|
|
+ if(usr_uart.m_modbus_rec_func != NULL)
|
|
|
|
+ {
|
|
|
|
+ usr_uart.m_modbus_rec_func(usr_uart.modbus_receive,&usr_uart.modbus_len,&usr_uart.modbus_rec);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void set_modbus_rec_func(modbus_rec_func func)
|
|
|
|
+{
|
|
|
|
+ usr_uart.uart_work = UART_MODBUS;
|
|
|
|
+ usr_uart.m_modbus_rec_func = func;
|
|
|
|
+}
|
|
|
|
+#endif
|
|
|
|
+#ifdef UART_STR_USED
|
|
static void uart_re_add_set(void)
|
|
static void uart_re_add_set(void)
|
|
{
|
|
{
|
|
usr_uart.uart_re_count_array[usr_uart.uart_re_point]++;
|
|
usr_uart.uart_re_count_array[usr_uart.uart_re_point]++;
|
|
@@ -126,72 +179,49 @@ static void Uart_Receive_Str(uint8_t c)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-void Hex_Set_Init(uint8_t *buffer,uint8_t size)
|
|
|
|
-{
|
|
|
|
- usr_uart.hex_rec=false;
|
|
|
|
- usr_uart.hex_len=0;
|
|
|
|
- usr_uart.hex_receive=buffer;
|
|
|
|
- usr_uart.hex_size=size;
|
|
|
|
- memset(usr_uart.hex_receive,0,usr_uart.hex_size);
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-void Modbus_Set_Init(void)
|
|
|
|
-{
|
|
|
|
- usr_uart.modbus_rec=false;
|
|
|
|
- usr_uart.modbus_len=0;
|
|
|
|
- memset(usr_uart.modbus_receive,0,MODBUS_REC_LEN);
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-void Uart_Set_Init(void)
|
|
|
|
-{
|
|
|
|
- usr_uart.uart_rx_stat=false,
|
|
|
|
- memset(usr_uart.uart_re_Byte,0,USER_UART_REBYTE_LEN);
|
|
|
|
- usr_uart.uart_re_addr_count=0;
|
|
|
|
- usr_uart.uart_re_addr=usr_uart.uart_re_Byte;
|
|
|
|
- usr_uart.uart_re_addr_begin=usr_uart.uart_re_Byte;
|
|
|
|
- memset(usr_uart.uart_re_array,0,10);
|
|
|
|
- usr_uart.uart_re_array[0]=usr_uart.uart_re_Byte;
|
|
|
|
- memset(usr_uart.uart_re_count_array,0,10);
|
|
|
|
- usr_uart.uart_re_point=0;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-static void Modbus_Data_Pro(uint8_t temp)
|
|
|
|
-{
|
|
|
|
- if(usr_uart.modbus_rec==false)
|
|
|
|
- {
|
|
|
|
- usr_uart.modbus_receive[usr_uart.modbus_len++]=temp;
|
|
|
|
- if(usr_uart.modbus_len>=MODBUS_REC_LEN)
|
|
|
|
- {
|
|
|
|
- usr_uart.modbus_rec=true;
|
|
|
|
- if(usr_uart.m_modbus_rec_func!=NULL)
|
|
|
|
- {
|
|
|
|
- usr_uart.m_modbus_rec_func(usr_uart.modbus_receive,&usr_uart.modbus_len,&usr_uart.modbus_rec);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-static void Hex_Data_Pro(uint8_t temp)
|
|
|
|
|
|
+/*******************************************************************************
|
|
|
|
+ * @函数名称 Uart_ReData_Pro
|
|
|
|
+ * @函数说明 检查Uart返回数据
|
|
|
|
+ * @输入参数 无
|
|
|
|
+ * @输出参数 无
|
|
|
|
+ * @返回参数 无
|
|
|
|
+*******************************************************************************/
|
|
|
|
+void Uart_ReData_Pro(void)
|
|
{
|
|
{
|
|
- if(usr_uart.hex_pro==true)
|
|
|
|
- {
|
|
|
|
- if(usr_uart.m_single_hex_rec_func!=NULL)
|
|
|
|
- {
|
|
|
|
- usr_uart.m_single_hex_rec_func(temp);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- else{
|
|
|
|
- if(usr_uart.hex_rec==false)
|
|
|
|
|
|
+// char str[30]={0};
|
|
|
|
+ uint8_t i=0;
|
|
|
|
+ char data[128]={0};
|
|
|
|
+// uint8_t *data;
|
|
|
|
+ char *idx;
|
|
|
|
+ uint16_t len=0;
|
|
|
|
+ uint16_t len_diff=0;
|
|
|
|
+
|
|
|
|
+ for(i=0;i<10;i++){
|
|
|
|
+ if(usr_uart.uart_re_array[i]!=0)
|
|
{
|
|
{
|
|
- usr_uart.hex_receive[usr_uart.hex_len++]=temp;
|
|
|
|
- if(usr_uart.hex_len>=usr_uart.hex_size)
|
|
|
|
|
|
+ len_diff=&usr_uart.uart_re_Byte[USER_UART_REBYTE_LEN-1]-usr_uart.uart_re_array[i]+1;
|
|
|
|
+
|
|
|
|
+// data=(uint8_t *)malloc(bc95_re_count_array[i]*sizeof(uint8_t));
|
|
|
|
+ idx=usr_uart.uart_re_array[i];
|
|
|
|
+ len=0;
|
|
|
|
+ while(usr_uart.uart_re_count_array[i])
|
|
{
|
|
{
|
|
- usr_uart.hex_rec=true;
|
|
|
|
- if(usr_uart.m_hex_rec_func!=NULL)
|
|
|
|
|
|
+ data[len++]=*idx++;
|
|
|
|
+ if(len==len_diff)
|
|
{
|
|
{
|
|
- usr_uart.m_hex_rec_func();
|
|
|
|
|
|
+ idx=usr_uart.uart_re_Byte;
|
|
}
|
|
}
|
|
|
|
+ usr_uart.uart_re_count_array[i]--;
|
|
}
|
|
}
|
|
|
|
+ data[len]='\0';
|
|
|
|
+
|
|
|
|
+ usr_uart.m_uart_rec_func(data);
|
|
|
|
+//#ifdef DEBUG
|
|
|
|
+// printf(data);
|
|
|
|
+// printf("\r\n");
|
|
|
|
+//#endif
|
|
|
|
+ usr_uart.uart_re_array[i]=0;
|
|
|
|
+ // free(data);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -241,22 +271,114 @@ static void Terminal_Data_Pro(uint8_t temp)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+void Uart_Set_Init(void)
|
|
|
|
+{
|
|
|
|
+ usr_uart.uart_rx_stat=false,
|
|
|
|
+ memset(usr_uart.uart_re_Byte,0,USER_UART_REBYTE_LEN);
|
|
|
|
+ usr_uart.uart_re_addr_count=0;
|
|
|
|
+ usr_uart.uart_re_addr=usr_uart.uart_re_Byte;
|
|
|
|
+ usr_uart.uart_re_addr_begin=usr_uart.uart_re_Byte;
|
|
|
|
+ memset(usr_uart.uart_re_array,0,10);
|
|
|
|
+ usr_uart.uart_re_array[0]=usr_uart.uart_re_Byte;
|
|
|
|
+ memset(usr_uart.uart_re_count_array,0,10);
|
|
|
|
+ usr_uart.uart_re_point=0;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void set_string_rec_func(uart_rec_func func)
|
|
|
|
+{
|
|
|
|
+ usr_uart.uart_work=UART_STR;
|
|
|
|
+ usr_uart.m_uart_rec_func=func;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void set_terminal_rec_func(uart_rec_func func)
|
|
|
|
+{
|
|
|
|
+ usr_uart.uart_work=UART_TERMINAL;
|
|
|
|
+ usr_uart.m_uart_rec_func=func;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static void user_uart_pro(void)
|
|
|
|
+{
|
|
|
|
+ if(usr_uart.uart_rx_stat==true)
|
|
|
|
+ {
|
|
|
|
+ Uart_ReData_Pro();
|
|
|
|
+ usr_uart.uart_rx_stat=false;
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+#endif
|
|
|
|
+#ifdef UART_HEX_USED
|
|
|
|
+void set_hex_rec_func(hex_rec_func func)
|
|
|
|
+{
|
|
|
|
+ usr_uart.uart_work=UART_HEX;
|
|
|
|
+ usr_uart.m_hex_rec_func=func;
|
|
|
|
+ usr_uart.hex_pro=false;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void set_single_hex_rec_func(single_hex_rec_func func)
|
|
|
|
+{
|
|
|
|
+ usr_uart.uart_work=UART_HEX;
|
|
|
|
+ usr_uart.m_single_hex_rec_func=func;
|
|
|
|
+ usr_uart.hex_pro=true;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+void Hex_Set_Init(uint8_t *buffer,uint8_t size)
|
|
|
|
+{
|
|
|
|
+ usr_uart.hex_rec=false;
|
|
|
|
+ usr_uart.hex_len=0;
|
|
|
|
+ usr_uart.hex_receive=buffer;
|
|
|
|
+ usr_uart.hex_size=size;
|
|
|
|
+ memset(usr_uart.hex_receive,0,usr_uart.hex_size);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static void Hex_Data_Pro(uint8_t temp)
|
|
|
|
+{
|
|
|
|
+ if(usr_uart.hex_pro==true)
|
|
|
|
+ {
|
|
|
|
+ if(usr_uart.m_single_hex_rec_func!=NULL)
|
|
|
|
+ {
|
|
|
|
+ usr_uart.m_single_hex_rec_func(temp);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else{
|
|
|
|
+ if(usr_uart.hex_rec==false)
|
|
|
|
+ {
|
|
|
|
+ usr_uart.hex_receive[usr_uart.hex_len++]=temp;
|
|
|
|
+ if(usr_uart.hex_len>=usr_uart.hex_size)
|
|
|
|
+ {
|
|
|
|
+ usr_uart.hex_rec=true;
|
|
|
|
+ if(usr_uart.m_hex_rec_func!=NULL)
|
|
|
|
+ {
|
|
|
|
+ usr_uart.m_hex_rec_func();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+#endif
|
|
|
|
+
|
|
static void Uart_Data_Pro(uint8_t c)
|
|
static void Uart_Data_Pro(uint8_t c)
|
|
{
|
|
{
|
|
- if(usr_uart.uart_work==UART_MODBUS)
|
|
|
|
|
|
+ if(usr_uart.uart_work == UART_MODBUS)
|
|
{
|
|
{
|
|
|
|
+#ifdef MODUBS_USED
|
|
Modbus_Data_Pro(c);
|
|
Modbus_Data_Pro(c);
|
|
|
|
+#endif
|
|
}
|
|
}
|
|
- else if(usr_uart.uart_work==UART_HEX)
|
|
|
|
|
|
+ else if(usr_uart.uart_work == UART_HEX)
|
|
{
|
|
{
|
|
|
|
+#ifdef UART_HEX_USED
|
|
Hex_Data_Pro(c);
|
|
Hex_Data_Pro(c);
|
|
|
|
+#endif
|
|
}
|
|
}
|
|
- else if(usr_uart.uart_work==UART_TERMINAL)
|
|
|
|
|
|
+ else if(usr_uart.uart_work == UART_TERMINAL)
|
|
{
|
|
{
|
|
|
|
+#ifdef UART_STR_USED
|
|
Terminal_Data_Pro(c);
|
|
Terminal_Data_Pro(c);
|
|
|
|
+#endif
|
|
}
|
|
}
|
|
else{
|
|
else{
|
|
|
|
+#ifdef UART_STR_USED
|
|
Uart_Receive_Str(c);
|
|
Uart_Receive_Str(c);
|
|
|
|
+#endif
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -275,7 +397,7 @@ void uart_event_handle(app_uart_evt_t * p_event)
|
|
break;
|
|
break;
|
|
//通讯错误事件,进入错误处理
|
|
//通讯错误事件,进入错误处理
|
|
case APP_UART_COMMUNICATION_ERROR:
|
|
case APP_UART_COMMUNICATION_ERROR:
|
|
-// APP_ERROR_HANDLER(p_event->data.error_communication);
|
|
|
|
|
|
+ APP_ERROR_HANDLER(p_event->data.error_communication);
|
|
break;
|
|
break;
|
|
//FIFO错误事件,进入错误处理
|
|
//FIFO错误事件,进入错误处理
|
|
case APP_UART_FIFO_ERROR:
|
|
case APP_UART_FIFO_ERROR:
|
|
@@ -286,52 +408,7 @@ void uart_event_handle(app_uart_evt_t * p_event)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-/*******************************************************************************
|
|
|
|
- * @函数名称 Uart_ReData_Pro
|
|
|
|
- * @函数说明 检查Uart返回数据
|
|
|
|
- * @输入参数 无
|
|
|
|
- * @输出参数 无
|
|
|
|
- * @返回参数 无
|
|
|
|
-*******************************************************************************/
|
|
|
|
-void Uart_ReData_Pro(void)
|
|
|
|
-{
|
|
|
|
-// char str[30]={0};
|
|
|
|
- uint8_t i=0;
|
|
|
|
- char data[128]={0};
|
|
|
|
-// uint8_t *data;
|
|
|
|
- char *idx;
|
|
|
|
- uint16_t len=0;
|
|
|
|
- uint16_t len_diff=0;
|
|
|
|
-
|
|
|
|
- for(i=0;i<10;i++){
|
|
|
|
- if(usr_uart.uart_re_array[i]!=0)
|
|
|
|
- {
|
|
|
|
- len_diff=&usr_uart.uart_re_Byte[USER_UART_REBYTE_LEN-1]-usr_uart.uart_re_array[i]+1;
|
|
|
|
-
|
|
|
|
-// data=(uint8_t *)malloc(bc95_re_count_array[i]*sizeof(uint8_t));
|
|
|
|
- idx=usr_uart.uart_re_array[i];
|
|
|
|
- len=0;
|
|
|
|
- while(usr_uart.uart_re_count_array[i])
|
|
|
|
- {
|
|
|
|
- data[len++]=*idx++;
|
|
|
|
- if(len==len_diff)
|
|
|
|
- {
|
|
|
|
- idx=usr_uart.uart_re_Byte;
|
|
|
|
- }
|
|
|
|
- usr_uart.uart_re_count_array[i]--;
|
|
|
|
- }
|
|
|
|
- data[len]='\0';
|
|
|
|
-
|
|
|
|
- usr_uart.m_uart_rec_func(data);
|
|
|
|
-//#ifdef DEBUG
|
|
|
|
-// printf(data);
|
|
|
|
-// printf("\r\n");
|
|
|
|
-//#endif
|
|
|
|
- usr_uart.uart_re_array[i]=0;
|
|
|
|
- // free(data);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
|
|
+
|
|
|
|
|
|
//串口配置
|
|
//串口配置
|
|
void uart_config(void)
|
|
void uart_config(void)
|
|
@@ -359,32 +436,6 @@ void uart_config(void)
|
|
|
|
|
|
APP_ERROR_CHECK(err_code);
|
|
APP_ERROR_CHECK(err_code);
|
|
}
|
|
}
|
|
-
|
|
|
|
-void set_hex_rec_func(hex_rec_func func)
|
|
|
|
-{
|
|
|
|
- usr_uart.uart_work=UART_HEX;
|
|
|
|
- usr_uart.m_hex_rec_func=func;
|
|
|
|
- usr_uart.hex_pro=false;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-void set_single_hex_rec_func(single_hex_rec_func func)
|
|
|
|
-{
|
|
|
|
- usr_uart.uart_work=UART_HEX;
|
|
|
|
- usr_uart.m_single_hex_rec_func=func;
|
|
|
|
- usr_uart.hex_pro=true;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-void set_string_rec_func(uart_rec_func func)
|
|
|
|
-{
|
|
|
|
- usr_uart.uart_work=UART_STR;
|
|
|
|
- usr_uart.m_uart_rec_func=func;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-void set_terminal_rec_func(uart_rec_func func)
|
|
|
|
-{
|
|
|
|
- usr_uart.uart_work=UART_TERMINAL;
|
|
|
|
- usr_uart.m_uart_rec_func=func;
|
|
|
|
-}
|
|
|
|
|
|
|
|
void uart_open(void)
|
|
void uart_open(void)
|
|
{
|
|
{
|
|
@@ -406,63 +457,20 @@ void uart_close(void)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-static void uart_config_9600(void)
|
|
|
|
-{
|
|
|
|
- uint32_t err_code;
|
|
|
|
-
|
|
|
|
- //定义串口通讯参数配置结构体并初始化
|
|
|
|
- const app_uart_comm_params_t comm_params =
|
|
|
|
- {
|
|
|
|
- rx_pin,//定义uart接收引脚
|
|
|
|
- tx_pin,//定义uart发送引脚
|
|
|
|
- RTS_PIN_NUMBER,//定义uart RTS引脚,流控关闭后虽然定义了RTS和CTS引脚,但是驱动程序会忽略,不会配置这两个引脚,两个引脚仍可作为IO使用
|
|
|
|
- CTS_PIN_NUMBER,//定义uart CTS引脚
|
|
|
|
- APP_UART_FLOW_CONTROL_DISABLED,//关闭uart硬件流控
|
|
|
|
- false,//禁止奇偶检验
|
|
|
|
- 2576384//uart波特率设置为9600bps
|
|
|
|
- };
|
|
|
|
- //初始化串口,注册串口事件回调函数
|
|
|
|
- APP_UART_FIFO_INIT(&comm_params,
|
|
|
|
- UART_RX_BUF_SIZE,
|
|
|
|
- UART_TX_BUF_SIZE,
|
|
|
|
- uart_event_handle,
|
|
|
|
- APP_IRQ_PRIORITY_MID,
|
|
|
|
- err_code);
|
|
|
|
-
|
|
|
|
- APP_ERROR_CHECK(err_code);
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-void uart_open_9600(void)
|
|
|
|
-{
|
|
|
|
- if(usr_uart.uart_init_stat==false)
|
|
|
|
- {
|
|
|
|
- NRF_LOG_INFO("uart for 9600 open!");
|
|
|
|
- uart_config_9600();
|
|
|
|
- usr_uart.uart_init_stat=true;
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
void set_uart_pin(uint32_t tx,uint32_t rx)
|
|
void set_uart_pin(uint32_t tx,uint32_t rx)
|
|
{
|
|
{
|
|
rx_pin=rx;
|
|
rx_pin=rx;
|
|
tx_pin=tx;
|
|
tx_pin=tx;
|
|
}
|
|
}
|
|
|
|
|
|
-static void user_uart_pro(void)
|
|
|
|
-{
|
|
|
|
- if(usr_uart.uart_rx_stat==true)
|
|
|
|
- {
|
|
|
|
- Uart_ReData_Pro();
|
|
|
|
- usr_uart.uart_rx_stat=false;
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
static void user_uart_queue(void *p_event_data, uint16_t event_size)
|
|
static void user_uart_queue(void *p_event_data, uint16_t event_size)
|
|
{
|
|
{
|
|
custome_event *evt = (custome_event*)p_event_data;
|
|
custome_event *evt = (custome_event*)p_event_data;
|
|
if((user_uart_event.flag & (1<<USER_UART_QUEUE_INT))!=0)
|
|
if((user_uart_event.flag & (1<<USER_UART_QUEUE_INT))!=0)
|
|
{
|
|
{
|
|
|
|
+#ifdef UART_STR_USED
|
|
user_uart_pro();
|
|
user_uart_pro();
|
|
|
|
+#endif
|
|
user_uart_event.flag&=(~(1<<USER_UART_QUEUE_INT));
|
|
user_uart_event.flag&=(~(1<<USER_UART_QUEUE_INT));
|
|
}
|
|
}
|
|
if((user_uart_event.flag & (1<<USER_UART_QUEUE_TIME))!=0)
|
|
if((user_uart_event.flag & (1<<USER_UART_QUEUE_TIME))!=0)
|