3bcb3ce0eab64617aabe14d8c4413c6b10403403
[goodfet] / firmware / lib / msp430x1612.c
1 //! MSP430F1612/1611 clock and I/O definitions
2
3 #include "platform.h"
4
5 #include <signal.h>
6 #include <io.h>
7 #include <iomacros.h>
8
9
10 //! Receive a byte.
11 unsigned char serial_rx(){
12   char c;
13   
14   while(!(IFG1&URXIFG0));//wait for a byte
15   c = RXBUF0;
16   IFG1&=~URXIFG0;
17   U0TCTL &= ~URXSE;
18   
19   return c;
20 }
21
22 //! Receive a byte.
23 unsigned char serial1_rx(){
24   char c;
25   
26   while(!(IFG2&URXIFG1));//wait for a byte
27   c = RXBUF1;
28   IFG2&=~URXIFG1;
29   U1TCTL &= ~URXSE;
30   
31   return c;
32 }
33
34
35 //! Transmit a byte.
36 void serial_tx(unsigned char x){
37   while ((IFG1 & UTXIFG0) == 0); //loop until buffer is free
38   TXBUF0 = x;
39 }
40
41 //! Transmit a byte on the second UART.
42 void serial1_tx(unsigned char x){
43   while ((IFG2 & UTXIFG1) == 0); //loop until buffer is free
44   TXBUF1 = x;
45 }
46
47 //! Set the baud rate.
48 void setbaud(unsigned char rate){
49   
50   //http://mspgcc.sourceforge.net/baudrate.html
51   switch(rate){
52   case 1://9600 baud
53     UBR00=0x7F; UBR10=0x01; UMCTL0=0x5B; /* uart0 3683400Hz 9599bps */
54     break;
55   case 2://19200 baud
56     UBR00=0xBF; UBR10=0x00; UMCTL0=0xF7; /* uart0 3683400Hz 19194bps */
57     break;
58   case 3://38400 baud
59     UBR00=0x5F; UBR10=0x00; UMCTL0=0xBF; /* uart0 3683400Hz 38408bps */
60     break;
61   case 4://57600 baud
62     UBR00=0x40; UBR10=0x00; UMCTL0=0x00; /* uart0 3683400Hz 57553bps */
63     break;
64   default:
65   case 5://115200 baud
66     UBR00=0x20; UBR10=0x00; UMCTL0=0x00; /* uart0 3683400Hz 115106bps */
67     break;
68   }
69 }
70
71 //! Set the baud rate of the second uart.
72 void setbaud1(unsigned char rate){
73   
74   //http://mspgcc.sourceforge.net/baudrate.html
75   switch(rate){
76   case 1://9600 baud
77     //    UBR01=0x7F; UBR11=0x01; UMCTL1=0x5B; /* uart0 3683400Hz 9599bps */
78     break;
79   case 2://19200 baud
80     //UBR01=0xBF; UBR11=0x00; UMCTL1=0xF7; /* uart0 3683400Hz 19194bps */
81     break;
82   case 3://38400 baud
83     //UBR01=0x5F; UBR11=0x00; UMCTL1=0xBF; /* uart0 3683400Hz 38408bps */
84     break;
85   case 4://57600 baud
86     //UBR01=0x40; UBR11=0x00; UMCTL1=0x00; /* uart0 3683400Hz 57553bps */
87     break;
88   default:
89   case 5://115200 baud
90     //UBR01=0x20; UBR11=0x00; UMCTL1=0x00; /* uart0 3683400Hz 115106bps */
91     break;
92   }
93 }
94
95
96 void msp430_init_uart(){
97 }
98
99
100 void msp430_init_dco() {
101 }
102