Compare commits

..

No commits in common. "7844102336a442f793121aed4ca74db7aa4818b0" and "6a0469418001fa31c706ed7661be55bca2087d5c" have entirely different histories.

16 changed files with 60 additions and 40966 deletions

View File

@ -3,6 +3,7 @@
#ifdef T_DISPLAY
#include <TFT_eSPI.h>
#include "media/images_320_170.h"
#include "media/myFonts.h"
#include "media/Free_Fonts.h"
#include "version.h"
@ -10,12 +11,6 @@
#include "OpenFontRender.h"
#include "rotation.h"
#ifdef NERD_NOS
#include "media/images_NOS_320_170.h"
#else
#include "media/images_320_170.h"
#endif
#define WIDTH 340
#define HEIGHT 170
@ -88,9 +83,9 @@ void tDisplay_MinerScreen(unsigned long mElapsed)
// Total hashes
render.setFontSize(18);
render.rdrawString(data.totalMHashes.c_str(), 268, 138, TFT_BLACK);
// ASIC temp
// Block templates
render.setFontSize(18);
render.drawString(data.currentTemperature.c_str(), 186, 20, 0xDEDB);
render.drawString(data.templates.c_str(), 186, 20, 0xDEDB);
// Best diff
render.drawString(data.bestDiff.c_str(), 186, 48, 0xDEDB);
// 32Bit shares

View File

