BSP430  20141115
Board Support Package for MSP430 microcontrollers
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
serial_.h
Go to the documentation of this file.
1 /* Copyright 2012-2014, Peter A. Bigot
2  *
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  *
11  * * Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  *
15  * * Neither the name of the software nor the names of its contributors may be
16  * used to endorse or promote products derived from this software without
17  * specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
53 #ifndef BSP430_SERIAL__H
54 #define BSP430_SERIAL__H
55 
56 #include <bsp430/core.h>
57 #include <bsp430/periph.h>
58 
73 #ifndef BSP430_SERIAL_ENABLE_RESOURCE
74 #define BSP430_SERIAL_ENABLE_RESOURCE 0
75 #endif /* BSP430_SERIAL_ENABLE_RESOURCE */
76 
77 #if defined(BSP430_DOXYGEN) || (BSP430_SERIAL_ENABLE_RESOURCE - 0)
78 #include <bsp430/resource.h>
79 #endif /* BSP430_SERIAL_ENABLE_RESOURCE */
80 
84 #define BSP430_SERIAL_HAL_HPL_VARIANT_USCI 1
85 
89 #define BSP430_SERIAL_HAL_HPL_VARIANT_USCI5 2
90 
94 #define BSP430_SERIAL_HAL_HPL_VARIANT_EUSCIA 3
95 
99 #define BSP430_SERIAL_HAL_HPL_VARIANT_EUSCIB 4
100 
101 /* !BSP430! instance=usci,usci5,euscia,euscib */
102 /* !BSP430! periph=serial insert=hal_variant_hpl_macro */
103 /* BEGIN AUTOMATICALLY GENERATED CODE---DO NOT MODIFY [hal_variant_hpl_macro] */
105 #define BSP430_SERIAL_HAL_HPL_VARIANT_IS_USCI(hal_) (BSP430_SERIAL_HAL_HPL_VARIANT_USCI == BSP430_PERIPH_HAL_STATE_CFLAGS_VARIANT(hal_))
106 
110 #define BSP430_SERIAL_HAL_GET_HPL_USCI(hal_) ((BSP430_SERIAL_HAL_HPL_VARIANT_IS_USCI(hal_)) ? (hal_)->hpl.usci : (void *)0)
111 
113 #define BSP430_SERIAL_HAL_HPL_VARIANT_IS_USCI5(hal_) (BSP430_SERIAL_HAL_HPL_VARIANT_USCI5 == BSP430_PERIPH_HAL_STATE_CFLAGS_VARIANT(hal_))
114 
118 #define BSP430_SERIAL_HAL_GET_HPL_USCI5(hal_) ((BSP430_SERIAL_HAL_HPL_VARIANT_IS_USCI5(hal_)) ? (hal_)->hpl.usci5 : (void *)0)
119 
121 #define BSP430_SERIAL_HAL_HPL_VARIANT_IS_EUSCIA(hal_) (BSP430_SERIAL_HAL_HPL_VARIANT_EUSCIA == BSP430_PERIPH_HAL_STATE_CFLAGS_VARIANT(hal_))
122 
126 #define BSP430_SERIAL_HAL_GET_HPL_EUSCIA(hal_) ((BSP430_SERIAL_HAL_HPL_VARIANT_IS_EUSCIA(hal_)) ? (hal_)->hpl.euscia : (void *)0)
127 
129 #define BSP430_SERIAL_HAL_HPL_VARIANT_IS_EUSCIB(hal_) (BSP430_SERIAL_HAL_HPL_VARIANT_EUSCIB == BSP430_PERIPH_HAL_STATE_CFLAGS_VARIANT(hal_))
130 
134 #define BSP430_SERIAL_HAL_GET_HPL_EUSCIB(hal_) ((BSP430_SERIAL_HAL_HPL_VARIANT_IS_EUSCIB(hal_)) ? (hal_)->hpl.euscib : (void *)0)
135 
136 /* END AUTOMATICALLY GENERATED CODE [hal_variant_hpl_macro] */
137 /* !BSP430! end=hal_variant_hpl_macro */
138 /* !BSP430! periph=serial insert=hal_variant_hplaux_macro */
139 /* BEGIN AUTOMATICALLY GENERATED CODE---DO NOT MODIFY [hal_variant_hplaux_macro] */
143 #define BSP430_SERIAL_HAL_GET_HPLAUX_USCI(hal_) ((BSP430_SERIAL_HAL_HPL_VARIANT_IS_USCI(hal_)) ? (hal_)->hpl_aux.usci : (void *)0)
144 
148 #define BSP430_SERIAL_HAL_GET_HPLAUX_USCI5(hal_) ((BSP430_SERIAL_HAL_HPL_VARIANT_IS_USCI5(hal_)) ? (hal_)->hpl_aux.usci5 : (void *)0)
149 
153 #define BSP430_SERIAL_HAL_GET_HPLAUX_EUSCIA(hal_) ((BSP430_SERIAL_HAL_HPL_VARIANT_IS_EUSCIA(hal_)) ? (hal_)->hpl_aux.euscia : (void *)0)
154 
158 #define BSP430_SERIAL_HAL_GET_HPLAUX_EUSCIB(hal_) ((BSP430_SERIAL_HAL_HPL_VARIANT_IS_EUSCIB(hal_)) ? (hal_)->hpl_aux.euscib : (void *)0)
159 
160 /* END AUTOMATICALLY GENERATED CODE [hal_variant_hplaux_macro] */
161 /* !BSP430! end=hal_variant_hplaux_macro */
162 
179 #ifndef BSP430_SERIAL_SPI_READ_TX_BYTE
180 #define BSP430_SERIAL_SPI_READ_TX_BYTE(i_) (i_)
181 #endif /* BSP430_SERIAL_SPI_READ_TX_BYTE */
182 
183 /* Forward declarations */
184 struct sBSP430hplUSCI;
185 struct sBSP430usciHPLAux;
186 struct sBSP430hplUSCI5;
187 struct sBSP430hplEUSCIA;
188 struct sBSP430hplEUSCIB;
189 struct sBSP430serialDispatch;
190 
193 typedef struct sBSP430halSERIAL {
197 
198 #if defined(BSP430_DOXYGEN) || (BSP430_SERIAL_ENABLE_RESOURCE - 0)
199 
203 #endif /* BSP430_SERIAL_ENABLE_RESOURCE */
204 
211  union {
213  volatile void * any;
214 
216  volatile struct sBSP430hplUSCI * usci;
217 
219  volatile struct sBSP430hplUSCI5 * usci5;
220 
222  volatile struct sBSP430hplEUSCIA * euscia;
223 
225  volatile struct sBSP430hplEUSCIB * euscib;
226  } const hpl;
227 
239  union {
242  void * any;
245  struct sBSP430usciHPLAux * usci;
246  } const hpl_aux;
247 
250  uint8_t rx_byte;
251 
254  uint8_t tx_byte;
255 
267  const struct sBSP430halISRVoidChainNode * volatile rx_cbchain_ni;
268 
289  const struct sBSP430halISRVoidChainNode * volatile tx_cbchain_ni;
290 
292  unsigned long num_rx;
293 
295  unsigned long num_tx;
296 
297 #if (BSP430_SERIAL - 0)
298 
299  const struct sBSP430serialDispatch * const dispatch;
301 #endif /* BSP430_SERIAL */
303 
306 
308 struct sBSP430serialDispatch {
309 #if (configBSP430_SERIAL_ENABLE_UART - 0)
310  hBSP430halSERIAL (* openUART) (hBSP430halSERIAL hal,
311  unsigned char ctl0_byte,
312  unsigned char ctl1_byte,
313  unsigned long baud);
314  int (* uartRxByte_rh) (hBSP430halSERIAL hal);
315  int (* uartTxByte_rh) (hBSP430halSERIAL hal,
316  uint8_t c);
317  int (* uartTxData_rh) (hBSP430halSERIAL hal,
318  const uint8_t * data,
319  size_t len);
320  int (* uartTxASCIIZ_rh) (hBSP430halSERIAL hal, const char * str);
321 #endif /* configBSP430_SERIAL_ENABLE_UART */
322 #if (configBSP430_SERIAL_ENABLE_SPI - 0)
323  hBSP430halSERIAL (* openSPI) (hBSP430halSERIAL hal,
324  unsigned char ctl0_byte,
325  unsigned char ctl1_byte,
326  unsigned int prescaler);
327  int (* spiTxRx_rh) (hBSP430halSERIAL hal, const uint8_t * tx_data, size_t tx_len, size_t rx_len, uint8_t * rx_data);
328 #endif /* configBSP430_SERIAL_ENABLE_SPI */
329 #if (configBSP430_SERIAL_ENABLE_I2C - 0)
330  hBSP430halSERIAL (* openI2C) (hBSP430halSERIAL hal,
331  unsigned char ctl0_byte,
332  unsigned char ctl1_byte,
333  unsigned int prescaler);
334  int (* i2cSetAddresses_rh) (hBSP430halSERIAL hal, int own_address, int slave_address);
335  int (* i2cRxData_rh) (hBSP430halSERIAL hal, uint8_t * rx_data, size_t rx_len);
336  int (* i2cTxData_rh) (hBSP430halSERIAL hal, const uint8_t * tx_data, size_t tx_len);
337 #endif /* configBSP430_SERIAL_ENABLE_I2C */
338  int (* setReset_rh) (hBSP430halSERIAL hal, int resetp);
339  int (* setHold_rh) (hBSP430halSERIAL hal, int holdp);
340  int (* close) (hBSP430halSERIAL hal);
341  void (* wakeupTransmit_rh) (hBSP430halSERIAL hal);
342  void (* flush_ni) (hBSP430halSERIAL hal);
343  unsigned long (* rate) (hBSP430halSERIAL hal);
344 };
347 #endif /* BSP430_SERIAL__H */
volatile struct sBSP430hplUSCI5 * usci5
Definition: serial_.h:219
uint8_t rx_byte
Definition: serial_.h:250
struct sBSP430usciHPLAux * usci
Definition: serial_.h:245
Definition: resource.h:78
Common header included by all BSP430 leaf headers.
const struct sBSP430halISRVoidChainNode *volatile rx_cbchain_ni
Definition: serial_.h:267
volatile struct sBSP430hplEUSCIA * euscia
Definition: serial_.h:222
volatile struct sBSP430hplUSCI * usci
Definition: serial_.h:216
uint8_t tx_byte
Definition: serial_.h:254
Definition: serial_.h:193
unsigned long num_tx
Definition: serial_.h:295
Definition: periph.h:425
volatile struct sBSP430hplEUSCIB * euscib
Definition: serial_.h:225
unsigned long num_rx
Definition: serial_.h:292
struct sBSP430halSERIAL * hBSP430halSERIAL
Definition: serial_.h:305
union sBSP430halSERIAL::@63 hpl
Generic peripheral support for MSP430 MCUs.
Definition: usci.h:117
Support for resource management in BSP430.
volatile void * any
Definition: serial_.h:213
const struct sBSP430halISRVoidChainNode *volatile tx_cbchain_ni
Definition: serial_.h:289
Definition: usci5.h:108
struct sBSP430halSERIAL sBSP430halSERIAL
Definition: eusci.h:149
sBSP430hplHALStatePrefix hal_state
Definition: serial_.h:196
sBSP430resource resource
Definition: serial_.h:202
union sBSP430halSERIAL::@64 hpl_aux
Definition: periph.h:272
void * any
Definition: serial_.h:242
Definition: eusci.h:111