Example #1
0
File: mapped.c Project: nhanh0/hah
/* This is ment to be called on the flash window once it is in jedec mode */
int isjedec(unsigned long base)
{
   // Test #1, JEDEC numbers are readable from 0x??00/0x??01
   if (readb(base + 0) != readb(base + 0x100) || 
       readb(base + 1) != readb(base + 0x101))
      return 0;
   
   // Test #2 JEDEC numbers exhibit odd parity
   if (checkparity(readb(base + 0)) == 0 || checkparity(readb(base + 1)) == 0)
      return 0;
   return 1;
}
Example #2
0
/* this function parses the command line options */
void parse_opts(int argc, char *argv[])
{

	int c;

	while ((c =
		getopt(argc, argv, "T:I:i:n:b:d:p:s:H:D:U:P:f:hvBqN")) != EOF) {
		switch (c) {
		case 'h':
			usage();
			break;
		case 'v':
			cfg.verbose = 1;
			break;
		case 'B':
			cfg.daemon = 1;
			break;
		case 'q':
			cfg.polling = 1;
			break;
		case 'N':
			cfg.nosendstart = 1;
			break;
		case 'T':
			if (checkupdatesecs(atoi(optarg)))
				cfg.update_secs = atoi(optarg);
			else
				printFatal
				    ("Number of seconds must be greater then 0!");
			break;
		case 'n':
			if (checkinstancenum(atoi(optarg)))
				cfg.instancenum = atoi(optarg);
			else
				printFatal("Number of instance not valid!");
			break;
		case 'i':
			cfg.port = strndup(optarg, strlen(optarg));
			break;
		case 'I':
			emb_info.ip_macchina = strndup(optarg, strlen(optarg));
			break;
		case 'b':
			if (checkbaudrate(atoi(optarg)))
				cfg.baudrate = strndup(optarg, strlen(optarg));
			else {
				printFatal("Baud Rate value is not valid");
			}
			break;
		case 'd':
			if (checkdatabits(atoi(optarg))
			    && strlen(optarg) == 1)
				cfg.databits = strndup(optarg, strlen(optarg));
			else {
				printFatal("Data bits value is not valid");
			}
			break;
		case 'p':
			if (checkparity(optarg[0]))
				cfg.parity = strndup(optarg, strlen(optarg));
			else {
				printFatal("Parity value is not valid");
			}
			break;
		case 's':
			if (checkstopbits(atoi(optarg))
			    && strlen(optarg) == 1)
				cfg.stopbit = strndup(optarg, strlen(optarg));
			else {
				printFatal("Stop bit value is not valid");
			}
			break;
		case 'D':
			cfg.dsn = strndup(optarg, strlen(optarg));
			break;
		case 'U':
			cfg.dbuser = strndup(optarg, strlen(optarg));
			break;
		case 'P':
			cfg.dbpass = strndup(optarg, strlen(optarg));
			break;
		case 'f':
			cfg.cfgfile = strndup(optarg, strlen(optarg));
			break;
		default:
			usage();
			break;
		}
	}
}