bb76eaf922eb8036c28be5a185fb46068685f937
[avr_bc100.git] / BaseTinyFirmware / GCC / battery.h
1 /* This file has been prepared for Doxygen automatic documentation generation.*/\r
2 /*! \file *********************************************************************\r
3  *\r
4  * \brief\r
5  *      Headerfile for battery.c\r
6  *\r
7  *      Contains definitions for the setup of 1-Wire(R) and behaviour of the\r
8  *      battery data and status refreshing functions.\n\r
9  *      Also contains definitions of default battery data, and declarations\r
10  *      for the RID and NTC lookup tables.\r
11  *\r
12  * \par Application note:\r
13  *      AVR458: Charging Li-Ion Batteries with BC100\r
14  *\r
15  * \par Documentation:\r
16  *      For comprehensive code documentation, supported compilers, compiler\r
17  *      settings and supported devices see readme.html\r
18  *\r
19  * \author\r
20  *      Atmel Corporation: http://www.atmel.com \n\r
21  *      Support email: avr@atmel.com \n\r
22  *      Original author: \n\r
23  *\r
24  * $Name$\r
25  * $Revision: 2261 $\r
26  * $RCSfile$\r
27  * $URL: http://svn.norway.atmel.com/AppsAVR8/avr458_Charging_Li-Ion_Batteries_with_BC100/tag/20070904_release_1.0/code/IAR/battery.h $\r
28  * $Date: 2007-08-10 09:28:35 +0200 (fr, 10 aug 2007) $\n\r
29  ******************************************************************************/\r
30 \r
31 \r
32 #ifndef BATTERY_H\r
33 #define BATTERY_H\r
34 \r
35 #include <avr/eeprom.h>\r
36 \r
37 \r
38 //******************************************************************************\r
39 // Defines for EEPROM reading\r
40 //******************************************************************************\r
41 #define OWIBUS  OWI_PIN_0         //!< One-wire bus (pin).\r
42 \r
43 #define OW_NONE           0x00    //!< One-wire device family code.\r
44 #define OW_DS2505         0x09    //!< One-wire device family code.\r
45 \r
46 #define DS2505_MEM_READ     0xF0  //!< One-wire device command.\r
47 #define DS2505_STATUS_READ  0xAA  //!< One-wire device command.\r
48 #define DS2505_DATA_READ    0xC3  //!< One-wire device command.\r
49 \r
50 \r
51 //******************************************************************************\r
52 // RID-less charging (for BatteryStatusRefresh())\r
53 //******************************************************************************\r
54 //#define ALLOW_NO_RID  //!< Use default battery data if no matching entry found.\r
55 \r
56 #define DEF_BAT_CAPACITY                0  //!< Default battery capacity, in mAh.\r
57 #define DEF_BAT_CURRENT_MAX     0  //!< Default maximum charge current, in mA.\r
58 #define DEF_BAT_TIME_MAX                0  //!< Default maximum charge time, in minutes.\r
59 //! Default minimum current to stop charge, in mA.\r
60 #define DEF_BAT_CURRENT_MIN     0\r
61 \r
62 \r
63 \r
64 //******************************************************************************\r
65 // RID and NTC defines and struct declarations\r
66 //******************************************************************************\r
67 #define RID_TABLE_SIZE        4     //!< Number of entries in RID table.\r
68 #define NTC_TABLE_SIZE        20    //!< Number of entries in NTC table.\r
69 \r
70 //! \brief Struct for an entry in the resistor ID lookup-table\r
71 struct RID_Lookup_struct {\r
72   unsigned int  Low;              //!< Lowest acceptable ADC value.\r
73   unsigned int  High;             //!< Highest acceptable ADC value.\r
74   unsigned int  Resistance;       //!< RID resistance, in Ohms.\r
75   unsigned int  Capacity;         //!< Associated battery capacity, in mAh.\r
76   unsigned int  Icharge;          //!< Associated initial charge current, in mA.\r
77   unsigned int  tCutOff;          //!< Associated cut-off time, in minutes.\r
78   unsigned int  ICutOff;          //!< Associated cut-off current, in mA.\r
79 };\r
80 typedef struct RID_Lookup_struct RID_Lookup_t; //!< For convenience.\r
81 \r
82 /*! \brief Struct for an entry in the NTC lookup-table\r
83  *\r
84  * \note Must be sorted in descending ADC order.\r
85  */\r
86 struct NTC_Lookup_struct\r
87 {\r
88   unsigned int  ADCV;  //!< Measured NTC.\r
89   unsigned char ADCsteps;  //!< ADC steps per half degree at this temperature.\r
90 };\r
91 typedef struct NTC_Lookup_struct NTC_Lookup_t; //!< For convenience.\r
92 \r
93 \r
94 //******************************************************************************\r
95 // Global variables\r
96 //******************************************************************************\r
97 extern Battery_t EEMEM BattControl[];\r
98 extern Batteries_t BattData;\r
99 extern unsigned char EEMEM BattEEPROM[][32];\r
100 extern unsigned char BattActive;\r
101 \r
102 \r
103 //******************************************************************************\r
104 // Function prototypes\r
105 //******************************************************************************\r
106 unsigned char BatteryCheck(void);\r
107 unsigned char BatteryStatusRefresh(void);\r
108 unsigned char BatteryDataRefresh(void);\r
109 void EnableBattery(unsigned char);\r
110 void DisableBatteries(void);\r
111 unsigned char RIDLookUp(void);\r
112 void NTCLookUp(void);\r
113 \r
114 \r
115 #endif // BATTERY_H\r