Esempio n. 1
0
void SetupGPTimer(unsigned int nTimerNum,void *const pMemory,ADI_CALLBACK pfCallback, ADI_TMR_HANDLE *const phTimer,
		          uint32_t nPeriod,uint32_t nWidth)
{
	ADI_TMR_RESULT 	 eTmrResult;
/* Open the timer */
           if( (eTmrResult = adi_tmr_Open (nTimerNum,
                       		pMemory,
                       		ADI_TMR_MEMORY,
                       		pfCallback,
                       		NULL,
                       		phTimer)) != ADI_TMR_SUCCESS)
            {
                /* Failed to open the timer handle the error here */
            }

           /*
            * Use the GP timer's API's to configure and enable the timer
            *
            */
           eTmrResult = adi_tmr_EnableDataInt(*phTimer,false);
           eTmrResult = adi_tmr_EnableStatusInt(*phTimer,false);
       	/* Set the mode to PWM OUT */
           eTmrResult = adi_tmr_SetMode(*phTimer, ADI_TMR_MODE_CONTINUOUS_PWMOUT);

           /* Set the IRQ mode to get interrupt after counts till TMR_PERIOD register value */
           eTmrResult = adi_tmr_SetIRQMode(*phTimer, ADI_TMR_IRQMODE_PERIOD);
           /* Set the Period */
           eTmrResult = adi_tmr_SetPeriod(*phTimer,nPeriod);

           /* Set the timer width */
       	   eTmrResult = adi_tmr_SetWidth(*phTimer, nWidth);

       	   /* Enable the timer */
       	   eTmrResult = adi_tmr_Enable(*phTimer, true);


}
int main(void)
{
     
    /* Clock initialization */
    SystemInit();

    /* test system initialization */
    test_Init();
        //adi_gpio_OutputEnable(EN_5V, true);
        //adi_gpio_SetHigh(EN_5V);
    
  /*    SWITCHED TO LOW POWER MODE - ACTIVE MODE    */
  pwrResult = adi_pwr_EnterLowPowerMode(ADI_PWR_MODE_ACTIVE,NULL,0x00);  //Low Power Active mode
  DEBUG_RESULT("\n Failed to enter active mode %04d",pwrResult,ADI_PWR_SUCCESS);
  /*    BUCK CONVERTER ENABLED TO REDUCE POWER      */
  adi_pwr_EnableHPBuck(true); 
  
  NUM_FAN_500MS_CYCLES = fanOnTime/0.5;//Number of 500ms cycles equals ratio of given fanOnTime to 0.5 
  
    do 
    {
      if(ADI_PWR_SUCCESS != adi_pwr_Init())
        {
          DEBUG_MESSAGE("Failed to intialize the power service\n");
          break;
        }
      
      if(ADI_PWR_SUCCESS != adi_pwr_SetLFClockMux(ADI_CLOCK_MUX_LFCLK_LFXTAL))
      {
        return(eResult);
      }
      
      if(ADI_PWR_SUCCESS != adi_pwr_EnableClockSource(ADI_CLOCK_SOURCE_HFXTAL, true))
      {
        return(eResult);
      }

      if(ADI_PWR_SUCCESS != adi_pwr_SetRootClockMux(ADI_CLOCK_MUX_ROOT_HFXTAL))
      {
        return(eResult);
      }

      
      if(ADI_PWR_SUCCESS != adi_pwr_EnableClockSource(ADI_CLOCK_SOURCE_LFXTAL,true))
      {
        return(eResult);
      }
   
      if (ADI_PWR_SUCCESS != adi_pwr_SetClockDivider(ADI_CLOCK_HCLK,1))
      {
          DEBUG_MESSAGE("Failed to intialize the power service\n");
      }
      if (ADI_PWR_SUCCESS != adi_pwr_SetClockDivider(ADI_CLOCK_PCLK,1))
      {
          DEBUG_MESSAGE("Failed to intialize the power service\n");
      }

  
      if(ADI_RTC_SUCCESS !=rtc_Init())
        {
          DEBUG_MESSAGE("\nFailed to initialize RTC device \n");
        }
      

      
      if(ADI_GPIO_SUCCESS != adi_gpio_Init(gpioMemory, ADI_GPIO_MEMORY_SIZE))
        {
            DEBUG_MESSAGE("adi_gpio_Init failed\n");
            break;
        }
      //P0.13 --> LED3
      adi_gpio_OutputEnable(LED3, true);
      //P1.12 --> LED4 
      adi_gpio_OutputEnable(LED4, true);
      adi_gpio_OutputEnable(CO_HEATER, true);
      adi_gpio_OutputEnable(CO_SENSE, true);
      adi_gpio_OutputEnable(PM25_LED, true);
      adi_gpio_OutputEnable(PM25_FAN, true);
      adi_gpio_OutputEnable(DBG_ST8_PIN, true);
      adi_gpio_OutputEnable(DBG_ADC_PIN, true);

      adi_gpio_SetLow(CO_HEATER);
      adi_gpio_SetLow(CO_SENSE);
      adi_gpio_SetLow(PM25_LED);
      adi_gpio_SetLow(PM25_FAN);
      adi_gpio_SetLow(DBG_ADC_PIN);   
      adi_gpio_SetHigh(LED3);
      adi_gpio_SetHigh(LED4);
      
      ADC_Setup();
      
      adi_tmr_Open(TIMER_DEVICE_1,aDeviceMemory1,ADI_TMR_MEMORY_SIZE,&hDevice1); 
      adi_tmr_RegisterCallback( hDevice1, GPTimer1Callback ,hDevice1);
      
      adi_tmr_SetPrescaler(hDevice1, ADI_GPT_PRESCALER_256);
      adi_tmr_SetLoadValue( hDevice1, GPT1_LOAD_1SEC);
     
      DEBUG_MESSAGE("AQ Sensor initializing!\n");    
        
    }while(0);
    
    do
    {}
    while(1);
    
    
 
}
Esempio n. 3
0
void GP_Timer6_Init(void)
{
	ADI_TMR_RESULT eTmrResult   =   ADI_TMR_SUCCESS;
    /* Open the timer */
    if( (eTmrResult = adi_tmr_Open (
            GP_TIMER6_NUM,
            TimerMemory6,
            ADI_TMR_MEMORY,
            Timer6_ISR,
            NULL,
            &ghTimer6)) != ADI_TMR_SUCCESS)
    {
        printf("Timer open failed 0x%08X \n", eTmrResult);
    }
    // Set the mode to PWM OUT
     if((eTmrResult = adi_tmr_SetMode(
             ghTimer6,
             ADI_TMR_MODE_CONTINUOUS_PWMOUT)) != ADI_TMR_SUCCESS)
     {
         printf("Failed to open timer in PWM out mode 0x%08X \n", eTmrResult);
     }
      //Set the IRQ mode to get interrupt after timer counts to Delay + Width
     if((eTmrResult = adi_tmr_SetIRQMode(
             ghTimer6,
             ADI_TMR_IRQMODE_PERIOD)) != ADI_TMR_SUCCESS)
     {
         printf("Failed to set the timer IRQ mode 0x%08X \n", eTmrResult);
     }

      //Set the Period
     if((eTmrResult = adi_tmr_SetPeriod(
             ghTimer6,
             TIMER6_PERIOD)) != ADI_TMR_SUCCESS)
     {
         printf("Failed to set the timer Period 0x%08X \n", eTmrResult);
     }

      //Set the timer width
     if((eTmrResult = adi_tmr_SetWidth(
             ghTimer6,
             TIMER6_WIDTH)) != ADI_TMR_SUCCESS)
     {
         printf("Failed to set the timer Width 0x%08X \n", eTmrResult);
     }

     // Set the timer Delay
     if((eTmrResult = adi_tmr_SetDelay(
             ghTimer6,
             TIMER6_DELAY)) != ADI_TMR_SUCCESS)
     {
         printf("Failed to set the timer Delay 0x%08X \n", eTmrResult);
     }

      //Enable the timer to stop gracefully,used in PWM mode,set the PWM wave more graceful.
     if((eTmrResult = adi_tmr_EnableGracefulStop(
             ghTimer6,
             true)) != ADI_TMR_SUCCESS)
     {
         printf("Failed to enable the timer to stop gracefully 0x%08X \n", eTmrResult);
     }
     adi_tmr_Enable(ghTimer6, true);

}
int main(void)
{
     
    /* Clock initialization */
    SystemInit();

    /* test system initialization */
    test_Init();
        //adi_gpio_OutputEnable(EN_5V, true);
        //adi_gpio_SetHigh(EN_5V);
        
    do 
    {
      if(ADI_PWR_SUCCESS != adi_pwr_Init())
        {
          DEBUG_MESSAGE("Failed to intialize the power service\n");
          break;
        }
      
      if(ADI_PWR_SUCCESS != adi_pwr_SetLFClockMux(ADI_CLOCK_MUX_LFCLK_LFXTAL))
      {
        return(eResult);
      }
      
      if(ADI_PWR_SUCCESS != adi_pwr_EnableClockSource(ADI_CLOCK_SOURCE_HFXTAL, true))
      {
        return(eResult);
      }

      if(ADI_PWR_SUCCESS != adi_pwr_SetRootClockMux(ADI_CLOCK_MUX_ROOT_HFXTAL))
      {
        return(eResult);
      }

      
      if(ADI_PWR_SUCCESS != adi_pwr_EnableClockSource(ADI_CLOCK_SOURCE_LFXTAL,true))
      {
        return(eResult);
      }
   
      if (ADI_PWR_SUCCESS != adi_pwr_SetClockDivider(ADI_CLOCK_HCLK,1))
      {
          DEBUG_MESSAGE("Failed to intialize the power service\n");
      }
      if (ADI_PWR_SUCCESS != adi_pwr_SetClockDivider(ADI_CLOCK_PCLK,1))
      {
          DEBUG_MESSAGE("Failed to intialize the power service\n");
      }

  
      if(ADI_RTC_SUCCESS !=rtc_Init())
        {
          DEBUG_MESSAGE("\nFailed to initialize RTC device \n");
        }
      

      
      if(ADI_GPIO_SUCCESS != adi_gpio_Init(gpioMemory, ADI_GPIO_MEMORY_SIZE))
        {
            DEBUG_MESSAGE("adi_gpio_Init failed\n");
            break;
        }
      //P0.13 --> LED3
      adi_gpio_OutputEnable(LED3, true);
      //P1.12 --> LED4 
      adi_gpio_OutputEnable(LED4, true);
      adi_gpio_OutputEnable(CO_HEATER, true);
      adi_gpio_OutputEnable(CO_SENSE, true);
      adi_gpio_OutputEnable(PM25_LED, true);
      adi_gpio_OutputEnable(PM25_FAN, true);
      adi_gpio_OutputEnable(DBG_ST8_PIN, true);
      adi_gpio_OutputEnable(DBG_ADC_PIN, true);

      adi_gpio_SetLow(CO_HEATER);
      adi_gpio_SetLow(CO_SENSE);
      adi_gpio_SetLow(PM25_LED);
      adi_gpio_SetLow(PM25_FAN);
      adi_gpio_SetLow(DBG_ADC_PIN);   
      adi_gpio_SetHigh(LED3);
      adi_gpio_SetHigh(LED4);
      
      ADC_Setup();
      
      adi_tmr_Open(TIMER_DEVICE_1,aDeviceMemory1,ADI_TMR_MEMORY_SIZE,&hDevice1); 
      adi_tmr_RegisterCallback( hDevice1, GPTimer1Callback ,hDevice1);
      
      adi_tmr_SetPrescaler(hDevice1, ADI_GPT_PRESCALER_256);
      adi_tmr_SetLoadValue( hDevice1, GPT1_LOAD_1SEC);
     
      DEBUG_MESSAGE("AQ Sensor initializing!\n");    
        
    }while(0);
    
    do
    {}
    while(1);
    
    
 
}