BSP430  20141115
Board Support Package for MSP430 microcontrollers
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
Macros | Functions
serial.h File Reference

Declarations for abstracted serial interface. More...

#include <bsp430/core.h>
#include <bsp430/periph.h>
#include <bsp430/serial_.h>

Go to the source code of this file.

Macros

#define configBSP430_SERIAL_USE_USCI   defined(__MSP430_HAS_USCI__)
 
#define configBSP430_SERIAL_USE_USCI5   defined(__MSP430_HAS_USCI_A0__)
 
#define configBSP430_SERIAL_USE_EUSCI   (defined(__MSP430_HAS_EUSCI_A0__) || defined(__MSP430_HAS_EUSCI_B0__))
 
#define configBSP430_SERIAL_ENABLE_UART   (configBSP430_CONSOLE - 0)
 
#define configBSP430_SERIAL_ENABLE_SPI   0
 
#define BSP430_SERIAL_SPI_BUS_SPEED_HZ   4000000UL
 
#define configBSP430_SERIAL_ENABLE_I2C   0
 
#define BSP430_SERIAL_I2C_BUS_SPEED_HZ   400000UL
 
#define BSP430_SERIAL
 
#define BSP430_SERIAL_ADJUST_CTL0_INITIALIZER(_i)   (((_i) >= 0x100) ? ((_i) >> 8) : (_i))
 
#define BSP430_I2C_SPIN_LIMIT   65536
 
#define BSP430_I2C_ERRFLAG_PROTOCOL   0x4000
 
#define BSP430_I2C_ERRFLAG_SPINLIMIT   0x2000
 

Functions

unsigned int uiBSP430serialSMCLKPrescaler (unsigned long freq_Hz)
 
static BSP430_CORE_INLINE hBSP430halSERIAL hBSP430serialOpenUART (hBSP430halSERIAL hal, unsigned char ctl0_byte, unsigned char ctl1_byte, unsigned long baud)
 
static BSP430_CORE_INLINE int iBSP430uartRxByte_rh (hBSP430halSERIAL hal)
 
static BSP430_CORE_INLINE int iBSP430uartTxByte_rh (hBSP430halSERIAL hal, uint8_t c)
 
static BSP430_CORE_INLINE int iBSP430uartTxData_rh (hBSP430halSERIAL hal, const uint8_t *data, size_t len)
 
static BSP430_CORE_INLINE int iBSP430uartTxASCIIZ_rh (hBSP430halSERIAL hal, const char *str)
 
static BSP430_CORE_INLINE hBSP430halSERIAL hBSP430serialOpenSPI (hBSP430halSERIAL hal, unsigned char ctl0_byte, unsigned char ctl1_byte, unsigned int prescaler)
 
static BSP430_CORE_INLINE int iBSP430spiTxRx_rh (hBSP430halSERIAL hal, const uint8_t *tx_data, size_t tx_len, size_t rx_len, uint8_t *rx_data)
 
static BSP430_CORE_INLINE hBSP430halSERIAL hBSP430serialOpenI2C (hBSP430halSERIAL hal, unsigned char ctl0_byte, unsigned char ctl1_byte, unsigned int prescaler)
 
static BSP430_CORE_INLINE int iBSP430i2cSetAddresses_rh (hBSP430halSERIAL hal, int own_address, int slave_address)
 
static BSP430_CORE_INLINE int iBSP430i2cTxData_rh (hBSP430halSERIAL hal, const uint8_t *tx_data, size_t tx_len)
 
static BSP430_CORE_INLINE int iBSP430i2cRxData_rh (hBSP430halSERIAL hal, uint8_t *rx_data, size_t rx_len)
 
static BSP430_CORE_INLINE int iBSP430serialSetReset_rh (hBSP430halSERIAL hal, int resetp)
 
static BSP430_CORE_INLINE int iBSP430serialSetHold_rh (hBSP430halSERIAL hal, int holdp)
 
static BSP430_CORE_INLINE int iBSP430serialClose (hBSP430halSERIAL hal)
 
