From 1f493d64626ac0f9519ca089b49d203f75f5ab58 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Sun, 26 May 2013 21:30:55 +1000 Subject: [PATCH] Iterate over spare bytes in the avalon result returned from a reset request trying to find the beginning of the reset. --- driver-avalon.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/driver-avalon.c b/driver-avalon.c index 758be6c6..7792943a 100644 --- a/driver-avalon.c +++ b/driver-avalon.c @@ -269,8 +269,8 @@ static int avalon_reset(struct cgpu_info *avalon, int fd) { struct avalon_result ar; struct avalon_task at; - uint8_t *buf; - int ret, i = 0; + uint8_t *buf, *tmp; + int ret, i, spare; struct timespec p; /* Send reset, then check for result */ @@ -294,12 +294,17 @@ static int avalon_reset(struct cgpu_info *avalon, int fd) p.tv_nsec = AVALON_RESET_PITCH; nanosleep(&p, NULL); - buf = (uint8_t *)&ar; - /* We may also get 0x00 and 0x18 first */ - if (buf[0] != 0xAA) - buf = &buf[1]; - if (buf[0] != 0xAA) - buf = &buf[1]; + /* Look for the first occurrence of 0xAA, the reset response should be: + * AA 55 AA 55 00 00 00 00 00 00 */ + spare = AVALON_READ_SIZE - 10; + tmp = (uint8_t *)&ar; + for (i = 0; i <= spare; i++) { + buf = &tmp[i]; + if (buf[0] == 0xAA) + break; + } + i = 0; + if (buf[0] == 0xAA && buf[1] == 0x55 && buf[2] == 0xAA && buf[3] == 0x55) { for (i = 4; i < 11; i++)