⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 trab_fkt.c

📁 嵌入式试验箱S3C2410的bootloader源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
	return 1;                 /* not "tl", nor "dr", so return error */}#ifdef CONFIG_TOUCH_WAIT_PRESSEDstatic void touch_wait_pressed (void){	while (!(tsc2000_read(TSC2000_REG_ADC) & TC_PSM));}#elsestatic int touch_check_pressed (void){	return (tsc2000_read(TSC2000_REG_ADC) & TC_PSM);}#endif /* CONFIG_TOUCH_WAIT_PRESSED */static int touch_write_clibration_values (int calib_point, int x, int y){#if (CONFIG_COMMANDS & CFG_CMD_I2C)	int x_verify = 0;	int y_verify = 0;	tsc2000_reg_init ();	if (calib_point == CALIB_TL) {		if (i2c_write_multiple (I2C_EEPROM_DEV_ADDR, TOUCH_X0, 1,			       (unsigned char *)&x, 2)) {			return 1;		}		if (i2c_write_multiple (I2C_EEPROM_DEV_ADDR, TOUCH_Y0, 1,			       (unsigned char *)&y, 2)) {			return 1;		}		/* verify written values */		if (i2c_read_multiple (I2C_EEPROM_DEV_ADDR, TOUCH_X0, 1,			      (unsigned char *)&x_verify, 2)) {			return 1;		}		if (i2c_read_multiple (I2C_EEPROM_DEV_ADDR, TOUCH_Y0, 1,			       (unsigned char *)&y_verify, 2)) {			return 1;		}		if ((y != y_verify) || (x != x_verify)) {			print_identifier ();			printf ("error: verify error\n");			return 1;		}		return 0;       /* no error */	}	else if (calib_point == CALIB_DR) {		  if (i2c_write_multiple (I2C_EEPROM_DEV_ADDR, TOUCH_X1, 1,			       (unsigned char *)&x, 2)) {			return 1;		  }		if (i2c_write_multiple (I2C_EEPROM_DEV_ADDR, TOUCH_Y1, 1,			       (unsigned char *)&y, 2)) {			return 1;		}		/* verify written values */		if (i2c_read_multiple (I2C_EEPROM_DEV_ADDR, TOUCH_X1, 1,				       (unsigned char *)&x_verify, 2)) {			return 1;		}		if (i2c_read_multiple (I2C_EEPROM_DEV_ADDR, TOUCH_Y1, 1,			       (unsigned char *)&y_verify, 2)) {			return 1;		}		if ((y != y_verify) || (x != x_verify)) {			print_identifier ();			printf ("error: verify error\n");			return 1;		}		return 0;	}	return 1;#else	printf ("No I2C support enabled (CFG_CMD_I2C), could not write "		"to EEPROM\n");	return (1);#endif /* CFG_CMD_I2C */}static void touch_read_x_y (int *px, int *py){	tsc2000_write(TSC2000_REG_ADC, DEFAULT_ADC | TC_AD0 | TC_AD1);	adc_wait_conversion_done();	*px = tsc2000_read(TSC2000_REG_X);	tsc2000_write(TSC2000_REG_ADC, DEFAULT_ADC | TC_AD2);	adc_wait_conversion_done();	*py = tsc2000_read(TSC2000_REG_Y);}int do_rs485 (char **argv){	int timeout;	char data[RS485_MAX_RECEIVE_BUF_LEN];	if (strcmp (argv[2], "send") == 0) {		return (rs485_send_line (argv[3]));	}	else if (strcmp (argv[2], "receive") == 0) {		timeout = simple_strtoul(argv[3], NULL, 10);		if (rs485_receive_chars (data, timeout) != 0) {			print_identifier ();			printf ("## nothing received\n");			return (1);		}		else {			print_identifier ();			printf ("%s\n", data);			return (0);		}	}	printf ("%s: unknown command %s\n", __FUNCTION__, argv[2]);	return (1);             /* unknown command, return error */}static int rs485_send_line (const char *data){	rs485_init ();	trab_rs485_enable_tx ();	rs485_puts (data);	rs485_putc ('\n');	return (0);}static int rs485_receive_chars (char *data, int timeout){	int i;	int receive_count = 0;	rs485_init ();	trab_rs485_enable_rx ();	/* test every 1 ms for received characters to avoid a receive FIFO	 * overrun (@ 38.400 Baud) */	for (i = 0; i < (timeout * 1000); i++) {		while (rs485_tstc ()) {			if (receive_count >= RS485_MAX_RECEIVE_BUF_LEN-1)				break;			*data++ = rs485_getc ();			receive_count++;		}		udelay (1000);  /* pause 1 ms */	}	*data = '\0';           /* terminate string */	if (receive_count == 0)		return (1);	else		return (0);}int do_serial_number (char **argv){#if (CONFIG_COMMANDS & CFG_CMD_I2C)	unsigned int serial_number;	if (strcmp (argv[2], "read") == 0) {		if (i2c_read (I2C_EEPROM_DEV_ADDR, SERIAL_NUMBER, 1,			      (unsigned char *)&serial_number, 4)) {			printf ("could not read from eeprom\n");			return (1);		}		print_identifier ();		printf ("%08d\n", serial_number);		return (0);	}	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,			      (unsigned char *)&serial_number, 4)) {			printf ("could not write to eeprom\n");			return (1);		}		return (0);	}	printf ("%s: unknown command %s\n", __FUNCTION__, argv[2]);	return (1);             /* unknown command, return error */#else	printf ("No I2C support enabled (CFG_CMD_I2C), could not write "		"to EEPROM\n");	return (1);#endif /* CFG_CMD_I2C */}int do_crc16 (void){#if (CONFIG_COMMANDS & CFG_CMD_I2C)	int crc;	unsigned char buf[EEPROM_MAX_CRC_BUF];	if (i2c_read (I2C_EEPROM_DEV_ADDR, 0, 1, buf, 60)) {		printf ("could not read from eeprom\n");		return (1);	}	crc = 0;                /* start value of crc calculation */	crc = updcrc (crc, buf, 60);	print_identifier ();	printf ("crc16=%#04x\n", crc);	if (i2c_write (I2C_EEPROM_DEV_ADDR, CRC16, 1, (unsigned char *)&crc,		       sizeof (crc))) {		printf ("could not read from eeprom\n");		return (1);	}	return (0);#else	printf ("No I2C support enabled (CFG_CMD_I2C), could not write "		"to EEPROM\n");	return (1);#endif /* CFG_CMD_I2C */}/* * Calculate, intelligently, the CRC of a dataset incrementally given a * buffer full at a time. * Initialize crc to 0 for XMODEM, -1 for CCITT. * * Usage: *   newcrc = updcrc( oldcrc, bufadr, buflen ) *        unsigned int oldcrc, buflen; *        char *bufadr; * * Compile with -DTEST to generate program that prints CRC of stdin to stdout. * Compile with -DMAKETAB to print values for crctab to stdout */    /* the CRC polynomial. This is used by XMODEM (almost CCITT).     * If you change P, you must change crctab[]'s initial value to what is     * printed by initcrctab()     */#define   P    0x1021    /* number of bits in CRC: don't change it. */#define W 16    /* this the number of bits per char: don't change it. */#define B 8static unsigned short crctab[1<<B] = { /* as calculated by initcrctab() */    0x0000,  0x1021,  0x2042,  0x3063,  0x4084,  0x50a5,  0x60c6,  0x70e7,    0x8108,  0x9129,  0xa14a,  0xb16b,  0xc18c,  0xd1ad,  0xe1ce,  0xf1ef,    0x1231,  0x0210,  0x3273,  0x2252,  0x52b5,  0x4294,  0x72f7,  0x62d6,    0x9339,  0x8318,  0xb37b,  0xa35a,  0xd3bd,  0xc39c,  0xf3ff,  0xe3de,    0x2462,  0x3443,  0x0420,  0x1401,  0x64e6,  0x74c7,  0x44a4,  0x5485,    0xa56a,  0xb54b,  0x8528,  0x9509,  0xe5ee,  0xf5cf,  0xc5ac,  0xd58d,    0x3653,  0x2672,  0x1611,  0x0630,  0x76d7,  0x66f6,  0x5695,  0x46b4,    0xb75b,  0xa77a,  0x9719,  0x8738,  0xf7df,  0xe7fe,  0xd79d,  0xc7bc,    0x48c4,  0x58e5,  0x6886,  0x78a7,  0x0840,  0x1861,  0x2802,  0x3823,    0xc9cc,  0xd9ed,  0xe98e,  0xf9af,  0x8948,  0x9969,  0xa90a,  0xb92b,    0x5af5,  0x4ad4,  0x7ab7,  0x6a96,  0x1a71,  0x0a50,  0x3a33,  0x2a12,    0xdbfd,  0xcbdc,  0xfbbf,  0xeb9e,  0x9b79,  0x8b58,  0xbb3b,  0xab1a,    0x6ca6,  0x7c87,  0x4ce4,  0x5cc5,  0x2c22,  0x3c03,  0x0c60,  0x1c41,    0xedae,  0xfd8f,  0xcdec,  0xddcd,  0xad2a,  0xbd0b,  0x8d68,  0x9d49,    0x7e97,  0x6eb6,  0x5ed5,  0x4ef4,  0x3e13,  0x2e32,  0x1e51,  0x0e70,    0xff9f,  0xefbe,  0xdfdd,  0xcffc,  0xbf1b,  0xaf3a,  0x9f59,  0x8f78,    0x9188,  0x81a9,  0xb1ca,  0xa1eb,  0xd10c,  0xc12d,  0xf14e,  0xe16f,    0x1080,  0x00a1,  0x30c2,  0x20e3,  0x5004,  0x4025,  0x7046,  0x6067,    0x83b9,  0x9398,  0xa3fb,  0xb3da,  0xc33d,  0xd31c,  0xe37f,  0xf35e,    0x02b1,  0x1290,  0x22f3,  0x32d2,  0x4235,  0x5214,  0x6277,  0x7256,    0xb5ea,  0xa5cb,  0x95a8,  0x8589,  0xf56e,  0xe54f,  0xd52c,  0xc50d,    0x34e2,  0x24c3,  0x14a0,  0x0481,  0x7466,  0x6447,  0x5424,  0x4405,    0xa7db,  0xb7fa,  0x8799,  0x97b8,  0xe75f,  0xf77e,  0xc71d,  0xd73c,    0x26d3,  0x36f2,  0x0691,  0x16b0,  0x6657,  0x7676,  0x4615,  0x5634,    0xd94c,  0xc96d,  0xf90e,  0xe92f,  0x99c8,  0x89e9,  0xb98a,  0xa9ab,    0x5844,  0x4865,  0x7806,  0x6827,  0x18c0,  0x08e1,  0x3882,  0x28a3,    0xcb7d,  0xdb5c,  0xeb3f,  0xfb1e,  0x8bf9,  0x9bd8,  0xabbb,  0xbb9a,    0x4a75,  0x5a54,  0x6a37,  0x7a16,  0x0af1,  0x1ad0,  0x2ab3,  0x3a92,    0xfd2e,  0xed0f,  0xdd6c,  0xcd4d,  0xbdaa,  0xad8b,  0x9de8,  0x8dc9,    0x7c26,  0x6c07,  0x5c64,  0x4c45,  0x3ca2,  0x2c83,  0x1ce0,  0x0cc1,    0xef1f,  0xff3e,  0xcf5d,  0xdf7c,  0xaf9b,  0xbfba,  0x8fd9,  0x9ff8,    0x6e17,  0x7e36,  0x4e55,  0x5e74,  0x2e93,  0x3eb2,  0x0ed1,  0x1ef0    };static unsigned short updcrc(unsigned short icrc, unsigned char *icp,			     unsigned int icnt ){	register unsigned short crc = icrc;	register unsigned char *cp = icp;	register unsigned int cnt = icnt;	while (cnt--)		crc = (crc<<B) ^ crctab[(crc>>(W-B)) ^ *cp++];	return (crc);}int do_gain (char **argv){	int range;	range = simple_strtoul (argv[2], NULL, 10);	if ((range < 1) || (range > 3))	{		printf ("%s: invalid parameter %s\n", __FUNCTION__, argv[2]);		return 1;	}	tsc2000_set_range (range);	return (0);}int do_eeprom (char **argv){#if (CONFIG_COMMANDS & CFG_CMD_I2C)	if (strcmp (argv[2], "read") == 0) {		return (trab_eeprom_read (argv));	}	else if (strcmp (argv[2], "write") == 0) {		return (trab_eeprom_write (argv));	}	printf ("%s: invalid parameter %s\n", __FUNCTION__, argv[2]);	return (1);#else	printf ("No I2C support enabled (CFG_CMD_I2C), could not write "		"to EEPROM\n");	return (1);#endif /* CFG_CMD_I2C */}#if (CONFIG_COMMANDS & CFG_CMD_I2C)static int trab_eeprom_read (char **argv){	int i;	int len;	unsigned int addr;	long int value = 0;	uchar *buffer;	buffer = (uchar *) &value;	addr = simple_strtoul (argv[3], NULL, 10);	addr &= 0xfff;	len = simple_strtoul (argv[4], NULL, 10);	if ((len < 1) || (len > 4)) {		printf ("%s: invalid parameter %s\n", __FUNCTION__,			argv[4]);		return (1);	}	for (i = 0; i < len; i++) {		if (i2c_read (I2C_EEPROM_DEV_ADDR, addr+i, 1, buffer+i, 1)) {			printf ("%s: could not read from i2c device %#x"				", addr %d\n", __FUNCTION__,				I2C_EEPROM_DEV_ADDR, addr);			return (1);		}	}	print_identifier ();	if (strcmp (argv[5], "-") == 0) {		if (len == 1)			printf ("%d\n", (signed char) value);		else if (len == 2)			printf ("%d\n", (signed short int) value);		else			printf ("%ld\n", value);	}	else {		if (len == 1)			printf ("%d\n", (unsigned char) value);		else if (len == 2)			printf ("%d\n", (unsigned short int) value);		else			printf ("%ld\n", (unsigned long int) value);	}	return (0);}static int trab_eeprom_write (char **argv){	int i;	int len;	unsigned int addr;	long int value = 0;	uchar *buffer;	buffer = (uchar *) &value;	addr = simple_strtoul (argv[3], NULL, 10);	addr &= 0xfff;	len = simple_strtoul (argv[4], NULL, 10);	if ((len < 1) || (len > 4)) {		printf ("%s: invalid parameter %s\n", __FUNCTION__,			argv[4]);		return (1);	}	value = simple_strtol (argv[5], NULL, 10);	debug ("value=%ld\n", value);	for (i = 0; i < len; i++) {		if (i2c_write (I2C_EEPROM_DEV_ADDR, addr+i, 1, buffer+i, 1)) {			printf ("%s: could not write to i2c device %d"				", addr %d\n", __FUNCTION__,				I2C_EEPROM_DEV_ADDR, addr);			return (1);		}#if 0		printf ("chip=%#x, addr+i=%#x+%d=%p, alen=%d, *buffer+i="			"%#x+%d=%p=%#x \n",I2C_EEPROM_DEV_ADDR_DEV_ADDR , addr,			i, addr+i, 1, buffer, i, buffer+i, *(buffer+i));#endif		udelay (30000); /* wait for EEPROM ready */	}	return (0);}int i2c_write_multiple (uchar chip, uint addr, int alen,			uchar *buffer, int len){	int i;	if (alen != 1) {		printf ("%s: addr len other than 1 not supported\n",			 __FUNCTION__);		return (1);	}	for (i = 0; i < len; i++) {		if (i2c_write (chip, addr+i, alen, buffer+i, 1)) {			printf ("%s: could not write to i2c device %d"				 ", addr %d\n", __FUNCTION__, chip, addr);			return (1);		}#if 0		printf ("chip=%#x, addr+i=%#x+%d=%p, alen=%d, *buffer+i="			"%#x+%d=%p=\"%.1s\"\n", chip, addr, i, addr+i,			alen, buffer, i, buffer+i, buffer+i);#endif		udelay (30000);	}	return (0);}int i2c_read_multiple ( uchar chip, uint addr, int alen,			uchar *buffer, int len){	int i;	if (alen != 1) {		printf ("%s: addr len other than 1 not supported\n",			 __FUNCTION__);		return (1);	}	for (i = 0; i < len; i++) {		if (i2c_read (chip, addr+i, alen, buffer+i, 1)) {			printf ("%s: could not read from i2c device %#x"				 ", addr %d\n", __FUNCTION__, chip, addr);			return (1);		}	}	return (0);}#endif /* CFG_CMD_I2C */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -