1ed8840fed53e3cf99d88f024b95c4ed8f46e4a7
[goodfet] / firmware / lib / atmega168.c
1 //! MSP430F1612/1611 clock and I/O definitions
2
3 #include "platform.h"
4
5 #include <avr/io.h>
6 #include <util/delay.h>
7
8 //! Receive a byte.
9 unsigned char serial0_rx(){
10   while( !(UCSR0A & (1 << RXC0)) );
11   return UDR0;
12 }
13
14 //! Receive a byte.
15 unsigned char serial1_rx(){
16   return 0;
17 }
18
19 //! Transmit a byte.
20 void serial0_tx(unsigned char x){
21   while (!(UCSR0A & (1<<UDRE0)) );
22   UDR0 = x;
23 }
24
25 //! Transmit a byte on the second UART.
26 void serial1_tx(unsigned char x){
27 }
28
29 //! Set the baud rate.
30 void setbaud0(unsigned char rate){
31   //TODO support multiple rates.
32   #define SPEED 9600
33   
34   
35   switch(rate){
36   case 1://9600 baud
37     
38     break;
39   case 2://19200 baud
40     
41     break;
42   case 3://38400 baud
43     
44     break;
45   case 4://57600 baud
46     
47     break;
48   default:
49   case 5://115200 baud
50     
51     break;
52   }
53   
54   uint16_t bittimer=( F_CPU / SPEED / 16 ) - 1;
55   UBRR0H = (unsigned char) (bittimer >> 8);
56   UBRR0L = (unsigned char) bittimer;
57   
58   
59   /* set the framing to 8N1 */
60   UCSR0C = (3 << UCSZ00);
61   /* Engage! */
62   UCSR0B = (1 << RXEN0) | (1 << TXEN0);
63   return;
64   
65 }
66
67 //! Set the baud rate of the second uart.
68 void setbaud1(unsigned char rate){
69   //http://mspgcc.sourceforge.net/baudrate.html
70   switch(rate){
71   case 1://9600 baud
72     
73     break;
74   case 2://19200 baud
75     
76     break;
77   case 3://38400 baud
78     
79     break;
80   case 4://57600 baud
81     
82     break;
83   default:
84   case 5://115200 baud
85     
86     break;
87   }
88 }
89
90
91 void msp430_init_uart0(){
92 }
93
94
95 void msp430_init_uart1(){
96 }
97
98
99
100 //! Initialization is correct.
101 void msp430_init_dco_done(){
102   //Nothing to do for the AVR w/ xtal.
103 }
104
105
106 void msp430_init_dco() {
107   //
108 }
109