Browse Source

add check

Chenyingjia 2 years ago
parent
commit
b4f1e0351e
5 changed files with 354 additions and 10 deletions
  1. 106 8
      app/app_chargerpin_conn_detect.c
  2. 217 0
      app/app_one_wire.c
  3. 19 0
      app/app_one_wire.h
  4. 7 0
      app/app_pair_chargerpin.c
  5. 5 2
      app/app_pair_chargerpin.h

+ 106 - 8
app/app_chargerpin_conn_detect.c

@@ -7,6 +7,7 @@
 #include "hal_mt.h"
 #include "app_flash.h"
 #include "app_pair_chargerpin.h"
+#include "app_one_wire.h"
 
 //=================debug=============
 #include "ringframe.h"
@@ -57,7 +58,7 @@ void app_pair_host_uninit(void)
 }
 
 #define DISCON_HOST_MAX_ADC 1200
-#define DISCON_HOST_MIN_ADC 700
+#define DISCON_HOST_MIN_ADC 600
 
 #define CON_HOST_MAX_ADC DISCON_HOST_MIN_ADC
 #define CON_HOST_MIN_ADC 300
@@ -65,7 +66,7 @@ void app_pair_host_uninit(void)
 static void null_pcs(void)
 {
 }
-#define UPPULL_MS 5
+#define UPPULL_MS 3
 static void ReadAdc_timcallback(void *t)
 {
 	if(TIME_GetTicks()-host_ram.pulluppcs_timer<UPPULL_MS)return;
@@ -100,7 +101,19 @@ static void ReadAdc_timcallback(void *t)
 		}
 	}
 }
-
+//-------------------------------------------
+unsigned char shefcheck_buff[5];
+char shefcheck_event_fag=0;
+check_callbackt check_callbackt_ram;
+void shefcheck_event(unsigned char *buff, int length)
+{
+	shefcheck_event_fag=1;
+}
+void check_callback_regist(check_callbackt evt)
+{
+check_callbackt_ram=evt;
+}
+//-------------------------------------------
 static void app_pair_host_process(void)
 {
 	for(int i=1;i>0;i--)
@@ -120,11 +133,32 @@ static void app_pair_host_process(void)
 					app_pair_chargerpin_Init();
 					PAIR_CHARGERPIN_PRINT("mFlash.isHost change %d %d\n",TIME_GetTicks(),mFlash.isHost );
 				}
-//				if (ADC_OP_SUCCESS != ADC_Read(PIN_CHARGING_CHANNEL, &host_ram.adc_value))
-//				{
-//						PAIR_CHARGERPIN_PRINT("ADC_Read ERROR %d\n", host_ram.adc_value);
-//				}
-//				PAIR_CHARGERPIN_PRINT("ADC f(  %d  ):isHost %d Ticks %d\n", host_ram.adc_value, mFlash.isHost,TIME_GetTicks());
+//==============================s
+				if (ADC_OP_SUCCESS != ADC_Read(PIN_CHARGING_CHANNEL, &host_ram.adc_value))
+				{
+						PAIR_CHARGERPIN_PRINT("ADC_Read ERROR %d\n", host_ram.adc_value);
+				}
+				PAIR_CHARGERPIN_PRINT("ADC f(  %d  ):isHost %d Ticks %d\n", host_ram.adc_value, mFlash.isHost,TIME_GetTicks());
+				if(host_ram.adc_value>2800)
+				{
+					if(check_callbackt_ram)
+					{
+						host_ram.statu=11;
+						host_ram.delay_pair_count=TIME_GetTicks();
+						Process_UpdatePeroid(app_pair_host_process,100);
+						Process_SetHoldOn(app_pair_host_process,1);
+						one_byte_receive_init(shefcheck_buff,2,shefcheck_event);
+						shefcheck_event_fag=0;
+						i=2;
+						break;
+					}
+					else
+					{
+						PAIR_CHARGERPIN_PRINT("check_callbackt_ram NULL\n");
+					}
+				}
+//==============================e
+				
 				nrf_gpio_cfg_input(PIN_CHARGING, NRF_GPIO_PIN_PULLUP);
 				PAIR_CHARGERPIN_PRINT("nrf_gpio_cfg_input(PIN_CHARGING, NRF_GPIO_PIN_PULLUP); %d \n",TIME_GetTicks() );
 				host_ram.pulluppcs_timer = TIME_GetTicks();
