Esempio n. 1
0
void llwu_init(void)
{   
#ifdef OPENMOTE_K20
	SIM_SCGC4 |= SIM_SCGC4_LLWU_MASK; //power llwu, in k20 72Mhz is always powered as there isn't a register to power it. in k20 100Mhz needs to be clocked.
#endif	
    enable_irq(LLWU_IRQ_NUM);
    /*0x0200|0x0001 == LLWU_PE3_WUPE9 is radio isr and LLWU_PE1_WUPE0 is UART RX */
    llwu_configure( 0x0200|0x0001, LLWU_PIN_RISING, LLWU_ME_WUME0_MASK);//lptmr is wume0 manual page 76       
}
Esempio n. 2
0
/*!
* @brief initializes LLWU module
*/
void llwu_init(void)
{
    /* Configure the interrupt vector for the interrupt handler */
    INT_SYS_InstallHandler(LLW_IRQn, &llwu_isr);
    
    /* Enable the IRQs */
    INT_SYS_EnableIRQ(LLW_IRQn);
    
    /* Configure the interrupt vector for the interrupt handler */
    INT_SYS_InstallHandler(LPTimer_IRQn, &demo_lptmr_isr);

    /* 
    * TWR_K22F120M and TWR_K64F120M: SW1,PTC6 LLWU_P10
    * FRDM_K64F120M: SW2,PTC6 LLWU_P10
    * FRDM_K22F120M: SW2,PTC1 LLWU_P6
    */
    llwu_configure(LLWU_PIN_NUM, kLlwuExternalPinFallingEdge, kLlwuWakeupModule0);
}
int main (void)
{
    	char ch;
        char low_power_mode = MODE_SELECT;
        
         
        SMC_PMPROT = SMC_PMPROT_ALLS_MASK | SMC_PMPROT_AVLLS_MASK | SMC_PMPROT_AVLP_MASK ;  
        
#ifdef CMSIS  // If we are conforming to CMSIS, we need to call start here
    start();
#endif
        print_llwu_status();
        gpio_init();
               
        rtc_init();  // driven by 32kHz external oscillator //

        vfnLCD_Init();
        vfnLCD_Write_Msg("1234");      
             
        
    
        PORTC_PCR3 = PORT_PCR_MUX(1) | PORT_PCR_PE_MASK | PORT_PCR_PS_MASK;
        enable_irq(INT_LLW-16);
        llwu_configure(0x0080,0x02,LLWU_ME_WUME5_MASK); //M5= RTC Alarm,  M7 RTC seconds
        
        
   //check if it comes from VLLx mode
        if (PMC_REGSC % PMC_REGSC_ACKISO_MASK)
        {
          if (last_gpio_status&0x01) LED1_ON; else LED1_OFF;  //configure GPIO pin with latest state
          PMC_REGSC |= PMC_REGSC_ACKISO_MASK; //write to release hold on I/O
          last_gpio_status ^= 0x01;  //update state for next work
        }

        
  	printf("\n\rRunning the lcd_rtc_lowpower project.\n\r");
        
        // wait 3 seconds before start entering in low power mode
        while  (rtc_seconds_isrv_count<3){};
        

	while(1)
	{
           LED2_TOGGLE;
           
           ch=  (char)RTC_TSR;
	   sprintf(gu8USB_Buffer,"%4i",ch );
           vfnLCD_Write_Msg(gu8USB_Buffer);	
           printf("\n\r llwu_isrv_counter = %i, rtc_isrv_counter=%i ",llwu_isrv_counter, rtc_isrv_counter );
           printf("                       "); //delay 
          
        
           switch (low_power_mode)
           { 
             case MODE_WAIT:
             enter_wait();
             printf("\n\r exit from WAIT"); 
             break;
             
           case MODE_STOP:
           /* 0x00 = STOP - Normal Stop Mode
              0x40 = PSTOP1 - Partial Stop with both system and bus clocks disabled
              0x80 = PSTOP2 - Partial Stop with system clock disabled and bus clock enabled
           */
             enter_stop(0x00);

             printf("\n\r exit from STOP"); 
           break;
             
           case MODE_LLS:  
            MCG_C6 &= ~MCG_C6_CME0_MASK;  //Disable Clock Monitor before entering in low power mode LLS, VLSSx
            enter_lls();
            op_mode = what_mcg_mode();
            if(op_mode==PBE)
            {
              mcg_clk_hz = pbe_pee(CLK0_FREQ_HZ);
              MCG_C6 |= MCG_C6_CME0_MASK;
            }
            printf("\n\r exit from LLS");  
            break;
            
            case MODE_VLLS3:  
            MCG_C6 &= ~MCG_C6_CME0_MASK;
            enter_vlls3();
            //Note:  exit from VLLSx mode is through RESET PMC_REGSC_ACKISO is set
            break;
            
          // VLLS2 mode not supported on KL46       
            
            case MODE_VLLS1:  
            MCG_C6 &= ~MCG_C6_CME0_MASK;
            enter_vlls1();  //In VLLS1 and VLLS0 no SRAM is retained.
            //Note:  exit from VLLSx mode is through RESET PMC_REGSC_ACKISO is set            
            break;            
            
           default:
           }          
	} 
}
int main (void)
{  
	uint32_t execution_cycle;	//actual execution cycle
	char ch;

#ifdef CMSIS  // If we are conforming to CMSIS, we need to call start here
    start();
#endif

	printf("\n\rRunning the LQRUG_bme_ex2 project.\n\r");
	

	if (RCM_SRS0 & RCM_SRS0_WAKEUP_MASK)
	{
	  	printf("Wakeup initialization flow\n\r");
		
		systick_init();
		
		cnt_start_value = SYST_CVR;
			
		Init_BME_GPIO();
		
		ADC_BME_Trigger();
		
		//Set LPTMR to timeout about 1 second
		Lptmr_BME_Init(1000, LPOCLK);	
		
		ADC_BME_Init();
		Calibrate_BME_ADC();
		ADC_BME_Init();
		ADC_Start(ADC0_CHANB);
		
		// Enable the ADC interrupt in NVIC
#ifdef CMSIS
		enable_irq(ADC0_IRQn) ;   // ready for this interrupt.  
		enable_irq(LPTimer_IRQn);
#else
		enable_irq(ADC0_irq_no) ;   // ready for this interrupt.  
		enable_irq(LPTMR0_irq_no);
#endif
	  
		cnt_end_value = SYST_CVR;
		
		execution_cycle = cnt_start_value - cnt_end_value - overhead;
		
		systick_disable();
		
#ifdef DEBUG_PRINT
		printf("Systick start value: 0x%x\n\r", cnt_start_value);
		printf("Systick end value: 0x%x\n\r", cnt_end_value);
		printf("Actual execution cycle for initialization phase in normal C code: 0x%x\n\r", execution_cycle);
#endif	
	}
	else
	{
	  	printf("Normal initialization flow\n\r");	//make sure the two printf has the same characters to output
		
	  	systick_init();
	
		cnt_start_value = SYST_CVR;
			
		Init_GPIO();
		
		ADC_Trigger();
		
		//Set LPTMR to timeout about 1 second
		Lptmr_Init(1000, LPOCLK);	
		
		ADC_Init();
		Calibrate_ADC();
		ADC_Init();
		
		ADC_Start(ADC0_CHANB);
		
		// Enable the ADC interrupt in NVIC
#ifdef CMSIS
		enable_irq(ADC0_IRQn) ;   // ready for this interrupt.  
		enable_irq(LPTimer_IRQn);
#else
		enable_irq(ADC0_irq_no) ;   // ready for this interrupt.  
		enable_irq(LPTMR0_irq_no);
#endif

		cnt_end_value = SYST_CVR;
		
		execution_cycle = cnt_start_value - cnt_end_value - overhead;
		
		systick_disable();
		
#ifdef DEBUG_PRINT
		printf("Systick start value: 0x%x\n\r", cnt_start_value);
		printf("Systick end value: 0x%x\n\r", cnt_end_value);
		printf("Actual execution cycle for initialization phase in normal C code: 0x%x\n\r", execution_cycle);
#endif	
	}
	
	Lptmr_Start();
	
#ifndef FREEDOM
	printf("ADC conversion for potentiometer started, press any key to stop ADC conversion\n\r");
#else
	printf("No potentiometer or LED on FREEDOM board, press any key to stop ADC conversion\n\r");
#endif
	
	while(!char_present()) 
	{
#ifndef FREEDOM
		if (cycle_flags == ADC0A_DONE) 
		{
			printf("\r  R0A=%8d",result0A); 
			cycle_flags &= ~ADC0A_DONE ;
		}	
#endif
	} 
	
	in_char();	//Read out any available characters 
	
	ADC_Stop();
	
	printf("ADC conversion stopped, press 'l' to enter VLLS1 mode\n\r");
	
#ifndef FREEDOM
	printf("Press SW3 or SW4(Reset button) on TWR-KL25Z48M to exit VLLS1 mode\n\r");	
#else
	printf("Press SW1(Reset button) on FREEDOM board to exit VLLS1 mode\n\r");
#endif	
	
	while(1)
	{
	  ch = in_char();
	  //out_char(ch);
	  if(ch != 'l')
	  	printf("Incorrect character input, Press 'l' to enter VLLS1 mode\n\r");	
	  else
		break;
	}
		
	llwu_configure(0x0080/*PTC3*/, LLWU_PIN_FALLING, 0x0);
	
	/* Configure SW3 - init for GPIO PTC3/LLWU_P7/UART1_RX/FTM0_CH2/CLKOUT*/
	PORTC_PCR3 = ( PORT_PCR_MUX(1) |
				   PORT_PCR_PE_MASK |
				   PORT_PCR_PFE_MASK |
				   PORT_PCR_PS_MASK);
	  
	enter_vlls1();		  
	
}
void LLWU_Init(void)
{
    enable_irq(LLWU_irq_no);
//    llwu_configure(0x0080/*PTC3*/, LLWU_PIN_RISING, 0x1);
    llwu_configure(0x0000, LLWU_PIN_RISING, 0x1);
}