@ -48,8 +48,6 @@ typedef struct __attribute__((__packed__))
static const char *TAG = "bm1397Module";
static const uint8_t chip_id[] = {0xAA, 0x55, 0x13, 0x97, 0x18, 0x00};
uint32_t increment_bitmask(const uint32_t value, const uint32_t mask);
/// @brief
@ -206,8 +204,9 @@ static uint8_t _send_init(uint64_t frequency, uint16_t asic_count)
int chip_counter = 0;
while (true) {
int received = SERIAL_rx(buf, 9, 1000);
if (received > 0 && !memcmp(chip_id, buf, sizeof(chip_id))) {
int received = SERIAL_rx(buf, 11, 1000);
if (received > 0) {
//ESP_LOG_BUFFER_HEX(TAG, asic_response_buffer, received);
chip_counter++;
} else {
break;
@ -362,23 +361,24 @@ bool BM1397_receive_work(uint16_t timeout, asic_result *result)
{
uint8_t *rcv_buf = (uint8_t*) result;
// non blocking read
int received = SERIAL_rx_non_blocking(rcv_buf, 9);
// wait for a response, wait time is pretty arbitrary
int received = SERIAL_rx(rcv_buf, 9, timeout);
if (received < 0)
{
Serial.println("Error in serial RX");
return false;
}
else if (!received)
else if (received == 0)
{
// we have not received any data
// Didn't find a solution, restart and try again
return false;
}
if (received != 9 || rcv_buf[0] != 0xAA || rcv_buf[1] != 0x55)
{
Serial.println("Serial RX invalid. Resetting receive buffer ...");
//ESP_LOG_BUFFER_HEX(TAG, asic_response_buffer, received);
SERIAL_clear_buffer();
return false;
}

File diff suppressed because it is too large Load Diff

Binary file not shown.

Before

Width:  |  Height:  |  Size: 41 KiB

File diff suppressed because it is too large Load Diff

Binary file not shown.

Before

Width:  |  Height:  |  Size: 40 KiB

File diff suppressed because it is too large Load Diff

Binary file not shown.

Before

Width:  |  Height:  |  Size: 49 KiB

File diff suppressed because it is too large Load Diff

Binary file not shown.

Before

Width:  |  Height:  |  Size: 58 KiB

File diff suppressed because it is too large Load Diff

Binary file not shown.

Before

Width:  |  Height:  |  Size: 73 KiB

View File

@ -57,28 +57,6 @@ size_t SERIAL_check_for_data() {
return length;
}
/// @brief waits for a serial response from the device
/// @param buf buffer to read data into
/// @param buf number of ms to wait before timing out
/// @return number of bytes read, or -1 on error
int16_t SERIAL_rx_non_blocking(uint8_t *buf, uint16_t size) {
// check how much data we have
size_t available = SERIAL_check_for_data();
// no data available, return 0
if (!available) {
return 0;
}
// check for incomplete data
if (available && available < size) {
Serial.printf("not returning incomplete data ... %d vs %d\n", (int) available, (int) size);
return 0;
}
// timeout 0 means non_blocking read
return SERIAL_rx(buf, size, 0);
}
/// @brief waits for a serial response from the device
/// @param buf buffer to read data into
@ -86,6 +64,13 @@ int16_t SERIAL_rx_non_blocking(uint8_t *buf, uint16_t size) {
/// @return number of bytes read, or -1 on error
int16_t SERIAL_rx(uint8_t *buf, uint16_t size, uint16_t timeout_ms)
{
// don't return incomplete data
size_t available = SERIAL_check_for_data();
if (available && available < size) {
Serial.printf("not returning parts of data ... %d vs %d\n", (int) available, (int) size);
return 0;
}
int16_t bytes_read = uart_read_bytes(UART_NUM_1, buf, size, timeout_ms / portTICK_PERIOD_MS);
// if (bytes_read > 0) {
// printf("rx: ");
@ -98,6 +83,21 @@ int16_t SERIAL_rx(uint8_t *buf, uint16_t size, uint16_t timeout_ms)
return bytes_read;
}
void SERIAL_debug_rx(void)
{
int ret;
uint8_t buf[CHUNK_SIZE];
ret = SERIAL_rx(buf, 100, 20);
if (ret < 0)
{
fprintf(stderr, "unable to read data\n");
return;
}
memset(buf, 0, 1024);
}
void SERIAL_clear_buffer(void)
{
uart_flush(UART_NUM_1);

View File

@ -4,8 +4,8 @@
int SERIAL_send(uint8_t *, int, bool);
void SERIAL_init(void);
void SERIAL_debug_rx(void);
int16_t SERIAL_rx(uint8_t *, uint16_t, uint16_t);
int16_t SERIAL_rx_non_blocking(uint8_t *buf, uint16_t size);
void SERIAL_clear_buffer(void);
void SERIAL_set_baud(int baud);

File diff suppressed because it is too large Load Diff

View File

@ -29,8 +29,6 @@ extern pthread_mutex_t job_mutex;
extern double best_diff;
extern unsigned long mLastTXtoPool;
extern uint32_t shares;
extern uint32_t valids;
// we can have 32 different job ids
#define ASIC_JOB_COUNT 32
@ -100,9 +98,6 @@ static void calculate_hashrate(history_t *history, uint32_t diff) {
}
history->newest++;
// Increment the global shares counter
shares++;
}
// triggers the job creation
@ -155,34 +150,34 @@ void runASIC(void * task_id) {
uint32_t current_difficulty = 0;
while (mMiner.inRun) {
// Temperature check
unsigned long currentTime = millis();
if (currentTime - lastTempCheck > TEMP_CHECK_INTERVAL) {
float currentTemp = nerdnos_get_temperature(); // Get ASIC temperature
if (currentTemp > MAX_SAFE_TEMP) {
gpio_set_level(NERD_NOS_GPIO_PEN, 0); // Disable Buck
Serial.println("ASIC temperature too high. Disabling power.");
// Wait for temperature to drop
while (nerdnos_get_temperature() > (MAX_SAFE_TEMP - 15)) { // 15 degree hysteresis
vTaskDelay(2000 / portTICK_PERIOD_MS); // Check every 2 second
}
gpio_set_level(NERD_NOS_GPIO_PEN, 1); // Enable Buck again
Serial.println("Temperature safe. Re-enabling ASIC.");
BM1397_init(200, 1); // Re-Init ASIC
}
lastTempCheck = currentTime;
}
// wait for the timer to start a new job
// also yields the CPU
pthread_mutex_lock(&job_interval_mutex);
pthread_cond_wait(&job_interval_cond, &job_interval_mutex);
pthread_mutex_unlock(&job_interval_mutex);
// Temperature check
unsigned long currentTime = millis();
if (currentTime - lastTempCheck > TEMP_CHECK_INTERVAL) {
float currentTemp = nerdnos_get_temperature(); // Get ASIC temperature
if (currentTemp > MAX_SAFE_TEMP) {
gpio_set_level(NERD_NOS_GPIO_PEN, 0); // Disable Buck
Serial.println("ASIC temperature too high. Disabling power.");
// Wait for temperature to drop
while (nerdnos_get_temperature() > (MAX_SAFE_TEMP - 15)) { // 15 degree hysteresis
vTaskDelay(2000 / portTICK_PERIOD_MS); // Check every 2 second
}
gpio_set_level(NERD_NOS_GPIO_PEN, 1); // Enable Buck again
Serial.println("Temperature safe. Re-enabling ASIC.");
BM1397_init(200, 1); // Re-Init ASIC
}
lastTempCheck = currentTime;
}
// increment extranonce2
extranonce_2++;
@ -196,15 +191,13 @@ void runASIC(void * task_id) {
// make sure that another task doesn't mess with the data while
// we are using it
pthread_mutex_lock(&job_mutex);
nerdnos_create_job(&mWorker, &mJob, &asic_jobs[asic_job_id], extranonce_2, mMiner.poolDifficulty);
pthread_mutex_unlock(&job_mutex);
// don't send difficulty while the job mutex is locked
if (current_difficulty != asic_jobs[asic_job_id].pool_diff) {
current_difficulty = asic_jobs[asic_job_id].pool_diff;
if (current_difficulty != mMiner.poolDifficulty) {
current_difficulty = mMiner.poolDifficulty;
nerdnos_set_asic_difficulty(current_difficulty);
Serial.printf("Set difficulty to %lu\n", current_difficulty);
}
nerdnos_create_job(&mWorker, &mJob, &asic_jobs[asic_job_id], extranonce_2, current_difficulty);
pthread_mutex_unlock(&job_mutex);
// send the job and
nerdnos_send_work(&asic_jobs[asic_job_id], asic_job_id);