// TODO: add input buffer int main(int argc, char *argv[]) { int q; int ppc_fd = 0; int num_q = 4; miner_t miner[4]; int start_port = 8087; unsigned int nonce; unsigned char bufferin[64]; // 512 bits unsigned char bufferout[4]; // 32 bits // Initialize HW interface and reset ppc_fd = InitQuadInterface(); if (argc == 2){ num_q = atoi(argv[1]); if (num_q <= 0 || num_q > 4){ printf("Num Quads must be 1-4\n"); print_usage(argv); exit(1); } } for (q = 0; q < num_q; q++){ SetQuad(q, ppc_fd); ResetRW(ppc_fd); } // Initialize miners: numQ consecutive ports for (q = 0; q < num_q; ++q) { NetGetConnection(start_port + q, &miner[q].connection); miner[q].state = STATE_IDLE; } while (1) { // feed / consume FPGA data // Note: several potential sources of lockups here. for (q = 0; q < num_q; ++q) { SetQuad(q, ppc_fd); if (miner[q].state == STATE_WORKING) { // Check for available data and read if available. if (ReadByteNB(&bufferout[0], ppc_fd)) { ReadByte(&bufferout[1], ppc_fd); ReadByte(&bufferout[2], ppc_fd); ReadByte(&bufferout[3], ppc_fd); // Send NetWrite(&miner[q].connection, bufferout, 4); miner[q].state = STATE_IDLE; // Debug nonce = BufferToNonce(bufferout); printf("Miner(%d) TX nonce: %d (0x%08x)\n", q, nonce, nonce); } } //else if (miner[q].state == STATE_READY) { // Just always do this. // RX net data and forward to FPGA if (NetRead(&miner[q].connection, bufferin, 64) == 64) { WriteBuffer(bufferin, 64, ppc_fd); miner[q].state = STATE_WORKING; printf("Miner(%d) RX data\n", q); } } // quad iterator // TODO: Check sideband for commands. } // while (1) // Close connections for (q = 0; q < num_q; ++q) { NetClose(&miner[q].connection); } return 0; }
void MetricThresholdAttributes::SetFromNode(DataNode *parentNode) { if(parentNode == 0) return; DataNode *searchNode = parentNode->GetNode("MetricThresholdAttributes"); if(searchNode == 0) return; DataNode *node; if((node = searchNode->GetNode("preset")) != 0) { // Allow enums to be int or string in the config file if(node->GetNodeType() == INT_NODE) { int ival = node->AsInt(); if(ival >= 0 && ival < 21) SetPreset(Preset(ival)); } else if(node->GetNodeType() == STRING_NODE) { Preset value; if(Preset_FromString(node->AsString(), value)) SetPreset(value); } } if((node = searchNode->GetNode("Hexahedron")) != 0) SetHexahedron(node->AsBool()); if((node = searchNode->GetNode("hex_lower")) != 0) SetHex_lower(node->AsDouble()); if((node = searchNode->GetNode("hex_upper")) != 0) SetHex_upper(node->AsDouble()); if((node = searchNode->GetNode("Tetrahedron")) != 0) SetTetrahedron(node->AsBool()); if((node = searchNode->GetNode("tet_lower")) != 0) SetTet_lower(node->AsDouble()); if((node = searchNode->GetNode("tet_upper")) != 0) SetTet_upper(node->AsDouble()); if((node = searchNode->GetNode("Wedge")) != 0) SetWedge(node->AsBool()); if((node = searchNode->GetNode("wed_lower")) != 0) SetWed_lower(node->AsDouble()); if((node = searchNode->GetNode("wed_upper")) != 0) SetWed_upper(node->AsDouble()); if((node = searchNode->GetNode("Pyramid")) != 0) SetPyramid(node->AsBool()); if((node = searchNode->GetNode("pyr_lower")) != 0) SetPyr_lower(node->AsDouble()); if((node = searchNode->GetNode("pyr_upper")) != 0) SetPyr_upper(node->AsDouble()); if((node = searchNode->GetNode("Triangle")) != 0) SetTriangle(node->AsBool()); if((node = searchNode->GetNode("tri_lower")) != 0) SetTri_lower(node->AsDouble()); if((node = searchNode->GetNode("tri_upper")) != 0) SetTri_upper(node->AsDouble()); if((node = searchNode->GetNode("Quad")) != 0) SetQuad(node->AsBool()); if((node = searchNode->GetNode("quad_lower")) != 0) SetQuad_lower(node->AsDouble()); if((node = searchNode->GetNode("quad_upper")) != 0) SetQuad_upper(node->AsDouble()); }
int main(int argc, char *argv[]) { int ppc_fd = 0; int numQ = 4; //Number of Quads, should probably be command line arg. unsigned int nonce; unsigned char bufferin[64]; unsigned char bufferout[4]; unsigned char midstate_buf[32]; unsigned char data_buf[32]; // Test vectors char *midstate_hex = "2b3f81261b3cfd001db436cfd4c8f3f9c7450c9a0d049bee71cba0ea2619c0b5"; // 256 bits char *data_hex = "000000000000000000000000800000000000000039f3001b6b7b8d4dc14bfc31"; // 256 bits // Expected nonce <= 30411740; int ii; for (ii = 0; ii < 32; ii++){ sscanf(&midstate_hex[ii*2], "%02hhx", &midstate_buf[ii]); sscanf(&data_hex[ii*2], "%02hhx", &data_buf[ii]); // printf("%02x %02x\n", midstate_buf[ii], data_buf[ii]); } #ifndef NOXC ppc_fd = InitQuadInterface(); //SetQuad(0, ppc_fd); int q; for (q = 0; q < numQ; q++){ SetQuad(q, ppc_fd); ResetRW(ppc_fd); } #endif // Single byte read/write test // WriteByte('z', ppc_fd); // ReadByte(&data, ppc_fd); // printf("\nRead : %c\n", data); // Buffer read/write test memset(bufferin, 0, 64); memcpy(bufferin, midstate_buf, 32); memcpy(bufferin+32, data_buf, 32); #ifndef NOXC //WriteBuffer(bufferin, 64, ppc_fd); //ReadBuffer(bufferout, 4, ppc_fd); WriteBufferToAll(bufferin, 64, numQ, ppc_fd); ReadBufferFromAny(bufferout, 4, numQ, ppc_fd); #endif nonce = (bufferout[0] << 0 & 0x000000FF); nonce |= (bufferout[1] << 8 & 0x0000FF00); nonce |= (bufferout[2] << 16 & 0x00FF0000); nonce |= (bufferout[3] << 24 & 0xFF000000); printf("\nRead : %d (0x%08x)\n", nonce, nonce); return 0; }