BSP430  20141115
Board Support Package for MSP430 microcontrollers
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
usci.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 
88 /* !BSP430! periph=usci */
89 /* !BSP430! instance=USCI_A0,USCI_A1,USCI_B0,USCI_B1 */
90 
91 #ifndef BSP430_PERIPH_USCI_H
92 #define BSP430_PERIPH_USCI_H
93 
94 #include <bsp430/periph.h>
95 #include <bsp430/serial_.h>
96 
104 #define BSP430_MODULE_USCI defined(__MSP430_HAS_USCI__)
105 
106 #if defined(BSP430_DOXYGEN) || (BSP430_MODULE_USCI - 0)
107 
112 #ifndef BSP430_USCI_UART_MAX_BAUD
113 #define BSP430_USCI_UART_MAX_BAUD 1000000UL
114 #endif /* BSP430_USCI_UART_MAX_BAUD */
115 
117 typedef struct sBSP430hplUSCI {
118  unsigned char ctl0; /* 0x00 */
119  unsigned char ctl1; /* 0x01 */
120  unsigned char br0; /* 0x02 */
121  unsigned char br1; /* 0x03 */
122  unsigned char mctl; /* 0x04 */
123  unsigned char stat; /* 0x05 */
124  unsigned char rxbuf; /* 0x06 */
125  unsigned char txbuf; /* 0x07 */
127 
129 #define BSP430_PERIPH_USCI_A0_BASEADDRESS_ 0x0060
130 #define BSP430_PERIPH_USCI_A1_BASEADDRESS_ 0x00d0
131 #define BSP430_PERIPH_USCI_B0_BASEADDRESS_ 0x0068
132 #define BSP430_PERIPH_USCI_B1_BASEADDRESS_ 0x00d8
133  /* DOXYGEN_INTERNAL */
134 
135 /* !BSP430! periph=serial insert=hal_decl */
136 /* BEGIN AUTOMATICALLY GENERATED CODE---DO NOT MODIFY [hal_decl] */
153 #ifndef configBSP430_HAL_USCI_A0
154 #define configBSP430_HAL_USCI_A0 0
155 #endif /* configBSP430_HAL_USCI_A0 */
156 
158 #if (configBSP430_HAL_USCI_A0 - 0)
159 /* You do not need to know about this */
160 extern sBSP430halSERIAL xBSP430hal_USCI_A0_;
161 #endif /* configBSP430_HAL_USCI_A0 */
162 
170 #if defined(BSP430_DOXYGEN) || (configBSP430_HAL_USCI_A0 - 0)
171 #define BSP430_HAL_USCI_A0 (&xBSP430hal_USCI_A0_)
172 #endif /* configBSP430_HAL_USCI_A0 */
173 
190 #ifndef configBSP430_HAL_USCI_A1
191 #define configBSP430_HAL_USCI_A1 0
192 #endif /* configBSP430_HAL_USCI_A1 */
193 
195 #if (configBSP430_HAL_USCI_A1 - 0)
196 /* You do not need to know about this */
197 extern sBSP430halSERIAL xBSP430hal_USCI_A1_;
198 #endif /* configBSP430_HAL_USCI_A1 */
199 
207 #if defined(BSP430_DOXYGEN) || (configBSP430_HAL_USCI_A1 - 0)
208 #define BSP430_HAL_USCI_A1 (&xBSP430hal_USCI_A1_)
209 #endif /* configBSP430_HAL_USCI_A1 */
210 
227 #ifndef configBSP430_HAL_USCI_B0
228 #define configBSP430_HAL_USCI_B0 0
229 #endif /* configBSP430_HAL_USCI_B0 */
230 
232 #if (configBSP430_HAL_USCI_B0 - 0)
233 /* You do not need to know about this */
234 extern sBSP430halSERIAL xBSP430hal_USCI_B0_;
235 #endif /* configBSP430_HAL_USCI_B0 */
236 
244 #if defined(BSP430_DOXYGEN) || (configBSP430_HAL_USCI_B0 - 0)
245 #define BSP430_HAL_USCI_B0 (&xBSP430hal_USCI_B0_)
246 #endif /* configBSP430_HAL_USCI_B0 */
247 
264 #ifndef configBSP430_HAL_USCI_B1
265 #define configBSP430_HAL_USCI_B1 0
266 #endif /* configBSP430_HAL_USCI_B1 */
267 
269 #if (configBSP430_HAL_USCI_B1 - 0)
270 /* You do not need to know about this */
271 extern sBSP430halSERIAL xBSP430hal_USCI_B1_;
272 #endif /* configBSP430_HAL_USCI_B1 */
273 
281 #if defined(BSP430_DOXYGEN) || (configBSP430_HAL_USCI_B1 - 0)
282 #define BSP430_HAL_USCI_B1 (&xBSP430hal_USCI_B1_)
283 #endif /* configBSP430_HAL_USCI_B1 */
284 
285 /* END AUTOMATICALLY GENERATED CODE [hal_decl] */
286 /* !BSP430! end=hal_decl */
287 /* !BSP430! periph=usci */
288 
289 /* !BSP430! insert=periph_decl */
290 /* BEGIN AUTOMATICALLY GENERATED CODE---DO NOT MODIFY [periph_decl] */
306 #ifndef configBSP430_HPL_USCI_A0
307 #define configBSP430_HPL_USCI_A0 (configBSP430_HAL_USCI_A0 - 0)
308 #endif /* configBSP430_HPL_USCI_A0 */
309 
310 #if (configBSP430_HAL_USCI_A0 - 0) && ! (configBSP430_HPL_USCI_A0 - 0)
311 #warning configBSP430_HAL_USCI_A0 requested without configBSP430_HPL_USCI_A0
312 #endif /* HAL and not HPL */
313 
320 #if defined(BSP430_DOXYGEN) || (configBSP430_HPL_USCI_A0 - 0)
321 #define BSP430_PERIPH_USCI_A0 ((tBSP430periphHandle)(BSP430_PERIPH_USCI_A0_BASEADDRESS_))
322 #endif /* configBSP430_HPL_USCI_A0 */
323 
339 #ifndef configBSP430_HPL_USCI_A1
340 #define configBSP430_HPL_USCI_A1 (configBSP430_HAL_USCI_A1 - 0)
341 #endif /* configBSP430_HPL_USCI_A1 */
342 
343 #if (configBSP430_HAL_USCI_A1 - 0) && ! (configBSP430_HPL_USCI_A1 - 0)
344 #warning configBSP430_HAL_USCI_A1 requested without configBSP430_HPL_USCI_A1
345 #endif /* HAL and not HPL */
346 
353 #if defined(BSP430_DOXYGEN) || (configBSP430_HPL_USCI_A1 - 0)
354 #define BSP430_PERIPH_USCI_A1 ((tBSP430periphHandle)(BSP430_PERIPH_USCI_A1_BASEADDRESS_))
355 #endif /* configBSP430_HPL_USCI_A1 */
356 
372 #ifndef configBSP430_HPL_USCI_B0
373 #define configBSP430_HPL_USCI_B0 (configBSP430_HAL_USCI_B0 - 0)
374 #endif /* configBSP430_HPL_USCI_B0 */
375 
376 #if (configBSP430_HAL_USCI_B0 - 0) && ! (configBSP430_HPL_USCI_B0 - 0)
377 #warning configBSP430_HAL_USCI_B0 requested without configBSP430_HPL_USCI_B0
378 #endif /* HAL and not HPL */
379 
386 #if defined(BSP430_DOXYGEN) || (configBSP430_HPL_USCI_B0 - 0)
387 #define BSP430_PERIPH_USCI_B0 ((tBSP430periphHandle)(BSP430_PERIPH_USCI_B0_BASEADDRESS_))
388 #endif /* configBSP430_HPL_USCI_B0 */
389 
405 #ifndef configBSP430_HPL_USCI_B1
406 #define configBSP430_HPL_USCI_B1 (configBSP430_HAL_USCI_B1 - 0)
407 #endif /* configBSP430_HPL_USCI_B1 */
408 
409 #if (configBSP430_HAL_USCI_B1 - 0) && ! (configBSP430_HPL_USCI_B1 - 0)
410 #warning configBSP430_HAL_USCI_B1 requested without configBSP430_HPL_USCI_B1
411 #endif /* HAL and not HPL */
412 
419 #if defined(BSP430_DOXYGEN) || (configBSP430_HPL_USCI_B1 - 0)
420 #define BSP430_PERIPH_USCI_B1 ((tBSP430periphHandle)(BSP430_PERIPH_USCI_B1_BASEADDRESS_))
421 #endif /* configBSP430_HPL_USCI_B1 */
422 
423 /* END AUTOMATICALLY GENERATED CODE [periph_decl] */
424 /* !BSP430! end=periph_decl */
425 
426 /* !BSP430! insert=hpl_decl */
427 /* BEGIN AUTOMATICALLY GENERATED CODE---DO NOT MODIFY [hpl_decl] */
435 #if defined(BSP430_DOXYGEN) || (configBSP430_HPL_USCI_A0 - 0)
436 #define BSP430_HPL_USCI_A0 ((volatile sBSP430hplUSCI *)BSP430_PERIPH_USCI_A0)
437 #endif /* configBSP430_HPL_USCI_A0 */
438 
446 #if defined(BSP430_DOXYGEN) || (configBSP430_HPL_USCI_A1 - 0)
447 #define BSP430_HPL_USCI_A1 ((volatile sBSP430hplUSCI *)BSP430_PERIPH_USCI_A1)
448 #endif /* configBSP430_HPL_USCI_A1 */
449 
457 #if defined(BSP430_DOXYGEN) || (configBSP430_HPL_USCI_B0 - 0)
458 #define BSP430_HPL_USCI_B0 ((volatile sBSP430hplUSCI *)BSP430_PERIPH_USCI_B0)
459 #endif /* configBSP430_HPL_USCI_B0 */
460 
468 #if defined(BSP430_DOXYGEN) || (configBSP430_HPL_USCI_B1 - 0)
469 #define BSP430_HPL_USCI_B1 ((volatile sBSP430hplUSCI *)BSP430_PERIPH_USCI_B1)
470 #endif /* configBSP430_HPL_USCI_B1 */
471 
472 /* END AUTOMATICALLY GENERATED CODE [hpl_decl] */
473 /* !BSP430! end=hpl_decl */
474 
475 /* !BSP430! instance=0,1 */
476 /* !BSP430! insert=hal_usci_isr_decl */
477 /* BEGIN AUTOMATICALLY GENERATED CODE---DO NOT MODIFY [hal_usci_isr_decl] */
494 #ifndef configBSP430_HAL_USCI_AB0RX_ISR
495 #define configBSP430_HAL_USCI_AB0RX_ISR ((configBSP430_HAL_USCI_A0 - 0) || (configBSP430_HAL_USCI_B0 - 0))
496 #endif /* configBSP430_HAL_USCI_AB0RX_ISR */
497 
498 #if ((configBSP430_HAL_0_ISR - 0) \
499  && ! ((configBSP430_HAL_USCI_A0RX - 0) | (configBSP430_HAL_USCI_B0 - 0)))
500 #warning configBSP430_HAL_USCI_AB0RX_ISR requested without configBSP430_HAL_USCI_A0 or configBSP430_HAL_USCI_B0
501 #endif /* HAL_ISR and not HAL */
502 
519 #ifndef configBSP430_HAL_USCI_AB0TX_ISR
520 #define configBSP430_HAL_USCI_AB0TX_ISR ((configBSP430_HAL_USCI_A0 - 0) | (configBSP430_HAL_USCI_B0 - 0))
521 #endif /* configBSP430_HAL_USCI_AB0TX_ISR */
522 
523 #if ((configBSP430_HAL_0_ISR - 0) \
524  && ! ((configBSP430_HAL_USCI_A0TX - 0) | (configBSP430_HAL_USCI_B0 - 0)))
525 #warning configBSP430_HAL_USCI_AB0TX_ISR requested without configBSP430_HAL_USCI_A0 or configBSP430_HAL_USCI_B0
526 #endif /* HAL_ISR and not HAL */
527 
544 #ifndef configBSP430_HAL_USCI_AB1RX_ISR
545 #define configBSP430_HAL_USCI_AB1RX_ISR ((configBSP430_HAL_USCI_A1 - 0) || (configBSP430_HAL_USCI_B1 - 0))
546 #endif /* configBSP430_HAL_USCI_AB1RX_ISR */
547 
548 #if ((configBSP430_HAL_1_ISR - 0) \
549  && ! ((configBSP430_HAL_USCI_A1RX - 0) | (configBSP430_HAL_USCI_B1 - 0)))
550 #warning configBSP430_HAL_USCI_AB1RX_ISR requested without configBSP430_HAL_USCI_A1 or configBSP430_HAL_USCI_B1
551 #endif /* HAL_ISR and not HAL */
552 
569 #ifndef configBSP430_HAL_USCI_AB1TX_ISR
570 #define configBSP430_HAL_USCI_AB1TX_ISR ((configBSP430_HAL_USCI_A1 - 0) | (configBSP430_HAL_USCI_B1 - 0))
571 #endif /* configBSP430_HAL_USCI_AB1TX_ISR */
572 
573 #if ((configBSP430_HAL_1_ISR - 0) \
574  && ! ((configBSP430_HAL_USCI_A1TX - 0) | (configBSP430_HAL_USCI_B1 - 0)))
575 #warning configBSP430_HAL_USCI_AB1TX_ISR requested without configBSP430_HAL_USCI_A1 or configBSP430_HAL_USCI_B1
576 #endif /* HAL_ISR and not HAL */
577 
578 /* END AUTOMATICALLY GENERATED CODE [hal_usci_isr_decl] */
579 /* !BSP430! end=hal_usci_isr_decl */
580 /* !BSP430! instance=USCI_A0,USCI_A1,USCI_B0,USCI_B1 */
581 
584  unsigned char ctl0_byte,
585  unsigned char ctl1_byte,
586  unsigned long baud);
587 
590  unsigned char ctl0_byte,
591  unsigned char ctl1_byte,
592  unsigned int prescaler);
593 
596  unsigned char ctl0_byte,
597  unsigned char ctl1_byte,
598  unsigned int prescaler);
599 
601 int iBSP430usciSetReset_rh (hBSP430halSERIAL hal, int resetp);
602 
604 int iBSP430usciSetHold_rh (hBSP430halSERIAL hal, int holdp);
605 
608 
611 
614 
617 
619 int iBSP430usciUARTtxByte_rh (hBSP430halSERIAL device, uint8_t c);
620 
622 int iBSP430usciUARTtxData_rh (hBSP430halSERIAL device, const uint8_t * data, size_t len);
623 
625 int iBSP430usciUARTtxASCIIZ_rh (hBSP430halSERIAL device, const char * str);
626 
629  const uint8_t * tx_data,
630  size_t tx_len,
631  size_t rx_len,
632  uint8_t * rx_data);
633 
636  int own_address,
637  int slave_address);
638 
641  uint8_t * rx_data,
642  size_t rx_len);
643 
646  const uint8_t * tx_data,
647  size_t tx_len);
648 
658 static BSP430_CORE_INLINE
660 {
661  /* !BSP430! insert=periph_hpl_demux */
662  /* BEGIN AUTOMATICALLY GENERATED CODE---DO NOT MODIFY [periph_hpl_demux] */
663 #if (configBSP430_HPL_USCI_A0 - 0)
664  if (BSP430_PERIPH_USCI_A0 == periph) {
665  return BSP430_HPL_USCI_A0;
666  }
667 #endif /* configBSP430_HPL_USCI_A0 */
668 
669 #if (configBSP430_HPL_USCI_A1 - 0)
670  if (BSP430_PERIPH_USCI_A1 == periph) {
671  return BSP430_HPL_USCI_A1;
672  }
673 #endif /* configBSP430_HPL_USCI_A1 */
674 
675 #if (configBSP430_HPL_USCI_B0 - 0)
676  if (BSP430_PERIPH_USCI_B0 == periph) {
677  return BSP430_HPL_USCI_B0;
678  }
679 #endif /* configBSP430_HPL_USCI_B0 */
680 
681 #if (configBSP430_HPL_USCI_B1 - 0)
682  if (BSP430_PERIPH_USCI_B1 == periph) {
683  return BSP430_HPL_USCI_B1;
684  }
685 #endif /* configBSP430_HPL_USCI_B1 */
686 
687  /* END AUTOMATICALLY GENERATED CODE [periph_hpl_demux] */
688  /* !BSP430! end=periph_hpl_demux */
689  return NULL;
690 }
691 
700 static BSP430_CORE_INLINE
702 {
703  /* !BSP430! insert=periph_hal_demux */
704  /* BEGIN AUTOMATICALLY GENERATED CODE---DO NOT MODIFY [periph_hal_demux] */
705 #if (configBSP430_HAL_USCI_A0 - 0)
706  if (BSP430_PERIPH_USCI_A0 == periph) {
707  return BSP430_HAL_USCI_A0;
708  }
709 #endif /* configBSP430_HAL_USCI_A0 */
710 
711 #if (configBSP430_HAL_USCI_A1 - 0)
712  if (BSP430_PERIPH_USCI_A1 == periph) {
713  return BSP430_HAL_USCI_A1;
714  }
715 #endif /* configBSP430_HAL_USCI_A1 */
716 
717 #if (configBSP430_HAL_USCI_B0 - 0)
718  if (BSP430_PERIPH_USCI_B0 == periph) {
719  return BSP430_HAL_USCI_B0;
720  }
721 #endif /* configBSP430_HAL_USCI_B0 */
722 
723 #if (configBSP430_HAL_USCI_B1 - 0)
724  if (BSP430_PERIPH_USCI_B1 == periph) {
725  return BSP430_HAL_USCI_B1;
726  }
727 #endif /* configBSP430_HAL_USCI_B1 */
728 
729  /* END AUTOMATICALLY GENERATED CODE [periph_hal_demux] */
730  /* !BSP430! end=periph_hal_demux */
731  return NULL;
732 }
733 
740 const char * xBSP430usciName (tBSP430periphHandle periph);
741 
742 #endif /* BSP430_MODULE_USCI */
743 
744 #endif /* BSP430_PERIPH_USCI_H */
static BSP430_CORE_INLINE hBSP430halSERIAL hBSP430usciLookup(tBSP430periphHandle periph)
Definition: usci.h:701
int iBSP430usciClose(hBSP430halSERIAL xUSCI)
#define BSP430_HPL_USCI_A0
Definition: usci.h:436
static BSP430_CORE_INLINE volatile sBSP430hplUSCI * xBSP430hplLookupUSCI(tBSP430periphHandle periph)
Definition: usci.h:659
int iBSP430usciUARTrxByte_rh(hBSP430halSERIAL device)
struct sBSP430hplUSCI sBSP430hplUSCI
unsigned char ctl1
Definition: usci.h:119
#define BSP430_HPL_USCI_A1
Definition: usci.h:447
void vBSP430usciFlush_ni(hBSP430halSERIAL device)
#define BSP430_HAL_USCI_A0
Definition: usci.h:171
int iBSP430usciI2CsetAddresses_rh(hBSP430halSERIAL hal, int own_address, int slave_address)
Definition: serial_.h:193
void vBSP430usciWakeupTransmit_rh(hBSP430halSERIAL device)
#define BSP430_PERIPH_USCI_A0
Definition: usci.h:321
int iBSP430usciUARTtxASCIIZ_rh(hBSP430halSERIAL device, const char *str)
unsigned char rxbuf
Definition: usci.h:124
unsigned char txbuf
Definition: usci.h:125
#define BSP430_HPL_USCI_B0
Definition: usci.h:458
hBSP430halSERIAL hBSP430usciOpenSPI(hBSP430halSERIAL hal, unsigned char ctl0_byte, unsigned char ctl1_byte, unsigned int prescaler)
int iBSP430usciI2CtxData_rh(hBSP430halSERIAL hal, const uint8_t *tx_data, size_t tx_len)
#define BSP430_CORE_INLINE
Definition: core.h:439
hBSP430halSERIAL hBSP430usciOpenUART(hBSP430halSERIAL hal, unsigned char ctl0_byte, unsigned char ctl1_byte, unsigned long baud)
const char * xBSP430usciName(tBSP430periphHandle periph)
Generic peripheral support for MSP430 MCUs.
Definition: usci.h:117
hBSP430halSERIAL hBSP430usciOpenI2C(hBSP430halSERIAL hal, unsigned char ctl0_byte, unsigned char ctl1_byte, unsigned int prescaler)
#define BSP430_PERIPH_USCI_B1
Definition: usci.h:420
int iBSP430usciI2CrxData_rh(hBSP430halSERIAL hal, uint8_t *rx_data, size_t rx_len)
int iBSP430usciUARTtxByte_rh(hBSP430halSERIAL device, uint8_t c)
#define BSP430_PERIPH_USCI_B0
Definition: usci.h:387
unsigned char br0
Definition: usci.h:120
unsigned char ctl0
Definition: usci.h:118
unsigned char br1
Definition: usci.h:121
int iBSP430usciSetReset_rh(hBSP430halSERIAL hal, int resetp)
unsigned char mctl
Definition: usci.h:122
#define BSP430_HAL_USCI_A1
Definition: usci.h:208
#define BSP430_HAL_USCI_B0
Definition: usci.h:245
int tBSP430periphHandle
Definition: periph.h:106
#define BSP430_HAL_USCI_B1
Definition: usci.h:282
int iBSP430usciSPITxRx_rh(hBSP430halSERIAL hal, const uint8_t *tx_data, size_t tx_len, size_t rx_len, uint8_t *rx_data)
Structures for abstracted serial interface.
#define BSP430_PERIPH_USCI_A1
Definition: usci.h:354
int iBSP430usciUARTtxData_rh(hBSP430halSERIAL device, const uint8_t *data, size_t len)
int iBSP430usciSetHold_rh(hBSP430halSERIAL hal, int holdp)
unsigned char stat
Definition: usci.h:123
#define BSP430_HPL_USCI_B1
Definition: usci.h:469