Skip to content

Commit

Permalink
Merge pull request #20160 from maribu/cpu/msp430/timer
Browse files Browse the repository at this point in the history
cpu/msp430: improve periph_timer
  • Loading branch information
maribu authored Dec 10, 2023
2 parents a3cd9ef + eca0bdd commit bb07bb6
Show file tree
Hide file tree
Showing 24 changed files with 372 additions and 180 deletions.
10 changes: 1 addition & 9 deletions boards/common/msb-430/Makefile.include
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
INCLUDES += -I$(RIOTBOARD)/common/msb-430/include

# set default port depending on operating system
PORT_LINUX ?= /dev/ttyUSB0
PORT_DARWIN ?= $(firstword $(sort $(wildcard /dev/tty.SLAB_USBtoUART*)))

# setup flash tool
PROGRAMMER ?= mspdebug
MSPDEBUG_PROGRAMMER ?= olimex

PROGRAMMERS_SUPPORTED += mspdebug
include $(RIOTBOARD)/common/msp430/Makefile.include
11 changes: 11 additions & 0 deletions boards/common/msp430/Makefile.include
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
INCLUDES += -I$(RIOTBOARD)/common/msp430/include

# set default port depending on operating system
PORT_LINUX ?= /dev/ttyUSB0
PORT_DARWIN ?= $(firstword $(sort $(wildcard /dev/tty.SLAB_USBtoUART*)))

# setup flash tool
PROGRAMMER ?= mspdebug
MSPDEBUG_PROGRAMMER ?= olimex

PROGRAMMERS_SUPPORTED += mspdebug
17 changes: 17 additions & 0 deletions boards/common/msp430/doc.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright (C) 2023 Otto-von-Guericke-Universität Magdeburg
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/

/**
* @defgroup boards_common_msp430 Common Configuration Snippets for MSP430 boards
* @ingroup boards_common
* @brief Board configuration snippets for MSP430-based boards
*
* All boards using a CPU from the MSP430 family share certain parts of their
* configuration. This module provides a collection of fine grained
* configuration snippets that can be reused for different boards.
*/
61 changes: 61 additions & 0 deletions boards/common/msp430/include/cfg_timer_a_smclk_b_aclk.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright (C) 2023 Otto-von-Guericke-Universität Magdeburg
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/

/**
* @ingroup boards_common_msp430
* @{
*
* @file
* @brief Common timer configuration for TIMER_A clocked by SMCLK and
* TIMER_B clocked by ACLK
*
* @author Marian Buschsieweke <[email protected]>
*/

#ifndef CFG_TIMER_A_SMCLK_B_ACLK_H
#define CFG_TIMER_A_SMCLK_B_ACLK_H

#include "periph_cpu.h"

#ifdef __cplusplus
extern "C" {
#endif

/**
* @name Timer configuration
* @{
*/
/**
* @brief Timer configuration
*/
static const timer_conf_t timer_conf[] = {
{
.timer = &TIMER_A,
.irq_flags = &TIMER_A_IRQFLAGS,
.clock_source = TIMER_CLOCK_SOURCE_SUBMAIN_CLOCK,
},
{
.timer = &TIMER_B,
.irq_flags = &TIMER_B_IRQFLAGS,
.clock_source = TIMER_CLOCK_SOURCE_AUXILIARY_CLOCK,
}
};
#define TIMER_NUMOF ARRAY_SIZE(timer_conf) /**< Number of timers available */

#define TIMER0_ISR_CC0 (TIMERA0_VECTOR) /**< IRQ vector for channel 0 of TIMER_DEV(0) */
#define TIMER0_ISR_CCX (TIMERA1_VECTOR) /**< IRQ vector for channels !=0 of TIMER_DEV(0) */

Check warning on line 51 in boards/common/msp430/include/cfg_timer_a_smclk_b_aclk.h

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters
#define TIMER1_ISR_CC0 (TIMERB0_VECTOR) /**< IRQ vector for channel 0 of TIMER_DEV(0) */
#define TIMER1_ISR_CCX (TIMERB1_VECTOR) /**< IRQ vector for channels !=0 of TIMER_DEV(1) */

Check warning on line 53 in boards/common/msp430/include/cfg_timer_a_smclk_b_aclk.h

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters
/** @} */

#ifdef __cplusplus
}
#endif

#endif /* CFG_TIMER_A_SMCLK_B_ACLK_H */
/** @} */
12 changes: 1 addition & 11 deletions boards/msb-430/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include "periph_cpu.h"
#include "macros/units.h"
#include "cfg_timer_a_smclk_b_aclk.h"