@@ -238,6 +272,27 @@ static void app_pair_host_process(void)
 					i=3;
 				}
 				break;
+//==============================s				
+			case 11:
+				if((TIME_GetTicks() - host_ram.delay_pair_count > 5000)||(shefcheck_event_fag))
+				{
+					if(shefcheck_event_fag)
+					{
+						if(check_callbackt_ram)check_callbackt_ram(shefcheck_buff[0]);
+					}
+					else 
+					{
+						PAIR_CHARGERPIN_PRINT("  =====================wait low over time %d\n", nrf_gpio_pin_read(PIN_CHARGING));
+					}
+					host_ram.statu=0;
+					Process_UpdatePeroid(app_pair_host_process,ADC_CHECKMS);
+					Process_SetHoldOn(app_pair_host_process,0);
+					one_byte_receive_uninit();
+					
+					i=3;					
+				}
+				break;
+//==============================s
 		}
 	}
 }
@@ -294,6 +349,28 @@ static void app_pair_client_process(void)
 				}
 				log("ad:%d,%d\n",client_ram.adc_value, client_ram.pair_line);
 				PAIR_CHARGERPIN_PRINT("ADC (  %d  ):isHost %d Ticks %d\n", client_ram.adc_value, mFlash.isHost,TIME_GetTicks());
+
+//==============================s				
+				if(client_ram.adc_value>2800)
+				{
+					if(check_callbackt_ram)
+					{
+						client_ram.statu=11;
+						client_ram.delay_pair_count=TIME_GetTicks();
+						Process_UpdatePeroid(app_pair_client_process,100);
+						Process_SetHoldOn(app_pair_client_process,1);
+						one_byte_receive_init(shefcheck_buff,2,shefcheck_event);
+						shefcheck_event_fag=0;
+						i=2;
+						break;
+					}
+					else
+					{
+						PAIR_CHARGERPIN_PRINT("check_callbackt_ram NULL\n");
+					}
+				}
+//==============================e	
+				
 				if(client_ram.adc_value>CONN_MAX_ADC)
 				{
 					PAIR_CHARGERPIN_PRINT("CHARGE\n");
@@ -379,6 +456,27 @@ static void app_pair_client_process(void)
 					i=3;
 				}
 				break;
+//==============================s				
+			case 11:
+				if((TIME_GetTicks() - client_ram.delay_pair_count > 5000)||(shefcheck_event_fag))
+				{
+					if(shefcheck_event_fag)
+					{
+						if(check_callbackt_ram)check_callbackt_ram(shefcheck_buff[0]);
+					}
+					else 
+					{
+						PAIR_CHARGERPIN_PRINT("  =====================wait low over time %d\n", nrf_gpio_pin_read(PIN_CHARGING));
+					}
+					client_ram.statu=0;
+					Process_UpdatePeroid(app_pair_client_process,ADC_CHECKMS);
+					Process_SetHoldOn(app_pair_client_process,0);
+					one_byte_receive_uninit();
+					
+					i=3;					
+				}
+				break;
+//==============================s
 		}
 	}
 }

+ 217 - 0
app/app_one_wire.c

@@ -498,3 +498,220 @@ void chargerpin_one_ms_pcs(void *t)
 
 
 //===========================================================================================================
