示例#1
0
文件: can_bus.c 项目: fschill/MavBoot
void can_bus_init(int channel, can_stream_config_t config) {

	// Setup the generic clock for CAN
	scif_gc_setup(AVR32_SCIF_GCLK_CANIF,
					CAN_GCLK_SOURCE,
					CAN_GCLK_DIV_MODE,
					CAN_GCLK_DIV);
	// Now enable the generic clock
	scif_gc_enable(AVR32_SCIF_GCLK_CANIF);
	 
	// Assign GPIO to CAN. 
	gpio_enable_module_pin(config.can_rx_map.pin, config.can_rx_map.function);
	gpio_enable_module_pin(config.can_tx_map.pin, config.can_tx_map.function);

	// activate control pins for CAN transceiver
	gpio_configure_pin(config.can_shutdown_pin, GPIO_DIR_OUTPUT | GPIO_INIT_LOW); // CAN0 shutdown line
	gpio_configure_pin(config.can_standby_pin, GPIO_DIR_OUTPUT | GPIO_INIT_LOW); // CAN0 standby line

	// Initialize channel 0 
	can_bus_init_hardware(channel, ((uint32_t)&mob_ram_ch[channel][0]), CANIF_CHANNEL_MODE_NORMAL, NULL);

	CAN_stream_rx[channel]=NULL;
	CAN_stream_tx[channel]=NULL;
	
}
int
DeviceCharacterBufferedUsart0::implPortInit(void)
{
  setPortAddress(&AVR32_USART0);

  gpio_enable_module_pin(OS_CFGPIN_DEVICECHARACTERBUFFEREDUSART0_RX_PIN,
      OS_CFGINT_DEVICECHARACTERBUFFEREDUSART0_GPIO_FUNCTION);
  gpio_enable_module_pin(OS_CFGPIN_DEVICECHARACTERBUFFEREDUSART0_TX_PIN,
      OS_CFGINT_DEVICECHARACTERBUFFEREDUSART0_GPIO_FUNCTION);

  usart_options_t usartConfig;
#if defined(OS_INCLUDE_OSDEVICECHARACTER_SETBAUDRATE)
  if(m_baudRate == 0)
    m_baudRate = OS_CFGINT_DEVICECHARACTERBUFFEREDUSART0_BAUD_RATE;
  usartConfig.baudrate =m_baudRate;
#else
  usartConfig.baudrate = OS_CFGINT_DEVICECHARACTERBUFFEREDUSART0_BAUD_RATE;
#endif  /* defined(OS_INCLUDE_OSDEVICECHARACTER_SETBAUDRATE) */
  usartConfig.channelmode = USART_NORMAL_CHMODE;
  usartConfig.charlength = 8;
  usartConfig.paritytype = USART_NO_PARITY;
  usartConfig.stopbits = USART_1_STOPBIT;

  usart_init_rs232(&AVR32_USART0, &usartConfig, OS_CFGLONG_PBA_FREQUENCY_HZ);

  INTC_register_interrupt(DeviceCharacterBufferedUsart0::contextHandler,
      AVR32_USART0_IRQ, OS_CFGINT_DEVICECHARACTERBUFFEREDUSART0_IRQ_PRIORITY);

  // Enable the RX interrupt
  AVR32_USART0.ier = AVR32_USART_IER_RXRDY_MASK;

  // Do not enable TX interrupts

  return 0;
}
示例#3
0
void demo_init_pwma(void)
{
  // Enable the pins driving the LEDs with the PWMA function (functionality E).
  gpio_enable_module_pin(LED0_GPIO, LED0_PWM_FUNCTION);
  gpio_enable_module_pin(LED1_GPIO, LED1_PWM_FUNCTION);
  gpio_enable_module_pin(LED2_GPIO, LED2_PWM_FUNCTION);
  gpio_enable_module_pin(LED3_GPIO, LED3_PWM_FUNCTION);

  //#
  //# Setup and enable the "PWMA and GCLK3 pin" generic clock to 120MHz
  //#
  // Start the RC120M clock
  scif_start_rc120M();
  // Setup the generic clock at 120MHz
  scif_gc_setup(  AVR32_PM_GCLK_PWMA, // The generic clock to setup
                  SCIF_GCCTRL_RC120M, // The input clock source to use for the generic clock
                  false,              // Disable the generic clock divisor
                  0);                 // divfactor = DFLL0freq/gclkfreq
  // Enable the generic clock
  scif_gc_enable(AVR32_PM_GCLK_PWMA);

  //#
  //# Enable all the PWMAs to output to all LEDs. LEDs are default turned on by
  //# setting PWM duty cycles to 0.
  //#
  pwma_config_enable(&AVR32_PWMA,PWMA_OUTPUT_FREQUENCY,PWMA_GCLK_FREQUENCY,0);
  pwma_set_channels_value(&AVR32_PWMA,LED_PWMA_CHANNELS_MASK,PWMA_DUTY_CYCLE_INIT_VAL);
}
示例#4
0
文件: rtouch.c 项目: InSoonPark/asf
static void inline rtouch_tristate_x_surface(void)
{
	gpio_enable_gpio_pin(rtouch_gpio_xmap[1].pin);
	gpio_enable_gpio_pin(rtouch_gpio_xmap[0].pin);

	gpio_disable_pin_pull_up(rtouch_gpio_xmap[0].pin);
	gpio_disable_pin_pull_up(rtouch_gpio_xmap[1].pin);

	/* Enable ADC to control the pins */
	gpio_enable_module_pin(rtouch_gpio_xmap[0].pin,
			rtouch_gpio_xmap[0].function);
	gpio_enable_module_pin(rtouch_gpio_xmap[1].pin,
			rtouch_gpio_xmap[1].function);
}
示例#5
0
/** \brief Register an external interrupt handler for the touch event.
 *
 */
void at42qt1060_register_eic_int(void (*touch_detect_callback)(void))
{
  eic_options_t eic_options[1];

  at42qt1060.touch_detect_callback = touch_detect_callback;

  gpio_enable_module_pin(AT42QT1060_DETECT_PIN, AT42QT1060_EIC_EXTINT_FUNCTION);

  Disable_global_interrupt();

  INTC_register_interrupt(&at42qt1060_detect_eic_int_handler, AT42QT1060_EIC_EXTINT_IRQ,
    AT42QT1060_EIC_EXTINT_LEVEL);

  eic_options[0].eic_mode = EIC_MODE_EDGE_TRIGGERED;
  eic_options[0].eic_level = EIC_EDGE_FALLING_EDGE;
  eic_options[0].eic_async = EIC_SYNCH_MODE;
  eic_options[0].eic_line = AT42QT1060_EIC_LINE;

  eic_init(&AVR32_EIC, &eic_options[0], 1);
  eic_enable_lines(&AVR32_EIC, (1 << eic_options[0].eic_line));
  eic_enable_interrupt_lines(&AVR32_EIC, (1 << eic_options[0].eic_line));

  Enable_global_interrupt();

  return;
}
示例#6
0
/* Enable the specified GCLK output on the nominated pin for the selected board. */
static void local_enable_gclk_on_gpio(volatile avr32_pm_t* pm)
{
#if ( BOARD == STK600_RCUC3L0 ) || ( BOARD == UC3C_EK ) || ( BOARD == STK600_RCUC3D )
	// Note: for UC3L and UC3C devices, the generic clock configurations are handled
	// by the SCIF module.
	/* setup generic clock on Osc0, no divisor */
	scif_gc_setup(EXAMPLE_GCLK_ID, SCIF_GCCTRL_OSC0, AVR32_SCIF_GC_NO_DIV_CLOCK, 0);

	/* Now enable the generic clock */
	scif_gc_enable(EXAMPLE_GCLK_ID);
#else
	/* setup generic clock on Osc0, no divisor */
	pm_gc_setup(pm, EXAMPLE_GCLK_ID, AVR32_GC_USES_OSC, AVR32_GC_USES_OSC0, AVR32_GC_NO_DIV_CLOCK, 0);

	/* Now enable the generic clock */
	pm_gc_enable(pm, EXAMPLE_GCLK_ID);
#endif

	/* Assign a GPIO to generic clock output */
	gpio_enable_module_pin(EXAMPLE_GCLK_PIN, EXAMPLE_GCLK_FUNCTION);

	// Note that gclk0_1 is GPIO pin 51 pb19 on AT32UC3A0512 QFP144.
	// Note that gclk2 is GPIO pin 30 pa30 on AT32UC3B0256 QFP64.
	// Note that gclk1 is GPIO pin 43 pb11 on AT32UC3A3256 QFP144.
	// Note that gclk1 is GPIO pin 6 pa06 on AT32UC3L064 pin 10 on QFP48.
	// Note that gclk0 is GPIO pin 54 pb22 on AT32UC3C0512C QFP144.
	// Note that gclk0 is GPIO pin 9 pa03 on ATUC128D3 QFN64.
}
示例#7
0
/*! \brief Sets up generic clock for the audio codec.
 */
