Loading...
Searching...
No Matches
periph_cpu_common.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_common.h.

#include <stdbool.h>
#include "bitarithm.h"
#include "compiler_hints.h"
#include "cpu.h"
#include "msp430_regs.h"
+ Include dependency graph for periph_cpu_common.h:

Go to the source code of this file.

Data Structures

struct  msp430_clock_params_t
 MSP430Fxzy Basic Clock System Parameters. More...
 
struct  timer_conf_t
 Timer device configuration. More...
 

Macros

#define GPIO_UNDEF   (0xffff)
 Definition of a fitting UNDEF value.
 
#define GPIO_PIN(x, y)   ((gpio_t)(((x & 0xff) << 8) | (1 << (y & 0x07))))
 Mandatory function for defining a GPIO pins.
 
#define SPI_HWCS(x)   (SPI_CS_UNDEF)
 No support for HW chip select...
 
#define TIMER_CHANNEL_NUMOF   7
 The MSP430 timer peripheral can have up to 8 channels.
 

Enumerations

enum  {
  P1 = 1 , P2 = 2 , P3 = 3 , P4 = 4 ,
  P5 = 5 , P6 = 6
}
 Available ports on MSP430 platforms. More...
 
enum  msp430_main_clock_source_t { MAIN_CLOCK_SOURCE_DCOCLK = SELM_0 , MAIN_CLOCK_SOURCE_XT2CLK = SELM_2 , MAIN_CLOCK_SOURCE_LFXT1CLK = SELM_3 }
 Possible clock sources to generate the main clock from. More...
 
enum  msp430_submain_clock_source_t { SUBMAIN_CLOCK_SOURCE_DCOCLK = 0 , SUBMAIN_CLOCK_SOURCE_XT2CLK = SELS , SUBMAIN_CLOCK_SOURCE_LFXT1CLK = SELS }
 Possible clock sources to generate the submain clock from. More...
 
enum  msp430_main_clock_divider_t { MAIN_CLOCK_DIVIDE_BY_1 = DIVM_0 , MAIN_CLOCK_DIVIDE_BY_2 = DIVM_1 , MAIN_CLOCK_DIVIDE_BY_4 = DIVM_2 , MAIN_CLOCK_DIVIDE_BY_8 = DIVM_3 }
 Clock dividers for the main clock. More...
 
enum  msp430_submain_clock_divider_t { SUBMAIN_CLOCK_DIVIDE_BY_1 = DIVS_0 , SUBMAIN_CLOCK_DIVIDE_BY_2 = DIVS_1 , SUBMAIN_CLOCK_DIVIDE_BY_4 = DIVS_2 , SUBMAIN_CLOCK_DIVIDE_BY_8 = DIVS_3 }
 Clock dividers for the submain clock. More...
 
enum  msp430_auxiliary_clock_divider_t { AUXILIARY_CLOCK_DIVIDE_BY_1 = DIVA_0 , AUXILIARY_CLOCK_DIVIDE_BY_2 = DIVA_1 , AUXILIARY_CLOCK_DIVIDE_BY_4 = DIVA_2 , AUXILIARY_CLOCK_DIVIDE_BY_8 = DIVA_3 }
 Clock dividers for the auxiliary clock. More...
 
enum  msp430_timer_clock_source_t { TIMER_CLOCK_SOURCE_TXCLK = TXSSEL_TXCLK , TIMER_CLOCK_SOURCE_AUXILIARY_CLOCK = TXSSEL_ACLK , TIMER_CLOCK_SOURCE_SUBMAIN_CLOCK = TXSSEL_SMCLK , TIMER_CLOCK_SOURCE_INCLK = TXSSEL_INCLK }
 Enumeration of possible clock sources for a timer. More...
 

Functions

void gpio_periph_mode (gpio_t pin, bool enable)
 Enable or disable a pin to be used by peripheral modules.
 
void default_clock_init (void)
 Initialize the basic clock system to provide the main clock, the subsystem clock, and the auxiliary clock.
 
void clock_init (void)
 Call during boot up process to initialize the clock.
 
uint32_t PURE msp430_submain_clock_freq (void)
 Get the configured submain clock frequency.
 
uint32_t PURE msp430_auxiliary_clock_freq (void)
 Get the configured auxiliary clock frequency.
 

Variables

uint32_t msp430_dco_freq
 The measured DCO frequency.
 
#define HAVE_GPIO_T
 Define a custom type for GPIO pins.
 
typedef uint16_t gpio_t
 

Override flank selection values

#define HAVE_GPIO_FLANK_T
 MSP430 has a custom gpio_flank_t.
 
enum  gpio_flank_t { GPIO_FALLING = 0xff , GPIO_RISING = 0x00 , GPIO_BOTH = 0xab }
 Enumeration of supported GPIO flanks. More...
 

Macro Definition Documentation

◆ GPIO_PIN

#define GPIO_PIN (   x,
 
)    ((gpio_t)(((x & 0xff) << 8) | (1 << (y & 0x07))))

Mandatory function for defining a GPIO pins.

Definition at line 49 of file periph_cpu_common.h.

◆ GPIO_UNDEF

#define GPIO_UNDEF   (0xffff)

Definition of a fitting UNDEF value.

Definition at line 44 of file periph_cpu_common.h.

◆ HAVE_GPIO_FLANK_T

#define HAVE_GPIO_FLANK_T

MSP430 has a custom gpio_flank_t.

Definition at line 71 of file periph_cpu_common.h.

◆ HAVE_GPIO_T

#define HAVE_GPIO_T

Define a custom type for GPIO pins.

Definition at line 37 of file periph_cpu_common.h.

◆ SPI_HWCS

#define SPI_HWCS (   x)    (SPI_CS_UNDEF)

No support for HW chip select...

Definition at line 54 of file periph_cpu_common.h.

◆ TIMER_CHANNEL_NUMOF

#define TIMER_CHANNEL_NUMOF   7

The MSP430 timer peripheral can have up to 8 channels.

Note
The actual number of channels should be queried per timer, as timers have either 7 or 3 capture/compare channels; typically both variants are present in the same MCU. This is the highest number of channels supported, e.g. useful for "worst case" static memory allocation.

Definition at line 65 of file periph_cpu_common.h.

Typedef Documentation

◆ gpio_t

typedef uint16_t gpio_t

Definition at line 38 of file periph_cpu_common.h.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

Available ports on MSP430 platforms.

Enumerator
P1 

PORT 1.

P2 

PORT 2.

P3 

PORT 3.

P4 

PORT 4.

P5 

PORT 5.

P6 

PORT 6.

Definition at line 85 of file periph_cpu_common.h.

◆ gpio_flank_t

Enumeration of supported GPIO flanks.

Enumerator
GPIO_FALLING 

emit interrupt on falling flank

GPIO_RISING 

emit interrupt on rising flank

GPIO_BOTH 

not supported -> random value

Definition at line 75 of file periph_cpu_common.h.

◆ msp430_auxiliary_clock_divider_t

Clock dividers for the auxiliary clock.

Enumerator
AUXILIARY_CLOCK_DIVIDE_BY_1 

Divide the main clock by 1.

AUXILIARY_CLOCK_DIVIDE_BY_2 

Divide the main clock by 2.

AUXILIARY_CLOCK_DIVIDE_BY_4 

Divide the main clock by 4.

AUXILIARY_CLOCK_DIVIDE_BY_8 

Divide the main clock by 8.

Definition at line 209 of file periph_cpu_common.h.

◆ msp430_main_clock_divider_t

Clock dividers for the main clock.

Enumerator
MAIN_CLOCK_DIVIDE_BY_1 

Divide the main clock by 1.

MAIN_CLOCK_DIVIDE_BY_2 

Divide the main clock by 2.

MAIN_CLOCK_DIVIDE_BY_4 

Divide the main clock by 4.

MAIN_CLOCK_DIVIDE_BY_8 

Divide the main clock by 8.

Definition at line 165 of file periph_cpu_common.h.

◆ msp430_main_clock_source_t

Possible clock sources to generate the main clock from.

Enumerator
MAIN_CLOCK_SOURCE_DCOCLK 

Internal digitally controlled oscillator (DCO) with RC-type characteristics.

MAIN_CLOCK_SOURCE_XT2CLK 

High frequency crystal between 450 kHz and 8 MHz.

Note
If XT2 is not enabled, this will behave identical to MAIN_CLOCK_SOURCE_LFXT1CLK
MAIN_CLOCK_SOURCE_LFXT1CLK 

Low frequency 32.768 kHz or high frequency crystal between 450 kHz and 8 MHz.

Definition at line 113 of file periph_cpu_common.h.

◆ msp430_submain_clock_divider_t

Clock dividers for the submain clock.

Enumerator
SUBMAIN_CLOCK_DIVIDE_BY_1 

Divide the main clock by 1.

SUBMAIN_CLOCK_DIVIDE_BY_2 

Divide the main clock by 2.

SUBMAIN_CLOCK_DIVIDE_BY_4 

Divide the main clock by 4.

SUBMAIN_CLOCK_DIVIDE_BY_8 

Divide the main clock by 8.

Definition at line 187 of file periph_cpu_common.h.

◆ msp430_submain_clock_source_t

Possible clock sources to generate the submain clock from.

Enumerator
SUBMAIN_CLOCK_SOURCE_DCOCLK 

Internal digitally controlled oscillator (DCO) with RC-type characteristics.

SUBMAIN_CLOCK_SOURCE_XT2CLK 

High frequency crystal between 450 kHz and 8 MHz.

Note
If XT2 is not enabled, this will behave identical to SUBMAIN_CLOCK_SOURCE_LFXT1CLK
SUBMAIN_CLOCK_SOURCE_LFXT1CLK 

Low frequency 32.768 kHz or high frequency crystal between 450 kHz and 8 MHz.

Note
If XT2 is enabled, this will behave identical to SUBMAIN_CLOCK_SOURCE_XT2CLK

It is recommended to use SUBMAIN_CLOCK_SOURCE_XT2CLK when XT2 is present in the config to avoid confusion.

Definition at line 136 of file periph_cpu_common.h.

◆ msp430_timer_clock_source_t

Enumeration of possible clock sources for a timer.

Enumerator
TIMER_CLOCK_SOURCE_TXCLK 

External TxCLK as clock source.

TIMER_CLOCK_SOURCE_AUXILIARY_CLOCK 

Auxiliary clock as clock source.

TIMER_CLOCK_SOURCE_SUBMAIN_CLOCK 

Sub-system master clock as clock source.

TIMER_CLOCK_SOURCE_INCLK 

External INCLK as clock source.

Definition at line 307 of file periph_cpu_common.h.

Function Documentation

◆ clock_init()

void clock_init ( void  )

Call during boot up process to initialize the clock.

Note
This is a weak alias for default_clock_init so that this can be overwritten with a strong symbol from the board in case some special handling is required. The boards custom clock_init() can still call default_clock_init if that is useful; or it could do everything from scratch.

◆ default_clock_init()

void default_clock_init ( void  )

Initialize the basic clock system to provide the main clock, the subsystem clock, and the auxiliary clock.

The main clock, the subsystem clock, and the auxiliary clock will be set up as specified by static const msp430_clock_params_t clock_params in the periph_conf.h of the board.

Note
This function takes some time and typically is only called during boot.
Postcondition
The main clock, the subsystem clock and the auxiliary clock are are set up and stable

◆ gpio_periph_mode()

void gpio_periph_mode ( gpio_t  pin,
bool  enable 
)

Enable or disable a pin to be used by peripheral modules.

Parameters
[in]pinpin to (de-)select
[in]enabletrue for enabling peripheral use, false for disabling it

◆ msp430_auxiliary_clock_freq()

uint32_t PURE msp430_auxiliary_clock_freq ( void  )

Get the configured auxiliary clock frequency.

Note
This is only useful when implementing MSP430 peripheral drivers

◆ msp430_submain_clock_freq()

uint32_t PURE msp430_submain_clock_freq ( void  )

Get the configured submain clock frequency.

Note
This is only useful when implementing MSP430 peripheral drivers

Variable Documentation

◆ msp430_dco_freq

uint32_t msp430_dco_freq
extern

The measured DCO frequency.

Warning
This will have a value of 0 if the DCO is not enabled in the boards periph_conf.h