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

📄 charger.c

📁 OMAP1030 处理器的ARM 侧硬件测试代码 OMAP1030 是TI的双核处理器
💻 C
📖 第 1 页 / 共 3 页
字号:
#include "charger.h"
#include "UART_IrDA.h"

/*-------------------------------------------------------------------------------
// NAME        : precharge_off
//
// DESCRIPTION : stops the AC and USB precharge     
//
// PARAMETERS  : 
//
// RETURN VALUE: 
//
// LIMITATIONS : None
//------------------------------------------------------------------------------- */
void precharge_off(void)
{
  /* Selects the TRITON BCI register page */
  MSI2C_AccessPage(BCI_page);
  
  /* Disables both the AC precharge and the USB precharge */
  MSI2C_MasterPollingSendAbb(BCI_BCICTL3,0xC0);
  
  /* A) DONE */
  
  UART_Printf(UART2,"\r\n AC Precharge and USB precharge disabled\r\n"); 
}

/*-------------------------------------------------------------------------------
// NAME        : precharge_on
//
// DESCRIPTION : start the AC and USB precharge     
//
// PARAMETERS  : 
//
// RETURN VALUE: 
//
// LIMITATIONS : None
//------------------------------------------------------------------------------- */
void precharge_on(void)
{
  /* Selects the TRITON BCI register page */
  MSI2C_AccessPage(BCI_page);
  
  /* Enables both the AC precharge and the USB precharge */
  MSI2C_MasterPollingSendAbb(BCI_BCICTL3,0x00);
  
  /* A) DONE */
  
  UART_Printf(UART2,"\r\n AC Precharge and USB precharge enabled\r\n"); 
}

/*-------------------------------------------------------------------------------
// NAME        : MADC_RT_poll
//
// DESCRIPTION : Performs an MADC Real Time conversion of the selected channels     
//
// PARAMETERS  : list of selected channels to be converted (integer)
//
// RETURN VALUE: '1' is returned when the conversion is finished
//
// LIMITATIONS : None
//------------------------------------------------------------------------------- */

int MADC_RT_poll(int list)
{
  int madc_busy = 1;  /* MADC status bit randomly initialized as busy */
  int madc_eocrt = 0; /* MADC real time conversion randomly initialized as working */
  int tempo;
  int previous_content;      
  char st[80]  ;
  
  /* access to the BCI register page */
  MSI2C_AccessPage(BCI_page);
  
  /* Read previous BCICTL3 content */
  previous_content = MSI2C_MasterPollingReceiveAbb(BCI_BCICTL3) & 0xff;
  
  /* Set the resistor divider bridges for MESBAT and MESVAC */
  MSI2C_MasterPollingSendAbb(BCI_BCICTL3,(previous_content | 0x30));  
  
  /* access to the INTH module register page */
  MSI2C_AccessPage(INT2_page);
  
  /* mask the end-of-conversion INT2P1 */
  MSI2C_MasterPollingSendAbb(INT2_IT2MASKP1L,0x8); 
  
  /* access to the MADC module register page */
  MSI2C_AccessPage(MADC_page);
  
  /* MADC ON */
  MSI2C_MasterPollingSendAbb(AUX_REG_TOGGLE1,0x2);
  
  /* channel selection (LSB) */
  MSI2C_MasterPollingSendAbb(MADC_RTSELECT_LSB,(list & 0xff));
  
  /* channel selection (MSB) */
  MSI2C_MasterPollingSendAbb(MADC_RTSELECT_MSB,(list & 0x700)>>8);
  
  
  /* START Real Time conversion */
  
  /* 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(tempo=0; tempo<5; tempo++);  /* Wait before next command */
  TPU_Enable(1);		   /* Enable the TPU */
  
  
  
  /* Polling on the BUSY bit */
  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\n EOCRT bit = %d , expected '1' when conversion finished\r\n",madc_eocrt);
     
      
    } while ((madc_busy)||(!madc_eocrt));
  
  /* access to the INTH module register page */
  MSI2C_AccessPage(INT2_page);
  
  /* unmask the end-of-conversion INT2P1 */
  MSI2C_MasterPollingSendAbb(INT2_IT2MASKP1L,0x0); 
  
  return (1);
}


