示例#1
0
文件: main.c 项目: z13z4ck/hwa
int main ( )
{
  hwa_begin_from_reset();

  hwa( power, HW_RELATIVE(LED1,port), on );

  hwa( configure, LED1,
       mode,	  digital,
       direction, output,
       frequency, 50MHz );

  hwa_commit();

  for(;;) {
    hwa( write, LED1, 1 );
    hwa_commit();

    hw_waste_cycles( PERIOD/2 * HW_DEVICE_HSIHZ );

    hwa( write, LED1, 0 );
    hwa_commit();

    hw_waste_cycles( PERIOD/2 * HW_DEVICE_HSIHZ );
  }
}
示例#2
0
文件: main.c 项目: z13z4ck/hwa
/*
 * Do all the startup-time peripheral initializations: UART (for our
 * debug/test output), and TWI clock.
 */
void
ioinit(void)
{
  hwa_begin_from_reset();
  hwa( configure,   uart0,
       bps,	    9600,
       receiver,    disabled,
       transmitter, enabled  );
  hwa( configure, TWI, sclhz, 100000 );
  hwa_commit();
}
示例#3
0
文件: main.c 项目: z13z4ck/hwa
int main ( )
{
  hwa_begin_from_reset();

  /* Configure the PLL source and multiplier (must be done before it is enabled).
   * Prepare the connection of the sysclk to the pll. The hardware will wait for
   * the PLL to be locked before actually switching.
   */
  hwa( configure,  pll,
       source,     hsi/2,
       multiplier, SYSHZ/(HW_DEVICE_HSIHZ/2) );
  hwa( connect, sysclk, pll );
  hwa_commit();

  /*  Turn the PLL on.
   */
  hwa( turn, pll, on );
  hwa_commit();

  /* Wait for the PLL to be locked.
   */
  while ( ! hw(stat,pll).ready ) {}

  /*  Configure the AHB
   */
  hwa( configure, ahb,
       clock,     sysclk,
       prescaler, SYSHZ/AHBHZ );
  hwa_commit();

  /*  Configure the GPIO pin
   */
  hwa( power, HW_RELATIVE(LED1,port), on );
  hwa_commit();

  hwa( configure, LED1,
       mode,      digital,
       direction, output,
       frequency, 50MHz );
  hwa_commit();

  /*  Configure the system tick timer
   */
  uint32_t onems = hw(read, HW_REGISTER(systick,onems));

  hwa( configure, systick,
       clock,     ahb,
       reload,    ((uint32_t)(PERIOD/2 / 0.001)*onems - 1) & 0xFFFFFF );
  hwa( turn, systick, on );
  hwa( turn, HW_IRQ(systick), on );
  hwa_commit();

  /*  Toggle the LED between sleeps
   */
  for(;;) {
    hw_sleep_until_irq();	// hw_sleep_until_event() is OK too.
    hw( toggle, LED );
  }
}
示例#4
0
文件: main.c 项目: z13z4ck/hwa
int main ( )
{
  hwa_begin_from_reset();

  /*  Start the high-speed external oscillator.
   */
  hwa( power, hse, on );

  /* Configure the PLL source and multiplier (must be done before it is enabled).
   */
  hwa( configure,  pll,
       source,     hse/2,
       multiplier, SYSHZ/HW_DEVICE_HSEHZ );

  /* Prepare the connection of the sysclk to the pll. The hardware will wait for
   * the PLL to be locked before actually switching.
   */
  hwa( connect, sysclk, pll );
  hwa_commit();

  /*  Turn the PLL on.
   */
  hwa( turn, pll, on );
  hwa_commit();

  /* Wait for the PLL to be locked.
   */
  while ( ! hw(stat,pll).ready ) {}

  /* Now that the SYSCLK is driven by the PLL, the HSI can be stopped.
   */
  hwa( power, hsi, off );

  /*  Configure the AHB
   */
  hwa( configure, ahb,
       clock,     sysclk,
       prescaler, SYSHZ/COREHZ );
  hwa_commit();

  /*  Configure the GPIO pin
   */
  hwa( power, HW_RELATIVE(LED1,port), on );
  hwa_commit();

  hwa( configure, LED1,
       mode,      digital,
       direction, output,
       frequency, 50MHz );
  hwa_commit();

  /*  Wait for the HSI to actually stop.
   */
  while ( hw(stat,hsi).ready ) {}

  for(;;) {
    hw( toggle, LED1 );
    hw_waste_cycles( PERIOD*COREHZ/2 );
  }
}
示例#5
0
文件: user.c 项目: duparq/hwa
/*  The UART should be ready for reconfiguration. Configure timer1 too.
 */
