text: /*
   * Copyright (c) 2015, Intel Corporation
   * All rights reserved.
   * 
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions are met:
   * 
   * 1. Redistributions of source code must retain the above copyright notice,
   *    this list of conditions and the following disclaimer.
   * 2. Redistributions in binary form must reproduce the above copyright notice,
   *    this list of conditions and the following disclaimer in the documentation
   *    and/or other materials provided with the distribution.
   * 3. Neither the name of the Intel Corporation nor the names of its
   *    contributors may be used to endorse or promote products derived from this
   *    software without specific prior written permission.
   * 
   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   * ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL CORPORATION OR CONTRIBUTORS BE
   * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   * POSSIBILITY OF SUCH DAMAGE.
   */
  
  #include "qm_pic_timer.h"
  #include "qm_interrupt.h"
  
  #include <stdio.h>
  
  static unsigned int ticks;
  
  static void timer_expired(void)
  {
  	QM_PRINTF("%u\n", ticks);
  
  	ticks++;
  }
  
  qm_pic_timer_config_t conf;
  
  int main(void)
  {
  	ticks = 0;
  
  	conf.mode = QM_PIC_TIMER_MODE_PERIODIC;
  	conf.int_en = true;
  	conf.callback = timer_expired;
  
  #if (HAS_APIC)
  	qm_int_vector_request(QM_INT_VECTOR_PIC_TIMER, qm_pic_timer_isr);
  #elif(HAS_MVIC)
  	qm_irq_request(QM_IRQ_PIC_TIMER, qm_pic_timer_isr);
  #else
  #error "Unsupported processor/architecture"
  #endif
  
  	qm_pic_timer_set_config(&conf);
  
  	/* Set period.  The following value generates one interrupt per second
  	 * with a 32MHz sysclk.
  	 */
  	qm_pic_timer_set(0x2000000);
  
  	while (1) {
  	}
  
  	return 0;
  }
  