Skip to content
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
20 changes: 14 additions & 6 deletions firmware/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ static int g_local_work = 0;
static int g_hw_work = 0;

uint32_t g_clock_conf_count = 0;

uint16_t temperature0[10] = {0};
uint16_t temperature1[10] = {0};

static uint32_t g_nonce2_offset = 0;
static uint32_t g_nonce2_range = 0xffffffff;
Expand Down Expand Up @@ -82,10 +83,11 @@ static void encode_pkg(uint8_t *p, int type, uint8_t *buf, unsigned int len)
case AVA2_P_ACKDETECT:
case AVA2_P_NONCE:
case AVA2_P_TEST_RET:
case AVA2_P_INFO_RET:
memcpy(data, buf, len);
break;
case AVA2_P_STATUS:
tmp = read_temp0() << 16 | read_temp1();
tmp = read_temp0(temperature0) << 16 | read_temp1(temperature1);
memcpy(data + 0, &tmp, 4);

tmp = read_fan0() << 16 | read_fan1();
Expand Down Expand Up @@ -229,7 +231,7 @@ static int decode_pkg(uint8_t *p, struct mm_work *mw)
case AVA2_P_REQUIRE:
break;
case AVA2_P_SET:
if (read_temp0() >= IDLE_TEMP || read_temp1() >= IDLE_TEMP)
if (read_temp0(temperature0) >= IDLE_TEMP || read_temp1(temperature1) >= IDLE_TEMP)
break;

memcpy(&tmp, data, 4);
Expand Down Expand Up @@ -262,6 +264,13 @@ static int decode_pkg(uint8_t *p, struct mm_work *mw)
set_voltage(ASIC_0V);
gpio_led(0);
break;
case AVA2_P_INFO:
memcpy(&tmp, data + 28, 4);
if (g_module_id != tmp)
break;

send_pkg(AVA2_P_INFO_RET, hardware_info, sizeof(hardware_info));
break;
default:
break;
}
Expand Down Expand Up @@ -327,7 +336,6 @@ static int get_pkg(struct mm_work *mw)

start = 0;
count = 2;