static BSP430_CORE_INLINE void vBSP430serialWakeupTransmit_rh (hBSP430halSERIAL hal)
 
static BSP430_CORE_INLINE void vBSP430serialFlush_ni (hBSP430halSERIAL hal)
 
static BSP430_CORE_INLINE unsigned long ulBSP430serialRate (hBSP430halSERIAL hal)
 
static BSP430_CORE_INLINE hBSP430halSERIAL hBSP430serialLookup (tBSP430periphHandle periph)
 
const char * xBSP430serialName (tBSP430periphHandle periph)
 

Detailed Description

Declarations for abstracted serial interface.

The MSP430 line has a variety of peripherals that support serial communications, including the origin 2xx/4xx family USCI, 5xx USCI, and 5xx eUSCI. These are sufficiently similar in function that it is useful to have a hardware abstraction layer that delegates to the peripherals available on the current platform.

Homepage
http://github.com/pabigot/bsp430

Macro Definition Documentation

#define BSP430_I2C_ERRFLAG_PROTOCOL   0x4000

Bit set in absolute value of I2C error codes to indicate a protocol error.

I2C error codes are negative values. The absolute value may encode information on the cause of an error.

If BSP430_I2C_ERRFLAG_PROTOCOL is set in the absolute value, the low 8 bits encode peripheral-specific error data, taken from (for example) UCBxIFG. Generally protocol errors include receipt of a NACK or loss of arbitration.

See also
BSP430_I2C_ERRFLAG_SPINLIMIT
#define BSP430_I2C_ERRFLAG_SPINLIMIT   0x2000

Bit set in absolute value of I2C error codes to indicate spin limit exceeded.

I2C error codes are negative values. The absolute value may encode information on the cause of an error.

If BSP430_I2C_ERRFLAG_SPINLIMIT is set in the absolute value then a loop awaiting an expected condition executed for BSP430_I2C_SPIN_LIMIT times without detecting the desired condition. The I2C operation aborts immediately, but no restorative action is taken by the infrastructure.

See also
BSP430_I2C_ERRFLAG_PROTOCOL
#define BSP430_I2C_SPIN_LIMIT   65536

Control the duration of I2C loops waiting for bus conditions.

A positive value enables a loop limit; the number of loops attempted ranges from 1 to 65536. A zero or negative value disables the loop limit.

Note
A positive value that is equal to zero modulo 2^16 will result in the maximum iteration count of 2^16.
Defaulted:
The value here is superseded by previously encountered definitions.
#define BSP430_SERIAL
Value:
#define configBSP430_SERIAL_ENABLE_I2C
Definition: serial.h:150
#define configBSP430_SERIAL_ENABLE_SPI
Definition: serial.h:119
#define configBSP430_SERIAL_ENABLE_UART
Definition: serial.h:104

Defined by the infrastructure to a true expression in the case where at least one protocol is to be supported by the serial abstraction. If it evaluates to false, the serial abstraction will be absent from the compiled infrastructure code.

C Preprocessor Only:
This macro may have a value that restricts its use to C preprocessor conditional directives.
#define BSP430_SERIAL_ADJUST_CTL0_INITIALIZER (   _i)    (((_i) >= 0x100) ? ((_i) >> 8) : (_i))

When the underlying implementation is an EUSCI device (as on FR5xx chips), the header defines used to construct the value ctl0_byte are specified for a 16-bit access. The ctl0 byte is the upper byte of the ctlw0 word that comprises ctl0 and ctl1 on these MCUs. On those devices you must use the _H suffix to select the high-byte version of these constants or divide your configured value by 256 to place it in the low byte of the argument. This applies to configuration values UCPEN, UCPAR, UCMSB, UC7BIT, UCSPB, UCCKPH, UCCKPL, UCMST, and UCMODE_0 or UCMODE_1 or UCMODE_2, and perhaps others.