#ifdef __cplusplus
extern "C" {
Expand All @@ -44,17 +45,6 @@ static const msp430_clock_params_t clock_params = {
.has_r_osc = true,
};

/**
* @name Timer configuration
* @{
*/
#define TIMER_NUMOF (1U)
#define TIMER_BASE (&TIMER_A)
#define TIMER_CHAN (3)
#define TIMER_ISR_CC0 (TIMERA0_VECTOR)
#define TIMER_ISR_CCX (TIMERA1_VECTOR)
/** @} */

/**
* @name UART configuration
* @{
Expand Down
12 changes: 1 addition & 11 deletions boards/msb-430h/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#define PERIPH_CONF_H

#include "periph_cpu.h"
#include "cfg_timer_a_smclk_b_aclk.h"

#ifdef __cplusplus
extern "C" {
Expand All @@ -43,17 +44,6 @@ static const msp430_clock_params_t clock_params = {
.has_r_osc = true,
};

/**
* @name Timer configuration
* @{
*/
#define TIMER_NUMOF (1U)
#define TIMER_BASE (&TIMER_A)
#define TIMER_CHAN (3)
#define TIMER_ISR_CC0 (TIMERA0_VECTOR)
#define TIMER_ISR_CCX (TIMERA1_VECTOR)
/** @} */

/**
* @name UART configuration
* @{
Expand Down
12 changes: 2 additions & 10 deletions boards/olimex-msp430-h1611/Makefile.include
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
# set default port depending on operating system
PORT_LINUX ?= /dev/ttyUSB0
PORT_DARWIN ?= $(firstword $(sort $(wildcard /dev/tty.usbserial-MXV*)))

# flash tool configuration
PROGRAMMER ?= mspdebug
MSPDEBUG_PROGRAMMER ?= olimex

PROGRAMMERS_SUPPORTED += mspdebug

# When freshly plugged in the Olimex MSP430-JTAG-Tiny debugger provides a
# ttyACM interface, which is only available until the first flashing. A
# `make term` or even a `make flash term` may pick the JTAG debugger instead
Expand All @@ -24,3 +14,5 @@ TTY_SELECT_CMD := $(RIOTTOOLS)/usb-serial/ttys.py \
$(RIOTTOOLS)/usb-serial/ttys.py \
--most-recent \
--format path serial

include $(RIOTBOARD)/common/msp430/Makefile.include
12 changes: 1 addition & 11 deletions boards/olimex-msp430-h1611/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include "periph_cpu.h"
#include "macros/units.h"
#include "cfg_timer_a_smclk_b_aclk.h"

#ifdef __cplusplus
extern "C" {
Expand All @@ -43,17 +44,6 @@ static const msp430_clock_params_t clock_params = {
.auxiliary_clock_divier = AUXILIARY_CLOCK_DIVIDE_BY_1,
};

/**
* @name Timer configuration
* @{
*/
#define TIMER_NUMOF (1U)
#define TIMER_BASE (&TIMER_A)
#define TIMER_CHAN (3)
#define TIMER_ISR_CC0 (TIMERA0_VECTOR)
#define TIMER_ISR_CCX (TIMERA1_VECTOR)
/** @} */

/**
* @name UART configuration
* @{
Expand Down
12 changes: 2 additions & 10 deletions boards/olimex-msp430-h2618/Makefile.include
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
# set default port depending on operating system
PORT_LINUX ?= /dev/ttyUSB0
PORT_DARWIN ?= $(firstword $(sort $(wildcard /dev/tty.usbserial-MXV*)))

# flash tool configuration
PROGRAMMER ?= mspdebug
MSPDEBUG_PROGRAMMER ?= olimex

PROGRAMMERS_SUPPORTED += mspdebug

# When freshly plugged in the Olimex MSP430-JTAG-Tiny debugger provides a
# ttyACM interface, which is only available until the first flashing. A
# `make term` or even a `make flash term` may pick the JTAG debugger instead
Expand All @@ -24,3 +14,5 @@ TTY_SELECT_CMD := $(RIOTTOOLS)/usb-serial/ttys.py \
$(RIOTTOOLS)/usb-serial/ttys.py \
--most-recent \
--format path serial

include $(RIOTBOARD)/common/msp430/Makefile.include
12 changes: 1 addition & 11 deletions boards/olimex-msp430-h2618/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include "periph_cpu.h"
#include "macros/units.h"
#include "cfg_timer_a_smclk_b_aclk.h"

#ifdef __cplusplus
extern "C" {
Expand All @@ -42,17 +43,6 @@ static const msp430_clock_params_t clock_params = {
.auxiliary_clock_divier = AUXILIARY_CLOCK_DIVIDE_BY_1,
};

/**
* @name Timer configuration
* @{
*/
#define TIMER_NUMOF (1U)
#define TIMER_BASE (&TIMER_A)
#define TIMER_CHAN (3)
#define TIMER_ISR_CC0 (TIMERA0_VECTOR)
#define TIMER_ISR_CCX (TIMERA1_VECTOR)
/** @} */

/**
* @name UART configuration
* @{
Expand Down
8 changes: 2 additions & 6 deletions boards/telosb/Makefile.include
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
# set default port depending on operating system
PORT_LINUX ?= /dev/ttyUSB0
PORT_DARWIN ?= $(firstword $(sort $(wildcard /dev/tty.usbserial-MXV*)))
# setup serial terminal
BAUD ?= 9600

# flash tool configuration
PROGRAMMER ?= goodfet
GOODFET_FLAGS ?= --telosb

PROGRAMMERS_SUPPORTED += goodfet

include $(RIOTBOARD)/common/msp430/Makefile.include
12 changes: 1 addition & 11 deletions boards/telosb/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include "macros/units.h"
#include "periph_cpu.h"
#include "cfg_timer_a_smclk_b_aclk.h"

#ifdef __cplusplus
extern "C" {
Expand All @@ -43,17 +44,6 @@ static const msp430_clock_params_t clock_params = {
.auxiliary_clock_divier = AUXILIARY_CLOCK_DIVIDE_BY_1,
};

/**
* @name Timer configuration
* @{
*/
#define TIMER_NUMOF (1U)
#define TIMER_BASE (&TIMER_A)
#define TIMER_CHAN (3)
#define TIMER_ISR_CC0 (TIMERA0_VECTOR)
#define TIMER_ISR_CCX (TIMERA1_VECTOR)
/** @} */

/**
* @name UART configuration
* @{
Expand Down
6 changes: 2 additions & 4 deletions boards/z1/Makefile.include
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# set default port depending on operating system
PORT_LINUX ?= /dev/ttyUSB0
PORT_DARWIN ?= $(firstword $(sort $(wildcard /dev/tty.SLAB_USBtoUART*)))

# setup flash tool
PROGRAMMER ?= goodfet
GOODFET_FLAGS ?= --z1

PROGRAMMERS_SUPPORTED += goodfet

include $(RIOTBOARD)/common/msp430/Makefile.include
12 changes: 1 addition & 11 deletions boards/z1/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include "macros/units.h"
#include "periph_cpu.h"
#include "cfg_timer_a_smclk_b_aclk.h"

#ifdef __cplusplus
extern "C" {
Expand All @@ -43,17 +44,6 @@ static const msp430_clock_params_t clock_params = {
.auxiliary_clock_divier = AUXILIARY_CLOCK_DIVIDE_BY_1,
};

/**
* @name Timer configuration
* @{
*/
#define TIMER_NUMOF (1U)
#define TIMER_BASE (&TIMER_A)
#define TIMER_CHAN (3)
#define TIMER_ISR_CC0 (TIMERA0_VECTOR)
#define TIMER_ISR_CCX (TIMERA1_VECTOR)
/** @} */

/**
* @name UART configuration
* @{
Expand Down
1 change: 1 addition & 0 deletions cpu/msp430/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ config CPU_ARCH_MSP430
select HAS_PERIPH_FLASHPAGE_IN_ADDRESS_SPACE
select HAS_PERIPH_FLASHPAGE_PAGEWISE
select HAS_PERIPH_PM
select HAS_PERIPH_TIMER_QUERY_FREQS
select MODULE_MALLOC_THREAD_SAFE if TEST_KCONFIG

config HAS_CPU_MSP430
Expand Down
1 change: 1 addition & 0 deletions cpu/msp430/Makefile.features
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ FEATURES_PROVIDED += periph_flashpage
FEATURES_PROVIDED += periph_flashpage_in_address_space
FEATURES_PROVIDED += periph_flashpage_pagewise
FEATURES_PROVIDED += periph_pm
FEATURES_PROVIDED += periph_timer_query_freqs
5 changes: 3 additions & 2 deletions cpu/msp430/clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,8 @@ void default_clock_init(void)

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

uint32_t msp430_submain_clock_freq(void) {
uint32_t PURE 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 @@ -365,7 +366,7 @@ uint32_t msp430_submain_clock_freq(void) {
}
}

uint32_t msp430_auxiliary_clock_freq(void)
uint32_t PURE msp430_auxiliary_clock_freq(void)
{
uint16_t shift = (clock_params.auxiliary_clock_divier >> 4) & 0x3;
return clock_params.lfxt1_frequency >> shift;
Expand Down
Loading

0 comments on commit bb07bb6

Please sign in to comment.