OWI.h

Go to the documentation of this file.
00001 // This file has been prepared for Doxygen automatic documentation generation.
00029 #ifndef OWI_H
00030 #define OWI_H
00031 
00032 #include <ioavr.h>
00033 
00034 
00035 //******************************************************************************
00036 // Defines for CRC-functions
00037 //******************************************************************************
00038 #define     OWI_CRC_OK      0x00    
00039 #define     OWI_CRC_ERROR   0x01    
00040 
00041 
00042 //******************************************************************************
00043 // Defines for OWI-functions
00044 //******************************************************************************
00051 #define     CPU_FREQUENCY   8.000
00052 
00053 
00060 //#define     OWI_USE_INTERNAL_PULLUP
00061 
00062 
00063 // Port configuration registers for 1-Wire buses.
00064 // Make sure that all three registers belong to the same port.
00065 #define     OWI_PORT        PORTA   
00066 #define     OWI_PIN         PINA    
00067 #define     OWI_DDR         DDRA    
00068 
00069 
00070 //******************************************************************************
00071 // Pin bitmasks
00072 //******************************************************************************
00073 #define     OWI_PIN_0       0x01
00074 #define     OWI_PIN_1       0x02
00075 #define     OWI_PIN_2       0x04
00076 #define     OWI_PIN_3       0x08
00077 #define     OWI_PIN_4       0x10
00078 #define     OWI_PIN_5       0x20
00079 #define     OWI_PIN_6       0x40
00080 #define     OWI_PIN_7       0x80
00081 
00082 
00083 //******************************************************************************
00084 // Timing parameters
00085 //******************************************************************************
00087 #define     OWI_DELAY_OFFSET_CYCLES    13   
00088 
00089 // Bit timing delays in clock cycles (= us*clock freq in MHz).
00090 #define     OWI_DELAY_A_STD_MODE    (unsigned long)((6   * CPU_FREQUENCY) - OWI_DELAY_OFFSET_CYCLES)
00091 #define     OWI_DELAY_B_STD_MODE    (unsigned long)((64  * CPU_FREQUENCY) - OWI_DELAY_OFFSET_CYCLES)
00092 #define     OWI_DELAY_C_STD_MODE    (unsigned long)((60  * CPU_FREQUENCY) - OWI_DELAY_OFFSET_CYCLES)
00093 #define     OWI_DELAY_D_STD_MODE    (unsigned long)((10  * CPU_FREQUENCY) - OWI_DELAY_OFFSET_CYCLES)
00094 #define     OWI_DELAY_E_STD_MODE    (unsigned long)((9   * CPU_FREQUENCY) - OWI_DELAY_OFFSET_CYCLES)
00095 #define     OWI_DELAY_F_STD_MODE    (unsigned long)((55  * CPU_FREQUENCY) - OWI_DELAY_OFFSET_CYCLES)
00096 //#define     OWI_DELAY_G_STD_MODE  (unsigned long)((0   * CPU_FREQUENCY) - OWI_DELAY_OFFSET_CYCLES)
00097 #define     OWI_DELAY_H_STD_MODE    (unsigned long)((480 * CPU_FREQUENCY) - OWI_DELAY_OFFSET_CYCLES)
00098 #define     OWI_DELAY_I_STD_MODE    (unsigned long)((70  * CPU_FREQUENCY) - OWI_DELAY_OFFSET_CYCLES)
00099 #define     OWI_DELAY_J_STD_MODE    (unsigned long)((410 * CPU_FREQUENCY) - OWI_DELAY_OFFSET_CYCLES)
00100 
00101 
00102 //******************************************************************************
00103 // ROM commands
00104 //******************************************************************************
00105 #define     OWI_ROM_READ    0x33    
00106 #define     OWI_ROM_SKIP    0xcc    
00107 #define     OWI_ROM_MATCH   0x55    
00108 #define     OWI_ROM_SEARCH  0xf0    
00109 
00110 
00111 //******************************************************************************
00112 // Return codes
00113 //******************************************************************************
00114 #define     OWI_ROM_SEARCH_FINISHED     0x00   
00115 #define     OWI_ROM_SEARCH_FAILED       0xff   
00116 
00117 
00118 //******************************************************************************
00119 // Macros
00120 //******************************************************************************
00128 #define OWI_PULL_BUS_LOW(bitMask) \
00129                         OWI_DDR |= (bitMask); \
00130                         OWI_PORT &= ~(bitMask)
00131 
00132 
00142 #ifdef OWI_USE_INTERNAL_PULLUP            
00143         // Set 1-Wire pin(s) to input and enable internal pull-up resistor.
00144 #define OWI_RELEASE_BUS(bitMask) \
00145                         OWI_DDR &= ~(bitMask); \
00146                         OWI_PORT |= (bitMask)
00147 
00148 #else
00149         // Set 1-Wire pin(s) to input mode. No internal pull-up enabled.
00150 #define OWI_RELEASE_BUS(bitMask) \
00151                         OWI_DDR &= ~(bitMask); \
00152                         OWI_PORT &= ~(bitMask)
00153 
00154 #endif
00155 
00156 
00157 //******************************************************************************
00158 // Function prototypes
00159 //******************************************************************************
00160 void OWI_SendByte(unsigned char data, unsigned char pins);
00161 unsigned char OWI_ReceiveByte(unsigned char pin);
00162 void OWI_SkipRom(unsigned char pins);
00163 void OWI_ReadRom(unsigned char * romValue, unsigned char pin);
00164 void OWI_MatchRom(unsigned char * romValue, unsigned char pins);
00165 unsigned char OWI_SearchRom(unsigned char * bitPattern,
00166                                                                          unsigned char lastDeviation, unsigned char pin);
00167 void OWI_Init(unsigned char pins);
00168 void OWI_WriteBit1(unsigned char pins);
00169 void OWI_WriteBit0(unsigned char pins);
00170 unsigned char OWI_ReadBit(unsigned char pins);
00171 unsigned char OWI_DetectPresence(unsigned char pins);
00172 
00173 unsigned char OWI_ComputeCRC8(unsigned char inData, unsigned char seed);
00174 unsigned int OWI_ComputeCRC16(unsigned char inData, unsigned int seed);
00175 unsigned char OWI_CheckRomCRC(unsigned char *romValue);
00176 
00177 #endif // OWI_H
00178 

Generated on Tue Sep 4 19:17:55 2007 for AVR463 Charging NiMH Batteries with ATAVRBC100 by  doxygen 1.5.2