This class provides APIs to all of the registers of the TI BQ35100 battery gauge, as used on the u-blox C030 primary battery shield.

Dependents:   example-battery-gauge-bq35100

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "greentea-client/test_env.h"
00003 #include "unity.h"
00004 #include "utest.h"
00005 #include "battery_gauge_bq35100.h"
00006 
00007 using namespace utest::v1;
00008 
00009 // ----------------------------------------------------------------
00010 // COMPILE-TIME MACROS
00011 // ----------------------------------------------------------------
00012 
00013 // The gauge enable pin
00014 #define GAUGE_ENABLE_PIN D4
00015 
00016 // Pick some sensible minimum and maximum numbers
00017 #define MAX_TEMPERATURE_READING_C  80
00018 #define MIN_TEMPERATURE_READING_C -20
00019 #define MIN_VOLTAGE_READING_MV     0
00020 #define MAX_VOLTAGE_READING_MV     12000
00021 #define MAX_CURRENT_READING_MA     2000
00022 #define MIN_CURRENT_READING_MA    -2000
00023 #define MIN_CAPACITY_READING_UAH   0
00024 #define MAX_CAPACITY_READING_UAH   32177000 // Some randomly chosen
00025 #define SET_DESIGN_CAPACITY_MAH    32177    // values that match
00026 
00027 
00028 // ----------------------------------------------------------------
00029 // PRIVATE VARIABLES
00030 // ----------------------------------------------------------------
00031 
00032 // I2C interface
00033 I2C * gpI2C = new I2C(I2C_SDA, I2C_SCL);
00034 
00035 // ----------------------------------------------------------------
00036 // PRIVATE FUNCTIONS
00037 // ----------------------------------------------------------------
00038 
00039 // ----------------------------------------------------------------
00040 // TESTS
00041 // ----------------------------------------------------------------
00042 
00043 // Test that the BQ35100 battery gauge can be initialised
00044 void test_init() {
00045     BatteryGaugeBq35100 * pBatteryGauge = new BatteryGaugeBq35100();
00046     
00047     TEST_ASSERT_FALSE(pBatteryGauge->init(NULL, GAUGE_ENABLE_PIN));
00048     TEST_ASSERT(pBatteryGauge->init(gpI2C, GAUGE_ENABLE_PIN));
00049 }
00050 
00051 // Test that a temperature reading can be performed
00052 void test_temperature() {
00053     BatteryGaugeBq35100 * pBatteryGauge = new BatteryGaugeBq35100();
00054     int32_t temperatureC = MIN_TEMPERATURE_READING_C - 1;
00055     
00056     // Call should fail if the battery gauge has not been initialised
00057     TEST_ASSERT_FALSE(pBatteryGauge->getTemperature(&temperatureC));
00058     
00059     // Normal case
00060     TEST_ASSERT(pBatteryGauge->init(gpI2C, GAUGE_ENABLE_PIN));
00061     TEST_ASSERT(pBatteryGauge->getTemperature(&temperatureC));
00062     printf ("Temperature %d C.\n", (int) temperatureC);
00063     // Range check
00064     TEST_ASSERT((temperatureC >= MIN_TEMPERATURE_READING_C) && (temperatureC <= MAX_TEMPERATURE_READING_C));
00065     
00066     // The parameter is allowed to be NULL
00067     TEST_ASSERT(pBatteryGauge->getTemperature(NULL));
00068 }
00069 
00070 // Test that a voltage reading can be performed
00071 void test_voltage() {
00072     BatteryGaugeBq35100 * pBatteryGauge = new BatteryGaugeBq35100();
00073     int32_t voltageMV = MIN_VOLTAGE_READING_MV - 1;
00074     
00075     // Call should fail if the battery gauge has not been initialised
00076     TEST_ASSERT_FALSE(pBatteryGauge->getVoltage(&voltageMV));
00077     
00078     // Normal case
00079     TEST_ASSERT(pBatteryGauge->init(gpI2C, GAUGE_ENABLE_PIN));
00080     TEST_ASSERT(pBatteryGauge->getVoltage(&voltageMV));
00081     printf ("Voltage %.3f V.\n", ((float) voltageMV) / 1000);
00082     // Range check
00083     TEST_ASSERT((voltageMV >= MIN_VOLTAGE_READING_MV) && (voltageMV <= MAX_VOLTAGE_READING_MV));
00084     
00085     // The parameter is allowed to be NULL
00086     TEST_ASSERT(pBatteryGauge->getVoltage(NULL));
00087 }
00088 
00089 // Test that a current reading can be performed
00090 void test_current() {
00091     BatteryGaugeBq35100 * pBatteryGauge = new BatteryGaugeBq35100();
00092     int32_t currentMA = MIN_CURRENT_READING_MA - 1;
00093     
00094     // Call should fail if the battery gauge has not been initialised
00095     TEST_ASSERT_FALSE(pBatteryGauge->getCurrent(&currentMA));
00096     
00097     // Normal case
00098     TEST_ASSERT(pBatteryGauge->init(gpI2C, GAUGE_ENABLE_PIN));
00099     TEST_ASSERT(pBatteryGauge->getCurrent(&currentMA));
00100     printf ("Current %.3f A.\n", ((float) currentMA) / 1000);
00101     // Range check
00102     TEST_ASSERT((currentMA >= MIN_CURRENT_READING_MA) && (currentMA <= MAX_CURRENT_READING_MA));
00103     
00104     // The parameter is allowed to be NULL
00105     TEST_ASSERT(pBatteryGauge->getCurrent(NULL));
00106 }
00107 
00108 // Test that a capacity used reading can be performed
00109 void test_used_capacity() {
00110     BatteryGaugeBq35100 * pBatteryGauge = new BatteryGaugeBq35100();
00111     uint32_t capacityUAh = MIN_CAPACITY_READING_UAH - 1;
00112     
00113     // Call should fail if the battery gauge has not been initialised
00114     TEST_ASSERT_FALSE(pBatteryGauge->getUsedCapacity(&capacityUAh));
00115     
00116     // Normal case
00117     TEST_ASSERT(pBatteryGauge->init(gpI2C, GAUGE_ENABLE_PIN));
00118     TEST_ASSERT(pBatteryGauge->getUsedCapacity(&capacityUAh));
00119     printf ("Used capacity %.3f mAh.\n", ((float) capacityUAh) / 1000);
00120     // Range check
00121     TEST_ASSERT((capacityUAh >= MIN_CAPACITY_READING_UAH) && (capacityUAh <= MAX_CAPACITY_READING_UAH));
00122 
00123     // The parameter is allowed to be NULL
00124     TEST_ASSERT(pBatteryGauge->getUsedCapacity(NULL));
00125 }
00126 
00127 // Test that the design capacity can be set and read
00128 void test_design_capacity() {
00129     BatteryGaugeBq35100 * pBatteryGauge = new BatteryGaugeBq35100();
00130     uint32_t originalDesignCapacity;
00131     uint32_t newDesignCapacity = SET_DESIGN_CAPACITY_MAH;
00132     uint32_t readDesignCapacity = 0;
00133     
00134     // Calls should fail if the battery gauge has not been initialised
00135     TEST_ASSERT_FALSE(pBatteryGauge->getDesignCapacity(&readDesignCapacity));
00136     TEST_ASSERT_FALSE(pBatteryGauge->setDesignCapacity(newDesignCapacity));
00137 
00138     // First get the original design capacity
00139     TEST_ASSERT(pBatteryGauge->init(gpI2C, GAUGE_ENABLE_PIN));
00140     TEST_ASSERT(pBatteryGauge->getDesignCapacity(&originalDesignCapacity));
00141     printf ("Design capacity was originally %d mAh.\n", (unsigned int) originalDesignCapacity);
00142 
00143     // Avoid the old and new values being the same
00144     if (originalDesignCapacity == newDesignCapacity) {
00145         newDesignCapacity--;
00146     }
00147 
00148     // Now set a new value
00149     TEST_ASSERT(pBatteryGauge->setDesignCapacity(newDesignCapacity));
00150     printf ("Design capacity set to %d mAh.\n", (unsigned int) newDesignCapacity);
00151 
00152     // Read the value back and check that it's been set
00153     TEST_ASSERT(pBatteryGauge->getDesignCapacity(&readDesignCapacity));
00154     printf ("Design capacity was read as %d mAh.\n", (unsigned int) readDesignCapacity);
00155     TEST_ASSERT(readDesignCapacity = newDesignCapacity)
00156 
00157     // The parameter in the get call is allowed to be NULL
00158     TEST_ASSERT(pBatteryGauge->getDesignCapacity(NULL));
00159 
00160     // Put the original value back
00161     TEST_ASSERT(pBatteryGauge->setDesignCapacity(originalDesignCapacity));
00162     printf ("Design capacity returned to %d mAh.\n", (unsigned int) originalDesignCapacity);
00163 }
00164 
00165 // Test that a remaining capacity reading can be performed
00166 void test_remaining_capacity() {
00167     BatteryGaugeBq35100 * pBatteryGauge = new BatteryGaugeBq35100();
00168     uint32_t capacityUAh = MIN_CAPACITY_READING_UAH - 1;
00169 
00170     // Call should fail if the battery gauge has not been initialised
00171     TEST_ASSERT_FALSE(pBatteryGauge->getRemainingCapacity(&capacityUAh));
00172     
00173     // Normal case
00174     TEST_ASSERT(pBatteryGauge->init(gpI2C, GAUGE_ENABLE_PIN));
00175     TEST_ASSERT(pBatteryGauge->getRemainingCapacity(&capacityUAh));
00176     printf ("Remaining capacity %.3f mAh.\n", ((float) capacityUAh) / 1000);
00177     // Range check
00178     TEST_ASSERT((capacityUAh >= MIN_CAPACITY_READING_UAH) && (capacityUAh <= MAX_CAPACITY_READING_UAH));
00179 
00180     // The parameter is allowed to be NULL
00181     TEST_ASSERT(pBatteryGauge->getRemainingCapacity(NULL));
00182 }
00183 
00184 // Test that a remaining precentage reading can be performed
00185 void test_remaining_percentage() {
00186     BatteryGaugeBq35100 * pBatteryGauge = new BatteryGaugeBq35100();
00187     int32_t percentage = -1;
00188 
00189     // Call should fail if the battery gauge has not been initialised
00190     TEST_ASSERT_FALSE(pBatteryGauge->getRemainingPercentage(&percentage));
00191     
00192     // Normal case
00193     TEST_ASSERT(pBatteryGauge->init(gpI2C, GAUGE_ENABLE_PIN));
00194     TEST_ASSERT(pBatteryGauge->getRemainingPercentage(&percentage));
00195     printf ("Remaining capacity %d%%.\n", (signed int) percentage);
00196     // Range check
00197     TEST_ASSERT((percentage >= 0) && (percentage <= 100));
00198 
00199     // The parameter is allowed to be NULL
00200     TEST_ASSERT(pBatteryGauge->getRemainingPercentage(NULL));
00201 }
00202 
00203 // Test behaviours with gauging on
00204 void test_gauging() {
00205     BatteryGaugeBq35100 * pBatteryGauge = new BatteryGaugeBq35100();
00206     uint32_t capacityUAh = MIN_CAPACITY_READING_UAH - 1;
00207     
00208     // Call should fail if the battery gauge has not been initialised
00209     TEST_ASSERT_FALSE(pBatteryGauge->enableGauge());
00210     TEST_ASSERT_FALSE(pBatteryGauge->disableGauge());
00211     TEST_ASSERT_FALSE(pBatteryGauge->isGaugeEnabled());
00212     
00213     // Normal case, gauging should be off to begin with
00214     TEST_ASSERT(pBatteryGauge->init(gpI2C, GAUGE_ENABLE_PIN));
00215     TEST_ASSERT_FALSE(pBatteryGauge->isGaugeEnabled());
00216     
00217     // Enable gauge, without non-volatile storage
00218 
00219     TEST_ASSERT(pBatteryGauge->enableGauge());
00220     TEST_ASSERT(pBatteryGauge->getUsedCapacity(&capacityUAh));
00221     printf ("Used capacity %.3f mAh.\n", ((float) capacityUAh) / 1000);
00222     // Range check
00223     TEST_ASSERT((capacityUAh >= MIN_CAPACITY_READING_UAH) && (capacityUAh <= MAX_CAPACITY_READING_UAH));
00224     TEST_ASSERT(pBatteryGauge->isGaugeEnabled());
00225     TEST_ASSERT(pBatteryGauge->disableGauge());
00226     TEST_ASSERT_FALSE(pBatteryGauge->isGaugeEnabled());
00227 
00228     // Enable gauge, with non-volatile storage
00229     TEST_ASSERT(pBatteryGauge->enableGauge(true));
00230     TEST_ASSERT(pBatteryGauge->getUsedCapacity(&capacityUAh));
00231     printf ("Used capacity %.3f mAh.\n", ((float) capacityUAh) / 1000);
00232     // Range check
00233     // TODO: any way to check that the non-volatileness has worked?
00234     TEST_ASSERT((capacityUAh >= MIN_CAPACITY_READING_UAH) && (capacityUAh <= MAX_CAPACITY_READING_UAH));
00235     TEST_ASSERT(pBatteryGauge->isGaugeEnabled());
00236     TEST_ASSERT(pBatteryGauge->disableGauge());
00237     TEST_ASSERT_FALSE(pBatteryGauge->isGaugeEnabled());
00238 }
00239 
00240 // Test the new battery call
00241 void test_new_battery() {
00242     BatteryGaugeBq35100 * pBatteryGauge = new BatteryGaugeBq35100();
00243     uint32_t originalDesignCapacity;
00244     uint32_t newDesignCapacity = SET_DESIGN_CAPACITY_MAH;
00245     uint32_t readDesignCapacity = 0;
00246 
00247     // Call should fail if the battery gauge has not been initialised
00248     TEST_ASSERT_FALSE(pBatteryGauge->newBattery(1000));
00249     
00250     // Normal case
00251     TEST_ASSERT(pBatteryGauge->init(gpI2C, GAUGE_ENABLE_PIN));
00252     // Get the original design capacity so that we can set it back
00253     // at the end
00254     TEST_ASSERT(pBatteryGauge->getDesignCapacity(&originalDesignCapacity));
00255     printf ("Design capacity was originally %d mAh.\n", (unsigned int) originalDesignCapacity);
00256 
00257     // Avoid the old and new values being the same
00258     if (originalDesignCapacity == newDesignCapacity) {
00259         newDesignCapacity--;
00260     }
00261 
00262     // Now add the new battery
00263     TEST_ASSERT(pBatteryGauge->newBattery(newDesignCapacity));
00264     printf ("New battery added with design capacity %d mAh.\n", (unsigned int) newDesignCapacity);
00265 
00266     // Read the value back and check that it's been set
00267     TEST_ASSERT(pBatteryGauge->getDesignCapacity(&readDesignCapacity));
00268     printf ("Design capacity was read as %d mAh.\n", (unsigned int) readDesignCapacity);
00269     TEST_ASSERT(readDesignCapacity = newDesignCapacity)
00270 
00271     // Put the original value back
00272     TEST_ASSERT(pBatteryGauge->setDesignCapacity(originalDesignCapacity));
00273     printf ("Design capacity returned to %d mAh.\n", (unsigned int) originalDesignCapacity);
00274 }
00275 
00276 // Test get/set config
00277 void test_advanced_get_set_config() {
00278     BatteryGaugeBq35100 * pBatteryGauge = new BatteryGaugeBq35100();
00279     int32_t address = 0x4036; // Manufacturer Info Block A01, a 1 byte field
00280     char originalValue;
00281     char oldValue;
00282     char newValue;
00283     
00284     // Calls should fail if the battery gauge has not been initialised
00285     TEST_ASSERT_FALSE(pBatteryGauge->advancedGetConfig(address, &originalValue, sizeof(originalValue)));
00286     TEST_ASSERT_FALSE(pBatteryGauge->advancedSetConfig(address, &newValue, sizeof(newValue)));
00287 
00288     // Initialise the battery gauge
00289     TEST_ASSERT(pBatteryGauge->init(gpI2C, GAUGE_ENABLE_PIN));
00290     
00291     // Normal case
00292     TEST_ASSERT(pBatteryGauge->advancedGetConfig(address, &originalValue, sizeof(originalValue)));
00293     // Invert the result and write it back
00294     oldValue = originalValue;
00295     printf ("Original value was 0x%02x.\n", oldValue);
00296     newValue = ~oldValue;
00297     printf ("Setting it to 0x%02x.\n", newValue);
00298     TEST_ASSERT(pBatteryGauge->advancedSetConfig(address, &newValue, sizeof(newValue)));
00299     // Read it and check that it has changed
00300     TEST_ASSERT(pBatteryGauge->advancedGetConfig(address, &oldValue, sizeof(oldValue)));
00301     printf ("Read back 0x%02x.\n", oldValue);
00302     TEST_ASSERT_EQUAL_UINT8(newValue, oldValue);
00303     
00304     // Put the original value back again
00305     TEST_ASSERT(pBatteryGauge->advancedSetConfig(address, &originalValue, sizeof(originalValue)));
00306 }
00307 
00308 // Send a control word
00309 void test_advanced_control() {
00310     BatteryGaugeBq35100 * pBatteryGauge = new BatteryGaugeBq35100();
00311     uint16_t controlWord = 0x0003; // get HW version
00312     uint16_t response = 0;
00313     
00314     // Call should fail if the battery gauge has not been initialised
00315     TEST_ASSERT_FALSE(pBatteryGauge->advancedSendControlWord(controlWord, &response));
00316     
00317     // Initialise the battery gauge
00318     TEST_ASSERT(pBatteryGauge->init(gpI2C, GAUGE_ENABLE_PIN));
00319     
00320     // Normal case
00321     TEST_ASSERT(pBatteryGauge->advancedSendControlWord(controlWord, &response));
00322     // FW version must be 0x00a8
00323     TEST_ASSERT_EQUAL_UINT16(0x00a8, response);
00324 
00325     // The parameter is allowed to be null
00326     TEST_ASSERT(pBatteryGauge->advancedSendControlWord(controlWord, NULL));
00327 }
00328 
00329 // Read using a standard command
00330 void test_advanced_get() {
00331     BatteryGaugeBq35100 * pBatteryGauge = new BatteryGaugeBq35100();
00332     uint8_t address = 0x06; // Temperature
00333     uint16_t value = 0;
00334     int32_t temperatureC = -1;
00335     
00336     // Call should fail if the battery gauge has not been initialised
00337     TEST_ASSERT_FALSE(pBatteryGauge->advancedGet(address, &value));
00338     
00339     // Initialise the battery gauge
00340     TEST_ASSERT(pBatteryGauge->init(gpI2C, GAUGE_ENABLE_PIN));
00341     
00342     // Normal case
00343     TEST_ASSERT(pBatteryGauge->advancedGet(address, &value));
00344     // Get the temperature via the standard API command
00345     TEST_ASSERT(pBatteryGauge->getTemperature(&temperatureC));
00346     // Convert the value returned into a temperature reading and compare
00347     // it with the real answer, allowing a 1 degree tolerance in case
00348     // it has changed between readings.
00349     TEST_ASSERT_INT32_WITHIN (1, temperatureC, ((int32_t) value / 10) - 273);
00350 
00351     // The parameter is allowed to be null
00352     TEST_ASSERT(pBatteryGauge->advancedGet(address, NULL));
00353 }
00354 
00355 // Test that the security mode of the chip can be changed
00356 void test_advanced_security_mode() {
00357     BatteryGaugeBq35100 * pBatteryGauge = new BatteryGaugeBq35100();
00358     BatteryGaugeBq35100::SecurityMode securityMode;
00359 
00360     // Get the existing device mode and then set it to sealed
00361     TEST_ASSERT(pBatteryGauge->init(gpI2C, GAUGE_ENABLE_PIN));
00362     printf ("Calling advancedGetSecurityMode()...\n");
00363     securityMode = pBatteryGauge->advancedGetSecurityMode();
00364     printf ("Calling advancedSetSecurityMode(SECURITY_MODE_SEALED)...\n");
00365     TEST_ASSERT(pBatteryGauge->advancedSetSecurityMode(BatteryGaugeBq35100::SECURITY_MODE_SEALED));
00366 
00367     delete pBatteryGauge;
00368     pBatteryGauge = new BatteryGaugeBq35100();
00369     // Calls should fail if the battery gauge has not been initialised
00370     printf ("Calling advancedGetSecurityMode()...\n");
00371     TEST_ASSERT(pBatteryGauge->advancedGetSecurityMode() == BatteryGaugeBq35100::SECURITY_MODE_UNKNOWN);
00372     printf ("Calling advancedSetSecurityMode(SECURITY_MODE_UNSEALED)...\n");
00373     TEST_ASSERT_FALSE(pBatteryGauge->advancedSetSecurityMode(BatteryGaugeBq35100::SECURITY_MODE_UNSEALED));
00374     
00375     // Normal case
00376     printf ("Calling init()...\n");
00377     TEST_ASSERT(pBatteryGauge->init(gpI2C, GAUGE_ENABLE_PIN));
00378     printf ("Calling advancedGetSecurityMode()...\n");
00379     TEST_ASSERT(pBatteryGauge->advancedGetSecurityMode() == BatteryGaugeBq35100::SECURITY_MODE_SEALED);
00380     
00381     // These calls should fail
00382     // TODO do a thing that only works when unsealed
00383     // TODO do a thing that only works when full access
00384 
00385     // Now unseal it
00386     printf ("Calling advancedSetSecurityMode(SECURITY_MODE_UNSEALED)...\n");
00387     TEST_ASSERT(pBatteryGauge->advancedSetSecurityMode(BatteryGaugeBq35100::SECURITY_MODE_UNSEALED));
00388     
00389     // This call should now pass
00390     // TODO do a thing that only works when unsealed
00391     
00392     // But this should still fail
00393     // TODO do a thing that only works when full access
00394 
00395     // Seal it again
00396     printf ("Calling advancedSetSecurityMode(SECURITY_MODE_SEALED)...\n");
00397     TEST_ASSERT(pBatteryGauge->advancedSetSecurityMode(BatteryGaugeBq35100::SECURITY_MODE_SEALED));
00398 
00399     // Now allow full access, which should fail as you can't get there from SEALED
00400     printf ("Calling advancedSetSecurityMode(SECURITY_MODE_FULL_ACCESS)...\n");
00401     TEST_ASSERT_FALSE(pBatteryGauge->advancedSetSecurityMode(BatteryGaugeBq35100::SECURITY_MODE_FULL_ACCESS));
00402     
00403     // Now unseal it
00404     printf ("Calling advancedSetSecurityMode(SECURITY_MODE_UNSEALED)...\n");
00405     TEST_ASSERT(pBatteryGauge->advancedSetSecurityMode(BatteryGaugeBq35100::SECURITY_MODE_UNSEALED));
00406     
00407     // *Now* allow full access, which should succeed
00408     printf ("Calling advancedSetSecurityMode(SECURITY_MODE_FULL_ACCESS)...\n");
00409     TEST_ASSERT(pBatteryGauge->advancedSetSecurityMode(BatteryGaugeBq35100::SECURITY_MODE_FULL_ACCESS));
00410     
00411     // These calls should now both pass
00412     // TODO do a thing that only works when unsealed
00413     // TODO do a thing that only works when full access
00414 
00415     // Put the device back the way it was
00416     TEST_ASSERT(pBatteryGauge->advancedSetSecurityMode(securityMode));
00417 }
00418 
00419 // Reset the BQ35100 battery gauge chip
00420 void test_advanced_reset() {
00421     BatteryGaugeBq35100 * pBatteryGauge = new BatteryGaugeBq35100();
00422     BatteryGaugeBq35100::SecurityMode securityMode;
00423 
00424     // Call should fail if the battery gauge has not been initialised
00425     TEST_ASSERT_FALSE(pBatteryGauge->advancedReset());
00426 
00427     // Get the existing security mode and then set it to unsealed
00428     TEST_ASSERT(pBatteryGauge->init(gpI2C, GAUGE_ENABLE_PIN));
00429 
00430     printf ("Calling advancedGetSecurityMode()...\n");
00431     securityMode = pBatteryGauge->advancedGetSecurityMode();
00432     printf ("Calling advancedSetSecurityMode(SECURITY_MODE_UNSEALED)...\n");
00433     TEST_ASSERT(pBatteryGauge->advancedSetSecurityMode(BatteryGaugeBq35100::SECURITY_MODE_UNSEALED));
00434    
00435     // TODO: modify a thing that will later be reset
00436     
00437     // Now reset the chip
00438     printf ("Calling advancedReset()...\n");
00439     TEST_ASSERT(pBatteryGauge->advancedReset());
00440     
00441     // TODO check that the thing has been reset
00442 
00443     // Put the security mode back to what it was
00444     TEST_ASSERT(pBatteryGauge->advancedSetSecurityMode(securityMode));
00445 }
00446 
00447 // ----------------------------------------------------------------
00448 // TEST ENVIRONMENT
00449 // ----------------------------------------------------------------
00450 
00451 // Setup the test environment
00452 utest::v1::status_t test_setup(const size_t number_of_cases) {
00453     // Setup Greentea, timeout is long enough to run these tests with
00454     // DEBUG_BQ35100 defined
00455     GREENTEA_SETUP(250, "default_auto");
00456     return verbose_test_setup_handler(number_of_cases);
00457 }
00458 
00459 // Test cases
00460 Case cases[] = {
00461     Case("Initialisation", test_init),
00462     Case("Temperature read", test_temperature),
00463     Case("Voltage read", test_voltage),
00464     Case("Current read", test_current),
00465     Case("Used capacity read", test_used_capacity),
00466     Case("Design capacity read/set", test_design_capacity),
00467     Case("Remaining capacity read", test_remaining_capacity),
00468     Case("Remaining precentage read", test_remaining_percentage),
00469     Case("Gauging", test_gauging),
00470     Case("New battery", test_new_battery),
00471     Case("Advanced get/set config", test_advanced_get_set_config),
00472     Case("Advanced control", test_advanced_control),
00473     Case("Advanced get", test_advanced_get),
00474     Case("Advanced security mode", test_advanced_security_mode),
00475     Case("Advanced reset", test_advanced_reset)
00476 };
00477 
00478 Specification specification(test_setup, cases);
00479 
00480 // ----------------------------------------------------------------
00481 // MAIN
00482 // ----------------------------------------------------------------
00483 
00484 // Entry point into the tests
00485 int main() {    
00486     bool success = false;
00487     
00488     if (gpI2C != NULL) {        
00489         success = !Harness::run(specification);
00490     } else {
00491         printf ("Unable to instantiate I2C interface.\n");
00492     }
00493     
00494     return success;
00495 }
00496 
00497 // End Of File