if (decode_pkg(g_pkg, mw)) {
#ifdef CFG_ENABLE_ACK
send_pkg(AVA2_P_NAK, NULL, 0);
Expand Down Expand Up @@ -385,7 +393,7 @@ int main(int argv, char **argc)

uart_init();
debug32("%d:MM-%s\n", g_module_id, MM_VERSION);
debug32("T:%d, %d\n", read_temp0(), read_temp1());
debug32("T:%d, %d\n", read_temp0(temperature0), read_temp1(temperature1));

timer_set(0, IDLE_TIME);
g_new_stratum = 0;
Expand All @@ -403,7 +411,7 @@ int main(int argv, char **argc)

wdg_feed((CPU_FREQUENCY / 1000) * 2);
if ((!timer_read(0) && g_new_stratum) ||
(read_temp0() >= IDLE_TEMP && read_temp1() >= IDLE_TEMP)) {
(read_temp0(temperature0) >= IDLE_TEMP && read_temp1(temperature1) >= IDLE_TEMP)) {
g_new_stratum = 0;
g_local_work = 0;
g_hw_work = 0;
Expand Down
24 changes: 23 additions & 1 deletion firmware/miner.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,28 @@
#include "alink.h"
#include "twipwm.h"

uint8_t hardware_info[0x1c] = {
#if defined(AVALON2_A3255_MACHINE)
0,0,0x8a,0, /* minimum voltage: 1V */
0,0,0x8a,0, /* default voltage: 1V */
0,0,0x8a,0, /* maximum voltage: 1V */
0,0,5,0xdc, /* minimum clock: 1500 MHz */
0,0,5,0xdc, /* default clock: 1500 MHz */
0,0,5,0xdc, /* maximum clock: 1500 MHz */
#elif defined(AVALON3_A3233_MACHINE) || defined(AVALON3_A3233_CARD)
0,0,0xe1,0, /* minimum voltage: 0.6625V */
0,0,0xe1,0, /* default voltage: 0.6625V */
0,0,0xe1,0, /* maximum voltage: 0.6625V */
0,0,1,0xc2, /* minimum clock: 450 MHz */
0,0,1,0xc2, /* default clock: 450 MHz */
0,0,1,0xc2, /* maximum clock: 450 MHz */
#else
# error "Please define hardware_info for this platform"
#endif
20, /* max merkle links */
(AVA2_P_COINBASE_SIZE >> 0x10) & 0xff, (AVA2_P_COINBASE_SIZE >> 8) & 0xff, AVA2_P_COINBASE_SIZE & 0xff,
};

static uint32_t g_asic_freq = ASIC_FREQUENCY;

static inline void flip32(void *dest_p, const void *src_p)
Expand Down Expand Up @@ -248,7 +270,7 @@ void miner_gen_nonce2_work(struct mm_work *mw, uint32_t nonce2, struct work *wor
tmp32 = bswap_32(nonce2);
work->nonce2 = nonce2;

if(mw->coinbase_len > AVA2_P_COINBASE_SIZE) {
if (mw->coinbase_len > AVA2_P_COINBASE_SIZE) {
nonce2_offset_posthash = (mw->nonce2_offset % SHA256_BLOCK_SIZE) + 32;
coinbase_len_posthash = mw->coinbase_len - mw->nonce2_offset + (mw->nonce2_offset % SHA256_BLOCK_SIZE);
memcpy(mw->coinbase + nonce2_offset_posthash, (uint8_t *)(&tmp32), mw->nonce2_size);
Expand Down
2 changes: 2 additions & 0 deletions firmware/miner.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,6 @@ int test_nonce(struct mm_work *mw, struct result *ret);
void set_asic_freq(uint32_t value);
uint32_t get_asic_freq();

extern uint8_t hardware_info[0x1c];

#endif /* __MINER_H__ */
2 changes: 2 additions & 0 deletions firmware/protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,7 @@
#define AVA2_P_STATUS 24
#define AVA2_P_ACKDETECT 25
#define AVA2_P_TEST_RET 26
#define AVA2_P_INFO 28
#define AVA2_P_INFO_RET 29

#endif /* _PROTOCOL_H_ */
43 changes: 38 additions & 5 deletions firmware/twipwm.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include "defines.h"
#include "io.h"


static struct lm32_twipwm *tp = (struct lm32_twipwm *)TWIPWM_BASE;

static void twi_start(void)
Expand Down Expand Up @@ -120,12 +119,46 @@ void adjust_fan(uint32_t pwm)
write_pwm(value);
}

uint16_t read_temp0()
uint16_t read_temp0(uint16_t *temperature)
{
return (twi_read_2byte(LM32_TWI_REG_TEMP0) >> 4) / 16;
int i;
uint32_t sum = 0;
uint16_t min = temperature[0];
uint16_t max = temperature[0];
uint16_t temp[10] = {0};

memcpy(temp, temperature + 1, 9 * sizeof(uint16_t));
temp[9] = (twi_read_2byte(LM32_TWI_REG_TEMP0) >> 4) / 16;
memcpy(temperature, temp, 10 * sizeof(uint16_t));
for(i = 0; i < 10; i++)
{
if(max < temperature[i])
max = temperature[i];
if(min > temp[i])
min = temperature[i];
sum = sum + temperature[i];
}
return (uint16_t)((sum - max - min) / 8);
}

uint16_t read_temp1()
uint16_t read_temp1(uint16_t *temperature)
{
return (twi_read_2byte(LM32_TWI_REG_TEMP1) >> 4) / 16;
int i;
uint32_t sum = 0;
uint16_t min = temperature[0];
uint16_t max = temperature[0];
uint16_t temp[10] = {0};

memcpy(temp, temperature + 1, 9 * sizeof(uint16_t));
temp[9] = (twi_read_2byte(LM32_TWI_REG_TEMP0) >> 4) / 16;
memcpy(temperature, temp, 10 * sizeof(uint16_t));
for(i = 0; i < 10; i++)
{
if(max < temperature[i])
max = temperature[i];
if(min > temp[i])
min = temperature[i];
sum = sum + temperature[i];
}
return (uint16_t)((sum - max - min) / 8);
}
4 changes: 2 additions & 2 deletions firmware/twipwm.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ void wdg_feed(uint32_t value);
uint32_t read_fan0();
uint32_t read_fan1();

uint16_t read_temp0();
uint16_t read_temp1();
uint16_t read_temp0(uint16_t *temperature);
uint16_t read_temp1(uint16_t *temperature);

void adjust_fan(uint32_t pwm);
void reset();
Expand Down