Given a ctl0_byte expression comprised of these constants, this macro will adjust it for you when the value appears to be outside the expected range (i.e., greater than 0xFF) and will leave the values alone when it is not, so you can use the standard header constant names without having to worry about the underlying implementation.

Examples:
sensors/hh10d/main.c, sensors/tmp102/main.c, and utility/m25p/main.c.
#define BSP430_SERIAL_I2C_BUS_SPEED_HZ   400000UL

Default speed for I2C bus transactions when application does not specify divisor.

This is referenced by hBSP430serialOpenI2C() when the prescaler parameter is zero.

As most I2C devices accept the V1.0 specification maximum, the default value should be 400kHz.

Warning
The maximum speed is specified in the MCU data sheet; e.g. the MSP430F5438A will go up to 400 kHz. Higher speeds may result in anomalous clocks and unreliable behavior.
Defaulted:
The value here is superseded by previously encountered definitions.
Examples:
sensors/hh10d/main.c.
#define BSP430_SERIAL_SPI_BUS_SPEED_HZ   4000000UL

Default speed for SPI bus transactions when application does not specify divisor.

This is referenced by hBSP430serialOpenSPI() when the prescaler parameter is zero.

SPI flash can often work at 20MHz; the ChipCon radios are good to 6MHz generally. The default will be 4MHz although there are chips that will not operate at that speed (e.g., the CMA3000 accelerometer).

Defaulted:
The value here is superseded by previously encountered definitions.
#define configBSP430_SERIAL_ENABLE_I2C   0

Define to a true value to allow the general serial layer to recognize and dispatch I2C-related functions. If left false, I2C-related functions will not be added to the serial abstraction dispatch table.

Note
This flag does not control the availabilty of I2C-related functions within the peripheral implementation, only access to them through the serial abstraction.
C Preprocessor Only:
This macro may have a value that restricts its use to C preprocessor conditional directives.
Defaulted:
The value here is superseded by previously encountered definitions.
#define configBSP430_SERIAL_ENABLE_SPI   0

Define to a true value to allow the general serial layer to recognize and dispatch SPI-related functions. If left false, SPI-related functions will not be added to the serial abstraction dispatch table.

Note
This flag does not control the availabilty of SPI-related functions within the peripheral implementation, only access to them through the serial abstraction.
C Preprocessor Only:
This macro may have a value that restricts its use to C preprocessor conditional directives.
Defaulted:
The value here is superseded by previously encountered definitions.
#define configBSP430_SERIAL_ENABLE_UART   (configBSP430_CONSOLE - 0)

Define to a true value to allow the general serial layer to recognize and dispatch UART-related functions. If left false, UART-related functions will not be added to the serial abstraction dispatch table.

Note
This flag does not control the availabilty of UART-related functions within the peripheral implementation, only access to them through the serial abstraction.
C Preprocessor Only:
This macro may have a value that restricts its use to C preprocessor conditional directives.
Defaulted:
The value here is superseded by previously encountered definitions.
#define configBSP430_SERIAL_USE_EUSCI   (defined(__MSP430_HAS_EUSCI_A0__) || defined(__MSP430_HAS_EUSCI_B0__))

Define to true value to allow the generic serial dispatches to recognize sBSP430hplEUSCIA and sBSP430hplEUSCIB as underlying serial implementation. This defaults to true iff the MCU supports the eUSCI device as implemented on 5xx MCUs.

C Preprocessor Only:
This macro may have a value that restricts its use to C preprocessor conditional directives.
Defaulted:
The value here is superseded by previously encountered definitions.
#define configBSP430_SERIAL_USE_USCI   defined(__MSP430_HAS_USCI__)

Define to true value to allow the generic serial dispatches to recognize sBSP430hplUSCI as an underlying serial implementation. This defaults to true iff the MCU supports the USCI device as implemented on 2xx/4xx MCUs.

C Preprocessor Only:
This macro may have a value that restricts its use to C preprocessor conditional directives.
Defaulted:
The value here is superseded by previously encountered definitions.
#define configBSP430_SERIAL_USE_USCI5   defined(__MSP430_HAS_USCI_A0__)