+
+struct 
+{
+	char statu;
+	unsigned int ms;
+	unsigned int bit_width;
+	int now_bit;
+  char cf_BIT_WIDTH;
+  short tim_cun;
+  int bitindex;
+	int byteindex;
+	int receive_byteslength;
+	unsigned char *buff;
+	unsigned short length;
+	int value ;
+	_Event _evt;
+}one_byte_ram;
+void one_byte_receive_init(unsigned char *recbuff,unsigned short len,_Event evt)
+{
+		nrf_gpio_cfg(
+            PIN_CHARGING,
+            NRF_GPIO_PIN_DIR_OUTPUT,
+            NRF_GPIO_PIN_INPUT_CONNECT,
+            NRF_GPIO_PIN_NOPULL,
+            NRF_GPIO_PIN_D0H1,
+            NRF_GPIO_PIN_NOSENSE);
+        nrf_gpio_cfg_watcher(PIN_CHARGING);
+        one_byte_ram.statu = 1;
+        nrf_gpio_pin_clear(PIN_CHARGING);
+	
+	one_byte_ram.now_bit = nrf_gpio_pin_read(PIN_CHARGING);
+    //这里应该高电平进入
+	one_byte_ram.bit_width=0;
+	one_byte_ram.cf_BIT_WIDTH=30;
+	
+	one_byte_ram.buff=recbuff;
+	one_byte_ram.length=len;
+	one_byte_ram._evt=evt;
+	
+  Process_Start(0, "null_pcs", null_pcs);
+	Process_SetHoldOn(null_pcs, 1);
+	TIME_Regist(one_byte_receive_pcs);
+}
+void one_byte_receive_uninit(void)
+{
+	Process_Stop(null_pcs);
+	TIME_UnRegist(one_byte_receive_pcs);
+	PAIR_CHARGERPIN_PRINT("-------------------------------------------chargerpin_one_ms_uninit.%d\r\n", 1);
+}
+void one_byte_receive_pcs(void*t)
+{
+	for(int i=1;i>0;i--)
+	{
+		switch(one_byte_ram.statu)
+		{
+			case 1://等待完整的开始信号
+				if (one_byte_ram.now_bit == nrf_gpio_pin_read(PIN_CHARGING))
+				{
+					one_byte_ram.bit_width++;
+				}
+				else
+				{
+					//由高电平切换到低电平,下降信号,下降沿
+					if(one_byte_ram.now_bit==1)
+					{
+						one_byte_ram.now_bit=0;
+					}
+					else//上升沿
+					{
+							if((one_byte_ram.bit_width > 1.5*one_byte_ram.cf_BIT_WIDTH-5)&&(one_byte_ram.bit_width < 1.5*one_byte_ram.cf_BIT_WIDTH+5))
+							{
+									//已经收到1.5个位宽低电平的开始信号
+									one_byte_ram.tim_cun=-1.5*one_byte_ram.cf_BIT_WIDTH+1;//第一个数据位开始的时刻,该变量的值为0
+									one_byte_ram.statu=2;
+									PAIR_CHARGERPIN_PRINT(" into receive mode %d;\r\n",one_byte_ram.tim_cun);
+							}
+							one_byte_ram.now_bit=1;						
+					}
+					one_byte_ram.bit_width=0;
+				}
+				break;
+			case 2:
+				one_byte_ram.tim_cun++;
+				if(one_byte_ram.tim_cun==0)
+				{
+					one_byte_ram.statu=3;
+					PAIR_CHARGERPIN_PRINT("one_byte_ram.tim_cun==0;%d\r\n",nrf_gpio_pin_read(PIN_CHARGING));
+					i=2;
+					one_byte_ram.value=0;
+				}
+				break;
+			case 3:
+					if(one_byte_ram.tim_cun>(one_byte_ram.length)*8*one_byte_ram.cf_BIT_WIDTH + 4*one_byte_ram.cf_BIT_WIDTH)//接收超时判断
+					{
+						PAIR_CHARGERPIN_PRINT("one_byte_ram receive overtime; %d \r\n",(one_byte_ram.length+1)*one_byte_ram.cf_BIT_WIDTH);
+						one_byte_ram.statu=1;
+					}
+				
+					if((one_byte_ram.tim_cun % (one_byte_ram.cf_BIT_WIDTH-1)==0)&&(one_byte_ram.tim_cun>0))
+					{
+							one_byte_ram.bitindex=one_byte_ram.tim_cun/one_byte_ram.cf_BIT_WIDTH;
+							one_byte_ram.byteindex=one_byte_ram.bitindex/8;
+							one_byte_ram.bitindex=one_byte_ram.bitindex%8;
+							if(one_byte_ram.byteindex<one_byte_ram.length)
+							{
+								PAIR_CHARGERPIN_PRINT("%d %d %3d %d\r\n", one_byte_ram.bitindex,one_byte_ram.byteindex,one_byte_ram.value,one_byte_ram.value > 0);
+								if (one_byte_ram.value > 0)
+								{
+										one_byte_ram.buff[one_byte_ram.byteindex] |= 0x01 << one_byte_ram.bitindex;
+								}
+								else
+								{
+										one_byte_ram.buff[one_byte_ram.byteindex] &= ~(0x01 << one_byte_ram.bitindex);
+								}							
+							}
+							else if((one_byte_ram.bitindex==0)&&(one_byte_ram.byteindex==one_byte_ram.length))
+							{
+								//数据位接收完成
+								PAIR_CHARGERPIN_PRINT(" data receive done length : %d \r\n data :",one_byte_ram.length);
+								for (int k = 0; k < one_byte_ram.length; k++)
+								{
+										PAIR_CHARGERPIN_PRINT("%x ",one_byte_ram.buff[k]);
+								}
+								PAIR_CHARGERPIN_PRINT("\r\n");
+							}
+
+							one_byte_ram.value=0;
+					}
+					else
+					{
+							if(nrf_gpio_pin_read(PIN_CHARGING)==0)
+							{
+								one_byte_ram.value--;
+							}
+							else 
+							{
+								one_byte_ram.value++;							
+							}
+					}
+					
+					if (one_byte_ram.now_bit == nrf_gpio_pin_read(PIN_CHARGING))
+					{
+						one_byte_ram.bit_width++;
+					}
+					else
+					{
+						
+						//由高电平切换到低电平,下降信号,下降沿
+						if(one_byte_ram.now_bit==1)
+						{
+							if((one_byte_ram.bit_width > 1.5*one_byte_ram.cf_BIT_WIDTH-5)&&(one_byte_ram.bit_width < 1.5*one_byte_ram.cf_BIT_WIDTH+5))
+							{
+								if(one_byte_ram._evt)one_byte_ram._evt(one_byte_ram.buff,one_byte_ram.byteindex);
+								PAIR_CHARGERPIN_PRINT("  one_byte_ram._evt  \r\n");
+								PAIR_CHARGERPIN_PRINT("  receive done tim %d; %d\r\n",one_byte_ram.tim_cun,one_byte_ram.bit_width);
+								one_byte_ram.statu=1;
+							}
+							one_byte_ram.now_bit=0;						
+						}
+						else//上升沿
+						{
+							one_byte_ram.now_bit=1;						
+						}						
+						one_byte_ram.bit_width=0;
+					}
+					one_byte_ram.tim_cun++;
+					break;
+			default:
+					break;
+		}
+	}
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+ 19 - 0
app/app_one_wire.h

@@ -6,4 +6,23 @@ void chargerpin_one_ms_init(_Event success_evt);
 void chargerpin_one_ms_pcs(void *t);
 void chargerpin_one_ms_uninit(void);
 
+void one_byte_receive_pcs(void*t);
+void one_byte_receive_init(unsigned char *recbuff,unsigned short len,_Event evt);
+void one_byte_receive_uninit(void);
 #endif
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+ 7 - 0
app/app_pair_chargerpin.c

@@ -336,8 +336,15 @@ void over_event(void)
 	pair_done_pcs();
 }
 
