NoPaste

main.c

von blan

SNIPPET_TEXT:
  1. #include <avr/io.h>
  2. #include <avr/interrupt.h>
  3. #include <util/delay.h>
  4. #include "util/util.h"
  5. #include "util/uart.h"
  6. #include "util/fifo.h"
  7. #include "util/engine.h"
  8.  
  9. #define FRAGMENT_RX 1
  10. #define FRAGMENT_TX 1
  11.  
  12. volatile fifo_t *fifo_rx;
  13. volatile fifo_t *fifo_tx;
  14.  
  15. ISR(USART_RXC_vect)
  16. {
  17.   int8_t data = uart_getc_nowait();
  18.   fifo_push(fifo_rx, &data);
  19. }
  20.  
  21. int main()
  22. {
  23.   uart_init((1 << RXEN) | (1 << TXEN) | (1 << RXCIE),
  24.             (1 << URSEL) | (1 << UCSZ1) | (1 << UCSZ0),
  25.             UART_BAUD_SELECT);
  26.  
  27.   engine_init();
  28.  
  29.   fifo_rx = fifo_new(8, FRAGMENT_RX + 3);
  30.  
  31.   sei();
  32.  
  33.   if(fifo_rx)
  34.   {
  35.     while(TRUE)
  36.     {
  37.       int8_t *data = (int8_t*) malloc(5);
  38.       data[4] = '\0';
  39.  
  40.       /*
  41.       if(fifo_pop(fifo_rx, data) == FIFO_SUCCESS)
  42.       {
  43.         uart_puts(data);
  44.       }
  45.       */
  46.  
  47.  
  48.       uart_putc( (int8_t) strlen( (char*) fifo_rx->data) );
  49.       _delay_ms(1000);
  50.  
  51.       free(data);
  52.     }
  53.   }
  54.  
  55.   return 0x00;
  56. }

Quellcode

Hier kannst du den Code kopieren und ihn in deinen bevorzugten Editor einfügen. PASTEBIN_DOWNLOAD_SNIPPET_EXPLAIN