static void init_codec_gclk(void)
{
 // Use PBA for the I2S clock
  const int gc = 0;
  gpio_enable_module_pin(TLV320_PM_GCLK_PIN, TLV320_PM_GCLK_FUNCTION);
  pm_gc_setup(&AVR32_PM, gc, AVR32_GC_USES_OSC, AVR32_GC_USES_OSC0, 0, 0);
  pm_gc_enable(&AVR32_PM, gc);
}
示例#8
0
/*! \brief Sets up generic clock for the audio codec.
 */
static void init_codec_gclk(void)
{
  #if defined(AIC23B_DAC_USE_RX_CLOCK) && AIC23B_DAC_USE_RX_CLOCK == ENABLED
  // GCLK to supply the I2S TX clock
  gpio_enable_module_pin(TLV320_PM_GCLK_RX_PIN, TLV320_PM_GCLK_RX_FUNCTION);
  gpio_enable_module_pin(TLV320_PM_GCLK_PIN, TLV320_PM_GCLK_FUNCTION);
  #else
  // Use PBA for the I2S clock
  const int gc = 0;
  gpio_enable_module_pin(TLV320_PM_GCLK_PIN, TLV320_PM_GCLK_FUNCTION);
    #if AIC23B_MCLK_HZ == 11289600
  pm_gc_setup(&AVR32_PM, gc, AVR32_GC_USES_OSC, AVR32_GC_USES_OSC1, 0, 0);
    #elif AIC23B_MCLK_HZ == 12000000
  pm_gc_setup(&AVR32_PM, gc, AVR32_GC_USES_OSC, AVR32_GC_USES_OSC0, 0, 0);
    #endif
  pm_gc_enable(&AVR32_PM, gc);
  #endif
}
示例#9
0
int gpio_enable_module(const gpio_map_t gpiomap, uint32_t size)
{
  int status = GPIO_SUCCESS;
  uint32_t i;

  for (i = 0; i < size; i++)
  {
    status |= gpio_enable_module_pin(gpiomap->pin, gpiomap->function);
    gpiomap++;
  }

  return status;
}
示例#10
0
static void local_start_gc()
{
  // Setup gc on DFLL; the target frequency is 12MHz => divide the DFLL frequency
  // by 2 (== EXAMPLE_FDFLL_HZ / EXAMPLE_GCLK_FREQ_HZ).
  scif_gc_setup(EXAMPLE_GCLK_ID, SCIF_GCCTRL_DFLL0, AVR32_GC_DIV_CLOCK,
                TARGET_DFLL_FREQ_HZ/EXAMPLE_GCLK_FREQ_HZ);

  // Now enable the generic clock
  scif_gc_enable(EXAMPLE_GCLK_ID);

  /* Assign a GPIO to generic clock output */
  gpio_enable_module_pin(EXAMPLE_GCLK_PIN, EXAMPLE_GCLK_FUNCTION);
  // Note that gclk1 is GPIO pin 6 pa06 on AT32UC3L064 pin 10 on QFP48.
}
示例#11
0
/* \brief Set-up a generic clock to run from RC120M and output it to a gpio pin.
 *
 */
static void local_start_gc(void)
{
  // Note: for UC3L devices, the generic clock configurations are handled by the
  // SCIF module.
  // Setup gc to use RC120M as source clock, divisor enabled, apply a division factor.
  // Since the RC120M frequency is 120MHz, set the division factor to 4 to have a
  // gclk frequency of 30MHz.
  scif_gc_setup(EXAMPLE_GCLK_ID, SCIF_GCCTRL_RC120M, AVR32_SCIF_GC_DIV_CLOCK, 4);

  // Now enable the generic clock
  scif_gc_enable(EXAMPLE_GCLK_ID);

  // Set the GCLOCK function to the GPIO pin
  gpio_enable_module_pin(EXAMPLE_GCLK_PIN, EXAMPLE_GCLK_FUNCTION);
}
示例#12
0
int main(void)
{

	sysclk_init();
	board_init();

	genclk_enable_config(GCLK_ID, GCLK_SOURCE, GCLK_DIV);

	/* Enable GPIO Alternate to output GCLK*/
	gpio_enable_module_pin(GCLK_PIN,GCLK_FUNCTION);

	while (1) {
		/* Do nothing */
	}
}
示例#13
0
/*!
 *  \brief Init the temperature channel.
 *
 *  \return true upon success, false if error.
 */
bool b_temperature_init ( void )
{
portCHAR token[6];
portCHAR * unit;

   // Get the xCFGMutex.
   if( pdTRUE == x_supervisor_SemaphoreTake( xCFGMutex, 0 ) )
   {
       // get the field
       if (config_file_get_value(SENSOR_TEMP_CONFIG_FILE, "alarm" , token) >= 0)
       {
         // update value
         if (!strcmp(token, "on"))
         {
           b_temp_alarm = pdTRUE;
         }
       }
       if (config_file_get_value(SENSOR_TEMP_CONFIG_FILE, "min" , token) >= 0)
       {
         unit = strpbrk(token , "C");
         if (unit != NULL)
         {
           *unit = '\0';
         }
         l_temp_min = atol(token);
       }
       if (config_file_get_value(SENSOR_TEMP_CONFIG_FILE, "max" , token) >= 0)
       {
         unit = strpbrk(token , "C");
         if (unit != NULL)
         {
           *unit = '\0';
         }
         l_temp_max = atol(token);
       }
       if (config_file_get_value(SENSOR_TEMP_CONFIG_FILE, "lograte" , token) >= 0)
       {
         ul_temp_lograte = atoi(token);
       }
     // Release the xCFGMutex.
     x_supervisor_SemaphoreGive( xCFGMutex );
   }
   /* enable pin for sensor */
   gpio_enable_module_pin( ADC_TEMPERATURE_PIN , ADC_TEMPERATURE_FUNCTION );

   return (true);
}
示例#14
0
/*!
 *  \brief Init the potentiometer channel.
 *
 *  \return true upon success, false if error.
 */
