Skip to content

Lab 2 Tasks

Requested Functions

  • int timer_set_frequency(uint8_t timer, uint32_t freq)
  • int timer_get_conf(uint8_t timer, uint8_t *status)
  • int timer_subscribe(lcom_irq_t *irq)
  • int timer_unsubscribe(lcom_irq_t *irq)
  • void timer_ih(void)
  • uint32_t timer_ticks(void)

Guided Gaps

  • Reject invalid timer numbers and impossible frequencies.
  • Build the control word from fields.
  • Split a 16-bit divisor into low and high bytes.
  • Track ticks without relying on wall-clock time.
  • Make subscribe and unsubscribe symmetric.

IMPORTANT

Interrupt handlers should not contain large application logic. Record the device event, then let the main loop decide what to do.

Common Mistakes

  • Dividing in the wrong direction.
  • Accepting a divisor of zero.
  • Writing only one byte of the divisor.
  • Counting ticks in the main loop instead of in the handler.

Next: checks and references.

Course/docs licensed CC BY 4.0. Code licensed MIT.