ccbb5e84f9
Docs are here: http://tannewt-micropython.readthedocs.io/en/microcontroller/ It differs from upstream's machine in the following ways: * Python API is identical across ports due to code structure. (Lives in shared-bindings) * Focuses on abstracting common functionality (AnalogIn) and not representing structure (ADC). * Documentation lives with code making it easy to ensure they match. * Pin is split into references (board.D13 and microcontroller.pin.PA17) and functionality (DigitalInOut). * All nativeio classes claim underlying hardware resources when inited on construction, support Context Managers (aka with statements) and have deinit methods which release the claimed hardware. * All constructors take pin references rather than peripheral ids. Its up to the implementation to find hardware or throw and exception.
34 lines
941 B
C
34 lines
941 B
C
#include "autoreset.h"
|
|
|
|
#include "tick.h"
|
|
|
|
#include "asf/sam0/drivers/tc/tc_interrupt.h"
|
|
|
|
// Global millisecond tick count
|
|
volatile uint64_t ticks_ms = 0;
|
|
|
|
static struct tc_module ms_timer;
|
|
|
|
static void ms_tick(struct tc_module *const module_inst) {
|
|
// SysTick interrupt handler called when the SysTick timer reaches zero
|
|
// (every millisecond).
|
|
ticks_ms += 1;
|
|
|
|
#ifdef AUTORESET_DELAY_MS
|
|
autoreset_tick();
|
|
#endif
|
|
}
|
|
|
|
void tick_init() {
|
|
struct tc_config config_tc;
|
|
tc_get_config_defaults(&config_tc);
|
|
config_tc.counter_size = TC_COUNTER_SIZE_16BIT;
|
|
config_tc.clock_prescaler = TC_CLOCK_PRESCALER_DIV1;
|
|
tc_set_top_value(&ms_timer, system_cpu_clock_get_hz() / 1000);
|
|
tc_init(&ms_timer, TC5, &config_tc);
|
|
tc_enable(&ms_timer);
|
|
tc_register_callback(&ms_timer, ms_tick, TC_CALLBACK_OVERFLOW);
|
|
tc_enable_callback(&ms_timer, TC_CALLBACK_OVERFLOW);
|
|
tc_start_counter(&ms_timer);
|
|
}
|