/*---------------------------------------------------------------------------------
// NAME        : MADC_RT_INT2
//
// DESCRIPTION : Performs an MADC Real Time conversion of the selected channels     
//
// PARAMETERS  : list of selected channels to be converted (integer)
//
// RETURN VALUE: '1' is returned when the TPU scenario is launched
//
// LIMITATIONS : None
//--------------------------------------------------------------------------------- */

int MADC_RT_INT2(int list)
{
  int tempo;
  int previous_content;      
  char st[80]  ;
  
  /* access to the BCI register page */
  MSI2C_AccessPage(BCI_page);
  
  /* Read previous BCICTL3 content */
  previous_content = MSI2C_MasterPollingReceiveAbb(BCI_BCICTL3) & 0xff;
  
  /* Set the resistor divider bridges for MESBAT and MESVAC */
  MSI2C_MasterPollingSendAbb(BCI_BCICTL3,(previous_content | 0x30));  
  
  /* access to the INTH module register page */
  MSI2C_AccessPage(INT2_page);
  
  /* enable all INT2P1 sources */
  MSI2C_MasterPollingSendAbb(INT2_IT2MASKP1L,0x00); 
  
  /* access to the MADC module register page */
  MSI2C_AccessPage(MADC_page);
  
  /* MADC ON */
  MSI2C_MasterPollingSendAbb(AUX_REG_TOGGLE1,0x2);
  
  /* channel selection (LSB) */
  MSI2C_MasterPollingSendAbb(MADC_RTSELECT_LSB,(list & 0xff));
  
  /* channel selection (MSB) */
  MSI2C_MasterPollingSendAbb(MADC_RTSELECT_MSB,(list & 0x700)>>8);
  
  
  /* START Real Time conversion */
  
  /* 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(tempo=0; tempo<5; tempo++);        /* Wait before next command */
  TPU_Enable(1);		         /* Enable the TPU */
  for(tempo=0; tempo<10000; tempo++);    /* Wait loop for TPU scenario to execute */ 
  
  return (1);
}


/*-------------------------------------------------------------------------------
// NAME        : MADC_SP1_poll
//
// DESCRIPTION : Performs an MADC asynchronous conversion of all the channels     
//
// PARAMETERS  : No
//
// RETURN VALUE: '1' is returned when the conversion is finished
//
// LIMITATIONS : None
//------------------------------------------------------------------------------- */
//
int MADC_SP1_poll()
{
  int madc_busy = 1;    /* MADC status bit initialized as busy */
  int madc_eocrt = 0;   /* MADC real time conversion initialized as working */
  int previous_content;
  char st[80]  ;
  
  /* access to the BCI register page */
  MSI2C_AccessPage(BCI_page);
  
  /* Read previous BCICTL3 content */
  previous_content = MSI2C_MasterPollingReceiveAbb(BCI_BCICTL3) & 0xff;
  
  /* Set the resistor divider bridges for MESBAT and MESVAC */
  MSI2C_MasterPollingSendAbb(BCI_BCICTL3,(previous_content | 0x30));  
  
  /* access to the INTH module register page */
  MSI2C_AccessPage(INT2_page);
  
  /* mask the end-of-conversion INT2P1 */
  MSI2C_MasterPollingSendAbb(INT2_IT2MASKP1L,0x8); 
  
  /* access to the MADC module register page */
  MSI2C_AccessPage(MADC_page);
  
  /* MADC ON */
  MSI2C_MasterPollingSendAbb(AUX_REG_TOGGLE1,0x2);
  
  /* Read previous MADC_CTRL_P1 content */
  previous_content = MSI2C_MasterPollingReceiveAbb(MADC_CTRL_P1) & 0xf;
  
  /* START SP1 conversion (set SP1 bit) */
  MSI2C_MasterPollingSendAbb(MADC_CTRL_P1,(previous_content | 0x8));
  
  
  
  /* Polling on the BUSY bit */
  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));
  
  /* access to the INTH module register page */
  MSI2C_AccessPage(INT2_page);
  
  /* unmask the end-of-conversion INT2P1 */
  MSI2C_MasterPollingSendAbb(INT2_IT2MASKP1L,0x0); 
  
  return (1);
}



int MADC_SP1_poll_Measure()
{
  int madc_busy = 1;    /* MADC status bit initialized as busy */
  int madc_eocrt = 0;   /* MADC real time conversion initialized as working */
  int previous_content;
  char st[80]  ;
  
  /* access to the BCI register page */
  MSI2C_AccessPage(BCI_page);
  
  /* Read previous BCICTL3 content */
  previous_content = MSI2C_MasterPollingReceiveAbb(BCI_BCICTL3) & 0xff;
  
  /* Set the resistor divider bridges for MESBAT and MESVAC */
  MSI2C_MasterPollingSendAbb(BCI_BCICTL3,(previous_content | 0x30));  
  
  /* access to the INTH module register page */
  MSI2C_AccessPage(INT2_page);
  
  /* mask the end-of-conversion INT2P1 */
  MSI2C_MasterPollingSendAbb(INT2_IT2MASKP1L,0x8); 
  
  /* access to the MADC module register page */
  MSI2C_AccessPage(MADC_page);
  
  /* MADC ON */
  MSI2C_MasterPollingSendAbb(AUX_REG_TOGGLE1,0x2);
  
  /* Read previous MADC_CTRL_P1 content */
  previous_content = MSI2C_MasterPollingReceiveAbb(MADC_CTRL_P1) & 0xf;
  
  /* START SP1 conversion (set SP1 bit) */
  MSI2C_MasterPollingSendAbb(MADC_CTRL_P1,(previous_content | 0x8));
  
  
 
  /* Polling on the BUSY bit */
 
  do
    {
      madc_busy = MSI2C_MasterPollingReceiveAbb(MADC_CTRL_P1) & 0x1;
      madc_eocrt = (MSI2C_MasterPollingReceiveAbb(MADC_CTRL_P1) & 0x4)>>2;
     // sprintf(st,"\r\n BUSY bit = %d , expected '0' when conversion finished\r\n",madc_busy);
     // SERI_Send(st);
      //sprintf(st,"\r EOCRT bit = %d , expected '1' when conversion finished\r\n\n",madc_eocrt);
      //SERI_Send(st);
      
    } while ((madc_busy)||(!madc_eocrt));


  
  /* access to the INTH module register page */
  MSI2C_AccessPage(INT2_page);
  
  /* unmask the end-of-conversion INT2P1 */
  MSI2C_MasterPollingSendAbb(INT2_IT2MASKP1L,0x0); 
  
  return (1);
}


/*-------------------------------------------------------------------------------
// NAME        : MADC_SP1_INT2
//
// DESCRIPTION : Performs an MADC asynchronous conversion of all the channels     
//
// PARAMETERS  : No
//
// RETURN VALUE: '1' is returned when the conversion is finished
//
// LIMITATIONS : None
//------------------------------------------------------------------------------- */

int MADC_SP1_INT2()
{
  int previous_content;
  
  /* access to the BCI register page */
  MSI2C_AccessPage(BCI_page);
  
  /* Read previous BCICTL3 content */
  previous_content = MSI2C_MasterPollingReceiveAbb(BCI_BCICTL3) & 0xff;
  
  /* Set the resistor divider bridges for MESBAT and MESVAC */
  MSI2C_MasterPollingSendAbb(BCI_BCICTL3,(previous_content | 0x30));  
  
  /* access to the INTH module register page */
  MSI2C_AccessPage(INT2_page);
  
  /* enable all INT2P1 sources */
  MSI2C_MasterPollingSendAbb(INT2_IT2MASKP1L,0x00);
  
  /* access to the MADC module register page */
  MSI2C_AccessPage(MADC_page);
  
  /* MADC ON */
  MSI2C_MasterPollingSendAbb(AUX_REG_TOGGLE1,0x2);
  

⌨️ 快捷键说明

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