Define to true value to allow the generic serial dispatches to recognize sBSP430hplUSCI5 as an underlying serial implementation. This defaults to true iff the MCU supports the USCI device as implemented on 5xx MCUs.

C Preprocessor Only:
This macro may have a value that restricts its use to C preprocessor conditional directives.
Defaulted:
The value here is superseded by previously encountered definitions.

Function Documentation

static BSP430_CORE_INLINE hBSP430halSERIAL hBSP430serialLookup ( tBSP430periphHandle  periph)
static

Get the HAL handle for a specific serial peripheral.

Parameters
periphThe handle identifier, such as BSP430_PERIPH_USCI_A0.
Returns
the HAL handle for the peripheral. A null pointer is returned if the handle does not correspond to a serial peripheral for which the HAL interface has been enabled.
Examples:
rf/cc110x/main.c, sensors/hh10d/main.c, sensors/tmp102/main.c, and utility/m25p/main.c.
static BSP430_CORE_INLINE hBSP430halSERIAL hBSP430serialOpenI2C ( hBSP430halSERIAL  hal,
unsigned char  ctl0_byte,
unsigned char  ctl1_byte,
unsigned int  prescaler 
)
static

Request and configure a serial device in I2C mode.

Parameters
halthe handle for the HAL interface for the serial device to be configured. These are found from the peripheral handle using hBSP430serialLookup().
ctl0_byteThe configuration to be written to the device's ctl0 byte. For I2C mode, potential values specified in the <msp430.h> header include UCA10, UCSLA10, UCMM, and UCMST (but see the warning above). The UCSYNC field is cleared and the UCMODE field is configured for I2C before being written.
Warning
See BSP430_SERIAL_ADJUST_CTL0_INITIALIZER() regarding portable use of ctl0_byte header constants.
Parameters
ctl1_byteThe configuration to be written to the device's ctl1 byte. For I2C mode, potential values specified in the <msp430.h> header are configuration of the clock (UCSSEL_0, UCSSEL_1, UCSSEL_2, or UCSSEL_3) and perhaps UCTR. The UCSWRST field is controlled by the function. If prescaler is zero, the clock configuration in this will be overridden to select SMCLK.
prescalerThe value by which the clock selected in ctl1_byte is divided to produce the I2C clock. A value of zero will select the minimum of 1 and ceil(ulBSP430clockSMCLK_Hz()/BSP430_SERIAL_I2C_BUS_SPEED_HZ), resulting in the highest speed that does not exceed BSP430_SERIAL_I2C_BUS_SPEED_HZ. Use of this feature will override the clock selection in ctl1_byte.
Returns
A peripheral-specific HAL handle if the allocation and configuration is successful, and a null handle if something went wrong (e.g., absence of the requested peripheral or a zero-valued prescaler).
Examples:
sensors/hh10d/main.c, and sensors/tmp102/main.c.
static BSP430_CORE_INLINE hBSP430halSERIAL hBSP430serialOpenSPI ( hBSP430halSERIAL  hal,
unsigned char  ctl0_byte,
unsigned char  ctl1_byte,
unsigned int  prescaler 
)
static

Request and configure a serial device in SPI mode.

