Skip to content

Commit

Permalink
cpu/msp430: reorganize code
Browse files Browse the repository at this point in the history
RIOT supports two distinct families of the MSP430: The [MSP430 x1xx]
MCU family and the [MSP430 F2xx/G2xx] MCU family. For both incompatible
MCU families the code was located in the msp430fxyz folder, resulting
in case of the UART driver in particularly bizarre code looking roughly
like this:

    #ifndef UART_USE_USCI
    /* implementation of x1xx peripheral ... */
    #else
    /* implementation of F2xx/G2xx peripheral ... */
    #endif
    /* zero shared code between both variants */

This splits the peripheral drivers for USCI and USART serial IP blocks
into separate files and relocates everything in cpu/msp430, similar to
how cpu/stm32 is organized.

[MSP430 x1xx]: https://www.ti.com/lit/ug/slau049f/slau049f.pdf
[MSP430 F2xx/G2xx]: https://www.ti.com/lit/ug/slau144k/slau144k.pdf
  • Loading branch information
maribu committed Jun 19, 2023
1 parent 4deca3d commit ff7f8ae
Show file tree
Hide file tree
Showing 91 changed files with 1,216 additions and 801 deletions.
2 changes: 1 addition & 1 deletion boards/common/msb-430/Makefile.features
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
CPU = msp430fxyz
CPU = msp430
CPU_MODEL = msp430f1612
4 changes: 2 additions & 2 deletions boards/msb-430/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
extern "C" {
#endif

#define CLOCK_CORECLOCK msp430_fxyz_dco_freq
#define CLOCK_CORECLOCK msp430_dco_freq

/**
* @brief Clock configuration
*/
static const msp430_fxyz_clock_params_t clock_params = {
static const msp430_clock_params_t clock_params = {
.target_dco_frequency = 7372800U,
.lfxt1_frequency = 32768,
.main_clock_source = MAIN_CLOCK_SOURCE_DCOCLK,
Expand Down
2 changes: 1 addition & 1 deletion boards/msb-430h/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ extern "C" {
/**
* @brief Clock configuration
*/
static const msp430_fxyz_clock_params_t clock_params = {
static const msp430_clock_params_t clock_params = {
.xt2_frequency = CLOCK_CORECLOCK,
.lfxt1_frequency = 32768,
.main_clock_source = MAIN_CLOCK_SOURCE_XT2CLK,
Expand Down
2 changes: 1 addition & 1 deletion boards/olimex-msp430-h1611/Makefile.features
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CPU = msp430fxyz
CPU = msp430
CPU_MODEL = msp430f1611

# Put defined MCU peripherals here (in alphabetical order)
Expand Down
4 changes: 2 additions & 2 deletions boards/olimex-msp430-h1611/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
extern "C" {
#endif

#define CLOCK_CORECLOCK msp430_fxyz_dco_freq
#define CLOCK_CORECLOCK msp430_dco_freq

/**
* @brief Clock configuration
*/
static const msp430_fxyz_clock_params_t clock_params = {
static const msp430_clock_params_t clock_params = {
.target_dco_frequency = MHZ(8),
.lfxt1_frequency = 32768,
.main_clock_source = MAIN_CLOCK_SOURCE_DCOCLK,
Expand Down
2 changes: 1 addition & 1 deletion boards/olimex-msp430-h2618/Makefile.features
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CPU = msp430fxyz
CPU = msp430
CPU_MODEL = msp430f2618

# Put defined MCU peripherals here (in alphabetical order)
Expand Down
6 changes: 2 additions & 4 deletions boards/olimex-msp430-h2618/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@
extern "C" {
#endif

#define CLOCK_CORECLOCK msp430_fxyz_dco_freq
#define CLOCK_CORECLOCK msp430_dco_freq

/**
* @brief Clock configuration
*/
static const msp430_fxyz_clock_params_t clock_params = {
static const msp430_clock_params_t clock_params = {
.target_dco_frequency = MHZ(16),
.lfxt1_frequency = 32768,
.main_clock_source = MAIN_CLOCK_SOURCE_DCOCLK,
Expand All @@ -59,7 +59,6 @@ static const msp430_fxyz_clock_params_t clock_params = {
*/
#define UART_NUMOF (1U)

#define UART_USE_USCI
#define UART_BASE (USCI_0)
#define UART_IE (SFR->IE2)
#define UART_IF (SFR->IFG2)
Expand All @@ -80,7 +79,6 @@ static const msp430_fxyz_clock_params_t clock_params = {
#define SPI_NUMOF (1U)

/* SPI configuration */
#define SPI_USE_USCI
#define SPI_BASE (USCI_0_B_SPI)
#define SPI_IE (SFR->IE2)
#define SPI_IF (SFR->IFG2)
Expand Down
2 changes: 1 addition & 1 deletion boards/telosb/Makefile.features
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CPU = msp430fxyz
CPU = msp430
CPU_MODEL = msp430f1611

# Put defined MCU peripherals here (in alphabetical order)
Expand Down
4 changes: 2 additions & 2 deletions boards/telosb/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
extern "C" {
#endif

#define CLOCK_CORECLOCK msp430_fxyz_dco_freq
#define CLOCK_CORECLOCK msp430_dco_freq

/**
* @brief Clock configuration
*/
static const msp430_fxyz_clock_params_t clock_params = {
static const msp430_clock_params_t clock_params = {
.target_dco_frequency = 2457600U,
.lfxt1_frequency = 32768,
.main_clock_source = MAIN_CLOCK_SOURCE_DCOCLK,
Expand Down
2 changes: 1 addition & 1 deletion boards/z1/Makefile.features
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
CPU = msp430fxyz
CPU = msp430
CPU_MODEL = msp430f2617

# Put defined MCU peripherals here (in alphabetical order)
Expand Down
6 changes: 2 additions & 4 deletions boards/z1/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
extern "C" {
#endif

#define CLOCK_CORECLOCK msp430_fxyz_dco_freq
#define CLOCK_CORECLOCK msp430_dco_freq

/**
* @brief Clock configuration
*/
static const msp430_fxyz_clock_params_t clock_params = {
static const msp430_clock_params_t clock_params = {
.target_dco_frequency = MHZ(8),
.lfxt1_frequency = 32768,
.main_clock_source = MAIN_CLOCK_SOURCE_DCOCLK,
Expand All @@ -60,7 +60,6 @@ static const msp430_fxyz_clock_params_t clock_params = {
*/
#define UART_NUMOF (1U)

#define UART_USE_USCI
#define UART_BASE (USCI_0)
#define UART_IE (SFR->IE2)
#define UART_IF (SFR->IFG2)
Expand All @@ -81,7 +80,6 @@ static const msp430_fxyz_clock_params_t clock_params = {
#define SPI_NUMOF (1U)

/* SPI configuration */
#define SPI_USE_USCI
#define SPI_BASE (USCI_0_B_SPI)
#define SPI_IE (SFR->IE2)
#define SPI_IF (SFR->IFG2)
Expand Down
48 changes: 23 additions & 25 deletions cpu/msp430_common/Kconfig → cpu/msp430/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -6,48 +6,42 @@
# directory for more details.
#

config MODULE_MSP430_COMMON
bool
default y if CPU_CORE_MSP430
depends on TEST_KCONFIG
imply MODULE_NEWLIB_NANO
select MODULE_MALLOC_THREAD_SAFE
help
Common code for MSP430 cores.

config MODULE_MSP430_COMMON_PERIPH
bool
default y if CPU_CORE_MSP430
depends on TEST_KCONFIG
select MODULE_PERIPH
help
Common peripheral code for MSP430 cores.

choice LIBC_IMPLEMENTATION
default MODULE_NEWLIB
endchoice

config CPU_ARCH_MSP430
bool
imply MODULE_NEWLIB_NANO
select HAS_ARCH_16BIT
select HAS_ARCH_MSP430
select HAS_CPU_MSP430
select HAS_DBGPIN
select HAS_NEWLIB
select HAS_PERIPH_FLASHPAGE
select HAS_PERIPH_FLASHPAGE_IN_ADDRESS_SPACE
select HAS_PERIPH_FLASHPAGE_PAGEWISE
select HAS_NEWLIB
select HAS_PERIPH_PM
select MODULE_MALLOC_THREAD_SAFE if TEST_KCONFIG

config HAS_CPU_MSP430
bool
help
Indicates that an 'MSP430' CPU is being used.

config CPU_CORE_MSP430
config CPU_MSP430
bool
select CPU_ARCH_MSP430

choice LIBC_IMPLEMENTATION
default MODULE_NEWLIB
endchoice

## Common CPU symbols
config CPU_ARCH
default "msp430" if CPU_ARCH_MSP430
default "msp430" if CPU_MSP430

config CPU
default "msp430" if CPU_MSP430

config CPU_CORE
default "msp430" if CPU_CORE_MSP430
default "msp430" if CPU_MSP430

## Definition of specific features
config HAS_ARCH_MSP430
Expand All @@ -59,3 +53,7 @@ config HAS_ARCH_MSP430
config GNRC_PKTBUF_SIZE
default 2560
depends on KCONFIG_USEMODULE_GNRC_PKTBUF_STATIC

source "$(RIOTCPU)/msp430/periph/Kconfig"
source "$(RIOTCPU)/msp430/kconfigs/x1xx/Kconfig"
source "$(RIOTCPU)/msp430/kconfigs/f2xx_g2xx/Kconfig"
5 changes: 5 additions & 0 deletions cpu/msp430/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
MODULE = cpu

DIRS := periph

include $(RIOTBASE)/Makefile.base
3 changes: 1 addition & 2 deletions cpu/msp430_common/Makefile.dep → cpu/msp430/Makefile.dep
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
USEMODULE += msp430_common
USEMODULE += msp430_common_periph
USEMODULE += newlib
USEMODULE += periph

ifneq (,$(filter newlib,$(USEMODULE)))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
CPU_ARCH = msp430
CPU_CORE = msp430

ifneq (,$(filter msp430f2% msp430g2%,$(CPU_MODEL)))
CPU_FAM := msp430_f2xx_g2xx
endif

ifneq (,$(filter msp430f1%,$(CPU_MODEL)))
CPU_FAM := msp430_x1xx
endif

FEATURES_PROVIDED += arch_16bit
FEATURES_PROVIDED += arch_msp430
FEATURES_PROVIDED += cpu_$(CPU_FAM)
FEATURES_PROVIDED += dbgpin
FEATURES_PROVIDED += newlib
FEATURES_PROVIDED += periph_flashpage
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
INCLUDES += -I$(RIOTCPU)/msp430_common/include/
INCLUDES += -I$(RIOTCPU)/msp430/include/
INCLUDES += -I$(RIOTCPU)/msp430/include/$(subst msp430_,,$(CPU_FAM))

CFLAGS += -DCPU_MODEL_$(call uppercase_and_underscore,$(CPU_MODEL))

Expand Down
14 changes: 7 additions & 7 deletions cpu/msp430fxyz/clock.c → cpu/msp430/clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/

/**
* @ingroup cpu_msp430fxyz
* @ingroup cpu_msp430
* @{
* @file
* @brief MSP430Fxzy clock initialization
Expand Down Expand Up @@ -38,9 +38,9 @@
#define HAS_RSEL3 0
#endif

uint32_t msp430_fxyz_dco_freq;
uint32_t msp430_dco_freq;

static inline bool is_dco_in_use(const msp430_fxyz_clock_params_t *params)
static inline bool is_dco_in_use(const msp430_clock_params_t *params)
{
return ((params->main_clock_source == MAIN_CLOCK_SOURCE_DCOCLK) ||
(params->submain_clock_source == SUBMAIN_CLOCK_SOURCE_DCOCLK));
Expand Down Expand Up @@ -253,7 +253,7 @@ static void calibrate_dco(void)
TACTL = 0;

/* calculate actual DCO frequency */
msp430_fxyz_dco_freq = (clock_params.lfxt1_frequency * actual_clock_ratio) >> 3;
msp430_dco_freq = (clock_params.lfxt1_frequency * actual_clock_ratio) >> 3;
}

void default_clock_init(void)
Expand Down Expand Up @@ -348,7 +348,7 @@ void default_clock_init(void)

__attribute__((weak, alias("default_clock_init"))) void clock_init(void);

uint32_t msp430_fxyz_submain_clock_freq(void) {
uint32_t msp430_submain_clock_freq(void) {
uint16_t shift = (clock_params.submain_clock_divier >> 1) & 0x3;
switch (clock_params.submain_clock_source) {
case SUBMAIN_CLOCK_SOURCE_LFXT1CLK:
Expand All @@ -361,11 +361,11 @@ uint32_t msp430_fxyz_submain_clock_freq(void) {
return clock_params.lfxt1_frequency >> shift;
default:
case SUBMAIN_CLOCK_SOURCE_DCOCLK:
return msp430_fxyz_dco_freq >> shift;
return msp430_dco_freq >> shift;
}
}

uint32_t msp430_fxyz_auxiliary_clock_freq(void)
uint32_t msp430_auxiliary_clock_freq(void)
{
uint16_t shift = (clock_params.auxiliary_clock_divier >> 4) & 0x3;
return clock_params.lfxt1_frequency >> shift;
Expand Down
File renamed without changes.
36 changes: 36 additions & 0 deletions cpu/msp430/doc.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
@defgroup cpu_msp430 TI MSP430
@ingroup cpu
@brief Texas Instruments MSP430 specific code

Support for [TI MSP430] CPU architecture. Check the [MSP430 Dev Guide Book]
for an overview and a starting point for the CPU architecture. See
[MSP430 Programming With JTAG] on how to interface with the MCUs.

[TI MSP430]: https://www.ti.com/microcontrollers-mcus-processors/msp430-microcontrollers/overview.html
[MSP430 Dev Guide Book]: https://www.ti.com/lit/ug/slau840a/slau840a.pdf
[MSP430 Programming With JTAG]: https://www.ti.com/lit/ug/slau320aj/slau320aj.pdf
*/


/**
@defgroup cpu_msp430_f2xx_g2xx MSP430 F2xx/G2xx MCU family
@ingroup cpu_msp430
@brief Common code for the MSP430 F2xx/G2xx MCU family

This module contains code common to all of the [MSP430 F2xx/G2xx] MCU family.

[MSP430 F2xx/G2xx]: https://www.ti.com/lit/ug/slau144k/slau144k.pdf
*/


/**
@defgroup cpu_msp430_x1xx MSP430 x1xx MCU family
@ingroup cpu_msp430
@brief Common code for the MSP430 x1xx MCU family

This module contains code common to all of the [MSP430 x1xx] MCU family.

[MSP430 x1xx]: https://www.ti.com/lit/ug/slau049f/slau049f.pdf

*/
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

/**
* @ingroup cpu_msp430_common
* @ingroup cpu_msp430
* @{
*
* @file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

/**
* @ingroup cpu_msp430_common
* @ingroup cpu_msp430
*
* @{
*
Expand Down
3 changes: 1 addition & 2 deletions cpu/msp430_common/include/cpu.h → cpu/msp430/include/cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
*/

/**
* @defgroup cpu_msp430_common TI MSP430
* @ingroup cpu
* @ingroup cpu_msp430
* @brief Texas Instruments MSP430 specific code
*
* @{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

/**
* @ingroup cpu_msp430_common
* @ingroup cpu_msp430
* @{
*
* @file
Expand Down
Loading

0 comments on commit ff7f8ae

Please sign in to comment.