int main(void) { io_init(); //adc_init(); init_interrupt(); TCCR1A = 0; // set entire TCCR1A register to 0 TCCR1B = 0; TIMSK1 = (1 << TOIE1); // enable Timer1 overflow interrupt TCCR1B |= (1 << CS12); // Set CS12 prescaler (100). Prescaler set to 256. 16 000 000 CPU speed / 256 = 62 500. Each bit is 1/62500 s = 16 us interrupts_on(); while (1) { ;; //lightAll(); //update7seg(0); //bin_to_7seg(2, 0); //set_output(OUT1, 1); //set_output(OUT2, 1); //set_output(OUT3, 1); //set_output(OUT4, 1); //set_output(OUT5, 1); //set_output(OUT6, 1); //set_output(OUT7, 1); } return 0; }
static void show_interrupt(void) { int err; /* QUESTION: how did we get here if there was an assert above? */ /* now think about interrupts. you will need to understand how they * work, and how they interact with get/setcontext for implementing * preemptive threading. */ /* QUESTION: what does interrupts_on() do? see interrupt.c */ interrupts_on(); /* getcontext stores the process's signal mask */ err = getcontext(&mycontext); assert(!err); /* QUESTION: Are interrupts masked (i.e., disabled) in mycontext? * HINT: use sigismember below. */ printf("interrupt is disabled = %d\n", (unsigned int) sigismember(&mycontext.uc_sigmask, SIG_TYPE)); interrupts_off(); err = getcontext(&mycontext); assert(!err); /* QUESTION: which fields of mycontext changed as a result of the * getcontext call above? */ printf("interrupt is disabled = %d\n", (unsigned int) sigismember(&mycontext.uc_sigmask, SIG_TYPE)); }
int main(void) { io_init(); timer0_init(); timer1_init(OFF); interrupts_on(); while (1) { } return 0; }