Mercurial > ~darius > hgwebdir.cgi > avr-lib
comparison 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 |
comparison
equal
deleted
inserted
replaced
18:0876867347de | 19:b5e4591b6570 |
---|---|
41 | 41 |
42 static uint8_t OW_LastDevice = 0; | 42 static uint8_t OW_LastDevice = 0; |
43 static uint8_t OW_LastDiscrepancy = 0; | 43 static uint8_t OW_LastDiscrepancy = 0; |
44 static uint8_t OW_LastFamilyDiscrepancy = 0; | 44 static uint8_t OW_LastFamilyDiscrepancy = 0; |
45 | 45 |
46 const PROGMEM char *OWProgROM_Status[] = { | 46 static const char __str1[] PROGMEM = "OK"; |
47 "OK", | 47 static const char __str2[] PROGMEM = "no HW support"; |
48 "no HW support", | 48 static const char __str3[] PROGMEM = "Invalid params"; |
49 "Invalid params", | 49 static const char __str4[] PROGMEM = "module missing/broken"; |
50 "module missing/broken" | 50 PGM_P const OWProgROM_Status[] PROGMEM = { |
51 __str1, | |
52 __str2, | |
53 __str3, | |
54 __str4 | |
51 }; | 55 }; |
52 | 56 |
53 /*----------------------------------------------------------------------------- | 57 /*----------------------------------------------------------------------------- |
54 * Configure the IO port as we need | 58 * Configure the IO port as we need |
55 */ | 59 */ |
304 | 308 |
305 OWPRINTFP(PSTR("bit_test = %d\r\n"), bit_test); | 309 OWPRINTFP(PSTR("bit_test = %d\r\n"), bit_test); |
306 | 310 |
307 /* check for no devices on 1-wire */ | 311 /* check for no devices on 1-wire */ |
308 if (bit_test == 3) { | 312 if (bit_test == 3) { |
313 /* 11 */ | |
309 OWPRINTFP(PSTR("bit_test = %d\r\n"), bit_test); | 314 OWPRINTFP(PSTR("bit_test = %d\r\n"), bit_test); |
310 return(OW_BADWIRE); | 315 return(OW_NOMODULES); |
311 } | 316 } |
317 /* all devices coupled have 0 or 1 */ | |
318 if (bit_test != 0) | |
319 /* 10 or 01 */ | |
320 search_direction = !(bit_test & 0x01); /* bit write value for search */ | |
312 else { | 321 else { |
313 /* all devices coupled have 0 or 1 */ | 322 /* 00 */ |
314 if (bit_test > 0) | 323 /* if this discrepancy is before the Last Discrepancy |
315 search_direction = !(bit_test & 0x01); /* bit write value for search */ | 324 * on a previous OWNext then pick the same as last time */ |
316 else { | 325 if (bit_number < OW_LastDiscrepancy) |
317 /* if this discrepancy is before the Last Discrepancy | 326 search_direction = (ROM[rom_byte_number] & rom_byte_mask) > 0; |
318 * on a previous OWNext then pick the same as last time */ | 327 else |
319 if (bit_number < OW_LastDiscrepancy) | 328 /* if equal to last pick 1, if not then pick 0 */ |
320 search_direction = ((ROM[rom_byte_number] & rom_byte_mask) > 0); | 329 search_direction = bit_number == OW_LastDiscrepancy; |
321 else | 330 |
322 /* if equal to last pick 1, if not then pick 0 */ | 331 /* if 0 was picked then record its position in LastZero */ |
323 search_direction = (bit_number == OW_LastDiscrepancy); | 332 if (search_direction == 0) { |
324 | 333 last_zero = bit_number; |
325 /* if 0 was picked then record its position in LastZero */ | 334 |
326 if (search_direction == 0) { | 335 /* check for Last discrepancy in family */ |
327 last_zero = bit_number; | 336 if (last_zero < 9) |
328 | 337 OW_LastFamilyDiscrepancy = last_zero; |
329 /* check for Last discrepancy in family */ | |
330 if (last_zero < 9) | |
331 OW_LastFamilyDiscrepancy = last_zero; | |
332 } | |
333 } | 338 } |
334 | 339 } |
335 /* set or clear the bit in the ROM byte rom_byte_number | 340 |
336 * with mask rom_byte_mask */ | 341 /* set or clear the bit in the ROM byte rom_byte_number |
337 if (search_direction == 1) | 342 * with mask rom_byte_mask */ |
338 ROM[rom_byte_number] |= rom_byte_mask; | 343 if (search_direction == 1) |
339 else | 344 ROM[rom_byte_number] |= rom_byte_mask; |
340 ROM[rom_byte_number] &= ~rom_byte_mask; | 345 else |
341 | 346 ROM[rom_byte_number] &= ~rom_byte_mask; |
342 /* serial number search direction write bit */ | 347 |
343 OWWriteBit(search_direction); | 348 /* serial number search direction write bit */ |
344 | 349 OWWriteBit(search_direction); |
345 /* increment the byte counter bit_number | 350 |
346 * and shift the mask rom_byte_mask */ | 351 /* increment the byte counter bit_number |
347 bit_number++; | 352 * and shift the mask rom_byte_mask */ |
348 rom_byte_mask <<= 1; | 353 bit_number++; |
349 | 354 rom_byte_mask <<= 1; |
350 /* if the mask is 0 then go to new ROM byte rom_byte_number | 355 |
351 * and reset mask */ | 356 /* if the mask is 0 then go to new ROM byte rom_byte_number |
352 if (rom_byte_mask == 0) { | 357 * and reset mask */ |
353 OWCRC(ROM[rom_byte_number], &crcaccum); /* accumulate the CRC */ | 358 if (rom_byte_mask == 0) { |
354 lastcrc8 = crcaccum; | 359 OWCRC(ROM[rom_byte_number], &crcaccum); /* accumulate the CRC */ |
360 lastcrc8 = crcaccum; | |
355 | 361 |
356 rom_byte_number++; | 362 rom_byte_number++; |
357 rom_byte_mask = 1; | 363 rom_byte_mask = 1; |
358 } | |
359 } | 364 } |
360 } while (rom_byte_number < 8); /* loop until through all ROM bytes 0-7 */ | 365 } while (rom_byte_number < 8); /* loop until through all ROM bytes 0-7 */ |
361 | 366 |
362 /* if the search was successful then */ | 367 /* if the search was successful then */ |
363 if (!(bit_number < 65) || lastcrc8) { | 368 if (!(bit_number < 65) || lastcrc8) { |
387 | 392 |
388 return next_result; | 393 return next_result; |
389 | 394 |
390 } | 395 } |
391 | 396 |
392 uint8_t PROGMEM dscrc_table[] = { | 397 const uint8_t dscrc_table[] PROGMEM = { |
393 0, 94, 188, 226, 97, 63, 221, 131, 194, 156, 126, 32, 163, 253, 31, 65, | 398 0, 94, 188, 226, 97, 63, 221, 131, 194, 156, 126, 32, 163, 253, 31, 65, |
394 157, 195, 33, 127, 252, 162, 64, 30, 95, 1, 227, 189, 62, 96, 130, 220, | 399 157, 195, 33, 127, 252, 162, 64, 30, 95, 1, 227, 189, 62, 96, 130, 220, |
395 35, 125, 159, 193, 66, 28, 254, 160, 225, 191, 93, 3, 128, 222, 60, 98, | 400 35, 125, 159, 193, 66, 28, 254, 160, 225, 191, 93, 3, 128, 222, 60, 98, |
396 190, 224, 2, 92, 223, 129, 99, 61, 124, 34, 192, 158, 29, 67, 161, 255, | 401 190, 224, 2, 92, 223, 129, 99, 61, 124, 34, 192, 158, 29, 67, 161, 255, |
397 70, 24, 250, 164, 39, 121, 155, 197, 132, 218, 56, 102, 229, 187, 89, 7, | 402 70, 24, 250, 164, 39, 121, 155, 197, 132, 218, 56, 102, 229, 187, 89, 7, |
506 OWDELAY_H; | 511 OWDELAY_H; |
507 OWSETVPPOFF(); | 512 OWSETVPPOFF(); |
508 | 513 |
509 tmp = OWReadByte(); | 514 tmp = OWReadByte(); |
510 | 515 |
511 /* Check the bits we turned off are off */ | 516 /* Verify */ |
512 /* | 517 if (data[i] != tmp) { |
513 for (i = 0; i < 8; i++) | |
514 if (!(data[i] & 1 << i) && (tmp & 1 << i)) | |
515 return(-3); | |
516 */ | |
517 if ((!data[i] & tmp) != 0) { | |
518 cons_putsP(PSTR("Readback mismatch ")); | 518 cons_putsP(PSTR("Readback mismatch ")); |
519 cons_puts_hex(data[i]); | 519 cons_puts_hex(data[i]); |
520 cons_putsP(PSTR(" vs ")); | 520 cons_putsP(PSTR(" vs ")); |
521 cons_puts_hex(data[i]); | 521 cons_puts_hex(data[i]); |
522 cons_putsP(PSTR("\r\n")); | 522 cons_putsP(PSTR("\r\n")); |