Add features to TRAB board standalone test application.

- add "touch read" command
- the crc16 command now verifies the crc value written to the EEPROM
- use i2c_write_multiple() instead of i2c_write(), because i2c_write_mulitple()
  waites for the EEPROM to finish its write cycle

Signed-off-by Martin Krause <martin.krause@tqs.de>

---
commit e1bbb03deb546abcb226ee64adef40015a75c6f3
tree 0edce03aef2f9daec207a4bb7a8d37f43ac399c3
parent 686ad3009fb839ea8b3243f5b2d96cf91bc4eb3a
author Martin Krause <mkr@tq-sewsrv-4.tq-net.de> Mon, 19 Jun 2006 09:49:46 +0200
committer Martin Krause <mkr@tq-sewsrv-4.tq-net.de> Mon, 19 Jun 2006 09:49:46 +0200

 board/trab/trab_fkt.c |  106 +++++++++++++++++++++++++------------------------
 1 files changed, 55 insertions(+), 51 deletions(-)

diff --git a/board/trab/trab_fkt.c b/board/trab/trab_fkt.c
index abb3b29..b6e7de4 100644
--- a/board/trab/trab_fkt.c
+++ b/board/trab/trab_fkt.c
@@ -142,7 +142,7 @@ static int touch_check_pressed (void);
 #endif /* CONFIG_TOUCH_WAIT_PRESSED */
 
 static void touch_read_x_y (int *x, int *y);
-static int touch_write_clibration_values (int calib_point, int x, int y);
+static int touch_write_calibration_values (int calib_point, int x, int y);
 static int rs485_send_line (const char *data);
 static int rs485_receive_chars (char *data, int timeout);
 static unsigned short updcrc(unsigned short icrc, unsigned char *icp,
@@ -888,59 +888,45 @@ int do_thermo (char **argv)
 int do_touch (char **argv)
 {
 	int     x, y;
+	int	rc = 0;
+
+	if ( !((strcmp (argv[2], "tl") == 0) ||
+	       (strcmp (argv[2], "dr") == 0) ||
+	       (strcmp (argv[2], "read") == 0)))
+	{
+		printf ("invalid parameter %s\n", argv[2]);
+		return 1;
+	}
 
-	if (strcmp (argv[2], "tl") == 0) {
 #ifdef CONFIG_TOUCH_WAIT_PRESSED
-		touch_wait_pressed();
+	touch_wait_pressed();
 #else
-		{
-			int i;
-			for (i = 0; i < (TOUCH_TIMEOUT * 1000); i++) {
-				if (touch_check_pressed ()) {
-					break;
-				}
-				udelay (1000);  /* pause 1 ms */
+	{
+		int i;
+		for (i = 0; i < (TOUCH_TIMEOUT * 1000); i++) {
+			if (touch_check_pressed ()) {
+				break;
 			}
+			udelay (1000);  /* pause 1 ms */
 		}
-		if (!touch_check_pressed()) {
-			print_identifier ();
-			printf ("error: touch not pressed\n");
-			return 1;
-		}
-#endif /* CONFIG_TOUCH_WAIT_PRESSED */
-		touch_read_x_y (&x, &y);
-
+	}
+	if (!touch_check_pressed()) {
 		print_identifier ();
-		printf ("x=%d y=%d\n", x, y);
-		return touch_write_clibration_values (CALIB_TL, x, y);
+		printf ("error: touch not pressed\n");
+		return 1;
 	}
-	else if (strcmp (argv[2], "dr") == 0) {
-#ifdef CONFIG_TOUCH_WAIT_PRESSED
-		touch_wait_pressed();
-#else
-		{
-			int i;
-			for (i = 0; i < (TOUCH_TIMEOUT * 1000); i++) {
-				if (touch_check_pressed ()) {
-					break;
-				}
-				udelay (1000);  /* pause 1 ms */
-			}
-		}
-		if (!touch_check_pressed()) {
-			print_identifier ();
-			printf ("error: touch not pressed\n");
-			return 1;
-		}
 #endif /* CONFIG_TOUCH_WAIT_PRESSED */
-		touch_read_x_y (&x, &y);
+	touch_read_x_y (&x, &y);
 
-		print_identifier ();
-		printf ("x=%d y=%d\n", x, y);
+	print_identifier ();
+	printf ("x=%d y=%d\n", x, y);
 
-		return touch_write_clibration_values (CALIB_DR, x, y);
-	}
-	return 1;                 /* not "tl", nor "dr", so return error */
+	if (strcmp (argv[2], "tl") == 0)
+		rc = touch_write_calibration_values (CALIB_TL, x, y);
+	else if (strcmp (argv[2], "dr") == 0)
+		rc = touch_write_calibration_values (CALIB_DR, x, y);
+
+	return rc;
 }
 
 
@@ -957,7 +943,7 @@ static int touch_check_pressed (void)
 }
 #endif /* CONFIG_TOUCH_WAIT_PRESSED */
 
-static int touch_write_clibration_values (int calib_point, int x, int y)
+static int touch_write_calibration_values (int calib_point, int x, int y)
 {
 #if (CONFIG_COMMANDS & CFG_CMD_I2C)
 	int x_verify = 0;
@@ -1120,8 +1106,8 @@ #if (CONFIG_COMMANDS & CFG_CMD_I2C)
 	}
 	else if (strcmp (argv[2], "write") == 0) {
 		serial_number = simple_strtoul(argv[3], NULL, 10);
-		if (i2c_write (I2C_EEPROM_DEV_ADDR, SERIAL_NUMBER, 1,
-			      (char *)&serial_number, 4)) {
+		if (i2c_write_multiple (I2C_EEPROM_DEV_ADDR, SERIAL_NUMBER, 1,
+					(char *)&serial_number, 4)) {
 			printf ("could not write to eeprom\n");
 			return (1);
 		}
@@ -1142,6 +1128,7 @@ int do_crc16 (void)
 #if (CONFIG_COMMANDS & CFG_CMD_I2C)
 	int crc;
 	char buf[EEPROM_MAX_CRC_BUF];
+	int crc_verify = 0;
 
 	if (i2c_read (I2C_EEPROM_DEV_ADDR, 0, 1, buf, 60)) {
 		printf ("could not read from eeprom\n");
@@ -1153,12 +1140,29 @@ #if (CONFIG_COMMANDS & CFG_CMD_I2C)
 	print_identifier ();
 	printf ("crc16=%#04x\n", crc);
 
-	if (i2c_write (I2C_EEPROM_DEV_ADDR, CRC16, 1, (char *)&crc,
-		       sizeof (crc))) {
-		printf ("could not read from eeprom\n");
+	if (i2c_write_multiple (I2C_EEPROM_DEV_ADDR, CRC16, 1, (char *)&crc,
+				sizeof (crc))) {
+		printf ("could not write to eeprom\n");
 		return (1);
 	}
-	return (0);
+	/* verify written values */
+	if (i2c_read_multiple (I2C_EEPROM_DEV_ADDR, CRC16, 1,
+			       (char *)&crc_verify, 2)) {
+		return 1;
+	}
+
+	print_identifier ();
+	if (crc == crc_verify)
+	{
+		printf ("OK\n");
+		return 0;
+	} else 	{
+		printf ("error: verify error\n");
+		return 1;
+	}
+
+	/* should not be reached */
+	return (1);
 #else
 	printf ("No I2C support enabled (CFG_CMD_I2C), could not write "
 		"to EEPROM\n");
