Ejemplo n.º 1
0
void ring_buffer_write(ring_buffer* ring, const uint8_t* buffer, uint16_t size) {
  uint16_t i;
  
  // TODO can be optimized
  for(i = 0; i < size; i++) {
    ring_buffer_write_byte(ring, buffer[i]);
  }
}
Ejemplo n.º 2
0
/* _____LOCAL FUNCTIONS______________________________________________________ */
static void usart0_interrupt(void)
{
    u8_t data;

    // Read status register
    u32_t csr = AT91C_BASE_US0->US_CSR;

    // See if a receive error was detected
    if(csr & (AT91C_US_RXBRK | AT91C_US_OVRE | AT91C_US_FRAME | AT91C_US_PARE))
    {
        // Reset status bits
        AT91C_BASE_US0->US_CR = AT91C_US_RSTSTA;
        return;
    }

    // See if a character has been received
    if(csr & AT91C_US_RXRDY)
    {
        // Read character and buffer it
        data = (char)(AT91C_BASE_US0->US_RHR);
        ring_buffer_write_byte(&usart0_rx_ring_buffer, data);
    }

    // See if the transmitter is ready
    if(csr & AT91C_US_TXRDY)
    {
        // See if there is more data to be sent
        if(ring_buffer_read_byte(&usart0_tx_ring_buffer,&data))
        {
            // Clear flag to indicate that transmission is busy
            usart0_tx_finished_flag = FALSE;
            // Buffer data to be transmitted
            AT91C_BASE_US0->US_THR = data;            
        }
        else
        {
            // Disable transmit ready interrupt
            AT91C_BASE_US0->US_IDR = AT91C_US_TXRDY;
            // Enable transmit empty interrupt
            AT91C_BASE_US0->US_IER = AT91C_US_TXEMPTY;
        }
    }

    // See if the transmitter is finished
    if(csr & AT91C_US_TXEMPTY)
    {
        // Set flag to indicate that transmission is finished
        usart0_tx_finished_flag = TRUE;
        // Disable transmit empty interrupt
        AT91C_BASE_US0->US_IDR = AT91C_US_TXEMPTY;
    }
}
Ejemplo n.º 3
0
bool_t usart0_tx_byte(u8_t data)
{
    if(!ring_buffer_write_byte(&usart0_tx_ring_buffer,data))
    {
        // Buffer is full
        return FALSE;
    }

    // Make sure transmission has started
    AT91C_BASE_US0->US_IER = AT91C_US_TXRDY;

    return TRUE;
}
Ejemplo n.º 4
0
void main() {
  char temp[100];
  uint16_t len;

  ring_buffer_init(&ring, buffer, BUFFER_SIZE);

  len = ring_buffer_readline(&ring, temp, 100);
  printf("%d - %s\n", len, temp);
  
  strcpy(temp, "line1\nline2\nline3");
  ring_buffer_write(&ring, temp, strlen(temp));
  while((len = ring_buffer_readline(&ring, temp, 100)) > 0) {
    printf("%d - %s\n", len, temp);
  }
  
  printf("available: %d\n", ring.available);
  ring_buffer_write_byte(&ring, '\n');
  while((len = ring_buffer_readline(&ring, temp, 100)) > 0) {
    printf("%d - %s\n", len, temp);
  }
}
Ejemplo n.º 5
0
interrupt void Scic_Rx_Int (void)
{
	EINT;

//	isB_RX = true;

	if (ScicRegs.SCIRXST.bit.RXERROR) {
		ScicRegs.SCIFFRX.bit.RXFIFORESET = 0;
		ScicRegs.SCIFFRX.bit.RXFIFORESET = 1;
		ScicRegs.SCICTL1.bit.SWRESET = 0;
		ScicRegs.SCICTL1.bit.SWRESET = 1;
//		rx_err_cnt2++;
		return;
	}
	u8 byte = ScicRegs.SCIRXBUF.bit.RXDT;
	ring_buffer_write_byte(&ring_buf,byte);

	ScicRegs.SCIFFRX.bit.RXFFOVRCLR = 1;			// Clear Overflow flag
	ScicRegs.SCIFFRX.bit.RXFFINTCLR = 1;			// Clear Interrupt flag
	PieCtrlRegs.PIEACK.all |= PIEACK_GROUP8;		// Issue PIE ack
}