Loading...
Searching...
No Matches
periph_cpu.h File Reference

CPU specific definitions for internal peripheral handling. More...

Detailed Description

CPU specific definitions for internal peripheral handling.

Author
Hauke Petersen hauke.nosp@m..pet.nosp@m.ersen.nosp@m.@fu-.nosp@m.berli.nosp@m.n.de

Definition in file periph_cpu.h.

#include <stdbool.h>
#include "compiler_hints.h"
#include "periph_cpu_common.h"
#include "macros/units.h"
+ Include dependency graph for periph_cpu.h:

Go to the source code of this file.

Data Structures

struct  msp430_usart_params_t
 MSP430 x1xx USART configuration. More...
 
struct  msp430_usart_prescaler_t
 MSP430 x1xx USART prescaler configuration. More...
 
struct  msp430_usart_conf_t
 MSP430 x1xx USART configuration registers. More...
 
struct  msp430_usart_uart_params_t
 MSP430 x1xx UART configuration, CPU level. More...
 
struct  uart_conf_t
 UART device configuration. More...
 
struct  msp430_usart_spi_params_t
 MSP430 x1xx SPI configuration, CPU level. More...
 
struct  spi_conf_t
 SPI device configuration. More...
 

Enumerations

enum  msp430_usart_clk_t { USART_CLK_UCLKI = UXTCTL_SSEL_UCLKI , USART_CLK_AUX = UXTCTL_SSEL_ACLK , USART_CLK_SUBMAIN = UXTCTL_SSEL_SMCLK }
 MSP430 x1xx USART clock source. More...
 

Functions

static void msp430_usart_enable_tx_irq (const msp430_usart_params_t *usart_conf)
 Enable the TX interrupt on the given USART.
 
static void msp430_usart_enable_rx_irq (const msp430_usart_params_t *usart_conf)
 Enable the RX interrupt on the given USART.
 
static void msp430_usart_disable_tx_irq (const msp430_usart_params_t *usart_conf)
 Disable the TX interrupt on the given USART.
 
static void msp430_usart_disable_rx_irq (const msp430_usart_params_t *usart_conf)
 Disable the RX interrupt on the given USART.
 
static bool msp430_usart_get_tx_irq_flag (const msp430_usart_params_t *usart_conf)
 Get the TX IRQ flag of the given USART.
 
static bool msp430_usart_get_rx_irq_flag (const msp430_usart_params_t *usart_conf)
 Get the RX IRQ flag of the given USART.
 
static bool msp430_usart_are_both_irq_flags_set (const msp430_usart_params_t *usart_conf)
 Check if both TX and RX IRQ flags are set on the given USART.
 
static void msp430_usart_clear_tx_irq_flag (const msp430_usart_params_t *usart_conf)
 Clear the TX IRQ flag of the given USART.
 
static void msp430_usart_clear_rx_irq_flag (const msp430_usart_params_t *usart_conf)
 Clear the RX IRQ flag of the given USART.
 
void msp430_usart_acquire (const msp430_usart_params_t *params, const msp430_usart_conf_t *conf, uint8_t enable_mask)
 Get exclusive access to an USART peripheral and initialize it for operation as configured.
 
void msp430_usart_release (const msp430_usart_params_t *params)
 Release exclusive access to an USART peripheral and turn it off again.
 
msp430_usart_prescaler_t msp430_usart_prescale (uint32_t clock, uint16_t min_br)
 Compute a suitable prescaler.
 

Variables

const msp430_usart_uart_params_t usart0_as_uart
 MSP430 x1xx USART0 in UART configuration.
 
const msp430_usart_uart_params_t usart1_as_uart
 MSP430 x1xx USART1 in UART configuration.
 
const msp430_usart_spi_params_t usart0_as_spi
 MSP430 x1xx USART0 in SPI configuration.
 
const msp430_usart_spi_params_t usart1_as_spi
 MSP430 x1xx USART1 in SPI configuration.
 
#define USART_NUMOF   2
 All MSP430 x1xx MCUs have two USART peripherals.
 
#define USART_MIN_BR_SPI   2
 The clock divider of the UASRT (BR register) must be at least 2 when in SPI mode.
 
#define USART_MIN_BR_UART   3
 The clock divider of the UASRT (BR register) must be at least 3 when in UART mode.
 

Override SPI mode selection values

#define HAVE_SPI_MODE_T
 MSP430 x1xx has a custom spi_mode_t.
 
enum  spi_mode_t { SPI_MODE_0 = (CKPH) , SPI_MODE_1 = 0 , SPI_MODE_2 = (CKPL | CKPH) , SPI_MODE_3 = (CKPL) }
 Support SPI modes. More...
 

Override SPI clock speed selection values

#define HAVE_SPI_CLK_T
 MSP430 x1xx has a custom spi_clock_t.
 
