Пример #1
0
int main(void) {
	uint32_t sysTickRate;

	Board_Init();

#ifdef DEBUG
	// Set up UART for debug
	init_uart(115200);
	putLineUART("\n");
#endif

	// Enable EEPROM clock and reset EEPROM controller
	Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_EEPROM);
	Chip_SYSCTL_PeriphReset(RESET_EEPROM);

	// Set up clocking for SD lib
	SystemCoreClockUpdate();
	DWT_Init();

	// Set up the FatFS Object
	f_mount(fatfs,"",0);

	// Initialize SD card
	Board_LED_Color(LED_CYAN);
	if(sd_reset(&cardinfo) != SD_OK) {
		error(ERROR_SD_INIT);
	}
	sd_state = SD_READY;

	// Setup config
	Board_LED_Color(LED_CYAN);
	configStart();
	Board_LED_Color(LED_GREEN);

	// Allow MSC mode on startup
	msc_state = MSC_ENABLED;

	// Log startup
	log_string("Startup");

	// Set up ADC for reading battery voltage
	read_vBat_setup();

	// Initialize ring buffer used to buffer raw data samples
	rawBuff = RingBuffer_initWithBuffer(RAW_BUFF_SIZE, RAM1_BASE);

	// Set up MRT used by pb and daq
	Chip_MRT_Init();
	NVIC_ClearPendingIRQ(MRT_IRQn);
	NVIC_EnableIRQ(MRT_IRQn);
	NVIC_SetPriority(MRT_IRQn, 0x02); // Set higher than systick, but lower than sampling

	// Initialize push button
	pb_init();

	// Enable and setup SysTick Timer at a periodic rate
	Chip_Clock_SetSysTickClockDiv(1);
	sysTickRate = Chip_Clock_GetSysTickClockRate();
	SysTick_Config(sysTickRate / TICKRATE_HZ1);

	// Idle and run systick loop until triggered or plugged in as a USB device
	system_state = STATE_IDLE;
	enterIdleTime = Chip_RTC_GetCount(LPC_RTC);

    // Wait for interrupts
    while (1) {
    	__WFI();
    }

    return 0 ;
}
Пример #2
0
/**
 * @brief	main routine for ADC example
 * @return	Function should not exit
 */
int main(void)
{
	SystemCoreClockUpdate();
	Board_Init();
	DEBUGSTR("ADC ROM sequencer demo\r\n");

	/* Power up, enable clock and reset ADC0 */
	Chip_SYSCTL_PowerUp(SYSCTL_POWERDOWN_ADC0_PD);
	Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_ADC0);
	Chip_SYSCTL_PeriphReset(RESET_ADC0);
	/* Power up, enable clock and reset ADC1 */
	Chip_SYSCTL_PowerUp(SYSCTL_POWERDOWN_ADC1_PD);
	Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_ADC1);
	Chip_SYSCTL_PeriphReset(RESET_ADC1);
	/* Power up the internal temperature sensor */
	Chip_SYSCTL_PowerUp(SYSCTL_POWERDOWN_TS_PD);

#if defined(BOARD_NXP_LPCXPRESSO_1549)
	/* Disables pullups/pulldowns and disable digital mode */
	Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 9, (IOCON_MODE_INACT | IOCON_ADMODE_EN));

	/* Assign ADC1_1 to PIO0_9 via SWM (fixed pin) */
	Chip_SWM_EnableFixedPin(SWM_FIXED_ADC1_1);