Parameters
halthe handle for the HAL interface for the serial device to be configured. These are found from the peripheral handle using hBSP430serialLookup().
ctl0_byteThe configuration to be written to the device's ctl0 byte. For SPI mode, potential values specified in the <msp430.h> header include UCCKPH, UCCKPL, UCMSB, UC7BIT, UCMST, and UCMODE_0 or UCMODE_1 or UCMODE_2. The UCSYNC field is cleared before being written. Selection of UCMODE_3 (I2C mode) will result in this function returning an error.
Warning
(1) See BSP430_SERIAL_ADJUST_CTL0_INITIALIZER() regarding portable use of ctl0_byte header constants.
(2) The MSP430's method of specifying SPI clock phase is opposite the industry standard. Use this table:
Mode CPOL CPHA ctl0_byte
0 0 0 UCCKPH
1 0 1 0
2 1 0 UCCKPH | UCCKPL
3 1 1 UCCKPL
Parameters
ctl1_byteThe configuration to be written to the device's ctl1 byte. For SPI mode, potential values specified in the <msp430.h> header are only configuration of the clock: UCSSEL_0, UCSSEL_1, UCSSEL_2, UCSSEL_3. The UCSWRST field is controlled by the function. If prescaler is zero, the clock configuration in this will be overridden to select SMCLK.
prescalerThe value by which the clock selected in ctl1_byte is divided to produce the SPI clock. A value of zero will select the minimum of 1 and ceil(ulBSP430clockSMCLK_Hz()/BSP430_SERIAL_SPI_BUS_SPEED_HZ), resulting in the highest speed that does not exceed BSP430_SERIAL_SPI_BUS_SPEED_HZ. Use of this feature will override the clock selection in ctl1_byte.
Returns
A peripheral-specific HAL handle if the allocation and configuration is successful, and a null handle if something went wrong (e.g., absence of the requested peripheral, an invalid mode in ctl0_byte or a zero-valued prescaler).
Examples:
rf/cc110x/main.c.
static BSP430_CORE_INLINE hBSP430halSERIAL hBSP430serialOpenUART ( hBSP430halSERIAL  hal,
unsigned char  ctl0_byte,
unsigned char  ctl1_byte,
unsigned long  baud 
)
static

Request and configure a serial device in UART mode.

Parameters
halthe handle for the HAL interface for the serial device to be configured. These are found from the peripheral handle using hBSP430serialLookup().
ctl0_byteThe configuration to be written to the device's ctl0 byte. For UART mode, potential values specified in the <msp430.h> header include UCPEN, UCPAR, UCMSB, UC7BIT, UCSPB. The UCMODE and UCSYNC elements of the byte are ignored. In most cases for UART mode a value of 0 producing 8N1 serial communications is appropriate.
Warning
See BSP430_SERIAL_ADJUST_CTL0_INITIALIZER() regarding portable use of ctl0_byte header constants.
Parameters
ctl1_byteThe configuration to be written to the device's ctl1 byte. For UART mode, potential values specified in the <msp430.h> header include UCRXEIE, UCBRKIE, and UCDORM. The UCSSEL and UCSWRST elements of the byte are cleared as the function configures those. In most cases a value of 0 is appropriate.
baudThe desired baud rate. This will be configured automatically. ACLK will be used as the baud rate clock if ACLK is both at least 20 kHz and at least three times faster than the requested baud rate; otherwise SMCLK will be used. The function invokes ulBSP430clockSMCLK_Hz() and ulBSP430clockACLK_Hz() as necessary to determine the actual speed of the baud rate clock.
Returns
A peripheral-specific HAL handle if the allocation and configuration is successful, and a null handle if something went wrong.
Dependency:
configBSP430_SERIAL_ENABLE_UART
static BSP430_CORE_INLINE int iBSP430i2cRxData_rh ( hBSP430halSERIAL  hal,
uint8_t *  rx_data,
size_t  rx_len 
)
static

Receive using a master I2C-configured device

This routine receives rx_len octets into rx_data, storing the octets received in response into rx_data.

This routine should only be invoked when hal->tx_cbchain_ni is null. If a callback is present, it is expected to be used to provide data for transmission. Note that such a callback must handle I2C start and stop conditions, which are peripheral-specific.

Warning
This routine supports the common case of the MSP430 as single I2C master. It does not support repeated-start. It will not work for slave operations, and may not work with multimaster configurations. BSP430 does not currently provide abstractions for these alternative I2C configurations.
Parameters
halthe serial device from which the data is received
rx_datawhere to store the data. The space available must be at least rx_len octets.
rx_lenthe number of bytes expected in response. A transaction reading more than 255 bytes may be rejected.
Returns
the total number of bytes stored in rx_data, or a negative error code (see BSP430_I2C_ERRFLAG_PROTOCOL and BSP430_I2C_ERRFLAG_SPINLIMIT). This function will not return -1, reserving that as a generic error code for higher-level functions.
Examples:
sensors/tmp102/main.c.
static BSP430_CORE_INLINE int iBSP430i2cSetAddresses_rh ( hBSP430halSERIAL  hal,
int  own_address,
int  slave_address 
)
static

