Commit 1d654e77 authored by Bernd-Christian Renner's avatar Bernd-Christian Renner
Browse files

clean-up

parent 1c67958d
...@@ -186,7 +186,7 @@ agc_setGain(void) ...@@ -186,7 +186,7 @@ agc_setGain(void)
void void
agc_init(bool en) agc_init(bool en)
{ {
// enable ? // store enable state
enabled = en; enabled = en;
if (enabled) { if (enabled) {
led_on(LED_AGC); led_on(LED_AGC);
...@@ -216,8 +216,8 @@ agc_enable(void) ...@@ -216,8 +216,8 @@ agc_enable(void)
void void
agc_disable(void) agc_disable(void)
{ {
led_off(LED_AGC);
enabled = false; enabled = false;
led_off(LED_AGC);
} }
...@@ -228,12 +228,12 @@ agc_restore(void) ...@@ -228,12 +228,12 @@ agc_restore(void)
// make sure that previously set gain is set correctly // make sure that previously set gain is set correctly
// however, avoid extremes (min or max): if anything in the lower // however, avoid extremes (min or max): if anything in the lower
// layer is wrong, this may lead to a lock-out (we assume at least // layer is wrong, this may lead to a lock-out (we assume at least
// three levels // three levels)
if (enabled) { if (enabled) {
if (gainLvl == 0) { if (gainLvl == 0) {
gainLvl++; gainLvl = 1;
} else if (gainLvl >= NUM_GAIN_LEVELS - 1) { } else if (gainLvl >= NUM_GAIN_LEVELS - 1) {
gainLvl--; gainLvl = NUM_GAIN_LEVELS - 2;
} }
agc_setGain(); agc_setGain();
} }
...@@ -316,6 +316,7 @@ agc_checkAction(sample_time_t ticks) ...@@ -316,6 +316,7 @@ agc_checkAction(sample_time_t ticks)
} }
void void
agc_processSample(fp16_t sample, sample_time_t ticks) agc_processSample(fp16_t sample, sample_time_t ticks)
{ {
......
...@@ -133,8 +133,8 @@ enum { ...@@ -133,8 +133,8 @@ enum {
#define FREQ_IDX(n) (n) #define FREQ_IDX(n) (n)
#define FREQ_LIST_NUM 49 #define FREQ_LIST_NUM 49
#define SAMPLES_PER_SYMBOL_MASK (SAMPLES_PER_SYMBOL-1) #define SAMPLES_PER_SYMBOL_MASK (SAMPLES_PER_SYMBOL-1)
const fp16_t * const FREQ_LIST[FREQ_LIST_NUM]; extern const fp16_t * const FREQ_LIST[FREQ_LIST_NUM];
const fp16_t * const FREQ_TXLIST[FREQ_LIST_NUM]; extern const fp16_t * const FREQ_TXLIST[FREQ_LIST_NUM];
// sync/preamble length setup // sync/preamble length setup
......
...@@ -38,19 +38,6 @@ ...@@ -38,19 +38,6 @@
#ifndef HAL_BOARD_H_ #ifndef HAL_BOARD_H_
#define HAL_BOARD_H_ #define HAL_BOARD_H_
// needs to define
//
// static inline void
// __attribute__((__always_inline__))
// board_enterPowerSaveMode(void) {
// ...
// }
//
// static inline void
// __attribute__((__always_inline__))
// board_restMCU(void) {
// }
#include "mcu_board.h" #include "mcu_board.h"
#endif #endif
...@@ -425,7 +425,6 @@ ISR_ADC(void) ...@@ -425,7 +425,6 @@ ISR_ADC(void)
// read from ADC // read from ADC
// note that this starts the conversion and sample will be available next time // note that this starts the conversion and sample will be available next time
spi_receive((void *)&SPI_RX_Buf); spi_receive((void *)&SPI_RX_Buf);
} }
......
/** /**
* Copyright 2016-2019 * Copyright 2016-2021
* *
* Timo Kortbrae, * Timo Kortbrae,
* Jan Heitmann, * Jan Heitmann,
...@@ -36,13 +36,6 @@ ...@@ -36,13 +36,6 @@
*/ */
/*! \file board_config.h
\brief Configuration file for the stm32f4 project
This file can be used to add application and target specific configurations to the project by adding defines and include paths.
All hal interfaces include this header file.
*/
#ifndef BOARD_CONFIG_H_ #ifndef BOARD_CONFIG_H_
#define BOARD_CONFIG_H_ #define BOARD_CONFIG_H_
...@@ -51,6 +44,7 @@ ...@@ -51,6 +44,7 @@
#define INTERRUPT //!< The INTERRUPT define is not needed for the stm32f4 project #define INTERRUPT //!< The INTERRUPT define is not needed for the stm32f4 project
#define CONST #define CONST
// adc/dac spi channels // adc/dac spi channels
/** /**
* \defgroup spi_channels adc/dac spi channels * \defgroup spi_channels adc/dac spi channels
...@@ -61,6 +55,7 @@ ...@@ -61,6 +55,7 @@
#define NO_CHANNEL 2 #define NO_CHANNEL 2
/** @} */ /** @} */
/** /**
* \defgroup timer_config configuration for adc/dac and uart timer * \defgroup timer_config configuration for adc/dac and uart timer
* @{ * @{
...@@ -95,38 +90,31 @@ ...@@ -95,38 +90,31 @@
* @{ * @{
*/ */
#ifdef PIN_DEBUG
//#define DEBUG_GPIO_PORT GPIOC //#define DEBUG_GPIO_PORT GPIOC
#define DEBUG_PIN_0 MODEM_GPIO_10 # define DEBUG_PIN_0 MODEM_GPIO_10
#define DEBUG_PIN_1 MODEM_GPIO_1 # define DEBUG_PIN_1 MODEM_GPIO_1
#define DEBUG_PIN_2 MODEM_GPIO_2 # define DEBUG_PIN_2 MODEM_GPIO_2
#define DEBUG_PIN_3 MODEM_GPIO_3 # define DEBUG_PIN_3 MODEM_GPIO_3
#define DEBUG_PIN_4 MODEM_GPIO_4 # define DEBUG_PIN_4 MODEM_GPIO_4
#define DEBUG_PIN_5 MODEM_GPIO_5 # define DEBUG_PIN_5 MODEM_GPIO_5
#define DEBUG_PIN_6 MODEM_GPIO_6 # define DEBUG_PIN_6 MODEM_GPIO_6
#define DEBUG_PIN_7 MODEM_GPIO_7 # define DEBUG_PIN_7 MODEM_GPIO_7
#define DEBUG_PIN_8 MODEM_GPIO_8 # define DEBUG_PIN_8 MODEM_GPIO_8
#define DEBUG_PIN_9 MODEM_GPIO_9 # define DEBUG_PIN_9 MODEM_GPIO_9
#endif
/** @} */ /** @} */
/** /**
* \defgroup gpio_pins STM32F4 GPIO Pins * \defgroup gpio_pins STM32F4 GPIO Pins
* @{ * @{
*/ */
// #define ... (gpio_t){GPIOC, GPIO_PIN_11} // currently unused
#define TXEN_PIN (gpio_t){GPIOA, GPIO_PIN_1}
#define RXEN_PIN (gpio_t){GPIOA, GPIO_PIN_0} #define RXEN_PIN (gpio_t){GPIOA, GPIO_PIN_0}
#define TXEN_PIN (gpio_t){GPIOA, GPIO_PIN_1}
#define TXRX_SW_PIN (gpio_t){GPIOA, GPIO_PIN_2} #define TXRX_SW_PIN (gpio_t){GPIOA, GPIO_PIN_2}
#define MODEM_EN_PIN (gpio_t){GPIOA, GPIO_PIN_8}
/** @} */ /** @} */
/**
* \defgroup modem_sleep_pin STM32F4 Sleep
* @{
*/
// #define SLEEP_PIN (gpio_t){GPIOA, GPIO_PIN_8}
// #define SLEEP_EXTI_IRQn EXTI9_5_IRQn
// #define SLEEP_EXTI_IRQHandler EXTI9_5_IRQHandler
/** /**
* \defgroup leds STM32F4 Led to GPIO mapping * \defgroup leds STM32F4 Led to GPIO mapping
...@@ -229,7 +217,7 @@ enum { ...@@ -229,7 +217,7 @@ enum {
}; };
// flash setup for modem config // flash setup for modem config (the legacy board has no EEPROM IC)
#define MODEM_CONFIG_FLASH_SECTOR FLASH_SECTOR_7 #define MODEM_CONFIG_FLASH_SECTOR FLASH_SECTOR_7
#define MODEM_CONFIG_ADDR_START 0x08060000 /* 128kb sector :-( */ #define MODEM_CONFIG_ADDR_START 0x08060000 /* 128kb sector :-( */
#define MODEM_CONFIG_ADDR_END 0x0807FFFF #define MODEM_CONFIG_ADDR_END 0x0807FFFF
......
/** /**
* Copyright 2016-2018 * Copyright 2016-2020
* *
* Timo Kortbrae, * Timo Kortbrae,
* Jan Heitmann, * Jan Heitmann,
...@@ -50,9 +50,15 @@ ...@@ -50,9 +50,15 @@
static inline void static inline void
__attribute__((__always_inline__)) __attribute__((__always_inline__))
board_enterPowerSaveMode(void) { board_enterPowerSaveMode(void) {
// sleep mode (not deep sleep aka stop)
CLEAR_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk)); CLEAR_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk));
__WFI(); // Sleep and wait for next interrupt __WFI(); // Sleep and wait for next interrupt
//HAL_PWR_EnterSTANDBYMode();
} }
/** /**
* @brief Resets the MCU * @brief Resets the MCU
* *
......
/** /**
* Copyright 2016-2019 * Copyright 2016-2021
* *
* Timo Kortbrae, * Timo Kortbrae,
* Jan Heitmann, * Jan Heitmann,
...@@ -44,6 +44,7 @@ ...@@ -44,6 +44,7 @@
#define INTERRUPT //!< The INTERRUPT define is not needed for the stm32f4 project #define INTERRUPT //!< The INTERRUPT define is not needed for the stm32f4 project
#define CONST #define CONST
// adc/dac spi channels // adc/dac spi channels
/** /**
* \defgroup spi_channels adc/dac spi channels * \defgroup spi_channels adc/dac spi channels
...@@ -54,6 +55,7 @@ ...@@ -54,6 +55,7 @@
#define NO_CHANNEL 2 #define NO_CHANNEL 2
/** @} */ /** @} */
/** /**
* \defgroup timer_config configuration for adc/dac and uart timer * \defgroup timer_config configuration for adc/dac and uart timer
* @{ * @{
...@@ -88,37 +90,31 @@ ...@@ -88,37 +90,31 @@
* @{ * @{
*/ */
#ifdef PIN_DEBUG
//#define DEBUG_GPIO_PORT GPIOC //#define DEBUG_GPIO_PORT GPIOC
#define DEBUG_PIN_0 MODEM_GPIO_10 # define DEBUG_PIN_0 MODEM_GPIO_10
#define DEBUG_PIN_1 MODEM_GPIO_1 # define DEBUG_PIN_1 MODEM_GPIO_1
#define DEBUG_PIN_2 MODEM_GPIO_2 # define DEBUG_PIN_2 MODEM_GPIO_2
#define DEBUG_PIN_3 MODEM_GPIO_3 # define DEBUG_PIN_3 MODEM_GPIO_3
#define DEBUG_PIN_4 MODEM_GPIO_4 # define DEBUG_PIN_4 MODEM_GPIO_4
#define DEBUG_PIN_5 MODEM_GPIO_5 # define DEBUG_PIN_5 MODEM_GPIO_5
#define DEBUG_PIN_6 MODEM_GPIO_6 # define DEBUG_PIN_6 MODEM_GPIO_6
#define DEBUG_PIN_7 MODEM_GPIO_7 # define DEBUG_PIN_7 MODEM_GPIO_7
#define DEBUG_PIN_8 MODEM_GPIO_8 # define DEBUG_PIN_8 MODEM_GPIO_8
#define DEBUG_PIN_9 MODEM_GPIO_9 # define DEBUG_PIN_9 MODEM_GPIO_9
#endif
/** @} */ /** @} */
/** /**
* \defgroup gpio_pins STM32F4 GPIO Pins * \defgroup gpio_pins STM32F4 GPIO Pins
* @{ * @{
*/ */
// #define ... (gpio_t){GPIOC, GPIO_PIN_11} // currently unused
#define TXEN_PIN (gpio_t){GPIOA, GPIO_PIN_1}
#define RXEN_PIN (gpio_t){GPIOA, GPIO_PIN_0} #define RXEN_PIN (gpio_t){GPIOA, GPIO_PIN_0}
#define TXEN_PIN (gpio_t){GPIOA, GPIO_PIN_1}
#define TXRX_SW_PIN (gpio_t){GPIOA, GPIO_PIN_2} #define TXRX_SW_PIN (gpio_t){GPIOA, GPIO_PIN_2}
/** @} */ /** @} */
/**
* \defgroup modem_sleep_pin STM32F4 Sleep
* @{
*/
// #define SLEEP_PIN (gpio_t){GPIOA, GPIO_PIN_8}
// #define SLEEP_EXTI_IRQn EXTI9_5_IRQn
// #define SLEEP_EXTI_IRQHandler EXTI9_5_IRQHandler
/** /**
* \defgroup leds STM32F4 Led to GPIO mapping * \defgroup leds STM32F4 Led to GPIO mapping
......
/** /**
* Copyright 2016-2019 * Copyright 2016-2021
* *
* Timo Kortbrae, * Timo Kortbrae,
* Jan Heitmann, * Jan Heitmann,
...@@ -43,8 +43,9 @@ ...@@ -43,8 +43,9 @@
#include <stdbool.h> #include <stdbool.h>
// TODO define "NONE" (rather than using magic 0xFF everywhere)
// TODO use pointers (call by reference rather than call by value)
#define GPIO_NA ((gpio_t){0}) /* (pin0 = 1, pin1 = 2, ..., @see stm32f4xx_hal_gpio.h) */
typedef struct { typedef struct {
GPIO_TypeDef * port; GPIO_TypeDef * port;
uint16_t pin; uint16_t pin;
...@@ -69,9 +70,6 @@ void gpio_init(void); ...@@ -69,9 +70,6 @@ void gpio_init(void);
static inline bool static inline bool
__attribute__((__always_inline__)) __attribute__((__always_inline__))
gpio_read(gpio_t gpio) { gpio_read(gpio_t gpio) {
if (gpio.pin == 0xFF) {
return false;
}
return (gpio.port->IDR & gpio.pin) != 0; return (gpio.port->IDR & gpio.pin) != 0;
} }
...@@ -85,9 +83,6 @@ gpio_read(gpio_t gpio) { ...@@ -85,9 +83,6 @@ gpio_read(gpio_t gpio) {
static inline void static inline void
__attribute__((__always_inline__)) __attribute__((__always_inline__))
gpio_set(gpio_t gpio) { gpio_set(gpio_t gpio) {
if (gpio.pin == 0xFF) {
return;
}
gpio.port->BSRR = gpio.pin; gpio.port->BSRR = gpio.pin;
} }
...@@ -101,25 +96,20 @@ gpio_set(gpio_t gpio) { ...@@ -101,25 +96,20 @@ gpio_set(gpio_t gpio) {
static inline void static inline void
__attribute__((__always_inline__)) __attribute__((__always_inline__))
gpio_clear(gpio_t gpio) { gpio_clear(gpio_t gpio) {
if (gpio.pin == 0xFF) {
return;
}
gpio.port->BSRR = gpio.pin << 16; gpio.port->BSRR = gpio.pin << 16;
//gpio.port->BRR = gpio.pin;
} }
/** /**
* @brief Toggles the gpio output * @brief Toggles the gpio output
* *
* @param pin: specifies the pin that is reset. * @param pin: specifies the pin that is toggled.
* This parameter has to be one of the @link gpio_pins gpio pins listed here@endlink * This parameter has to be one of the @link gpio_pins gpio pins listed here@endlink
* @retval None * @retval None
*/ */
static inline void static inline void
__attribute__((__always_inline__)) __attribute__((__always_inline__))
gpio_toggle(gpio_t gpio) { gpio_toggle(gpio_t gpio) {
if (gpio.pin == 0xFF) {
return;
}
gpio.port->BSRR = (gpio.port->ODR ^ gpio.pin) | (gpio.pin << 16); gpio.port->BSRR = (gpio.port->ODR ^ gpio.pin) | (gpio.pin << 16);
} }
...@@ -133,8 +123,6 @@ gpio_toggle(gpio_t gpio) { ...@@ -133,8 +123,6 @@ gpio_toggle(gpio_t gpio) {
static inline void static inline void
__attribute__((__always_inline__)) __attribute__((__always_inline__))
led_on(gpio_t gpio) { led_on(gpio_t gpio) {
if (gpio.pin == 0xFF)
return;
gpio.port->BSRR = gpio.pin; gpio.port->BSRR = gpio.pin;
} }
...@@ -148,23 +136,20 @@ led_on(gpio_t gpio) { ...@@ -148,23 +136,20 @@ led_on(gpio_t gpio) {
static inline void static inline void
__attribute__((__always_inline__)) __attribute__((__always_inline__))
led_off(gpio_t gpio) { led_off(gpio_t gpio) {
if (gpio.pin == 0xFF)
return;
gpio.port->BSRR = gpio.pin << 16; gpio.port->BSRR = gpio.pin << 16;
//gpio.port->BRR = gpio.pin;
} }
/** /**
* @brief Toggles the gpio output * @brief Toggles the gpio output
* *
* @param pin: specifies the pin that is reset. * @param pin: specifies the pin that is toggled.
* This parameter has to be one of the @link gpio_pins gpio pins listed here@endlink * This parameter has to be one of the @link gpio_pins gpio pins listed here@endlink
* @retval None * @retval None
*/ */
static inline void static inline void
__attribute__((__always_inline__)) __attribute__((__always_inline__))
led_toggle(gpio_t gpio) { led_toggle(gpio_t gpio) {
if (gpio.pin == 0xFF)
return;
gpio.port->BSRR = (gpio.port->ODR ^ gpio.pin) | (gpio.pin << 16); gpio.port->BSRR = (gpio.port->ODR ^ gpio.pin) | (gpio.pin << 16);
} }
......
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
#define BOARD_IRQ_H_ #define BOARD_IRQ_H_
#include <stm32f4xx_hal.h> #include <stm32f4xx_hal.h>
#include <stdbool.h>
/** /**
* @brief enable all interrupts * @brief enable all interrupts
...@@ -49,8 +50,9 @@ ...@@ -49,8 +50,9 @@
*/ */
static inline void static inline void
__attribute__((__always_inline__)) __attribute__((__always_inline__))
irq_enable_global(void) { irq_enable_global(void)
__enable_irq(); {
__enable_irq();
} }
/** /**
...@@ -64,4 +66,13 @@ irq_disable_global(void) { ...@@ -64,4 +66,13 @@ irq_disable_global(void) {
__disable_irq(); __disable_irq();
} }
static inline bool
__attribute__((__always_inline__))
irq_getState(void)
{
/* Returns 0 if they are enabled, or non-zero if disabled */
return 0 == __get_PRIMASK();
}
#endif #endif
...@@ -653,9 +653,9 @@ __attribute__((section(".after_vectors"),weak)) ...@@ -653,9 +653,9 @@ __attribute__((section(".after_vectors"),weak))
void void
SysTick_Handler(void) SysTick_Handler(void)
{ {
// default implementation in case this gets activated somewhere // default implementation in case this gets activated somewhere
// deep in STM's HAL and stalls the program as a consequence, // deep in STM's HAL and stalls the program as a consequence,
// (@see Default_Handler above) // (@see Default_Handler above)
} }
......
/** /**
* Copyright 2016-2019 * Copyright 2016-2021
* *
* Timo Kortbrae, * Timo Kortbrae,
* Jan Heitmann, * Jan Heitmann,
......
...@@ -59,61 +59,62 @@ ...@@ -59,61 +59,62 @@
* *
* @retval None * @retval None
*/ */
void gpio_init(void) { void
gpio_init(void)
{
__HAL_RCC_GPIOA_CLK_ENABLE(); __HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE(); __HAL_RCC_GPIOB_CLK_ENABLE();
__HAL_RCC_GPIOC_CLK_ENABLE(); __HAL_RCC_GPIOC_CLK_ENABLE();
GPIO_InitTypeDef GPIO_InitStruct; GPIO_InitTypeDef GPIO_InitStruct;
//>>>>>>> FIXME move partly (?) to txamp implementation //
GPIO_InitStruct.Pin = RXEN_PIN.pin; // internal switching, all same setup
//
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM;//<- medium should be fast enough GPIO_SPEED_FAST; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;