Browse Source

Merge commit 'e59f668' into cg_merges_20121207

Luke Dashjr 13 years ago
parent
commit
d4b683bc26
2 changed files with 19 additions and 46 deletions
  1. 2 4
      driver-ztex.c
  2. 17 42
      libztex.c

+ 2 - 4
driver-ztex.c

@@ -213,22 +213,20 @@ static int64_t ztex_scanhash(struct thr_info *thr, struct work *work,
 	
 	
 	applog(LOG_DEBUG, "%s: sent hashdata", ztex->repr);
 	applog(LOG_DEBUG, "%s: sent hashdata", ztex->repr);
 
 
-	lastnonce = malloc(sizeof(uint32_t)*ztex->numNonces);
+	lastnonce = calloc(1, sizeof(uint32_t)*ztex->numNonces);
 	if (lastnonce == NULL) {
 	if (lastnonce == NULL) {
 		applog(LOG_ERR, "%s: failed to allocate lastnonce[%d]", ztex->repr, ztex->numNonces);
 		applog(LOG_ERR, "%s: failed to allocate lastnonce[%d]", ztex->repr, ztex->numNonces);
 		return -1;
 		return -1;
 	}
 	}
-	memset(lastnonce, 0, sizeof(uint32_t)*ztex->numNonces);
 
 
 	/* Add an extra slot for detecting dupes that lie around */
 	/* Add an extra slot for detecting dupes that lie around */
 	backlog_max = ztex->numNonces * (2 + ztex->extraSolutions);
 	backlog_max = ztex->numNonces * (2 + ztex->extraSolutions);
-	backlog = malloc(sizeof(uint32_t) * backlog_max);
+	backlog = calloc(1, sizeof(uint32_t) * backlog_max);
 	if (backlog == NULL) {
 	if (backlog == NULL) {
 		applog(LOG_ERR, "%s: failed to allocate backlog[%d]", ztex->repr, backlog_max);
 		applog(LOG_ERR, "%s: failed to allocate backlog[%d]", ztex->repr, backlog_max);
 		free(lastnonce);
 		free(lastnonce);
 		return -1;
 		return -1;
 	}
 	}
-	memset(backlog, 0, sizeof(uint32_t) * backlog_max);
 	
 	
 	overflow = false;
 	overflow = false;
 
 

+ 17 - 42
libztex.c

@@ -422,9 +422,8 @@ static int libztex_configureFpgaLS(struct libztex_device *ztex, const char* firm
 {
 {
 	struct libztex_fpgastate state;
 	struct libztex_fpgastate state;
 	const int transactionBytes = 2048;
 	const int transactionBytes = 2048;
-	unsigned char buf[transactionBytes], cs;
-	int tries, cnt, buf_p, i;
-	ssize_t pos = 0;
+	unsigned char buf[transactionBytes];
+	int tries, cnt, i;
 	FILE *fp;
 	FILE *fp;
 
 
 	if (!libztex_checkCapability(ztex, CAPABILITY_FPGA))
 	if (!libztex_checkCapability(ztex, CAPABILITY_FPGA))
@@ -443,18 +442,6 @@ static int libztex_configureFpgaLS(struct libztex_device *ztex, const char* firm
 			return -2;
 			return -2;
 		}
 		}
 
 
-		cs = 0;
-		while (pos < transactionBytes && !feof(fp)) {
-			buf[pos] = getc(fp);
-			cs += buf[pos++];
-		}
-
-		if (feof(fp))
-			pos--;
-
-		if (bs != 0 && bs != 1)
-			bs = libztex_detectBitstreamBitOrder(buf, transactionBytes < pos? transactionBytes: pos);
-
 		//* Reset fpga
 		//* Reset fpga
 		cnt = libztex_resetFpga(ztex);
 		cnt = libztex_resetFpga(ztex);
 		if (unlikely(cnt < 0)) {
 		if (unlikely(cnt < 0)) {
@@ -462,36 +449,24 @@ static int libztex_configureFpgaLS(struct libztex_device *ztex, const char* firm
 			continue;
 			continue;
 		}
 		}
 
 
-		if (bs == 1)
-			libztex_swapBits(buf, pos);
-	 
-		buf_p = pos;
-		while (1) {
-			i = 0;
-			while (i < buf_p) {
-				cnt = libusb_control_transfer(ztex->hndl, 0x40, 0x32, 0, 0, &buf[i], buf_p - i, 5000);
-				if (unlikely(cnt < 0)) {
-					applog(LOG_ERR, "%s: Failed send fpga data with err %d", ztex->repr, cnt);
-					break;
-				}
-				i += cnt;
-			}
-			if (i < buf_p || buf_p < transactionBytes)
+		do
+		{
+			int length = fread(buf, 1, transactionBytes, fp);
+
+			if (bs != 0 && bs != 1)
+				bs = libztex_detectBitstreamBitOrder(buf, length);
+			if (bs == 1)
+				libztex_swapBits(buf, length);
+			cnt = libusb_control_transfer(ztex->hndl, 0x40, 0x32, 0, 0, buf, length, 5000);
+			if (cnt != length)
+			{
+				applog(LOG_ERR, "%s: Failed send hs fpga data", ztex->repr);
 				break;
 				break;
-			buf_p = 0;
-			while (buf_p < transactionBytes && !feof(fp)) {
-				buf[buf_p] = getc(fp);
-				cs += buf[buf_p++];
 			}
 			}
-			if (feof(fp))
-				buf_p--;
-			pos += buf_p;
-			if (buf_p == 0)
-				break;
-			if (bs == 1)
-				libztex_swapBits(buf, buf_p);
 		}
 		}
-		if (cnt >= 0)
+		while (!feof(fp));
+
+		if (cnt > 0)
 			tries = 0;
 			tries = 0;
 
 
 		fclose(fp);
 		fclose(fp);