Пример #1
0
/*************************************************************************
 * Function Name: main
 * Parameters: none
 *
 * Return: none
 *
 * Description: main
 *
 *************************************************************************/
int main(void)
{
typedef Int32U ram_unit;
// int cursor_x = (C_GLCD_H_SIZE - CURSOR_H_SIZE)/2, cursor_y = (C_GLCD_V_SIZE - CURSOR_V_SIZE)/2;
// unsigned long int deltaT;
static float freq_aveg;
int LCD_updatecount;
LCD_updatecount = 0;


//From uip start
unsigned int i;
uip_ipaddr_t ipaddr;
struct timer periodic_timer, arp_timer;
//From uip end
  /*** COMPARE FIX POINT 523235 ***/
  /*** COMPARE FIX POINT 523235 ***/
  GLCD_Ctrl (FALSE);
  // Init GPIO
  GpioInit();
#ifndef SDRAM_DEBUG
  // MAM init
  MAMCR_bit.MODECTRL = 0;
  MAMTIM_bit.CYCLES  = 3;   // FCLK > 40 MHz
  MAMCR_bit.MODECTRL = 2;   // MAM functions fully enabled
  // Init clock
  InitClock();
  // SDRAM Init
  SDRAM_Init();
#endif // SDRAM_DEBUG
  // Init VIC
  VIC_Init();
  // GLCD init
  // GLCD_Init (IarLogoPic.pPicStream, NULL); // Can be removed, remember to remove the h and c file as well
  // GLCD_Init (LogoPic.pPicStream, NULL);  // Can be removed, remember to remove the h and c file as well
  GLCD_Init (what_is_a_blissPic.pPicStream, NULL);
  GLCD_Cursor_Dis(0); //From uip
  // GLCD_Cursor_Dis(0);

  // GLCD_Copy_Cursor ((Int32U *)Cursor, 0, sizeof(Cursor)/sizeof(Int32U));
  /*** COMPARE FIX POINT 534252 ***/
  /*** COMPARE FIX POINT 534252 ***/
  GLCD_Cursor_Cfg(CRSR_FRAME_SYNC | CRSR_PIX_32); //From uip
  // GLCD_Cursor_Cfg(CRSR_FRAME_SYNC | CRSR_PIX_64);
  // GLCD_Move_Cursor(cursor_x, cursor_y);
  // GLCD_Cursor_En(0);

  //From uip start
  // Sys timer init 1/100 sec tick
  clock_init(2);

  timer_set(&periodic_timer, CLOCK_SECOND / 2);
  timer_set(&arp_timer, CLOCK_SECOND * 10);
  //From uip end


  // Init USB Link  LED
  USB_D_LINK_LED_SEL = 0; // GPIO
  USB_D_LINK_LED_FSET = USB_D_LINK_LED_MASK;
  USB_D_LINK_LED_FDIR |= USB_D_LINK_LED_MASK;
  
  USB_H_LINK_LED_SEL = 0; // GPIO
  USB_H_LINK_LED_FSET = USB_H_LINK_LED_MASK;
  USB_H_LINK_LED_FDIR |= USB_H_LINK_LED_MASK;

  
  /*-----------------------------------------------------------------*/
  
  // Init AD0[3] for current meassurement
  PINSEL1_bit.P0_26 = 1; // Assign P26 to AD0[3], page 180
  PINMODE1_bit.P0_26 = 2; // //Neither pull-up or pull-down
  // PCONP_bit.PCAD = 1;     // Note: Clear the PDN bit in the AD0CR before clearing this bit and set this before PDN
  // Other initial parameters are already set
  // AD0CR_bit.SEL  = 8;     // select Ch3 [1111]
  current_amp = 0;
  
  
  /*-----------------------------------------------------------------*/
  // Init the DAC converter
  //Clock: In the PCLK_SEL0 register (Table 4�), select PCLK_DAC
    //PCLKSEL0_bit.PCLK_DAC = 3UL;// **HAS Desided for values yet!** // '11' at bit 23 and 22  (which is CCLK/8)  //or use 0x3 for 3UL instead  
  //Pins: Select the DAC pin and pin mode in registers PINSEL1 and PINMODE1 (see Section 9�.
  //PINSEL1 |= (2UL<<20); //  PINSEL1_bit.P0_26 = 1; //??        
    //PINSEL1_bit.P0_26 = 2UL; 
  //"PINMODE registers control the on-chip pull-up/pull-down resistor feature for all GPIO ports." - page 178
  //PINMODE1 |= ________; // See table 128 for values. Write to bit 21:20
    //PINMODE1_bit.P0_26 = 2UL;  //P0.26MODE = 2UL; //Neither pull-up or pull-down


 /* ------------------------------------------------------------------*/
  // Init ADC converter
  // Power the ADC converter
  PINSEL1_bit.P0_25 = 1; // Assign Pin 25 to ADO[2]
  PINMODE1_bit.P0_25 = 1; // Neither pull-up or pull-dow
  PCONP_bit.PCAD = 1;     // Note: Clear the PDN bit in the AD0CR before clearing this bit and set this before PDN
  AD0CR_bit.PDN = 1;      // A/D converter is operational
  AD0CR_bit.START = 0;    // Conversion not started
  AD0CR_bit.BURST  = 0;   // disable burst
  // AD0CR_bit.SEL  = 4;     // select Ch2 [11]
  
  // Select number of clocks for each conversion
  AD0CR_bit.CLKS = 0; // [000] 11 clocks / 10 bits
  AD0CR_bit.CLKDIV = SYS_GetFpclk(ADC_PCLK_OFFSET)/ 10000; // 4500000;  // Should be equal to 10K samplingrate
  ADINTEN_bit.ADGINTEN = 1; // Global A/D channels enabled by ADINTEN 7:0
  // Since only on channel is used at the moment the global flag is enabled
  
  VIC_SetVectoredIRQ(AD0IntrHandler,1,VIC_AD0); // Set the interrupt call
  VICINTENABLE |= 1UL << VIC_AD0;
  


  // Setting parameters for the low-pass filter
  DACR_previous = 0; // Initialize DACR_temp which is y(i-1)
  deltaT = 1.0/TIMER0_TICK_PER_SEC; // Set the sample rate
  // Calculate the R*C for cut-off frequency of the low pass filter
  alpha = deltaT/(1./(2.*3.1416*100.) + deltaT); // Cut-off = 100 Hz
  done = 0; // Channel stage
/* ------------------------------------------------------------------*/
  
  // Setting the port to P0[11] and P0[19]
  PINSEL1_bit.P0_19 = 0; // GPIO to P0[19]
  PINSEL0_bit.P0_11 = 0; // GPIO to P0[11]
  PINMODE1_bit.P0_19 = 2; // Pin has neither pull up or down
  PINMODE0_bit.P0_11 = 2; // Pin has neither pull up or down
  FIO0DIR_bit.P0_19  = 1; 
  FIO0CLR  = (1UL<<19);
  FIO0DIR_bit.P0_11 = 1;
  FIO0CLR  = (1UL<<11);
  
  FIO0PIN_bit.P0_19 = 1;
  FIO0PIN_bit.P0_11 = 1;
/* ------------------------------------------------------------------*/  
  // Enable TIM0 clocks
  PCONP_bit.PCTIM0 = 1; // enable clock

  // Init Time0
  T0TCR_bit.CE = 0;     // counting  disable
  T0TCR_bit.CR = 1;     // set reset
  T0TCR_bit.CR = 0;     // release reset
  T0CTCR_bit.CTM = 0;   // Timer Mode: every rising PCLK edge
  T0MCR_bit.MR0I = 1;   // Enable Interrupt on MR0
  T0MCR_bit.MR0R = 1;   // Enable reset on MR0
  T0MCR_bit.MR0S = 0;   // Disable stop on MR0
  // set timer 0 period
  T0PR = 0;
  T0MR0 = SYS_GetFpclk(TIMER0_PCLK_OFFSET)/(TIMER0_TICK_PER_SEC);
  // init timer 0 interrupt
  T0IR_bit.MR0INT = 1;  // clear pending interrupt
  VIC_SetVectoredIRQ(Timer0IntrHandler,0,VIC_TIMER0);
  VICINTENABLE |= 1UL << VIC_TIMER0;
  T0TCR_bit.CE = 1;     // counting Enable
  __enable_interrupt();
  GLCD_Ctrl (TRUE);

#if 0
  SDRAM_Test();
#endif

  /*
  //
  SMB380_Init();

  SMB380_GetID(&Smb380Id, &Smb380Ver);

  SMB380_Data_t XYZT;
  */

  /*** COMPARE FIX POINT 856364 ***/
  /*** COMPARE FIX POINT 856364 ***/
  /*** COMPARE FIX POINT 856364 ***/
  /*** COMPARE FIX POINT 856364 ***/

  //From uip start
  GLCD_SetFont(&Terminal_18_24_12,0x000000,0x000cd4ff);
  GLCD_SetWindow(85,10,255,33);
  GLCD_TextSetPos(0,0);
  GLCD_print("\f Room Station");
  
  
  //From uip start

  /*** COMPARE FIX POINT 458923 ***/
  /*** COMPARE FIX POINT 458923 ***/

  // GLCD_SetWindow(5,200,319,239);
  // GLCD_SetFont(&Terminal_6_8_6,0x0000FF,0x000cd4ff);

  // Initialize the ethernet device driver
  do
  {
    GLCD_TextSetPos(0,0);
  }
  while(!tapdev_init());
  GLCD_TextSetPos(0,0);

  // uIP web server
  // Initialize the uIP TCP/IP stack.
  uip_init();

  uip_ipaddr(ipaddr, 192,168,0,100);
  uip_sethostaddr(ipaddr);
  uip_ipaddr(ipaddr, 192,168,0,1);
  uip_setdraddr(ipaddr);
  uip_ipaddr(ipaddr, 255,255,255,0);
  uip_setnetmask(ipaddr);

  // Initialize the HTTP server.
  httpd_init();

  /*** COMPARE FIX POINT 4572742 ***/
  /*** COMPARE FIX POINT 4572742 ***/
  /*** COMPARE FIX POINT 4572742 ***/
  /*** COMPARE FIX POINT 4572742 ***/


/*** WHILE LOOP START ***/
  while(1)
  {

  /*** COMPARE FIX POINT 938194 ***/
  /*** COMPARE FIX POINT 938194 ***/
  /*** COMPARE FIX POINT 938194 ***/
  /*** COMPARE FIX POINT 938194 ***/
  /*** COMPARE FIX POINT 938194 ***/

    uip_len = tapdev_read(uip_buf);
    if(uip_len > 0)
    {
      if(BUF->type == htons(UIP_ETHTYPE_IP))
      {
	      uip_arp_ipin();
	      uip_input();
	      /* If the above function invocation resulted in data that
	         should be sent out on the network, the global variable
	         uip_len is set to a value > 0. */
	      if(uip_len > 0)
        {
	        uip_arp_out();
	        tapdev_send(uip_buf,uip_len);
	      }
      }
      else if(BUF->type == htons(UIP_ETHTYPE_ARP))
      {
        uip_arp_arpin();
	      /* If the above function invocation resulted in data that
	         should be sent out on the network, the global variable
	         uip_len is set to a value > 0. */
	      if(uip_len > 0)
        {
	        tapdev_send(uip_buf,uip_len);
	      }
      }
    }
    else if(timer_expired(&periodic_timer))
    {
      timer_reset(&periodic_timer);
      for(i = 0; i < UIP_CONNS; i++)
      {
      	uip_periodic(i);
        /* If the above function invocation resulted in data that
           should be sent out on the network, the global variable
           uip_len is set to a value > 0. */
        if(uip_len > 0)
        {
          uip_arp_out();
          tapdev_send(uip_buf,uip_len);
        }
      }
#if UIP_UDP
      for(i = 0; i < UIP_UDP_CONNS; i++) {
        uip_udp_periodic(i);
        /* If the above function invocation resulted in data that
           should be sent out on the network, the global variable
           uip_len is set to a value > 0. */
        if(uip_len > 0) {
          uip_arp_out();
          tapdev_send();
        }
      }
#endif /* UIP_UDP */
      /* Call the ARP timer function every 10 seconds. */
      if(timer_expired(&arp_timer))
      {
        timer_reset(&arp_timer);
        uip_arp_timer();
      }
    }

    #define AVERAGECOUNT 100000
    if(LCD_updatecount <= AVERAGECOUNT) {
      ++LCD_updatecount;
      freq_aveg += freq;
    }
    else { 
      freq_aveg = freq_aveg/AVERAGECOUNT;

      updateFreqHistory(freq_aveg); //Must be kept together with freq calculation!

      GLCD_SetWindow(20,55,150,80);
      GLCD_SetFont(&Terminal_18_24_12,0x000000,0x009fee00);
      GLCD_TextSetPos(0,5);
      GLCD_print("\f Hz %3.3f", freq_aveg);
      freq_aveg = 0;
      
      GLCD_SetWindow(20,90,150,115);
      GLCD_SetFont(&Terminal_18_24_12,0x000000,0x009fee00);
      GLCD_TextSetPos(0,5);
      GLCD_print("\f  V  %3.3f", sqrtf(vol_rms_result));

      updateVoltageHistory(sqrtf(vol_rms_result));
      
      GLCD_SetWindow(20,125,150,150);
      GLCD_SetFont(&Terminal_18_24_12,0x000000,0x009fee00);
      GLCD_TextSetPos(0,5);
      GLCD_print("\f uA  %3.3f", sqrtf(current_amp));
      
      GLCD_SetWindow(20,160,150,185);
      GLCD_SetFont(&Terminal_18_24_12,0x000000,0x009fee00);
      GLCD_TextSetPos(0,5);
      GLCD_print("\f uP  %3.3f", sqrtf(vol_rms_result)*sqrtf(current_amp));
      LCD_updatecount = 0;
    }
    
    
  }//while(1) loop

}//main function
Пример #2
0
__interrupt void PORT2_ISR(void)
#endif
{
	u8 int_flag, int_enable;
	u8 buzzer = 0;
	u8 simpliciti_button_event = 0;
	static u8 simpliciti_button_repeat = 0;

	// Clear button flags
	button.all_flags = 0;

	// Remember interrupt enable bits
	int_enable = BUTTONS_IE;

	// Store valid button interrupt flag
	int_flag = BUTTONS_IFG & int_enable;

	// ---------------------------------------------------
	// While SimpliciTI stack is active, buttons behave differently:
	//  - Store button events in SimpliciTI packet data
	//  - Exit SimpliciTI when button DOWN was pressed 
  	if (is_rf())
  	{
  		// Erase previous button press after a number of resends (increase number if link quality is low)
  		// This will create a series of packets containing the same button press
  		// Necessary because we have no acknowledge
  		// Filtering (edge detection) will be done by receiver software
  		if (simpliciti_button_repeat++ > 6) 
  		{
  			simpliciti_data[0] &= ~0xF0;
  			simpliciti_button_repeat = 0;
  		}
  		
  		if ((int_flag & BUTTON_STAR_PIN) == BUTTON_STAR_PIN)			
  		{
  			simpliciti_data[0] |= SIMPLICITI_BUTTON_STAR;
  			simpliciti_button_event = 1;
  		}
  		else if ((int_flag & BUTTON_NUM_PIN) == BUTTON_NUM_PIN)	
  		{
  			simpliciti_data[0] |= SIMPLICITI_BUTTON_NUM;
  			simpliciti_button_event = 1;
  		}
		else if ((int_flag & BUTTON_UP_PIN) == BUTTON_UP_PIN)	
		{
			simpliciti_data[0] |= SIMPLICITI_BUTTON_UP;
			simpliciti_button_event = 1;
		}
		else if ((int_flag & BUTTON_DOWN_PIN) == BUTTON_DOWN_PIN)	
		{
			simpliciti_flag |= SIMPLICITI_TRIGGER_STOP;
		}
		
		// Trigger packet sending inside SimpliciTI stack
		if (simpliciti_button_event) simpliciti_flag |= SIMPLICITI_TRIGGER_SEND_DATA;
  	}
  	else // Normal operation
  	{
		// Debounce buttons
		if ((int_flag & ALL_BUTTONS) != 0)
		{ 
			// Disable PORT2 IRQ
			__disable_interrupt();
			BUTTONS_IE = 0x00; 
			__enable_interrupt();
	
			// Debounce delay 1
			Timer0_A4_Delay(CONV_MS_TO_TICKS(BUTTONS_DEBOUNCE_TIME_IN));
	
			// Reset inactivity detection
			sTime.last_activity = sTime.system_time;
		}

		// ---------------------------------------------------
		// STAR button IRQ
		if (IRQ_TRIGGERED(int_flag, BUTTON_STAR_PIN))
		{
			// Filter bouncing noise 
			if (BUTTON_STAR_IS_PRESSED)
			{
				button.flag.star = 1;
				
				// Generate button click
				buzzer = 1;
			}
		}
		// ---------------------------------------------------
		// NUM button IRQ
		else if (IRQ_TRIGGERED(int_flag, BUTTON_NUM_PIN))
		{
			// Filter bouncing noise 
			if (BUTTON_NUM_IS_PRESSED)
			{
				button.flag.num = 1;
	
				// Generate button click
				buzzer = 1;
				
				if( !sys.flag.lock_buttons)
				{
					#ifdef CONFIG_STOP_WATCH
					// Faster reaction for stopwatch split button press
					if (is_stopwatch_run())
					{
						split_stopwatch();
						button.flag.num = 0;
						
					}
					#endif
				}
			}
		}
		// ---------------------------------------------------
		// UP button IRQ
		else if (IRQ_TRIGGERED(int_flag, BUTTON_UP_PIN))
		{
			// Filter bouncing noise 
			if (BUTTON_UP_IS_PRESSED)
			{
				button.flag.up = 1;
		
				// Generate button click
				buzzer = 1;
			}
		}
		// ---------------------------------------------------
		// DOWN button IRQ
		else if (IRQ_TRIGGERED(int_flag, BUTTON_DOWN_PIN))
		{
			// Filter bouncing noise 
			if (BUTTON_DOWN_IS_PRESSED)
			{
				button.flag.down = 1;
	
				// Generate button click
				buzzer = 1;
				
				if( !sys.flag.lock_buttons)
				{
					#ifdef CONFIG_STOP_WATCH
					// Faster reaction for stopwatch stop button press
					if (is_stopwatch_run())
					{
						stop_stopwatch();
						button.flag.down = 0;
					}
					// Faster reaction for stopwatch start button press
					else if (is_stopwatch_stop())
					{
						start_stopwatch();
						button.flag.down = 0;
					}
					#endif
				}
			}
		}
		// ---------------------------------------------------
		// B/L button IRQ
		else if (IRQ_TRIGGERED(int_flag, BUTTON_BACKLIGHT_PIN))
		{
			// Filter bouncing noise 
			if (BUTTON_BACKLIGHT_IS_PRESSED)
			{
				sButton.backlight_status = 1;
				sButton.backlight_timeout = 0;
				P2OUT |= BUTTON_BACKLIGHT_PIN;
				P2DIR |= BUTTON_BACKLIGHT_PIN;
				button.flag.backlight = 1;
			}
		}	
	}
	
	// Trying to lock/unlock buttons?
	if ((button.flag.num && button.flag.down) || (button.flag.star && button.flag.up))
	{
		// No buzzer output
		buzzer = 0;
		button.all_flags = 0;
	}

	// Generate button click when button was activated
	if (buzzer)
	{
		// Any button event stops active alarm
		#ifdef CONFIG_ALARM
		if (sAlarm.state == ALARM_ON) 
		{
			stop_alarm();
			button.all_flags = 0;
		}
		else 
		#endif
		
		#ifdef CONFIG_EGGTIMER
		if (sEggtimer.state == EGGTIMER_ALARM) {
			stop_eggtimer_alarm();
			button.all_flags = 0;
		}
		else
		#endif
		
		if (!sys.flag.up_down_repeat_enabled && !sys.flag.no_beep)
		{
			start_buzzer(1, CONV_MS_TO_TICKS(20), CONV_MS_TO_TICKS(150));
		}
		
		// Debounce delay 2
		Timer0_A4_Delay(CONV_MS_TO_TICKS(BUTTONS_DEBOUNCE_TIME_OUT));
	}
	
	#ifdef FEATURE_PROVIDE_ACCEL
	// ---------------------------------------------------
	// Acceleration sensor IRQ
	if (IRQ_TRIGGERED(int_flag, AS_INT_PIN))
	{
		// Get data from sensor
		request.flag.acceleration_measurement = 1;
  	}
	#endif
	
  	// ---------------------------------------------------
	// Pressure sensor IRQ
	if (IRQ_TRIGGERED(int_flag, PS_INT_PIN)) 
	{
		// Get data from sensor
		request.flag.altitude_measurement = 1;
  	}
  	
  	// ---------------------------------------------------
  	// Safe long button event detection
  	if(button.flag.star || button.flag.num) 
	{
		// Additional debounce delay to enable safe high detection
		Timer0_A4_Delay(CONV_MS_TO_TICKS(BUTTONS_DEBOUNCE_TIME_LEFT));
	
		// Check if this button event is short enough
		if (BUTTON_STAR_IS_PRESSED) button.flag.star = 0;
		if (BUTTON_NUM_IS_PRESSED) button.flag.num = 0;	
	}
	
	// Reenable PORT2 IRQ
	__disable_interrupt();
	BUTTONS_IFG = 0x00; 	
	BUTTONS_IE  = int_enable; 	
	__enable_interrupt();

	// Exit from LPM3/LPM4 on RETI
	__bic_SR_register_on_exit(LPM4_bits); 
}
Пример #3
0
void main(void)
{
  unsigned int uartUpdateTimer = UART_UPDATE_INTERVAL;
  unsigned char i;

  WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT

  InitializeClocks();
  InitializeButton();
  InitializeLeds();
  PreApplicationMode();                     // Blinks LEDs, waits for button press
  
  /* Application Mode begins */
  applicationMode = APP_APPLICATION_MODE;
  ConfigureAdcTempSensor();
  ConfigureTimerPwm();
    
  __enable_interrupt();                     // Enable interrupts.
  
  /* Main Application Loop */
  while(1)
  {    
    ADC10CTL0 |= ENC + ADC10SC;             // Sampling and conversion start
    __bis_SR_register(CPUOFF + GIE);        // LPM0 with interrupts enabled
    
    
    /* Moving average filter out of 8 values to somewhat stabilize sampled ADC */
    tempMeasured[tempMeasuredPosition++] = ADC10MEM;
    if (tempMeasuredPosition == 8)
      tempMeasuredPosition = 0;
    tempAverage = 0;
    for (i = 0; i < 8; i++)
      tempAverage += tempMeasured[i];
    tempAverage >>= 3;                      // Divide by 8 to get average
    
    if ((--uartUpdateTimer == 0) || calibrateUpdate )
    {
      ConfigureTimerUart();
      if (calibrateUpdate)
      { 
        TXByte = 248;                       // A character with high value, outside of temp range 
        Transmit();
        calibrateUpdate = 0;
      }   
      TXByte = (unsigned char)( ((tempAverage - 630) * 761) / 1024 );   
         
      Transmit(); 
      
      uartUpdateTimer = UART_UPDATE_INTERVAL;
      ConfigureTimerPwm();      
    }
    
    tempDifference = tempAverage - tempCalibrated;
    if (tempDifference < -TEMP_THRESHOLD)
    {
      tempDifference = -tempDifference;
      tempPolarity = TEMP_COLD;
      LED_OUT &= ~ LED1;
    }
    else
    if (tempDifference > TEMP_THRESHOLD)
    {
      tempPolarity = TEMP_HOT;
      LED_OUT &= ~ LED2;
    }
    else
    {
      tempPolarity = TEMP_SAME;
      TACCTL0 &= ~CCIE;
      TACCTL1 &= ~CCIE;
      LED_OUT &= ~(LED1 + LED2);        
    } 
    
    if (tempPolarity != TEMP_SAME)    
    {      
      tempDifference <<= 3;
      tempDifference += TIMER_PWM_OFFSET;      
      TACCR1 = ( (tempDifference) < (TIMER_PWM_PERIOD-1) ? (tempDifference) : (TIMER_PWM_PERIOD-1) );
      TACCTL0 |= CCIE;
      TACCTL1 |= CCIE;      
    }   
  }  
}
Пример #4
0
Void Timer_masterEnable(Void)
{
    __enable_interrupt();
}
Пример #5
0
interrupt(WDT_VECTOR) isr_wdt(void)
{
	__disable_interrupt();
	(*isr_table[ISR_WDT])();
	__enable_interrupt();
}
Пример #6
0
interrupt(TIMERA1_VECTOR) isr_timer_a1(void)
{
	__disable_interrupt();
	(*isr_table[ISR_TIMERA1])();
	__enable_interrupt();
}
Пример #7
0
interrupt(ADC10_VECTOR) isr_adc(void)
{
	__disable_interrupt();
	(*isr_table[ISR_ADC])();
	__enable_interrupt();
}
Пример #8
0
void EnableInterrupts() {
    __enable_interrupt();
}
Пример #9
0
	__weak void vPortSuppressTicksAndSleep( portTickType xExpectedIdleTime )
	{
	unsigned long ulReloadValue, ulCompleteTickPeriods, ulCompletedSysTickIncrements;
	portTickType xModifiableIdleTime;

		/* Make sure the SysTick reload value does not overflow the counter. */
		if( xExpectedIdleTime > xMaximumPossibleSuppressedTicks )
		{
			xExpectedIdleTime = xMaximumPossibleSuppressedTicks;
		}

		/* Calculate the reload value required to wait xExpectedIdleTime
		tick periods.  -1 is used because this code will execute part way
		through one of the tick periods, and the fraction of a tick period is
		accounted for later. */
		ulReloadValue = ( ulTimerReloadValueForOneTick * ( xExpectedIdleTime - 1UL ) );
		if( ulReloadValue > ulStoppedTimerCompensation )
		{
			ulReloadValue -= ulStoppedTimerCompensation;
		}

		/* Stop the SysTick momentarily.  The time the SysTick is stopped for
		is accounted for as best it can be, but using the tickless mode will
		inevitably result in some tiny drift of the time maintained by the
		kernel with respect to calendar time. */
		portNVIC_SYSTICK_CTRL_REG = portNVIC_SYSTICK_CLK_BIT | portNVIC_SYSTICK_INT_BIT;

		/* Adjust the reload value to take into account that the current
		time slice is already partially complete. */
		ulReloadValue += ( portNVIC_SYSTICK_LOAD_REG - ( portNVIC_SYSTICK_LOAD_REG - portNVIC_SYSTICK_CURRENT_VALUE_REG ) );

		/* Enter a critical section but don't use the taskENTER_CRITICAL()
		method as that will mask interrupts that should exit sleep mode. */
		__disable_interrupt();

		/* If a context switch is pending or a task is waiting for the scheduler
		to be unsuspended then abandon the low power entry. */
		if( eTaskConfirmSleepModeStatus() == eAbortSleep )
		{
			/* Restart SysTick. */
			portNVIC_SYSTICK_CTRL_REG = portNVIC_SYSTICK_CLK_BIT | portNVIC_SYSTICK_INT_BIT | portNVIC_SYSTICK_ENABLE_BIT;

			/* Re-enable interrupts - see comments above __disable_interrupt()
			call above. */
			__enable_interrupt();
		}
		else
		{
			/* Set the new reload value. */
			portNVIC_SYSTICK_LOAD_REG = ulReloadValue;

			/* Clear the SysTick count flag and set the count value back to
			zero. */
			portNVIC_SYSTICK_CURRENT_VALUE_REG = 0UL;

			/* Restart SysTick. */
			portNVIC_SYSTICK_CTRL_REG = portNVIC_SYSTICK_CLK_BIT | portNVIC_SYSTICK_INT_BIT | portNVIC_SYSTICK_ENABLE_BIT;

			/* Sleep until something happens.  configPRE_SLEEP_PROCESSING() can
			set its parameter to 0 to indicate that its implementation contains
			its own wait for interrupt or wait for event instruction, and so wfi
			should not be executed again.  However, the original expected idle
			time variable must remain unmodified, so a copy is taken. */
			xModifiableIdleTime = xExpectedIdleTime;
			configPRE_SLEEP_PROCESSING( xModifiableIdleTime );
			if( xModifiableIdleTime > 0 )
			{
				__WFI();
			}
			configPOST_SLEEP_PROCESSING( xExpectedIdleTime );

			/* Stop SysTick.  Again, the time the SysTick is stopped for is
			accounted for as best it can be, but using the tickless mode will
			inevitably result in some tiny drift of the time maintained by the
			kernel with respect to calendar time. */
			portNVIC_SYSTICK_CTRL_REG = portNVIC_SYSTICK_CLK_BIT | portNVIC_SYSTICK_INT_BIT;

			/* Re-enable interrupts - see comments above __disable_interrupt()
			call above. */
			__enable_interrupt();

			if( ( portNVIC_SYSTICK_CTRL_REG & portNVIC_SYSTICK_COUNT_FLAG_BIT ) != 0 )
			{
				/* The tick interrupt has already executed, and the SysTick
				count reloaded with the portNVIC_SYSTICK_LOAD_REG value.
				Reset the portNVIC_SYSTICK_LOAD_REG with whatever remains of
				this tick period. */
				portNVIC_SYSTICK_LOAD_REG = ulTimerReloadValueForOneTick - ( ulReloadValue - portNVIC_SYSTICK_CURRENT_VALUE_REG );

				/* The tick interrupt handler will already have pended the tick
				processing in the kernel.  As the pending tick will be
				processed as soon as this function exits, the tick value
				maintained by the tick is stepped forward by one less than the
				time spent waiting. */
				ulCompleteTickPeriods = xExpectedIdleTime - 1UL;
			}
			else
			{
				/* Something other than the tick interrupt ended the sleep.
				Work out how long the sleep lasted. */
				ulCompletedSysTickIncrements = ( xExpectedIdleTime * ulTimerReloadValueForOneTick ) - portNVIC_SYSTICK_CURRENT_VALUE_REG;

				/* How many complete tick periods passed while the processor
				was waiting? */
				ulCompleteTickPeriods = ulCompletedSysTickIncrements / ulTimerReloadValueForOneTick;

				/* The reload value is set to whatever fraction of a single tick
				period remains. */
				portNVIC_SYSTICK_LOAD_REG = ( ( ulCompleteTickPeriods + 1 ) * ulTimerReloadValueForOneTick ) - ulCompletedSysTickIncrements;
			}

			/* Restart SysTick so it runs from portNVIC_SYSTICK_LOAD_REG
			again, then set portNVIC_SYSTICK_LOAD_REG back to its standard
			value. */
			portNVIC_SYSTICK_CURRENT_VALUE_REG = 0UL;
			portNVIC_SYSTICK_CTRL_REG = portNVIC_SYSTICK_CLK_BIT | portNVIC_SYSTICK_INT_BIT | portNVIC_SYSTICK_ENABLE_BIT;

			vTaskStepTick( ulCompleteTickPeriods );
		}
	}