⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 charger.c

📁 OMAP1030 处理器的ARM 侧硬件测试代码 OMAP1030 是TI的双核处理器
💻 C
📖 第 1 页 / 共 3 页
字号:
	   }
	 }

}



/*-------------------------------------------------------------------------------
// NAME        : RealTime_Voltage
//
// DESCRIPTION : Read the battery voltage     
//
// PARAMETERS  : 
//
// RETURN VALUE: 
//
// LIMITATIONS : None
//------------------------------------------------------------------------------- */
int RealTime_Voltage(void)
{
  int madc_busy = 1;  /* MADC status bit randomly initialized as busy */
  int madc_eocrt = 0; /* MADC real time conversion randomly initialized as working */
  int temp;
  int MSB,LSB,voltage;

  MSI2C_AccessPage(BCI_page);
  
  MSI2C_MasterPollingSendAbb(BCI_BCICTL3,0x30); //connect resisitive divider to main battery and chager input

//MSI2C_AccessPage(PMC_SLAVE_page);

//MSI2C_MasterPollingSendAbb(PMC_SLAVE_BBSPOR_CFG,0x19)//enable resisitor divider for backup battery voltage measure

  MSI2C_AccessPage(MADC_page);
  
  MSI2C_MasterPollingSendAbb(MADC_RTSELECT_MSB,0x03);//select channels 10,9 to convert
//MSI2C_MasterPollingSendAbb(MADC_RTSELECT_LSB,0x40);//select channel 7 for backup battery

  MSI2C_MasterPollingSendAbb(AUX_REG_TOGGLE1,0x02);//enable MADC


    
  MSI2C_AccessPage(INT2_page);// access to the INTH module register page
  
  
  MSI2C_MasterPollingSendAbb(INT2_IT2MASKP1L,0x00);//enable all INT2P1 sources


  //start real time conversition request
    // TSP Configuration 
  ULPD_GsmClockEn();               // Enable GSM clock in ULPD
  TPU_ClkEnable(1);                // Enable the TPU clock
  
  // TPU scenario launch 
  TPU_LoadScenario(startADC);	   // load first scenario in TPU RAM
  TPU_Reset(0);		           // Suppress TPU reset 		
  for(temp=0; temp<5; temp++);  // Wait before next command
  TPU_Enable(1);		   // Enable the TPU 
  for(temp=0; temp<10000; temp++);//Wait loop for TPU scenario to execute


  do
    {
      madc_busy = MSI2C_MasterPollingReceiveAbb(MADC_CTRL_P1) & 0x1;
      madc_eocrt = (MSI2C_MasterPollingReceiveAbb(MADC_CTRL_P1) & 0x4)>>2;
     // UART_Printf(UART2,"\r\n BUSY bit = %d , expected '0' when conversion finished\r\n",madc_busy);
      
     // UART_Printf(UART2,"\r EOCRT bit = %d , expected '1' when conversion finished\r\n\n",madc_eocrt);
      
      
    } while ((madc_busy)||(!madc_eocrt));


  //Read the result of conversition

  MSI2C_AccessPage(MADC_page);

  MSB = MSI2C_MasterPollingReceiveAbb(MADC_RTCH10_MSB);//main battery voltage MSB
  LSB = MSI2C_MasterPollingReceiveAbb(MADC_RTCH10_LSB);//main battery voltage LSB
  voltage = ((MSB & 0x03)<<8)|LSB;
  
  return voltage;
}





/*-------------------------------------------------------------------------------
// NAME        : Start_BB_charge
//
// DESCRIPTION : Start the back-up battery charging     
//
// PARAMETERS  : End of BB charging threshold
//
// RETURN VALUE: 
//
// LIMITATIONS : None
//------------------------------------------------------------------------------- */
void Start_BB_charge(int threshold)
//void Start_BB_charge(void)
{
  int temp1;
  /* Selects the PMC_SLAVE register page */
  MSI2C_AccessPage(PMC_SLAVE_page);
  
  /* Sets the end-of-charge threshold and enables the back-up battery charging */
  MSI2C_MasterPollingSendAbb(PMC_SLAVE_BBSPOR_CFG,(0x18 | (threshold << 1)));
  // MSI2C_MasterPollingSendAbb(PMC_SLAVE_BBSPOR_CFG,0x1f);
  temp1 = MSI2C_MasterPollingReceiveAbb(PMC_SLAVE_BBSPOR_CFG);
  UART_Printf(UART2,"0x%x",temp1);
}



/*-------------------------------------------------------------------------------
// NAME        : Stop_BB_charge
//
// DESCRIPTION : Start the back-up battery charging     
//
// PARAMETERS  : No
//
// RETURN VALUE: 
//
// LIMITATIONS : None
//------------------------------------------------------------------------------- */

void Stop_BB_charge(void)
{
  /* Selects the PMC_SLAVE register page */
  MSI2C_AccessPage(PMC_SLAVE_page);
  
  /* Sets the end-of-charge threshold and enables the back-up battery charging */
  MSI2C_MasterPollingSendAbb(PMC_SLAVE_BBSPOR_CFG, 0x10);
}



/*-------------------------------------------------------------------------------
// NAME        : Start_PWM
//
// DESCRIPTION : Start the battery pulsed charge     
//
// PARAMETERS  : duty cycle
//
// RETURN VALUE: N/A
//
// LIMITATIONS : None
//------------------------------------------------------------------------------- */
void Start_PWM(int duty_cycle)
{
  /* Selects the BCI register page */
  MSI2C_AccessPage(BCI_page);
  
  /* Sets MSBs of the duty cycle in the control register */
  MSI2C_MasterPollingSendAbb(BCI_BCIPWM1, ((duty_cycle >> 2) & 0xff));
  
  /* Sets LSBs of the duty cycle in the control register and enables the pulsed charge */
  MSI2C_MasterPollingSendAbb(BCI_BCIPWM2, ((duty_cycle & 0x3) << 6 | 0x20));
}





