Main Page | File List | Globals

serial.c

Go to the documentation of this file.
00001 /* serial.c --- 
00002  * 
00003  * Filename: serial.c
00004  * Description: 
00005  * Author: Bryce Himebaugh
00006  * Maintainer: 
00007  * Created: Mon Oct 16 10:58:20 2006
00008  * Version: 
00009  * Last-Updated: 
00010  *           By: 
00011  *     Update #: 0
00012  * Keywords: 
00013  * Compatibility: 
00014  * 
00015  */
00016 
00017 /* Commentary: 
00018  * 
00019  * 
00020  * 
00021  */
00022 
00023 /* Change log:
00024  * 
00025  * 
00026  */
00027 
00028 /* This program is free software; you can redistribute it and/or modify
00029  * it under the terms of the GNU General Public License as published by
00030  * the Free Software Foundation; either version 2, or (at your option)
00031  * any later version.
00032  * 
00033  * This program is distributed in the hope that it will be useful,
00034  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00035  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00036  * GNU General Public License for more details.
00037  * 
00038  * You should have received a copy of the GNU General Public License
00039  * along with this program; see the file COPYING.  If not, write to the
00040  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00041  * Boston, MA 02111-1307, USA.
00042  */
00043 
00044 /* Code: */
00045 #include <msp430x16x.h>
00046 #include <signal.h>
00047 #include <stdio.h>
00048 #include "vcsbsp.h"
00049 
00050 queue_t uart0_rx_q;
00051 queue_t uart1_rx_q;
00052 
00053 queue_t uart0_tx_q;
00054 queue_t uart1_tx_q;
00055 
00056 void init_serial_0(void) {
00057   int temp;
00058 
00059   init_queue(&uart0_rx_q);
00060   init_queue(&uart0_tx_q);
00061   
00062   // 115200 baud (Connected to Host)
00063   UCTL0 = CHAR + SWRST;
00064   UTCTL0 = SSEL1 + SSEL0;
00065   UBR00=0x45; 
00066   UBR10=0x00; 
00067   UMCTL0=0xAA;
00068   ME1 = 0xC0;
00069   UCTL0 = CHAR;
00070   temp=RXBUF0;  // Flush the RX buffer 
00071   temp=RXBUF0;  
00072   IE1|=URXIE0;
00073 }
00074 
00075 void init_serial_1(void) {
00076   int temp;
00077 
00078   init_queue(&uart1_rx_q);
00079   init_queue(&uart1_tx_q);
00080 
00081   // 19200 Baud (GPS Receiver Channel) 
00082   UCTL1 = CHAR + SWRST;
00083   UTCTL1 = SSEL1 + SSEL0;
00084   UBR01=0xA0; 
00085   UBR11=0x01;
00086   UMCTL1=0x5B; 
00087   ME2 = 0x30;
00088   UCTL1 = CHAR;
00089   temp=RXBUF1;  // Flush the RX buffer 
00090   temp=RXBUF1;  
00091   IE2|=URXIE1;  // Turn on the RX interrupt 
00092 }
00093 
00094 // UART0 Handlers 
00095 
00096 // U0 Vectors 
00097 interrupt (UART0RX_VECTOR) uart0_rx_handler(void) {
00098   enqueue(&uart0_rx_q,RXBUF0);
00099 }
00100 
00101 interrupt (UART0TX_VECTOR) uart0_tx_handler(void) {
00102   char temp;
00103   if ((temp=dequeue(&uart0_tx_q))==0) {
00104     IE1&=~UTXIE0;                       // Switch off the TX interrupt;
00105   }
00106   else {
00107     TXBUF0=temp;
00108   }
00109 }
00110 
00111 char getchar(void) {
00112   char ret_val = 0;
00113   while ((ret_val=dequeue(&uart0_rx_q))==0);
00114   return ret_val;
00115 }
00116 
00117 char getchar_nb(void) {
00118   return (dequeue(&uart0_rx_q));
00119 }
00120 
00121 int putchar(int in_char) {
00122   enqueue(&uart0_tx_q,in_char);
00123   return (0);
00124 }
00125 
00126 int flush_uart0(void) {
00127   int ret_val=0;
00128   if (!(IE1&UTXIE0)) {
00129     ret_val=1;
00130     IE1|=UTXIE0;          // Turn on the TX IRQ
00131     IFG1|=UTXIFG0;        // Set the Interrupt flag to start the TX                
00132   }
00133   return (ret_val);
00134 }
00135 
00136 
00137 // UART1 Handlers
00138 
00139 interrupt (UART1RX_VECTOR) uart1_rx_handler(void) {
00140   enqueue(&uart1_rx_q,RXBUF1);
00141   wiggler_p3();
00142 }
00143 
00144 interrupt (UART1TX_VECTOR) uart1_tx_handler(void) {
00145   char temp;
00146   if ((temp=dequeue(&uart1_tx_q))==0) {
00147     IE2&=~UTXIE1;                       // Switch off the TX interrupt;
00148   }
00149   else {
00150     TXBUF1=temp;
00151   }
00152 }
00153 
00154 char getchar_gps(void) {
00155   char ret_val = 0;
00156   while ((ret_val=dequeue(&uart1_rx_q))==0);
00157   return ret_val;
00158 }
00159 
00160 char getchar_gps_nb(void) {
00161   return (dequeue(&uart1_rx_q));
00162 }
00163 
00164 int putchar_gps(int in_char) {
00165   enqueue(&uart1_tx_q,in_char);
00166   return (0);
00167 }
00168 
00169 int flush_uart1(void) {
00170   int ret_val=0;
00171   if (!(IE2&UTXIE1)) {
00172     ret_val=1;
00173     IE2|=UTXIE1;          // Turn on the TX IRQ
00174     IFG2|=UTXIFG1;        // Set the Interrupt flag to start the TX                
00175   }
00176   return (ret_val);
00177 }
00178 
00179 /* serial.c ends here */

Generated on Fri Nov 3 14:40:12 2006 for hwiflib by  doxygen 1.3.9.1