예제 #1
0
파일: twi.c 프로젝트: novotnyjirka81/AV6
int twi_slave_init(volatile avr32_twi_t *twi, const twi_options_t *opt, const twi_slave_fct_t *slave_fct)
{
  bool global_interrupt_enabled = Is_global_interrupt_enabled();

  // Set pointer to TWIM instance for IT
  twi_inst = twi;

  // Disable TWI interrupts
  if (global_interrupt_enabled) Disable_global_interrupt();
  twi->idr = ~0UL;
  twi->sr;

  // Reset TWI
  twi->cr = AVR32_TWI_CR_SWRST_MASK;

  if (global_interrupt_enabled) Enable_global_interrupt();

  // Dummy read in SR
  twi->sr;

  // Disable all interrupts
  Disable_global_interrupt();

  // Register TWI handler on level 2
  INTC_register_interrupt( &twi_slave_interrupt_handler, AVR32_TWI_IRQ, AVR32_INTC_INT1);

  // Enable all interrupts
  Enable_global_interrupt();

  // Set slave address
  twi->smr = (opt->chip << AVR32_TWI_SMR_SADR_OFFSET);

  // Disable master transfer
  twi->cr = AVR32_TWI_CR_MSDIS_MASK;

  // Enable slave
  twi->cr = AVR32_TWI_CR_SVEN_MASK;

  // get a pointer to applicative routines
  twi_slave_fct = *slave_fct;

  // Slave Access Interrupt Enable
  twi_it_mask = AVR32_TWI_IER_SVACC_MASK;
  twi->ier = twi_it_mask;

  // Everything went ok
  return TWI_SUCCESS;
}
예제 #2
0
void boardsupport_init(void) 
{
	central_data_t *central_data;
	irq_initialize_vectors();
	cpu_irq_enable();
	Disable_global_interrupt();
		
	sysclk_init();

	//delay_init(sysclk_get_cpu_hz());
		
	INTC_init_interrupts();

	central_data=central_data_get_pointer_to_struct();
	
	#ifdef TELEMETRY_USE_UART
		uart_int_set_usart_conf(TELEMETRY_UART_INDEX, asv_debug_uart_conf());
		//uart configuration
		uart_int_init(TELEMETRY_UART_INDEX);
		uart_int_register_write_stream(uart_int_get_uart_handle(TELEMETRY_UART_INDEX), &(central_data->wired_out_stream));
		// Registering streams
		buffer_make_buffered_stream_lossy(&(wired_in_buffer), &(central_data->wired_in_stream));
		uart_int_register_read_stream(uart_int_get_uart_handle(TELEMETRY_UART_INDEX), &(central_data->wired_in_stream));
		central_data->debug_in_stream=&central_data->wired_in_stream;
		central_data->debug_out_stream=&central_data->wired_out_stream;

	#endif
		
	central_data_init();

	Enable_global_interrupt();

}
예제 #3
0
void DFU_UsbStop (void)
{
  Disable_global_interrupt();
  Usb_disable();
  (void)Is_usb_enabled();
  Enable_global_interrupt();
}
예제 #4
0
void avr32EthEnableIrq(NetInterface *interface)
{
   //Enable Ethernet MAC interrupts
   Enable_global_interrupt();
   //Enable Ethernet PHY interrupts
   interface->phyDriver->enableIrq(interface);
}
예제 #5
0
void encoder_init_all ()
	{
	uint8_t isr_counter = 0;
	
	Disable_global_interrupt();
	/* Initialization loop, this loop inits all required IO and interrupts
	 * for EIC module and pins used to read encoders.  */	
	while(isr_counter < ENCODER_COUNT)
		{
		/* Init io for interrupt line and state poll line. */
		gpio_enable_gpio_pin(encoder_handle[isr_counter].a_pin);
		gpio_enable_gpio_pin(encoder_handle[isr_counter].b_pin);
		
		/* Set pullup for both gpio channels. */
		gpio_enable_pin_pull_up(encoder_handle[isr_counter].a_pin);
		gpio_enable_pin_pull_up(encoder_handle[isr_counter].b_pin);
			
		/* Init interrupt from encoder A line */
		gpio_enable_pin_interrupt(encoder_handle[isr_counter].a_pin, GPIO_FALLING_EDGE);
		gpio_disable_pin_interrupt(encoder_handle[isr_counter].b_pin);
		
		INTC_register_interrupt(&encoders_and_buttons_isr, 
			AVR32_GPIO_IRQ_0 + (encoder_handle[isr_counter].a_pin/8),
			AVR32_INTC_INT0);			
		isr_counter++;
		}
	Enable_global_interrupt();
	}
예제 #6
0
int tc_configure_interrupts(volatile avr32_tc_t *tc, unsigned int channel, const tc_interrupt_t *bitfield)
{
  bool global_interrupt_enabled = Is_global_interrupt_enabled();

  // Check for valid input.
  if (channel >= TC_NUMBER_OF_CHANNELS)
    return TC_INVALID_ARGUMENT;

  // Enable the appropriate interrupts.
  tc->channel[channel].ier = bitfield->etrgs << AVR32_TC_ETRGS_OFFSET |
                             bitfield->ldrbs << AVR32_TC_LDRBS_OFFSET |
                             bitfield->ldras << AVR32_TC_LDRAS_OFFSET |
                             bitfield->cpcs << AVR32_TC_CPCS_OFFSET |
                             bitfield->cpbs << AVR32_TC_CPBS_OFFSET |
                             bitfield->cpas << AVR32_TC_CPAS_OFFSET |
                             bitfield->lovrs << AVR32_TC_LOVRS_OFFSET |
                             bitfield->covfs << AVR32_TC_COVFS_OFFSET;

  // Disable the appropriate interrupts.
  if (global_interrupt_enabled) Disable_global_interrupt();
  tc->channel[channel].idr = (~bitfield->etrgs & 1) << AVR32_TC_ETRGS_OFFSET |
                             (~bitfield->ldrbs & 1) << AVR32_TC_LDRBS_OFFSET |
                             (~bitfield->ldras & 1) << AVR32_TC_LDRAS_OFFSET |
                             (~bitfield->cpcs & 1) << AVR32_TC_CPCS_OFFSET |
                             (~bitfield->cpbs & 1) << AVR32_TC_CPBS_OFFSET |
                             (~bitfield->cpas & 1) << AVR32_TC_CPAS_OFFSET |
                             (~bitfield->lovrs & 1) << AVR32_TC_LOVRS_OFFSET |
                             (~bitfield->covfs & 1) << AVR32_TC_COVFS_OFFSET;
  tc->channel[channel].sr;
  if (global_interrupt_enabled) Enable_global_interrupt();

  return 0;
}
예제 #7
0
void Actividad2(void){
		
		
		pm_switch_to_osc0(&AVR32_PM, FOSC0, OSC0_STARTUP); //osc0 a 12Mhz
		center=0;
		//Interrupciones
		
		Disable_global_interrupt();

		INTC_init_interrupts();

		INTC_register_interrupt(&tecla_lrc_isr, 71, 0);
		INTC_register_interrupt(&tecla_lrc_isr, 70,0);
		gpio_enable_pin_interrupt(QT1081_TOUCH_SENSOR_LEFT,GPIO_RISING_EDGE);
		gpio_enable_pin_interrupt(QT1081_TOUCH_SENSOR_RIGHT,GPIO_RISING_EDGE);
		gpio_enable_pin_interrupt(QT1081_TOUCH_SENSOR_ENTER,GPIO_RISING_EDGE);
		gpio_enable_pin_interrupt(QT1081_TOUCH_SENSOR_UP,GPIO_RISING_EDGE);
		gpio_enable_pin_interrupt(QT1081_TOUCH_SENSOR_DOWN,GPIO_RISING_EDGE);


		Enable_global_interrupt();
		
		
		
		
		while (1){}
	}
예제 #8
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;
}
예제 #9
0
void sio_putstr(char *cptr)
{
  uint8_t byteSend = 0;

  Disable_global_interrupt();

  if( checkIfFifoEmpty  & (!checkIfDataToSend) )
    { // nothing in queue data can be transmited directly
      // to uart FIFO
      resetFifo;

      while( (*cptr!='\0') & (byteSend < UART_TX_FIFO_SIZE) )
        {
          UART_SendByte(SERIAL_USART, (*cptr++) );
          byteSend++;
        }
    }
  //FIFO full save data in buffer
  while(*cptr)
    {
      uartDataToSend.txbuf[uartDataToSend.lastPtr++] = (*cptr++);
      byteSend = 0xff;
    }

  if(byteSend == 0xff)
    {
      uartDataToSend.txbuf[uartDataToSend.lastPtr] = '\0';
    }

  Enable_global_interrupt();

  return;
}
예제 #10
0
파일: pushb.c 프로젝트: kerichsen/asf
/*!
 *  \brief Init the push button 3 sensor.
 *
 *  \return true upon success, false if error.
 */
bool b_pushb3_init ( void )
{
portCHAR token[6];

   // Get the xCFGMutex.
   if( pdTRUE == x_supervisor_SemaphoreTake( xCFGMutex, 20 ) )
   {
       // get the field
       if (config_file_get_value(SENSOR_PB3_CONFIG_FILE, "alarm" , token) >= 0)
       {
         // update value
         if (!strcmp(token, "on"))
         {
           bAlarm3 = pdTRUE;
         }
       }
     // Release the xCFGMutex.
     x_supervisor_SemaphoreGive( xCFGMutex );
   }
   /* configure push button to produce IT on input change */
   gpio_enable_pin_interrupt(PB3_POSITION , GPIO_PIN_CHANGE);
   /* Disable all interrupts */
   Disable_global_interrupt();
   /* register push button 3 handler on level 3 */
   INTC_register_interrupt( (__int_handler)&vpushb_ISR, AVR32_GPIO_IRQ_0 + (PB3_POSITION/8), AVR32_INTC_INT3);
   /* Enable all interrupts */
   Enable_global_interrupt();
   return (true);
}
예제 #11
0
파일: rtouch.c 프로젝트: InSoonPark/asf
/** \brief Prepare the rtouch detect function.
 *
 * A touch can be detected by setting the Y lines  (or X lines) as inputs and
 * enabling the internal pull-ups for these pins. The other lines, X in this
 * case are connected to GND. By a touch the Y lines will be pulled low and an
 * interrupt can be triggered on a low level detect.
 *
 * This function does the registering of the interrupt handler for the touch
 * detect. Currently we use a GPIO interrupt, but here it is only possible to
 * trigger on edges but actually we should trigger on a low level. Anyway this
 * should work too.
 * Here we use the YL line as source input for the edge detection but it is
 * also possible to use YH.
 */
static void inline rtouch_prepare_detect(void)
{
	Disable_global_interrupt();
	INTC_register_interrupt(&rtouch_detect_int_handler,
			AVR32_GPIO_IRQ_0 + rtouch_gpio_ymap[0].pin / 8, 0);
	Enable_global_interrupt();
}
void BUFFERED_SIO_SendHandler (void)
{
    // Something to send ?
    if (BUFFERED_SIO_TxBuffer_StartPointer == BUFFERED_SIO_TxBuffer_EndPointer)
    {
        return;
    }

    BUFFERED_SIO_TxBuffer_StartPointer++;

    // Rollover ?
    if (BUFFERED_SIO_TX_BUFFER_SIZE <= BUFFERED_SIO_TxBuffer_StartPointer)
    {
        BUFFERED_SIO_TxBuffer_StartPointer = 0;
    }

    // Send char
    usart_putchar (BUFFERED_SIO_USART, BUFFERED_SIO_TxBuffer[BUFFERED_SIO_TxBuffer_StartPointer]);


    // Enable USART Tx interrupt for transmitting all chars
    Disable_global_interrupt ();
    BUFFERED_SIO_USART->IER.txempty = 1;
    Enable_global_interrupt ();
}
예제 #13
0
파일: mdma.c 프로젝트: kerichsen/asf
void mdma_configure_interrupts(volatile avr32_mdma_t *mdma, const mdma_interrupt_t *bitfield)
{
  bool global_interrupt_enabled = Is_global_interrupt_enabled();

  // Enable the appropriate interrupts.
  mdma->ier            = bitfield->ch0c << AVR32_MDMA_IER_CH0C_OFFSET |
                         bitfield->ch1c << AVR32_MDMA_IER_CH1C_OFFSET |
                         bitfield->ch2c << AVR32_MDMA_IER_CH2C_OFFSET |
                         bitfield->ch3c << AVR32_MDMA_IER_CH3C_OFFSET |
                         bitfield->berr0 << AVR32_MDMA_IER_BERR0_OFFSET |
                         bitfield->berr1 << AVR32_MDMA_IER_BERR1_OFFSET |
                         bitfield->berr2 << AVR32_MDMA_IER_BERR2_OFFSET |
                         bitfield->berr3 << AVR32_MDMA_IER_BERR3_OFFSET ;


  // Disable the appropriate interrupts.
  if (global_interrupt_enabled) Disable_global_interrupt();
  mdma->idr            = (~bitfield->ch0c & 1)  << AVR32_MDMA_IDR_CH0C_OFFSET |
                         (~bitfield->ch1c & 1)  << AVR32_MDMA_IDR_CH1C_OFFSET |
                         (~bitfield->ch2c & 1)  << AVR32_MDMA_IDR_CH2C_OFFSET |
                         (~bitfield->ch3c & 1)  << AVR32_MDMA_IDR_CH3C_OFFSET |
                         (~bitfield->berr0 & 1) << AVR32_MDMA_IDR_BERR0_OFFSET |
                         (~bitfield->berr1 & 1) << AVR32_MDMA_IDR_BERR1_OFFSET |
                         (~bitfield->berr2 & 1) << AVR32_MDMA_IDR_BERR2_OFFSET |
                         (~bitfield->berr3 & 1) << AVR32_MDMA_IDR_BERR3_OFFSET ;

  if (global_interrupt_enabled) Enable_global_interrupt();

}
u8 BUFFERED_SIO_WriteString (u16 Len, u8 * String_pu8)
{
u16 Value;

    // Save end pointer
    Value = BUFFERED_SIO_TxBuffer_EndPointer;

    Disable_global_interrupt ();

    // For each byte
    while (0 < Len)
    {
        Value++;

        // End of buffer ?
        if (BUFFERED_SIO_TX_BUFFER_SIZE <= Value)
        {
            // Set pointer to start of buffer
            Value = 0;
        }

        // Buffer full ?
        if (Value == BUFFERED_SIO_TxBuffer_StartPointer)
        {
            // Abort sending
            Enable_global_interrupt ();
            return (FALSE);
        }

        // Write byte into buffer
        BUFFERED_SIO_TxBuffer_EndPointer = Value;

#ifdef STICK_20_SEND_DEBUGINFOS_VIA_HID
        BUFFERED_SIO_HID_TxBuffer_EndPointer = Value;
#endif

        BUFFERED_SIO_TxBuffer[Value] = *String_pu8;
        // Todo ISR Lock start
        // Pointers to next byte
        String_pu8++;
        Len--;
        // Todo ISR Lock end
    }

    Enable_global_interrupt ();
    return (TRUE);
}
void isrInternalClok(void){
		RTC->MODE0.CTRL.reg &=  0b1111111111111101;//stop timer
			Disable_global_interrupt();
			//printf("+");
			static bool state;
			state=stateLed;
			

			timeManage.halfmillis+=VALUE_TIMER;

		
			if(timeManage.halfmillis<(RTC_FREQ/2)){//all 500ms
				stateLed=LOW;
			}
			else{
				stateLed=HIGH;
			}
			if(state!=stateLed){
				led = stateLed;
				//	if(synchroLed!=NULL){
				//		xSemaphoreGiveFromISR( synchroLed,NULL);
				//	}
			}

			
			timeManage.second+=timeManage.halfmillis/RTC_FREQ;
			timeManage.halfmillis=timeManage.halfmillis%RTC_FREQ;
			if((valueCor!=0)){
				if (timeCorr==0){
					timeCorr=timeCorrection;
					Clock off;
					off.second=(unsigned int )abs(valueCor)/RTC_FREQ;
					off.halfmillis=(unsigned int)abs(valueCor)%RTC_FREQ;
					if(valueCor<0){
						off.sign=false;
					}
					else{
						off.sign=true;
					}
					//change the time
					timeManage=sumClock(timeManage,off);
					//change the correction offset
					sumOffset=sumClock(sumOffset,off);//ok
				}
				else{
					timeCorr--;
				}	
				sumOffset.second+=sumOffset.halfmillis/RTC_FREQ;
				sumOffset.halfmillis=sumOffset.halfmillis%RTC_FREQ;
				timeManage.second+=timeManage.halfmillis/RTC_FREQ;
				timeManage.halfmillis=timeManage.halfmillis%RTC_FREQ;
			
			}
			

			
	Enable_global_interrupt();
	RTC->MODE0.CTRL.reg |= RTC_MODE0_CTRL_ENABLE; //enable timer
}
예제 #16
0
/*! \brief Initializes MCU interrupts.
 */
static void init_interrupts(void)
{
  // Initialize interrupt handling.
  INTC_init_interrupts();

  // Enable interrupts globally.
  Enable_global_interrupt();
}
예제 #17
0
void eic_clear_interrupt_lines(volatile avr32_eic_t *eic, unsigned int mask_lines)
{
  Bool global_interrupt_enabled = Is_global_interrupt_enabled();

  if (global_interrupt_enabled) Disable_global_interrupt();
  eic->icr = mask_lines;
  eic->isr;
  if (global_interrupt_enabled) Enable_global_interrupt();
}
예제 #18
0
파일: twi.c 프로젝트: novotnyjirka81/AV6
void twi_disable_interrupt(volatile avr32_twi_t *twi)
{
  bool global_interrupt_enabled = Is_global_interrupt_enabled();

  if (global_interrupt_enabled) Disable_global_interrupt();
  twi->idr = ~0UL;
  twi->sr;
  if (global_interrupt_enabled) Enable_global_interrupt();
}
예제 #19
0
void controller_shutdown(void)
{
  // Disable all interrupts
  Disable_global_interrupt();
  // Disable the RTC
  rtc_disable(&AVR32_RTC);
  // Enable global interrupts
  Enable_global_interrupt();
}
예제 #20
0
void platform_int_init()
{
  unsigned i;
  
  for( i = 0; i < NUM_UART; i ++ )
    if( usart_irqs[ i ] != -1 )
      INTC_register_interrupt( phandlers[ i ], usart_irqs[ i ], AVR32_INTC_INT0 );   
  Enable_global_interrupt();   
}
예제 #21
0
파일: pm.c 프로젝트: 12019/USB-Rubber-Ducky
void pm_bod_disable_irq(volatile avr32_pm_t *pm)
{
  Bool global_interrupt_enabled = Is_global_interrupt_enabled();

  if (global_interrupt_enabled) Disable_global_interrupt();
  pm->idr = AVR32_PM_IDR_BODDET_MASK;
  pm->isr;
  if (global_interrupt_enabled) Enable_global_interrupt();
}
예제 #22
0
/*! \brief Main function. Execution starts here.
 *
 * \retval 42 Fatal error.
 */
int main(void)
{
  // Configure system clocks.
  if (pcl_configure_clocks(&pcl_freq_param) != PASS)
    return 42;

  // Initialize USB clock (on PLL1)
  pcl_configure_usb_clock();

  // Initialize usart comm
  init_dbg_rs232(pcl_freq_param.pba_f);

#if BOARD == EVK1105
  Disable_global_interrupt();
  /* 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);
  /* all gpios between PB23 - PB31) */
  INTC_register_interrupt(&touch_button_isr, AVR32_GPIO_IRQ_7, 0);
  Enable_global_interrupt();
#endif

  // Initialize USB task
  usb_task_init();

#if USB_DEVICE_FEATURE == true
  // Initialize device mouse USB task
  device_mouse_hid_task_init();
#endif
#if USB_HOST_FEATURE == true
  //host_keyboard_hid_task_init();

  // Initialize host mouse USB task
  host_mouse_hid_task_init();
#endif

#ifdef FREERTOS_USED
  // Start OS scheduler
  vTaskStartScheduler();
  portDBG_TRACE("FreeRTOS returned.");
  return 42;
#else
  // No OS here. Need to call each task in round-robin mode.
  while (true)
  {
    usb_task();
  #if USB_DEVICE_FEATURE == true
    device_mouse_hid_task();
  #endif
  #if USB_HOST_FEATURE == true
    //host_keyboard_hid_task();
    host_mouse_hid_task();
  #endif
  }
#endif  // FREERTOS_USED
}
예제 #23
0
void eic_clear_interrupt_line(volatile avr32_eic_t *eic, unsigned int line_number)
{
  Bool global_interrupt_enabled = Is_global_interrupt_enabled();

  // Clear line line_number
  if (global_interrupt_enabled) Disable_global_interrupt();
  eic->icr = 1 << line_number;
  eic->isr;
  if (global_interrupt_enabled) Enable_global_interrupt();
}
예제 #24
0
/**
 * Name         : interrupts_init
 *
 * Synopsis     : void interrupts_init (void)
 *
 * Description  : Initialize and enable global interrupts
 * 
 */
void interrupts_init (void)
{
	// Enable low level and medium level interrupts 
	PMIC.CTRL = PMIC_LVL_LOW | PMIC_LVL_MEDIUM;
	
	// Set priority of low level interrupts to Round Robin scheduling
	PMIC.CTRL |= PMIC_RREN_bm;
	
	// Enable global interrupts
	Enable_global_interrupt();
}
예제 #25
0
파일: pcrc.c 프로젝트: thegeek82000/asf
/**
 * \brief  Through this function, the SNA is configured for the PCRC service.
 *
 * \param  puc_sna   Pointer to the SNA
 *
 */
void pcrc_configure_sna(uint8_t *puc_sna)
{
	Disable_global_interrupt();

	memcpy(puc_SNA, puc_sna, SNA_SIZE);

	uc_SNA_crc_8  = _eval_crc_8(puc_SNA, SNA_SIZE, 0);
	ul_SNA_crc_32 = _eval_crc_32(puc_SNA, SNA_SIZE, 0);

	Enable_global_interrupt();
}
u16 BUFFERED_SIO_Init (void)
{
    // IO mapping
static const gpio_map_t USART_GPIO_MAP = {
    {BUFFERED_SIO_USART_RX_PIN, BUFFERED_SIO_USART_RX_FUNCTION},
    {BUFFERED_SIO_USART_TX_PIN, BUFFERED_SIO_USART_TX_FUNCTION}
};

    // USART options.
static const usart_options_t USART_OPTIONS = {
    .baudrate = 57600 * 2,
    .charlength = 8,
    .paritytype = USART_NO_PARITY,
    .stopbits = USART_1_STOPBIT,
    .channelmode = USART_NORMAL_CHMODE
};

    // Reset vars
    BUFFERED_SIO_TxBuffer_StartPointer = 0;
    BUFFERED_SIO_TxBuffer_EndPointer = 0;
    BUFFERED_SIO_TxActiv_Sendbytes = 0;

    BUFFERED_SIO_RxBuffer_StartPointer = 0;
    BUFFERED_SIO_RxBuffer_EndPointer = 0;

#ifdef STICK_20_SEND_DEBUGINFOS_VIA_HID
    BUFFERED_SIO_HID_TxBuffer_StartPointer = 0;
    BUFFERED_SIO_HID_TxBuffer_EndPointer = 0;
    BUFFERED_SIO_HID_TxActiv_Sendbytes = 0;
#endif

    // Assign GPIO to USART.
    gpio_enable_module (USART_GPIO_MAP, sizeof (USART_GPIO_MAP) / sizeof (USART_GPIO_MAP[0]));

    // Initialize USART in RS232 mode.
    usart_init_rs232 (BUFFERED_SIO_USART, &USART_OPTIONS, FPBA_HZ);

    // Disable all interrupts.
    Disable_global_interrupt ();

    // Set ISR
    INTC_register_interrupt (&BUFFERED_SIO_Usart_ISR, BUFFERED_SIO_USART_IRQ, AVR32_INTC_INT0);

    // Enable USART Rx interrupt.
    BUFFERED_SIO_USART->IER.rxrdy = 1;

    // Enable USART Tx interrupt.
    // BUFFERED_SIO_USART->IER.txempty = 1;

    // Enable all interrupts.
    Enable_global_interrupt ();

    return (TRUE);
}
예제 #27
0
파일: twim.c 프로젝트: Tjalling7/asf
int twi_master_init(volatile avr32_twim_t *twi, const twi_options_t *opt) {

    bool global_interrupt_enabled = Is_global_interrupt_enabled();
    int status = TWI_SUCCESS;

    // Disable TWI interrupts
    if (global_interrupt_enabled) Disable_global_interrupt();
    twi->idr = ~0UL;

    // Reset TWI
    twi->cr = AVR32_TWIM_CR_SWRST_MASK;
    if (global_interrupt_enabled) Enable_global_interrupt();

    // Clear SR
    twi->scr = ~0UL;

    // Disable all interrupts
    Disable_global_interrupt();

    // Register TWI handler on level 2
    BSP_INTC_IntReg( &twi_master_interrupt_handler, AVR32_TWIM0_IRQ, AVR32_INTC_INT1);

    // Enable all interrupts
    Enable_global_interrupt();

    twi->cr = AVR32_TWIM_CR_MEN_MASK;

    if (opt->smbus) {
        twi->cr = AVR32_TWIM_CR_SMEN_MASK;
        twi->smbtr = (unsigned long) -1;
    }

    // Select the speed
    if (twi_set_speed(twi, opt->speed, opt->pba_hz) == TWI_INVALID_CLOCK_DIV)
        return TWI_INVALID_CLOCK_DIV;

    // Probe the component
    //status = twi_probe(twi, opt->chip);

    return status;
}
void ISO7816_Usart_ISR_Test (void)
{
    static int n = 0;
    static int c;
    // static int x;

    // Test for tx int
    // Tx int enabled ?
    if (1 == EXAMPLE_INT_USART->IMR.txempty)
    {
        // Yes
        // Data send ?
        if (1 == EXAMPLE_INT_USART->CSR.txempty)
        {
            // Data send
            EXAMPLE_INT_USART->IDR.txempty = 1;
            usart_reset_tx (EXAMPLE_INT_USART);

            /*
               // Disable tx empty interrupt Disable_global_interrupt(); EXAMPLE_INT_USART->IDR.txempty = 1; Enable_global_interrupt(); while (1 ==
               EXAMPLE_INT_USART->IMR.txempty) ; */
            /*
               // clearing interrupt request x = EXAMPLE_INT_USART->cr; EXAMPLE_INT_USART->cr = x; x = EXAMPLE_INT_USART->cr; */
        }
    }
    else
    {
        n++;
    }

    // Test for rx int
    if (1 == EXAMPLE_INT_USART->CSR.rxrdy)
    {
        // Data is ready
        usart_read_char (EXAMPLE_INT_USART, &c);
        // EXAMPLE_INT_USART->IER.txempty = 1;

        // Send data
        // usart_write_char(EXAMPLE_INT_USART, c);

        // Enable tx int
        Disable_global_interrupt ();
        EXAMPLE_INT_USART->IER.txempty = 1;
        Enable_global_interrupt ();
        while (0 == EXAMPLE_INT_USART->IMR.txempty);

    }

    /*
       usart_read_char(EXAMPLE_INT_USART, &c); usart_write_char(EXAMPLE_INT_USART, c); */

    n++;
}
예제 #29
0
void _init(void)
{
	sysclk_init();
	
	// Disable all interrupts.
	Disable_global_interrupt();

	// Initialize interrupt vectors.
	INTC_init_interrupts();
	
	// Enable all interrupts.
	Enable_global_interrupt();
}
void BUFFERED_SIO_TxIntHandler (void)
{
    if (FALSE == BUFFERED_SIO_TxEmpty ())
    {
        BUFFERED_SIO_SendHandler ();
    }
    else
    {
        // Disable USART Tx interrupt.
        Disable_global_interrupt ();
        BUFFERED_SIO_USART->IDR.txempty = 1;
        Enable_global_interrupt ();
    }
}