Example #1
0
/**
 * @brief	Handle interrupt from SysTick timer
 * @return	Nothing
 */
void SysTick_Handler(void)
{
	static uint32_t count;

	/* Every 1/2 second */
	count++;
	if (count >= (TICKRATE_HZ / 2)) {
		count = 0;

		/* Regardless in BURST or non-BURST mode, once all ADC chamnels have been completed,
		the sequence and associated interrupt will be disabled. Re-enable the sequence is needed. */
		/* Enable ADC overrun and sequence A completion interrupts */
		Chip_ADC_EnableInt(LPC_ADC, (ADC_INTEN_SEQA_ENABLE | ADC_INTEN_OVRRUN_ENABLE));
		if ( state == 0 ) {
			Chip_ADC_SetupSequencer(LPC_ADC, ADC_SEQA_IDX, 0xFFF);
			Chip_ADC_EnableSequencer(LPC_ADC, ADC_SEQA_IDX);
			/* Manual start for ADC conversion sequence A using End of Conversion */
			Chip_ADC_StartSequencer(LPC_ADC, ADC_SEQA_IDX);
			state++;
		}
		else if ( state == 1 ) {
			Chip_ADC_SetupSequencer(LPC_ADC, ADC_SEQA_IDX, 0xFFF|ADC_SEQ_CTRL_BURST);
			Chip_ADC_EnableSequencer(LPC_ADC, ADC_SEQA_IDX);
			/* Manual start for ADC conversion sequence A using End of Conversion with BURST bit set. */
			Chip_ADC_StartBurstSequencer(LPC_ADC, ADC_SEQA_IDX);
			state++;
		}
		else if ( state == 2 ) {
			Chip_ADC_SetupSequencer(LPC_ADC, ADC_SEQA_IDX, 0xFFF|ADC_SEQ_CTRL_MODE_EOS);
			Chip_ADC_EnableSequencer(LPC_ADC, ADC_SEQA_IDX);
			/* Manual start for ADC conversion sequence A using End of Sequence */
			Chip_ADC_StartSequencer(LPC_ADC, ADC_SEQA_IDX);
			state++;
		}
		else if ( state == 3 ) {
			Chip_ADC_SetupSequencer(LPC_ADC, ADC_SEQA_IDX, 0xFFF|ADC_SEQ_CTRL_MODE_EOS|ADC_SEQ_CTRL_BURST);
			Chip_ADC_EnableSequencer(LPC_ADC, ADC_SEQA_IDX);
			/* Manual start for ADC conversion sequence A using End of Sequence with BURST bit set. */
			Chip_ADC_StartBurstSequencer(LPC_ADC, ADC_SEQA_IDX);
			state=0;
		}
	}
}
Example #2
0
/**
 * @brief	Handle interrupt from SysTick timer
 * @return	Nothing
 */
void SysTick_Handler(void)
{
	static uint32_t count;

	/* Every 1/2 second */
	count++;
	if (count >= (TICKRATE_HZ / 2)) {
		count = 0;

		/* Manual start for ADC conversion sequence A */
		Chip_ADC_StartSequencer(LPC_ADC, ADC_SEQA_IDX);
	}
}
Example #3
0
/**
 * @brief	Handle interrupt from ADC sequencer A
 * @return	Nothing
 */
