static void prvClockInit ( void )
{
    if(ADI_PWR_SUCCESS != adi_pwr_Init())
    {
        dprintf("\n Failed to initialize the power service \n");
    }
    if(ADI_PWR_SUCCESS != adi_pwr_SetClockDivider(ADI_CLOCK_HCLK,1))
    {
        dprintf("Failed to set ADI_CLOCK_HCLK \n");
    }
    if(ADI_PWR_SUCCESS != adi_pwr_SetClockDivider(ADI_CLOCK_PCLK,1))
    {
        dprintf("Failed to set ADI_CLOCK_PCLK \n");
    }
    
    return;
}
示例#2
0
void InitPower(void)
{
	uint32_t   fcclk = 0;
	uint32_t   fsclk = 0;
	uint32_t   fvco = 0;
	uint32_t   core;
	uint32_t   system;
	uint32_t expectedEvents;
	ADI_PWR_RESULT result;


	bError = false;
	callbackEvents = 0;
	expectedEvents = 0;

	result = adi_pwr_Init(CLKIN, CORE_MAX, SYSTEM_MAX, VCO_MIN);
	CheckResult(result);

//	result = adi_pwr_InstallCallback(PWRCallback);
//	CheckResult(result);

	setDefaultPower();

	// set max freq
	result = adi_pwr_SetFreq(CORE_MAX, SYSTEM_MAX);
	CheckResult(result);

	expectedEvents += 2; //pre and post event

	// get the freq settings
	result = adi_pwr_GetCoreFreq(&fcclk);
	CheckResult(result);

	result = adi_pwr_GetSystemFreq(&fsclk);
	CheckResult(result);
	if ((fcclk < (CORE_MAX-CLKIN)) || (fsclk < (SYSTEM_MAX-CLKIN)))
	{
		bError = true;
	}
	system_parameters.fcclk = fcclk;
	system_parameters.fsclk = fsclk;


}
示例#3
0
ADI_UART_RESULT UARTx_IntMode_Init(int UARTx, long Baudrate, int Stopbit_Num, int Check_Mode, UART_Data_Struct* Uart_Struct)
{

	ADI_UART_RESULT    eResult = ADI_UART_FAILURE;
	uint32_t 	div;
    /* System Clock Frequencies*/
    uint32_t   fsysclk = 0u;   /* System Clock */
    uint32_t   fsclk0  = 0u;   /* System Clock0 */
    uint32_t   fsclk1  = 0u;   /* System Clock1 */


    /*初始化接收数据结构体*/
    Uart_Struct->p_Buff_Start = Uart_Struct->Buff;
    Uart_Struct->p_Buff_end = Uart_Struct->p_Buff_Start + Length_UART_BUFF - 512;//p_Buff_end后面需要留一部分512字节的长度用于缓存,这样可以减少环形节点的异常处理,提高效率
    Uart_Struct->p_Buff_Read = Uart_Struct->p_Buff_Start;
    Uart_Struct->p_Buff_Write = Uart_Struct->p_Buff_Start;
    Uart_Struct->Num_Frame = 0;
    Uart_Struct->flag = 0;
    Uart_Struct->flag_Buff_Over = 0;
    Uart_Struct->p_Buff_Tx_Start = Uart_Struct->Buff_Tx;
    Uart_Struct->p_Buff_Tx = Uart_Struct->Buff_Tx;
    Uart_Struct->flag_Tx_Finish = 0;


    /* Initialize Power service */
    if(adi_pwr_Init(myCLKIN, myCORE_MAX, mySYSCLK_MAX, myVCO_MIN) != ADI_PWR_SUCCESS)
    {
    	printf("0x%08X :Failed to initialize power service \n", eResult);
    }


    if(adi_pwr_GetSystemFreq(&fsysclk, &fsclk0, &fsclk1) != ADI_PWR_SUCCESS)
     {
         return ADI_UART_SYSCLK_FAILED;
     }

	if( UARTx == UART0)
	{

	    /* PORTx_MUX registers */
	    *pREG_PORTD_MUX |= UART0_TX_PORTD_MUX | UART0_RX_PORTD_MUX;

	    /* PORTx_FER registers */
	    *pREG_PORTD_FER |= UART0_TX_PORTD_FER | UART0_RX_PORTD_FER;

		*pREG_UART0_CTL = 0;
		*pREG_UART0_CTL |= UART_W8b;
		switch ( Stopbit_Num )
		{
			case Onebit: break;

			case Onehalfbit:*pREG_UART0_CTL |= UART_STBH;
							break;

			case twobit:*pREG_UART0_CTL |= UART_STB;
						break;

			case twohalfbit:*pREG_UART0_CTL |= UART_STB | UART_STBH;
						break;

			default:return ADI_UART_FAILURE;

		}
		switch ( Check_Mode )
		{
			case CHECK_PARITY_NO:break;

			case CHECK_PARITY_ODD:*pREG_UART0_CTL |= UART_PEN;
									break;

			case CHECK_PARITY_EVEN:	*pREG_UART0_CTL |= UART_PEN | UART_EPS;
									break;

			default:return ADI_UART_FAILURE;

		}
		//设置波特率
		div = fsclk0 / Baudrate;
//		*pREG_UART0_CLK=(((uint32_t)BIT31)|div);		//Bit clock prescaler = 1
		*pREG_UART0_CLK=(((uint32_t)BIT31)|div);		//Bit clock prescaler = 1
		//设置中断
		adi_int_InstallHandler(80,IsrUart0Tx,Uart_Struct,true);
		adi_int_InstallHandler(81,IsrUart0Rx,Uart_Struct,true);

		*pREG_UART0_IMSK_SET |= BIT0;		//允许接收中断
		*pREG_UART0_CTL |= UART_EN;		//使能串口
		Uart0_T();
		return ADI_UART_SUCCESS;

	}else
	{

	    /* PORTx_MUX registers */
	    *pREG_PORTG_MUX = UART1_TX_PORTG_MUX | UART1_RX_PORTG_MUX;

	    /* PORTx_FER registers */
	    *pREG_PORTG_FER = UART1_TX_PORTG_FER | UART1_RX_PORTG_FER;

		*pREG_UART1_CTL = 0;
		*pREG_UART1_CTL |= UART_W8b;
		switch ( Stopbit_Num )
		{
			case Onebit: break;

			case Onehalfbit:*pREG_UART1_CTL |= UART_STBH;
							break;

			case twobit:*pREG_UART1_CTL |= UART_STB;
						break;

			case twohalfbit:*pREG_UART1_CTL |= UART_STB | UART_STBH;
						break;

			default:return ADI_UART_FAILURE;

		}
		switch ( Check_Mode )
		{
			case CHECK_PARITY_NO:break;

			case CHECK_PARITY_ODD:*pREG_UART1_CTL |= UART_PEN;
									break;

			case CHECK_PARITY_EVEN:	*pREG_UART1_CTL |= UART_PEN | UART_EPS;
									break;

			default:return ADI_UART_FAILURE;

		}
		//设置波特率
		div = fsysclk / Baudrate;
		*pREG_UART1_CLK=(((uint32_t)BIT31)|div);		//Bit clock prescaler = 1

		//设置中断
		adi_int_InstallHandler(83,IsrUart1Tx,Uart_Struct,true);
		adi_int_InstallHandler(84,IsrUart1Rx,Uart_Struct,true);

		*pREG_UART1_IMSK_SET |= BIT0;		//允许接收中断
		*pREG_UART1_CTL |= UART_EN;		//使能串口
		return ADI_UART_SUCCESS;

	}
}
示例#4
0
u32 adi_ssl_Init(void) {

    u32 i;
    u32 Result;

    do {
        // initialize the interrupt manager, parameters are
        //      pointer to memory for interrupt manager to use
        //      memory size (in bytes)
        //      location where the number of secondary handlers that can be
        //          supported will be stored
        //      parameter for adi_int_EnterCriticalRegion
        //          (always NULL for VDK and standalone systems)
        Result = adi_int_Init(InterruptServiceData,
                              sizeof(InterruptServiceData),
                              &i, ADI_SSL_ENTER_CRITICAL);
        while ((ADI_INT_RESULT_SUCCESS != Result) \
            ||(ADI_SSL_INT_NUM_SECONDARY_HANDLERS != i))
        {
        }

       //  initialize the EBIU, parameters are
       //  address of table containing RAM parameters
       //  0 - reserved field, always 0
       //  Ignores result, so it can keep going if it's already initialized
        Result = adi_ebiu_Init(config_ram, 0);
        while ((ADI_EBIU_RESULT_SUCCESS != Result) &&
        (ADI_EBIU_RESULT_ALREADY_INITIALIZED != Result))
        {

        }

        // initialize power, parameters are
        //      address of table containing processor information
        // keep going if it's already initialized
        Result = adi_pwr_Init(config_power);
        while ((ADI_PWR_RESULT_SUCCESS != Result) &&
            (ADI_PWR_RESULT_ALREADY_INITIALIZED != Result))
        {

        }
        
        // U-boot done setFreq
        Result = adi_pwr_SetFreq (256000000, 256000000, ADI_PWR_DF_ON);
        while (ADI_PWR_RESULT_SUCCESS != Result)
        {

        }
        
        // initialize port control, parameters are
        //      parameter for adi_int_EnterCriticalRegion
        //          (always NULL for VDK and standalone systems)
        Result = adi_ports_Init(ADI_SSL_ENTER_CRITICAL);
        while (ADI_PORTS_RESULT_SUCCESS != Result)
        {

        }

        // initialize deferred callback service if needed, parameters are
        //      pointer to data
        //      size of data
        //      location where number of servers is stored
        //      parameter for adi_int_EnterCriticalRegion
        //          (always NULL for VDK and standalone systems)
#if     (ADI_SSL_DCB_NUM_SERVERS != 0)
        Result = adi_dcb_Init(DeferredCallbackServiceData,
                              sizeof(DeferredCallbackServiceData),
                              &i, ADI_SSL_ENTER_CRITICAL);
        while ((ADI_DCB_RESULT_SUCCESS != Result) \
            || (ADI_SSL_DCB_NUM_SERVERS != i))
        {

        }
#endif

        // initialize the dma manager if needed, parameters are
        //      pointer to memory for the DMA manager to use
        //      memory size (in bytes)
        //      parameter for adi_int_EnterCriticalRegion
        //          (always NULL for VDK and standalone systems)
#if     (ADI_SSL_DMA_NUM_CHANNELS != 0)
        Result = adi_dma_Init(DMAServiceData,
                              sizeof(DMAServiceData),
                              &i, &adi_dma_ManagerHandle, ADI_SSL_ENTER_CRITICAL);
        while ((Result != ADI_DMA_RESULT_SUCCESS) \
            || (ADI_SSL_DMA_NUM_CHANNELS != i))
        {

        }
#endif


        // initialize the flag manager, parameters are
        //      pointer to memory for the flag service to use
        //      memory size (in bytes)
        //      location where the number of flag callbacks that can be
        //          supported will be stored
        //      parameter for adi_int_EnterCriticalRegion
        //          (always NULL for VDK and standalone systems)
        Result = adi_flag_Init(FlagServiceData, sizeof(FlagServiceData),
                               &i, ADI_SSL_ENTER_CRITICAL);
        while ((Result != ADI_FLAG_RESULT_SUCCESS) \
            || (ADI_SSL_FLAG_NUM_CALLBACKS != i))
        {

        }

        // initialize the timer manager, parameters are
        //      parameter for adi_int_EnterCriticalRegion
        //          (always NULL for VDK and standalone systems)
        Result = adi_tmr_Init(ADI_SSL_ENTER_CRITICAL);
        while (ADI_TMR_RESULT_SUCCESS != Result)
        {

        }


#if !defined(ADI_SSL_RTC_NO_INIT)
        // initialize the RTC service
        //      parameter for adi_int_EnterCriticalRegion
        //          (always NULL for VDK and standalone systems)
        Result = adi_rtc_Init(ADI_SSL_ENTER_CRITICAL);
        while (ADI_RTC_RESULT_SUCCESS != Result)
        {

        }
#endif

        // initialize the semaphore service if needed, parameters are
        //      pointer to memory for the semaphore service to use
        //      memory size (in bytes)
        //      parameter for adi_int_EnterCriticalRegion
        //          (always NULL for VDK and standalone systems)
#if     (ADI_SSL_SEM_NUM_SEMAPHORES != 0)
        Result = adi_sem_Init(SemaphoreServiceData,
                              sizeof(SemaphoreServiceData),
                              &i, ADI_SSL_ENTER_CRITICAL);
        while ((ADI_SEM_RESULT_SUCCESS != Result) \
            || (ADI_SSL_SEM_NUM_SEMAPHORES != i))
        {

        }
#endif

        // initialize the device manager if needed, parameters are
        //      pointer to data for the device manager to use
        //      size of the data in bytes
        //      location where the number of devices that can be managed
        //          will be stored
        //      location where the device manager handle will be stored
        //      parameter for adi_int_EnterCriticalRegion() function
        //          (always NULL for standalone and VDK)
#if     (ADI_SSL_DEV_NUM_DEVICES != 0)
        Result = adi_dev_Init(DevMgrData, sizeof(DevMgrData),
                              &i,  &adi_dev_ManagerHandle,
                              ADI_SSL_ENTER_CRITICAL);
        while ((Result != ADI_DEV_RESULT_SUCCESS) \
            || (ADI_SSL_DEV_NUM_DEVICES != i))
        {

        }
#endif
     } while (0);     // WHILE (no errors or 1 pass complete)
    return (Result);
}
int main(int argc, char *argv[])
{
    ADI_BLER_RESULT      eResult;
    ADI_PWR_RESULT       ePwr;
    uint32_t             nTime;
    uint8_t *            aTemplateSensorName = (unsigned char *)"ADI_BLE_TEMPLATESENSOR";

    /* Explicitly disable the watchdog timer */ 
    *pREG_WDT0_CTL = 0x0u;

    /* Pinmux */
    adi_initpinmux();

    /* Initialize clocks */
    ePwr = adi_pwr_Init(); 
    PRINT_ERROR("Error initializing the power service.\r\n", ePwr, ADI_PWR_SUCCESS);

    ePwr = adi_pwr_SetClockDivider(ADI_CLOCK_HCLK, 1u);     
    PRINT_ERROR("Error configuring the core clock.\r\n", ePwr, ADI_PWR_SUCCESS);
    ePwr = adi_pwr_SetClockDivider(ADI_CLOCK_PCLK, 1u);

    PRINT_ERROR("Error configuring the peripheral clock.\r\n", ePwr, ADI_PWR_SUCCESS);
    
    /*Initialize Timer */
    INIT_TIME();

#ifndef ADI_DEBUG
    /* Initialize UART redirection in release mode only */
    common_Init();
#endif

    PRINTF(("Starting Template Sensor Example.\r\n"));

    /* Initialize radio */
    eResult = adi_ble_Init(ApplicationCallback, NULL);
    PRINT_ERROR("Error initializing the radio.\r\n", eResult, ADI_BLER_SUCCESS);

    eResult = adi_radio_RegisterDevice(ADI_BLE_ROLE_PERIPHERAL);
    PRINT_ERROR("Error registering the radio.\r\n", eResult, ADI_BLER_SUCCESS);

    eResult = adi_radio_SetLocalBluetoothDevName(aTemplateSensorName, strlen((const char *) aTemplateSensorName), 0u, 0u);
    PRINT_ERROR("Error setting local device name.\r\n", eResult, ADI_BLER_SUCCESS);

    SetAdvertisingMode();

    /* Initialize data exchange profile */
    eResult = adi_radio_Register_DataExchangeServer();
    PRINT_ERROR("Error registering data exchange server.\r\n", eResult, ADI_BLER_SUCCESS);

    /* Initialize static components of the data packet. For a single "sensor" example these will not change. */
    eDataPacket.nPacketHeader = ADI_SET_HEADER(ADI_DATA_PACKET_TYPE, SENSOR_ID);

    /* The sensor type that is set here is the type of sensor this demo will simulate on the Android application */
    eDataPacket.eSensorType = ADI_APP_SIMULATE_SENSOR_TYPE;

    /* Now enter infinite loop waiting for connection and then data exchange events */
    PRINTF(("Waiting for connection. Initiate connection on central device please.\r\n"));

    /* WHILE(forever) */
    while(1u)
    {
        /* Dispatch events - they will arrive in the application callback */
        eResult = adi_ble_DispatchEvents(ADI_APP_DISPATCH_TIMEOUT);
        PRINT_ERROR("Error dispatching events to the callback.\r\n", eResult, ADI_BLER_SUCCESS);
        
        /* If connected, send data */
        if (gbConnected == true)
        {
            adi_ble_GetConnectionInfo(&sConnInfo);

            /* Fill the sensor data packet according to the sensor packet documentation */
            
            nTime = GET_TIME();
            memcpy(&eDataPacket.aTimestamp ,&nTime,4u);

            TemplateSensorRead((uint8_t*)&eDataPacket.aPayload);

            eResult = adi_radio_DE_SendData(sConnInfo.nConnHandle, DATAEXCHANGE_PACKET_SIZE, (uint8_t*)&eDataPacket);
            PRINT_ERROR("Error sending the data.\r\n", eResult, ADI_BLER_SUCCESS);
        }
        /* If disconnected, make sure we are in the right mode */
        else
        {
            if (geMode != PERIPHERAL_ADV_MODE)
            {
                SetAdvertisingMode();           
            }
        }        
    }
}
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);
    
    
 
}
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);
    
    
 
}
void main(void)
{
    uint8_t *pFilledFrame   = NULL;
    uint8_t *pDisplayFrame  = NULL;
    bool     bDisplayEnabled = false;

    adi_initComponents(); /* auto-generated code */

    /* Adjust the core frequency */
    if (adi_pwr_Init (PROC_CLOCK_IN, PROC_MAX_CORE_CLOCK, PROC_MAX_SYS_CLOCK, PROC_MIN_VCO_CLOCK) != ADI_PWR_SUCCESS)
    {
        printf ("Failed to initialize Power service\n");
        return;
    }
    if(adi_pwr_SetFreq(PROC_REQ_CORE_CLOCK, PROC_REQ_SYS_CLOCK)!= ADI_PWR_SUCCESS )
    {
        printf ("Failed to initialize Power service\n");
        return;
    }

    /* Configure the Software controlled switches on BF609 EZ-Board */
    //ConfigSoftSwitches_BF609();
#if defined(VIDEOLOOPBACKYUV_720P)
    FINBOARD_CLK_Synth_Config_OUT4_74_25_MHz();
#else
    FINBOARD_CLK_Synth_Config_OUT4_27_00_MHz();
#endif
    FINBOARD_LED_Drivers_Init();
    FINBOARD_LED_Drivers_Config(1);

    /* Configure the sensor */
    if(ConfigureSensor() != SUCCESS)
    {
        printf("Failed to configure Sensor \n");
        return;
    }

    /* Configure the sensor for display */
    if(ConfigureEncoder() != SUCCESS)
    {
        printf("Failed to configure LCD \n");
        return;
    }
    FINBOARD_ADV7511_16bit_Mode();

    /* Submit the frame for filling */
    if(SubmitEmptyVideoFrame() != SUCCESS)
    {
        printf("Failed to submit empty video frame to the sensor \n");
        return;
    }

    /* Submit the next frame for filling */
    if(SubmitEmptyVideoFrame() != SUCCESS)
    {
        printf("Failed to submit empty video frame to the sensor \n");
        return;
    }

    /* Enable the sensor to capture the frames */
    if(EnableSensor(true) != SUCCESS)
    {
        printf("Failed to enable sensor \n");
        return;
    }

#if (EXAMPLE_TIMEOUT > 0)
    while(NumFilledFrames < EXAMPLE_TIMEOUT)
#else
    while(1)
#endif
    {
        /* Get filled frame from sensor */
        if(GetFilledVideoFrame(&pFilledFrame) != SUCCESS)
        {
            printf("Failed to get filled frame from the sensor \n");
            return;
        }

        if(pFilledFrame != NULL)
        {
            NumFilledFrames++;

            pDisplayFrame = pFilledFrame;

            /* Submit the next frame for filling */
            if(SubmitEmptyVideoFrame() != SUCCESS)
            {
                printf("Failed to submit empty video frame to the sensor \n");
                return;
            }

            if(bDisplayEnabled == false)
            {
                /* Submit the filled frame to encoder for display */
                if(DisplayFrame(pDisplayFrame) != SUCCESS)
                {
                    printf("Failed to submit the filled frame to LCD for display \n");
                    return;
                }
            }

            if(NumFilledFrames == 2)
            {
                /* Enable video display after submitting two frames */
                if(EnableDisplay(true) != SUCCESS)
                {
                    printf("Failed to enable video display \n");
                    return;
                }

                bDisplayEnabled = true;
            }
        }

        if(bDisplayEnabled == true)
        {
              uint8_t *pFrame;

              if(GetDisplayedFrame((void **)&pFrame) != SUCCESS)
              {
                  printf("Failed to get the displayed frame \n");
              }

              /* Submit the filled frame to the encoder for display */
              if(DisplayFrame(pDisplayFrame) != SUCCESS)
              {
                  printf("Failed to submit the filled frame to encoder for display \n");
                  return;
              }
          }
       }

   FINBOARD_LED_Drivers_Config(0);
    printf("All done \n");
}
void main(void)
{
    uint32_t nResult= SUCCESS;	
   /* Buffer pointer used to get the  frames with data */
    void *pVideoBuffer=NULL;
    uint32_t *pTemp = (uint32_t *)&buffer[0];
    //MT9M114_VIDEO_BUF *pBufTemp;
    //uint32_t       *pBuf;
    //int32_t        nSize;
   /* Initialize the ADI components such as pin muxing etc */
    adi_initComponents(); /* auto-generated code */
   /* Initialize  DMC */
    adi_DMCamInit();
   /* By default, Graphics is not used to draw the bounding rectangle around the detected dot */
    InitTitle((void*)(*pTemp));


    nBoundingRectFlag = 0;
#if defined(FINBOARD)
	nIllumination = prevIllumination = 1;
#endif
    /* Registering the MDMA callback for Channel-1(Dest) with Interrupt ID 91 (page 219, HRM)
     * to Core-B since it is used to mark the canny output */
    //nSize = sizeof(uint32_t);

    /******************************************************/


    /*mcapi_finalize(&mcapi_status);
    if (MCAPI_SUCCESS != mcapi_status) {
        exit(1);
    }*/
#ifdef DEBUG_INFO
    printf("[CORE A]: BF609_MCAPI_msg: %s\n", retVal == PASS ? "All done" : "Error...");
#endif
     /******************************************************/

    do
    {
			/* Initialize the power services*/
		if (adi_pwr_Init (PROC_CLOCK_IN, PROC_MAX_CORE_CLOCK, PROC_MAX_SYS_CLOCK, PROC_MIN_VCO_CLOCK) != ADI_PWR_SUCCESS)
		{
			printf ("Failed to initialize Power service\n");
			nResult= FAILURE;
			break;
		}
		 /* Set the required core clock and system clock */
		if(adi_pwr_SetFreq(PROC_REQ_CORE_CLOCK, PROC_REQ_SYS_CLOCK)!= ADI_PWR_SUCCESS )
		{
			printf ("Failed to initialize Power service\n");
			nResult= FAILURE;
			break;
		}
		/* Initialize the GPIO for enabling/disabling the PB1 which inturn control the graphics to
		   draw the  rectangle around the detected dots
		 */
		if(Init_GPIO()!= SUCCESS)
		{
			printf("\n GPIO initialization failed \n");
			nResult= FAILURE;
			break;
		}


#if !defined(FINBOARD)
		/* Configure the Software controlled switches on BF609 EZ-Board */
		ConfigSoftSwitches_BF609();
#else // !defined(FINBOARD)
		FINBOARD_CLK_Synth_Restore(); // restore firmware settings
		FINBOARD_LED_Drivers_Init();
		FINBOARD_LED_Drivers_Config( nIllumination );
#endif // defined(FINBOARD)

		/* Configure the sensor */
		if(ConfigureSensor() != SUCCESS)
		{
			printf("Failed to configure Sensor \n");
			nResult= FAILURE;
			break;
		}
		/* Configure the sensor for display */
		if(ConfigureEncoder() != SUCCESS)
		{
			printf("Failed to configure LCD \n");
			nResult= FAILURE;
			break;
		}

#if defined(FINBOARD)
		FINBOARD_ADV7511_16bit_Mode();
#endif

		/* Submit the first frame for filling */
		if(SubmitEmptyVideoFrame() != SUCCESS)
		{
			printf("Failed to submit empty video frame to the sensor \n");
			nResult= FAILURE;
			break;
		}

		/* Submit the second frame for filling */
		if(SubmitEmptyVideoFrame() != SUCCESS)
		{
			printf("Failed to submit empty video frame to the sensor \n");
			nResult= FAILURE;
			break;
		}
		/* Submit first buffer to encoder */
		if(SubmitEncBuf(pEncDispStartBuf) != SUCCESS)
		{
			printf("Failed to submit  video frame to the encoder \n");
			nResult= FAILURE;
			break;
		}
		/* Submit same buffer since we will be waiting for the first frame from the sensor */
		if(SubmitEncBuf(pEncDispStartBuf) != SUCCESS)
		{
			printf("Failed to submit  video frame to the encoder \n");
			nResult= FAILURE;
			break;
		}
		/* Wait till the first frame is captured */
		/* Enable the sensor to capture the frames */
		if(EnableDisplay(true) != SUCCESS)
				{
					printf("Failed to enable video encoder  \n");
					nResult= FAILURE;
					break;
				}
		if(EnableSensor(true) != SUCCESS)
				{
					printf("Failed to enable sensor \n");
					nResult= FAILURE;
					break;
				}
		/* Start the display */
		while( NumFramesCaptured == 0 );

    }while(0);

    printf( "\nVersion: %s-%s\n", __DATE__, __TIME__);

    /* A while loop to timeout the example*/
    while(NumFramesCaptured < EXAMPLE_TIMEOUT && nResult == SUCCESS )
    {
    	           /* Get the video display frame */
           pVideoBuffer = NULL;
           while(pVideoBuffer == NULL)
           {
               GetProcessedSensorBuf (&pVideoBuffer);
           }
           if(pVideoBuffer != NULL )
           {
#if defined(FINBOARD)
               if ( prevIllumination != nIllumination )
               {
            	  prevIllumination = nIllumination;
                  FINBOARD_LED_Drivers_Config( nIllumination );
               }
#endif
           }
           /* Increment the counter */
           NumFilledFrames++;
    }
    /* end of while loop */
    if(nResult == SUCCESS)
    {
         printf("All done \n");
    }
    else
    {
	 printf("Failed to run dot count application.\n");
    }
}