Beispiel #1
0
int main(void){

    //    UART_Setup();

    DDRB |= (1<<LED);
    PORTB |= (1<<LED);

    DDRB |= (1<<MB1) | (1<<MC1);

    PORTE |= (1<<SW1C);

    DDRH |= (1<<MA)| (1<<MD);

    ADC_Setup();

    TIM0_Setup();
    sei();

    while(1){
        PORTB ^= (1<<LED);
        _delay_ms(500);

        vrailing=read_adc(TRRAILLING);
        if(vrailing<5){
            vrailing=5;
        }

        vfiller=read_adc(TRFILLER);
        if(vfiller<5){
            vfiller=5;
        }

    }
}
Beispiel #2
0
int main(void)
{
	// Initialize delay function
	DelayInit();
	
	// Initialize ADC, PWM, and GPIO
	ADC_Setup();
	PWM_Setup();
	GPIO_Setup();
	
	while (1)
	{
		// Read input switch (active low)
		effect = GPIO_ReadInputData(GPIOB);
		// Invert and mask input switch bits
		effect = ~effect & 0x7000;
		
		// If any audio effect is active, then turn on LED 
		if (effect)
		{
			// Turn on LED (active low)
			GPIO_ResetBits(GPIOC, GPIO_Pin_13);
		}
		else
		{
			GPIO_SetBits(GPIOC, GPIO_Pin_13);
		}
		
		DelayMs(50);
	}
}
/*
 * Function Name: main();
 * Description: All the function calls are done in main(). The CPU goes to sleep while in main(); until Interupt is generated.
 */
int main(void)
{

    CHIP_Init();

    CMU_HFRCOBandSet(cmuHFRCOBand_14MHz);
    CMU_ClockSelectSet(cmuClock_HF, cmuSelect_HFRCO);
    CMU_OscillatorEnable(cmuOsc_HFXO, false, false);

    blockSleepMode(EM2); //Prevents the CPU to go below EM3 mode.

#if DEBUG_ON
    BSP_TraceSwoSetup(); //For simplicity studio Energy profiler code correlation.
#endif
    LETIMER_setup(); //Initialize LETIMER.

    ADC_Setup(); //Initialize the ADC

    DMA_Init();	//Initialize DMA.

    DMA_Setup(); //Setup DMA.

    LEUART_Setup(); //Initialize LEUART.

    GPIO_Init(); //Initialize GPOIs.

    LETIMER_IntEnable(LETIMER0, LETIMER_IF_UF); //Enable underflow UF interrupt.

    LEUART_IntEnable(LEUART0, LEUART_IF_SIGF);	// Enable SF RXDATAV

    NVIC_EnableIRQ(LETIMER0_IRQn); //Enable LETIMER0 interrupt vector in NVIC (Nested Vector Interrupt Controller)

    NVIC_EnableIRQ(LEUART0_IRQn); //Enable LETIMER0 interrupt vector in NVIC (Nested Vector Interrupt Controller)

	LEUART0->SIGFRAME = '!';							// Set LEUART signal frame to '!'

	LEUART0->CTRL |= LEUART_CTRL_RXDMAWU;				// Enable DMA wake up for LEUART RX in EM2
    DMA_ActivateBasic(DMA_CHANNEL_RX, true, false, (void *)RX_Buffer, (void *)&(LEUART0->RXDATA), LEUART0_BUFFER-1);

    // Enable Sleep-on-Exit
#if SLEEPONEXIT
    SCB->SCR |= SCB_SCR_SLEEPONEXIT_Msk;	// Setting the corresponding bit for SleepOnExit
#endif

    while(1)
    {
        sleep(); //CPU goes to EM3 Mode to save energy, waits there until Interrupt is generated.
    }

}
/*
 * Function Name: ADC_setup
 * Description: Configures ADC0
 */
