Mercurial > ~darius > hgwebdir.cgi > avr-lib
diff 1wire.c @ 19:b5e4591b6570
- Satisfy new compiler
- Put strings in PROGMEM
- Add various time functions
author | Daniel O'Connor <darius@dons.net.au> |
---|---|
date | Sat, 31 Jan 2015 23:27:10 +1030 |
parents | 0876867347de |
children |
line wrap: on
line diff
--- a/1wire.c Sat Jan 31 23:26:21 2015 +1030 +++ b/1wire.c Sat Jan 31 23:27:10 2015 +1030 @@ -43,11 +43,15 @@ static uint8_t OW_LastDiscrepancy = 0; static uint8_t OW_LastFamilyDiscrepancy = 0; -const PROGMEM char *OWProgROM_Status[] = { - "OK", - "no HW support", - "Invalid params", - "module missing/broken" +static const char __str1[] PROGMEM = "OK"; +static const char __str2[] PROGMEM = "no HW support"; +static const char __str3[] PROGMEM = "Invalid params"; +static const char __str4[] PROGMEM = "module missing/broken"; +PGM_P const OWProgROM_Status[] PROGMEM = { + __str1, + __str2, + __str3, + __str4 }; /*----------------------------------------------------------------------------- @@ -306,56 +310,57 @@ /* check for no devices on 1-wire */ if (bit_test == 3) { + /* 11 */ OWPRINTFP(PSTR("bit_test = %d\r\n"), bit_test); - return(OW_BADWIRE); + return(OW_NOMODULES); } + /* all devices coupled have 0 or 1 */ + if (bit_test != 0) + /* 10 or 01 */ + search_direction = !(bit_test & 0x01); /* bit write value for search */ else { - /* all devices coupled have 0 or 1 */ - if (bit_test > 0) - search_direction = !(bit_test & 0x01); /* bit write value for search */ - else { - /* if this discrepancy is before the Last Discrepancy - * on a previous OWNext then pick the same as last time */ - if (bit_number < OW_LastDiscrepancy) - search_direction = ((ROM[rom_byte_number] & rom_byte_mask) > 0); - else - /* if equal to last pick 1, if not then pick 0 */ - search_direction = (bit_number == OW_LastDiscrepancy); + /* 00 */ + /* if this discrepancy is before the Last Discrepancy + * on a previous OWNext then pick the same as last time */ + if (bit_number < OW_LastDiscrepancy) + search_direction = (ROM[rom_byte_number] & rom_byte_mask) > 0; + else + /* if equal to last pick 1, if not then pick 0 */ + search_direction = bit_number == OW_LastDiscrepancy; - /* if 0 was picked then record its position in LastZero */ - if (search_direction == 0) { - last_zero = bit_number; + /* if 0 was picked then record its position in LastZero */ + if (search_direction == 0) { + last_zero = bit_number; - /* check for Last discrepancy in family */ - if (last_zero < 9) - OW_LastFamilyDiscrepancy = last_zero; - } + /* check for Last discrepancy in family */ + if (last_zero < 9) + OW_LastFamilyDiscrepancy = last_zero; } + } - /* set or clear the bit in the ROM byte rom_byte_number - * with mask rom_byte_mask */ - if (search_direction == 1) - ROM[rom_byte_number] |= rom_byte_mask; - else - ROM[rom_byte_number] &= ~rom_byte_mask; + /* set or clear the bit in the ROM byte rom_byte_number + * with mask rom_byte_mask */ + if (search_direction == 1) + ROM[rom_byte_number] |= rom_byte_mask; + else + ROM[rom_byte_number] &= ~rom_byte_mask; - /* serial number search direction write bit */ - OWWriteBit(search_direction); + /* serial number search direction write bit */ + OWWriteBit(search_direction); - /* increment the byte counter bit_number - * and shift the mask rom_byte_mask */ - bit_number++; - rom_byte_mask <<= 1; + /* increment the byte counter bit_number + * and shift the mask rom_byte_mask */ + bit_number++; + rom_byte_mask <<= 1; - /* if the mask is 0 then go to new ROM byte rom_byte_number - * and reset mask */ - if (rom_byte_mask == 0) { - OWCRC(ROM[rom_byte_number], &crcaccum); /* accumulate the CRC */ - lastcrc8 = crcaccum; + /* if the mask is 0 then go to new ROM byte rom_byte_number + * and reset mask */ + if (rom_byte_mask == 0) { + OWCRC(ROM[rom_byte_number], &crcaccum); /* accumulate the CRC */ + lastcrc8 = crcaccum; - rom_byte_number++; - rom_byte_mask = 1; - } + rom_byte_number++; + rom_byte_mask = 1; } } while (rom_byte_number < 8); /* loop until through all ROM bytes 0-7 */ @@ -389,7 +394,7 @@ } -uint8_t PROGMEM dscrc_table[] = { +const uint8_t dscrc_table[] PROGMEM = { 0, 94, 188, 226, 97, 63, 221, 131, 194, 156, 126, 32, 163, 253, 31, 65, 157, 195, 33, 127, 252, 162, 64, 30, 95, 1, 227, 189, 62, 96, 130, 220, 35, 125, 159, 193, 66, 28, 254, 160, 225, 191, 93, 3, 128, 222, 60, 98, @@ -508,13 +513,8 @@ tmp = OWReadByte(); - /* Check the bits we turned off are off */ -/* - for (i = 0; i < 8; i++) - if (!(data[i] & 1 << i) && (tmp & 1 << i)) - return(-3); -*/ - if ((!data[i] & tmp) != 0) { + /* Verify */ + if (data[i] != tmp) { cons_putsP(PSTR("Readback mismatch ")); cons_puts_hex(data[i]); cons_putsP(PSTR(" vs "));