static inline u32 dispatch_t150(t150 a151, t18 a152) { switch (a151) { case FUN_ENUM_align32: return align32(a152); default: return min_u32(a152); } }
static ICACHE_RAM_ATTR void timer1Interrupt() { uint32_t nextEventCycles; #if F_CPU == 160000000 uint8_t cnt = 20; #else uint8_t cnt = 10; #endif do { nextEventCycles = MicrosecondsToCycles(MAXIRQUS); for (size_t i = 0; i < countof(waveform); i++) { Waveform *wave = &waveform[i]; uint32_t now; // If it's not on, ignore! if (!wave->enabled) { continue; } // Check for toggles now = GetCycleCount(); int32_t cyclesToGo = wave->nextServiceCycle - now; if (cyclesToGo < 0) { wave->state = !wave->state; if (wave->state) { SetGPIO(wave->gpioMask); if (wave->gpio16Mask) { GP16O |= wave->gpio16Mask; // GPIO16 write slow as it's RMW } wave->nextServiceCycle = now + wave->nextTimeHighCycles; nextEventCycles = min_u32(nextEventCycles, wave->nextTimeHighCycles); } else { ClearGPIO(wave->gpioMask); if (wave->gpio16Mask) { GP16O &= ~wave->gpio16Mask; } wave->nextServiceCycle = now + wave->nextTimeLowCycles; nextEventCycles = min_u32(nextEventCycles, wave->nextTimeLowCycles); } } else { uint32_t deltaCycles = wave->nextServiceCycle - now; nextEventCycles = min_u32(nextEventCycles, deltaCycles); } } } while (--cnt && (nextEventCycles < MicrosecondsToCycles(4))); uint32_t curCycleCount = GetCycleCount(); uint32_t deltaCycles = curCycleCount - lastCycleCount; lastCycleCount = curCycleCount; // Check for timed-out waveforms out of the high-frequency toggle loop for (size_t i = 0; i < countof(waveform); i++) { Waveform *wave = &waveform[i]; if (wave->timeLeftCycles) { // Check for unsigned underflow with new > old if (deltaCycles >= wave->timeLeftCycles) { // Done, remove! wave->enabled = false; ClearGPIO(wave->gpioMask); GP16O &= ~wave->gpio16Mask; } else { uint32_t newTimeLeftCycles = wave->timeLeftCycles - deltaCycles; wave->timeLeftCycles = newTimeLeftCycles; } } } if (timer1CB) { nextEventCycles = min_u32(nextEventCycles, timer1CB()); } #if F_CPU == 160000000 if (nextEventCycles <= 5 * MicrosecondsToCycles(1)) { nextEventCycles = MicrosecondsToCycles(1) / 2; } else { nextEventCycles -= 5 * MicrosecondsToCycles(1); } nextEventCycles = nextEventCycles >> 1; #else if (nextEventCycles <= 6 * MicrosecondsToCycles(1)) { nextEventCycles = MicrosecondsToCycles(1) / 2; } else { nextEventCycles -= 6 * MicrosecondsToCycles(1); } #endif ReloadTimer(nextEventCycles); }