void LEUART_Setup(void)
{
	/* Enabling the required clocks */
	CMU_ClockEnable(cmuClock_LFB, true);           //Enable the clock input to LETIMER
	CMU_ClockSelectSet(cmuClock_LFB, cmuSelect_LFXO); //Selecting the ULFRCO as the source clock
	CMU_ClockEnable(cmuClock_LEUART0, true);           //Enable the clock input to LETIMER
	/* Defining the LEUART1 initialization data */
		LEUART_Init_TypeDef leuart0Init =
		{
		  .enable   = leuartEnable,        // Activate data reception on LEUn_TX pin.
		  .refFreq  = 0,                   // Inherit the clock frequency from the LEUART clock source
		  .baudrate = LEUART0_BAUD,    // Baudrate = 9600 bps
		  .databits = LEUART0_Databits,    // Each LEUART frame contains 8 databits
		  .parity   = LEUART0_Parity,      // No parity bits in use
		  .stopbits = LEUART0_Stopbits,    // Setting the number of stop bits in a frame to 2 bitperiods
		};

		LEUART_Init(LEUART0, &leuart0Init);

		// Route LEUART1 TX,RX pin to DMA location 0
		LEUART0->ROUTE = LEUART_ROUTE_TXPEN | LEUART_ROUTE_RXPEN | LEUART_ROUTE_LOCATION_LOC0;

		// Enable GPIO for LEUART1. TX is on D4
		GPIO_PinModeSet(gpioPortD, 4, gpioModePushPull, 0);
		// Enable GPIO for LEUART1. RX is on D5
		GPIO_PinModeSet(gpioPortD, 5, gpioModeInputPull, 0);
		// Pull PD15(CTS pin of BLE module) to GRND
		GPIO_PinModeSet(gpioPortD, 15, gpioModePushPull, 0);

}

/*
 *Function name: LETIMER0_IRQHandler
 *Description : Interrupt Service Routine for LETIMER.
 */
void LETIMER0_IRQHandler(void)
{
    LETIMER_IntClear(LETIMER0, LETIMER_IF_UF); //Clear LETIMER0 underflow (UF) and COMP1 flag.
    DMA_ActivateBasic(DMA_CHANNEL_ADC, true, false, (void *)ADC_Buffer, (void *)&(ADC0->SINGLEDATA), ADC_SAMPLES - 1);
    ADC_Setup();
    // ADC start
    ADC_Start(ADC0, adcStartSingle);
    unblockSleepMode(EM2);
    blockSleepMode(EM1);
    trfComplete=false;
}
Beispiel #5
0
void main(void) 
{

  #if(BOOTLOADER_ENABLE == 1)
    ISR_vtable_reallocation();
  #endif  

  MCU_init(); /* MCU Initialization */   
  
  // Initialize BRTOS
  BRTOS_Init();  
  
  /* Peripheral inicialization */
#if (DEBUG == 1) 

  /* flash clock for reprogramming */ 
  Flash_Clock_Init();     
  
  /* Initialize A/D Converter and bandgap reference */
  ADC_Setup(HighSpeed, ShortSampleTime, 12);
  if(ADC_Bandgap_Set() != BANDGAP_OK){
    while(1){}
  }
 
#endif    
  
  
  #if(DEBUG == 1)    
  #if(NETWORK_ENABLE == 1)     
  
  GPSNET_Init();     
  
  if(InstallTask(&GPSNET_RxApp,"GPSNET RX task",320,APP3_Priority) != OK)
  {
    while(1){};
  }
  /*
  if(InstallTask(&GPSNET_TxApp,"GPSNET TX task",1280,APP2_Priority) != OK)
  {
    while(1){};
  }
  */
  
  if(InstallTask(&GPSNET_SensorApp,"GPSNET Sensor task",1280,APP1_Priority) != OK)
  {
    while(1){};
  }
    

  #endif   
  #endif
  
     
  if(InstallTask(&System_Time,"System Time",320,System_Time_Priority) != OK)
  {
    while(1){};
  };
  
  if(InstallTask(&Comm2PC_Task,"Comm2PC task",448,Comm2PC_Task_Priority) != OK)
  {
    while(1){};
  };    
  
  
  if(InstallTask(&HeartBeat_LED_Task,"HeartBeat LED task",320,HeartBeat_LED_Priority) != OK)
  {
    while(1){};
  };
    

  // Start Task Scheduler
  if(BRTOSStart() != OK)
  {
    while(1){};
  };  



  for(;;) {
    /* __RESET_WATCHDOG(); by default, COP is disabled with device init. When enabling, also reset the watchdog. */
  } /* loop forever */
  /* please make sure that you never leave main */
}
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);
    
    
 
}