Example #1
0
File: main.c Project: duparq/hwa
int main ( )
{
  /*  Create a HWA context to collect the hardware configuration
   *  Preload this context with RESET values
   */
  hwa( begin_from_reset );

  /*  Have the CPU enter idle mode when the 'sleep' instruction is executed.
   */
  hwa( configure,  core0,
       sleep,	   enabled,
       sleep_mode, idle	     );

  /*  Configure LED pin
   */
  hwa( configure, PIN_LED,
       mode,     digital_output   );

  /*  Configure analog input pin in analog mode (disable digital input buffer)
   *  and enable the internal pull-up resistor
   */
  hwa( configure, PIN_ANALOG_INPUT,
       mode,      analog_input_pullup );

  /*  Check that the counter can handle the top value. This must be done
   *  here since the C preprocessor does not allow floats in expressions.
   */
  if ( COUNT_TOP > ((1UL<<HW_BITS(COUNTER))-1) )
    HWA_ERR("PWM_COUNTER can not afford PWM_PERIOD.") ;

  /*  Configure the counter prescaler
   */
  hwa( configure, (COUNTER,prescaler),
       clock,	  ioclk );

  /*  Configure the counter to overflow periodically and trigger an interrupt
   *  The counter overflow ISR manages the compare IRQ
   */
  hwa( configure, COUNTER,
       clock,	  ioclk / COUNTER_CLK_DIV,
       direction, up_loop,
       bottom,	  0,
       top,	  TOP_OBJ,
       //	    overflow,  after_top,
       );
  hwa( write, (COUNTER, TOP_OBJ), COUNT_TOP );
  hwa( turn, irq(COUNTER,overflow), on );

  /*  Configure the ADC to make a single conversion and trigger an
   *  IRQ. The ISR will start a new conversion after its hard job is done.
   */
  hwa( configure, adc0,
       clock,	  ioclk / ADC_CLK_DIV,
       trigger,	  manual,
       vref,	  vcc,
       align,	  right,
       input,	  PIN_ANALOG_INPUT );
  
  hwa( turn, irq(adc0), on );
  hwa( trigger, adc0 );

  /*  Write this configuration into the hardware
   */
  hwa( commit );

  hw( enable_interrupts );

  for(;;)
    hw( sleep_until_irq );

  return 0 ;
}
Example #2
0
File: main.c Project: z13z4ck/hwa
int main ( )
{
  /*  Create a HWA context to collect the hardware configuration
   *  Preload this context with RESET values
   */
  hwa_begin_from_reset();

  /*  Have the CPU enter idle mode when the 'sleep' instruction is executed.
   */
  hwa( configure,  core0,
       sleep,	   enabled,
       sleep_mode, idle );

  /*  Configure LED pin
   */
  hwa( configure, PIN_LED, direction, output );

  /*  If REFERENCE is a pin, configure it in analog mode (disable its digital
   *  input buffer)
   */
#if HW_ID(REFERENCE)
  hwa( configure, REFERENCE,
       mode,	  analog,
       direction, input );
#endif

  /*  Configure INPUT_NEG pin in analog mode (disable digital input buffer)
   */
  hwa( configure, PIN_ANALOG_INPUT,
       mode,	  analog,
       direction, input );

  /*  Check that the counter can handle the ON_TIME value. This must be done
   *  here since the C preprocessor does not allow floats in expressions.
   */
  if ( ON_TIME_COUNT > ((1UL<<HW_BITS(COUNTER))-1) )
    HWA_ERR("COUNTER can not afford ON_TIME.") ;

  /*  Configure the counter to count from 0 to max
   */
  hwa( configure, COUNTER,
       clock,	  prescaler_output(COUNTER_CLK_DIV),
       countmode, up_loop );

  /*  Prepare the compare value for the PIN_LED pulse
   */
  hwa( write, HW_RELATIVE(COUNTER,COMPARE), ON_TIME_COUNT );

  /*  Configure the analog comparator
   */
  hwa( configure,      acmp0,
       edge,	       EDGE,
       positive_input, REFERENCE,
       negative_input, PIN_ANALOG_INPUT );

  hwa( turn, HW_IRQ(acmp0), on );

  /*  Write this configuration into the hardware
   */
  hwa_commit();

  hw_enable_interrupts();

  for(;;)
    hw_sleep();

  return 0 ;
}