diff --git a/components/asic/bm1366.c b/components/asic/bm1366.c index 691aac5..e7b340a 100644 --- a/components/asic/bm1366.c +++ b/components/asic/bm1366.c @@ -456,7 +456,7 @@ static uint8_t _send_init(uint64_t frequency, uint16_t asic_count) // unsigned char init137[11] = {0x55, 0xAA, 0x51, 0x09, 0x00, 0x14, 0x00, 0x00, 0x00, 0xFF, 0x08}; // _send_simple(init137, 11); - BM1366_set_job_difficulty_mask(BM1366_INITIAL_DIFFICULTY); + BM1366_set_job_difficulty_mask(BM1366_ASIC_DIFFICULTY); unsigned char init138[11] = {0x55, 0xAA, 0x51, 0x09, 0x00, 0x54, 0x00, 0x00, 0x00, 0x03, 0x1D}; _send_simple(init138, 11); diff --git a/components/asic/bm1368.c b/components/asic/bm1368.c index 52e5012..b6b71b6 100644 --- a/components/asic/bm1368.c +++ b/components/asic/bm1368.c @@ -291,7 +291,7 @@ uint8_t BM1368_init(uint64_t frequency, uint16_t asic_count) vTaskDelay(pdMS_TO_TICKS(500)); } - BM1368_set_job_difficulty_mask(BM1368_INITIAL_DIFFICULTY); + BM1368_set_job_difficulty_mask(BM1368_ASIC_DIFFICULTY); do_frequency_ramp_up((float)frequency); diff --git a/components/asic/bm1370.c b/components/asic/bm1370.c index 18c9171..d96d6e9 100644 --- a/components/asic/bm1370.c +++ b/components/asic/bm1370.c @@ -264,7 +264,7 @@ static uint8_t _send_init(uint64_t frequency, uint16_t asic_count) //set ticket mask // unsigned char init11[11] = {0x55, 0xAA, 0x51, 0x09, 0x00, 0x14, 0x00, 0x00, 0x00, 0xFF, 0x08}; // _send_simple(init11, 11); - BM1370_set_job_difficulty_mask(BM1370_INITIAL_DIFFICULTY); + BM1370_set_job_difficulty_mask(BM1370_ASIC_DIFFICULTY); //Analog Mux Control unsigned char init12[11] = {0x55, 0xAA, 0x51, 0x09, 0x00, 0x54, 0x00, 0x00, 0x00, 0x03, 0x1D}; diff --git a/components/asic/bm1397.c b/components/asic/bm1397.c index d88e950..7dccaeb 100644 --- a/components/asic/bm1397.c +++ b/components/asic/bm1397.c @@ -257,7 +257,7 @@ static uint8_t _send_init(uint64_t frequency, uint16_t asic_count) unsigned char init4[9] = {0x00, CORE_REGISTER_CONTROL, 0x80, 0x00, 0x80, 0x74}; // init4 - init_4_? _send_BM1397((TYPE_CMD | GROUP_ALL | CMD_WRITE), init4, 6, BM1937_SERIALTX_DEBUG); - BM1397_set_job_difficulty_mask(256); + BM1397_set_job_difficulty_mask(BM1397_ASIC_DIFFICULTY); unsigned char init5[9] = {0x00, PLL3_PARAMETER, 0xC0, 0x70, 0x01, 0x11}; // init5 - pll3_parameter _send_BM1397((TYPE_CMD | GROUP_ALL | CMD_WRITE), init5, 6, BM1937_SERIALTX_DEBUG); diff --git a/components/asic/include/bm1366.h b/components/asic/include/bm1366.h index a8010ec..afa417c 100644 --- a/components/asic/include/bm1366.h +++ b/components/asic/include/bm1366.h @@ -8,7 +8,7 @@ #define ASIC_BM1366_JOB_FREQUENCY_MS 2000 #define CRC5_MASK 0x1F -#define BM1366_INITIAL_DIFFICULTY 256 +#define BM1366_ASIC_DIFFICULTY 256 #define BM1366_SERIALTX_DEBUG false #define BM1366_SERIALRX_DEBUG false diff --git a/components/asic/include/bm1368.h b/components/asic/include/bm1368.h index f9046b9..227b806 100644 --- a/components/asic/include/bm1368.h +++ b/components/asic/include/bm1368.h @@ -8,7 +8,7 @@ #define ASIC_BM1368_JOB_FREQUENCY_MS 500 #define CRC5_MASK 0x1F -#define BM1368_INITIAL_DIFFICULTY 256 +#define BM1368_ASIC_DIFFICULTY 256 #define BM1368_SERIALTX_DEBUG false #define BM1368_SERIALRX_DEBUG false diff --git a/components/asic/include/bm1370.h b/components/asic/include/bm1370.h index 3456b17..7cfd6fd 100644 --- a/components/asic/include/bm1370.h +++ b/components/asic/include/bm1370.h @@ -8,8 +8,7 @@ #define ASIC_BM1370_JOB_FREQUENCY_MS 500 #define CRC5_MASK 0x1F - -#define BM1370_INITIAL_DIFFICULTY 256 +#define BM1370_ASIC_DIFFICULTY 256 #define BM1370_SERIALTX_DEBUG true #define BM1370_SERIALRX_DEBUG false diff --git a/components/asic/include/bm1397.h b/components/asic/include/bm1397.h index 95ea4aa..11b5e61 100644 --- a/components/asic/include/bm1397.h +++ b/components/asic/include/bm1397.h @@ -8,7 +8,7 @@ #define ASIC_BM1397_JOB_FREQUENCY_MS 20 //not currently used #define CRC5_MASK 0x1F -#define BM1397_INITIAL_DIFFICULTY 256 +#define BM1397_ASIC_DIFFICULTY 256 #define BM1937_SERIALTX_DEBUG false #define BM1937_SERIALRX_DEBUG false diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index 4d05dec..7d00f0b 100755 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -14,6 +14,7 @@ SRCS "TPS546.c" "vcore.c" "work_queue.c" + "nvs_device.c" "./http_server/http_server.c" "./self_test/self_test.c" "./tasks/stratum_task.c" @@ -27,6 +28,7 @@ INCLUDE_DIRS "." "tasks" "http_server" + "self_test" "../components/asic/include" "../components/connect/include" "../components/dns_server/include" diff --git a/main/global_state.h b/main/global_state.h index f887104..8ac051e 100644 --- a/main/global_state.h +++ b/main/global_state.h @@ -89,7 +89,7 @@ typedef struct uint16_t voltage_domain; AsicFunctions ASIC_functions; double asic_job_frequency_ms; - uint32_t initial_ASIC_difficulty; + uint32_t ASIC_difficulty; work_queue stratum_queue; work_queue ASIC_jobs_queue; diff --git a/main/http_server/axe-os/src/app/app-routing.module.ts b/main/http_server/axe-os/src/app/app-routing.module.ts index 3d27efb..b443f76 100644 --- a/main/http_server/axe-os/src/app/app-routing.module.ts +++ b/main/http_server/axe-os/src/app/app-routing.module.ts @@ -4,6 +4,7 @@ import { RouterModule, Routes } from '@angular/router'; import { HomeComponent } from './components/home/home.component'; import { LogsComponent } from './components/logs/logs.component'; import { SettingsComponent } from './components/settings/settings.component'; +import { NetworkComponent } from './components/network/network.component'; import { SwarmComponent } from './components/swarm/swarm.component'; import { AppLayoutComponent } from './layout/app.layout.component'; @@ -20,6 +21,10 @@ const routes: Routes = [ path: 'logs', component: LogsComponent }, + { + path: 'network', + component: NetworkComponent + }, { path: 'settings', component: SettingsComponent diff --git a/main/http_server/axe-os/src/app/app.module.ts b/main/http_server/axe-os/src/app/app.module.ts index f89d369..fb3fd7c 100644 --- a/main/http_server/axe-os/src/app/app.module.ts +++ b/main/http_server/axe-os/src/app/app.module.ts @@ -11,9 +11,11 @@ import { ToastrModule } from 'ngx-toastr'; import { AppRoutingModule } from './app-routing.module'; import { AppComponent } from './app.component'; import { EditComponent } from './components/edit/edit.component'; +import { NetworkEditComponent } from './components/network-edit/network.edit.component'; import { HomeComponent } from './components/home/home.component'; import { LoadingComponent } from './components/loading/loading.component'; import { LogsComponent } from './components/logs/logs.component'; +import { NetworkComponent } from './components/network/network.component'; import { SettingsComponent } from './components/settings/settings.component'; import { SwarmComponent } from './components/swarm/swarm.component'; import { AppLayoutModule } from './layout/app.layout.module'; @@ -26,8 +28,10 @@ import { MessageModule } from 'primeng/message'; const components = [ AppComponent, EditComponent, + NetworkEditComponent, HomeComponent, LoadingComponent, + NetworkComponent, SettingsComponent, LogsComponent ]; diff --git a/main/http_server/axe-os/src/app/components/edit/edit.component.html b/main/http_server/axe-os/src/app/components/edit/edit.component.html index faa1ac3..071622c 100644 --- a/main/http_server/axe-os/src/app/components/edit/edit.component.html +++ b/main/http_server/axe-os/src/app/components/edit/edit.component.html @@ -1,29 +1,5 @@
- -
- -
- -
-
-
- -
- -
-
-
- -
- - -
-
@@ -81,8 +57,13 @@
-
- +
+ +
@@ -172,7 +153,6 @@ -
Power
-
+
Power
-
+
@@ -117,7 +117,7 @@   Danger: Low voltage
-
+
ASIC Voltage Requested diff --git a/main/http_server/axe-os/src/app/components/network-edit/network.edit.component.html b/main/http_server/axe-os/src/app/components/network-edit/network.edit.component.html new file mode 100644 index 0000000..071c31f --- /dev/null +++ b/main/http_server/axe-os/src/app/components/network-edit/network.edit.component.html @@ -0,0 +1,34 @@ + + + +
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ + +
+
+ +
+ + You must restart this device after saving for changes to take effect. +
+ +
diff --git a/main/http_server/axe-os/src/app/components/network-edit/network.edit.component.scss b/main/http_server/axe-os/src/app/components/network-edit/network.edit.component.scss new file mode 100644 index 0000000..bfff955 --- /dev/null +++ b/main/http_server/axe-os/src/app/components/network-edit/network.edit.component.scss @@ -0,0 +1,5 @@ +.pi { + right: 1rem; + font-size: 1.5rem; + top: 1rem; +} diff --git a/main/http_server/axe-os/src/app/components/network-edit/network.edit.component.spec.ts b/main/http_server/axe-os/src/app/components/network-edit/network.edit.component.spec.ts new file mode 100644 index 0000000..b28df6a --- /dev/null +++ b/main/http_server/axe-os/src/app/components/network-edit/network.edit.component.spec.ts @@ -0,0 +1,21 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { NetworkEditComponent } from './network.edit.component'; + +describe('NetworkEditComponent', () => { + let component: NetworkEditComponent; + let fixture: ComponentFixture; + + beforeEach(() => { + TestBed.configureTestingModule({ + declarations: [NetworkEditComponent] + }); + fixture = TestBed.createComponent(NetworkEditComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/main/http_server/axe-os/src/app/components/network-edit/network.edit.component.ts b/main/http_server/axe-os/src/app/components/network-edit/network.edit.component.ts new file mode 100644 index 0000000..c4ad4e2 --- /dev/null +++ b/main/http_server/axe-os/src/app/components/network-edit/network.edit.component.ts @@ -0,0 +1,70 @@ +import { HttpErrorResponse } from '@angular/common/http'; +import { Component, Input, OnInit } from '@angular/core'; +import { FormBuilder, FormGroup, Validators } from '@angular/forms'; +import { ToastrService } from 'ngx-toastr'; +import { startWith } from 'rxjs'; +import { LoadingService } from 'src/app/services/loading.service'; +import { SystemService } from 'src/app/services/system.service'; + +@Component({ + selector: 'app-network-edit', + templateUrl: './network.edit.component.html', + styleUrls: ['./network.edit.component.scss'] +}) +export class NetworkEditComponent implements OnInit { + + public form!: FormGroup; + + @Input() uri = ''; + + constructor( + private fb: FormBuilder, + private systemService: SystemService, + private toastr: ToastrService, + private toastrService: ToastrService, + private loadingService: LoadingService + ) { + + } + ngOnInit(): void { + this.systemService.getInfo(this.uri) + .pipe(this.loadingService.lockUIUntilComplete()) + .subscribe(info => { + this.form = this.fb.group({ + hostname: [info.hostname, [Validators.required]], + ssid: [info.ssid, [Validators.required]], + wifiPass: ['*****'], + }); + + }); + } + + + public updateSystem() { + + const form = this.form.getRawValue(); + + // Allow an empty wifi password + form.wifiPass = form.wifiPass == null ? '' : form.wifiPass; + + if (form.wifiPass === '*****') { + delete form.wifiPass; + } + + this.systemService.updateSystem(this.uri, form) + .pipe(this.loadingService.lockUIUntilComplete()) + .subscribe({ + next: () => { + this.toastr.success('Success!', 'Saved.'); + }, + error: (err: HttpErrorResponse) => { + this.toastr.error('Error.', `Could not save. ${err.message}`); + } + }); + } + + showWifiPassword: boolean = false; + toggleWifiPasswordVisibility() { + this.showWifiPassword = !this.showWifiPassword; + } +} diff --git a/main/http_server/axe-os/src/app/components/network/network.component.html b/main/http_server/axe-os/src/app/components/network/network.component.html new file mode 100644 index 0000000..d563441 --- /dev/null +++ b/main/http_server/axe-os/src/app/components/network/network.component.html @@ -0,0 +1,5 @@ +
+

Network Configuration

+ + +
diff --git a/main/http_server/axe-os/src/app/components/network/network.component.scss b/main/http_server/axe-os/src/app/components/network/network.component.scss new file mode 100644 index 0000000..f2798eb --- /dev/null +++ b/main/http_server/axe-os/src/app/components/network/network.component.scss @@ -0,0 +1,35 @@ +input[type="text"], +input[type="number"], +input[type="password"], +input[type="range"] { + min-width: 250px; + max-width: 90%; +} + +select { + min-width: 268px; + max-width: 90%; +} + +.restart { + margin-bottom: 1.5rem; + +} + +@media only screen and (min-width:900px) { + + input[type="text"], + input[type="password"], + input[type="number"], + input[type="range"] { + min-width: 500px + } + + select { + min-width: 518px + } +} + +a { + color: white; +} diff --git a/main/http_server/axe-os/src/app/components/network/network.component.spec.ts b/main/http_server/axe-os/src/app/components/network/network.component.spec.ts new file mode 100644 index 0000000..578f466 --- /dev/null +++ b/main/http_server/axe-os/src/app/components/network/network.component.spec.ts @@ -0,0 +1,21 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { NetworkComponent } from './network.component'; + +describe('NetworkComponent', () => { + let component: NetworkComponent; + let fixture: ComponentFixture; + + beforeEach(() => { + TestBed.configureTestingModule({ + declarations: [NetworkComponent] + }); + fixture = TestBed.createComponent(NetworkComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/main/http_server/axe-os/src/app/components/network/network.component.ts b/main/http_server/axe-os/src/app/components/network/network.component.ts new file mode 100644 index 0000000..da08b1a --- /dev/null +++ b/main/http_server/axe-os/src/app/components/network/network.component.ts @@ -0,0 +1,62 @@ +import { HttpErrorResponse, HttpEventType } from '@angular/common/http'; +import { Component } from '@angular/core'; +import { FormBuilder, FormGroup, Validators } from '@angular/forms'; +import { ToastrService } from 'ngx-toastr'; +import { map, Observable, shareReplay, startWith } from 'rxjs'; +import { LoadingService } from 'src/app/services/loading.service'; +import { SystemService } from 'src/app/services/system.service'; + +@Component({ + selector: 'app-network', + templateUrl: './network.component.html', + styleUrls: ['./network.component.scss'] +}) +export class NetworkComponent { + + public form!: FormGroup; + + public info$: Observable; + + constructor( + private fb: FormBuilder, + private systemService: SystemService, + private toastr: ToastrService, + private toastrService: ToastrService, + private loadingService: LoadingService, + ) { + this.info$ = this.systemService.getInfo().pipe(shareReplay({refCount: true, bufferSize: 1})) + + this.info$.pipe(this.loadingService.lockUIUntilComplete()) + .subscribe(info => { + this.form = this.fb.group({ + hostname: [info.hostname, [Validators.required]], + ssid: [info.ssid, [Validators.required]], + wifiPass: ['*****'], + }); + }); + + } + + public updateSystem() { + + const form = this.form.getRawValue(); + + // Allow an empty wifi password + form.wifiPass = form.wifiPass == null ? '' : form.wifiPass; + + if (form.wifiPass === '*****') { + delete form.wifiPass; + } + + this.systemService.updateSystem(undefined, form) + .pipe(this.loadingService.lockUIUntilComplete()) + .subscribe({ + next: () => { + this.toastr.success('Success!', 'Saved.'); + }, + error: (err: HttpErrorResponse) => { + this.toastr.error('Error.', `Could not save. ${err.message}`); + } + }); + } +} diff --git a/main/http_server/axe-os/src/app/components/settings/settings.component.ts b/main/http_server/axe-os/src/app/components/settings/settings.component.ts index a6719cf..33e0ae9 100644 --- a/main/http_server/axe-os/src/app/components/settings/settings.component.ts +++ b/main/http_server/axe-os/src/app/components/settings/settings.component.ts @@ -71,8 +71,6 @@ export class SettingsComponent { ]], stratumUser: [info.stratumUser, [Validators.required]], stratumPassword: ['*****', [Validators.required]], - ssid: [info.ssid, [Validators.required]], - wifiPass: ['*****'], coreVoltage: [info.coreVoltage, [Validators.required]], frequency: [info.frequency, [Validators.required]], autofanspeed: [info.autofanspeed == 1, [Validators.required]], @@ -116,12 +114,6 @@ export class SettingsComponent { form.invertfanpolarity = form.invertfanpolarity == true ? 1 : 0; form.autofanspeed = form.autofanspeed == true ? 1 : 0; - // Allow an empty wifi password - form.wifiPass = form.wifiPass == null ? '' : form.wifiPass; - - if (form.wifiPass === '*****') { - delete form.wifiPass; - } if (form.stratumPassword === '*****') { delete form.stratumPassword; } @@ -211,9 +203,4 @@ export class SettingsComponent { }); this.toastr.success('Success!', 'Bitaxe restarted'); } - - - - - } diff --git a/main/http_server/axe-os/src/app/layout/app.menu.component.html b/main/http_server/axe-os/src/app/layout/app.menu.component.html index cecd713..69858eb 100644 --- a/main/http_server/axe-os/src/app/layout/app.menu.component.html +++ b/main/http_server/axe-os/src/app/layout/app.menu.component.html @@ -5,6 +5,8 @@ - +
  • + +
  • \ No newline at end of file diff --git a/main/http_server/axe-os/src/app/layout/app.menu.component.ts b/main/http_server/axe-os/src/app/layout/app.menu.component.ts index 70c239d..f5ed5da 100644 --- a/main/http_server/axe-os/src/app/layout/app.menu.component.ts +++ b/main/http_server/axe-os/src/app/layout/app.menu.component.ts @@ -24,22 +24,19 @@ export class AppMenuComponent implements OnInit { items: [ { label: 'Dashboard', icon: 'pi pi-fw pi-home', routerLink: ['/'] }, { label: 'Swarm', icon: 'pi pi-fw pi-share-alt', routerLink: ['swarm'] }, + { label: 'Network', icon: 'pi pi-fw pi-wifi', routerLink: ['network'] }, { label: 'Settings', icon: 'pi pi-fw pi-cog', routerLink: ['settings'] }, { label: 'Logs', icon: 'pi pi-fw pi-list', routerLink: ['logs'] }, - ] } ]; } - - public restart() { this.systemService.restart().subscribe(res => { }); this.toastr.success('Success!', 'Bitaxe restarted'); } - } diff --git a/main/http_server/axe-os/src/app/layout/styles/layout/_menu.scss b/main/http_server/axe-os/src/app/layout/styles/layout/_menu.scss index 3b957ec..a547962 100644 --- a/main/http_server/axe-os/src/app/layout/styles/layout/_menu.scss +++ b/main/http_server/axe-os/src/app/layout/styles/layout/_menu.scss @@ -135,6 +135,10 @@ } #restart { - padding: 2rem 1rem; - display: block; + display: inline-block; +} + +#restart-container { + margin: 2rem 1rem; + display: flex; } \ No newline at end of file diff --git a/main/main.c b/main/main.c index 0d6e515..dbc467b 100644 --- a/main/main.c +++ b/main/main.c @@ -17,6 +17,9 @@ #include "stratum_task.h" #include "user_input_task.h" #include "i2c_bitaxe.h" +#include "adc.h" +#include "nvs_device.h" +#include "self_test.h" static GlobalState GLOBAL_STATE = { .extranonce_str = NULL, @@ -27,7 +30,6 @@ static GlobalState GLOBAL_STATE = { }; static const char * TAG = "bitaxe"; -static const double NONCE_SPACE = 4294967296.0; // 2^32 void app_main(void) { @@ -40,132 +42,47 @@ void app_main(void) //wait for I2C to init vTaskDelay(100 / portTICK_PERIOD_MS); - ESP_ERROR_CHECK(nvs_flash_init()); + //Init ADC + ADC_init(); - GLOBAL_STATE.POWER_MANAGEMENT_MODULE.frequency_value = nvs_config_get_u16(NVS_CONFIG_ASIC_FREQ, CONFIG_ASIC_FREQUENCY); - ESP_LOGI(TAG, "NVS_CONFIG_ASIC_FREQ %f", (float)GLOBAL_STATE.POWER_MANAGEMENT_MODULE.frequency_value); - - GLOBAL_STATE.device_model_str = nvs_config_get_string(NVS_CONFIG_DEVICE_MODEL, ""); - if (strcmp(GLOBAL_STATE.device_model_str, "max") == 0) { - ESP_LOGI(TAG, "DEVICE: Max"); - GLOBAL_STATE.device_model = DEVICE_MAX; - GLOBAL_STATE.asic_count = 1; - GLOBAL_STATE.voltage_domain = 1; - } else if (strcmp(GLOBAL_STATE.device_model_str, "ultra") == 0) { - ESP_LOGI(TAG, "DEVICE: Ultra"); - GLOBAL_STATE.device_model = DEVICE_ULTRA; - GLOBAL_STATE.asic_count = 1; - GLOBAL_STATE.voltage_domain = 1; - } else if (strcmp(GLOBAL_STATE.device_model_str, "supra") == 0) { - ESP_LOGI(TAG, "DEVICE: Supra"); - GLOBAL_STATE.device_model = DEVICE_SUPRA; - GLOBAL_STATE.asic_count = 1; - GLOBAL_STATE.voltage_domain = 1; - } else if (strcmp(GLOBAL_STATE.device_model_str, "gamma") == 0) { - ESP_LOGI(TAG, "DEVICE: Gamma"); - GLOBAL_STATE.device_model = DEVICE_GAMMA; - GLOBAL_STATE.asic_count = 1; - GLOBAL_STATE.voltage_domain = 1; - } else { - ESP_LOGE(TAG, "Invalid DEVICE model"); - // maybe should return here to now execute anything with a faulty device parameter ! - // this stops crashes/reboots and allows dev testing without an asic - GLOBAL_STATE.device_model = DEVICE_UNKNOWN; - GLOBAL_STATE.asic_count = -1; - GLOBAL_STATE.voltage_domain = 1; - } - GLOBAL_STATE.board_version = atoi(nvs_config_get_string(NVS_CONFIG_BOARD_VERSION, "000")); - ESP_LOGI(TAG, "Found Device Model: %s", GLOBAL_STATE.device_model_str); - ESP_LOGI(TAG, "Found Board Version: %d", GLOBAL_STATE.board_version); - - GLOBAL_STATE.asic_model_str = nvs_config_get_string(NVS_CONFIG_ASIC_MODEL, ""); - if (strcmp(GLOBAL_STATE.asic_model_str, "BM1366") == 0) { - ESP_LOGI(TAG, "ASIC: %dx BM1366 (%" PRIu64 " cores)", GLOBAL_STATE.asic_count, BM1366_CORE_COUNT); - GLOBAL_STATE.asic_model = ASIC_BM1366; - AsicFunctions ASIC_functions = {.init_fn = BM1366_init, - .receive_result_fn = BM1366_proccess_work, - .set_max_baud_fn = BM1366_set_max_baud, - .set_difficulty_mask_fn = BM1366_set_job_difficulty_mask, - .send_work_fn = BM1366_send_work, - .set_version_mask = BM1366_set_version_mask}; - //GLOBAL_STATE.asic_job_frequency_ms = (NONCE_SPACE / (double) (GLOBAL_STATE.POWER_MANAGEMENT_MODULE.frequency_value * BM1366_CORE_COUNT * 1000)) / (double) GLOBAL_STATE.asic_count; // version-rolling so Small Cores have different Nonce Space - GLOBAL_STATE.asic_job_frequency_ms = ASIC_BM1366_JOB_FREQUENCY_MS; //2000ms - GLOBAL_STATE.initial_ASIC_difficulty = BM1366_INITIAL_DIFFICULTY; - - GLOBAL_STATE.ASIC_functions = ASIC_functions; - } else if (strcmp(GLOBAL_STATE.asic_model_str, "BM1370") == 0) { - ESP_LOGI(TAG, "ASIC: %dx BM1370 (%" PRIu64 " cores)", GLOBAL_STATE.asic_count, BM1370_CORE_COUNT); - GLOBAL_STATE.asic_model = ASIC_BM1370; - AsicFunctions ASIC_functions = {.init_fn = BM1370_init, - .receive_result_fn = BM1370_proccess_work, - .set_max_baud_fn = BM1370_set_max_baud, - .set_difficulty_mask_fn = BM1370_set_job_difficulty_mask, - .send_work_fn = BM1370_send_work, - .set_version_mask = BM1370_set_version_mask}; - //GLOBAL_STATE.asic_job_frequency_ms = (NONCE_SPACE / (double) (GLOBAL_STATE.POWER_MANAGEMENT_MODULE.frequency_value * BM1370_CORE_COUNT * 1000)) / (double) GLOBAL_STATE.asic_count; // version-rolling so Small Cores have different Nonce Space - GLOBAL_STATE.asic_job_frequency_ms = ASIC_BM1370_JOB_FREQUENCY_MS; //500ms - GLOBAL_STATE.initial_ASIC_difficulty = BM1370_INITIAL_DIFFICULTY; - - GLOBAL_STATE.ASIC_functions = ASIC_functions; - } else if (strcmp(GLOBAL_STATE.asic_model_str, "BM1368") == 0) { - ESP_LOGI(TAG, "ASIC: %dx BM1368 (%" PRIu64 " cores)", GLOBAL_STATE.asic_count, BM1368_CORE_COUNT); - GLOBAL_STATE.asic_model = ASIC_BM1368; - AsicFunctions ASIC_functions = {.init_fn = BM1368_init, - .receive_result_fn = BM1368_proccess_work, - .set_max_baud_fn = BM1368_set_max_baud, - .set_difficulty_mask_fn = BM1368_set_job_difficulty_mask, - .send_work_fn = BM1368_send_work, - .set_version_mask = BM1368_set_version_mask}; - //GLOBAL_STATE.asic_job_frequency_ms = (NONCE_SPACE / (double) (GLOBAL_STATE.POWER_MANAGEMENT_MODULE.frequency_value * BM1368_CORE_COUNT * 1000)) / (double) GLOBAL_STATE.asic_count; // version-rolling so Small Cores have different Nonce Space - GLOBAL_STATE.asic_job_frequency_ms = ASIC_BM1368_JOB_FREQUENCY_MS; //500ms - GLOBAL_STATE.initial_ASIC_difficulty = BM1368_INITIAL_DIFFICULTY; - - GLOBAL_STATE.ASIC_functions = ASIC_functions; - } else if (strcmp(GLOBAL_STATE.asic_model_str, "BM1397") == 0) { - ESP_LOGI(TAG, "ASIC: %dx BM1397 (%" PRIu64 " cores)", GLOBAL_STATE.asic_count, BM1397_SMALL_CORE_COUNT); - GLOBAL_STATE.asic_model = ASIC_BM1397; - AsicFunctions ASIC_functions = {.init_fn = BM1397_init, - .receive_result_fn = BM1397_proccess_work, - .set_max_baud_fn = BM1397_set_max_baud, - .set_difficulty_mask_fn = BM1397_set_job_difficulty_mask, - .send_work_fn = BM1397_send_work, - .set_version_mask = BM1397_set_version_mask}; - GLOBAL_STATE.asic_job_frequency_ms = (NONCE_SPACE / (double) (GLOBAL_STATE.POWER_MANAGEMENT_MODULE.frequency_value * BM1397_SMALL_CORE_COUNT * 1000)) / (double) GLOBAL_STATE.asic_count; // no version-rolling so same Nonce Space is splitted between Small Cores - GLOBAL_STATE.initial_ASIC_difficulty = BM1397_INITIAL_DIFFICULTY; - - GLOBAL_STATE.ASIC_functions = ASIC_functions; - } else { - ESP_LOGE(TAG, "Invalid ASIC model"); - AsicFunctions ASIC_functions = {.init_fn = NULL, - .receive_result_fn = NULL, - .set_max_baud_fn = NULL, - .set_difficulty_mask_fn = NULL, - .send_work_fn = NULL}; - GLOBAL_STATE.ASIC_functions = ASIC_functions; - // maybe should return here to now execute anything with a faulty device parameter ! + //initialize the ESP32 NVS + if (NVSDevice_init() != ESP_OK){ + ESP_LOGE(TAG, "Failed to init NVS"); + return; } - bool is_max = GLOBAL_STATE.asic_model == ASIC_BM1397; - uint64_t best_diff = nvs_config_get_u64(NVS_CONFIG_BEST_DIFF, 0); - uint16_t should_self_test = nvs_config_get_u16(NVS_CONFIG_SELF_TEST, 0); - if (should_self_test == 1 && !is_max && best_diff < 1) { + //parse the NVS config into GLOBAL_STATE + if (NVSDevice_parse_config(&GLOBAL_STATE) != ESP_OK) { + ESP_LOGE(TAG, "Failed to parse NVS config"); + return; + } + + //should we run the self test? + if (should_test(&GLOBAL_STATE)) { self_test((void *) &GLOBAL_STATE); vTaskDelay(60 * 60 * 1000 / portTICK_PERIOD_MS); } + SYSTEM_init_system(&GLOBAL_STATE); + // pull the wifi credentials and hostname out of NVS char * wifi_ssid = nvs_config_get_string(NVS_CONFIG_WIFI_SSID, WIFI_SSID); char * wifi_pass = nvs_config_get_string(NVS_CONFIG_WIFI_PASS, WIFI_PASS); char * hostname = nvs_config_get_string(NVS_CONFIG_HOSTNAME, HOSTNAME); // copy the wifi ssid to the global state - strncpy(GLOBAL_STATE.SYSTEM_MODULE.ssid, - wifi_ssid, - sizeof(GLOBAL_STATE.SYSTEM_MODULE.ssid)); + strncpy(GLOBAL_STATE.SYSTEM_MODULE.ssid, wifi_ssid, sizeof(GLOBAL_STATE.SYSTEM_MODULE.ssid)); GLOBAL_STATE.SYSTEM_MODULE.ssid[sizeof(GLOBAL_STATE.SYSTEM_MODULE.ssid)-1] = 0; // init and connect to wifi wifi_init(wifi_ssid, wifi_pass, hostname); + + SYSTEM_init_peripherals(&GLOBAL_STATE); + + xTaskCreate(SYSTEM_task, "SYSTEM_task", 4096, (void *) &GLOBAL_STATE, 3, NULL); + xTaskCreate(POWER_MANAGEMENT_task, "power mangement", 8192, (void *) &GLOBAL_STATE, 10, NULL); + + //start the API for AxeOS start_rest_server((void *) &GLOBAL_STATE); EventBits_t result_bits = wifi_connect(); @@ -195,11 +112,6 @@ void app_main(void) free(wifi_pass); free(hostname); - SYSTEM_init_system(&GLOBAL_STATE); - - xTaskCreate(SYSTEM_task, "SYSTEM_task", 4096, (void *) &GLOBAL_STATE, 3, NULL); - xTaskCreate(POWER_MANAGEMENT_task, "power mangement", 8192, (void *) &GLOBAL_STATE, 10, NULL); - // set the startup_done flag GLOBAL_STATE.SYSTEM_MODULE.startup_done = true; GLOBAL_STATE.new_stratum_version_rolling_msg = false; diff --git a/main/nvs_device.c b/main/nvs_device.c new file mode 100644 index 0000000..123e6fb --- /dev/null +++ b/main/nvs_device.c @@ -0,0 +1,147 @@ +#include +#include "esp_event.h" +#include "esp_log.h" +#include "nvs_flash.h" +#include "nvs_config.h" +#include "nvs_device.h" + +#include "connect.h" +#include "global_state.h" + +static const char * TAG = "nvs_device"; +static const double NONCE_SPACE = 4294967296.0; // 2^32 + + +esp_err_t NVSDevice_init(void) { + esp_err_t err = nvs_flash_init(); + if (err == ESP_ERR_NVS_NO_FREE_PAGES) { + ESP_ERROR_CHECK(nvs_flash_erase()); + err = nvs_flash_init(); + } + return err; +} + +esp_err_t NVSDevice_get_wifi_creds(GlobalState * GLOBAL_STATE, char ** wifi_ssid, char ** wifi_pass, char ** hostname) { + // pull the wifi credentials and hostname out of NVS + *wifi_ssid = nvs_config_get_string(NVS_CONFIG_WIFI_SSID, WIFI_SSID); + *wifi_pass = nvs_config_get_string(NVS_CONFIG_WIFI_PASS, WIFI_PASS); + *hostname = nvs_config_get_string(NVS_CONFIG_HOSTNAME, HOSTNAME); + + // copy the wifi ssid to the global state + strncpy(GLOBAL_STATE->SYSTEM_MODULE.ssid, *wifi_ssid, sizeof(GLOBAL_STATE->SYSTEM_MODULE.ssid)); + GLOBAL_STATE->SYSTEM_MODULE.ssid[sizeof(GLOBAL_STATE->SYSTEM_MODULE.ssid)-1] = 0; + + return ESP_OK; +} + +esp_err_t NVSDevice_parse_config(GlobalState * GLOBAL_STATE) { + + GLOBAL_STATE->POWER_MANAGEMENT_MODULE.frequency_value = nvs_config_get_u16(NVS_CONFIG_ASIC_FREQ, CONFIG_ASIC_FREQUENCY); + ESP_LOGI(TAG, "NVS_CONFIG_ASIC_FREQ %f", (float)GLOBAL_STATE->POWER_MANAGEMENT_MODULE.frequency_value); + + GLOBAL_STATE->device_model_str = nvs_config_get_string(NVS_CONFIG_DEVICE_MODEL, ""); + if (strcmp(GLOBAL_STATE->device_model_str, "max") == 0) { + ESP_LOGI(TAG, "DEVICE: Max"); + GLOBAL_STATE->device_model = DEVICE_MAX; + GLOBAL_STATE->asic_count = 1; + GLOBAL_STATE->voltage_domain = 1; + } else if (strcmp(GLOBAL_STATE->device_model_str, "ultra") == 0) { + ESP_LOGI(TAG, "DEVICE: Ultra"); + GLOBAL_STATE->device_model = DEVICE_ULTRA; + GLOBAL_STATE->asic_count = 1; + GLOBAL_STATE->voltage_domain = 1; + } else if (strcmp(GLOBAL_STATE->device_model_str, "supra") == 0) { + ESP_LOGI(TAG, "DEVICE: Supra"); + GLOBAL_STATE->device_model = DEVICE_SUPRA; + GLOBAL_STATE->asic_count = 1; + GLOBAL_STATE->voltage_domain = 1; + } else if (strcmp(GLOBAL_STATE->device_model_str, "gamma") == 0) { + ESP_LOGI(TAG, "DEVICE: Gamma"); + GLOBAL_STATE->device_model = DEVICE_GAMMA; + GLOBAL_STATE->asic_count = 1; + GLOBAL_STATE->voltage_domain = 1; + } else { + ESP_LOGE(TAG, "Invalid DEVICE model"); + // maybe should return here to now execute anything with a faulty device parameter ! + // this stops crashes/reboots and allows dev testing without an asic + GLOBAL_STATE->device_model = DEVICE_UNKNOWN; + GLOBAL_STATE->asic_count = -1; + GLOBAL_STATE->voltage_domain = 1; + + return ESP_FAIL; + } + + GLOBAL_STATE->board_version = atoi(nvs_config_get_string(NVS_CONFIG_BOARD_VERSION, "000")); + ESP_LOGI(TAG, "Found Device Model: %s", GLOBAL_STATE->device_model_str); + ESP_LOGI(TAG, "Found Board Version: %d", GLOBAL_STATE->board_version); + + GLOBAL_STATE->asic_model_str = nvs_config_get_string(NVS_CONFIG_ASIC_MODEL, ""); + if (strcmp(GLOBAL_STATE->asic_model_str, "BM1366") == 0) { + ESP_LOGI(TAG, "ASIC: %dx BM1366 (%" PRIu64 " cores)", GLOBAL_STATE->asic_count, BM1366_CORE_COUNT); + GLOBAL_STATE->asic_model = ASIC_BM1366; + AsicFunctions ASIC_functions = {.init_fn = BM1366_init, + .receive_result_fn = BM1366_proccess_work, + .set_max_baud_fn = BM1366_set_max_baud, + .set_difficulty_mask_fn = BM1366_set_job_difficulty_mask, + .send_work_fn = BM1366_send_work, + .set_version_mask = BM1366_set_version_mask}; + //GLOBAL_STATE.asic_job_frequency_ms = (NONCE_SPACE / (double) (GLOBAL_STATE.POWER_MANAGEMENT_MODULE.frequency_value * BM1366_CORE_COUNT * 1000)) / (double) GLOBAL_STATE.asic_count; // version-rolling so Small Cores have different Nonce Space + GLOBAL_STATE->asic_job_frequency_ms = 2000; //ms + GLOBAL_STATE->ASIC_difficulty = BM1366_ASIC_DIFFICULTY; + + GLOBAL_STATE->ASIC_functions = ASIC_functions; + } else if (strcmp(GLOBAL_STATE->asic_model_str, "BM1370") == 0) { + ESP_LOGI(TAG, "ASIC: %dx BM1370 (%" PRIu64 " cores)", GLOBAL_STATE->asic_count, BM1370_CORE_COUNT); + GLOBAL_STATE->asic_model = ASIC_BM1370; + AsicFunctions ASIC_functions = {.init_fn = BM1370_init, + .receive_result_fn = BM1370_proccess_work, + .set_max_baud_fn = BM1370_set_max_baud, + .set_difficulty_mask_fn = BM1370_set_job_difficulty_mask, + .send_work_fn = BM1370_send_work, + .set_version_mask = BM1370_set_version_mask}; + //GLOBAL_STATE.asic_job_frequency_ms = (NONCE_SPACE / (double) (GLOBAL_STATE.POWER_MANAGEMENT_MODULE.frequency_value * BM1370_CORE_COUNT * 1000)) / (double) GLOBAL_STATE.asic_count; // version-rolling so Small Cores have different Nonce Space + GLOBAL_STATE->asic_job_frequency_ms = 500; //ms + GLOBAL_STATE->ASIC_difficulty = BM1370_ASIC_DIFFICULTY; + + GLOBAL_STATE->ASIC_functions = ASIC_functions; + } else if (strcmp(GLOBAL_STATE->asic_model_str, "BM1368") == 0) { + ESP_LOGI(TAG, "ASIC: %dx BM1368 (%" PRIu64 " cores)", GLOBAL_STATE->asic_count, BM1368_CORE_COUNT); + GLOBAL_STATE->asic_model = ASIC_BM1368; + AsicFunctions ASIC_functions = {.init_fn = BM1368_init, + .receive_result_fn = BM1368_proccess_work, + .set_max_baud_fn = BM1368_set_max_baud, + .set_difficulty_mask_fn = BM1368_set_job_difficulty_mask, + .send_work_fn = BM1368_send_work, + .set_version_mask = BM1368_set_version_mask}; + //GLOBAL_STATE.asic_job_frequency_ms = (NONCE_SPACE / (double) (GLOBAL_STATE.POWER_MANAGEMENT_MODULE.frequency_value * BM1368_CORE_COUNT * 1000)) / (double) GLOBAL_STATE.asic_count; // version-rolling so Small Cores have different Nonce Space + GLOBAL_STATE->asic_job_frequency_ms = 500; //ms + GLOBAL_STATE->ASIC_difficulty = BM1368_ASIC_DIFFICULTY; + + GLOBAL_STATE->ASIC_functions = ASIC_functions; + } else if (strcmp(GLOBAL_STATE->asic_model_str, "BM1397") == 0) { + ESP_LOGI(TAG, "ASIC: %dx BM1397 (%" PRIu64 " cores)", GLOBAL_STATE->asic_count, BM1397_SMALL_CORE_COUNT); + GLOBAL_STATE->asic_model = ASIC_BM1397; + AsicFunctions ASIC_functions = {.init_fn = BM1397_init, + .receive_result_fn = BM1397_proccess_work, + .set_max_baud_fn = BM1397_set_max_baud, + .set_difficulty_mask_fn = BM1397_set_job_difficulty_mask, + .send_work_fn = BM1397_send_work, + .set_version_mask = BM1397_set_version_mask}; + GLOBAL_STATE->asic_job_frequency_ms = (NONCE_SPACE / (double) (GLOBAL_STATE->POWER_MANAGEMENT_MODULE.frequency_value * BM1397_SMALL_CORE_COUNT * 1000)) / (double) GLOBAL_STATE->asic_count; // no version-rolling so same Nonce Space is splitted between Small Cores + GLOBAL_STATE->ASIC_difficulty = BM1397_ASIC_DIFFICULTY; + + GLOBAL_STATE->ASIC_functions = ASIC_functions; + } else { + ESP_LOGE(TAG, "Invalid ASIC model"); + AsicFunctions ASIC_functions = {.init_fn = NULL, + .receive_result_fn = NULL, + .set_max_baud_fn = NULL, + .set_difficulty_mask_fn = NULL, + .send_work_fn = NULL}; + GLOBAL_STATE->ASIC_functions = ASIC_functions; + // maybe should return here to not execute anything with a faulty device parameter ! + return ESP_FAIL; + } + + return ESP_OK; +} \ No newline at end of file diff --git a/main/nvs_device.h b/main/nvs_device.h new file mode 100644 index 0000000..9f6e6e4 --- /dev/null +++ b/main/nvs_device.h @@ -0,0 +1,12 @@ +#ifndef MAIN_NVS_DEVICE_H +#define MAIN_NVS_DEVICE_H + +#include +#include "esp_err.h" +#include "global_state.h" + +esp_err_t NVSDevice_init(void); +esp_err_t NVSDevice_parse_config(GlobalState *); +esp_err_t NVSDevice_get_wifi_creds(GlobalState *, char **, char **, char **); + +#endif // MAIN_NVS_DEVICE_H diff --git a/main/self_test/self_test.c b/main/self_test/self_test.c index 868b23c..9cc090d 100644 --- a/main/self_test/self_test.c +++ b/main/self_test/self_test.c @@ -20,6 +20,16 @@ static const char * TAG = "self_test"; +bool should_test(GlobalState * GLOBAL_STATE) { + bool is_max = GLOBAL_STATE->asic_model == ASIC_BM1397; + uint64_t best_diff = nvs_config_get_u64(NVS_CONFIG_BEST_DIFF, 0); + uint16_t should_self_test = nvs_config_get_u16(NVS_CONFIG_SELF_TEST, 0); + if (should_self_test == 1 && !is_max && best_diff < 1) { + return true; + } + return false; +} + static void display_msg(char * msg, GlobalState * GLOBAL_STATE) { SystemModule * module = &GLOBAL_STATE->SYSTEM_MODULE; diff --git a/main/self_test/self_text.h b/main/self_test/self_test.h similarity index 65% rename from main/self_test/self_text.h rename to main/self_test/self_test.h index e694fc5..7e441ca 100644 --- a/main/self_test/self_text.h +++ b/main/self_test/self_test.h @@ -2,5 +2,6 @@ #define SELF_TEST_H_ void self_test(void * pvParameters); +bool should_test(GlobalState * GLOBAL_STATE); #endif \ No newline at end of file diff --git a/main/system.c b/main/system.c index c6cd011..02cc8f6 100644 --- a/main/system.c +++ b/main/system.c @@ -1,24 +1,3 @@ -#include "system.h" - -#include "esp_log.h" - -#include "i2c_bitaxe.h" -#include "EMC2101.h" -//#include "INA260.h" -#include "adc.h" -#include "connect.h" -#include "led_controller.h" -#include "nvs_config.h" -#include "oled.h" -#include "vcore.h" - -#include "driver/gpio.h" -#include "esp_app_desc.h" -#include "esp_netif.h" -#include "esp_timer.h" -#include "esp_wifi.h" -#include "lwip/inet.h" - #include #include #include @@ -30,13 +9,33 @@ #include "freertos/task.h" #include "freertos/queue.h" #include "driver/gpio.h" +#include "esp_log.h" + +#include "driver/gpio.h" +#include "esp_app_desc.h" +#include "esp_netif.h" +#include "esp_timer.h" +#include "esp_wifi.h" +#include "lwip/inet.h" + +#include "system.h" +#include "i2c_bitaxe.h" +#include "EMC2101.h" +#include "INA260.h" +#include "adc.h" +#include "connect.h" +#include "led_controller.h" +#include "nvs_config.h" +#include "oled.h" +#include "vcore.h" + + static const char * TAG = "SystemModule"; static void _suffix_string(uint64_t, char *, size_t, int); static esp_netif_t * netif; -static esp_netif_ip_info_t ip_info; QueueHandle_t user_input_queue; @@ -95,11 +94,15 @@ void SYSTEM_init_system(GlobalState * GLOBAL_STATE) // set the wifi_status to blank memset(module->wifi_status, 0, 20); +} + +void SYSTEM_init_peripherals(GlobalState * GLOBAL_STATE) { // Initialize the core voltage regulator VCORE_init(GLOBAL_STATE); VCORE_set_voltage(nvs_config_get_u16(NVS_CONFIG_ASIC_VOLTAGE, CONFIG_ASIC_VOLTAGE) / 1000.0, GLOBAL_STATE); + //init the EMC2101, if we have one switch (GLOBAL_STATE->device_model) { case DEVICE_MAX: case DEVICE_ULTRA: @@ -110,6 +113,20 @@ void SYSTEM_init_system(GlobalState * GLOBAL_STATE) default: } + //initialize the INA260, if we have one. + switch (GLOBAL_STATE->device_model) { + case DEVICE_MAX: + case DEVICE_ULTRA: + case DEVICE_SUPRA: + if (GLOBAL_STATE->board_version < 402) { + // Initialize the LED controller + INA260_init(); + } + break; + case DEVICE_GAMMA: + default: + } + vTaskDelay(500 / portTICK_PERIOD_MS); // Ensure overheat_mode config exists @@ -118,6 +135,7 @@ void SYSTEM_init_system(GlobalState * GLOBAL_STATE) ESP_LOGE(TAG, "Failed to ensure overheat_mode config"); } + //Init the OLED switch (GLOBAL_STATE->device_model) { case DEVICE_MAX: case DEVICE_ULTRA: @@ -143,8 +161,6 @@ void SYSTEM_init_system(GlobalState * GLOBAL_STATE) _init_connection(GLOBAL_STATE); } - - void SYSTEM_task(void * pvParameters) { GlobalState * GLOBAL_STATE = (GlobalState *) pvParameters; @@ -276,7 +292,7 @@ void SYSTEM_notify_found_nonce(GlobalState * GLOBAL_STATE, double found_diff, ui // Calculate the time difference in seconds with sub-second precision // hashrate = (nonce_difficulty * 2^32) / time_to_find - module->historical_hashrate[module->historical_hashrate_rolling_index] = GLOBAL_STATE->initial_ASIC_difficulty; + module->historical_hashrate[module->historical_hashrate_rolling_index] = GLOBAL_STATE->ASIC_difficulty; module->historical_hashrate_time_stamps[module->historical_hashrate_rolling_index] = esp_timer_get_time(); module->historical_hashrate_rolling_index = (module->historical_hashrate_rolling_index + 1) % HISTORY_LENGTH; @@ -319,6 +335,7 @@ void SYSTEM_notify_found_nonce(GlobalState * GLOBAL_STATE, double found_diff, ui static void _show_overheat_screen(GlobalState * GLOBAL_STATE) { SystemModule * module = &GLOBAL_STATE->SYSTEM_MODULE; + esp_netif_ip_info_t ip_info; switch (GLOBAL_STATE->device_model) { case DEVICE_MAX: @@ -384,6 +401,7 @@ static void _update_screen_two(GlobalState * GLOBAL_STATE) { SystemModule * module = &GLOBAL_STATE->SYSTEM_MODULE; + switch (GLOBAL_STATE->device_model) { case DEVICE_MAX: case DEVICE_ULTRA: diff --git a/main/system.h b/main/system.h index d8782dc..46a2540 100644 --- a/main/system.h +++ b/main/system.h @@ -4,6 +4,7 @@ #include "global_state.h" void SYSTEM_init_system(GlobalState * GLOBAL_STATE); +void SYSTEM_init_peripherals(GlobalState * GLOBAL_STATE); void SYSTEM_task(void * parameters); void SYSTEM_notify_accepted_share(GlobalState * GLOBAL_STATE); diff --git a/main/tasks/asic_result_task.c b/main/tasks/asic_result_task.c index 99dfd50..d81f1bd 100644 --- a/main/tasks/asic_result_task.c +++ b/main/tasks/asic_result_task.c @@ -15,8 +15,6 @@ void ASIC_result_task(void *pvParameters) { GlobalState *GLOBAL_STATE = (GlobalState *)pvParameters; - char *user = nvs_config_get_string(NVS_CONFIG_STRATUM_USER, STRATUM_USER); - while (1) { task_result *asic_result = (*GLOBAL_STATE->ASIC_functions.receive_result_fn)(GLOBAL_STATE); @@ -45,6 +43,7 @@ void ASIC_result_task(void *pvParameters) if (nonce_diff > GLOBAL_STATE->ASIC_TASK_MODULE.active_jobs[job_id]->pool_diff) { + char * user = GLOBAL_STATE->SYSTEM_MODULE.is_using_fallback ? nvs_config_get_string(NVS_CONFIG_FALLBACK_STRATUM_USER, FALLBACK_STRATUM_USER) : nvs_config_get_string(NVS_CONFIG_STRATUM_USER, STRATUM_USER); int ret = STRATUM_V1_submit_share( GLOBAL_STATE->sock, user, @@ -53,6 +52,7 @@ void ASIC_result_task(void *pvParameters) GLOBAL_STATE->ASIC_TASK_MODULE.active_jobs[job_id]->ntime, asic_result->nonce, asic_result->rolled_version ^ GLOBAL_STATE->ASIC_TASK_MODULE.active_jobs[job_id]->version); + free(user); if (ret < 0) { ESP_LOGI(TAG, "Unable to write share to socket. Closing connection. Ret: %d (errno %d: %s)", ret, errno, strerror(errno)); diff --git a/main/tasks/power_management_task.c b/main/tasks/power_management_task.c index 68a76b9..c7eb7b9 100644 --- a/main/tasks/power_management_task.c +++ b/main/tasks/power_management_task.c @@ -134,8 +134,6 @@ void POWER_MANAGEMENT_task(void * pvParameters) // The power reading from the TPS546 is only it's output power. So the rest of the Bitaxe power is not accounted for. power_management->power += SUPRA_POWER_OFFSET; // Add offset for the rest of the Bitaxe power. TODO: this better. } else { - INA260_init(); - if (INA260_installed() == true) { power_management->voltage = INA260_read_voltage(); power_management->current = INA260_read_current(); diff --git a/main/vcore.c b/main/vcore.c index f91dec1..71cd18a 100644 --- a/main/vcore.c +++ b/main/vcore.c @@ -37,7 +37,6 @@ uint8_t VCORE_init(GlobalState * global_state) { // case DEVICE_HEX: default: } - ADC_init(); return result; }