/* Init the ARM global timer to a microsecond-frequency clock.  */
void time_init_global_timer()
/* Init the ARM global timer to a microsecond-frequency clock.  */
void time_init_global_timer()
{
    uint32_t periphClock = get_main_clock(CPU_CLK) / 2;
    uint32_t prescaler = (periphClock / 1000000) - 1;
    g_microsecondTimerMultiple = 1;
    while (prescaler > 0xff)
    {
        prescaler /= 2;
        ++g_microsecondTimerMultiple;
    }
    HW_ARMGLOBALTIMER_CONTROL.B.TIMER_ENABLE = 0;
    HW_ARMGLOBALTIMER_COUNTERn_WR(0, 0);
    HW_ARMGLOBALTIMER_COUNTERn_WR(1, 0);
    HW_ARMGLOBALTIMER_CONTROL_WR(BF_ARMGLOBALTIMER_CONTROL_PRESCALER(prescaler));
    HW_ARMGLOBALTIMER_CONTROL.B.TIMER_ENABLE = 1;
}