Configure I2C addresses

This routine sets the own-address and slave-address registers of an I2C peripheral. The device should have been opened as an I2C device prior to invoking this function.

Warning
On some families the underlying peripheral must be held in reset if own_address is to be set.
Parameters
halthe serial device to be configured
own_addressthe value to use as this device's address. A negative value leaves the current configured own address unchanged.
slave_addressthe value to use as the slave address. A negative value leaves the current configured slave address unchanged.
Returns
0 if successfully set, -1 if an error occurs.
Examples:
sensors/tmp102/main.c.
static BSP430_CORE_INLINE int iBSP430i2cTxData_rh ( hBSP430halSERIAL  hal,
const uint8_t *  tx_data,
size_t  tx_len 
)
static

Transmit using a master I2C-configured device

This routine transmits tx_len octets from tx_data.

This routine should only be invoked when hal->tx_cbchain_ni is null. If a callback is present, it is expected to be used to provide data for transmission. Note that such a callback must handle I2C start and stop conditions, which are peripheral-specific.

Warning
This routine supports the common case of the MSP430 as single I2C master. It does not support repeated-start. It will not work for slave operations, and may not work with multimaster configurations. BSP430 does not currently provide abstractions for these alternative I2C configurations.
Parameters
halthe serial device over which the data is transmitted and received
tx_datathe data to be transmitted
tx_lenthe number of bytes to transmit. A transaction writing more than 255 bytes may be rejected.
Returns
the total number of bytes transmitted, or a negative error code (see BSP430_I2C_ERRFLAG_PROTOCOL and BSP430_I2C_ERRFLAG_SPINLIMIT). This function will not return -1, reserving that as a generic error code for higher-level functions.
Examples:
sensors/tmp102/main.c.
static BSP430_CORE_INLINE int iBSP430serialClose ( hBSP430halSERIAL  hal)
static

Release a serial device.

This places the device into reset mode and resets the peripheral pins to port function. It does not release or disassociate any callbacks.

Parameters
hala serial HAL handle previously obtained through hBSP430serialOpenUART(), hBSP430serialOpenSPI(), or hBSP430serialOpenI2C().
Returns
0 if the close occurred without error.
static BSP430_CORE_INLINE int iBSP430serialSetHold_rh ( hBSP430halSERIAL  hal,
int  holdp 
)
static

Control serial device hold mode

When a serial peripheral is placed in hold mode the peripheral is reset per iBSP430serialSetReset_rh() with resetp set to a negative value to force a wait for pending activity to complete. In addition, the function reconfigures the associated port pins to their digital I/O function per iBSP430platformConfigurePeripheralPins_ni().

When the hold is released, the port pins are reconfigured to their peripheral function per iBSP430platformConfigurePeripheralPins_ni(), and the device is taken out of reset mode.

See also
iBSP430serialSetReset_rh()
Parameters
hala serial HAL handle to a peripheral that has been opened
holdpa nonzero value if the peripheral is to be placed into hold mode, and a zero value to release it from hold mode
Returns
0 if the device was previously enabled; a positive value if the device was previously in hold mode.
Examples:
bootstrap/applpm/main.c, and rf/cc110x/main.c.
static BSP430_CORE_INLINE int iBSP430serialSetReset_rh ( hBSP430halSERIAL  hal,
int  resetp 
)
static

Control serial device reset mode.

When placed into reset mode, the UCSWRST bit (or peripheral-specific analog) is set, clearing all errors and stopping all activity but retaining all configuration information. Interrupts are disabled. When the hold is released the UCSWRST bit is cleared, and any interrupts for which callbacks are registered are re-enabled. (Note that enabling the interrupts at the peripheral level does not change the GIE state, which should be cleared while this function is executing.)

