0.6.3 Changes since last version
[digitaldcpower] / uart.c
diff --git a/uart.c b/uart.c
index 72cc33f..eb7c4e1 100644 (file)
--- a/uart.c
+++ b/uart.c
 #include "uart.h"
 #define F_CPU 8000000UL  // 8 MHz
 
+// a receiver stack:
+#define SENDSTACKSIZE 12
+static volatile char ustack[SENDSTACKSIZE];
+static volatile uint8_t stackpointer_end=0;
+static uint8_t stackpointer_start=0;
+
 void uart_init(void) 
 {
         unsigned int baud=51;   // 9600 baud at 8MHz
@@ -62,6 +68,35 @@ void uart_sendstr_p(const prog_char *progmem_s)
 
 }
 
+// call this function from interrupt to fill the
+// ustack reveiver buffer. We need this big buffer
+// to handle fast copy/paste of strings comming
+// into the UART
+void uart_poll_getchar_isr(void)
+{
+#ifdef VAR_88CHIP
+        if(!(UCSR0A & (1<<RXC0))) return;
+        ustack[stackpointer_end]=UDR0;
+#else
+        if(!(UCSRA & (1<<RXC))) return;
+        ustack[stackpointer_end]=UDR;
+#endif
+        stackpointer_end=(stackpointer_end+1) % SENDSTACKSIZE;
+}
+
+// get the characters out of the buffer which is filled by
+// the above interrupt function
+unsigned char uart_getchar_isr_noblock(char *returnval)  
+{
+        if (stackpointer_start!=stackpointer_end){
+                *returnval=ustack[stackpointer_start];
+                stackpointer_start=(stackpointer_start+1) % SENDSTACKSIZE;
+                return(1);
+        }
+        return(0);
+}
+
+/*
 // get a byte from rs232
 // this function does a blocking read 
 char uart_getchar(void)  
@@ -109,3 +144,4 @@ void uart_flushRXbuf(void)
 #endif
 }
 
+*/