yuyinyuyin664 (OP)
Newbie
Offline
Activity: 1
Merit: 0
|
|
July 27, 2014, 01:24:37 AM |
|
I porting new driver of cgminer for my hashboard,but i got HW.
below is MCU code: while(1) { res = GetUART(); switch(res) { case C_ASK: Astat[ch] = SPI_R(); if (Astat[ch] & 0x02) //Has nonce { PutcUART(A_YES); GetNonce(s_job[ch].nonce,Astat[ch]); PutnUART(s_job[ch].nonce,4); Clr_Mask(); } else if (Astat[ch] & 0x01) //Ready to got new job { PutcUART(A_WAL); } else //Chip busy { PutcUART(A_NO); } break; case C_JOB: for (i=0;i<50;i++) { job_buff = GetUART(); } PutcUART(0x58); memcpy((void*)&s_job[ch],(void*)job_buff,SZ_MJOB); BYTE * p = &s_job[ch]; /* for(i=0;i<32;i++) { SPI_IO(i|0x80); SPI_IO(s_job[ch].midstate); } for(c=0;c<4;c++) { SPI_IO(i|0x80); SPI_IO(s_job[ch].mshit);i++;} for(c=0;c<4;c++) { SPI_IO(i|0x80); SPI_IO(s_job[ch].ntime);i++;} for(c=0;c<4;c++) { SPI_IO(i|0x80); SPI_IO(s_job[ch].ndiff);i++;} */ //for(i=0;i<44;i++) { SPI_IO(i|0x80); SPI_IO(*(p+i)); } for(i=0;i<44;i++) { SPI_IO(i|0x80); SPI_IO(job_buff); } Start_Job(); break; } Below is driver of cgminer: static uint8_t *create_job(uint8_t chip_id, uint8_t job_id, const char *midstate, const char *wdata, const double sdiff) { static uint8_t job[58] = { /* midstate */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* wdata */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /*exnc2*/ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }; uint32_t *p1 = (uint32_t *) &job[32]; uint32_t *p2 = (uint32_t *) wdata; uint32_t diffIdx,*diff=(uint32_t*)&job[42]; //difficulty pointer
swab256(job, midstate); p1 = (uint32_t *) &job[32]; p2 = (uint32_t *) wdata; p1[0] = bswap_32(p2[0]); p1[1] = bswap_32(p2[1]); p1[2] = bswap_32(p2[2]);
/* if(sdiff>4096) *diff=difficult_Tbl[15]; else { if(opt_diff>=1&&opt_diff<=16) { diffIdx=opt_diff-1; *diff=difficult_Tbl[diffIdx]; } else *diff=difficult_Tbl[14]; } */ return job; }
static bool set_work(int fd,struct work *work) { int ret; char buff; char cmd; unsigned char *midstate = work->midstate; unsigned char *wdata = work->data + 64; double sdiff = work->sdiff; uint8_t *jobdata = create_job(1,1, midstate, wdata, sdiff); cmd = C_JOB;
ret = icarus_write(fd,&cmd, 1);
ret = icarus_write(fd, jobdata, 50); read(fd,&buff,1); printf("respond:%02x\n",buff); if(ret) return true; else return false;
}
static bool get_nonce(int fd,struct work * work,uint8_t * nonce) { int ret;
ret = read(fd,nonce,4);
return true; }
static int64_t icarus_scanhash(struct thr_info *thr, struct work *work, __maybe_unused int64_t max_nonce) { struct cgpu_info *icarus; int fd; int ret; char command = 0;
struct ICARUS_INFO *info;
unsigned char read_buff[128]; char *ob_hex; uint32_t nonce; int64_t hash_count; uint32_t mask; struct timeval tv_start, tv_finish, elapsed; int curr_hw_errors, i; bool was_hw_error;
int64_t estimate_hashes;
elapsed.tv_sec = elapsed.tv_usec = 0;
icarus = thr->cgpu; if (icarus->device_fd == -1) if (!icarus_prepare(thr)) { applog(LOG_ERR, "%s%i: Comms error", icarus->drv->name, icarus->device_id); dev_error(icarus, REASON_DEV_COMMS_ERROR);
// fail the device if the reopen attempt fails return -1; }
fd = icarus->device_fd;
info = icarus_info[icarus->device_id];
cgtime(&tv_start);
command = C_ASK;
ret = icarus_write(fd, &command, 1); if (ret) { do_icarus_close(thr); applog(LOG_ERR, "%s%i: Comms error", icarus->drv->name, icarus->device_id); dev_error(icarus, REASON_DEV_COMMS_ERROR); return 0; /* This should never happen */ }
ret = read(fd,read_buff,1);
switch(read_buff[0]) { case A_WAL: //ready to take a new master job set_work(fd,work); break; case A_NO: break; //nothing, means the chips are working/busy case A_YES: if(get_nonce(fd,work,(uint8_t*)&nonce)) nonce+=1; //nonce = bswap_32(nonce); submit_nonce(thr, work, nonce); break; //there is a nonce in the FIFO case A_STR: break; // send a string or data followed by termination zero to the host, the host will print it. }
//submit_nonce(thr, work, nonce);
}
|