Explorar o código

去掉cs1180死等ready,确保cs1180有问题的时候,不会wdog复位

Signed-off-by: huhui <huhui@sharkgulf.com>
huhui %!s(int64=5) %!d(string=hai) anos
pai
achega
a3e3437848
Modificáronse 1 ficheiros con 38 adicións e 17 borrados
  1. 38 17
      Application/bsp/cs1180.c

+ 38 - 17
Application/bsp/cs1180.c

@@ -75,6 +75,25 @@ static void cs1180_dumy_read(){
 	spi_read_reg(0x0, data, 16);
 	cs1180_cs(1);
 }
+static int cs1180_wait_ready(int ms){
+	u64 now = shark_get_mseconds();
+	while (IS_CS1180_NOT_READY()){
+		if (shark_get_mseconds() - now > ms) {
+			return 0;
+		}
+	}
+	return 1;
+}
+
+static int cs1180_wait_not_ready(int ms){
+	u64 now = shark_get_mseconds();
+	while (IS_CS1180_NOT_READY()){
+		if (shark_get_mseconds() - now > ms) {
+			return 0;
+		}
+	}
+	return 1;
+}
 
 
 /* 对芯片的偏移误差和增益误差进行纠正 */
@@ -84,10 +103,10 @@ __attribute__((unused)) static void cs1180_self_calibrate(void)
 	cs1180_send_cmd(CS1180_CALSELF);
 	cs1180_cs(1);
 	/* wait calibrate finished */
-	while (IS_CS1180_NOT_READY());
-	while (!IS_CS1180_NOT_READY());
+	cs1180_wait_ready(10);
+	cs1180_wait_not_ready(10);
 	delay_us(33 * 1000);
-	while (IS_CS1180_NOT_READY()); //drop first data
+	cs1180_wait_ready(10); //drop first data
 }
 
 /* 对芯片的偏移误差进行纠正 */
@@ -97,10 +116,10 @@ __attribute__((unused)) static void cs1180_self_offset_calibrate(void)
 	cs1180_send_cmd(CS1180_OCALSELF);
 	cs1180_cs(1);
 	/* wait calibrate finished */
-	while (IS_CS1180_NOT_READY());
-	while (!IS_CS1180_NOT_READY());
+	cs1180_wait_ready(10);
+	cs1180_wait_not_ready(10);
 	delay_us(33 * 1000);
-	while (IS_CS1180_NOT_READY()); //drop first data
+	cs1180_wait_ready(10); //drop first data
 
 }
 
@@ -111,10 +130,10 @@ __attribute__((unused)) static void cs1180_self_gain_calibrate(void)
 	cs1180_send_cmd(CS1180_SLFGCAL);
 	cs1180_cs(1);
 	/* wait calibrate finished */
-	while (IS_CS1180_NOT_READY());
-	while (!IS_CS1180_NOT_READY());
+	cs1180_wait_ready(10);
+	cs1180_wait_not_ready(10);
 	delay_us(33 * 1000);
-	while (IS_CS1180_NOT_READY()); //drop first data
+	cs1180_wait_ready(10); //drop first data
 
 }
 
@@ -127,10 +146,10 @@ __attribute__((unused)) static void cs1180_sys_offset_calibrate(void)
 	cs1180_cs(1);
 	/* wait calibrate finished */
 	delay_us(20);
-	while (IS_CS1180_NOT_READY());
-	while (!IS_CS1180_NOT_READY());
+	cs1180_wait_ready(10);
+	cs1180_wait_not_ready(10);
 	delay_us(33 * 1000);
-	while (IS_CS1180_NOT_READY()); //drop first data	
+	cs1180_wait_ready(10); //drop first data	
 }
 
 /* 对系统的增益误差进行纠正,必须输入正满幅度的电压, SP700,SP600未提供满辐电压,故这一项不做 */
@@ -140,10 +159,10 @@ __attribute__((unused)) static void cs1180_sys_gain_calibrate(void)
 	cs1180_send_cmd(CS1180_GCALSYS);
 	cs1180_cs(1);
 	/* wait calibrate finished */
-	while (IS_CS1180_NOT_READY());
-	while (!IS_CS1180_NOT_READY());
+	cs1180_wait_ready(10);
+	cs1180_wait_not_ready(10);
 	delay_us(33 * 1000);
-	while (IS_CS1180_NOT_READY()); //drop first data
+	cs1180_wait_ready(10); //drop first data
 
 }
 
@@ -346,8 +365,10 @@ float cs1180_adc_sample(int *valide)
 	static int cs1180_low_ff_count = 0;
 	uint8_t data[3] = {0,0,0};
 	int a = 0;
-	while (IS_CS1180_NOT_READY()); //当drdy 为高时,不读取数据
-
+	if (cs1180_wait_ready(35) == 0) { //当drdy 为高时,不读取数据
+		*valide = 0;
+		return 0.0f;
+	}
 #if 0
 	int retry = 5;
 	while(retry-- >= 0) {