Hardware timer support
This commit is contained in:
parent
5151ccc3b2
commit
1d72ed3f70
8 changed files with 527 additions and 4 deletions
examples/blink_timers
2
examples/blink_timers/Makefile
Normal file
2
examples/blink_timers/Makefile
Normal file
|
@ -0,0 +1,2 @@
|
|||
PROGRAM=blink_timers
|
||||
include ../../common.mk
|
64
examples/blink_timers/blink_timers.c
Normal file
64
examples/blink_timers/blink_timers.c
Normal file
|
@ -0,0 +1,64 @@
|
|||
/* The "blink" example, but writing the LED from timer interrupts
|
||||
*
|
||||
* This sample code is in the public domain.
|
||||
*/
|
||||
#include "espressif/esp_common.h"
|
||||
#include "espressif/sdk_private.h"
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include "esp8266.h"
|
||||
|
||||
const int gpio_frc1 = 12;
|
||||
const int freq_frc1 = 1;
|
||||
|
||||
const int gpio_frc2 = 14;
|
||||
const int freq_frc2 = 10;
|
||||
|
||||
static volatile uint32_t frc1_count;
|
||||
static volatile uint32_t frc2_count;
|
||||
|
||||
void frc1_interrupt_handler(void)
|
||||
{
|
||||
frc1_count++;
|
||||
gpio_toggle(gpio_frc1);
|
||||
}
|
||||
|
||||
void frc2_interrupt_handler(void)
|
||||
{
|
||||
/* FRC2 needs the match register updated on each timer interrupt */
|
||||
timer_set_frequency(TIMER_FRC2, freq_frc2);
|
||||
frc2_count++;
|
||||
gpio_toggle(gpio_frc2);
|
||||
}
|
||||
|
||||
void user_init(void)
|
||||
{
|
||||
sdk_uart_div_modify(0, UART_CLK_FREQ / 115200);
|
||||
|
||||
/* configure GPIOs */
|
||||
gpio_enable(gpio_frc1, GPIO_OUTPUT);
|
||||
gpio_enable(gpio_frc2, GPIO_OUTPUT);
|
||||
gpio_write(gpio_frc1, 1);
|
||||
|
||||
/* stop both timers and mask their interrupts as a precaution */
|
||||
timer_set_interrupts(TIMER_FRC1, false);
|
||||
timer_set_run(TIMER_FRC1, false);
|
||||
timer_set_interrupts(TIMER_FRC2, false);
|
||||
timer_set_run(TIMER_FRC2, false);
|
||||
|
||||
/* set up ISRs */
|
||||
_xt_isr_attach(INUM_TIMER_FRC1, frc1_interrupt_handler);
|
||||
_xt_isr_attach(INUM_TIMER_FRC2, frc2_interrupt_handler);
|
||||
|
||||
/* configure timer frequencies */
|
||||
timer_set_frequency(TIMER_FRC1, freq_frc1);
|
||||
timer_set_frequency(TIMER_FRC2, freq_frc2);
|
||||
|
||||
/* unmask interrupts and start timers */
|
||||
timer_set_interrupts(TIMER_FRC1, true);
|
||||
timer_set_run(TIMER_FRC1, true);
|
||||
timer_set_interrupts(TIMER_FRC2, true);
|
||||
timer_set_run(TIMER_FRC2, true);
|
||||
|
||||
gpio_write(gpio_frc1, 0);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue