changes to the GUI to allow for better loading and writing as well as tested our...
[goodfet] / firmware / lib / atmega168.c
index 36795fa..d8705ba 100644 (file)
@@ -2,9 +2,13 @@
 
 #include "platform.h"
 
+#include <avr/io.h>
+#include <util/delay.h>
+
 //! Receive a byte.
 unsigned char serial0_rx(){
-  return 0;
+  while( !(UCSR0A & (1 << RXC0)) );
+  return UDR0;
 }
 
 //! Receive a byte.
@@ -14,6 +18,8 @@ unsigned char serial1_rx(){
 
 //! Transmit a byte.
 void serial0_tx(unsigned char x){
+  while (!(UCSR0A & (1<<UDRE0)) );
+  UDR0 = x;
 }
 
 //! Transmit a byte on the second UART.
@@ -22,8 +28,10 @@ void serial1_tx(unsigned char x){
 
 //! Set the baud rate.
 void setbaud0(unsigned char rate){
+  //TODO support multiple rates.
+  #define SPEED 9600
+  
   
-  //http://mspgcc.sourceforge.net/baudrate.html
   switch(rate){
   case 1://9600 baud
     
@@ -42,6 +50,18 @@ void setbaud0(unsigned char rate){
     
     break;
   }
+  
+#define F_CPU 8000000L
+  //#define BAUD 115200L
+#define BAUD 9600L
+#include <util/setbaud.h>
+  UBRR0H = UBRRH_VALUE;
+  UBRR0L = UBRRL_VALUE;
+  
+  UCSR0C = _BV(UCSZ01) | _BV(UCSZ00);
+  UCSR0B = _BV(RXEN0) | _BV(TXEN0);
+  return;
+  
 }
 
 //! Set the baud rate of the second uart.
@@ -68,22 +88,15 @@ void setbaud1(unsigned char rate){
 }
 
 
-void msp430_init_uart0(){
+void avr_init_uart0(){
+  PORTD = _BV(PD2);
+  setbaud0(0);
+  _delay_ms(500); //takes a bit to stabilize
 }
 
 
-void msp430_init_uart1(){
+void avr_init_uart1(){
 }
 
 
 
-//! Initialization is correct.
-void msp430_init_dco_done(){
-  //Nothing to do for the 1612.
-}
-
-
-void msp430_init_dco() {
-
-}
-