Commit 62f6fefb12bc1ca5003677aecaec5ddf87ee4d59

Con Kolivas 2013-09-21T08:33:11

Create a struct array of hashfast commands and their associated usb command names.

diff --git a/driver-hashfast.c b/driver-hashfast.c
index 409fa92..338e985 100644
--- a/driver-hashfast.c
+++ b/driver-hashfast.c
@@ -13,7 +13,6 @@
 #include <stdbool.h>
 
 #include "usbutils.h"
-#include "fpgautils.h"
 
 #include "driver-hashfast.h"
 
@@ -96,6 +95,33 @@ static uint32_t __maybe_unused hf_crc32(unsigned char *p, int len, int plug_in)
 static hf_info_t **hashfast_infos;
 struct device_drv hashfast_drv;
 
+struct hf_cmd {
+	int cmd;
+	char *cmd_name;
+	enum usb_cmds usb_cmd;
+};
+
+static const struct hf_cmd hf_cmds[] = {
+	{OP_NULL, "OP_NULL", C_NULL},
+	{OP_ROOT, "OP_ROOT", C_NULL},
+	{OP_RESET, "OP_RESET", C_HF_RESET},
+	{OP_PLL_CONFIG, "OP_PLL_CONFIG", C_HF_PLL_CONFIG},
+	{OP_ADDRESS, "OP_ADDRESS", C_HF_ADDRESS},
+	{OP_READDRESS, "OP_READDRESS", C_NULL},
+	{OP_HIGHEST, "OP_HIGHEST", C_NULL},
+	{OP_BAUD, "OP_BAUD", C_HF_BAUD},
+	{OP_UNROOT, "OP_UNROOT", C_NULL},
+	{OP_HASH, "OP_HASH", C_HF_HASH},
+	{OP_NONCE, "OP_NONCE", C_HF_NONCE},
+	{OP_ABORT, "OP_ABORT", C_HF_ABORT},
+	{OP_STATUS, "OP_STATUS", C_HF_STATUS},
+	{OP_GPIO, "OP_GPIO", C_NULL},
+	{OP_CONFIG, "OP_CONFIG", C_HF_CONFIG},
+	{OP_STATISTICS, "OP_STATISTICS", C_HF_STATISTICS},
+	{OP_GROUP, "OP_GROUP", C_NULL},
+	{OP_CLOCKGATE, "OP_CLOCKGATE", C_HF_CLOCKGATE}
+};
+
 static int hashfast_reset(struct cgpu_info __maybe_unused *hashfast)
 {
 	return 0;
diff --git a/driver-hashfast.h b/driver-hashfast.h
index 042c2bd..7daea2a 100644
--- a/driver-hashfast.h
+++ b/driver-hashfast.h
@@ -24,6 +24,7 @@
 #define HF_BROADCAST_ADDRESS    (uint8_t) 0xff
 
 // Operation codes (Second header byte)
+#define OP_NULL		0
 #define OP_ROOT         1
 #define OP_RESET        2
 #define OP_PLL_CONFIG   3
diff --git a/usbutils.c b/usbutils.c
index c188bc5..1c84eef 100644
--- a/usbutils.c
+++ b/usbutils.c
@@ -500,6 +500,7 @@ static int next_stat = USB_NOSTAT;
 
 static const char **usb_commands;
 
+static const char *C_NULL_S = "Null";
 static const char *C_REJECTED_S = "RejectedNoDevice";
 static const char *C_PING_S = "Ping";
 static const char *C_CLEAR_S = "Clear";
@@ -1001,6 +1002,7 @@ static void cgusb_check_init()
 		// use constants so the stat generation is very quick
 		// and the association between number and name can't
 		// be missalined easily
+		usb_commands[C_NULL] = C_NULL_S;
 		usb_commands[C_REJECTED] = C_REJECTED_S;
 		usb_commands[C_PING] = C_PING_S;
 		usb_commands[C_CLEAR] = C_CLEAR_S;
diff --git a/usbutils.h b/usbutils.h
index b9cd0fc..d02766f 100644
--- a/usbutils.h
+++ b/usbutils.h
@@ -254,7 +254,8 @@ struct cg_usb_info {
 };
 
 enum usb_cmds {
-	C_REJECTED = 0,
+	C_NULL = 0,
+	C_REJECTED,
 	C_PING,
 	C_CLEAR,
 	C_REQUESTVERSION,