Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Frequency, Voltage and Serial to DEV #19

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions api.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
#include "compat.h"
#include "miner.h"
#include "util.h"
#ifdef USE_GRIDSEED
#include "driver-gridseed.h"
#endif

#if defined(USE_BFLSC) || defined(USE_AVALON) || defined(USE_HASHFAST) || defined(USE_BITFURY) || defined(USE_KLONDIKE) || defined(USE_KNC) || defined(USE_GRIDSEED)
#define HAVE_AN_ASIC 1
Expand Down Expand Up @@ -2102,6 +2105,18 @@ static void ascstatus(struct io_data *io_data, int asc, bool isjson, bool precom
root = api_add_int(root, "Last Share Pool", &last_share_pool, false);
root = api_add_time(root, "Last Share Time", &(cgpu->last_share_pool_time), false);
root = api_add_mhtotal(root, "Total MH", &(cgpu->total_mhashes), false);
#ifdef USE_GRIDSEED
GRIDSEED_INFO *info = cgpu->device_data;
double frequency = 0;
float voltage = 0;
if (cgpu->drv->drv_id == DRIVER_gridseed) {
frequency = info->freq;
voltage = info->voltage;
root = api_add_string(root, "Serial", cgpu->usbdev->serial_string, false);
root = api_add_freq(root, "Frequency", &frequency, false);
root = api_add_volts(root, "Voltage", &voltage, false);
}
#endif
root = api_add_int(root, "Diff1 Work", &(cgpu->diff1), false);
root = api_add_diff(root, "Difficulty Accepted", &(cgpu->diff_accepted), false);
root = api_add_diff(root, "Difficulty Rejected", &(cgpu->diff_rejected), false);
Expand Down
18 changes: 15 additions & 3 deletions cgminer.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ char *opt_bitburner_fury_options = NULL;
#endif
#ifdef USE_GRIDSEED
char *opt_gridseed_options = NULL;
char *opt_gridseed_freq = NULL;
#endif
#ifdef USE_KLONDIKE
char *opt_klondike_options = NULL;
Expand Down Expand Up @@ -1049,6 +1050,12 @@ static char *set_gridseed_options(const char *arg)

return NULL;
}
static char *set_gridseed_freq(const char *arg)
{
opt_set_charp(arg, &opt_gridseed_freq);

return NULL;
}
#endif

