Trying to get 2618 going.
[goodfet] / firmware / lib / msp430x2618.c
1 //! MSP430F2618 clock and I/O definitions
2
3 // Ought to be portable to other 2xx chips.
4 // 2274 looks particularly appealing.
5
6 #include "platform.h"
7
8 #include <signal.h>
9 #include <io.h>
10 #include <iomacros.h>
11
12
13 //! Receive a byte.
14 unsigned char serial_rx(){
15   char c;
16   
17   while(!(IFG2&UCA0RXIFG));//wait for a byte
18   c = UCA0RXBUF;
19   IFG2&=~UCA0RXIFG;
20   
21   //UCA0CTL1 &= ~UCA0RXSE;
22   return c;
23 }
24
25 //! Receive a byte.
26 unsigned char serial1_rx(){
27   //TODO
28   return 00;
29 }
30
31 //! Transmit a byte.
32 void serial_tx(unsigned char x){
33   while ((IFG2 & UCA0TXIFG) == 0); //loop until buffer is free
34   UCA0TXBUF = x;        /* send the character */
35   while(!(IFG2 & UCA0TXIFG));
36 }
37 //! Transmit a byte.
38 void serial_tx_old(unsigned char x){
39   while ((IFG2 & UCA0TXIFG) == 0); //loop until buffer is free
40   UCA0TXBUF = x;        /* send the character */
41   while(!(IFG2 & UCA0TXIFG));
42 }
43
44 //! Transmit a byte on the second UART.
45 void serial1_tx(unsigned char x){
46
47 }
48
49 //! Set the baud rate.
50 void setbaud(unsigned char rate){
51   
52   //http://mspgcc.sourceforge.net/baudrate.html
53   switch(rate){
54   case 1://9600 baud
55     
56     break;
57   case 2://19200 baud
58     
59     break;
60   case 3://38400 baud
61     
62     break;
63   case 4://57600 baud
64     
65     break;
66   default:
67   case 5://115200 baud
68     
69     break;
70   }
71 }
72
73 //! Set the baud rate of the second uart.
74 void setbaud1(unsigned char rate){
75   
76   //http://mspgcc.sourceforge.net/baudrate.html
77   switch(rate){
78   case 1://9600 baud
79     
80     break;
81   case 2://19200 baud
82     
83     break;
84   case 3://38400 baud
85     
86     break;
87   case 4://57600 baud
88     
89     break;
90   default:
91   case 5://115200 baud
92     
93     break;
94   }
95 }
96
97
98
99 //19200
100 #define BAUD0EN 0x1b
101 #define BAUD1EN 0x00
102
103
104 void msp430_init_uart(){
105
106   // Serial on P3.4, P3.5                                                                                                                                                 
107   P3SEL |= BIT4 + BIT5;
108   P3DIR |= BIT4;
109
110   //UCA0CTL1 |= UCSWRST;                    /* disable UART */                                                                                                            
111
112   UCA0CTL0 = 0x00;
113   //UCA0CTL0 |= UCMSB ;                                                                                                                                                   
114   UCA0CTL1 |= UCSSEL_2;                     // SMCLK                                                                                                                      
115   UCA0BR0 = BAUD0EN;                        // 115200                                                                                                                     
116   UCA0BR1 = BAUD1EN;
117   UCA0MCTL = 0;                             // Modulation UCBRSx = 5                                                                                                      
118   UCA0CTL1 &= ~UCSWRST;                     // **Initialize USCI state machine**                                                                                          
119
120
121   //Leave this commented!                                                                                                                                                 
122   //Interrupt is handled by target code, not by bootloader.                                                                                                               
123   //IE2 |= UCA0RXIE;         
124
125 }
126
127 //external resistor
128 #define DCOR 1
129 void msp430_init_dco() {
130   BCSCTL1 = CALBC1_16MHZ;
131   DCOCTL = CALDCO_16MHZ;  
132   return;
133 }
134