bool b_potentiometer_init ( void )
{
portCHAR token[6];
portCHAR * percent;

   // Get the xCFGMutex.
   if( pdTRUE == x_supervisor_SemaphoreTake( xCFGMutex, 0 ) )
   {
       // get the field
       if (config_file_get_value(SENSOR_POT_CONFIG_FILE, "alarm" , token) >= 0)
       {
         // update value
         if (!strcmp(token, "on"))
         {
           b_pot_alarm = pdTRUE;
         }
       }
       if (config_file_get_value(SENSOR_POT_CONFIG_FILE, "min" , token) >= 0)
       {
         percent = strpbrk(token , "%");
         if (percent != NULL)
         {
           *percent = '\0';
         }
         sscanf(token, "%u", &ul_pot_min);
       }
       if (config_file_get_value(SENSOR_POT_CONFIG_FILE, "max" , token) >= 0)
       {
         percent = strpbrk(token , "%");
         if (percent != NULL)
         {
           *percent = '\0';
         }
         sscanf(token, "%u", &ul_pot_max);
       }
       if (config_file_get_value(SENSOR_POT_CONFIG_FILE, "lograte" , token) >= 0)
       {
         sscanf(token, "%u", &ul_pot_lograte);
       }
     // Release the xCFGMutex.
     x_supervisor_SemaphoreGive( xCFGMutex );
   }
   /* enable pin for sensor */
   gpio_enable_module_pin( ADC_POTENTIOMETER_PIN , ADC_POTENTIOMETER_FUNCTION );

   return (true);
}
示例#15
0
文件: main.c 项目: gameswarp/Arduino
void tc_init(void)
{
	  // The timer/counter instance and channel number are used in several functions.
	  // It's defined as local variable for ease-of-use causes and readability.
	  volatile avr32_tc_t *tc = WIFI_TC;

	  // Options for waveform genration.
	  tc_waveform_opt_t waveform_opt =
	  {
	    .channel  = WIFI_TC_CHANNEL_ID,        // Channel selection.

	    .bswtrg   = TC_EVT_EFFECT_NOOP,           // Software trigger effect on TIOB.
	    .beevt    = TC_EVT_EFFECT_NOOP,           // External event effect on TIOB.
	    .bcpc     = TC_EVT_EFFECT_NOOP,           // RC compare effect on TIOB.
	    .bcpb     = TC_EVT_EFFECT_NOOP,           // RB compare effect on TIOB.

	    .aswtrg   = TC_EVT_EFFECT_NOOP,           // Software trigger effect on TIOA.
	    .aeevt    = TC_EVT_EFFECT_NOOP,           // External event effect on TIOA.
	    .acpc     = TC_EVT_EFFECT_TOGGLE,         // RC compare effect on TIOA: toggle.
	    .acpa     = TC_EVT_EFFECT_TOGGLE,         // RA compare effect on TIOA: toggle (other possibilities are none, set and clear).

	    .wavsel   = TC_WAVEFORM_SEL_UP_MODE_RC_TRIGGER,// Waveform selection: Up mode with automatic trigger(reset) on RC compare.
	    .enetrg   = FALSE,                        // External event trigger enable.
	    .eevt     = TC_EXT_EVENT_SEL_TIOB_INPUT,  // External event selection.
	    .eevtedg  = TC_SEL_NO_EDGE,               // External event edge selection.
	    .cpcdis   = FALSE,                        // Counter disable when RC compare.
	    .cpcstop  = FALSE,                        // Counter clock stopped with RC compare.

	    .burst    = TC_BURST_NOT_GATED,           // Burst signal selection.
	    .clki     = TC_CLOCK_RISING_EDGE,         // Clock inversion.
	    .tcclks   = TC_CLOCK_SOURCE_TC2           // Internal source clock 3, connected to fPBA / 2.
	  };

	  // Assign I/O to timer/counter channel pin & function.
	  gpio_enable_module_pin(WIFI_TC_CHANNEL_PIN, WIFI_TC_CHANNEL_FUNCTION);

	  // Initialize the timer/counter.
	  tc_init_waveform(tc, &waveform_opt);  // Initialize the timer/counter waveform.

	  // Set the compare triggers.
	  tc_write_ra(tc, WIFI_TC_CHANNEL_ID, 0x01A4);     // Set RA value.
	  tc_write_rc(tc, WIFI_TC_CHANNEL_ID, 0x0348);     // Set RC value.

	  // Start the timer/counter.
	  tc_start(tc, WIFI_TC_CHANNEL_ID);

}
示例#16
0
void Actividad3(void){
	
pm_switch_to_osc0(&AVR32_PM,FOSC0,OSC0_STARTUP);

Disable_global_interrupt();
//! Structure holding the configuration parameters of the EIC module.
eic_options_t eic_options[2];

// Enable edge-triggered interrupt.
eic_options[0].eic_mode  = EIC_MODE_EDGE_TRIGGERED;
// Interrupt will trigger on falling edge (this is a must-do for the keypad scan
// feature if the chosen mode is edge-triggered).
eic_options[0].eic_edge  = EIC_EDGE_RISING_EDGE;
// Initialize in synchronous mode : interrupt is synchronized to the clock
eic_options[0].eic_async = EIC_SYNCH_MODE;
// Set the interrupt line number.
eic_options[0].eic_line  = QT1081_EIC_EXTINT_INT;


INTC_init_interrupts();
    /* Register the EXTINT1 interrupt handler to the interrupt controller
     */
	INTC_register_interrupt(&touch_button_isr, QT1081_EIC_EXTINT_IRQ, AVR32_INTC_INT0);
 // Init the EIC controller with the options
 eic_init(&AVR32_EIC, eic_options, 1);
 // Enable the EIC lines.
 eic_enable_lines(&AVR32_EIC, (1<<eic_options[0].eic_line));
 // Enable the interrupt for each EIC line.
 eic_enable_interrupt_lines(&AVR32_EIC, (1<<eic_options[0].eic_line));
 
 gpio_enable_module_pin( QT1081_EIC_EXTINT_PIN, QT1081_EIC_EXTINT_FUNCTION);

 Enable_global_interrupt();
 
 while (1){
	 gpio_tgl_gpio_pin(LED0_GPIO);
	 gpio_tgl_gpio_pin(LED1_GPIO);
	 gpio_tgl_gpio_pin(LED2_GPIO);
	 gpio_tgl_gpio_pin(LED3_GPIO);
	 delay_s(100);

 }
 

}
示例#17
0
/* \brief Set-up a generic clock to run from a high-frequency clock and output it to a gpio pin.
 *
 */
