view src/cs/drivers/drv_app/pwr/pwr_disch.c @ 629:3231dd9b38c1

armio.c: make GPIOs 8 & 13 outputs driving 1 on all "classic" targets Calypso GPIOs 8 & 13 are pinmuxed with MCUEN1 & MCUEN2, respectively, and on powerup these pins are MCUEN, i.e., outputs driving 1. TI's code for C-Sample and earlier turns them into GPIOs configured as outputs also driving 1 - so far, so good - but TI's code for BOARD 41 (which covers D-Sample, Leonardo and all real world Calypso devices derived from the latter) switches them from MCUEN to GPIOs, but then leaves them as inputs. Given that the hardware powerup state of these two pins is outputs driving 1, every Calypso board design MUST be compatible with such driving; typically these GPIO signals will be either unused and unconnected or connected as outputs driving some peripheral. Turning these pins into GPIO inputs will result in floating inputs on every reasonably-wired board, thus I am convinced that this configuration is nothing but a bug on the part of whoever wrote this code at TI. This floating input bug had already been fixed earlier for GTA modem and FCDEV3B targets; the present change makes the fix unconditional for all "classic" targets. The newly affected targets are D-Sample, Leonardo, Tango and GTM900.
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 02 Jan 2020 05:38:26 +0000
parents c93a236e0d50
children
line wrap: on
line source

/*******************************************************************************
 *
 * pwr_disch.c
 *
 * Purpose: This file contains functions for battery discharge management.
 *
 * (C) Texas Instruments 2001
 *
 ******************************************************************************/

#include "rv/rv_defined_swe.h"	   // for RVM_PWR_SWE

#ifdef RVM_PWR_SWE

#include "abb/abb.h"
#include "rvm/rvm_use_id_list.h"
#include "pwr/pwr_disch.h"
#include "power/power.h"
#include "spi/spi_task.h"
#include "pwr/pwr_cust.h"
#include "pwr/pwr_messages.h"
#include "spi/spi_env.h"
#include "pwr/pwr_env.h"

/* Define a pointer to the PWR Environment control block.  */
extern T_PWR_ENV_CTRL_BLK *pwr_env_ctrl_blk;




/*******************************************************************************
** Function         pwr_discharge_timer_process
**
** Description      
**
*******************************************************************************/
void pwr_discharge_timer_process(void)
{
   rvf_send_trace("TIMER3", 6, NULL_PARAM, RV_TRACE_LEVEL_DEBUG_LOW, PWR_USE_ID);
   if (SPI_GBL_INFO_PTR->is_gsm_on == TRUE)
   {
      pwr_handle_discharge(); /* battery discharge management */
   } 

}



/*******************************************************************************
** Function         pwr_handle_discharge
**
** Description      Compares the battery voltage with some thresholds and, if a 
**                  threshold is passed, sends event(s) to the upper layer.
**                  Re-start the timer with a value depending on the discharge 
**                  level.
**
*******************************************************************************/
void pwr_handle_discharge(void)
{
   UINT16 timer_value;
   UINT16 status;
   UINT16 bat_madc_voltage, bat_voltage;
   static T_PWR_PERCENT remain_capacity = 100;  /* since this variable is declared as static */
                                                /* it will keep its value from one function call to the other */
   T_PWR_PERCENT current_capacity;
  
   if (SPI_GBL_INFO_PTR->is_adc_on == FALSE) 
   {
      /* Start VBAT channel conversion by writing in the result register */
      ABB_Write_Register_on_page(PAGE0, VBATREG, 0x0000);
      rvf_delay(RVF_MS_TO_TICKS(5));
      bat_madc_voltage = ABB_Read_Register_on_page(PAGE0, VBATREG);
      rvf_send_trace("battery voltage (MADC code) ", 28, bat_madc_voltage, RV_TRACE_LEVEL_DEBUG_LOW, PWR_USE_ID);
   }
   else /* The L1 asks for ADC conversions */
   {
#ifndef _WINDOWS
      bat_madc_voltage = SPI_GBL_INFO_PTR->adc_result[0];
#else
      bat_madc_voltage = ABB_Read_Register_on_page(PAGE0, VBATREG);
#endif
   }

   /* Find the remaining capacity in the battery corresponding to this new voltage */
   bat_voltage = pwr_adc_to_mvolt(bat_madc_voltage);
   rvf_send_trace("battery voltage (mV) ", 21, bat_voltage, RV_TRACE_LEVEL_DEBUG_LOW, PWR_USE_ID);
   current_capacity = pwr_get_capacity_vs_voltage(bat_voltage);
   rvf_send_trace("current capacity (%) ", 21, current_capacity, RV_TRACE_LEVEL_DEBUG_LOW, PWR_USE_ID);

   status = ABB_Read_Status();

   /* Determine if a threshold has been passed */
   if (current_capacity != remain_capacity) 
   {
      /* a new threshold has been passed */
      remain_capacity = current_capacity;

      /* informs the upper layer */
      pwr_send_bat_discharge_event(remain_capacity);

      if (status & CHGPRES)   /* charger plugged */
      {
         if (remain_capacity == CHARGE_START_AGAIN_CAPACITY)
         {
            PWR_Charger_Plug();
         }
      }

      else  /* charger not plugged */
      {
         if(remain_capacity <= pwr_env_ctrl_blk->power_alert.remain_capa_threshold)
         {
            /* informs the upper layer that the battery is low */
            pwr_send_low_bat_event(remain_capacity);
            timer_value = SPI_TIMER3_INTERVAL_BIS; /* 10 s */
         }
         else  
         {
#ifndef _WINDOWS
            timer_value = SPI_TIMER3_INTERVAL; /* 1 minute */
#else
            timer_value = SPI_TIMER3_INTERVAL_BIS; /* 10 s */
#endif
         }

         /* Start timer with a value depending on the remaining capacity in the battery */
         rvf_start_timer (SPI_TIMER3,
                          RVF_MS_TO_TICKS (timer_value),
                          FALSE);
      }
   }

   else /* the capacity has not changed */
   {
#ifndef _WINDOWS
      timer_value = SPI_TIMER3_INTERVAL; /* 1 minute */
#else
      timer_value = SPI_TIMER3_INTERVAL_BIS; /* 10 s */
#endif

      /* Start timer with a value depending on the remaining capacity in the battery */
      rvf_start_timer (SPI_TIMER3,
                       RVF_MS_TO_TICKS (timer_value),
                       FALSE);

   }
}

#endif /* #ifdef RVM_PWR_SWE */