void FLYMAPLEScheduler::init(void* machtnichts) { delay_us(2000000); // Wait for startup so we have time to connect a new USB console // 1kHz interrupts from systick for normal timers systick_attach_callback(_timer_procs_timer_event); // Set up Maple hardware timer for 1khz failsafe timer // ref: http://leaflabs.com/docs/lang/api/hardwaretimer.html#lang-hardwaretimer _failsafe_timer.pause(); _failsafe_timer.setPeriod(1000); // 1000us = 1kHz _failsafe_timer.setChannelMode(TIMER_CH1, TIMER_OUTPUT_COMPARE);// Set up an interrupt on channel 1 _failsafe_timer.setCompare(TIMER_CH1, 1); // Interrupt 1 count after each update _failsafe_timer.attachInterrupt(TIMER_CH1, _failsafe_timer_event); _failsafe_timer.refresh();// Refresh the timer's count, prescale, and overflow _failsafe_timer.resume(); // Start the timer counting // We run this timer at a higher priority, so that a broken timer handler (ie one that hangs) // will not prevent the failsafe timer interrupt. // Caution: the timer number must agree with the HardwareTimer number nvic_irq_set_priority(NVIC_TIMER2, 0x14); }