static void local_start_gc(void)
{
#if BOARD == STK600_RCUC3L0 || BOARD == UC3L_EK
  // Note: for UC3L devices, the generic clock configurations are handled by the
  // SCIF module.
  // Setup gc to use the DFLL0 as source clock, divisor enabled, apply a division factor.
  // Since the DFLL0 frequency is 96MHz, set the division factor to 2 to have a
  // gclk frequency of 48MHz.
  scif_gc_setup(EXAMPLE_GCLK_ID, SCIF_GCCTRL_DFLL0, AVR32_GC_DIV_CLOCK, 2);

  /* Now enable the generic clock */
  scif_gc_enable(EXAMPLE_GCLK_ID);
#elif BOARD == UC3C_EK || BOARD == STK600_RCUC3D
  // Note: for UC3 C, D and L series, the generic clock configurations are handled by the
  // SCIF module.
  /* setup gc on Osc0, no divisor */
  scif_gc_setup(EXAMPLE_GCLK_ID, SCIF_GCCTRL_PLL0, AVR32_SCIF_GC_NO_DIV_CLOCK, 0);

  /* Now enable the generic clock */
  scif_gc_enable(EXAMPLE_GCLK_ID);
#else
  volatile avr32_pm_t* pm = &AVR32_PM;
  /* Setup generic clock on PLL0, with Osc0/PLL0, no divisor */
  /*
  void pm_gc_setup(volatile avr32_pm_t* pm,
                  unsigned int gc,
                  unsigned int osc_or_pll, // Use Osc (=0) or PLL (=1)
                  unsigned int pll_osc, // Sel Osc0/PLL0 or Osc1/PLL1
                  unsigned int diven,
                  unsigned int div) {
  */
  pm_gc_setup(pm,
              EXAMPLE_GCLK_ID,
              1,  // Use Osc (=0) or PLL (=1), here PLL
              0,  // Sel Osc0/PLL0 or Osc1/PLL1
              0,  // disable divisor
              0); // no divisor

  /* Enable Generic clock */
  pm_gc_enable(pm, EXAMPLE_GCLK_ID);
#endif
  /* Set the GCLOCK function to the GPIO pin */
  gpio_enable_module_pin(EXAMPLE_GCLK_PIN, EXAMPLE_GCLK_FUNCTION);
}
/*! \brief Set-up a generic clock at 32kz with the OSC32 as a source, output the
 * generic clock to a pin.
 *
 */
static void local_start_gc(void)
{
  scif_gclk_opt_t gclkOpt = {SCIF_GCCTRL_OSC32K, 0, 0};
  volatile int i;


  if(scif_start_gclk(EXAMPLE_GCLK_ID, &gclkOpt))
  {   // Error
    while(1)
    {
      gpio_tgl_gpio_pin(LED3_GPIO);
      for(i=1000; i; i--);
    }
  }

  // Assign a GPIO to generic clock output
  gpio_enable_module_pin(EXAMPLE_GCLK_PIN, EXAMPLE_GCLK_FUNCTION);
  // Note that gclk1 is GPIO pin 6 pa06 on AT32UC3L064 pin 10 on QFP48.
}
示例#19
0
///< Enable/Disable the clock to the ADC
void ads1274_ADC_switch_clock(bool on_off) 
{
	if (on_off == true) 
	{
		gpio_enable_module_pin(AVR32_SCIF_GCLK_1_1_PIN, AVR32_SCIF_GCLK_1_1_FUNCTION);	

		gpio_configure_pin(ADC_CLKDIV,GPIO_DIR_OUTPUT | GPIO_INIT_HIGH);	
		
		//scif_gc_setup(AVR32_SCIF_GCLK_GCLK0PIN, SCIF_GCCTRL_CPUCLOCK, 1, 1);
		//scif_gc_enable(AVR32_SCIF_GCLK_GCLK0PIN);
		genclk_config_defaults(&gcfg, AVR32_SCIF_GCLK_GCLK1PIN);
		genclk_config_set_source(&gcfg, GENCLK_SRC_PLL1);
		genclk_config_set_divider(&gcfg, 2);
		genclk_enable(&gcfg, AVR32_SCIF_GCLK_GCLK1PIN);
	} 
	else 
	{
		genclk_disable(AVR32_SCIF_GCLK_GCLK1PIN);	
	}
}
示例#20
0
/*! \brief Enable an EIC interrupt line.
 *
 * This routine maps a GPIO pin and peripheral function to a specified EIC line.
 *
 * \param eic_line      Line number to enable
 * \param eic_pin       GPIO module pin
 * \param eic_func      GPIO module function
 * \param eic_irq       IRQ of the interrupt handler
 * \param eic_handler   Interrupt handler to register
 */
static void eic_irq_connect(uint32_t eic_line, uint32_t eic_pin,
		uint32_t eic_func, uint32_t eic_irq, __int_handler eic_handler)
{
	eic_options_t const eic_options = {
		.eic_line   = eic_line,
		.eic_mode   = EIC_MODE_EDGE_TRIGGERED,
		.eic_edge   = EIC_EDGE_RISING_EDGE,
		.eic_level  = EIC_LEVEL_HIGH_LEVEL,
		.eic_filter = EIC_FILTER_ENABLED,
		.eic_async  = EIC_ASYNCH_MODE
	};

	sysclk_enable_pba_module(SYSCLK_EIC);

	gpio_enable_module_pin(eic_pin, eic_func);
	irq_register_handler(eic_handler, eic_irq, 0);

	eic_init(&AVR32_EIC, &eic_options, 1);
	eic_enable_line(&AVR32_EIC, eic_line);
	eic_enable_interrupt_line(&AVR32_EIC, eic_line);
}
示例#21
0
int PWM_prog(void) {
	board_init();
	unsigned int channel_id = 3;
	avr32_pwm_channel_t pwm_channel = { .ccnt = 0 }; // One	channel config.

	gpio_enable_module_pin(EXAMPLE_PWM_PIN,
	EXAMPLE_PWM_FUNCTION);
	pwm_channel.CMR.cpre = AVR32_PWM_CPRE_MCK_DIV_256; //	Channel prescaler.

	pwm_channel.cdty = 1; // Channel duty cycle, should be <	CPRD.

	pwm_channel.cprd = 20; // Channel period.
	// With these settings, the output waveform period will be :
	// (115200/256)/20 == 22.5Hz == (MCK/prescaler)/period, with	MCK == 115200Hz,

	// prescaler == 256, period == 20.
	pwm_channel_init(channel_id, &pwm_channel); // Set channel	configuration to channel 3.
	pwm_start_channels(1 << channel_id); // Start channel 3.
	while(1){
	}
	return 0;
}
示例#22
0
/*! \brief Sets up generic clock for the audio codec.
 */