#ifdef USE_ICARUS
Expand Down Expand Up @@ -1271,6 +1278,9 @@ static struct opt_table opt_config_table[] = {
OPT_WITH_ARG("--gridseed-options",
set_gridseed_options, NULL, NULL,
opt_hidden),
OPT_WITH_ARG("--gridseed-freq",
set_gridseed_freq, NULL, NULL,
opt_hidden),
#endif
#ifdef USE_ICARUS
OPT_WITH_ARG("--icarus-options",
Expand Down Expand Up @@ -4667,6 +4677,8 @@ void write_config(FILE *fcfg)
#ifdef USE_GRIDSEED
if (opt_gridseed_options)
fprintf(fcfg, ",\n\"gridseed-options\" : \"%s\"", json_escape(opt_gridseed_options));
if (opt_gridseed_freq)
fprintf(fcfg, ",\n\"gridseed-freq\" : \"%s\"", json_escape(opt_gridseed_freq));
#endif
#ifdef USE_USBUTILS
if (opt_usb_select)
Expand Down Expand Up @@ -7142,11 +7154,11 @@ static void *watchpool_thread(void __maybe_unused *userdata)
}

/* Only switch pools if the failback pool has been
* alive for more than 5 minutes to prevent
* alive for more than one minute to prevent
* intermittently failing pools from being used. */
if (!pool->idle && pool_strategy == POOL_FAILOVER && pool->prio < cp_prio() &&
now.tv_sec - pool->tv_idle.tv_sec > 300) {
applog(LOG_WARNING, "Pool %d %s stable for 5 mins",
now.tv_sec - pool->tv_idle.tv_sec > 60) {
applog(LOG_WARNING, "Pool %d %s stable for 1 minute",
pool->pool_no, pool->rpc_url);
switch_pools(NULL);
}
Expand Down
80 changes: 64 additions & 16 deletions driver-gridseed.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,6 @@

static const char *gridseed_version = "v3.8.5.20140210.02";

typedef struct s_gridseed_info {
enum sub_ident ident;
uint32_t fw_version;
struct timeval scanhash_time;
int nonce_count[GRIDSEED_MAX_CHIPS]; // per chip
int error_count[GRIDSEED_MAX_CHIPS]; // per chip
// options
int baud;
int freq;
unsigned char freq_cmd[8];
int chips; //chips per module
int voltage;
int per_chip_stats;
} GRIDSEED_INFO;

static const char *str_reset[] = {
"55AAC000808080800000000001000000", // Chip reset
NULL
Expand Down Expand Up @@ -249,6 +234,23 @@ static void gc3355_set_core_freq(struct cgpu_info *gridseed)
applog(LOG_NOTICE, "Set GC3355 core frequency to %d MHz", info->freq);
}

static void gc3355_switch_leds(struct cgpu_info *gridseed) {
uint32_t reg_value;

// Set GPIOB pins 0 and 1 as general purpose output, open-drain, 50 MHz max
if (!gc3355_read_register(gridseed, GRIDSEED_GPIOB_BASE + GRIDSEED_CRL_OFFSET, &reg_value)) {
applog(LOG_DEBUG, "Failed to read GPIOA CRL register from %i", gridseed->device_id);
return;
}
reg_value = (reg_value & 0xffffff00) | 0x00000077;
if (!gc3355_write_register(gridseed, GRIDSEED_GPIOB_BASE + GRIDSEED_CRL_OFFSET, reg_value)) {
applog(LOG_DEBUG, "Failed to write GPIOA CRL register from %i", gridseed->device_id);
return;
}

applog(LOG_NOTICE, "Turned off GC3355 LEDs");
}

static void gc3355_switch_voltage(struct cgpu_info *gridseed) {
uint32_t reg_value;

Expand Down Expand Up @@ -291,6 +293,8 @@ static void gc3355_init(struct cgpu_info *gridseed, GRIDSEED_INFO *info)
gc3355_set_core_freq(gridseed);
if (info->voltage)
gc3355_switch_voltage(gridseed);
if (info->led)
gc3355_switch_leds(gridseed);
}

static bool get_options(GRIDSEED_INFO *info, char *options)
Expand Down Expand Up @@ -344,6 +348,9 @@ static bool get_options(GRIDSEED_INFO *info, char *options)
else if (strcasecmp(p, "per_chip_stats")==0) {
info->per_chip_stats = (tmp != 0) ? tmp : info->per_chip_stats;
}
else if (strcasecmp(p, "led")==0) {
info->led = (tmp != 0) ? tmp : info->led;
}

next:
if (comma != NULL) {
Expand Down Expand Up @@ -373,6 +380,45 @@ static bool get_options(GRIDSEED_INFO *info, char *options)
return true;
}

static bool get_freq(GRIDSEED_INFO *info, char *options)
{
char *ss, *p, *end, *comma, *colon;
int tmp;

if (options == NULL)
return false;

applog(LOG_NOTICE, "GridSeed freq options: '%s'", options);
ss = strdup(options);
p = ss;
end = p + strlen(p);

another:
comma = strchr(p, ',');
if (comma != NULL)
*comma = '\0';
colon = strchr(p, '=');
if (colon == NULL)
goto next;
*colon = '\0';

tmp = atoi(colon+1);
if (strcasecmp(p, info->serial)==0) {
applog(LOG_NOTICE, "%s unique frequency: %i", p, tmp);
info->freq = tmp;
}

next:
if (comma != NULL) {
p = comma + 1;
if (p < end)
goto another;
}
free(ss);

return true;
}

static int gridseed_cp210x_init(struct cgpu_info *gridseed, int interface)
{
// Enable the UART
Expand Down Expand Up @@ -576,11 +622,13 @@ static bool gridseed_detect_one(libusb_device *dev, struct usb_find_devices *fou
info->chips = GRIDSEED_DEFAULT_CHIPS;
info->voltage = 0;
info->per_chip_stats = 0;
info->led = 0;
info->serial = strdup(gridseed->usbdev->serial_string);
memset(info->nonce_count, 0, sizeof(info->nonce_count));
memset(info->error_count, 0, sizeof(info->error_count));

get_options(info, opt_gridseed_options);

get_freq(info, opt_gridseed_freq);
update_usb_stats(gridseed);

gridseed->usbdev->usb_type = USB_TYPE_STD;
Expand Down
18 changes: 18 additions & 0 deletions driver-gridseed.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#define GRIDSEED_PERIPH_BASE ((uint32_t)0x40000000)
#define GRIDSEED_APB2PERIPH_BASE (GRIDSEED_PERIPH_BASE + 0x10000)
#define GRIDSEED_GPIOA_BASE (GRIDSEED_APB2PERIPH_BASE + 0x0800)
#define GRIDSEED_GPIOB_BASE (GRIDSEED_APB2PERIPH_BASE + 0x0c00)
#define GRIDSEED_CRL_OFFSET 0x00
#define GRIDSEED_ODR_OFFSET 0x0c

Expand All @@ -36,4 +37,21 @@

extern struct device_drv gridseed_drv;

typedef struct s_gridseed_info {
enum sub_ident ident;
uint32_t fw_version;
struct timeval scanhash_time;
int nonce_count[GRIDSEED_MAX_CHIPS]; // per chip
int error_count[GRIDSEED_MAX_CHIPS]; // per chip
char *serial;
// options
int baud;
int freq;
unsigned char freq_cmd[8];
int chips; //chips per module
int voltage;
int per_chip_stats;
int led;
} GRIDSEED_INFO;

#endif /* INCLUDE_DRIVER_GRIDSEED_H */
1 change: 1 addition & 0 deletions miner.h
Original file line number Diff line number Diff line change
Expand Up @@ -1046,6 +1046,7 @@ extern char *opt_bitburner_fury_options;
#endif
#ifdef USE_GRIDSEED
extern char *opt_gridseed_options;
extern char *opt_gridseed_freq;
#endif
#ifdef USE_KLONDIKE
extern char *opt_klondike_options;
Expand Down