void IROM user_init_2 ( )
{
  os_timer_disarm( &os_timer );

  /*  Install user IRQ handlers
   */
  os_set_isr( irq(timer1,irq), ev_timer );
  os_set_isr( irq(timer1,nmi), ev_timer );

  hwa( begin_from_reset );

  hwa( configure, PIN_LED, function, gpio, mode, digital_output );

  /*  Reconfigure the UART
   */
  hwa( configure, gpio15, function, (uart0,txd) );
  hwa( configure, gpio13, function, (uart0,rxd) );

  hwa( configure, uart0,
       baudrate,  115200,
       databits,  8,
       parity,    none,
       stopbits,  1 );

  /*  Configure the timer1 to trigger an interrupt every 10 ms
   */
  hwa( configure, timer1,
       clock,     apb/256,
       direction, down_loop,
       top,       0.5 + 0.1*HW_APBHZ/256,
       action,    irq );

  hwa( commit );

  os_printf("START with user configuration: RXD=GPIO13 TXD=GPIO15\n");

  /*  Trigger a function call every 100 ms (about)
   */
  os_timer_setfn( &os_timer, (os_timer_func_t *)every_100ms, NULL );
  os_timer_arm( &os_timer, 100, 1 );
}
示例#6
0
文件: main.c 项目: z13z4ck/hwa
int
main ( )
{
  /*  Create a HWA context to collect the hardware configuration
   *  Preload this context with RESET values
   */
  hwa_begin_from_reset();

  /*  Configure the software UART
   */
  hwa( configure, UART );

  /*  Configure SPI (SPI master clocked by software over USI)
   */
  hwa( configure, SPI );

  /*  Configure nRF CSN pin
   */
  hwa( configure, NRF_CSN, direction, output );
  hwa( write,  NRF_CSN, 1 );

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

  hw_enable_interrupts();

  /*  Wait for UART synchronization
   */
  while ( !hw(stat,UART).sync ) {}

  /*  Process commands from host
   */
  for(;;) {

    /*	Prompt
     */
    hw( write, UART, '$' );

    /*	Get command
     */
    uint8_t c = hw( read, UART );
    if ( c == '=' ) {

      /*  Number of bytes to send to SPI slave
       */
      uint8_t ntx = hw( read, UART );
      if ( ntx < 1 || ntx > 33 )
	goto error ;

      /*  Number of bytes to send back to talker
       */
      uint8_t nrx = hw( read, UART );
      if ( nrx > 32 )
	goto error ;

      /*  Select SPI slave and send data
       */
      hw( write, NRF_CSN, 0 );
      while ( ntx-- ) {
	c = hw( read, UART );
	hw( write, SPI, c );
      }

      /*  Send reply to talker and deselect SPI slave
       */
      while ( nrx-- ) {
	hw( write, SPI, 0 );
	c = hw( read, SPI );
	hw( write, UART, c );
      }
      hw( write, NRF_CSN, 1 );
    }
    else {
      /*
       *  First byte of command must be '='. Send '!' as error indicator and
       *  wait for '\n' as error acknowledgement.
       */
      do {
      error:
	hw( write, UART, '!' );
	c = hw( read, UART );
      } while ( c != '\n' ) ;
    }
  }
}
示例#7
0
文件: main.c 项目: 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 ;
}
示例#8
0
文件: main.c 项目: 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 ;
}
示例#9
0
文件: main.c 项目: duparq/hwa
int main ( )
{
  hwa( begin_from_reset );

  /*  After RESET, the core is clocked at 8 MHz by the HSI RC oscillator.
   *
   *  * Start the high-speed external oscillator.
   *  * Configure the PLL source and multiplier (must be done before it is
   *    enabled).
   *  * Prepare the connection of the sysclk to the pll. The hardware waits for
   *    the clocks to be stable before switching.
   *
   *  Alternately, we could check ourselves the clocks:
   *    while ( !hw(stat,hse).ready ) {} : waits for the HSE to be stable.
   *    while ( !hw(stat,pll).ready ) {} : waits for the PLL to be locked.
   */
  hwa( power, hse, on );
  hwa( connect, pll, hse );
  hwa( write, pll, (SYSHZ / HW_DEVICE_HSEHZ) );
  hwa( connect, sysclk, pll );
  hwa( commit );

  /*  Now turn the PLL on and the hardware will use it as sysclk when the PLL is
   *  locked.
   */
  hwa( turn, pll, on );
  hwa( commit );

  /*  Power the GPIO port
   */
  hwa( power, (LED1,port), on );

  /*  Configure the GPIO pin
   */
  hwa( configure, LED1,
       mode,      digital_output,
       frequency, lowest );

  hwa( commit );


  for(;;) {
    hw( toggle, LED1 );
    hw_waste_cycles( PERIOD/2 * SYSHZ );
  }
}