static void init_codec_gclk(void)
{
#if(DEFAULT_DACS == AUDIO_MIXER_DAC_ABDAC)
    // Configure the ABDAC generic clock
    // We do not activate it here since this is done by activating the
    // ABDAC in the driver.
    pm_gc_setup(&AVR32_PM, AVR32_PM_GCLK_ABDAC,
                AVR32_GC_USES_OSC, AVR32_GC_USES_OSC1, 0, 0);

#elif(DEFAULT_DACS == AUDIO_MIXER_DAC_AIC23B)
    int gc = 0;
    gpio_enable_module_pin(TLV320_PM_GCLK_PIN, TLV320_PM_GCLK_FUNCTION);

# if(AIC23B_MCLK_HZ == 11289600)
    pm_gc_setup(&AVR32_PM, gc, AVR32_GC_USES_OSC, AVR32_GC_USES_OSC1, 0, 0);
# elif(AIC23B_MCLK_HZ == 12000000)
    pm_gc_setup(&AVR32_PM, gc, AVR32_GC_USES_OSC, AVR32_GC_USES_OSC0, 0, 0);
# else
#   error Wrong Master clock configuration
# endif

    pm_gc_enable(&AVR32_PM, gc);
#endif
}
int main(void)
{
	enum sleepmgr_mode      current_sleep_mode = SLEEPMGR_ACTIVE;
	uint32_t                ast_counter = 0;

	/*
	 * Initialize the synchronous clock system to the default configuration
	 * set in conf_clock.h.
	 * \note All non-essential peripheral clocks are initially disabled.
	 */
	sysclk_init();

	/*
	 * Initialize the resources used by this example to the default
	 * configuration set in conf_board.h
	 */
	board_init();

	/*
	 * Turn the activity status LED on to inform the user that the device
	 * is active.
	 */
	gpio_set_pin_low(LED_ACTIVITY_STATUS_PIN);

	/*
	 * Configure pin change interrupt for asynchronous wake-up (required to
	 * wake up from the STATIC sleep mode) and enable the EIC clock.
	 *
	 * First, enable the clock for the EIC module.
	 */
	sysclk_enable_pba_module(SYSCLK_EIC);
	/*
	 * Map the interrupt line to the GPIO pin with the right peripheral
	 * function.
	 */
	gpio_enable_module_pin(WAKE_BUTTON_EIC_PIN, WAKE_BUTTON_EIC_FUNCTION);
	/*
	 * Enable the internal pull-up resistor on that pin (because the EIC is
	 * configured such that the interrupt will trigger on low-level, see
	 * eic_options.eic_level).
	 */
	gpio_enable_pin_pull_up(WAKE_BUTTON_EIC_PIN);
	// Init the EIC controller with the options
	eic_init(&AVR32_EIC, &eic_options, sizeof(eic_options) /
			sizeof(eic_options_t));
	// Enable External Interrupt Controller Line
	eic_enable_line(&AVR32_EIC, WAKE_BUTTON_EIC_LINE);

	// Enable the AST clock.
	sysclk_enable_pba_module(SYSCLK_AST);
	// Initialize the AST in Counter mode
	ast_init_counter(&AVR32_AST, AST_OSC_RC, AST_PSEL_RC_1_76HZ,
			ast_counter);
	/*
	 * Configure the AST to wake up the CPU when the counter reaches the
	 * selected alarm0 value.
	 */
	AVR32_AST.WER.alarm0 = 1;
	// Enable the AST
	ast_enable(&AVR32_AST);

	// Initialize the sleep manager, lock initial mode.
	sleepmgr_init();
	sleepmgr_lock_mode(current_sleep_mode);

	while (1) {
		ast_counter = ast_get_counter_value(&AVR32_AST);
		// disable alarm 0
		ast_disable_alarm0(&AVR32_AST);
		// Set Alarm to current time + (6/1.76) seconds
		ast_counter += 6;
		ast_set_alarm0_value(&AVR32_AST, ast_counter);
		// Enable alarm 0
		ast_enable_alarm0(&AVR32_AST);

		/*
		 * Turn the activity status LED off to inform the user that the
		 * device is in a sleep mode.
		 */
		gpio_set_pin_high(LED_ACTIVITY_STATUS_PIN);

		/*
		 * Go to sleep in the deepest allowed sleep mode (i.e. no
		 * deeper than the currently locked sleep mode).
		 */
		sleepmgr_enter_sleep();

		/*
		 * Turn the activity status LED on to inform the user that the
		 * device is active.
		 */
		gpio_set_pin_low(LED_ACTIVITY_STATUS_PIN);

		// After wake up, clear the Alarm0
		AVR32_AST.SCR.alarm0 = 1;

		// Unlock the current sleep mode.
		sleepmgr_unlock_mode(current_sleep_mode);

		// Add a 3s delay
		cpu_delay_ms(3000, sysclk_get_cpu_hz());

		// Clear the External Interrupt Line (in case it was raised).
		eic_clear_interrupt_line(&AVR32_EIC, WAKE_BUTTON_EIC_LINE);

		// Lock the next sleep mode.
		++current_sleep_mode;
		if ((current_sleep_mode >= SLEEPMGR_NR_OF_MODES)
#if UC3L && (BOARD == UC3L_EK)
		/* Note concerning the SHUTDOWN sleep mode: the shutdown sleep
		 * mode can only be used when the UC3L supply mode is the 3.3V
		 * Supply Mode with 1.8V Regulated I/O Lines. That is not how
		 * the UC3L is powered on the ATUC3L-EK so the SHUTDOWN mode
		 * cannot be used on this board. Thus we skip this sleep mode
		 * in this example for this board.
		 */
			|| (current_sleep_mode == SLEEPMGR_SHUTDOWN)
#endif
			) {
			current_sleep_mode = SLEEPMGR_ACTIVE;
		}

		sleepmgr_lock_mode(current_sleep_mode);
	}
}
void init_PWM(int velocidad, int direccion){
	int auxiliar;
	switch(velocidad){
		case 9:
			auxiliar = 2;
			break;
		case 8:
			auxiliar = 4;
			break;
		case 7:
			auxiliar = 6;
			break;
		case 6:
			auxiliar = 8;
			break;
		case 5:
			auxiliar = 10;
			break;
		case 4:
			auxiliar = 12;
			break;
		case 3:
			auxiliar = 14;
			break;
		case 2:
			auxiliar = 16;
			break;
		case 1:
			auxiliar = 18;
			break;
	}//SWITCH
	pwm_opt_t pwm_opt =
	{
		.diva = AVR32_PWM_DIVA_CLK_OFF,
		.divb = AVR32_PWM_DIVB_CLK_OFF,
		.prea = AVR32_PWM_PREA_MCK,
		.preb = AVR32_PWM_PREB_MCK
	};
	
	avr32_pwm_channel_t pwm_channel = { .ccnt = 0 };
		pwm_channel.cdty = auxiliar; /* Channel duty cycle, should be < CPRD. */
		pwm_channel.cprd = 20; /* Channel period. */
		pwm_channel.cupd = 0; /* Channel update is not used here. */
		pwm_channel.CMR.calg = PWM_MODE_LEFT_ALIGNED; /* Channel mode. */
		pwm_channel.CMR.cpol = PWM_POLARITY_LOW;      /* Channel polarity. */
		pwm_channel.CMR.cpd = PWM_UPDATE_DUTY;        /* Not used the first time. */
		pwm_channel.CMR.cpre = AVR32_PWM_CPRE_MCK_DIV_256; /* Channel prescaler. */
		
		gpio_enable_module_pin(PWM_PIN_3, PWM_PIN_Function);
		gpio_enable_module_pin(PWM_PIN_1, PWM_PIN_Function);
		pwm_init(&pwm_opt);
		if(direccion == 1){//FORWARD
			pwm_channel_init(PWM_ID_3, &pwm_channel);
			pwm_start_channels(1 << PWM_ID_3);

		}
		if(direccion == 0){//REVERSE
			pwm_channel_init(PWM_ID_1, &pwm_channel);
			pwm_start_channels(1 << PWM_ID_1);
		}
}
void update_PWM(int velocidad, int direccion){
	int auxiliar;
	switch(velocidad){
		case 9:
		auxiliar = 2;
		break;
		case 8:
		auxiliar = 4;
		break;
		case 7:
		auxiliar = 6;
		break;
		case 6:
		auxiliar = 8;
		break;
		case 5:
		auxiliar = 10;
		break;
		case 4:
		auxiliar = 12;
		break;
		case 3:
		auxiliar = 14;
		break;
		case 2:
		auxiliar = 16;
		break;
		case 1:
		auxiliar = 18;
		break;
	}//SWITCH
		avr32_pwm_channel_t pwm_channel = { .ccnt = 0 };
		pwm_channel.cdty = auxiliar; /* Channel duty cycle, should be < CPRD. */
		pwm_channel.cprd = 20; /* Channel period. */
		pwm_channel.cupd = 0; /* Channel update is not used here. */
		pwm_channel.CMR.calg = PWM_MODE_LEFT_ALIGNED; /* Channel mode. */
		pwm_channel.CMR.cpol = PWM_POLARITY_LOW;      /* Channel polarity. */
		pwm_channel.CMR.cpd = PWM_UPDATE_DUTY;        /* Not used the first time. */
		pwm_channel.CMR.cpre = AVR32_PWM_CPRE_MCK_DIV_256; /* Channel prescaler. */
	
	if(direccion == 1){//FORWARD
		pwm_stop_channels(1<<PWM_ID_1);
		pwm_stop_channels(1<<PWM_ID_3);
		pwm_channel_init(PWM_ID_3, &pwm_channel);
		pwm_start_channels(1 << PWM_ID_3);
		
	}
	if(direccion == 0){//REVERSE
		pwm_stop_channels(1<<PWM_ID_1);
		pwm_stop_channels(1<<PWM_ID_3);
		pwm_channel_init(PWM_ID_1, &pwm_channel);
		pwm_start_channels(1 << PWM_ID_1);
	}
	bandera = 0;
}
static void handler_interrupt(void){
	if (gpio_get_pin_interrupt_flag(GPIO_JOYSTICK_UP)){
		direccion = 1;
		gpio_clear_pin_interrupt_flag(GPIO_JOYSTICK_UP);
	}
	if (gpio_get_pin_interrupt_flag(GPIO_JOYSTICK_DOWN)){
		direccion = 0;
		gpio_clear_pin_interrupt_flag(GPIO_JOYSTICK_DOWN);
	}
	bandera = 1;
}
void init_INTC(void){
	gpio_enable_pin_interrupt(GPIO_JOYSTICK_UP , GPIO_FALLING_EDGE);
	gpio_enable_pin_interrupt(GPIO_JOYSTICK_DOWN , GPIO_FALLING_EDGE);
	Disable_global_interrupt();
	INTC_init_interrupts();
	  INTC_register_interrupt( &handler_interrupt, AVR32_GPIO_IRQ_0 + (GPIO_JOYSTICK_UP/8), AVR32_INTC_INT1);
	  INTC_register_interrupt( &handler_interrupt, AVR32_GPIO_IRQ_0 + (GPIO_JOYSTICK_DOWN/8), AVR32_INTC_INT1);
	Enable_global_interrupt();
}
示例#25
0
/**
 * Setup TWI
 */
