Initial import
[avr_bc100.git] / BaseTinyFirmware / GCC / chargefunc.h
1 /* This file has been prepared for Doxygen automatic documentation generation.*/\r
2 /*! \file *********************************************************************\r
3  *\r
4  * \brief\r
5  *      Headerfile for chargefunc.c\r
6  *\r
7  *      Contains definitions to decide PWM error handling and of halt flags,\r
8  *      and declarations of parameter structs for charging.\r
9  *\r
10  * \par Application note:\r
11  *      AVR458: Charging Li-Ion Batteries with BC100\r
12  *\r
13  * \par Documentation\r
14  *      For comprehensive code documentation, supported compilers, compiler \r
15  *      settings and supported devices see readme.html\r
16  *\r
17  * \author\r
18  *      Atmel Corporation: http://www.atmel.com \n\r
19  *      Support email: avr@atmel.com\r
20  *\r
21  * \r
22  * $Name$\r
23  * $Revision: 2261 $\r
24  * $RCSfile$\r
25  * $URL: http://svn.norway.atmel.com/AppsAVR8/avr458_Charging_Li-Ion_Batteries_with_BC100/tag/20070904_release_1.0/code/IAR/chargefunc.h $\r
26  * $Date: 2007-08-10 09:28:35 +0200 (fr, 10 aug 2007) $\n\r
27  ******************************************************************************/\r
28 \r
29 #ifndef CHARGEFUNC_H\r
30 #define CHARGEFUNC_H\r
31 \r
32 \r
33 //******************************************************************************\r
34 // PWM error handling\r
35 //******************************************************************************\r
36 //! Report error if maximum duty cycle doesn't give a sufficient charge current.\r
37 #define ABORT_IF_PWM_MAX\r
38 \r
39 //! Report error if minimum duty cycle gives a too great charge current.\r
40 #define ABORT_IF_PWM_MIN\r
41 \r
42 \r
43 //******************************************************************************\r
44 // Definitions for HaltFlags\r
45 //******************************************************************************\r
46 //! Halt if VBAT drops more than the set limit.\r
47 #define HALT_VOLTAGE_DROP               0x01  \r
48 \r
49 //! Halt if VBAT reaches the set maximum.\r
50 #define HALT_VOLTAGE_MAX                0x02  \r
51 \r
52 //! Halt if avgIBAT goes below the set minimum.\r
53 #define HALT_CURRENT_MIN                0x04  \r
54 \r
55 //! Halt if BattData.Temperature rises quicker than the set maximum.\r
56 #define HALT_TEMPERATURE_RISE   0x08\r
57 \r
58 //! Halt if TIMER_CHG runs out.\r
59 #define HALT_TIME                                       0x10  \r
60 \r
61 //! Flag battery as exhausted if timeout occurs.\r
62 #define HALT_FLAG_EXHAUSTION    0x20\r
63 \r
64 \r
65 //******************************************************************************\r
66 // Parameter struct for charging\r
67 //******************************************************************************\r
68 /*! \brief Holds the parameters for ConstantCurrent() and ConstantVoltage().\r
69  *\r
70  */\r
71 struct ChargeParameters_struct {\r
72         unsigned int Voltage;  //!< Voltage to charge with.\r
73         unsigned int Current;  //!< Current to charge with.\r
74         unsigned char NextState;  //!< \brief Next state once charge stage finishes.\r
75                                  //!< \note Set in Charge(), but may be changed by\r
76                                  //!< HaltNow() if an error occurs!\r
77 };\r
78 typedef struct ChargeParameters_struct ChargeParameters_t;\r
79 \r
80 \r
81 //******************************************************************************\r
82 // Parameter struct for HaltNow()\r
83 //******************************************************************************\r
84 /*! \brief Holds the parameters for HaltNow();\r
85  *\r
86  */\r
87 struct HaltParameters_struct {\r
88         //! \brief Contains flags for what to evaluate. \r
89         //! \note See chargefunc.h for definitions of flags.\r
90         unsigned char HaltFlags;\r
91         \r
92         //! Maximum drop in voltage before halting, in mV.\r
93         unsigned int VoltageDrop;  \r
94         \r
95         //! Maximum limit for output voltage, in mV.\r
96         unsigned int VoltageMax;  \r
97         \r
98         //! Minimum limit for output current, in mA.\r
99         unsigned int CurrentMin;\r
100         \r
101         //! Maximum limit for battery temperature, in degrees centigrade.\r
102         unsigned int TemperatureMax;\r
103         \r
104         //! Minimum limit for battery temperature, in degrees centigrade.\r
105         signed int TemperatureMin;\r
106 \r
107         //! Maximum limit for temperature to rise, in degrees centigrade per minute.\r
108         unsigned int TemperatureRise;\r
109 \r
110         //! \brief Contains highest VBAT measured, used to calculate voltage drop.\r
111         //! \note Must be manually reset.\r
112         unsigned int VBATMax;\r
113 \r
114         //! Used to detect temperature rise.\r
115         unsigned int LastNTC;  \r
116 };\r
117 typedef struct HaltParameters_struct HaltParameters_t;\r
118 \r
119 \r
120 //******************************************************************************\r
121 // Global variables\r
122 //******************************************************************************\r
123 extern ChargeParameters_t ChargeParameters;\r
124 extern HaltParameters_t HaltParameters;\r
125 \r
126 \r
127 //******************************************************************************\r
128 // Function prototypes\r
129 //******************************************************************************\r
130 unsigned char ConstantCurrent(void);\r
131 unsigned char ConstantVoltage(void);\r
132 unsigned char HaltNow(void);\r
133 \r
134 #endif // CHARGEFUNC_H\r