static void dma_run_channel(int dma_idx, int chan_idx) { int done = 0; long ticks = 0; while (!done && (HAVE_DRQ(dma_idx, chan_idx) || SW_ACTIVE(dma_idx, chan_idx))) { if (!MASKED(dma_idx, chan_idx) && !REACHED_TC(dma_idx, chan_idx) && !(dma[dma_idx].command & 4) && (DMA_TRANSFER_MODE(dma[dma_idx].chans[chan_idx].mode) != CASCADE)) { dma_process_channel(dma_idx, chan_idx); ticks++; } else { done = 1; } dma_update_DRQ(dma_idx, chan_idx); } if (ticks > 1) q_printf("DMA: processed %lu (left %u) cycles on controller %i channel %i\n", ticks, dma[dma_idx].chans[chan_idx].cur_count.value, dma_idx, chan_idx); }
int main(void) { SetSystemClockPrescaler(0); init(); sei(); led_blink(3); while (1) { if(SW_ACTIVE()) { // SW pressed uint8_t pressCnt = 100; // wait until released do { // long term press detected? if(pressCnt>0 && --pressCnt==0) LED_ON(); _delay_ms(10); } while(SW_ACTIVE()); // SW released LED_OFF(); if(pressCnt>0) handleSensor(1); // force transmit else { // program mode LED_ON(); fs20_resetbuffer(); fs20_rxon(); fstelegram_t t; t.type = 'U'; // undefined pressCnt = 100; // wait for next telegram // exit if button pressed or timeout occured while(!fs20_readFS20Telegram(&t) && --pressCnt>0 && !SW_ACTIVE()) _delay_ms(100); fs20_idle(); LED_OFF(); // save the result if(t.type=='F') { saveConfig(t.housecode, t.button); led_blink(2); // confirm save of config handleSensor(1); // force transmit } // wait until sw releases while(SW_ACTIVE()); } } // check long term timer if(longTimerCnt >= LONGTIMER_VAL) handleSensor(1); // finaly check if sensor value changed // this will only be the case if the current sensor value haven't been sent // during this cycle handleSensor(0); // sleep well LED_OFF(); SENS_ACTIVATE(0); set_sleep_mode(SLEEP_MODE_PWR_DOWN); sleep_mode(); } }