void twi_setup(void) {
    gpio_enable_module_pin(TWI_SCL, AVR32_TWI_SCL_0_0_FUNCTION);
    gpio_enable_module_pin(TWI_DATA, AVR32_TWI_SDA_0_0_FUNCTION);
    twiInit();
}
示例#26
0
///< Initializes ADC (configures Pins, starts Clock, sets defaults)
void ads1274_init_DAC(void) 
{
	function_generator = NULL;
	
	///< set mode to "high resolution"
	gpio_configure_pin(ADC_MODE0,GPIO_DIR_OUTPUT | GPIO_INIT_HIGH);	
	gpio_configure_pin(ADC_MODE1,GPIO_DIR_OUTPUT | GPIO_INIT_LOW);	
	
	///< set Format to Fixed-position TDM via SPI
	gpio_configure_pin(ADC_FORMAT0,GPIO_DIR_OUTPUT | GPIO_INIT_HIGH);	
	gpio_configure_pin(ADC_FORMAT1,GPIO_DIR_OUTPUT | GPIO_INIT_LOW);	
	gpio_configure_pin(ADC_FORMAT2,GPIO_DIR_OUTPUT | GPIO_INIT_LOW);	
	
	///< configure the four channels
	gpio_configure_pin(ADC_PWDN1,GPIO_DIR_OUTPUT | GPIO_INIT_HIGH);	
	gpio_configure_pin(ADC_PWDN2,GPIO_DIR_OUTPUT | GPIO_INIT_HIGH);	
	gpio_configure_pin(ADC_PWDN3,GPIO_DIR_OUTPUT | GPIO_INIT_HIGH);	
	gpio_configure_pin(ADC_PWDN4,GPIO_DIR_OUTPUT | GPIO_INIT_HIGH);	

	//gpio_configure_pin(AVR32_TC1_B0_0_0_PIN,GPIO_DIR_OUTPUT | GPIO_INIT_HIGH);	
	//gpio_configure_pin(AVR32_PIN_PC19, GPIO_DIR_OUTPUT| GPIO_INIT_HIGH);	

	ads1274_ADC_switch_clock(true);	
	
	//tc_init_waveform(tc, &waveform_opt);  ///< Initialize the timer/counter .

	///< Set the compare triggers.
	//tc_write_rb(tc, EXAMPLE_TC_CHANNEL_ID, 0x1);     ///< Set RA value.
	//tc_write_rc(tc, EXAMPLE_TC_CHANNEL_ID, 0x2);     ///< Set RC value.
	
	///< Start the timer/counter.
	//tc_start(tc, EXAMPLE_TC_CHANNEL_ID);
	
	///< Enable edge-triggered interrupt.
	eic_options[0].eic_mode   = EIC_MODE_EDGE_TRIGGERED;
	///< Interrupt will trigger on falling edge.
	eic_options[0].eic_edge  = EIC_EDGE_FALLING_EDGE;
	///< Initialize in synchronous mode : interrupt is synchronized to the clock
	eic_options[0].eic_async  = EIC_SYNCH_MODE;
	///< Set the interrupt line number.
	eic_options[0].eic_line   = EXT_NMI;
	
	gpio_enable_module_pin(AVR32_EIC_EXTINT_0_1_PIN, AVR32_EIC_EXTINT_0_1_FUNCTION);
	
	///<Disable_global_interrupt();
	///< Initialize interrupt vectors.
	
	eic_init(&AVR32_EIC, eic_options, 1);

	///<INTC_init_interrupts();
	///< initialize SPI0 interface
	spi_buffered_init(&AVR32_SPI0, ADC_SPI_INDEX);
	spi_buffered_init_DMA(0, 12);
	spi_buffered_set_callback(ADC_SPI_INDEX, &process_data);
	
	///< Register the EIC interrupt handlers to the interrupt controller.
	//INTC_register_interrupt(&eic_int_handler1, AVR32_EIC_IRQ_1, AVR32_INTC_INT1);
	///< Enable the chosen lines and their corresponding interrupt feature.
	eic_enable_line(&AVR32_EIC, eic_options[0].eic_line);
	eic_enable_interrupt_line(&AVR32_EIC, eic_options[0].eic_line);
	
	///< Enable_global_interrupt();
	eic_clear_interrupt_line(&AVR32_EIC, EXT_NMI);
	
	///< activate sync and clkdiv
	gpio_configure_pin(ADC_CLKDIV,GPIO_DIR_OUTPUT | GPIO_INIT_HIGH);	
}
示例#27
0
//!
//! @brief This function initializes the hardware/software resources
//! required for device CDC task.
//!
void AK5394A_task_init(void)
{
	// Set up CS4344
	// Set up GLCK1 to provide master clock for CS4344
	gpio_enable_module_pin(GCLK1, GCLK1_FUNCTION);	// for DA_SCLK
													// LRCK is SCLK / 64 generated by TX_SSC
													// so SCLK of 6.144Mhz ===> 96khz

	pm_gc_setup(&AVR32_PM, AVR32_PM_GCLK_GCLK1, // gc
					  0,                  // osc_or_pll: use Osc (if 0) or PLL (if 1)
					  1,                  // pll_osc: select Osc0/PLL0 or Osc1/PLL1
					  1,                  // diven - enabled
					  0);                 // divided by 2.  Therefore GCLK1 = 6.144Mhz
	pm_gc_enable(&AVR32_PM, AVR32_PM_GCLK_GCLK1);

	pm_enable_osc1_ext_clock(&AVR32_PM);	// OSC1 is clocked by 12.288Mhz Osc
												// from AK5394A Xtal Oscillator
	pm_enable_clk1(&AVR32_PM, OSC1_STARTUP);

	// Set up AK5394A
	gpio_clr_gpio_pin(AK5394_RSTN);		// put AK5394A in reset
	gpio_clr_gpio_pin(AK5394_DFS0);		// L L  -> 48khz
	gpio_clr_gpio_pin(AK5394_DFS1);
	gpio_set_gpio_pin(AK5394_HPFE);		// enable HP filter
	gpio_clr_gpio_pin(AK5394_ZCAL);		// use VCOML and VCOMR to cal
	gpio_set_gpio_pin(AK5394_SMODE1);	// SMODE1 = H for Master i2s
	gpio_set_gpio_pin(AK5394_SMODE2);	// SMODE2 = H for Master/Slave i2s

    gpio_set_gpio_pin(AK5394_RSTN);		// start AK5394A
    while (gpio_get_pin_value(AK5394_CAL)); // wait till CAL goes low

		// Assign GPIO to SSC.
	  gpio_enable_module(SSC_GPIO_MAP, sizeof(SSC_GPIO_MAP) / sizeof(SSC_GPIO_MAP[0]));
	  gpio_enable_pin_glitch_filter(SSC_RX_CLOCK);
	  gpio_enable_pin_glitch_filter(SSC_RX_DATA);
	  gpio_enable_pin_glitch_filter(SSC_RX_FRAME_SYNC);
	  gpio_enable_pin_glitch_filter(SSC_TX_CLOCK);
	  gpio_enable_pin_glitch_filter(SSC_TX_DATA);
	  gpio_enable_pin_glitch_filter(SSC_TX_FRAME_SYNC);

	  current_freq.frequency = 96000;

	  // set up SSC
	  ssc_i2s_init(ssc, 96000, 24, 32, SSC_I2S_MODE_STEREO_OUT_STEREO_IN, FPBA_HZ);

	  // set up PDCA
	  // In order to avoid long slave handling during undefined length bursts (INCR), the Bus Matrix
	  // provides specific logic in order to re-arbitrate before the end of the INCR transfer.
	  //
	  // HSB Bus Matrix: By default the HSB bus matrix mode is in Undefined length burst type (INCR).
	  // Here we have to put in single access (the undefined length burst is treated as a succession of single
	  // accesses, allowing re-arbitration at each beat of the INCR burst.
	  // Refer to the HSB bus matrix section of the datasheet for more details.
	  //
	  // HSB Bus matrix register MCFG1 is associated with the CPU instruction master interface.
	  AVR32_HMATRIX.mcfg[AVR32_HMATRIX_MASTER_CPU_INSN] = 0x1;

	  audio_buffer_in = 0;
	  spk_buffer_out = 0;
	  // Register PDCA IRQ interrupt.
	  pdca_set_irq();

	  // Init PDCA channel with the pdca_options.
	  pdca_init_channel(PDCA_CHANNEL_SSC_RX, &PDCA_OPTIONS); // init PDCA channel with options.
      pdca_enable_interrupt_reload_counter_zero(PDCA_CHANNEL_SSC_RX);
      pdca_init_channel(PDCA_CHANNEL_SSC_TX, &SPK_PDCA_OPTIONS); // init PDCA channel with options.
       pdca_enable_interrupt_reload_counter_zero(PDCA_CHANNEL_SSC_TX);

       //////////////////////////////////////////////
       // Enable now the transfer.
       pdca_enable(PDCA_CHANNEL_SSC_TX);


	  xTaskCreate(AK5394A_task,
              configTSK_AK5394A_NAME,
              configTSK_AK5394A_STACK_SIZE,
              NULL,
              configTSK_AK5394A_PRIORITY,
              NULL);

}
示例#28
0
文件: ui.c 项目: AndreyMostovov/asf
/**
 * \name PWM functions
 * @{
 */
