ESP-Miner/main/global_state.h

113 lines
2.5 KiB
C
Raw Permalink Normal View History

#ifndef GLOBAL_STATE_H_
#define GLOBAL_STATE_H_
#include <stdbool.h>
#include <stdint.h>
#include "asic_task.h"
2024-08-15 18:51:05 -04:00
#include "bm1370.h"
#include "bm1368.h"
#include "bm1366.h"
#include "bm1397.h"
#include "common.h"
2023-06-13 09:26:43 -04:00
#include "power_management_task.h"
2023-08-20 13:09:55 -04:00
#include "serial.h"
#include "stratum_api.h"
#include "work_queue.h"
#define STRATUM_USER CONFIG_STRATUM_USER
#define HISTORY_LENGTH 100
#define DIFF_STRING_SIZE 10
2024-06-04 17:06:45 +02:00
typedef enum
{
DEVICE_UNKNOWN = -1,
DEVICE_MAX,
2024-06-07 14:05:11 +02:00
DEVICE_ULTRA,
DEVICE_SUPRA,
2024-08-15 18:51:05 -04:00
DEVICE_GAMMA,
2024-06-04 17:06:45 +02:00
} DeviceModel;
typedef enum
{
ASIC_UNKNOWN = -1,
ASIC_BM1397,
2024-06-07 14:05:11 +02:00
ASIC_BM1366,
ASIC_BM1368,
2024-08-15 18:51:05 -04:00
ASIC_BM1370,
2024-06-04 17:06:45 +02:00
} AsicModel;
2023-08-26 12:28:17 -04:00
typedef struct
{
uint8_t (*init_fn)(uint64_t, uint16_t);
task_result * (*receive_result_fn)(void * GLOBAL_STATE);
2023-08-20 13:09:55 -04:00
int (*set_max_baud_fn)(void);
void (*set_difficulty_mask_fn)(int);
void (*send_work_fn)(void * GLOBAL_STATE, bm_job * next_bm_job);
2023-08-20 13:09:55 -04:00
} AsicFunctions;
typedef struct
{
double duration_start;
int historical_hashrate_rolling_index;
double historical_hashrate_time_stamps[HISTORY_LENGTH];
double historical_hashrate[HISTORY_LENGTH];
int historical_hashrate_init;
double current_hashrate;
int64_t start_time;
uint64_t shares_accepted;
uint64_t shares_rejected;
int screen_page;
char oled_buf[20];
uint64_t best_nonce_diff;
char best_diff_string[DIFF_STRING_SIZE];
uint64_t best_session_nonce_diff;
char best_session_diff_string[DIFF_STRING_SIZE];
bool FOUND_BLOCK;
bool startup_done;
char ssid[32];
char wifi_status[20];
char * pool_url;
uint16_t pool_port;
2024-08-09 23:41:08 +02:00
uint16_t overheat_mode;
uint32_t lastClockSync;
} SystemModule;
2023-08-26 12:28:17 -04:00
typedef struct
{
2024-06-04 17:06:45 +02:00
DeviceModel device_model;
char * device_model_str;
2024-06-12 16:21:59 +02:00
int board_version;
2024-06-04 17:06:45 +02:00
AsicModel asic_model;
char * asic_model_str;
uint16_t asic_count;
uint16_t voltage_domain;
2023-08-20 13:09:55 -04:00
AsicFunctions ASIC_functions;
double asic_job_frequency_ms;
uint32_t initial_ASIC_difficulty;
2023-08-20 13:09:55 -04:00
work_queue stratum_queue;
work_queue ASIC_jobs_queue;
bm1397Module BM1397_MODULE;
SystemModule SYSTEM_MODULE;
AsicTaskModule ASIC_TASK_MODULE;
2023-06-13 09:26:43 -04:00
PowerManagementModule POWER_MANAGEMENT_MODULE;
char * extranonce_str;
int extranonce_2_len;
int abandon_work;
uint8_t * valid_jobs;
pthread_mutex_t valid_jobs_lock;
uint32_t stratum_difficulty;
uint32_t version_mask;
int sock;
bool ASIC_initalized;
} GlobalState;
#endif /* GLOBAL_STATE_H_ */