/*-------------------------------------------------------------------------------
// NAME        : Stop_PWM
//
// DESCRIPTION : Stop the battery pulsed charge     
//
// PARAMETERS  : N/A
//
// RETURN VALUE: N/A
//
// LIMITATIONS : None
//------------------------------------------------------------------------------- */
void Stop_PWM()
{
  /* Selects the BCI register page */
  MSI2C_AccessPage(BCI_page);
  
  /* Disables the pulsed charge */
  MSI2C_MasterPollingSendAbb(BCI_BCIPWM2, 0x0);
}




/*-------------------------------------------------------------------------------
// NAME        : Refresh_Watchdog
//
// DESCRIPTION : Re-writes the Watchdog key in WDKEY register to keep charging on     
//
// PARAMETERS  : N/A
//
// RETURN VALUE: N/A
//
// LIMITATIONS : None
//------------------------------------------------------------------------------- */
BOOL Refresh_Watchdog(int timer)
{
  int wdkey;
  int loop_time; /* in ms */
  int i,loop_number = 4;
  
  switch(timer)
    {
    case 1 :
      {
	wdkey = 0xAA;
	loop_time = 500;
      }
      break;
      
    case 2 :
      {
	wdkey = 0x55;
	loop_time = 1500;
      }
      break;
      
    case 4 :
      {
	wdkey = 0xDB;
	loop_time = 3500;
      }
      break;
      
    case 8 :
      {
	wdkey = 0xBD;
	loop_time = 7500;
      }
      break;
      
    default:
      break;
    }
  
  
  for (i=0;i<loop_number;i++)
    {
      /* Selects the BCI register page */
      MSI2C_AccessPage(BCI_page);
      
      /* Writes the specific key before the time counter is elapsed */
      MSI2C_MasterPollingSendAbb(BCI_BCIWDKEY, wdkey);
      
      /* delay before re-writing the key */
      TIME_WaitMs(loop_time);
    }
  
  return True;
}        



void Vibrator_Test(void)
 {
  MSI2C_AccessPage(VIB_page);
  MSI2C_MasterPollingSendAbb(0x68,0xa);
 // UART_Printf(UART2,"0x%x",MSI2C_MasterPollingReceiveAbb(0x6a));
 }

/*--------------------------------------------------------------
// NAME        : Battery_Charge_Test
//DESCRIPTION  : Test Triton main battery charge
//PARAMETERS   : NONE
//RETURN VALUE : NONE
//LIMITATIONS  : None
//-------------------------------------------------------------*/
 
void Battery_Charge_Test(void)
{
 int choice = 1;
 int temp;
 char st[80];
 while(choice)
 {
   UART_Printf(UART2,"\n\r");
   UART_Printf(UART2,"\t=================================\r\n");
   UART_Printf(UART2,"\t   Battery charge test menu\r\n");
   UART_Printf(UART2,"\t=================================\r\n");
   UART_Printf(UART2,"\t 0:EXIT\r\n");
   UART_Printf(UART2,"\t 1:I2V conversion calibration\r\n");
   UART_Printf(UART2,"\t 2:Begin constant current charge\r\n");
   UART_Printf(UART2,"\t 3:Begin constant voltage charge\r\n");
   UART_Printf(UART2,"\t 4:Begin the whole charge process\r\n");
   UART_Printf(UART2,"\t 5:Begin Backup Battery charge\r\n");
   UART_Printf(UART2,"\t 6:Vibrator Test\r\n");
   UART_Printf(UART2,"\t==================================\r\n");
   UART_Printf(UART2,"\r\n\tEnter your choice:\r\n");
   
   choice = UART_GetNum(UART2);
   UART_Printf(UART2,"\n\r");
  
  switch(choice)
  {
   case 0: 
   {
    break;
	}

	case 1:
	{
	 do
     {
      temp = I2V_calib(0,400);
	  }while(!temp);
	 UART_Printf(UART2,"\r\nI2V calibation done! 0x%x\r\n",temp);
    
    break;
	}

	case 2:
	{
      UART_Printf(UART2,"\t Constant current charge begin. \r\n");
      CC_charge(850, 100, 2);
     /*
      while(Read_BatteryVoltage() != ) //TBD
	  {
	   SERI_Send("\t The main battery voltage is ???V \r\n"); //TBD
	  }
      SERI_Send("\t The main battery voltage has reached 4.2V \r\n");       
	*/
	break;
	}

    case 3:
	{
	 UART_Printf(UART2,"\t Before you begin constant voltage charge, constant current charge process must be finished!\r\n");
	 UART_Printf(UART2,"\t Sure to begin? (0:N/n  1:Y/y) \r\n");
     temp = UART_GetNum(UART2);
	 if (temp = 1)
     {
      CV_charge(4300,2);
	  }
	 
	 break;
	}

    case 4:
	{
	break;
	}

	case 5:
	{
	 UART_Printf(UART2,"Enter the End of Charge threshold(0 for 3.1V, 1 for 3.2V, 2 for 3.0V, 3 for main battery voltage):");
     temp = UART_GetNum(UART2);
     Start_BB_charge(temp);
	break;
	}
   
   case 6:
  {
   Vibrator_Test();
   break;
   }

	default: 
	break;
   } //end switch
 } //end while 
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -