示例#1
0
//Interrupt handler
void _SCI3_(void)
{
if (SCI3.SSR.BIT.RDRF) {
  SCI3.SSR.BIT.RDRF = 0;
  reset_imask_ccr();
  if(sci3_input_handler != NULL) {
    if(sci3_input_handler(SCI3.RDR)) {;}
  }
}
else if (SCI3.SSR.BIT.OER || SCI3.SSR.BIT.FER || SCI3.SSR.BIT.PER) {
  SCI3.SCR3.BYTE &= ~0x40;
  SCI3.SCR3.BYTE &= ~0x10;
  SCI3.SSR.BYTE &= ~0x78;
  SCI3.SCR3.BYTE |= 0x10;
  SCI3.SCR3.BYTE |= 0x40;
  reset_imask_ccr();
}
/*else if () {
	}*/
else if (SCI3.SSR.BIT.TEND) {
	if(ringbuf_elements(&txbuf) == 0) {
		transmitting = 0;
		SCI3.SCR3.BYTE &= ~0x04;
	} else {
		SCI3.TDR = ringbuf_get(&txbuf);
		}
	}
}
示例#2
0
ISR(USART1_RX_vect, ISR_BLOCK)
{
  uint8_t receivedByte;
  
  if (ringbuf_elements(&USARTtoUSB_Buffer) >= ringbuf_size(&USARTtoUSB_Buffer) - 1 )
    return;

  receivedByte = UDR1;

  // TODO check for callback Code
  // set var if waiting for normal reply.
  // if not awaiting normal reply and receivedByte == 42 call callback.
  if(!jennic_in_programming_mode && opCode < 0){
  	if(receivedByte == 42){
	  	callback();
		return;
  	}
	opCode = receivedByte;
	return;
  }

  // removed if condition cause we need the serial in even if theres no USB Connection
  // if (USB_DeviceState == DEVICE_STATE_Configured) {
    ringbuf_put(&USARTtoUSB_Buffer, receivedByte);
  // }
}
示例#3
0
/** ISR to manage the reception of data from the serial port, placing received bytes into a circular buffer
 *  for later transmission to the host.
 */
ISR(USART1_UDRE_vect, ISR_BLOCK)
{
  if (ringbuf_elements(&USBtoUSART_Buffer))
    UDR1 = ringbuf_get(&USBtoUSART_Buffer);
  else
    UCSR1B &= ~(1 << UDRIE1);
}
示例#4
0
ISR(USCIAB0TX, uartA0B0_tx_interrupt)
{
  if(IFG2 & UCA0TXIFG) {
    if(ringbuf_elements(&txbuf) == 0) {
      transmitting = 0;
    } else {
      TXBUF = ringbuf_get(&txbuf);
    }
  }
}
示例#5
0
文件: uart1.c 项目: 1uk3/contiki
void
uart1_tx_interrupt(void)
{
  if(ringbuf_elements(&txbuf) == 0) {
    transmitting = 0;
    INT_SC1CFG &= ~INT_SCTXFREE;
  } else {
    SC1_DATA = ringbuf_get(&txbuf);
  }
}
示例#6
0
void CDC_In_Task()
{
 /* Read bytes from the USB OUT endpoint and transmit to jennic if programming mode */
 if ( ringbuf_elements(&USBtoUSART_Buffer) < ringbuf_size(&USBtoUSART_Buffer)-2 ) {
   // TODO check int16_t type
   int16_t ReceivedByte = CDC_Device_ReceiveByte(&VirtualSerial_CDC1_Interface);
   if ( !(ReceivedByte < 0) )
     ringbuf_put(&USBtoUSART_Buffer, ReceivedByte);
 }
}
示例#7
0
ISR(UART1TX, uart1_tx_interrupt)
{
  ENERGEST_ON(ENERGEST_TYPE_IRQ);

  if(ringbuf_elements(&txbuf) == 0) {
    transmitting = 0;
  } else {
    TXBUF1 = ringbuf_get(&txbuf);
  }

  ENERGEST_OFF(ENERGEST_TYPE_IRQ);
}
示例#8
0
void CDC_Arduino_In_Task()
{
uint16_t bytes = CDC_Device_BytesReceived(&VirtualSerial_CDC0_Interface);
	while(bytes--){
	/* Read bytes from the USB OUT endpoint and store it for the Arduino Serial Class */
 		if ( ringbuf_elements(&serialRx_Buffer) < ringbuf_size(&serialRx_Buffer)-2 ) {
   			int16_t ReceivedByte = CDC_Device_ReceiveByte(&VirtualSerial_CDC0_Interface);
   			if ( !(ReceivedByte < 0) )
     				ringbuf_put(&serialRx_Buffer, ReceivedByte);
 		}
 		else{
 			return;
 		}
 	} // end while
}
示例#9
0
文件: uart0.c 项目: AWRyder/contiki
ISR(USCIAB0TX, uart0_tx_interrupt)
{
  ENERGEST_ON(ENERGEST_TYPE_IRQ);
  if((IFG2 & UCA0TXIFG)){

    if(ringbuf_elements(&txbuf) == 0) {
      transmitting = 0;
    } else {
      UCA0TXBUF = ringbuf_get(&txbuf);
    }
  }

  /* In a stand-alone app won't work without this. Is the UG misleading? */
  IFG2 &= ~UCA0TXIFG;

  ENERGEST_OFF(ENERGEST_TYPE_IRQ);
}
示例#10
0
void Jennic_In_Task()
{
  size_t i;

  Endpoint_SelectEndpoint(VirtualSerial_CDC1_Interface.Config.DataINEndpoint.Address);
  if ( !Endpoint_IsINReady() )
    return;

  /* Read bytes from the USART receive buffer and send with CDC */
  /* pass through in programming mode */
  if (ringbuf_elements(&USARTtoUSB_Buffer) && jennic_in_programming_mode)
  {
    uint8_t byte = ringbuf_get(&USARTtoUSB_Buffer);

      if (CDC_Device_SendByte(&VirtualSerial_CDC1_Interface, byte) != ENDPOINT_READYWAIT_NoError)
        return;
  }
}
示例#11
0
/*---------------------------------------------------------------------------*/
static void
uart_event_handler(nrf_drv_uart_event_t * p_event, void * p_context)
{
  ENERGEST_ON(ENERGEST_TYPE_IRQ);

  if (p_event->type == NRF_DRV_UART_EVT_RX_DONE) {
    if (uart0_input_handler != NULL) {
      uart0_input_handler(p_event->data.rxtx.p_data[0]);
    }
    (void)nrf_drv_uart_rx(rx_buffer, 1);
  } else if (p_event->type == NRF_DRV_UART_EVT_TX_DONE) {
    if (ringbuf_elements(&txbuf) > 0) {
      uint8_t c = ringbuf_get(&txbuf);
      nrf_drv_uart_tx(&c, 1);
    }
  }

  ENERGEST_OFF(ENERGEST_TYPE_IRQ);
}
示例#12
0
void lufaLoop(void)
{
	if(!jennic_in_programming_mode){
		CDC_Device_USBTask(&VirtualSerial_CDC0_Interface);
		CDC_Arduino_In_Task();
	}
    do{
  	  if (jennic_reset_event)
  	  {
  	    
  	    if (!jennic_in_programming_mode)
  	    {
  	      jennic_in_programming_mode = true;
  	      Serial_Config(38400, 8, CDC_LINEENCODING_OneStopBit, CDC_PARITY_None);
  	      Jennic_Set_Mode(true); /* pull jennic into programming mode */
  	    }
  	    else
  	    {
  	      jennic_in_programming_mode = false;
  	      Serial_Config(1000000, 8, CDC_LINEENCODING_OneStopBit, CDC_PARITY_None);
  	      Jennic_Set_Mode(false); /* pull jennic into normal mode */

  	    }
  	    jennic_reset_event = false;
  	  }

  	  //if(jennic_in_programming_mode){
  	  Jennic_In_Task();
  	  CDC_In_Task();
  	  CDC_Device_USBTask(&VirtualSerial_CDC1_Interface);
	  
  	  USB_USBTask();
  	  /* do house-keeping */
  	  
	  // UDRE Interrupt enable (USART)
	  // cause if our USB->USART ringbuf is full we disable the interrupt.
	  if ( ringbuf_elements(&USBtoUSART_Buffer) && !(UCSR1B & (1 << UDRIE1)) )
  	    UCSR1B |= (1 << UDRIE1);
  	}while(jennic_in_programming_mode);


}
示例#13
0
void USART3_IRQHandler(void)
{
  ENERGEST_ON(ENERGEST_TYPE_IRQ);
  
	/* check if rx register not empty and int enabled */
  if ((USART3->SR & USART_SR_RXNE) && (USART3->CR1 & USART_CR1_RXNEIE)) {
		uint8_t c = USART3->DR;
		if (usart3_input_handler != NULL) {
			usart3_input_handler(c);
		}  
  }
	/* check if tx register empty and int enabled */
  if ((USART3->SR & USART_SR_TXE) && (USART3->CR1 & USART_CR1_TXEIE)) {
		if (ringbuf_elements(&txbuf) == 0) {
			transmitting = 0;
			USART3->CR1 &= ~USART_CR1_TXEIE;
		} else {
			USART3->DR = ringbuf_get(&txbuf);
		}
  }  
  
  ENERGEST_OFF(ENERGEST_TYPE_IRQ);
}
示例#14
0
/*---------------------------------------------------------------------------*/
static void
cs_isr(uint8_t port, uint8_t pin)
{
  int d, i;

  /* check if ISR comes from CS pin */
  if((port != SPI_CS_PORT) && (pin != SPI_CS_PIN)) {
    return;
  }
  
  /* CS goes HIGH, End of Transmission */
  if(GPIO_READ_PIN(SPI_CS_PORT_BASE, SPI_CS_PIN_MASK)) {
    /* check if something left in RX FIFO after transaction, and put all remain data into RX ringbuffer */
    while(REG(SSI0_BASE + SSI_SR) & SSI_SR_RNE) {
      d = REG(SSI0_BASE + SSI_DR);
      ringbuf_put(&spi_rx_buf, d);
      PRINTF("ERR: Something left in FIFO!\r\n");
    }
    /* pass received  data to upper level driver via callback */
    d = ringbuf_get(&spi_rx_buf);
    while(d != -1) {
      if(input_callback) {
        input_callback((unsigned char)d);
      }
      d = ringbuf_get(&spi_rx_buf);
    }
    /* mark that there is no start of frame phase */
    /* TODO: is it necessary? */
    start_of_frame = 0;
    /* check if TX FIFO is not empty */
    if(!(REG(SSI0_BASE + SSI_SR) & SSI_SR_TNF)) {
      /* if TX FIFO is not empty, reset SSI to flush TX FIFO
         it is possible that previous transaction has been failed, so complete frame
         has not been transmitted. Eg. NBR has been turned off during transmission
      */
      PRINTF("ERR: TX FIFO not empty after transaction!\r\n");
      ssi_reset_request = 3;
    }
    if(ssi_reset_request) {
      /* if reset request is active, perform SSI reset */
      PRINTF("WARN: SSI reset request %u\r\n", ssi_reset_request);
      ssi_reconfigure(1);
      ssi_reset_request = 0;
    }
  } else {
    /* CS goes LOW, Start of Transmission */
    start_of_frame = 1;
    /* fill TX FIFO with data only if we were connected */
    if(connected) {
      /* get number of elements in ringbuffer */
      d = ringbuf_elements(&spi_tx_buf);
      /* send that number to master with characteristic upper nibble */
      d = 0x50 | (d > 7 ? 7 : d);
      REG(SSI0_BASE + SSI_DR) = d;
      for(i = 0; i < 7; i++) {
        if(!(REG(SSI0_BASE + SSI_SR) & SSI_SR_TNF)) {
          /* Error, we shouldn't overflow TX FIFO */
          PRINTF("ERR: TX FIFO overflow!\r\n");
          break;
        }
        d = ringbuf_get(&spi_tx_buf);
        if(d == -1) {
          REG(SSI0_BASE + SSI_DR) = 0xff;
        } else {
          REG(SSI0_BASE + SSI_DR) = d;
        }
      }
      /* If the CS interrupt was triggered due to slave requesting SPI transfer,
       * we clear the INT pin, as the transfer has now been completed.
       */
      if(ringbuf_elements(&spi_tx_buf) == 0) {
        GPIO_CLR_PIN(SPI_INT_PORT_BASE, SPI_INT_PIN_MASK);
      }
    } else {
      /* mark we are connected */
      connected = 1;
    }
  }
}