1fa428a20682023f2d3a2357716adac43995c6f9
[avr_bc100.git] / BaseTinyFirmware / IAR / 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 \r
36 //******************************************************************************\r
37 // Defines for EEPROM reading\r
38 //******************************************************************************\r
39 #define OWIBUS  OWI_PIN_0         //!< One-wire bus (pin).\r
40 \r
41 #define OW_NONE           0x00    //!< One-wire device family code.\r
42 #define OW_DS2505         0x09    //!< One-wire device family code.\r
43 \r
44 #define DS2505_MEM_READ     0xF0  //!< One-wire device command.\r
45 #define DS2505_STATUS_READ  0xAA  //!< One-wire device command.\r
46 #define DS2505_DATA_READ    0xC3  //!< One-wire device command.\r
47 \r
48 \r
49 //******************************************************************************\r
50 // RID-less charging (for BatteryStatusRefresh())\r
51 //******************************************************************************\r
52 //#define ALLOW_NO_RID  //!< Use default battery data if no matching entry found.\r
53 \r
54 #define DEF_BAT_CAPACITY                0  //!< Default battery capacity, in mAh.\r
55 #define DEF_BAT_CURRENT_MAX     0  //!< Default maximum charge current, in mA.\r
56 #define DEF_BAT_TIME_MAX                0  //!< Default maximum charge time, in minutes.\r
57 //! Default minimum current to stop charge, in mA.\r
58 #define DEF_BAT_CURRENT_MIN     0\r
59 \r
60 \r
61 \r
62 //******************************************************************************\r
63 // RID and NTC defines and struct declarations\r
64 //******************************************************************************\r
65 #define RID_TABLE_SIZE        4     //!< Number of entries in RID table.\r
66 #define NTC_TABLE_SIZE        20    //!< Number of entries in NTC table.\r
67 \r
68 //! \brief Struct for an entry in the resistor ID lookup-table\r
69 struct RID_Lookup_struct {\r
70   unsigned int  Low;              //!< Lowest acceptable ADC value.\r
71   unsigned int  High;             //!< Highest acceptable ADC value.\r
72   unsigned int  Resistance;       //!< RID resistance, in Ohms.\r
73   unsigned int  Capacity;         //!< Associated battery capacity, in mAh.\r
74   unsigned int  Icharge;          //!< Associated initial charge current, in mA.\r
75   unsigned int  tCutOff;          //!< Associated cut-off time, in minutes.\r
76   unsigned int  ICutOff;          //!< Associated cut-off current, in mA.\r
77 };\r
78 typedef struct RID_Lookup_struct RID_Lookup_t; //!< For convenience.\r
79 \r
80 /*! \brief Struct for an entry in the NTC lookup-table\r
81  *\r
82  * \note Must be sorted in descending ADC order.\r
83  */\r
84 struct NTC_Lookup_struct\r
85 {\r
86   unsigned int  ADC;  //!< Measured NTC.\r
87   unsigned char ADCsteps;  //!< ADC steps per half degree at this temperature.\r
88 };\r
89 typedef struct NTC_Lookup_struct NTC_Lookup_t; //!< For convenience.\r
90 \r
91 \r
92 //******************************************************************************\r
93 // Global variables\r
94 //******************************************************************************\r
95 extern __eeprom Battery_t BattControl[];\r
96 extern Batteries_t BattData;\r
97 extern __eeprom unsigned char BattEEPROM[][32];\r
98 extern unsigned char BattActive;\r
99 \r
100 \r
101 //******************************************************************************\r
102 // Function prototypes\r
103 //******************************************************************************\r
104 unsigned char BatteryCheck(void);\r
105 unsigned char BatteryStatusRefresh(void);\r
106 unsigned char BatteryDataRefresh(void);\r
107 void EnableBattery(unsigned char);\r
108 void DisableBatteries(void);\r
109 unsigned char RIDLookUp(void);\r
110 void NTCLookUp(void);\r
111 \r
112 \r
113 #endif // BATTERY_H\r