When the peripheral is in I2C mode, any pending UCTXNACK, UCTXSTP, UCTXSTT, or similar family-specific requests will be cleared before the reset is released.

Placing a serial peripheral into reset mode prior to entering a low power mode will often reduce current consumption. Entering and leaving reset mode is also the simplest way to clear peripheral errors and flush pending data.

Note
A positive value for resetp places the peripheral into reset mode immediately. This can result in data loss if transmitted data is still in progress. Passing a negative value for resetp does the functional equivalent of invoking vBSP430serialFlush_ni() prior to placing the device in reset.
Warning
The GPIO configuration of peripheral pins is not affected by this function. Power consumption in a low power mode may be elevated as a result. Consider using iBSP430seriaLSetHold_rh().
Note
This function differs from iBSP430serialSetHold_rh() in that it:
  • Allows caller to determine whether to wait for pending activity to complete before placing the peripheral in reset mode.
  • Does not reconfigure port pins; these remain in their peripheral function role preventing their use as GPIOs while reset.
See also
iBSP430serialSetHold_rh()
Parameters
hala serial HAL handle to a peripheral that has been opened
resetpA positive value places peripheral into reset mode. A negative value places peripheral into reset mode after blocking until peripheral is no longer busy. A zero value releases peripheral from reset mode.
Returns
A positive value if the device had been in reset mode; zero if it had not been in reset mode.
static BSP430_CORE_INLINE int iBSP430spiTxRx_rh ( hBSP430halSERIAL  hal,
const uint8_t *  tx_data,
size_t  tx_len,
size_t  rx_len,
uint8_t *  rx_data 
)
static

Transmit and receive using a SPI-configured device

This routine transmits tx_len octets from tx_data, storing the octets received in response into rx_data. It then transmits rx_len dummy bytes, appending the resulting response into rx_data.

This routine should only be invoked when hal->tx_cbchain_ni and hal->rx_cbchain_ni are null. If callbacks are present, they are expected to be used to provide data for transmission and to process received data.

Parameters
halthe serial device over which the data is transmitted and received
tx_datathe data to be transmitted (generally, a command). The pointer may be null only if tx_len is zero.
tx_lenthe number of bytes to transmit as the command. The value may be zero if this call is reading additional data resulting from a previous command.
rx_lenthe number of additional bytes expected in response, exclusive of the synchronous responses to bytes transmitted from tx_data. See BSP430_SERIAL_SPI_READ_TX_BYTE regarding the content of the dummy bytes that are transmitted to trigger reception.
rx_datawhere to store the responses received during the transmit and receive phases. A null pointer may be passed if the incoming data is not of interest. If the pointer is not null, the space available must be at least tx_len + rx_len.
Returns
the total number of bytes stored in rx_data (or that would have been stored if rx_data were not null), or -1 if an error occcured.
Examples:
rf/cc110x/main.c.
static BSP430_CORE_INLINE int iBSP430uartRxByte_rh ( hBSP430halSERIAL  hal)
static

Receive a byte from a UART-configured device.

This routine should only be invoked when hal->rx_cbchain_ni is null. If a callback is present, it is expected to be used to accept data on reception.

Parameters
halthe serial device over which the data should be transmitted
Returns
the character received if any is ready to return, or -1 if the device has no data available.
static BSP430_CORE_INLINE int iBSP430uartTxASCIIZ_rh ( hBSP430halSERIAL  hal,
const char *  str 
)
static

Transmit a sequence of characters over a UART-configured device.

This routine should only be invoked when hal->tx_cbchain_ni is null. If a callback is present, it is expected to be used to provide data for transmission.

Parameters
halthe serial device over which the data should be transmitted
stra NUL-terminated sequence of character data to be transmitted. The NUL serves only as a termination marker, and is not transmitted.
Returns
the number of bytes transmitted, or -1 if an error occurs
static BSP430_CORE_INLINE int iBSP430uartTxByte_rh ( hBSP430halSERIAL  hal,
uint8_t  c 
)
static