void ui_pwm_led_init(uint8_t lednum)
{
	/* Timer waveform options */
	static tc_waveform_opt_t waveform_options = {
		/* Channel selection. */
		.channel  = 1,

		.bswtrg   = TC_EVT_EFFECT_NOOP,
		.beevt    = TC_EVT_EFFECT_NOOP,
		.bcpc     = TC_EVT_EFFECT_NOOP,
		.bcpb     = TC_EVT_EFFECT_NOOP,

		.aswtrg   = TC_EVT_EFFECT_NOOP,
		.aeevt    = TC_EVT_EFFECT_NOOP,
		.acpc     = TC_EVT_EFFECT_NOOP,
		.acpa     = TC_EVT_EFFECT_NOOP,

		/* Waveform selection */
		.wavsel   = TC_WAVEFORM_SEL_UP_MODE_RC_TRIGGER,
		/* External event trigger enable. */
		.enetrg   = false,
		/* External event selection (non-zero for Channel B to work) */
		.eevt     = !0,
		/* External event edge selection. */
		.eevtedg  = TC_SEL_NO_EDGE,

		.cpcdis   = false,
		.cpcstop  = false,

		.burst    = false,
		.clki     = false,
		/* Internal source clock 5, fPBA/128. */
		.tcclks   = TC_CLOCK_SOURCE_TC5,
	};
	switch (lednum) {
	case LED0:
		/* Assign output pin to timer/counter 0 channel A */

		/* Channel selection. */
		waveform_options.channel = 1;

		waveform_options.bcpc = TC_EVT_EFFECT_NOOP;

		waveform_options.bcpb = TC_EVT_EFFECT_NOOP;
		/* RC compare effect on TIOA. */
		waveform_options.acpc = TC_EVT_EFFECT_CLEAR;
		/* RA compare effect on TIOA. */
		waveform_options.acpa = TC_EVT_EFFECT_SET;

		/* Setup timer/counter waveform mode */
		sysclk_enable_peripheral_clock(&AVR32_TC0);
		tc_init_waveform(&AVR32_TC0, &waveform_options);

		/* Write the TOP (RC) and COMPARE (RA) values */
		tc_write_ra(&AVR32_TC0, 1, 1);   /* Set RA value. */
		tc_write_rc(&AVR32_TC0, 1, 255); /* Set RC value. */

		/* Start the timer PWM channel */
		tc_start(&AVR32_TC0, 1);
		break;

	case LED1:
		/* Assign output pin to timer/counter 1 channel B */

		/* Channel selection. */
		waveform_options.channel = 2;

		waveform_options.acpc = TC_EVT_EFFECT_NOOP;

		waveform_options.acpa = TC_EVT_EFFECT_NOOP;
		/* RC compare effect on TIOB. */
		waveform_options.bcpc = TC_EVT_EFFECT_CLEAR;
		/* RB compare effect on TIOB. */
		waveform_options.bcpb = TC_EVT_EFFECT_SET;

		/* Setup timer/counter waveform mode */
		sysclk_enable_peripheral_clock(&AVR32_TC1);
		tc_init_waveform(&AVR32_TC1, &waveform_options);

		/* Write the TOP (RC) and COMPARE (RB) values */
		tc_write_rb(&AVR32_TC1, 2, 1);   /* Set RB value. */
		tc_write_rc(&AVR32_TC1, 2, 255); /* Set RC value. */

		/* Start the timer PWM channel */
		tc_start(&AVR32_TC1, 2);
		break;

	default:
		break;
	}
}