#else
#warning "No ADC setup for this example"
#endif
	/* Initialize ROM API base address for ADC */
	pAdcApi = LPC_ADCD_API;
	size_in_bytes = pAdcApi->adc_get_mem_size();
	if (size_in_bytes / 4 > RAMBLOCK_H) {
		/* Adjust RAMBLOCK size in this case */
		return 1;
	}
	/* ADC Handle Setup*/
	adc_handle[0] = pAdcApi->adc_setup(LPC_ADC0_BASE, (uint8_t *) start_of_ram_block[0]);
	adc_handle[1] = pAdcApi->adc_setup(LPC_ADC1_BASE, (uint8_t *) start_of_ram_block[1]);
	/* ADC0 Config */
	adc_cfg[0].system_clock = SystemCoreClock;	/* System clock */
	adc_cfg[0].adc_clock = 500000;	/* ADC clock set to 500KHz for calibration*/
	/* ADC1 Config */
	adc_cfg[1].system_clock = SystemCoreClock;	/* System clock */
	adc_cfg[1].adc_clock = 500000;	/* ADC clock set to 500KHz for calibration*/
	pAdcApi->adc_calibration(adc_handle[0], &adc_cfg[0]);
	pAdcApi->adc_calibration(adc_handle[1], &adc_cfg[1]);

	/* ADC0 Config for Init */
	adc_cfg[0].system_clock = SystemCoreClock;	/* System clock */
	adc_cfg[0].adc_clock = ADC_CLOCK_RATE;	/* ADC clock */
	adc_cfg[0].async_mode = 0;	/* Synchronous mode */
	adc_cfg[0].tenbit_mode = 0;	/* 12 Bit ADC mode */
	adc_cfg[0].lpwr_mode = 0;	/* Disable low power mode */
	adc_cfg[0].input_sel = ADC_INSEL_TS;
	adc_cfg[0].seqa_ctrl = (ADC_SEQ_CTRL_CHANSEL(0) | ADC_SEQ_CTRL_MODE_EOS);
	adc_cfg[0].channel_num = 1;	/* Channel number is one higher than the maximum channel number used */
	/* ADC1 Config for Init */
	adc_cfg[1].system_clock = SystemCoreClock;	/* System clock */
	adc_cfg[1].adc_clock = ADC_CLOCK_RATE;	/* ADC clock */
	adc_cfg[1].async_mode = 0;	/* Synchronous mode */
	adc_cfg[1].tenbit_mode = 0;	/* 12 Bit ADC mode */
	adc_cfg[1].lpwr_mode = 0;	/* Disable low power mode */
	adc_cfg[1].seqa_ctrl = (ADC_SEQ_CTRL_CHANSEL(BOARD_ADC_CH) | ADC_SEQ_CTRL_MODE_EOS);
	adc_cfg[1].thrsel = 0;
	adc_cfg[1].thr0_low = ((1 * 0xFFF) / 4) << 4;
	adc_cfg[1].thr0_high = ((3 * 0xFFF) / 4) << 4;
	adc_cfg[1].thcmp_en = ADC_INTEN_CMP_ENABLE(ADC_INTEN_CMP_CROSSTH, BOARD_ADC_CH);
	adc_cfg[1].channel_num = BOARD_ADC_CH + 1;	/* Channel number is one higher than the maximum channel number used */
	pAdcApi->adc_init(adc_handle[0], &adc_cfg[0]);
	pAdcApi->adc_init(adc_handle[1], &adc_cfg[1]);
	
	/* When using ADC ROM API's lower the priority of ADC Sequence completion interrupt when compared to the threshold interrupt*/
	NVIC_SetPriority(ADC1_SEQA_IRQn, 1);
	/* Enable related ADC NVIC interrupts */
	NVIC_EnableIRQ(ADC0_SEQA_IRQn);
	NVIC_EnableIRQ(ADC1_SEQA_IRQn);
	NVIC_EnableIRQ(ADC1_THCMP);

	/* This example uses the periodic sysTick to manually trigger the ADC,
	   but a periodic timer can be used in a match configuration to start
	   an ADC sequence without software intervention. */
	SysTick_Config(Chip_Clock_GetSysTickClockRate() / TICKRATE_HZ);

	/* Endless loop */
	while (1) {
		/* Sleep until something happens */
		__WFI();

		if (threshold1Crossed) {
			threshold1Crossed = false;
			DEBUGSTR("********ADC1 threshold event********\r\n");
		}

		/* Is a conversion sequence complete? */
		if (sequence0Complete) {
			sequence0Complete = false;
			showValudeADC(LPC_ADC0);
		}
		if (sequence1Complete) {
			sequence1Complete = false;
			showValudeADC(LPC_ADC1);
		}
	}

	/* Should not run to here */
	return 0;
}
Пример #3
0
int main(void) {

#if defined (__USE_LPCOPEN)
	// Read clock settings and update SystemCoreClock variable
	SystemCoreClockUpdate();
#if !defined(NO_BOARD_LIB)
	// Set up and initialize all required blocks and
	// functions related to the board hardware
	Board_Init();
	// Set the LED to the state of "On"
#endif
#endif

	Timer aika(0, 30, 0, true);
	Timer ledi(0, 10, 0, true);
	Timer skooppi(0, 0, 300, true);

	// write code here that uses two timer objects
	// one is used to print current time every 30 seconds (use semihosting for printing)
	// second to switch led colour every 10 seconds
	// third to give a pulse on PIO0_10 every 300 ms
	// make the timer tick from main program - do not call object's methods from ISR

	// Otetaan käyttöön GPION 0,10
	Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 10, (IOCON_DIGMODE_EN));
	Chip_GPIO_SetPinDIROutput(LPC_GPIO, 0, 10);

	// Force the counter to be placed into memory
	volatile static int i = 0 ;

	/* The sysTick counter only has 24 bits of precision, so it will
	   overflow quickly with a fast core clock. You can alter the
	   sysTick divider to generate slower sysTick clock rates. */
	Chip_Clock_SetSysTickClockDiv(1);

	/* A SysTick divider is present that scales the sysTick rate down
	   from the core clock. Using the SystemCoreClock variable as a
	   rate reference for the SysTick_Config() function won't work,
	   so get the sysTick rate by calling Chip_Clock_GetSysTickClockRate() */
	uint32_t sysTickRate = Chip_Clock_GetSysTickClockRate();

	/* Enable and setup SysTick Timer at a periodic rate */
	SysTick_Config(sysTickRate / TICKRATE_HZ1);

	while(1){

		// Enter an infinite loop, just incrementing a counter
		while(!flag) __WFI();
		flag = false;

		if(aika.Tick()){
			// Aika on loppu tässä
			// Tulosta aika semihostingilla
			//enter_critical();
			 printf("RealTimeClock after every 30secons.: %d.%d.%d\n", h,m,s);
		}

		if(ledi.Tick()){
			//Aika on loppu tässä
			Board_LED_Set(q, false);
			q++;
			Board_LED_Set(q, true);
			if (q == 2){
				q = 0;
			}
		}

		if(skooppi.Tick()){
			//Aika on loppu tässä
			// pulssi
			if (pulssi == 0) {
				Chip_GPIO_SetPinState(LPC_GPIO, 0, 10, true);
				pulssi = 1;
			}else{
				pulssi = 0;
				Chip_GPIO_SetPinState(LPC_GPIO, 0, 10, false);
			}

		}
		i++ ;
	}
	return 0 ;
}