Transmit a byte over a UART-configured device.

This routine should only be invoked when hal->tx_cbchain_ni is null. If a callback is present, it is expected to be used to provide data for transmission.

Parameters
halthe serial device over which the data should be transmitted
ca data byte to be transmitted
Returns
the input character c if transmitted, or -1 if an error occurred.
static BSP430_CORE_INLINE int iBSP430uartTxData_rh ( hBSP430halSERIAL  hal,
const uint8_t *  data,
size_t  len 
)
static

Transmit a block of data over a UART-configured device.

This routine should only be invoked when hal->tx_cbchain_ni is null. If a callback is present, it is expected to be used to provide data for transmission.

Parameters
halthe serial device over which the data should be transmitted
datapointer to the start of a sequence of data to transmit
lenthe number of octets to be transmitted
Returns
the number of octets successfully transmitted
unsigned int uiBSP430serialSMCLKPrescaler ( unsigned long  freq_Hz)

Calculate prescaler to obtain desired clock from SMCLK.

The prescaler returned is designed to produce the fastest clock based on an integer division of ulBSP430clockSMCLK_Hz() that does not exceed freq_Hz, except that if freq_Hz is too slow to be produced by dividing SMCLK by a 16-bit prescaler then 65535 will be returned.

Parameters
freq_HzDesired clock frequency in Hz.
Returns
A prescaler, as used in hBSP430serialOpenSPI() or hBSP430serialOpenI2C(). The value will never be zero, and will saturate at 65535.
static BSP430_CORE_INLINE unsigned long ulBSP430serialRate ( hBSP430halSERIAL  hal)
static

Return the frequency of the serial interface.

If hal is configured in UART mode, this is the baud rate. In all other modes it's the bus frequency.

Parameters
halthe serial device for which frequency is desired
Returns
Frequency of the serial interface in baud (UART) or Hz (SPI, I2C). A zero value indicates an error.
static BSP430_CORE_INLINE void vBSP430serialFlush_ni ( hBSP430halSERIAL  hal)
static

Spin until any in-progress transmission or reception is complete.

This is used to ensure the device is idle prior to reconfiguring it.

Note
This function must be executed with interrupts disabled lest an interrupt cause the peripheral to begin new work after any in progress work had been completed.
Warning
This waits for UCBUSY to be clear in the peripheral. For I2C that flag may be set when another device is active on the I2C bus; further, it may be clear while this device is still transmitting special signals such as UCTXSTP. Alternative techniques are required to ensure I2C operations are complete prior to placing the peripheral into reset mode. This is done in the reference iBSP430i2cRxData_rh() and iBSP430i2cTxData_rh() single-master routines.
Parameters
hala serial HAL handle
static BSP430_CORE_INLINE void vBSP430serialWakeupTransmit_rh ( hBSP430halSERIAL  hal)
static

Wake up the interrupt-driven transmission if necessary.

Normally the transmission infrastructure transmits data as soon as space is available in the transmission buffer. The infrastructure is disabled when the sBSP430halSERIAL.tx_cbchain_ni indicates that no more data is available. When this has happened, it must be told that more data has been added and the infrastructure re-enabled.

For efficiency, this should only be called if it is believed that data is ready to be presented in a transmission callback, but that the transmission infrastructure may be idle.

Parameters
hala serial HAL handle
const char* xBSP430serialName ( tBSP430periphHandle  periph)

Get a human-readable identifier for the serial peripheral

Parameters
periphThe handle identifier, such as BSP430_PERIPH_USCI_A0.
Returns
The short name of the port, e.g. "USCI_A0". If the peripheral is not recognized as a serial device, a null pointer is returned.
Examples:
rf/cc110x/main.c, rf/cc3000/cli/main.c, sensors/hh10d/main.c, sensors/tmp102/main.c, sensors/venus6pps/main.c, utility/m25p/main.c, and utility/u8glib/main.c.