void ui_pwm_update(uint8_t channum, uint8_t brightness)
{
	switch (channum) {
	case LED0:
		if (brightness != 0) {
			gpio_enable_module_pin(AVR32_TC0_A1_0_1_PIN,
					AVR32_TC0_A1_0_1_FUNCTION);
			tc_start(&AVR32_TC0, 1);
			tc_write_ra(&AVR32_TC0, 1, brightness);
		} else {
			tc_stop(&AVR32_TC0, 1);
			LED_Off(LED0);
		}

		break;

	case LED1:
		if (brightness != 0) {
			gpio_enable_module_pin(AVR32_TC1_B2_0_PIN,
					AVR32_TC1_B2_0_FUNCTION);
			tc_start(&AVR32_TC1, 2);
			tc_write_rb(&AVR32_TC1, 2, brightness);
		} else {
			tc_stop(&AVR32_TC1, 2);
			LED_Off(LED0);
		}

		break;

	default:
		break;
	}
}

/* End of PWM */
/** @} */

/**
 * \name Display functions
 * @{
 */

static void ui_display_enable(void)
{
	delay_init(sysclk_get_cpu_hz());

	et024006_Init( sysclk_get_cpu_hz(), sysclk_get_hsb_hz());

	/* Clear the display i.e. make it black */
	et024006_DrawFilledRect(0, 0, ET024006_WIDTH, ET024006_HEIGHT, BLACK );

	/* Set the backlight. */
	gpio_set_gpio_pin(ET024006DHU_BL_PIN);

	ui_display_init_rtc();

	ui_display_welcome_msg();
}
示例#29
0
// main function
int main(void) {

	pm_switch_to_osc0(&AVR32_PM, FOSC0, OSC0_STARTUP);

	// Enable edge-triggered interrupt.
	eic_options[0].eic_mode  = EIC_MODE_EDGE_TRIGGERED;
	// Interrupt will trigger on falling edge (this is a must-do for the keypad scan
	// feature if the chosen mode is edge-triggered).
	eic_options[0].eic_edge  = EIC_EDGE_RISING_EDGE;
	// Initialize in synchronous mode : interrupt is synchronized to the clock
	eic_options[0].eic_async = EIC_SYNCH_MODE;
	// Set the interrupt line number.
	eic_options[0].eic_line  = QT1081_EIC_EXTINT_INT;

	// Activate LED0 & LED1 & LED2 & LED3 pins in GPIO output mode and switch them off.
	gpio_set_gpio_pin(LED0_GPIO);
	gpio_set_gpio_pin(LED1_GPIO);
	gpio_set_gpio_pin(LED2_GPIO);
	gpio_set_gpio_pin(LED3_GPIO);

	gpio_enable_module_pin( QT1081_EIC_EXTINT_PIN, QT1081_EIC_EXTINT_FUNCTION);

#if( INT_MODE == INT_MODE_GPIO)
	Disable_global_interrupt();

#if __GNUC__
	INTC_init_interrupts();
    /* Register interrupt handler to the interrupt controller
     * up, down buttons on PB22, PB23 -> GPIO_IRQ_6
     */
	INTC_register_interrupt(&touch_button_isr, AVR32_GPIO_IRQ_6, 0);//AVR32_INTC_INT0);
	/* Other buttons on PB[24..26] -> GPIO_IRQ_7 (PB23 - PB31) */
	INTC_register_interrupt(&touch_button_isr, AVR32_GPIO_IRQ_7, 0);
#endif
	gpio_enable_pin_interrupt(QT1081_TOUCH_SENSOR_0, GPIO_RISING_EDGE);
	gpio_enable_pin_interrupt(QT1081_TOUCH_SENSOR_1, GPIO_RISING_EDGE);
	gpio_enable_pin_interrupt(QT1081_TOUCH_SENSOR_2, GPIO_RISING_EDGE);
	gpio_enable_pin_interrupt(QT1081_TOUCH_SENSOR_3, GPIO_RISING_EDGE);
	gpio_enable_pin_interrupt(QT1081_TOUCH_SENSOR_4, GPIO_RISING_EDGE);

	Enable_global_interrupt();
#endif

#if(INT_MODE == INT_MODE_EIC)
	Disable_global_interrupt();

#if __GNUC__
	INTC_init_interrupts();
    /* Register the EXTINT1 interrupt handler to the interrupt controller
     */
	INTC_register_interrupt(&touch_button_isr, QT1081_EIC_EXTINT_IRQ, AVR32_INTC_INT0);
#endif

	  // Init the EIC controller with the options
	  eic_init(&AVR32_EIC, eic_options, 1);
	  // Enable the EIC lines.
	  eic_enable_lines(&AVR32_EIC, (1<<eic_options[0].eic_line));
	  // Enable the interrupt for each EIC line.
	  eic_enable_interrupt_lines(&AVR32_EIC, (1<<eic_options[0].eic_line));

	Enable_global_interrupt();
#endif

	while(true);

	return 0;
}
示例#30
0
/**
 * \brief Initializes the TC subsystem ready to generate a LED PWM wave.
 *
 * Initializes the on-chip TC module in PWM generation mode, and configures the
 * board LED as an output so that the LED brightness can be adjusted.
 */
static void pwm_timer_init(void)
{
	// Assign output pin to timer/counter 0 channel B
	gpio_enable_module_pin(AVR32_TC0_B0_0_0_PIN,
			AVR32_TC0_B0_0_0_FUNCTION);

	// Timer waveform options
	const tc_waveform_opt_t waveform_options = {
		//! Channel selection.
		.channel  = 0,

		//! Software trigger effect on TIOB.
		.bswtrg   = TC_EVT_EFFECT_NOOP,
		//! External event effect on TIOB.
		.beevt    = TC_EVT_EFFECT_NOOP,
		//! RC compare effect on TIOB.
		.bcpc     = TC_EVT_EFFECT_CLEAR,
		//! RB compare effect on TIOB.
		.bcpb     = TC_EVT_EFFECT_SET,

		//! Software trigger effect on TIOA.
		.aswtrg   = TC_EVT_EFFECT_NOOP,
		//! External event effect on TIOA.
		.aeevt    = TC_EVT_EFFECT_NOOP,
		//! RC compare effect on TIOA.
		.acpc     = TC_EVT_EFFECT_NOOP,
		//! RA compare effect on TIOA.
		.acpa     = TC_EVT_EFFECT_NOOP,

		//! Waveform selection
		.wavsel   = TC_WAVEFORM_SEL_UP_MODE_RC_TRIGGER,
		//! External event trigger enable.
		.enetrg   = false,
		//! External event selection (non-zero for Channel B to work)
		.eevt     = !0,
		//! External event edge selection.
		.eevtedg  = TC_SEL_NO_EDGE,
		//! Counter disable when RC compare.
		.cpcdis   = false,
		//! Counter clock stopped with RC compare.
		.cpcstop  = false,

		//! Burst signal selection.
		.burst    = false,
		//! Clock inversion selection.
		.clki     = false,
		//! Internal source clock 5, fPBA/128.
		.tcclks   = TC_CLOCK_SOURCE_TC5,
	};

	// Setup timer/counter waveform mode
	sysclk_enable_peripheral_clock(&AVR32_TC0);
	tc_init_waveform(&AVR32_TC0, &waveform_options);

	// Write the TOP (RC) and COMPARE (RB) values
	tc_write_rb(&AVR32_TC0, 0, 1);   // Set RB value.
	tc_write_rc(&AVR32_TC0, 0, 255); // Set RC value.

	// Start the timer PWM channel
	tc_start(&AVR32_TC0, 0);
}

/**
 * \brief Application main routine
 */
int main(void)
{
	board_init();
	sysclk_init();

	irq_initialize_vectors();
	cpu_irq_enable();

	pwm_timer_init();
	touch_init();

	while (true) {
		touch_handler();
	}
}