Commit mthomas changes to GCC and port those changes to IAR
[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 \r
55 #ifdef EASYPACK550\r
56 \r
57 #warning "using EasyPack 66590 711 099 (550mAh) settings - mthomas, no warranty!"\r
58 // RID not connected\r
59 #define ALLOW_NO_RID                //!< Use default battery data if no matching entry found.\r
60 #define DEF_BAT_CAPACITY       550  //!< Default battery capacity, in mAh.\r
61 #define DEF_BAT_CURRENT_MAX    260  //!< Default maximum charge current, in mA.\r
62 #define DEF_BAT_TIME_MAX    (5*60)  //!< Default maximum charge time, in minutes.\r
63 //! Default minimum current to stop charge, in mA.\r
64 #define DEF_BAT_CURRENT_MIN     10\r
65 \r
66 #else\r
67 \r
68 //#define ALLOW_NO_RID  //!< Use default battery data if no matching entry found.\r
69 \r
70 #define DEF_BAT_CAPACITY                0  //!< Default battery capacity, in mAh.\r
71 #define DEF_BAT_CURRENT_MAX     0  //!< Default maximum charge current, in mA.\r
72 #define DEF_BAT_TIME_MAX                0  //!< Default maximum charge time, in minutes.\r
73 //! Default minimum current to stop charge, in mA.\r
74 #define DEF_BAT_CURRENT_MIN     0\r
75 \r
76 #endif /* EASYPACK550 */\r
77 \r
78 \r
79 //******************************************************************************\r
80 // RID and NTC defines and struct declarations\r
81 //******************************************************************************\r
82 #define RID_TABLE_SIZE        4     //!< Number of entries in RID table.\r
83 #define NTC_TABLE_SIZE        20    //!< Number of entries in NTC table.\r
84 \r
85 //! \brief Struct for an entry in the resistor ID lookup-table\r
86 struct RID_Lookup_struct {\r
87   unsigned int  Low;              //!< Lowest acceptable ADC value.\r
88   unsigned int  High;             //!< Highest acceptable ADC value.\r
89   unsigned int  Resistance;       //!< RID resistance, in Ohms.\r
90   unsigned int  Capacity;         //!< Associated battery capacity, in mAh.\r
91   unsigned int  Icharge;          //!< Associated initial charge current, in mA.\r
92   unsigned int  tCutOff;          //!< Associated cut-off time, in minutes.\r
93   unsigned int  ICutOff;          //!< Associated cut-off current, in mA.\r
94 };\r
95 typedef struct RID_Lookup_struct RID_Lookup_t; //!< For convenience.\r
96 \r
97 /*! \brief Struct for an entry in the NTC lookup-table\r
98  *\r
99  * \note Must be sorted in descending ADC order.\r
100  */\r
101 struct NTC_Lookup_struct\r
102 {\r
103   unsigned int  ADCV;  //!< Measured NTC.\r
104   unsigned char ADCsteps;  //!< ADC steps per half degree at this temperature.\r
105 };\r
106 typedef struct NTC_Lookup_struct NTC_Lookup_t; //!< For convenience.\r
107 \r
108 \r
109 //******************************************************************************\r
110 // Global variables\r
111 //******************************************************************************\r
112 extern Battery_t EEMEM BattControl[];\r
113 extern Batteries_t BattData;\r
114 extern unsigned char EEMEM BattEEPROM[][32];\r
115 extern unsigned char BattActive;\r
116 \r
117 \r
118 //******************************************************************************\r
119 // Function prototypes\r
120 //******************************************************************************\r
121 unsigned char BatteryCheck(void);\r
122 unsigned char BatteryStatusRefresh(void);\r
123 unsigned char BatteryDataRefresh(void);\r
124 void EnableBattery(unsigned char);\r
125 void DisableBatteries(void);\r
126 unsigned char RIDLookUp(void);\r
127 void NTCLookUp(void);\r
128 \r
129 \r
130 #endif // BATTERY_H\r