AllJoyn/Samples/BACnetAdapter/bacnet-stack-0.8.2/ports/xplained/ASF/xmega/drivers/rtc32/rtc32.c
enum vbat_status_code rtc_vbat_system_check(bool first_time_startup)
{
    enum vbat_status_code vbat_status;
    uint8_t flags = VBAT.STATUS;

    /* Ensure the module is clocked to be able to check the registers */
    sysclk_enable_module(SYSCLK_PORT_GEN, SYSCLK_RTC);

    /*
     * Check if a sufficient voltage was detected on the VBAT input.
     * The brown-out detector (BBBOD) will be sampled once when the
     * device starts up and the result is visible as the BBPWR flag.
     */
    if (flags & VBAT_BBPWR_bm) {
        vbat_status = VBAT_STATUS_NO_POWER;
    } else {
        /*
         * We have sufficient power, now we check if a power-on-reset
         * (BBPOR) was detected on VBAT. This is visible from the BBPORF
         * flag which is also only updated once when the device starts.
         */
        if (flags & VBAT_BBPORF_bm) {
            if (first_time_startup) {
                vbat_status = VBAT_STATUS_INIT;
            } else {
                vbat_status = VBAT_STATUS_BBPOR;
            }
        } else if (flags & VBAT_BBBORF_bm) {
            vbat_status = VBAT_STATUS_BBBOD;
        } else {
            VBAT.CTRL = VBAT_ACCEN_bm;
            if (flags & VBAT_XOSCFAIL_bm) {
                vbat_status = VBAT_STATUS_XOSCFAIL;
            } else {
                vbat_status = VBAT_STATUS_OK;
            }
        }
    }
    return vbat_status;
}
/**
 * \brief Checks battery backup system status.
 *
 * This function should be called once after each reset of the device in order
 * to determine the current battery backup status.
 * This function can not be used to continuously poll the status of the backup
 * system during normal operation since most status flags are only latched
 * during the power up sequence of the device.
 *
 * \param first_time_startup Indicates whether or not the VBAT system has been
 * started previously. This should be set to \c true upon the first call to this
 * function, and \c false upon later calls. Typically, the value for this
 * parameter should be stored in, e.g., EEPROM, in order to preserve the value
 * when main system power is lost.
 *
 * \returns Battery backup system status.
 */
\brief Checks battery backup system status.
This function should be called once after each reset of the device in order
to determine the current battery backup status.
This function can not be used to continuously poll the status of the backup
system during normal operation since most status flags are only latched
during the power up sequence of the device.

\param first_time_startup Indicates whether or not the VBAT system has been
started previously. This should be set to \c true upon the first call to this
function, and \c false upon later calls. Typically, the value for this
parameter should be stored in, e.g., EEPROM, in order to preserve the value
when main system power is lost.

\returns Battery backup system status.
\ brief Checks battery backup system status . This function should be called once after each reset of the device in order to determine the current battery backup status . This function can not be used to continuously poll the status of the backup system during normal operation since most status flags are only latched during the power up sequence of the device . \ param first_time_startup Indicates whether or not the VBAT system has been started previously . This should be set to \ c true upon the first call to this function and \ c false upon later calls . Typically the value for this parameter should be stored in e . g . EEPROM in order to preserve the value when main system power is lost . \ returns Battery backup system status .
enum vbat_status_code rtc_vbat_system_check(bool first_time_startup)
{
    enum vbat_status_code vbat_status;
    uint8_t flags = VBAT.STATUS;
    sysclk_enable_module(SYSCLK_PORT_GEN, SYSCLK_RTC);
    if (flags & VBAT_BBPWR_bm) {
        vbat_status = VBAT_STATUS_NO_POWER;
    } else {
        if (flags & VBAT_BBPORF_bm) {
            if (first_time_startup) {
                vbat_status = VBAT_STATUS_INIT;
            } else {
                vbat_status = VBAT_STATUS_BBPOR;
            }
        } else if (flags & VBAT_BBBORF_bm) {
            vbat_status = VBAT_STATUS_BBBOD;
        } else {
            VBAT.CTRL = VBAT_ACCEN_bm;
            if (flags & VBAT_XOSCFAIL_bm) {
                vbat_status = VBAT_STATUS_XOSCFAIL;
            } else {
                vbat_status = VBAT_STATUS_OK;
            }
        }
    }
    return vbat_status;
}
enum vbat_status_code rtc_vbat_system_check ( bool first_time_startup ) { enum vbat_status_code vbat_status ; uint8_t flags = VBAT . STATUS ; sysclk_enable_module ( SYSCLK_PORT_GEN , SYSCLK_RTC ) ; if ( flags & VBAT_BBPWR_bm ) { vbat_status = VBAT_STATUS_NO_POWER ; } else { if ( flags & VBAT_BBPORF_bm ) { if ( first_time_startup ) { vbat_status = VBAT_STATUS_INIT ; } else { vbat_status = VBAT_STATUS_BBPOR ; } } else if ( flags & VBAT_BBBORF_bm ) { vbat_status = VBAT_STATUS_BBBOD ; } else { VBAT . CTRL = VBAT_ACCEN_bm ; if ( flags & VBAT_XOSCFAIL_bm ) { vbat_status = VBAT_STATUS_XOSCFAIL ; } else { vbat_status = VBAT_STATUS_OK ; } } } return vbat_status ; }
\brief Checks battery backup system status.
\ brief Checks battery backup system status .
/* Ensure the module is clocked to be able to check the registers */ /*
     * Check if a sufficient voltage was detected on the VBAT input.
     * The brown-out detector (BBBOD) will be sampled once when the
     * device starts up and the result is visible as the BBPWR flag.
     */ /*
         * We have sufficient power, now we check if a power-on-reset
         * (BBPOR) was detected on VBAT. This is visible from the BBPORF
         * flag which is also only updated once when the device starts.
         */