Contiki 2.5
msb430-uart1.h
1 /*
2 Copyright 2007, Freie Universitaet Berlin. All rights reserved.
3 
4 These sources were developed at the Freie Universität Berlin, Computer
5 Systems and Telematics group.
6 
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are
9 met:
10 
11 - Redistributions of source code must retain the above copyright
12 notice, this list of conditions and the following disclaimer.
13 
14 - Redistributions in binary form must reproduce the above copyright
15 notice, this list of conditions and the following disclaimer in the
16 documentation and/or other materials provided with the distribution.
17 
18 - Neither the name of Freie Universitaet Berlin (FUB) nor the names of its
19 contributors may be used to endorse or promote products derived from
20 this software without specific prior written permission.
21 
22 This software is provided by FUB and the contributors on an "as is"
23 basis, without any representations or warranties of any kind, express
24 or implied including, but not limited to, representations or
25 warranties of non-infringement, merchantability or fitness for a
26 particular purpose. In no event shall FUB or contributors be liable
27 for any direct, indirect, incidental, special, exemplary, or
28 consequential damages (including, but not limited to, procurement of
29 substitute goods or services; loss of use, data, or profits; or
30 business interruption) however caused and on any theory of liability,
31 whether in contract, strict liability, or tort (including negligence
32 or otherwise) arising in any way out of the use of this software, even
33 if advised of the possibility of such damage.
34 
35 This implementation was developed by the CST group at the FUB.
36 
37 For documentation and questions please use the web site
38 http://scatterweb.mi.fu-berlin.de and the mailinglist
39 scatterweb@lists.spline.inf.fu-berlin.de (subscription via the Website).
40 Berlin, 2007
41 */
42 
43 /**
44  * @addtogroup interfaces
45  * @{ */
46 
47 /**
48  * @defgroup uart1 UART1
49  * The UART module multiplexes differenct protocol on the MSB's UART1
50  * interface. Currently RS232 and SPI are supported.
51  * @{
52  */
53 
54 /**
55  * \file Header file for for the MSB430 UART driver.
56  * \author Michael Baar <baar@inf.fu-berlin.de>
57  */
58 
59 #ifndef MSB430_UART1_H
60 #define MSB430_UART1_H
61 
62 #define UART_RX RXBUF1
63 #define UART_TX TXBUF1
64 #define UART_RESET_RX() do { U1IFG &= ~URXIFG1; } while(0)
65 #define UART_RESET_RXTX() do { U1IFG &= ~(URXIFG1 | UTXIFG1); } while(0)
66 #define UART_WAIT_RX() while((U1IFG & URXIFG1) == 0) { _NOP(); }
67 #define UART_WAIT_TX() while((U1IFG & UTXIFG1) == 0) { _NOP(); }
68 #define UART_WAIT_TXDONE() while((UTCTL1 & TXEPT) == 0) { _NOP(); }
69 
70 /**
71  * @brief Operating state
72  */
73 extern volatile unsigned char uart_mode;
74 extern volatile unsigned char uart_lockcnt;
75 
76 /**
77  * @name UART mode flags
78  * @{
79  */
80 #define UART_MODE_RS232 (0x00u) ///< RS232 mode
81 #define UART_MODE_SPI (0x01u) ///< SPI mode
82 #define UART_MODE_DEFAULT UART_MODE_RS232
83 #define UART_NUM_MODES (UART_MODE_SPI + 1) ///< Highest mode number
84 #define UART_MODE_RESET (0xFFu) ///< reset with current settings
85 /** @} */
86 
87 #define UART_WAIT_LOCK(x) ((uart_mode != x) && (uart_lockcnt))
88 #define UART_MODE_IS(x) (uart_mode == x)
89 
90 typedef int(*uart_handler_t)(unsigned char);
91 
92 /**
93  * \brief Initialize the UART module
94  *
95  * This function is called from the boot up code to
96  * initalize the UART module.
97  */
98 void uart_init(void);
99 
100 void uart_set_speed(unsigned, unsigned, unsigned, unsigned);
101 void uart_set_handler(unsigned, uart_handler_t);
102 int uart_lock(unsigned);
103 int uart_lock_wait(unsigned);
104 int uart_unlock(unsigned);
105 void uart_set_mode(unsigned);
106 int uart_get_mode(void);
107 
108 #endif /* !MSB430_UART1_H */
109 
110 /** @} */
111 /** @} */