Volatile Variable

 

#include "hw_timer.h"
static const lpc_timer_e hw_timer = LPC_TIMER__1;
const uint32_t one_sec_in_us = UINT32_C(1) * 1000 * 1000;

static void hw_timer_isr_callback(void) { // every 1 second
  hw_timer__set_value(hw_timer, 0);
  hw_timer__acknowledge_interrupt(hw_timer, LPC_TIMER__MR0);

  ++counter;
  fprintf(stderr, "TTick: %i\n", counter);
}
void init_hw_timer_interrupt(uint32_t peripheral_clock_hz) {
  const uint32_t prescalar_for_1us = (peripheral_clock_hz / one_sec_in_us) - 1;
  hw_timer__enable(hw_timer, prescalar_for_1us, hw_timer_isr_callback);
  hw_timer__enable_match_isr(hw_timer, LPC_TIMER__MR0, one_sec_in_us);
}
//////////////////////////////////////////////////////////////////////////////////////////
// Tick 1
//   Tock
// Tick 1
//    Tock
// Tick 1
//    Tock
int main(void) {
  init_hw_timer_interrupt(96 * 1000 * 1000);
}
Back to top