int cmd_bme(int argc, char * const argv[]) { uint32_t tick; systick_disable(); systick_cnt_init(); tick = SysTick->VAL; GPIOA->PDOR ^= 0x04; tick = tick - SysTick->VAL; printf("C XOR take:%d ticks\r\n", tick); systick_disable(); systick_cnt_init(); tick = SysTick->VAL; BME_XOR32(&GPIOA->PDOR, 0x04); tick = tick - SysTick->VAL; printf("BME XOR take:%d ticks\r\n", tick); systick_disable(); return 0; }
void setup() { // Setup our pins pinMode(BOARD_LED_PIN, OUTPUT); pinMode(VGA_R, OUTPUT); pinMode(VGA_G, OUTPUT); pinMode(VGA_B, OUTPUT); pinMode(VGA_V, OUTPUT); pinMode(VGA_H, OUTPUT); digitalWrite(VGA_R, LOW); digitalWrite(VGA_G, LOW); digitalWrite(VGA_B, LOW); digitalWrite(VGA_H, HIGH); digitalWrite(VGA_V, HIGH); // Fill the logo array with color patterns corresponding to its // truth value. Note that we could get more tricky here, since // there are 3 bits of color. for (int y = 0; y < y_max; y++) { for (int x = 0; x < x_max; x++) { logo[y][x] = logo[y][x] ? ON_COLOR : OFF_COLOR; } } // This gets rid of the majority of the interrupt artifacts; // there's still a glitch for low values of y, but let's not worry // about that. (Probably due to the hackish way vsync is done). SerialUSB.end(); systick_disable(); // Configure timer.pause(); // while we configure timer.setPrescaleFactor(1); // Full speed timer.setMode(TIMER_CH1, TIMER_OUTPUT_COMPARE); timer.setMode(TIMER_CH2, TIMER_OUTPUT_COMPARE); timer.setMode(TIMER_CH3, TIMER_OUTPUT_COMPARE); timer.setMode(TIMER_CH4, TIMER_OUTPUT_COMPARE); timer.setOverflow(2287); // Total line time timer.setCompare(TIMER_CH1, 200); timer.attachInterrupt(TIMER_CH1, isr_porch); timer.setCompare(TIMER_CH2, 300); timer.attachInterrupt(TIMER_CH2, isr_start); timer.setCompare(TIMER_CH3, 2170); timer.attachInterrupt(TIMER_CH3, isr_stop); timer.setCompare(TIMER_CH4, 1); // Could be zero, I guess timer.attachInterrupt(TIMER_CH4, isr_update); timer.setCount(0); // Ready... timer.resume(); // Go! }
/** * Initial configuration of the SysTick. * * System clock is set as the clock source, counter reload * value is set to the desired value and the counter is cleared. * * After configuration, the SysTick is disabled (not running) * and triggering of interrupts is disabled. */ void systick_config(uint32_t reload) { /* Stop the SysTick if it is running */ systick_disable(); /* * According to the Data Sheet, page 138, the clock source * should be set by default to the system clock, but apparently * it isn't, so it will be set using this command. */ systick_setSource(true); /* Set the counter to the reload value */ systick_setReload(reload); /* And finally clear the counter */ systick_clear(); /* Initially triggering of interrupts will be disabled */ systick_disableInterrupt(); }
void loop() { volatile int i = 0; toggleLED(); // An artificial delay for(i = 0; i < 150000; i++) ; if (isButtonPressed()) { if (disable) { systick_disable(); SerialUSB.println("Disabling SysTick"); } else { SerialUSB.println("Re-enabling SysTick"); systick_enable(); } disable = !disable; } SerialUSB.println(millis()); }
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(); }