1 ///////////////////////////////////////////////////////////////////////////////
\r
3 // IAR Atmel AVR C/C++ Compiler V4.30F/W32 13/Mar/2008 04:49:36 /
\r
4 // Copyright 1996-2007 IAR Systems. All rights reserved. /
\r
6 // Source file = C:\home\kevin\pub\src\bc100\IAR\OWI.c /
\r
7 // Command line = C:\home\kevin\pub\src\bc100\IAR\OWI.c /
\r
8 // --cpu=tiny861 -ms -o C:\home\kevin\pub\src\bc1 /
\r
9 // 00\IAR\Release\Obj\ -D NDEBUG -lCN /
\r
10 // C:\home\kevin\pub\src\bc100\IAR\Release\List\ /
\r
11 // -lB C:\home\kevin\pub\src\bc100\IAR\Release\Li /
\r
12 // st\ --initializers_in_flash -s9 /
\r
13 // --no_cross_call --no_tbaa /
\r
14 // -DENABLE_BIT_DEFINITIONS -e -I "C:\Program /
\r
15 // Files\IAR Systems\Embedded Workbench /
\r
16 // 4.0\avr\INC\" -I "C:\Program Files\IAR /
\r
17 // Systems\Embedded Workbench 4.0\avr\INC\CLIB\" /
\r
18 // --eeprom_size 512 --misrac=5-9,11-12,14,16-17, /
\r
19 // 19-21,24-26,29-32,34-35,38-39,42-43,46,50, /
\r
20 // 52-54,56-59,61-62,64-65,68-80,83-84,87-91, /
\r
21 // 94-95,98-100,103-110,112-126 /
\r
22 // Enabled MISRA C rules = 5-9,11-12,14,16-17,19-21,24-26,29-32,34-35, /
\r
23 // 38-39,42-43,46,50,52-54,56-59,61-62,64-65, /
\r
24 // 68-80,83-84,87-91,94-95,98-100,103-110,112-126 /
\r
25 // Checked = 5,7-9,11-12,14,17,19-21,24,29-32,34-35,38-39, /
\r
26 // 42,46,50,52-54,56-59,61-62,64,68-69,71-80, /
\r
27 // 83-84,87-89,91,94-95,98,100,104-105,108-109, /
\r
28 // 112-115,118-126 /
\r
29 // Not checked = 6,16,25-26,43,65,70,90,99,103,106-107,110, /
\r
31 // List file = C:\home\kevin\pub\src\bc100\IAR\Release\List\O /
\r
35 ///////////////////////////////////////////////////////////////////////////////
\r
39 RSEG CSTACK:DATA:NOROOT(0)
\r
40 RSEG RSTACK:DATA:NOROOT(0)
\r
42 EXTERN ?Register_R4_is_cg_reg
\r
43 EXTERN ?Register_R5_is_cg_reg
\r
44 EXTERN ?Register_R6_is_cg_reg
\r
45 EXTERN ?Register_R7_is_cg_reg
\r
47 PUBLIC OWI_CheckRomCRC
\r
48 PUBLIC OWI_ComputeCRC16
\r
49 PUBLIC OWI_ComputeCRC8
\r
50 PUBLIC OWI_DetectPresence
\r
55 PUBLIC OWI_ReceiveByte
\r
56 PUBLIC OWI_SearchRom
\r
59 PUBLIC OWI_WriteBit0
\r
60 PUBLIC OWI_WriteBit1
\r
69 // C:\home\kevin\pub\src\bc100\IAR\OWI.c
\r
70 // 1 /* This file has been prepared for Doxygen automatic documentation generation.*/
\r
71 // 2 /*! \file ********************************************************************
\r
74 // 5 * Functions for 1-Wire(R) bus communication
\r
76 // 7 * High level functions for transmission of full bytes on the 1-Wire(R)
\r
77 // 8 * bus and implementations of ROM commands.\n
\r
78 // 9 * Polled software only implementation of the basic bit-level signalling
\r
79 // 10 * in the 1-Wire(R) protocol.\n
\r
80 // 11 * Includes functions for computing and checking CRC8 & 16 values of data
\r
81 // 12 * sets, and of 64 bit ROM identifiers.
\r
82 // 13 * Supported devices: All AVRs.
\r
84 // 15 * \par Application Note:
\r
85 // 16 * AVR458: Charging Li-Ion Batteries with BC100\n
\r
86 // 17 * AVR463: Charging NiMH Batteries with BC100\n
\r
87 // 18 * One-wire protocol based on AVR318 - Dallas 1-Wire(R) master.
\r
89 // 20 * \par Documentation:
\r
90 // 21 * For comprehensive code documentation, supported compilers, compiler
\r
91 // 22 * settings and supported devices see readme.html
\r
94 // 25 * Atmel Corporation: http://www.atmel.com \n
\r
95 // 26 * Support email: avr@atmel.com \n
\r
96 // 27 * Original author: \n
\r
99 // 30 * $Revision: 2299 $
\r
101 // 32 * $URL: http://svn.norway.atmel.com/AppsAVR8/avr458_Charging_Li-Ion_Batteries_with_BC100/tag/20070904_release_1.0/code/IAR/OWI.c $
\r
102 // 33 * $Date: 2007-08-23 12:55:51 +0200 (to, 23 aug 2007) $\n
\r
103 // 34 ****************************************************************************/
\r
105 // 36 #include <ioavr.h>
\r
107 ASEGN ABSOLUTE:DATA:NOROOT,03bH
\r
108 // <unnamed> volatile __io _A_PORTA
\r
112 ASEGN ABSOLUTE:DATA:NOROOT,03aH
\r
113 // <unnamed> volatile __io _A_DDRA
\r
117 ASEGN ABSOLUTE:DATA:NOROOT,039H
\r
118 // <unnamed> volatile __io _A_PINA
\r
121 // 37 #include <inavr.h>
\r
123 // 39 #include "OWI.h"
\r
126 // 42 //******************************************************************************
\r
128 // 44 //******************************************************************************
\r
129 // 45 /*! \brief Initialization of the one wire bus(es). (Software only driver)
\r
131 // 47 * This function initializes the 1-Wire bus(es) by releasing it and
\r
132 // 48 * waiting until any presence signals are finished.
\r
134 // 50 * \param pins A bitmask of the buses to initialize.
\r
137 RSEG CODE:CODE:NOROOT(1)
\r
138 // 52 void OWI_Init(unsigned char pins){
\r
140 // 53 OWI_RELEASE_BUS(pins);
\r
148 // 54 // The first rising edge can be interpreted by a slave as the end of a
\r
149 // 55 // Reset-pulse. Delay for the required reset recovery time (H) to be
\r
150 // 56 // sure that the real reset is interpreted correctly.
\r
151 // 57 __delay_cycles(OWI_DELAY_H_STD_MODE);
\r
164 // 61 /*! \brief Write a '1' bit to the bus(es). (Software only driver)
\r
166 // 63 * Generates the waveform for transmission of a '1' bit on the 1-Wire
\r
169 // 66 * \param pins A bitmask of the buses to write to.
\r
172 RSEG CODE:CODE:NOROOT(1)
\r
173 // 68 void OWI_WriteBit1(unsigned char pins){
\r
175 // 69 unsigned char intState;
\r
177 // 71 // Disable interrupts.
\r
178 // 72 intState = __save_interrupt();
\r
180 // 73 __disable_interrupt();
\r
183 // 75 // Drive bus low and delay.
\r
184 // 76 OWI_PULL_BUS_LOW(pins);
\r
192 // 77 __delay_cycles(OWI_DELAY_A_STD_MODE);
\r
198 // 79 // Release bus and delay.
\r
199 // 80 OWI_RELEASE_BUS(pins);
\r
206 // 81 __delay_cycles(OWI_DELAY_B_STD_MODE);
\r
212 // 83 // Restore interrupts.
\r
213 // 84 __restore_interrupt(intState);
\r
220 // 87 /*! \brief Write a '0' to the bus(es). (Software only driver)
\r
222 // 89 * Generates the waveform for transmission of a '0' bit on the 1-Wire(R)
\r
225 // 92 * \param pins A bitmask of the buses to write to.
\r
228 RSEG CODE:CODE:NOROOT(1)
\r
229 // 94 void OWI_WriteBit0(unsigned char pins)
\r
232 // 96 unsigned char intState;
\r
234 // 98 // Disable interrupts.
\r
235 // 99 intState = __save_interrupt();
\r
237 // 100 __disable_interrupt();
\r
240 // 102 // Drive bus low and delay.
\r
241 // 103 OWI_PULL_BUS_LOW(pins);
\r
249 // 104 __delay_cycles(OWI_DELAY_C_STD_MODE);
\r
255 // 106 // Release bus and delay.
\r
256 // 107 OWI_RELEASE_BUS(pins);
\r
263 // 108 __delay_cycles(OWI_DELAY_D_STD_MODE);
\r
269 // 110 // Restore interrupts.
\r
270 // 111 __restore_interrupt(intState);
\r
277 // 114 /*! \brief Read a bit from the bus(es). (Software only driver)
\r
279 // 116 * Generates the waveform for reception of a bit on the 1-Wire(R) bus(es).
\r
281 // 118 * \param pins A bitmask of the bus(es) to read from.
\r
283 // 120 * \return A bitmask of the buses where a '1' was read.
\r
286 RSEG CODE:CODE:NOROOT(1)
\r
287 // 122 unsigned char OWI_ReadBit(unsigned char pins)
\r
290 // 124 unsigned char intState;
\r
291 // 125 unsigned char bitsRead;
\r
293 // 127 // Disable interrupts.
\r
294 // 128 intState = __save_interrupt();
\r
296 // 129 __disable_interrupt();
\r
299 // 131 // Drive bus low and delay.
\r
300 // 132 OWI_PULL_BUS_LOW(pins);
\r
309 // 133 __delay_cycles(OWI_DELAY_A_STD_MODE);
\r
315 // 135 // Release bus and delay.
\r
316 // 136 OWI_RELEASE_BUS(pins);
\r
323 // 137 __delay_cycles(OWI_DELAY_E_STD_MODE);
\r
329 // 139 // Sample bus and delay.
\r
330 // 140 bitsRead = OWI_PIN & pins;
\r
333 // 141 __delay_cycles(OWI_DELAY_F_STD_MODE);
\r
339 // 143 // Restore interrupts.
\r
340 // 144 __restore_interrupt(intState);
\r
343 // 146 return bitsRead;
\r
352 // 150 /*! \brief Send a Reset signal and listen for Presence signal. (software
\r
353 // 151 * only driver)
\r
355 // 153 * Generates the waveform for transmission of a Reset pulse on the
\r
356 // 154 * 1-Wire(R) bus and listens for presence signals.
\r
358 // 156 * \param pins A bitmask of the buses to send the Reset signal on.
\r
360 // 158 * \return A bitmask of the buses where a presence signal was detected.
\r
363 RSEG CODE:CODE:NOROOT(1)
\r
364 // 160 unsigned char OWI_DetectPresence(unsigned char pins)
\r
365 OWI_DetectPresence:
\r
367 // 162 unsigned char intState;
\r
368 // 163 unsigned char presenceDetected;
\r
370 // 165 // Disable interrupts.
\r
371 // 166 intState = __save_interrupt();
\r
373 // 167 __disable_interrupt();
\r
376 // 169 // Drive bus low and delay.
\r
377 // 170 OWI_PULL_BUS_LOW(pins);
\r
386 // 171 __delay_cycles(OWI_DELAY_H_STD_MODE);
\r
394 // 173 // Release bus and delay.
\r
395 // 174 OWI_RELEASE_BUS(pins);
\r
402 // 175 __delay_cycles(OWI_DELAY_I_STD_MODE);
\r
408 // 177 // Sample bus to detect presence signal and delay.
\r
409 // 178 presenceDetected = ((~OWI_PIN) & pins);
\r
413 // 179 __delay_cycles(OWI_DELAY_J_STD_MODE);
\r
421 // 181 // Restore interrupts.
\r
422 // 182 __restore_interrupt(intState);
\r
425 // 184 return presenceDetected;
\r
433 // 188 /*! \brief Sends one byte of data on the 1-Wire(R) bus(es).
\r
435 // 190 * This function automates the task of sending a complete byte
\r
436 // 191 * of data on the 1-Wire bus(es).
\r
438 // 193 * \param data The data to send on the bus(es).
\r
440 // 195 * \param pins A bitmask of the buses to send the data to.
\r
443 RSEG CODE:CODE:NOROOT(1)
\r
444 // 197 void OWI_SendByte(unsigned char data, unsigned char pins)
\r
452 // 199 unsigned char temp;
\r
453 // 200 unsigned char i;
\r
455 // 202 // Do once for each bit
\r
456 // 203 for (i = 0; i < 8; i++) {
\r
458 // 204 // Determine if LSB is '0' or '1' and transmit corresponding
\r
459 // 205 // waveform on the bus.
\r
460 // 206 temp = data & 0x01;
\r
466 BRTC ??OWI_SendByte_1
\r
467 // 209 OWI_WriteBit1(pins);
\r
468 RCALL OWI_WriteBit1
\r
469 RJMP ??OWI_SendByte_2
\r
471 // 211 OWI_WriteBit0(pins);
\r
473 RCALL OWI_WriteBit0
\r
476 // 214 data >>= 1; // Right shift the data to get next bit.
\r
481 BRNE ??OWI_SendByte_0
\r
489 // 219 /*! \brief Receives one byte of data from the 1-Wire(R) bus.
\r
491 // 221 * This function automates the task of receiving a complete byte
\r
492 // 222 * of data from the 1-Wire bus.
\r
494 // 224 * \param pin A bitmask of the bus to read from.
\r
496 // 226 * \return The byte read from the bus.
\r
499 RSEG CODE:CODE:NOROOT(1)
\r
500 // 228 unsigned char OWI_ReceiveByte(unsigned char pin)
\r
507 // 230 unsigned char data;
\r
508 // 231 unsigned char i;
\r
510 // 233 // Clear the temporary input variable.
\r
511 // 234 data = 0x00;
\r
514 // 236 // Do once for each bit
\r
515 // 237 for (i = 0; i < 8; i++) {
\r
517 // 238 // Shift temporary input variable right.
\r
519 ??OWI_ReceiveByte_0:
\r
522 // 241 // Set the MSB if a '1' value is read from the bus.
\r
523 // 242 // Leave as it is ('0') else.
\r
524 // 243 if (OWI_ReadBit(pin)) {
\r
528 BREQ ??OWI_ReceiveByte_1
\r
529 // 244 data |= 0x80;
\r
533 ??OWI_ReceiveByte_1:
\r
535 BRNE ??OWI_ReceiveByte_0
\r
537 // 248 return data;
\r
546 // 252 /*! \brief Sends the SKIP ROM command to the 1-Wire bus(es).
\r
548 // 254 * \param pins A bitmask of the buses to send the SKIP ROM command to.
\r
551 RSEG CODE:CODE:NOROOT(1)
\r
552 // 256 void OWI_SkipRom(unsigned char pins)
\r
555 // 258 // Send the SKIP ROM command on the bus.
\r
556 // 259 OWI_SendByte(OWI_ROM_SKIP, pins);
\r
563 // 263 /*! \brief Sends the READ ROM command and reads back the ROM id.
\r
565 // 265 * \param romValue A pointer where the id will be placed.
\r
567 // 267 * \param pin A bitmask of the bus to read from.
\r
570 RSEG CODE:CODE:NOROOT(1)
\r
571 // 269 void OWI_ReadRom(unsigned char * romValue, unsigned char pin)
\r
578 MOVW R27:R26, R17:R16
\r
580 // 271 unsigned char bytesLeft = 8;
\r
582 // 273 // Send the READ ROM command on the bus.
\r
583 // 274 OWI_SendByte(OWI_ROM_READ, pin);
\r
589 // 276 // Do 8 times.
\r
590 // 277 while (bytesLeft > 0) {
\r
591 // 278 // Place the received data in memory.
\r
592 // 279 *romValue++ = OWI_ReceiveByte(pin);
\r
595 RCALL OWI_ReceiveByte
\r
597 // 280 bytesLeft--;
\r
600 BRNE ??OWI_ReadRom_0
\r
602 REQUIRE ?Subroutine0
\r
603 ; // Fall through to label ?Subroutine0
\r
605 RSEG CODE:CODE:NOROOT(1)
\r
614 // 285 /*! \brief Sends the MATCH ROM command and the ROM id to match against.
\r
616 // 287 * \param romValue A pointer to the ID to match against.
\r
618 // 289 * \param pins A bitmask of the buses to perform the MATCH ROM command on.
\r
621 RSEG CODE:CODE:NOROOT(1)
\r
622 // 291 void OWI_MatchRom(unsigned char * romValue, unsigned char pins)
\r
629 MOVW R27:R26, R17:R16
\r
631 // 293 unsigned char bytesLeft = 8;
\r
633 // 295 // Send the MATCH ROM command.
\r
634 // 296 OWI_SendByte(OWI_ROM_MATCH, pins);
\r
640 // 298 // Do once for each byte.
\r
641 // 299 while (bytesLeft > 0) {
\r
642 // 300 // Transmit 1 byte of the ID to match.
\r
643 // 301 OWI_SendByte(*romValue++, pins);
\r
648 // 302 bytesLeft--;
\r
651 BRNE ??OWI_MatchRom_0
\r
656 // 307 /*! \brief Sends the SEARCH ROM command and returns 1 id found on the
\r
657 // 308 * 1-Wire(R) bus.
\r
659 // 310 * \param bitPattern A pointer to an 8 byte char array where the
\r
660 // 311 * discovered identifier will be placed. When
\r
661 // 312 * searching for several slaves, a copy of the
\r
662 // 313 * last found identifier should be supplied in
\r
663 // 314 * the array, or the search will fail.
\r
665 // 316 * \param lastDeviation The bit position where the algorithm made a
\r
666 // 317 * choice the last time it was run. This argument
\r
667 // 318 * should be 0 when a search is initiated. Supplying
\r
668 // 319 * the return argument of this function when calling
\r
669 // 320 * repeatedly will go through the complete slave
\r
672 // 323 * \param pin A bit-mask of the bus to perform a ROM search on.
\r
674 // 325 * \return The last bit position where there was a discrepancy between slave
\r
675 // 326 * addresses the last time this function was run. Returns OWI_ROM_SEARCH_FAILED
\r
676 // 327 * if an error was detected (e.g. a device was connected to the bus during the
\r
677 // 328 * search), or OWI_ROM_SEARCH_FINISHED when there are no more devices to be
\r
678 // 329 * discovered.
\r
680 // 331 * \note See main.c for an example of how to utilize this function.
\r
683 RSEG CODE:CODE:NOROOT(1)
\r
684 // 333 unsigned char OWI_SearchRom(unsigned char * bitPattern,
\r
686 // 334 unsigned char lastDeviation, unsigned char pin)
\r
696 REQUIRE ?Register_R4_is_cg_reg
\r
697 REQUIRE ?Register_R5_is_cg_reg
\r
698 REQUIRE ?Register_R6_is_cg_reg
\r
699 REQUIRE ?Register_R7_is_cg_reg
\r
700 MOVW R27:R26, R17:R16
\r
703 // 336 unsigned char currentBit = 1;
\r
705 // 337 unsigned char newDeviation = 0;
\r
707 // 338 unsigned char bitMask = 0x01;
\r
709 // 339 unsigned char bitA;
\r
710 // 340 unsigned char bitB;
\r
712 // 342 // Send SEARCH ROM command on the bus.
\r
713 // 343 OWI_SendByte(OWI_ROM_SEARCH, pin);
\r
718 // 345 // Walk through all 64 bits.
\r
719 // 346 while (currentBit <= 64) {
\r
720 // 347 // Read bit from bus twice.
\r
721 // 348 bitA = OWI_ReadBit(pin);
\r
726 // 349 bitB = OWI_ReadBit(pin);
\r
730 // 351 if (bitA && bitB) {
\r
732 BREQ ??OWI_SearchRom_1
\r
734 BREQ ??OWI_SearchRom_1
\r
735 // 352 // Both bits 1 (Error).
\r
736 // 353 newDeviation = OWI_ROM_SEARCH_FAILED;
\r
737 // 354 return newDeviation;
\r
739 RJMP ??OWI_SearchRom_2
\r
740 // 355 } else if (bitA ^ bitB) {
\r
743 BREQ ??OWI_SearchRom_3
\r
744 // 356 // Bits A and B are different. All devices have the same bit here.
\r
745 // 357 // Set the bit in bitPattern to this value.
\r
748 BREQ ??OWI_SearchRom_4
\r
749 // 359 (*bitPattern) |= bitMask;
\r
751 MOVW R31:R30, R27:R26
\r
755 RJMP ??OWI_SearchRom_6
\r
757 // 361 (*bitPattern) &= ~bitMask;
\r
764 RJMP ??OWI_SearchRom_6
\r
767 // 364 // If this is where a choice was made the last time,
\r
768 // 365 // a '1' bit is selected this time.
\r
769 // 366 if (currentBit == lastDeviation) {
\r
772 BREQ ??OWI_SearchRom_5
\r
773 // 367 (*bitPattern) |= bitMask;
\r
776 // 370 // For the rest of the id, '0' bits are selected when
\r
777 // 371 // discrepancies occur.
\r
778 // 372 else if (currentBit > lastDeviation) {
\r
780 BRCC ??OWI_SearchRom_7
\r
781 // 373 (*bitPattern) &= ~bitMask;
\r
787 // 374 newDeviation = currentBit;
\r
788 RJMP ??OWI_SearchRom_8
\r
791 // 377 // If current bit in bit pattern = 0, then this is
\r
792 // 378 // out new deviation.
\r
793 // 379 else if ( !(*bitPattern & bitMask)) {
\r
797 BRNE ??OWI_SearchRom_6
\r
798 // 380 newDeviation = currentBit;
\r
803 // 383 // IF the bit is already 1, do nothing.
\r
808 // 388 // Send the selected bit to the bus.
\r
809 // 389 if ((*bitPattern) & bitMask) {
\r
814 BREQ ??OWI_SearchRom_9
\r
815 // 390 OWI_WriteBit1(pin);
\r
816 RCALL OWI_WriteBit1
\r
817 RJMP ??OWI_SearchRom_10
\r
819 // 392 OWI_WriteBit0(pin);
\r
821 RCALL OWI_WriteBit0
\r
824 // 395 // Increment current bit.
\r
825 // 396 currentBit++;
\r
826 ??OWI_SearchRom_10:
\r
829 // 398 // Adjust bitMask and bitPattern pointer.
\r
830 // 399 bitMask <<= 1;
\r
832 // 400 if (!bitMask) {
\r
833 BRNE ??OWI_SearchRom_11
\r
834 // 401 bitMask = 0x01;
\r
836 // 402 bitPattern++;
\r
840 ??OWI_SearchRom_11:
\r
842 BRCS ??OWI_SearchRom_0
\r
844 // 406 return newDeviation;
\r
859 // 410 /* Functions for handling CRC */
\r
860 // 411 /*! \brief Compute the CRC8 value of a data set.
\r
862 // 413 * This function will compute the CRC8 or DOW-CRC of inData using seed
\r
863 // 414 * as inital value for the CRC.
\r
865 // 416 * \param inData One byte of data to compute CRC from.
\r
867 // 418 * \param seed The starting value of the CRC.
\r
869 // 420 * \return The CRC8 of inData with seed as initial value.
\r
871 // 422 * \note Setting seed to 0 computes the crc8 of the inData.
\r
873 // 424 * \note Constantly passing the return value of this function
\r
874 // 425 * As the seed argument computes the CRC8 value of a
\r
875 // 426 * longer string of data.
\r
878 RSEG CODE:CODE:NOROOT(1)
\r
879 // 428 unsigned char OWI_ComputeCRC8(unsigned char inData, unsigned char seed)
\r
882 // 430 unsigned char bitsLeft;
\r
883 // 431 unsigned char temp;
\r
885 // 433 for (bitsLeft = 8; bitsLeft > 0; bitsLeft--) {
\r
887 // 434 temp = ((seed ^ inData) & 0x01);
\r
889 // 436 if (temp == 0) {
\r
890 ??OWI_ComputeCRC8_0:
\r
896 BRNE ??OWI_ComputeCRC8_1
\r
899 RJMP ??OWI_ComputeCRC8_2
\r
901 // 439 seed ^= 0x18;
\r
903 // 441 seed |= 0x80;
\r
904 ??OWI_ComputeCRC8_1:
\r
911 // 444 inData >>= 1;
\r
912 ??OWI_ComputeCRC8_2:
\r
916 BRNE ??OWI_ComputeCRC8_0
\r
917 // 446 return seed;
\r
923 // 450 /*! \brief Compute the CRC16 value of a data set.
\r
925 // 452 * This function will compute the CRC16 of inData using seed
\r
926 // 453 * as inital value for the CRC.
\r
928 // 455 * \param inData One byte of data to compute CRC from.
\r
930 // 457 * \param seed The starting value of the CRC.
\r
932 // 459 * \return The CRC16 of inData with seed as initial value.
\r
934 // 461 * \note Setting seed to 0 computes the crc16 of the inData.
\r
936 // 463 * \note Constantly passing the return value of this function
\r
937 // 464 * As the seed argument computes the CRC16 value of a
\r
938 // 465 * longer string of data.
\r
941 RSEG CODE:CODE:NOROOT(1)
\r
942 // 467 unsigned int OWI_ComputeCRC16(unsigned char inData, unsigned int seed)
\r
945 // 469 unsigned char bitsLeft;
\r
946 // 470 unsigned char temp;
\r
948 // 472 for (bitsLeft = 8; bitsLeft > 0; bitsLeft--) {
\r
950 // 473 temp = ((seed ^ inData) & 0x01);
\r
952 // 475 if (temp == 0) {
\r
953 ??OWI_ComputeCRC16_0:
\r
959 BRNE ??OWI_ComputeCRC16_1
\r
963 RJMP ??OWI_ComputeCRC16_2
\r
965 // 478 seed ^= 0x4002;
\r
967 // 480 seed |= 0x8000;
\r
968 ??OWI_ComputeCRC16_1:
\r
973 MOVW R19:R18, R21:R20
\r
979 // 483 inData >>= 1;
\r
980 ??OWI_ComputeCRC16_2:
\r
984 BRNE ??OWI_ComputeCRC16_0
\r
986 // 486 return seed;
\r
987 MOVW R17:R16, R19:R18
\r
992 // 490 /*! \brief Calculate and check the CRC of a 64 bit ROM identifier.
\r
994 // 492 * This function computes the CRC8 value of the first 56 bits of a
\r
995 // 493 * 64 bit identifier. It then checks the calculated value against the
\r
996 // 494 * CRC value stored in ROM.
\r
998 // 496 * \param *romValue A pointer to an array holding a 64 bit identifier.
\r
1000 // 498 * \retval OWI_CRC_OK The CRC's matched.
\r
1001 // 499 * \retval OWI_CRC_ERROR Calculated and stored CRC did not match.
\r
1004 RSEG CODE:CODE:NOROOT(1)
\r
1005 // 501 unsigned char OWI_CheckRomCRC(unsigned char *romValue)
\r
1011 MOVW R27:R26, R17:R16
\r
1012 // 503 unsigned char i;
\r
1013 // 504 unsigned char crc8 = 0;
\r
1016 // 506 for (i = 0; i < 7; i++) {
\r
1018 // 507 crc8 = OWI_ComputeCRC8(*romValue, crc8);
\r
1019 ??OWI_CheckRomCRC_0:
\r
1021 RCALL OWI_ComputeCRC8
\r
1023 // 508 romValue++;
\r
1026 BRNE ??OWI_CheckRomCRC_0
\r
1028 // 511 if (crc8 == (*romValue)) {
\r
1031 BRNE ??OWI_CheckRomCRC_1
\r
1032 // 512 return OWI_CRC_OK;
\r
1034 RJMP ??OWI_CheckRomCRC_2
\r
1037 // 515 return OWI_CRC_ERROR;
\r
1038 ??OWI_CheckRomCRC_1:
\r
1040 ??OWI_CheckRomCRC_2:
\r
1047 ASEGN ABSOLUTE:DATA:NOROOT,01cH
\r
1050 ASEGN ABSOLUTE:DATA:NOROOT,01dH
\r
1053 ASEGN ABSOLUTE:DATA:NOROOT,01eH
\r
1056 ASEGN ABSOLUTE:DATA:NOROOT,01fH
\r
1061 // 3 bytes in segment ABSOLUTE
\r
1062 // 708 bytes in segment CODE
\r
1064 // 708 bytes of CODE memory
\r
1065 // 0 bytes of DATA memory (+ 3 bytes shared)
\r