Contiki 2.6
|
00001 /* 00002 Copyright 2007, Freie Universitaet Berlin. All rights reserved. 00003 00004 These sources were developed at the Freie Universität Berlin, Computer 00005 Systems and Telematics group. 00006 00007 Redistribution and use in source and binary forms, with or without 00008 modification, are permitted provided that the following conditions are 00009 met: 00010 00011 - Redistributions of source code must retain the above copyright 00012 notice, this list of conditions and the following disclaimer. 00013 00014 - Redistributions in binary form must reproduce the above copyright 00015 notice, this list of conditions and the following disclaimer in the 00016 documentation and/or other materials provided with the distribution. 00017 00018 - Neither the name of Freie Universitaet Berlin (FUB) nor the names of its 00019 contributors may be used to endorse or promote products derived from 00020 this software without specific prior written permission. 00021 00022 This software is provided by FUB and the contributors on an "as is" 00023 basis, without any representations or warranties of any kind, express 00024 or implied including, but not limited to, representations or 00025 warranties of non-infringement, merchantability or fitness for a 00026 particular purpose. In no event shall FUB or contributors be liable 00027 for any direct, indirect, incidental, special, exemplary, or 00028 consequential damages (including, but not limited to, procurement of 00029 substitute goods or services; loss of use, data, or profits; or 00030 business interruption) however caused and on any theory of liability, 00031 whether in contract, strict liability, or tort (including negligence 00032 or otherwise) arising in any way out of the use of this software, even 00033 if advised of the possibility of such damage. 00034 00035 This implementation was developed by the CST group at the FUB. 00036 00037 For documentation and questions please use the web site 00038 http://scatterweb.mi.fu-berlin.de and the mailinglist 00039 scatterweb@lists.spline.inf.fu-berlin.de (subscription via the Website). 00040 Berlin, 2007 00041 */ 00042 00043 /** 00044 * @addtogroup interfaces 00045 * @{ */ 00046 00047 /** 00048 * @defgroup uart1 UART1 00049 * The UART module multiplexes differenct protocol on the MSB's UART1 00050 * interface. Currently RS232 and SPI are supported. 00051 * @{ 00052 */ 00053 00054 /** 00055 * \file Header file for for the MSB430 UART driver. 00056 * \author Michael Baar <baar@inf.fu-berlin.de> 00057 */ 00058 00059 #ifndef MSB430_UART1_H 00060 #define MSB430_UART1_H 00061 00062 #define UART_RX RXBUF1 00063 #define UART_TX TXBUF1 00064 #define UART_RESET_RX() do { U1IFG &= ~URXIFG1; } while(0) 00065 #define UART_RESET_RXTX() do { U1IFG &= ~(URXIFG1 | UTXIFG1); } while(0) 00066 #define UART_WAIT_RX() while((U1IFG & URXIFG1) == 0) { _NOP(); } 00067 #define UART_WAIT_TX() while((U1IFG & UTXIFG1) == 0) { _NOP(); } 00068 #define UART_WAIT_TXDONE() while((UTCTL1 & TXEPT) == 0) { _NOP(); } 00069 00070 /** 00071 * @brief Operating state 00072 */ 00073 extern volatile unsigned char uart_mode; 00074 extern volatile unsigned char uart_lockcnt; 00075 00076 /** 00077 * @name UART mode flags 00078 * @{ 00079 */ 00080 #define UART_MODE_RS232 (0x00u) ///< RS232 mode 00081 #define UART_MODE_SPI (0x01u) ///< SPI mode 00082 #define UART_MODE_DEFAULT UART_MODE_RS232 00083 #define UART_NUM_MODES (UART_MODE_SPI + 1) ///< Highest mode number 00084 #define UART_MODE_RESET (0xFFu) ///< reset with current settings 00085 /** @} */ 00086 00087 #define UART_WAIT_LOCK(x) ((uart_mode != x) && (uart_lockcnt)) 00088 #define UART_MODE_IS(x) (uart_mode == x) 00089 00090 typedef int(*uart_handler_t)(unsigned char); 00091 00092 /** 00093 * \brief Initialize the UART module 00094 * 00095 * This function is called from the boot up code to 00096 * initalize the UART module. 00097 */ 00098 void uart_init(void); 00099 00100 void uart_set_speed(unsigned, unsigned, unsigned, unsigned); 00101 void uart_set_handler(unsigned, uart_handler_t); 00102 int uart_lock(unsigned); 00103 int uart_lock_wait(unsigned); 00104 int uart_unlock(unsigned); 00105 void uart_set_mode(unsigned); 00106 int uart_get_mode(void); 00107 00108 #endif /* !MSB430_UART1_H */ 00109 00110 /** @} */ 00111 /** @} */