void delay_init(void) /* Initializes the timer used for delays */ { pmc_enable_periph_clk(ID_TC4); tc_init(TC1,1,0); /* TC1, channel 1, TCLK1 och capturemode */ tc_set_block_mode(TC1,0); tc_stop(TC1,1); /* making sure the timer does not run */ }
/** * \brief Process Buttons Events * * Change active states of LEDs when corresponding button events happened. */ static void ProcessButtonEvt(uint8_t uc_button) { // [main_button1_evnt_process] if (uc_button == 0) { g_b_led0_active = !g_b_led0_active; if (!g_b_led0_active) { ioport_set_pin_level(LED0_GPIO, IOPORT_PIN_LEVEL_HIGH); } } // [main_button1_evnt_process] #ifdef LED1_GPIO else { // [main_button2_evnt_process] g_b_led1_active = !g_b_led1_active; /* Enable LED#2 and TC if they were enabled */ if (g_b_led1_active) { ioport_set_pin_level(LED1_GPIO, IOPORT_PIN_LEVEL_LOW); tc_start(TC0, 0); } /* Disable LED#2 and TC if they were disabled */ else { ioport_set_pin_level(LED1_GPIO, IOPORT_PIN_LEVEL_HIGH); tc_stop(TC0, 0); } // [main_button2_evnt_process] } #endif }
/** * \brief Application entry point. * * \return Unused (ANSI-C compatibility). */ int main(void) { uint8_t uc_key; /* Initialize the SAM system. */ sysclk_init(); board_init(); configure_console(); /* Output example information. */ puts(STRING_HEADER); g_afec0_sample_data = 0; g_afec1_sample_data = 0; g_max_digital = MAX_DIGITAL_12_BIT; set_afec_test(); while (1) { afec_start_software_conversion(AFEC0); delay_ms(g_delay_cnt); /* Check if the user enters a key. */ if (!uart_read(CONF_UART, &uc_key)) { /* Disable all afec interrupt. */ afec_disable_interrupt(AFEC0, AFEC_INTERRUPT_ALL); afec_disable_interrupt(AFEC1, AFEC_INTERRUPT_ALL); tc_stop(TC0, 0); set_afec_test(); } } }
/* Sleep for specified period. This is useful for synchronising the CPU clock MCK to the timer clock, especially since the fastest timer clock is MCK / 2. */ void tc_clock_sync (tc_t tc, tc_period_t period) { uint32_t id; tc_config_1 (tc, TC_MODE_DELAY_ONESHOT, period, period, 1); id = ID_TC0 + TC_CHANNEL (tc); irq_config (id, 7, tc_clock_sync_handler); irq_enable (id); /* Enable interrupt when have compare on A. */ tc->base->TC_IER = TC_IER_CPAS; tc_start (tc); /* Stop CPU clock until interrupt. FIXME, should disable other interrupts first. */ mcu_cpu_idle (); /* Disable interrupt when have compare on A. */ tc->base->TC_IDR = TC_IDR_CPAS; irq_disable (id); tc_stop (tc); }
/** * \brief Interrupt handler for USART. * * Increment the number of bytes received in the current second and start * another transfer if the desired bps has not been met yet. * */ void USART_Handler(void) { uint32_t ul_status; tc_stop(TC0, 0); /* Read USART status. */ ul_status = usart_get_status(BOARD_USART); /* Receive buffer is full. */ if (ul_status & US_CSR_RXBUFF) { g_ul_bytes_received += 2 * BUFFER_SIZE; if (g_ul_bytes_received < MAX_BPS) { /* Restart transfer if BPS is not high enough. */ g_st_packet.ul_addr = (uint32_t)gs_puc_buffer; g_st_packet.ul_size = BUFFER_SIZE; g_st_nextpacket.ul_addr = (uint32_t)gs_puc_nextbuffer; g_st_nextpacket.ul_size = BUFFER_SIZE; pdc_rx_init(g_p_pdc, &g_st_packet, &g_st_nextpacket); } else { /* Otherwise disable interrupt. */ usart_disable_interrupt(BOARD_USART, US_IDR_RXBUFF); } memcpy(gs_dump_buffer, gs_puc_buffer, BUFFER_SIZE); } tc_start(TC0, 0); }
/** * \brief ADC interrupt handler. * Entramos aqui quando a conversao for concluida. */ void ADC_Handler(void) { uint32_t tempValue; uint32_t status ; status = adc_get_status(ADC); /* Checa se a interrupção é devido ao canal 5 */ if ((status & ADC_ISR_EOC5)) { tempValue = adc_get_channel_value(ADC, ADC_POT_CHANNEL); if ((tempValue > adc_value_old + 2) || (tempValue < adc_value_old - 2)) { if (isAmp){ amplitude = tempValue; atualiza_amp(amplitude); } else { frequencia = tempValue; tc_stop(TC0,0); configure_tc((frequencia*32768/2000)/4095); atualiza_freq(frequencia); } } adc_value_old = tempValue; } }
void TC1_Handler(void) { volatile uint32_t ul_dummy; /* Clear status bit to acknowledge interrupt */ ul_dummy = tc_get_status(TC0,1); #if RTIMER_DEBUG if ((ul_dummy & TC_SR_CPCS) == TC_SR_CPCS) { #endif tc_stop(TC0,1); // Crucial, since the execution may take long time #if RTIMER_DEBUG printf("Compare event %16x\r\n", ul_dummy); #endif tc_disable_interrupt(TC0,1,TC_IDR_CPCS); // Disable the next compare interrupt XXX XXX ENERGEST_ON(ENERGEST_TYPE_IRQ); rtimer_run_next(); /* Run the posted task. */ ENERGEST_OFF(ENERGEST_TYPE_IRQ); #if RTIMER_DEBUG } else { printf("Unknown interrupt.\n\n"); } #endif }
// Set the frequency of the generated tone. 0 means off. void audioFrequencySet(uint32_t freq) { // In order to avoid audio hiccups, don't do anything if setting // same frequency. if (currFreq == freq) { return; } tc_stop(TC0, 0); if (freq == 0) { return; } // Find the best divisor for this frequency uint32_t ul_div, ul_tcclks; tc_find_mck_divisor(freq, SystemCoreClock, &ul_div, &ul_tcclks, SystemCoreClock); // Put Timer into wavesel up RC mode with TIOA at 50% duty cycle // Clear TIOA at CPC match and set at CPA match tc_init(TC0, 0, ul_tcclks | TC_CMR_WAVE | TC_CMR_WAVSEL_UP_RC | TC_CMR_ACPC_CLEAR | TC_CMR_ACPA_SET); uint16_t rcVal = (SystemCoreClock / ul_div) / freq; tc_write_rc(TC0, 0, rcVal); tc_write_ra(TC0, 0, rcVal / 2); // 50% duty cycle // Start the thing tc_start(TC0, 0); currFreq = freq; }
void tc_start(const char* tc_prefix) { rt_err_t result; /* tesecase prefix is null */ if (tc_prefix == RT_NULL) { rt_kprintf("TestCase Usage: tc_start(prefix)\n\n"); rt_kprintf("list_tc() can list all testcases.\n"); return ; } /* init tc thread */ if (_tc_stat & TC_STAT_RUNNING) { /* stop old tc thread */ tc_stop(); } rt_memset(_tc_prefix, 0, sizeof(_tc_prefix)); rt_snprintf(_tc_prefix, sizeof(_tc_prefix), "_tc_%s", tc_prefix); result = rt_thread_init(&_tc_thread, "tc", tc_thread_entry, RT_NULL, &_tc_stack[0], sizeof(_tc_stack), TC_PRIORITY - 3, 5); /* set tc stat */ _tc_stat = TC_STAT_RUNNING | TC_STAT_FAILED; if (result == RT_EOK) rt_thread_startup(&_tc_thread); }
/** * \brief LIN Application entry point. * * \return Unused (ANSI-C compatibility). */ int main(void) { /* Output example information */ console_example_info("LIN Example"); /* Configure Console interrupts */ printf("Initializing console interrupts\r\n"); console_set_rx_handler(_console_handler); console_enable_rx_interrupt(); /* Configure Timer/Counter */ _configure_tc(); /* Configure com port */ _init_com_master(); _init_com_slave(); /* main LIN program */ _display_menu(); do { switch (key) { case 'P': case 'p': case 'S': case 's': case 'I': case 'i': tc_stop(TC0, TC_CHANNEL); _process_button_evt(); _display_menu(); if (key == 'I' || key == 'i') tc_stop(TC0, 0); else tc_start(TC0, TC_CHANNEL); key = 0; break; default: break; } } while (key != 'q' && key != 'Q'); tc_stop(TC0, TC_CHANNEL); timer_wait(500); printf("\n\rEnd of demo\n\r"); while (1); }
int delayInit(void) /* Initializes the timer used for delays */ { pmc_enable_periph_clk(ID_TC0); /* power on the peripheral clock for timers */ tc_init(TC0,0,0); /* TC0, channel 0, TCLK1 och capturemode */ tc_set_block_mode(TC0,0); tc_stop(TC0,0); /* making sure the timer does not run */ return 0; /* evertyhing is ok, typical response */ }
//*** Private method that actually sends data ***// int wifi_send_data(int ch, const uint8_t* data, int size){ int cmd_buf_size = MD_BUF_SIZE; char *cmd; int timeout = 7; //wait 7 seconds to transmit the data //allocate memory cmd = core_malloc(cmd_buf_size); snprintf(cmd,cmd_buf_size,"AT+CIPSEND=%d,%d\r\n",ch,size); data_tx_status=TX_PENDING; rx_wait=true; resp_buf_idx = 0; memset(resp_buf,0x0,RESP_BUF_SIZE); memset(wifi_rx_buf,0x0,WIFI_RX_BUF_SIZE); //to make debugging easier wifi_rx_buf_idx=0; usart_serial_write_packet(WIFI_UART,(uint8_t*)cmd,strlen(cmd)); delay_ms(250); //wait for module to be ready to accept data usart_serial_write_packet(WIFI_UART,(uint8_t*)data,size); //now wait for the data to be sent while(timeout>0){ //start the timer tc_start(TC0, 0); //when timer expires, return what we have in the buffer rx_wait=true; //reset the wait flag while(rx_wait && data_tx_status!=TX_SUCCESS); tc_stop(TC0,0); //the success flag is set *before* we receive the server's response //core_process_wifi_data receives the response but discards it if(data_tx_status==TX_SUCCESS){ data_tx_status=TX_IDLE; rx_wait = false; //free memory core_free(cmd); return TX_SUCCESS; } timeout--; } //check if this is a timeout error if(strlen((char*)resp_buf)==0){ printf("timeout error\n"); core_log("timeout error"); data_tx_status = TX_TIMEOUT; } //an error occured, see if it is due to a module reset else if(strcmp((char*)resp_buf,"\r\nready\r\n")==0){ //module reset itself!!! printf("detected module reset\n"); core_log("module reset"); data_tx_status = TX_ERR_MODULE_RESET; } else { data_tx_status=TX_ERROR; core_log("TX error:"); core_log((char*)resp_buf); data_tx_status = TX_ERROR; } //free memory core_free(cmd); return data_tx_status; }
void start_timeoutcnt(void) { if(timerEnabled == false){ setup_timeoutcnt(); } tc_stop(TC0, TC_CHANNEL_TICKCNT); TimeoutTicksRemaining = defaultTimeoutTicks; /* x / 2500 = timeout in seconds */ tc_start(TC0, TC_CHANNEL_TICKCNT); }
/** * \brief This function closes and disables communication in the specified UART. * * \param chn Communication channel [0, 1] * * \retval true on success. * \retval false on failure. */ int8_t buart_if_close(uint8_t chn) { if (!buart_chn_open[chn]) { return false; } switch (chn) { #ifdef CONF_BOARD_UART0 case 0: { uart_disable(UART0); uart_disable_interrupt(UART0, US_IDR_RXRDY); uart_disable_interrupt(UART0, US_IER_ENDRX); /* Stop TC */ if (!buart_chn_open[1]) { tc_stop(TC_UART, TC_UART_CHN); } return true; } break; #endif #ifdef CONF_BOARD_UART1 case 1: { uart_disable(UART1); uart_disable_interrupt(UART1, US_IDR_RXRDY); uart_disable_interrupt(UART1, US_IER_ENDRX); /* Stop TC */ if (!buart_chn_open[0]) { tc_stop(TC_UART, TC_UART_CHN); } return true; } break; #endif default: return false; } }
static void disable_output(const channel_def_t* channel) { if (channel->externally_driven) { // software trigger to clear the output, turn off the timer tc_software_trigger(channel->ex.timer, channel->ex.channel); tc_stop(channel->ex.timer, channel->ex.channel); } else if (channel->in.active_level) { gpio_set_pin_low(channel->in.pin1); } else { gpio_set_pin_high(channel->in.pin1); } }
static void reset_timeout(void) { if (s_period_counter > 0) { // see how long to wait uint16_t rc = min(0xffff,s_period_counter); tc_write_rc(CONFIG_BSP_BUZZER_REP_TIMER, CONFIG_BSP_BUZZER_REP_CHANNEL, rc); // remember how much we've waited s_period_counter -= rc; // Reset the counter tc_start(CONFIG_BSP_BUZZER_REP_TIMER, CONFIG_BSP_BUZZER_REP_CHANNEL); } else { // make sure the timer is stopped tc_stop(CONFIG_BSP_BUZZER_REP_TIMER, CONFIG_BSP_BUZZER_REP_CHANNEL); } }
void TICKER_COUNTER_Handlr2(void) { uint32_t status=tc_get_status(TICKER_COUNTER_lp, TICKER_COUNTER_CHANNEL2); uint32_t interrupmask=tc_get_interrupt_mask(TICKER_COUNTER_lp, TICKER_COUNTER_CHANNEL2); if (((status & interrupmask) & TC_IER_CPCS)) { if(lp_ticker_interrupt_counter) { lp_ticker_interrupt_counter--; } else { if(lp_ticker_interrupt_offset) { tc_stop(TICKER_COUNTER_lp, TICKER_COUNTER_CHANNEL2); tc_write_rc(TICKER_COUNTER_lp, TICKER_COUNTER_CHANNEL2, (uint32_t)lp_ticker_interrupt_offset); tc_start(TICKER_COUNTER_lp, TICKER_COUNTER_CHANNEL2); lp_ticker_interrupt_offset=0; } else { lp_ticker_irq_handler(); } } } }
/** * \brief Configure Timer Counter 0 to generate an interrupt with the specific * frequency. * * \param freq Timer counter frequency. */ static void configure_tc(uint32_t freq) { uint32_t ul_div; uint32_t ul_tcclks; uint32_t ul_sysclk = sysclk_get_cpu_hz(); /* Disable TC first */ tc_stop(TC0, 0); tc_disable_interrupt(TC0, 0, TC_IER_CPCS); /** Configure TC with the frequency and trigger on RC compare. */ tc_find_mck_divisor(freq, ul_sysclk, &ul_div, &ul_tcclks, ul_sysclk); tc_init(TC0, 0, ul_tcclks | TC_CMR_CPCTRG); tc_write_rc(TC0, 0, (ul_sysclk / ul_div) / 4); /* Configure and enable interrupt on RC compare */ NVIC_EnableIRQ((IRQn_Type)ID_TC0); tc_enable_interrupt(TC0, 0, TC_IER_CPCS); /** Start the counter. */ tc_start(TC0, 0); }
/** * \brief Interrupt handler for USART. Echo the bytes received and start the * next receive. */ void USART_Handler(void) { uint32_t ul_status; /* Read USART Status. */ ul_status = usart_get_status(BOARD_USART); /* Receive buffer is full. */ if (ul_status & US_CSR_RXBUFF) { /* Disable timer. */ tc_stop(TC0, 0); /* Echo back buffer. */ pdca_channel_write_load(PDCA_TX_CHANNEL, (void *)gs_puc_buffer[gs_uc_buf_num], gs_ul_size_buffer); pdca_channel_write_reload(PDCA_TX_CHANNEL, (void *)gs_puc_nextbuffer[gs_uc_buf_num], gs_ul_size_nextbuffer); if (g_uc_transend_flag) { gs_ul_size_buffer = BUFFER_SIZE; gs_ul_size_nextbuffer = BUFFER_SIZE; g_uc_transend_flag = 0; } gs_uc_buf_num = MAX_BUF_NUM - gs_uc_buf_num; /* Restart read on buffer. */ pdca_channel_write_load(PDCA_RX_CHANNEL, (void *)gs_puc_buffer[gs_uc_buf_num], BUFFER_SIZE); pdca_channel_write_reload(PDCA_RX_CHANNEL, (void *)gs_puc_nextbuffer[gs_uc_buf_num], BUFFER_SIZE); /* Restart timer. */ tc_start(TC0, 0); } }
void stop_timeoutcnt(void) { tc_stop(TC0, TC_CHANNEL_TICKCNT); }
/** * \name PWM functions * @{ */ void ui_pwm_led_init(uint8_t lednum) { /* Timer waveform options */ static tc_waveform_opt_t waveform_options = { /* Channel selection. */ .channel = 1, .bswtrg = TC_EVT_EFFECT_NOOP, .beevt = TC_EVT_EFFECT_NOOP, .bcpc = TC_EVT_EFFECT_NOOP, .bcpb = TC_EVT_EFFECT_NOOP, .aswtrg = TC_EVT_EFFECT_NOOP, .aeevt = TC_EVT_EFFECT_NOOP, .acpc = TC_EVT_EFFECT_NOOP, .acpa = TC_EVT_EFFECT_NOOP, /* Waveform selection */ .wavsel = TC_WAVEFORM_SEL_UP_MODE_RC_TRIGGER, /* External event trigger enable. */ .enetrg = false, /* External event selection (non-zero for Channel B to work) */ .eevt = !0, /* External event edge selection. */ .eevtedg = TC_SEL_NO_EDGE, .cpcdis = false, .cpcstop = false, .burst = false, .clki = false, /* Internal source clock 5, fPBA/128. */ .tcclks = TC_CLOCK_SOURCE_TC5, }; switch (lednum) { case LED0: /* Assign output pin to timer/counter 0 channel A */ /* Channel selection. */ waveform_options.channel = 1; waveform_options.bcpc = TC_EVT_EFFECT_NOOP; waveform_options.bcpb = TC_EVT_EFFECT_NOOP; /* RC compare effect on TIOA. */ waveform_options.acpc = TC_EVT_EFFECT_CLEAR; /* RA compare effect on TIOA. */ waveform_options.acpa = TC_EVT_EFFECT_SET; /* Setup timer/counter waveform mode */ sysclk_enable_peripheral_clock(&AVR32_TC0); tc_init_waveform(&AVR32_TC0, &waveform_options); /* Write the TOP (RC) and COMPARE (RA) values */ tc_write_ra(&AVR32_TC0, 1, 1); /* Set RA value. */ tc_write_rc(&AVR32_TC0, 1, 255); /* Set RC value. */ /* Start the timer PWM channel */ tc_start(&AVR32_TC0, 1); break; case LED1: /* Assign output pin to timer/counter 1 channel B */ /* Channel selection. */ waveform_options.channel = 2; waveform_options.acpc = TC_EVT_EFFECT_NOOP; waveform_options.acpa = TC_EVT_EFFECT_NOOP; /* RC compare effect on TIOB. */ waveform_options.bcpc = TC_EVT_EFFECT_CLEAR; /* RB compare effect on TIOB. */ waveform_options.bcpb = TC_EVT_EFFECT_SET; /* Setup timer/counter waveform mode */ sysclk_enable_peripheral_clock(&AVR32_TC1); tc_init_waveform(&AVR32_TC1, &waveform_options); /* Write the TOP (RC) and COMPARE (RB) values */ tc_write_rb(&AVR32_TC1, 2, 1); /* Set RB value. */ tc_write_rc(&AVR32_TC1, 2, 255); /* Set RC value. */ /* Start the timer PWM channel */ tc_start(&AVR32_TC1, 2); break; default: break; } } void ui_pwm_update(uint8_t channum, uint8_t brightness) { switch (channum) { case LED0: if (brightness != 0) { gpio_enable_module_pin(AVR32_TC0_A1_0_1_PIN, AVR32_TC0_A1_0_1_FUNCTION); tc_start(&AVR32_TC0, 1); tc_write_ra(&AVR32_TC0, 1, brightness); } else { tc_stop(&AVR32_TC0, 1); LED_Off(LED0); } break; case LED1: if (brightness != 0) { gpio_enable_module_pin(AVR32_TC1_B2_0_PIN, AVR32_TC1_B2_0_FUNCTION); tc_start(&AVR32_TC1, 2); tc_write_rb(&AVR32_TC1, 2, brightness); } else { tc_stop(&AVR32_TC1, 2); LED_Off(LED0); } break; default: break; } } /* End of PWM */ /** @} */ /** * \name Display functions * @{ */ static void ui_display_enable(void) { delay_init(sysclk_get_cpu_hz()); et024006_Init( sysclk_get_cpu_hz(), sysclk_get_hsb_hz()); /* Clear the display i.e. make it black */ et024006_DrawFilledRect(0, 0, ET024006_WIDTH, ET024006_HEIGHT, BLACK ); /* Set the backlight. */ gpio_set_gpio_pin(ET024006DHU_BL_PIN); ui_display_init_rtc(); ui_display_welcome_msg(); }
/*! \brief to stop the running timer */ void tmr_stop(void) { tc_stop(TIMER, TIMER_CHANNEL_ID); }
/** * Handle Interrupcao botao 2. */ static void Button2_Handler(uint32_t id, uint32_t mask) { tc_stop(TC0,0); tc_write_rc(TC0, 0, tc_read_rc(TC0, 0)*0.9); tc_start(TC0,0); }
/** * \brief The PWM signal stops toggling. */ void PWM_stop_toggle(void) { tc_stop(EPD_TC_WAVEFORM_ID); }
/** * \brief Stop Timer */ void stop_EPD_timer(void) { tc_stop(EPD_TC_TIMER_ID); }
int main(void) { uint8_t uc_key; /* Initialize the system */ sysclk_init(); board_init(); /* Configure LED 1 */ pmc_enable_periph_clk(ID_LED_BLUE); pio_set_output(PORT_LED_BLUE , MASK_LED_BLUE ,1,0,0); /* Initialize debug console */ config_uart(); /* frase de boas vindas */ puts(" ---------------------------- \n\r" " Bem vindo Corsi ! \n\r" " ---------------------------- \n\r"); /* display main menu */ display_menu(); configure_tc(); TC0_Handler(); pio_clear(PORT_LED_RED, MASK_LED_RED); pio_set(PORT_LED_GREEN, MASK_LED_GREEN); PIOA->PIO_PER = (1 << PIN_LED_BLUE ); PIOA->PIO_OER |= (1 << PIN_LED_BLUE ); PMC->PMC_PCER0 |= ID_PIOC; PIOC->PIO_PER |= (1 << PIN_LED_RED ); PIOC->PIO_OER |= (1 << PIN_LED_RED ); tc_stop(TC0, 0); PIOA->PIO_SODR = (1 << PIN_LED_BLUE ); PIOC->PIO_CODR = (1 << PIN_LED_RED ); while (1) { usart_serial_getchar((Usart *)CONSOLE_UART, &uc_key); switch (uc_key) { case '1': display_menu(); break; case '2': tc_start(TC0,0); PIOA->PIO_CODR = (1 << PIN_LED_BLUE ); puts("Led BLUE ON \n\r"); break; case '3' : tc_stop(TC0, 0); PIOA->PIO_SODR = (1 << PIN_LED_BLUE ); puts("Led BLUE OFF \n\r"); break; case '4': tc_start(TC0,0); pio_clear(PORT_LED_GREEN, MASK_LED_GREEN); puts("Led GREEN ON \n\r"); break; case '5' : tc_stop(TC0, 0); pio_set(PORT_LED_GREEN, MASK_LED_GREEN); puts("Led GREEN OFF \n\r"); break; case '6': tc_start(TC0,0); PIOC->PIO_SODR = (1 << PIN_LED_RED ); puts("Led RED ON \n\r"); break; case '7' : tc_stop(TC0, 0); PIOC->PIO_CODR = (1 << PIN_LED_RED ); puts("Led RED OFF \n\r"); break; case '8' : tc_write_rc(TC0, 0, tc_read_rc(TC0,0) * 0.5); puts("aumentando \n\r"); break; case '9' : tc_write_rc(TC0, 0, tc_read_rc(TC0,0) * 1.4); puts("diminuindo \n\r"); break; default: printf("Opcao nao definida: %d \n\r", uc_key); } } }
void delay(uint32_t us) /* A simple implementation for a delay in us (not calibrated) */ { tc_start(TC1,1); while (tc_read_cv(TC1,1) < us*42); tc_stop(TC1,1); }
/** * \brief Turn on/off ADC module. * * \param on True to start ADC, false to turn off. */ static void demo_start_adc(bool on) { uint32_t low_threshold, high_threshold; if (on == true) { /* Check if already enabled */ if (demo_adc_on) { return; } demo_config_adc(); /* Start TC0 and hardware trigger. */ tc_start(TC0, 1); /* Get the potentiometer initial value */ pontentiometer_value = adc_get_channel_value(ADC, ADC_CHANNEL_POTENTIOMETER); /* Set Window threshold according to the initial values */ low_threshold = pontentiometer_value - (NB_INTERVALS * (0x1000 / 256)); if (low_threshold > 0xf000000) { low_threshold = 0; } high_threshold = pontentiometer_value + (NB_INTERVALS * (0x1000 / 256)); if (high_threshold >= 0x1000) { high_threshold = 0x1000 - 1; } pontentiometer_value = pontentiometer_value*100 + 1; /* Channel 5 has to be compared. */ adc_set_comparison_channel(ADC, ADC_CHANNEL_POTENTIOMETER); /* Compare mode, out the window. */ adc_set_comparison_mode(ADC, ADC_EMR_CMPMODE_OUT); /* Set up Threshold. */ adc_set_comparison_window(ADC, low_threshold, high_threshold); /* Enable ADC interrupt. */ NVIC_EnableIRQ(ADC_IRQn); /* Enable Compare Interrupt. */ adc_enable_interrupt(ADC, ADC_IER_COMPE); /* Set adc on flag */ demo_adc_on = 1; /* Reset clapse time */ ppt_delay_clapse_counter = 0; } else { tc_stop(TC0, 1); /* Enable ADC interrupt. */ NVIC_DisableIRQ(ADC_IRQn); /* Enable Compare Interrupt. */ adc_disable_interrupt(ADC, ADC_IDR_COMPE); /* Set adc off flag */ demo_adc_on = 0; } }
void lp_ticker_disable_interrupt(void) { tc_stop(TICKER_COUNTER_lp, TICKER_COUNTER_CHANNEL2); tc_disable_interrupt(TICKER_COUNTER_lp, TICKER_COUNTER_CHANNEL2, TC_IDR_CPCS); NVIC_DisableIRQ(TICKER_COUNTER_IRQn2); }
/** * \brief Interrupt handler. Record the number of bytes received, * and then restart a read transfer on the USART if the transfer was stopped. */ void TC_USART_Handler(void) { uint32_t ul_status; #if defined(CONF_BOARD_USART0_RXD) || defined(CONF_BOARD_USART1_RXD) uint32_t ul_byte_total = 0; #endif /* Read TC_USART Status. */ ul_status = tc_get_status(TC_USART, TC_USART_CHN); /* RC compare. */ if ((ul_status & TC_SR_CPCS) == TC_SR_CPCS) { #ifdef CONF_BOARD_USART0_RXD if (busart_chn_open[0]) { /* Flush PDC buffer. */ ul_byte_total = USART_BUFFER_SIZE - pdc_read_rx_counter(g_p_usart_pdc0); if (ul_byte_total > 0) { if (ul_byte_total == num_bytes_rx_usart0) { /* Disable timer. */ tc_stop(TC_USART, TC_USART_CHN); /* Log current size */ gs_ul_size_usart_buf0 = ul_byte_total; /* Stop DMA USART_RX -> force Uart Handler*/ g_st_usart_rx_packet0.ul_size = 0; pdc_rx_init(g_p_usart_pdc0, &g_st_usart_rx_packet0, NULL); } else { num_bytes_rx_usart0 = ul_byte_total; } } else { num_bytes_rx_usart0 = 0; } } #endif #ifdef CONF_BOARD_USART1_RXD if (busart_chn_open[1]) { /* Flush PDC buffer. */ ul_byte_total = USART_BUFFER_SIZE - pdc_read_rx_counter(g_p_usart_pdc1); if (ul_byte_total > 0) { if (ul_byte_total == num_bytes_rx_usart1) { /* Disable timer. */ tc_stop(TC_USART, TC_USART_CHN); /* Log current size */ gs_ul_size_usart_buf1 = ul_byte_total; /* Stop DMA USART_RX -> force Uart Handler*/ g_st_usart_rx_packet1.ul_size = 0; pdc_rx_init(g_p_usart_pdc1, &g_st_usart_rx_packet1, NULL); } else { num_bytes_rx_usart1 = ul_byte_total; } } else { num_bytes_rx_usart1 = 0; } } #endif } }