Esempio n. 1
0
/**
 * \brief Initialize SAM4E_XPRO board for low power test.
 */
void init_specific_board(void)
{
	/* Disable all Extra functions in matrix except for SWD CLK/IO */
	matrix_set_system_io(0x00001C30);

	/* Configure all PIOs as inputs to save power */
	pio_set_input(PIOA, 0xFFFFFFFF, PIO_PULLUP);
	pio_set_input(PIOB, 0xFFFFFFFF, PIO_PULLUP);
	pio_set_input(PIOC, 0xFFFFFFFF, PIO_PULLUP);
	pio_set_input(PIOD, 0xFFFFFFFF, PIO_PULLUP);
	pio_set_input(PIOE, 0xFFFFFFFF, PIO_PULLUP);

	/* Disable USB Clock */
	pmc_disable_udpck();

	/* Disable pull-up on PHY */
	pio_pull_up(PIOD, PIO_PD0 | PIO_PD4 | PIO_PD5 | PIO_PD6 | PIO_PD7, 0);
	/* Hold PHY in reset to avoid the clock output switching */
	pio_set_output(PIOD, PIO_PD31, 0, 0, 0);

	/* Disable pull-up on VBUS */
	pio_pull_up(PIOE, PIO_PE2, 0);
	/* Disable PIO pull-up for PB10(USB_DDM), PB11(USB_DDP) */
	pio_pull_up(PIOB, PIO_PB10 | PIO_PB11, 0);

	/* Enable the PMC clocks of push button for wakeup */
	pmc_enable_periph_clk(ID_PIOE);
	pio_handler_set_priority(PIOE, PIOE_IRQn, IRQ_PRIOR_PIO);
}
Esempio n. 2
0
/**
 * \brief Perform a HW initialization to the PHY and set up clocks.
 *
 * This should be called only once to initialize the PHY pre-settings.
 * The PHY address is the reset status of CRS, RXD[3:0] (the emacPins' pullups).
 * The COL pin is used to select MII mode on reset (pulled up for Reduced MII).
 * The RXDV pin is used to select test mode on reset (pulled up for test mode).
 * The above pins should be predefined for corresponding settings in resetPins.
 * The GMAC peripheral pins are configured after the reset is done.
 *
 * \param p_gmac   Pointer to the GMAC instance.
 * \param uc_phy_addr PHY address.
 * \param ul_mck GMAC MCK.
 *
 * Return GMAC_OK if successfully, GMAC_TIMEOUT if timeout.
 */
uint8_t ethernet_phy_init(Gmac *p_gmac, uint8_t uc_phy_addr, uint32_t mck)
{
	uint8_t uc_rc;
	uint8_t uc_phy;

	pio_set_output(PIN_GMAC_RESET_PIO, PIN_GMAC_RESET_MASK, 1,  false, true);
	pio_set_input(PIN_GMAC_INT_PIO, PIN_GMAC_INT_MASK, PIO_PULLUP);
	pio_set_input(PIN_GMAC_SIGDET_PIO, PIN_GMAC_SIGDET_MASK, PIO_DEFAULT);
	pio_set_peripheral(PIN_GMAC_PIO, PIN_GMAC_PERIPH, PIN_GMAC_MASK);
    
	ethernet_phy_reset(GMAC,uc_phy_addr);

	/* Configure GMAC runtime clock */
	uc_rc = gmac_set_mdc_clock(p_gmac, mck);
	if (uc_rc != GMAC_OK) {
		return 0;
	}

	/* Check PHY Address */
	uc_phy = ethernet_phy_find_valid(p_gmac, uc_phy_addr, 0);
	if (uc_phy == 0xFF) {
		return 0;
	}
	if (uc_phy != uc_phy_addr) {
		ethernet_phy_reset(p_gmac, uc_phy_addr);
	}

	return uc_rc;
}
Esempio n. 3
0
int main (void)
{
	// Insert system clock initialization code here (sysclk_init()).

	sysclk_init();
	board_init();

	// Insert application code here, after the board has been initialized.
	
	pmc_enable_periph_clk(ID_PIOA);
	pio_set_input(PIOA, PIO_PA16, PIO_DEFAULT);
	pio_pull_down(PIOA, (PIO_PA16), ENABLE);
	pio_handler_set(PIOA, ID_PIOA, PIO_PA16, PIO_IT_RISE_EDGE, pin_riseedge_handler);
	pio_enable_interrupt(PIOA,PIO_PA16);
	
	pio_set_input(PIOA, PIO_PA17, PIO_DEFAULT);
	pio_pull_down(PIOA, (PIO_PA17), ENABLE);
	pio_handler_set(PIOA, ID_PIOA, PIO_PA17, PIO_IT_RISE_EDGE, pin_riseedge_handler);
	pio_enable_interrupt(PIOA,PIO_PA17);
	
	NVIC_EnableIRQ(PIOA_IRQn);
	
	gpio_set_pin_low(LED0_GPIO);
	gpio_set_pin_high(LED1_GPIO);
	
	while(1){
		
	}
}
Esempio n. 4
0
/**
 * \brief Initialize SAM4C_EK board for low power test.
 */
void init_specific_board(void)
{
	/* Configure all PIOs as inputs to save power */
	pio_set_input(PIOA, 0xFFFFFFFF, PIO_PULLUP);
	pio_set_input(PIOB, 0xFFFFFFFF, PIO_PULLUP);

	/* Enable the PMC clocks of push button for wakeup */
	pmc_enable_periph_clk(ID_PIOA);
	pio_handler_set_priority(PIOA, PIOA_IRQn, IRQ_PRIOR_PIO);
}
Esempio n. 5
0
int main(void)
{
	// Disable watchdog timer
	wdt_disable(WDT);

	// Enable peripheral clock to be able to read button state
	pmc_enable_periph_clk(BUTTONS_PIO_ID);
	while (!pmc_is_periph_clk_enabled(BUTTONS_PIO_ID));

	// Configure pins
	pio_set_output(LEDS_PIO, ALL_LEDS, 1, false, false);
	pio_set_input(BUTTONS_PIO, ALL_BUTTONS, PIO_PULLUP);

	while (true)
	{
		pio_set(LEDS_PIO, LED_ORANGE);
		pio_clear(LEDS_PIO, LED_GREEN);
		while (pio_get(BUTTONS_PIO, PIO_INPUT, BUTTON1));
		pio_clear(LEDS_PIO, LED_ORANGE);
		pio_set(LEDS_PIO, LED_GREEN);
		while (pio_get(BUTTONS_PIO, PIO_INPUT, BUTTON2));
	}

	return 0;
}
Esempio n. 6
0
File: adc.c Progetto: vis81/uspi
void adc_init()
{
	pio_init();
	spi_init();
	//nSYNC/nPD
	pio_set_output(ADC_nSYNC,0,FALSE,FALSE);
			
	//ADC_nDRDY
	pio_set_input(ADC_nDRDY0,FALSE,FALSE);
	pio_set_input(ADC_nDRDY1,FALSE,FALSE);
	pio_set_input(ADC_nDRDY2,FALSE,FALSE);
	gAdcDesc.state=ADC_IDLE;
#if PWM_DEBUG
	pwm_init();
#endif
}
/**
 * \brief Perform complete pin(s) configuration; general attributes and PIO init
 * if necessary.
 *
 * \param p_pio Pointer to a PIO instance.
 * \param ul_type PIO type.
 * \param ul_mask Bitmask of one or more pin(s) to configure.
 * \param ul_attribute Pins attributes.
 *
 * \return Whether the pin(s) have been configured properly.
 */
uint32_t pio_configure(Pio *p_pio, const pio_type_t ul_type,
		const uint32_t ul_mask, const uint32_t ul_attribute)
{
	/* Configure pins */
	switch (ul_type) {
	case PIO_PERIPH_A:
	case PIO_PERIPH_B:
#     if (SAM3S || SAM3N || SAM4S)
	case PIO_PERIPH_C:
	case PIO_PERIPH_D:
#     endif
		pio_set_peripheral(p_pio, ul_type, ul_mask);
		pio_pull_up(p_pio, ul_mask, (ul_attribute & PIO_PULLUP));
		break;

	case PIO_INPUT:
		pio_set_input(p_pio, ul_mask, ul_attribute);
		break;

	case PIO_OUTPUT_0:
	case PIO_OUTPUT_1:
		pio_set_output(p_pio, ul_mask, (ul_type == PIO_OUTPUT_1),
				(ul_attribute & PIO_OPENDRAIN) ? 1 : 0,
				(ul_attribute & PIO_PULLUP) ? 1 : 0);
		break;

	default:
		return 0;
	}

	return 1;
}
Esempio n. 8
0
/**
 *  \brief Configure the Pushbuttons
 *
 *  Configure the PIO as inputs and generate corresponding interrupt when
 *  pressed or released.
 */
static void configure_buttons(void)
{
	pmc_enable_periph_clk(PIN_PUSHBUTTON_1_ID);
	pmc_enable_periph_clk(PIN_PUSHBUTTON_2_ID);	
	pio_set_input(PIN_PUSHBUTTON_1_PIO, PIN_PUSHBUTTON_1_MASK, PIO_PULLUP | PIO_DEBOUNCE);
	pio_set_input(PIN_PUSHBUTTON_2_PIO, PIN_PUSHBUTTON_2_MASK, PIO_PULLUP | PIO_DEBOUNCE);
	pio_set_debounce_filter(PIN_PUSHBUTTON_1_PIO, PIN_PUSHBUTTON_1_MASK, 10);
	pio_set_debounce_filter(PIN_PUSHBUTTON_2_PIO, PIN_PUSHBUTTON_2_MASK, 10);	
	pio_handler_set(PIN_PUSHBUTTON_1_PIO, PIN_PUSHBUTTON_1_ID, PIN_PUSHBUTTON_1_MASK, PIO_IT_FALL_EDGE | PIO_PULLUP, Button1_Handler);
	pio_handler_set(PIN_PUSHBUTTON_2_PIO, PIN_PUSHBUTTON_2_ID, PIN_PUSHBUTTON_2_MASK, PIO_IT_FALL_EDGE | PIO_PULLUP, Button2_Handler);	
	pio_enable_interrupt(PIN_PUSHBUTTON_1_PIO , PIN_PUSHBUTTON_1_MASK);
	pio_enable_interrupt(PIN_PUSHBUTTON_2_PIO , PIN_PUSHBUTTON_2_MASK);
	NVIC_SetPriority((IRQn_Type) PIN_PUSHBUTTON_1_ID, 0);
	NVIC_SetPriority((IRQn_Type) PIN_PUSHBUTTON_2_ID, 0);	
	NVIC_EnableIRQ((IRQn_Type) PIN_PUSHBUTTON_1_ID);
	NVIC_EnableIRQ((IRQn_Type) PIN_PUSHBUTTON_2_ID);
	}
Esempio n. 9
0
/**
 *  \brief Configure the Pushbuttons
 *
 *  Configure the PIO as inputs and generate corresponding interrupt when
 *  pressed or released.
 */
static void configure_buttons(void)
{
	pmc_enable_periph_clk(PIN_PUSHBUTTON_1_ID);
	pio_set_input(PIN_PUSHBUTTON_1_PIO, PIN_PUSHBUTTON_1_MASK, PIN_PUSHBUTTON_1_ATTR);
	pio_set_debounce_filter(PIN_PUSHBUTTON_1_PIO, PIN_PUSHBUTTON_1_MASK, 100);
	pio_handler_set(PIN_PUSHBUTTON_1_PIO,PIN_PUSHBUTTON_1_ID, PIN_PUSHBUTTON_1_MASK,PIO_IT_FALL_EDGE, Button1_Handler);
	pio_enable_interrupt(PIN_PUSHBUTTON_1_PIO, PIN_PUSHBUTTON_1_MASK);
	NVIC_SetPriority(PIN_PUSHBUTTON_1_ID,0);
	NVIC_EnableIRQ(PIN_PUSHBUTTON_1_ID);
	
	pmc_enable_periph_clk(PIN_PUSHBUTTON_2_ID);
	pio_set_input(PIN_PUSHBUTTON_2_PIO, PIN_PUSHBUTTON_2_MASK, PIN_PUSHBUTTON_2_ATTR);
	pio_set_debounce_filter(PIN_PUSHBUTTON_2_PIO, PIN_PUSHBUTTON_2_MASK, 100);
	pio_handler_set(PIN_PUSHBUTTON_2_PIO,PIN_PUSHBUTTON_2_ID, PIN_PUSHBUTTON_2_MASK,PIO_IT_FALL_EDGE, Button2_Handler);
	pio_enable_interrupt(PIN_PUSHBUTTON_2_PIO, PIN_PUSHBUTTON_2_MASK);
	NVIC_SetPriority(PIN_PUSHBUTTON_2_ID,1);
	NVIC_EnableIRQ(PIN_PUSHBUTTON_2_ID);
	}
Esempio n. 10
0
void config_hall_interrupt (void){
	pmc_enable_periph_clk(ID_HALL);
	
	pio_set_input(PIOA, GPIO_HALLB, PIO_DEFAULT);
	pio_pull_down(PIOA, GPIO_HALLB, ENABLE);
	pio_handler_set(PIOA, ID_HALL, GPIO_HALLB, PIO_IT_RISE_EDGE, pin_riseedge_handler);
	pio_enable_interrupt(PIOA, GPIO_HALLB);
	
	pio_set_input(PIOA, GPIO_HALLC, PIO_DEFAULT);
	pio_pull_down(PIOA, GPIO_HALLC, ENABLE);
	pio_handler_set(PIOA, ID_HALL, GPIO_HALLC, PIO_IT_FALL_EDGE, pin_riseedge_handler);
	pio_enable_interrupt(PIOA, GPIO_HALLC);
	
	NVIC_DisableIRQ(PIOA_IRQn);
	NVIC_ClearPendingIRQ(PIOA_IRQn);
	NVIC_SetPriority(PIOA_IRQn, PRIORITY_MEASURE);
	NVIC_EnableIRQ(PIOA_IRQn);
}
Esempio n. 11
0
void button_init(uint32_t ul_id, Pio *p_pio, const uint32_t ul_mask, IRQn_Type IRQn, void (*p_handler) (uint32_t, uint32_t))
{
	pmc_enable_periph_clk(ul_id);
	pio_set_input(p_pio, ul_mask, PIO_PULLUP | PIO_DEBOUNCE);
	pio_set_debounce_filter(p_pio, ul_mask, DEBOUNCE_FREQ);
	pio_handler_set(p_pio, ul_id, ul_mask, PIO_IT_FALL_EDGE, p_handler);
	pio_enable_interrupt(p_pio, ul_mask);
	NVIC_EnableIRQ(IRQn);
}
Esempio n. 12
0
/**
 * \brief Configures SAMG53 for low power demo.
 */
void init_specific_board(void)
{
	/* For the lowest power consumption all pins should have defined state
	 * e.g. no floating pins.
	 * Set all pins as input with pull-up enabled with the exception:
	 * - CDC UART RX (PA09) should not be pulled up because this pin is
	 *   driven by the EDBG in this application
	 * - CDC UART TX (PA10) This is actively driven by the SAMG53 in this
	 *   application
	 */
	pio_set_input(PIOA, 0xFFFFF9FF, PIO_PULLUP);
	pio_set_input(PIOA, 0x00000600, PIO_DEFAULT);
	pio_set_input(PIOB, 0xFFFFFFFF, PIO_PULLUP);

	/* Enable the PMC clocks of push button for wakeup */
	pmc_enable_periph_clk(ID_PIOA);
	pio_handler_set_priority(PIOA, PIOA_IRQn, IRQ_PRIORITY_PIO);
}
 /**************************************************************************
 Configure the interrupt.
 Digital Pin 12
 **************************************************************************/
 void configure_interrupt_pio_RightWheel(void)
 {
	 pmc_enable_periph_clk(ID_PIOD); //Enable the module clock
	 pio_set_input(PIOD, PIO_PD8,PIO_PULLUP);
	 pio_handler_set(PIOD,ID_PIOD,PIO_PD8,PIO_IT_EDGE,pin_edge_handler);
	 pio_enable_interrupt(PIOD,PIO_PD8);
	 NVIC_EnableIRQ(PIOD_IRQn);

 }
Esempio n. 14
0
/**
 *  \brief Configure the Pushbuttons
 *
 *  Configure the PIO as inputs and generate corresponding interrupt when
 *  pressed or released.
 */
static void configure_buttons(void)
{	
	pmc_enable_periph_clk(ID_BUT_2);
	pmc_enable_periph_clk(ID_BUT_1);
	pio_set_input(PORT_BUT_2, MASK_BUT_2, PIO_PULLUP | PIO_DEBOUNCE);
	pio_set_input(PORT_BUT_1, MASK_BUT_1, PIO_PULLUP | PIO_DEBOUNCE);
	pio_set_debounce_filter(PORT_BUT_2, MASK_BUT_2, 20);
	pio_set_debounce_filter(PORT_BUT_1, MASK_BUT_1, 20);
	pio_handler_set(PORT_BUT_2, ID_BUT_2, MASK_BUT_2, PIO_IT_FALL_EDGE , Button1_Handler );
	pio_handler_set(PORT_BUT_1, ID_BUT_1, MASK_BUT_1, PIO_IT_FALL_EDGE , Button2_Handler );
	pio_enable_interrupt(PORT_BUT_2, MASK_BUT_2);
	pio_enable_interrupt(PORT_BUT_1, MASK_BUT_1);
	NVIC_SetPriority((IRQn_Type) ID_PIOB, 2);
	NVIC_SetPriority((IRQn_Type) ID_PIOC, 2);
	NVIC_EnableIRQ(ID_BUT_2);
	NVIC_EnableIRQ(ID_BUT_1);	
		
}
Esempio n. 15
0
/**
 * \brief Initialize SAM4E_EK board for low power test.
 */
void init_specific_board(void)
{
	/* Configure all PIOs as inputs to save power */
	pio_set_input(PIOA, 0xFFFFFFFF, PIO_PULLUP);
	pio_set_input(PIOB, 0xFFFFFFFF, PIO_PULLUP);
	pio_set_input(PIOC, 0xFFFFFFFF, PIO_PULLUP);

	/* Disable USB Clock */
	pmc_disable_udpck();

	/* Disable PIO pull-up for PB10(USB_DDM), PB11(USB_DDP) */
	pio_pull_up(PIOB, (0x3 << 10), 0);
	/* Disable PIO pull-up for PC21(USB_CNX) */
	pio_pull_up(PIOC, (0x1 << 21), 0);

	/* Enable the PMC clocks of push button for wakeup */
	pmc_enable_periph_clk(ID_PIOA);
	pio_handler_set_priority(PIOA, PIOA_IRQn, IRQ_PRIOR_PIO);
}
Esempio n. 16
0
void configure_botao(void)
{
	pmc_enable_periph_clk(PIN_PUSHBUTTON_1_ID);
	pio_set_input(PIN_PUSHBUTTON_1_PIO, PIN_PUSHBUTTON_1_MASK, PIN_PUSHBUTTON_1_ATTR);
	pio_set_debounce_filter(PIN_PUSHBUTTON_1_PIO, PIN_PUSHBUTTON_1_MASK, 10);
	pio_handler_set(PIN_PUSHBUTTON_1_PIO, PIN_PUSHBUTTON_1_ID,PIN_PUSHBUTTON_1_MASK, PIN_PUSHBUTTON_1_ATTR ,push_button_handle);
	pio_enable_interrupt(PIN_PUSHBUTTON_1_PIO, PIN_PUSHBUTTON_1_MASK);
	NVIC_SetPriority((IRQn_Type) PIN_PUSHBUTTON_1_ID, 0);
	NVIC_EnableIRQ((IRQn_Type) PIN_PUSHBUTTON_1_ID);
}
Esempio n. 17
0
/**
 *  \brief Configure the Pushbuttons
 *
 *  Configure the PIO as inputs and generate corresponding interrupt when
 *  pressed or released.
 */
static void configure_buttons(void)
{
	pmc_enable_periph_clk(PIN_PUSHBUTTON_1_ID);
	pmc_enable_periph_clk(PIN_PUSHBUTTON_2_ID);

	/**
	* Configura entrada
	*/ 
	pio_set_input(PIN_PUSHBUTTON_1_PIO,PIN_PUSHBUTTON_1_MASK , PIO_PULLUP | PIO_DEBOUNCE);
	pio_set_input(PIN_PUSHBUTTON_2_PIO,PIN_PUSHBUTTON_2_MASK , PIO_PULLUP | PIO_DEBOUNCE);

	/*
	 * Configura divisor do clock para debounce
	 */
	pio_set_debounce_filter(PIN_PUSHBUTTON_1_PIO,PIN_PUSHBUTTON_1_MASK ,20);
	pio_set_debounce_filter(PIN_PUSHBUTTON_2_PIO,PIN_PUSHBUTTON_2_MASK ,20);
	
	/* 
	*	Configura interrupção para acontecer em borda de descida.
	*/
	pio_handler_set(PIN_PUSHBUTTON_1_PIO,PIN_PUSHBUTTON_1_ID,PIN_PUSHBUTTON_1_MASK ,PIN_PUSHBUTTON_1_ATTR ,Button1_Handler);
	pio_handler_set(PIN_PUSHBUTTON_2_PIO,PIN_PUSHBUTTON_2_ID,PIN_PUSHBUTTON_2_MASK ,PIN_PUSHBUTTON_2_ATTR ,Button2_Handler);
	
				
	/*
	*	Ativa interrupção no periférico B porta do botão
	*/	
	pio_enable_interrupt(PIN_PUSHBUTTON_1_PIO,PIN_PUSHBUTTON_1_MASK);
	pio_enable_interrupt(PIN_PUSHBUTTON_2_PIO,PIN_PUSHBUTTON_2_MASK);
	
	/*
	*	Configura a prioridade da interrupção no pORTB
	*/
	NVIC_SetPriority(ID_PIOB,2);
	NVIC_SetPriority(ID_PIOC,2);
	
	/*
	*	Ativa interrupção no port B
	*/
	NVIC_EnableIRQ(ID_PIOB);
	NVIC_EnableIRQ(ID_PIOC);
}
Esempio n. 18
0
static void configure_buttons(void)
{	
	pmc_enable_periph_clk(ID_BUT_2);
	pmc_enable_periph_clk(ID_BUT_3);
	/**
	* Configura entrada
	*/ 
	pio_set_input(PORT_BUT_2, MASK_BUT_2, PIO_PULLUP | PIO_DEBOUNCE);
	pio_set_input(PORT_BUT_3, MASK_BUT_3, PIO_PULLUP | PIO_DEBOUNCE);
	
	/*
	 * Configura divisor do clock para debounce
	 */
	pio_set_debounce_filter(PORT_BUT_2,MASK_BUT_2, 100);
	pio_set_debounce_filter(PORT_BUT_3,MASK_BUT_3, 100);
	
	/* 
	*	Configura interrupção para acontecer em borda de descida.
	*/
	pio_handler_set(PORT_BUT_2,ID_BUT_2,MASK_BUT_2,PIO_IT_FALL_EDGE,Button2_Handler);
	pio_handler_set(PORT_BUT_3,ID_BUT_3,MASK_BUT_3,PIO_IT_FALL_EDGE,Button3_Handler);
				
	/*
	*	Ativa interrupção no periférico B porta do botão
	*/	
	pio_enable_interrupt(PORT_BUT_2,MASK_BUT_2);
	pio_enable_interrupt(PORT_BUT_3,MASK_BUT_3);
	
	/*
	*	Configura a prioridade da interrupção no PORTB E PORTC
	*/
	NVIC_SetPriority(PIOB_IRQn, 10);
	NVIC_SetPriority(PIOC_IRQn, 10);
	
	/*
	*	Ativa interrupção no port B e C
	*/
	NVIC_EnableIRQ(PIOB_IRQn);
	NVIC_EnableIRQ(PIOC_IRQn);
		
}
Esempio n. 19
0
/**
 * \brief Initialize SAM3N_EK board for low power test.
 */
void init_specific_board(void)
{
    /* Configure all PIOs as inputs to save power */
    pio_set_input(PIOA, 0xFFFFFFFF, PIO_PULLUP);
    pio_set_input(PIOB, 0xFFFFFFFF, PIO_PULLUP);
    pio_set_input(PIOC, 0xFFFFFFFF, PIO_PULLUP);

    /* Disable USB Clock */
    pmc_disable_upll_clock();

    /* Disable PIO pull-up for PA0 (VBUS_USB) */
    pio_pull_up(PIOA, (0x1 << 0), 0);

    /* Initialize ADC pin as ADC input mode to save power */
    adc_enable_channel(ADC, ADC_CHANNEL_0);
    adc12b_enable_channel(ADC12B, ADC_CHANNEL_3);

    /* Enable the PMC clocks of push button for wakeup */
    pmc_enable_periph_clk(ID_PIOA);
    pio_handler_set_priority(PIOA, PIOA_IRQn, IRQ_PRIOR_PIO);
}
Esempio n. 20
0
int initMPU60X0(void)
{
	twi_options_t twi_options;
	
	twi_options.master_clk	= BOARD_MCK;
	twi_options.speed		= MPU60X0_SPEED;
	twi_options.chip		= MPU60X0_BASE_ADDRESS;

	// Enable External Interrupt Controller Line.
	// Enable interrupts with priority higher than USB.
	pio_set_input(PIOA, MPU60X0_BODY_INT_PIN, MPU60X0_BODY_INT_FUNCTION);
	pio_configure_interrupt(PIOA, MPU60X0_BODY_INT_PIN, MPU60X0_BODY_INT_FUNCTION);
	pio_handler_set(PIOA, ID_PIOA, MPU60X0_BODY_INT_PIN, PIO_IT_RISE_EDGE, MPU60X0BodyInterrupt);
	
	pio_set_input(PIOA, MPU60X0_HEAD_INT_PIN, MPU60X0_HEAD_INT_FUNCTION);
	pio_configure_interrupt(PIOA, MPU60X0_HEAD_INT_PIN, MPU60X0_HEAD_INT_FUNCTION);
	pio_handler_set(PIOA, ID_PIOA, MPU60X0_HEAD_INT_PIN, PIO_IT_RISE_EDGE, MPU60X0HeadInterrupt);
	
	NVIC_EnableIRQ(PIOA_IRQn);
	pio_enable_interrupt(PIOA, MPU60X0_BODY_INT_PIN);
	pio_enable_interrupt(PIOA, MPU60X0_HEAD_INT_PIN);
	
	// Initialize TWI driver with options.
	if (TWI_SUCCESS != twi_master_init(TWI0, &twi_options))
	{
		// Disable the interrupts.
		pio_disable_interrupt(PIOA, MPU60X0_BODY_INT_PIN);
		pio_disable_interrupt(PIOA, MPU60X0_HEAD_INT_PIN);
	
		return(-1);
	}

	// Enable both RX and TX
	TWI0->TWI_IER = TWI_IER_TXRDY | TWI_IER_RXRDY;

	return(0);
}
/**
 * \brief Initialize SAM3N_EK board for low power test.
 */
void init_specific_board(void)
{
	/* Configure all PIOs as inputs to save power */
	pio_set_input(PIOA, 0xFFFFFFFF, PIO_PULLUP);
	pio_set_input(PIOB, 0x0FFFFFFF, PIO_PULLUP); /* Exclude JTAG pins */
	pio_set_input(PIOC, 0xFFFFFFFF, PIO_PULLUP);
	pio_set_input(PIOD, 0x7FFFFFFF, PIO_PULLUP);
	pio_set_input(PIOE, 0xFFFFFFFF, PIO_PULLUP);
	pio_set_input(PIOF, 0x3F, PIO_PULLUP);

	/* Disable USB Clock */
	pmc_disable_udpck();
	pmc_disable_upll_clock();

	/* Disable PIO pull-up for PB4, PB5, PB6, PB7 */
	pio_pull_up(PIOB, (0xF << 4), 0);

	/* Initialize ADC pin as ADC input mode to save power */
	adc_enable_channel(ADC, ADC_CHANNEL_1);

	/* Enable the PMC clocks of push button for wakeup */
	pmc_enable_periph_clk(ID_PIOB);
	pio_handler_set_priority(PIOB, PIOB_IRQn, IRQ_PRIOR_PIO);
}
Esempio n. 22
0
int main (void)
{

	/**
	* Inicializando o clock do uP
	*/
	sysclk_init();
	
	/** 
	*  Desabilitando o WathDog do uP
	*/
	WDT->WDT_MR = WDT_MR_WDDIS;
		
	/**
	* Ativa clock nos periféricos
	*/
	_pmc_enable_clock_periferico(ID_LED_BLUE);
	_pmc_enable_clock_periferico(ID_LED_GREEN);		// Redundante mas não tem problema !
	_pmc_enable_clock_periferico(ID_LED_RED);
	_pmc_enable_clock_periferico(ID_BUT_2);
				
	/**
	*	Configura saída
	*/
	pio_set_output(PORT_LED_BLUE  , MASK_LED_BLUE	,1,0,0);
	pio_set_output(PORT_LED_GREEN , MASK_LED_GREEN  ,1,0,0);
	pio_set_output(PORT_LED_RED	  , MASK_LED_RED	,1,0,0);
	


	
	/**
	* Configura entrada
	*/ 
	pio_set_input(PORT_BUT_2, MASK_BUT_2, PIO_PULLUP | PIO_DEBOUNCE);
	
	/*
	 * Configura divisor do clock para debounce
	 */
	pio_set_debounce_filter(PORT_BUT_2, MASK_BUT_2, 100);
	

	
	/* 
	*	Configura interrupção para acontecer em borda de descida.
	*/
	pio_handler_set(PIOB, ID_BUT_2, MASK_BUT_2, PIO_IT_FALL_EDGE, push_button_handle);
				
	/*
	*	Ativa interrupção no periférico B porta do botão
	*/	
	pio_enable_interrupt(PORT_BUT_2, MASK_BUT_2);	
	/*
	*	Configura a prioridade da interrupção no pORTB
	*/
	NVIC_SetPriority((IRQn_Type)PIOB_IRQn, 0);
	
	/*
	*	Ativa interrupção no port B
	*/
	NVIC_EnableIRQ((IRQn_Type)PIOB_IRQn);
	
	/**
	*	Loop infinito
	*/
	while(1){
	    /*
		pio_set(PIOA, (1 << PIN_LED_BLUE));
		delay_ms(500);
		pio_clear(PIOA, (1 << PIN_LED_BLUE));
		delay_ms(500);
		*/
	}
}
Esempio n. 23
0
int main (void)
{
	/* Insert system clock initialization code here (sysclk_init()). */

	sysclk_init();
	board_init();

	/* Insert application code here, after the board has been initialized. */
	
	if (SysTick_Config(sysclk_get_cpu_hz() / 1000)) {
		puts("-E- Systick configuration error\r");
		while (1) {
			/* Capture error */
			gpio_set_pin_low(LED2_GPIO);
		}
	}
	
	config_lcd();
	
	pmc_enable_periph_clk(ID_ENC);
	
	//Interrupt for A:
	pio_set_input(PIOA, GPIO_A, PIO_DEFAULT);
	pio_pull_down(PIOA, GPIO_A, ENABLE);
	pio_handler_set(PIOA, ID_ENC, GPIO_A, PIO_IT_RISE_EDGE, pin_handler);
	pio_enable_interrupt(PIOA, GPIO_A);
	
	//Interrupt for B:
	pio_set_input(PIOA, GPIO_B, PIO_DEFAULT);
	pio_pull_down(PIOA, GPIO_B, ENABLE);
	pio_handler_set(PIOA, ID_ENC, GPIO_B, PIO_IT_RISE_EDGE, pin_handler);
	pio_enable_interrupt(PIOA, GPIO_B);
	
	//Interrupt for C:
	pio_set_input(PIOA, GPIO_C, PIO_DEFAULT);
	pio_pull_down(PIOA, GPIO_C, ENABLE);
	//pio_handler_set(PIOA, ID_ENC, GPIO_C, PIO_IT_RISE_EDGE, pin_handler);
	pio_handler_set(PIOA, ID_ENC, GPIO_C, PIO_IT_FALL_EDGE, pin_handler);
	pio_enable_interrupt(PIOA, GPIO_C);
	
	//Enable Interrupt GPIO:
	NVIC_DisableIRQ(PIOA_IRQn);
	NVIC_ClearPendingIRQ(PIOA_IRQn);
	NVIC_SetPriority(PIOA_IRQn, 0);
	NVIC_EnableIRQ(PIOA_IRQn);
	
	ili9225_set_foreground_color(COLOR_BLACK);
	ili9225_draw_string(10,10, (uint8_t *)"Encoder Test");
	
	while (1){
		ili9225_set_foreground_color(COLOR_WHITE);
		ili9225_draw_filled_rectangle(0,30,ILI9225_LCD_WIDTH,ILI9225_LCD_HEIGHT);
		ili9225_set_foreground_color(COLOR_BLACK);
		graus = ((float)round/ENC_RES)*VOLTA_COMP;
		snprintf(buf, sizeof(buf), "Graus:%.3f", graus );
		ili9225_draw_string(10,50, buf);
		snprintf(buf, sizeof(buf), "Round:%d", round );
		ili9225_draw_string(10,80, buf);
		mdelay(500);
	}
}