enum  spi_clk_t {
  SPI_CLK_100KHZ = KHZ(100) , SPI_CLK_400KHZ = KHZ(400) , SPI_CLK_1MHZ = MHZ(1) , SPI_CLK_5MHZ = MHZ(5) ,
  SPI_CLK_10MHZ = SPI_CLK_5MHZ
}
 Support SPI clock frequencies. More...
 

declare needed generic SPI functions

#define PERIPH_SPI_NEEDS_INIT_CS
 use shared spi_init_cs()
 
#define PERIPH_SPI_NEEDS_TRANSFER_BYTE
 use shared spi_transfer_byte()
 
#define PERIPH_SPI_NEEDS_TRANSFER_REG
 use shared spi_transfer_reg()
 
#define PERIPH_SPI_NEEDS_TRANSFER_REGS
 use shared spi_transfer_regs()
 

Macro Definition Documentation

◆ HAVE_SPI_CLK_T

#define HAVE_SPI_CLK_T

MSP430 x1xx has a custom spi_clock_t.

Definition at line 74 of file periph_cpu.h.

◆ HAVE_SPI_MODE_T

#define HAVE_SPI_MODE_T

MSP430 x1xx has a custom spi_mode_t.

Definition at line 53 of file periph_cpu.h.

◆ PERIPH_SPI_NEEDS_INIT_CS

#define PERIPH_SPI_NEEDS_INIT_CS

use shared spi_init_cs()

Definition at line 231 of file periph_cpu.h.

◆ PERIPH_SPI_NEEDS_TRANSFER_BYTE

#define PERIPH_SPI_NEEDS_TRANSFER_BYTE

use shared spi_transfer_byte()

Definition at line 232 of file periph_cpu.h.

◆ PERIPH_SPI_NEEDS_TRANSFER_REG

#define PERIPH_SPI_NEEDS_TRANSFER_REG

use shared spi_transfer_reg()

Definition at line 233 of file periph_cpu.h.

◆ PERIPH_SPI_NEEDS_TRANSFER_REGS

#define PERIPH_SPI_NEEDS_TRANSFER_REGS

use shared spi_transfer_regs()

Definition at line 234 of file periph_cpu.h.

◆ USART_MIN_BR_SPI

#define USART_MIN_BR_SPI   2

The clock divider of the UASRT (BR register) must be at least 2 when in SPI mode.

Definition at line 41 of file periph_cpu.h.

◆ USART_MIN_BR_UART

#define USART_MIN_BR_UART   3

The clock divider of the UASRT (BR register) must be at least 3 when in UART mode.

Definition at line 47 of file periph_cpu.h.

◆ USART_NUMOF

#define USART_NUMOF   2

All MSP430 x1xx MCUs have two USART peripherals.

Definition at line 35 of file periph_cpu.h.

Enumeration Type Documentation

◆ msp430_usart_clk_t

MSP430 x1xx USART clock source.

The UC

Enumerator
USART_CLK_UCLKI 

UCLKI clock source (not supported yet)

USART_CLK_AUX 

auxiliary clock source

USART_CLK_SUBMAIN 

sub-system master clock source

Definition at line 107 of file periph_cpu.h.

◆ spi_clk_t

enum spi_clk_t

Support SPI clock frequencies.

Enumerator
SPI_CLK_100KHZ 

100 kHz

SPI_CLK_400KHZ 

400 kHz

SPI_CLK_1MHZ 

1 MHz

SPI_CLK_5MHZ 

5 MHz

SPI_CLK_10MHZ 

10 MHz not supported, falling back to 5 MHz

Definition at line 78 of file periph_cpu.h.

◆ spi_mode_t

enum spi_mode_t

Support SPI modes.

Field Name Description
CKPH Clock phase select 0 = capture on second edge, 1 = capture on first
CKPL Clock polarity select 0 = clock is idle-low, 1 = clock is high idle-high
Enumerator
SPI_MODE_0 

CPOL=0, CPHA=0.

SPI_MODE_1 

CPOL=0, CPHA=1.

SPI_MODE_2 

CPOL=1, CPHA=0.

SPI_MODE_3 

CPOL=1, CPHA=1.

Definition at line 62 of file periph_cpu.h.

Function Documentation

◆ msp430_usart_acquire()

void msp430_usart_acquire ( const msp430_usart_params_t params,
const msp430_usart_conf_t conf,
uint8_t  enable_mask 
)

Get exclusive access to an USART peripheral and initialize it for operation as configured.

Parameters
[in]paramsStatic USART configuration
[in]confDynamic USART configuration
[in]enable_maskBitmask to write to the SFR register to enable the peripheral in the intended mode.
Warning
The freshly acquired USART will still be placed in software reset when this function returns. The caller is expected to finish configuration such as configuring GPIOs connected to the USART suitably, clearing error flags, setting up IRQ handlers etc. and finally releasing the USART from reset.

◆ msp430_usart_are_both_irq_flags_set()

static bool msp430_usart_are_both_irq_flags_set ( const msp430_usart_params_t usart_conf)
inlinestatic

Check if both TX and RX IRQ flags are set on the given USART.

Parameters
[in]usart_confUSART config of the USART to disable the RX IRQ on
Return values
trueThe interrupt flag both TX and RX is set
falseEither TX IRQ flag not set, or RX not set, or neither set

Definition at line 317 of file periph_cpu.h.

◆ msp430_usart_clear_rx_irq_flag()

static void msp430_usart_clear_rx_irq_flag ( const msp430_usart_params_t usart_conf)
inlinestatic

Clear the RX IRQ flag of the given USART.

Parameters
[in]usart_confUSART config of the USART to disable the RX IRQ on

Definition at line 336 of file periph_cpu.h.

◆ msp430_usart_clear_tx_irq_flag()

static void msp430_usart_clear_tx_irq_flag ( const msp430_usart_params_t usart_conf)
inlinestatic

Clear the TX IRQ flag of the given USART.

Parameters
[in]usart_confUSART config of the USART to disable the RX IRQ on

Definition at line 327 of file periph_cpu.h.

◆ msp430_usart_disable_rx_irq()

static void msp430_usart_disable_rx_irq ( const msp430_usart_params_t usart_conf)
inlinestatic

Disable the RX interrupt on the given USART.

Parameters
[in]usart_confUSART config of the USART to disable the RX IRQ on
Warning
This will not work while the peripheral is still under reset, as the IRQ configuration is constantly reset while the software reset bit is set.

Definition at line 284 of file periph_cpu.h.

◆ msp430_usart_disable_tx_irq()

static void msp430_usart_disable_tx_irq ( const msp430_usart_params_t usart_conf)
inlinestatic

Disable the TX interrupt on the given USART.

Parameters
[in]usart_confUSART config of the USART to disable the TX IRQ on
Warning
This will not work while the peripheral is still under reset, as the IRQ configuration is constantly reset while the software reset bit is set.

Definition at line 271 of file periph_cpu.h.

◆ msp430_usart_enable_rx_irq()

static void msp430_usart_enable_rx_irq ( const msp430_usart_params_t usart_conf)
inlinestatic

Enable the RX interrupt on the given USART.

Parameters
[in]usart_confUSART config of the USART to enable the RX IRQ on
Warning
This will not work while the peripheral is still under reset, as the IRQ configuration is constantly reset while the software reset bit is set.

Definition at line 258 of file periph_cpu.h.

◆ msp430_usart_enable_tx_irq()

static void msp430_usart_enable_tx_irq ( const msp430_usart_params_t usart_conf)
inlinestatic

Enable the TX interrupt on the given USART.

Parameters
[in]usart_confUSART config of the USART to enable the TX IRQ on
Warning
This will not work while the peripheral is still under reset, as the IRQ configuration is constantly reset while the software reset bit is set.

Definition at line 245 of file periph_cpu.h.

◆ msp430_usart_get_rx_irq_flag()

static bool msp430_usart_get_rx_irq_flag ( const msp430_usart_params_t usart_conf)
inlinestatic

Get the RX IRQ flag of the given USART.

Parameters
[in]usart_confUSART config of the USART to disable the RX IRQ on
Return values
trueThe interrupt flag is set
falseThe interrupt flag is NOT set

Definition at line 306 of file periph_cpu.h.

◆ msp430_usart_get_tx_irq_flag()

static bool msp430_usart_get_tx_irq_flag ( const msp430_usart_params_t usart_conf)
inlinestatic

Get the TX IRQ flag of the given USART.

Parameters
[in]usart_confUSART config of the USART to disable the RX IRQ on
Return values
trueThe interrupt flag is set
falseThe interrupt flag is NOT set

Definition at line 295 of file periph_cpu.h.

◆ msp430_usart_prescale()

msp430_usart_prescaler_t msp430_usart_prescale ( uint32_t  clock,
uint16_t  min_br 
)

Compute a suitable prescaler.

Parameters
[in]clockSPI clock in Hz or UART symbol rate in Baud
[in]min_brSmallest BR0/BR1 value supported by hardware (USART_MIN_BR_SPI or USART_MIN_BR_UART)
Returns
Suitable prescaler config
Note
If the board has an auxiliary clock generated from a 32,678 Hz watch crystal with no clock divider, the auxiliary clock is used for symbol rates of 9,600 Bd, 4,800 Bd, 2,400 Bd, and 1,200 Bd. For every other symbol rate the subsystem main clock is used instead.
Warning
This will compute the prescaler generating the frequency closest to clock. It may generate a frequency higher than requested, if this is closer to the target frequency than the next lower frequency. This makes bit-timings better in UART
The mctl struct field in the result may be non-zero. Callers must clear this, if the intend to use the USART in modes other than UART.

◆ msp430_usart_release()

void msp430_usart_release ( const msp430_usart_params_t params)

Release exclusive access to an USART peripheral and turn it off again.

Parameters
[in]paramsConfiguration specifying the USART to release