Commit mthomas changes to GCC and port those changes to IAR
[avr_bc100.git] / BaseTinyFirmware / GCC / structs.h
1 /* This file has been prepared for Doxygen automatic documentation generation.*/\r
2 /*! \file *********************************************************************\r
3  *\r
4  * \brief\r
5  *      Structs in common for Slave and Master\r
6  *\r
7  *      Contains struct declarations for ADC.c and battery.c.\n\r
8  *      These are also used in the Master, and have therefore been\r
9  *      put in a separate file for convenience.\r
10  *\r
11  * \par Application note:\r
12  *      AVR458: Charging Li-Ion Batteries with BC100\r
13  *\r
14  * \par Documentation:\r
15  *      For comprehensive code documentation, supported compilers, compiler\r
16  *      settings and supported devices see readme.html\r
17  *\r
18  * \author\r
19  *      Atmel Corporation: http://www.atmel.com \n\r
20  *      Support email: avr@atmel.com \n\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/structs.h $\r
26  * $Date: 2007-08-10 09:28:35 +0200 (fr, 10 aug 2007) $\n\r
27  ******************************************************************************/\r
28 \r
29 \r
30 #ifndef STRUCTS_H\r
31 #define STRUCTS_H\r
32 \r
33 \r
34 //******************************************************************************\r
35 // Battery struct declarations\r
36 //******************************************************************************\r
37 /*! \brief Holds status and various data for a battery\r
38  *\r
39  * These data are updated by BatteryStatusRefresh(), RIDLookUp(),\r
40  * NTCLookUp() and BatteryDataRefresh().\r
41  */\r
42 struct Batteries_struct\r
43 {\r
44 #if 0\r
45 #warning "no bitfield, used for debugging - mthomas"\r
46         unsigned char Present   ; //!< Battery found. (TRUE/FALSE)\r
47         unsigned char Charged   ; //!< Battery fully charged. (TRUE/FALSE)\r
48         unsigned char Low       ; //!< Battery low voltage. (TRUE/FALSE)\r
49         unsigned char Exhausted ; //!< Battery exhausted. (TRUE/FALSE)\r
50         unsigned char HasRID    ; //!< Battery has resistor ID. (TRUE/FALSE)\r
51 #else\r
52         unsigned char Present   : 1; //!< Battery found. (TRUE/FALSE)\r
53         unsigned char Charged   : 1; //!< Battery fully charged. (TRUE/FALSE)\r
54         unsigned char Low       : 1; //!< Battery low voltage. (TRUE/FALSE)\r
55         unsigned char Exhausted : 1; //!< Battery exhausted. (TRUE/FALSE)\r
56         unsigned char HasRID    : 1; //!< Battery has resistor ID. (TRUE/FALSE)\r
57 #endif\r
58         unsigned char Circuit;       //!< Battery safety circuit (family id).\r
59         signed char Temperature;     //!< Battery temperature, in centigrade.\r
60         unsigned char ADCSteps;      //!< ADC steps per half degree.\r
61         unsigned int  Capacity;      //!< Capacity, in mAh.\r
62         unsigned int  MaxCurrent;    //!< Charge current, in mA.\r
63         unsigned int  MaxTime;       //!< Charge cut-off time, in minutes.\r
64         unsigned int  MinCurrent;    //!< Cut-off current, in mA.\r
65 };\r
66 typedef struct Batteries_struct Batteries_t; //!< For convenience.\r
67 \r
68 \r
69 // KMR: These definitions are in structs.h because they are a conversion\r
70 // of Atmel's original IAR code which used a bitfield structs for the\r
71 // type Battery_t. However, porting to GCC/avr-libc makes the use of a\r
72 // bitfield struct for acceessing an EEPROM value cumbersome.\r
73 // So, bitmasks on a uint8_t are now used insteads of a bitfield struct.\r
74 // These bitmasks could be moved to battery.h, but are left here for easier\r
75 // comparison to changes in Atmel's IAR code.\r
76 #define BIT_BATTERY_ENABLED            0x01     //! Battery valid, enabling allowed.\r
77 #define BIT_BATTERY_DISCONNECT_ALLOWED 0x02     //! Disconnect allowed.\r
78 #define BIT_BATTERY_CHARGE_INHIBIT     0x04     //! Inhibit charging. \todo Changed by master?\r
79 typedef uint8_t Battery_t; //!< For convenience.\r
80 \r
81 \r
82 //******************************************************************************\r
83 // ADC status struct declaration\r
84 //******************************************************************************\r
85 /*! \brief Holds ADC-status and samples\r
86  *\r
87  * Is updated by ADC_ISR().\r
88  */\r
89 struct ADC_Status_struct\r
90 {\r
91         unsigned char MUX : 5;  //!< Corresponds to ADMUX low bits MUX4..0.\r
92         unsigned char Flag : 1;  //!< ADC cycle complete (TRUE/FALSE).\r
93         unsigned char Mains : 1;  //!< Mains OK? (TRUE/FALSE).\r
94         unsigned char Halt : 1;  //!< Stop A/D-conversions (TRUE/FALSE).\r
95         unsigned char ADC3_G20_OS : 4;  //!< Offset on ADC3 at 20x gain.\r
96         unsigned char ADC5_G20_OS : 4;  //!< Offset on ADC5 at 20x gain.\r
97         unsigned int rawRID;  //!< Raw, unconditioned resistor ID data.\r
98         unsigned int rawNTC;  //!< Raw, unconditioned thermistor data.\r
99         unsigned int rawVBAT;  //!< Raw, unconditioned battery voltage.\r
100         unsigned int VIN;  //!< Supply voltage, in mV.\r
101         unsigned int VBAT;  //!< Battery voltage, in mV.\r
102         signed int IBAT;  //!< Battery current, in mA.\r
103         signed int discIBAT[4];  //!< Discrete battery current readings, in mA.\r
104         signed int avgIBAT;  //!< Average of the last four IBAT readings, in mA.\r
105 };\r
106 typedef struct ADC_Status_struct ADC_Status_t; //!< For convenience.\r
107 \r
108 \r
109 #endif // STRUCTS_H\r