void ADC0A_IRQHandler(void)
{
	uint32_t i, pending;
	uint32_t gdata_value, data_value, seq_ctrl_value, ch_offset;

	/* Get pending interrupts */
	pending = Chip_ADC_GetFlags(LPC_ADC);

	/* Sequence A completion interrupt */
	if (pending & ADC_FLAGS_SEQA_INT_MASK) {
		seq_ctrl_value = Chip_ADC_GetSequencerCtrl(LPC_ADC, ADC_SEQA_IDX);
		if ( seq_ctrl_value & ADC_SEQ_CTRL_MODE_EOS ) {	
			/* End of sequence, get raw sample data for channels 0-11 */
			for (i = 0; i < BOARD_ADC_CH; i++) {
				if ( seq_ctrl_value & (0x1<<i) ) {
					if ( (data_value = Chip_ADC_GetDataReg(LPC_ADC, i)) & ADC_DR_DATAVALID ) {
						ADC_Data_Buffer[i] = ADC_DR_RESULT(data_value);
						channel_completion |= ( 0x1 << i );
					}
				}
			}
		}
		else {
			/* End of conversion, get raw sample data for channels 0-11 */
			gdata_value = Chip_ADC_GetGlobalDataReg(LPC_ADC, ADC_SEQA_IDX);
			if ( gdata_value & ADC_SEQ_GDAT_DATAVALID ) {
				ch_offset = (gdata_value & ADC_SEQ_GDAT_CHAN_MASK) >> ADC_SEQ_GDAT_CHAN_BITPOS;
				ADC_Data_Buffer[ch_offset] = ADC_DR_RESULT(gdata_value);
				channel_completion |= (0x1<<ch_offset);
			}
			if ( channel_completion != (seq_ctrl_value & 0xFFF) ) {
				/* Not all channels are completed. */
				if ( (seq_ctrl_value & ADC_SEQ_CTRL_SINGLESTEP) && !(seq_ctrl_value & ADC_SEQ_CTRL_BURST) ) {
					/* If SINGLE_STEP is set and BURST is not, this sequence needs to be restarted. */
					Chip_ADC_StartSequencer(LPC_ADC, ADC_SEQA_IDX);
				}
			}
		}
Example #4
0
/**
 * @brief Called upon waking from sleep to re-enable clocks, etc.
 */
void wakeup(void) {
	Chip_SYSCTL_DisablePINTWakeup(SW_LEFT_PININT);
	Chip_SYSCTL_DisablePINTWakeup(SW_RIGHT_PININT);
	g_go_to_sleep = 0;

	Plot_Clear(&g_plot_temp);
	Plot_Clear(&g_plot_rh);

	Plot_Clear(&g_plot_mag);
	Plot_Clear(&g_plot_mag);

	SysTick->CTRL  = SysTick_CTRL_CLKSOURCE_Msk |
	    		     SysTick_CTRL_TICKINT_Msk   |
	    		     SysTick_CTRL_ENABLE_Msk;


	g_sw_right_debouncing = 1;
	g_sw_left_debouncing = 1;
	g_sw_right_debounce_counter = 0;
	g_sw_left_debounce_counter = 0;


	NVIC_EnableIRQ(ADC_SEQA_IRQn);

	Chip_ADC_StartSequencer(LPC_ADC, ADC_SEQA_IDX);

	Chip_GPIO_SetPinState(LPC_GPIO_PORT, 0, LCD_BACKLIGHT, 0);

	Chip_GPIO_SetPinState(LPC_GPIO_PORT, 0, RANGE_POWER_PIN, 1);

	Chip_PININT_ClearIntStatus(LPC_PININT, SW_LEFT_PININTCH);
	Chip_PININT_ClearIntStatus(LPC_PININT, SW_RIGHT_PININTCH);

	NVIC_EnableIRQ(SW_LEFT_IRQn);
	NVIC_EnableIRQ(SW_RIGHT_IRQn);
}
Example #5
0
/**
 * @brief Handler for the systick timer; increments counters, etc.
 */
void SysTick_Handler(void) {
	//static uint32_t blink_counter = 0;
	static uint32_t sample_counter_temp = 0;
	static uint32_t sample_counter_rh = 10;

	static uint32_t sample_counter_mag = 20;
	static int_fp mag_x=0, mag_y=0, mag_z=0;

	static uint32_t sample_counter_range = 30;

	static uint32_t left_sw_hold_counter = 0;
	static uint8_t left_sw_engaged = 0;
	static uint32_t right_sw_hold_counter = 0;
	static uint8_t right_sw_engaged = 0;

	g_delayms_counter += MS_PER_TICK;

	sample_counter_temp++;
	if (sample_counter_temp > SAMPLE_PERIOD_TEMP) {
		Plot_AddSample(&g_plot_temp, HTU21D_GetTemp(&g_HTU21D));
		sample_counter_temp = 0;
	}

	sample_counter_rh++;
	if (sample_counter_rh > SAMPLE_PERIOD_RH) {

		Plot_AddSample(&g_plot_rh, HTU21D_GetRH(&g_HTU21D));
		sample_counter_rh = 0;
	}

	sample_counter_mag++;
	if (sample_counter_mag > SAMPLE_PERIOD_MAG) {
		HMC5883L_GetXYZ(&g_HMC5883L, &mag_x, &mag_y, &mag_z);
		Plot_AddSample(&g_plot_mag, mag_z);
		Compass_UpdateXY(&g_compass, mag_x, -mag_y);
		sample_counter_mag = 0;
	}

	sample_counter_range++;
	if (sample_counter_range > SAMPLE_PERIOD_RANGE) {

		if (g_adc_sample_ready) {
			g_adc_sample_ready = 0;
			sample_counter_range = 0;
			g_range_raw = ADC_DR_RESULT(Chip_ADC_GetDataReg(LPC_ADC, MoonLander_IO8_ADC));
			Chip_ADC_StartSequencer(LPC_ADC, ADC_SEQA_IDX);
		}
	}

	if (left_sw_engaged) {
		if (Chip_GPIO_GetPinState(LPC_GPIO_PORT, 0, SW_LEFT)) {
			left_sw_engaged = 0;
			left_sw_hold_counter = 0;
		}
		else {
			left_sw_hold_counter += MS_PER_TICK;
			if (left_sw_hold_counter >= SW_OFF_HOLD_TIME_MS) {
				g_go_to_sleep = 1;
				left_sw_hold_counter = 0;
				left_sw_engaged = 0;
			}
		}
	}

	if (right_sw_engaged) {
		if (Chip_GPIO_GetPinState(LPC_GPIO_PORT, 0, SW_RIGHT)) {
			right_sw_engaged = 0;
			right_sw_hold_counter = 0;
		}
		else {
			right_sw_hold_counter += MS_PER_TICK;
			if (right_sw_hold_counter >= SW_OFF_HOLD_TIME_MS) {
				g_go_to_sleep = 1;
				right_sw_hold_counter = 0;
				right_sw_engaged = 0;
			}
		}
	}

	if (g_sw_left_debouncing) {
		left_sw_engaged = 1;
		g_sw_left_debounce_counter += MS_PER_TICK;
		if (g_sw_left_debounce_counter >= SW_DEBOUNCE_MS) {
			g_sw_left_debouncing = 0;
			g_sw_left_debounce_counter = 0;
		}
	}

	if (g_sw_right_debouncing) {
		right_sw_engaged = 1;
		g_sw_right_debounce_counter += MS_PER_TICK;
		if (g_sw_right_debounce_counter >= SW_DEBOUNCE_MS) {
			g_sw_right_debouncing = 0;
			g_sw_right_debounce_counter = 0;
		}
	}

	g_millis_counter += MS_PER_TICK;
}
Example #6
0
 void SysTick_Handler(void)
 {
     ticks++;
     /* Manual start for ADC conversion sequence A */
     Chip_ADC_StartSequencer(LPC_ADC, ADC_SEQA_IDX);
 }