Iterate over spare bytes in the avalon result returned from a reset request trying to find the beginning of the reset.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
diff --git a/driver-avalon.c b/driver-avalon.c
index 758be6c..7792943 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++)