+void anksjhas(char sduh)
+{
+
+}
+
 void app_pair_chargerpin_Init(void)
 {
+//	check_callback_regist(anksjhas);
+//	mFlash.isHost=1;
 	if(mFlash.isHost!=HOST_SHOSE)
 		app_pair_client_init(into_event,over_event);
 	if(mFlash.isHost==HOST_SHOSE)

+ 5 - 2
app/app_pair_chargerpin.h

@@ -13,7 +13,7 @@
 
 // <q> PAIR_INFO_EN  - µ÷ÊÔÐÅÏ¢
 #ifndef PAIR_CHARGERPIN_INFO_EN
-#define PAIR_CHARGERPIN_INFO_EN 0
+#define PAIR_CHARGERPIN_INFO_EN 1
 #endif
 #if PAIR_CHARGERPIN_INFO_EN
 #define PAIR_CHARGERPIN_INFO(...) SEGGER_RTT_printf(0, __VA_ARGS__)
@@ -26,8 +26,11 @@
 typedef void (*Event)(void);
 void app_pair_chargerpin_Init(void);
 
+typedef void (*check_callbackt)(char);
+void check_callback_regist(check_callbackt evt);
+
 #define PAIR_START_REGISTER(_p_handler) 	__attribute__((section("pair_start"))) void* const main_init_##_p_handler##_row = _p_handler  
 	
 #define PAIR_DONE_REGISTER(_p_handler) 	__attribute__((section("pair_done"))) void* const main_init_##_p_handler##_row = _p_handler  
-
+	
 #endif