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)
void
agc_init(bool en)
{
// enable ?
// store enable state
enabled = en;
if (enabled) {
led_on(LED_AGC);
......@@ -216,8 +216,8 @@ agc_enable(void)
void
agc_disable(void)
{
led_off(LED_AGC);
enabled = false;
led_off(LED_AGC);
}
......@@ -228,12 +228,12 @@ agc_restore(void)
// make sure that previously set gain is set correctly
// 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
// three levels
// three levels)
if (enabled) {
if (gainLvl == 0) {
gainLvl++;
gainLvl = 1;
} else if (gainLvl >= NUM_GAIN_LEVELS - 1) {
gainLvl--;
gainLvl = NUM_GAIN_LEVELS - 2;
}
agc_setGain();
}
......@@ -316,6 +316,7 @@ agc_checkAction(sample_time_t ticks)
}
void
agc_processSample(fp16_t sample, sample_time_t ticks)
{
......
......@@ -133,8 +133,8 @@ enum {
#define FREQ_IDX(n) (n)
#define FREQ_LIST_NUM 49
#define SAMPLES_PER_SYMBOL_MASK (SAMPLES_PER_SYMBOL-1)
const fp16_t * const FREQ_LIST[FREQ_LIST_NUM];
const fp16_t * const FREQ_TXLIST[FREQ_LIST_NUM];
extern const fp16_t * const FREQ_LIST[FREQ_LIST_NUM];
extern const fp16_t * const FREQ_TXLIST[FREQ_LIST_NUM];
// sync/preamble length setup
......
......@@ -38,19 +38,6 @@
#ifndef 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"
#endif
......@@ -425,7 +425,6 @@ ISR_ADC(void)
// read from ADC
// note that this starts the conversion and sample will be available next time
spi_receive((void *)&SPI_RX_Buf);
}
......
/**
* Copyright 2016-2019
* Copyright 2016-2021
*
* Timo Kortbrae,
* Jan Heitmann,
......@@ -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_
#define BOARD_CONFIG_H_
......@@ -51,6 +44,7 @@
#define INTERRUPT //!< The INTERRUPT define is not needed for the stm32f4 project
#define CONST
// adc/dac spi channels
/**
* \defgroup spi_channels adc/dac spi channels
......@@ -61,6 +55,7 @@
#define NO_CHANNEL 2
/** @} */
/**
* \defgroup timer_config configuration for adc/dac and uart timer
* @{
......@@ -95,38 +90,31 @@
* @{
*/
#ifdef PIN_DEBUG
//#define DEBUG_GPIO_PORT GPIOC
#define DEBUG_PIN_0 MODEM_GPIO_10
#define DEBUG_PIN_1 MODEM_GPIO_1
#define DEBUG_PIN_2 MODEM_GPIO_2
#define DEBUG_PIN_3 MODEM_GPIO_3
#define DEBUG_PIN_4 MODEM_GPIO_4
#define DEBUG_PIN_5 MODEM_GPIO_5
#define DEBUG_PIN_6 MODEM_GPIO_6
#define DEBUG_PIN_7 MODEM_GPIO_7
#define DEBUG_PIN_8 MODEM_GPIO_8
#define DEBUG_PIN_9 MODEM_GPIO_9
# define DEBUG_PIN_0 MODEM_GPIO_10
# define DEBUG_PIN_1 MODEM_GPIO_1
# define DEBUG_PIN_2 MODEM_GPIO_2
# define DEBUG_PIN_3 MODEM_GPIO_3
# define DEBUG_PIN_4 MODEM_GPIO_4
# define DEBUG_PIN_5 MODEM_GPIO_5
# define DEBUG_PIN_6 MODEM_GPIO_6
# define DEBUG_PIN_7 MODEM_GPIO_7
# define DEBUG_PIN_8 MODEM_GPIO_8
# define DEBUG_PIN_9 MODEM_GPIO_9
#endif
/** @} */
/**
* \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 TXEN_PIN (gpio_t){GPIOA, GPIO_PIN_1}
#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
......@@ -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_ADDR_START 0x08060000 /* 128kb sector :-( */
#define MODEM_CONFIG_ADDR_END 0x0807FFFF
......
/**
* Copyright 2016-2018
* Copyright 2016-2020
*
* Timo Kortbrae,
* Jan Heitmann,
......@@ -50,9 +50,15 @@
static inline void
__attribute__((__always_inline__))
board_enterPowerSaveMode(void) {
// sleep mode (not deep sleep aka stop)
CLEAR_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk));
__WFI(); // Sleep and wait for next interrupt
//HAL_PWR_EnterSTANDBYMode();
}
/**
* @brief Resets the MCU
*
......
/**
* Copyright 2016-2019
* Copyright 2016-2021
*
* Timo Kortbrae,
* Jan Heitmann,
......@@ -44,6 +44,7 @@
#define INTERRUPT //!< The INTERRUPT define is not needed for the stm32f4 project
#define CONST
// adc/dac spi channels
/**
* \defgroup spi_channels adc/dac spi channels
......@@ -54,6 +55,7 @@
#define NO_CHANNEL 2
/** @} */
/**
* \defgroup timer_config configuration for adc/dac and uart timer
* @{
......@@ -88,37 +90,31 @@
* @{
*/
#ifdef PIN_DEBUG
//#define DEBUG_GPIO_PORT GPIOC
#define DEBUG_PIN_0 MODEM_GPIO_10
#define DEBUG_PIN_1 MODEM_GPIO_1
#define DEBUG_PIN_2 MODEM_GPIO_2
#define DEBUG_PIN_3 MODEM_GPIO_3
#define DEBUG_PIN_4 MODEM_GPIO_4
#define DEBUG_PIN_5 MODEM_GPIO_5
#define DEBUG_PIN_6 MODEM_GPIO_6
#define DEBUG_PIN_7 MODEM_GPIO_7
#define DEBUG_PIN_8 MODEM_GPIO_8
#define DEBUG_PIN_9 MODEM_GPIO_9
# define DEBUG_PIN_0 MODEM_GPIO_10
# define DEBUG_PIN_1 MODEM_GPIO_1
# define DEBUG_PIN_2 MODEM_GPIO_2
# define DEBUG_PIN_3 MODEM_GPIO_3
# define DEBUG_PIN_4 MODEM_GPIO_4
# define DEBUG_PIN_5 MODEM_GPIO_5
# define DEBUG_PIN_6 MODEM_GPIO_6
# define DEBUG_PIN_7 MODEM_GPIO_7
# define DEBUG_PIN_8 MODEM_GPIO_8
# define DEBUG_PIN_9 MODEM_GPIO_9
#endif
/** @} */
/**
* \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 TXEN_PIN (gpio_t){GPIOA, GPIO_PIN_1}
#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
......
/**
* Copyright 2016-2019
* Copyright 2016-2021
*
* Timo Kortbrae,
* Jan Heitmann,
......@@ -43,8 +43,9 @@
#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 {
GPIO_TypeDef * port;
uint16_t pin;
......@@ -69,9 +70,6 @@ void gpio_init(void);
static inline bool
__attribute__((__always_inline__))
gpio_read(gpio_t gpio) {
if (gpio.pin == 0xFF) {
return false;
}
return (gpio.port->IDR & gpio.pin) != 0;
}
......@@ -85,9 +83,6 @@ gpio_read(gpio_t gpio) {
static inline void
__attribute__((__always_inline__))
gpio_set(gpio_t gpio) {
if (gpio.pin == 0xFF) {
return;
}
gpio.port->BSRR = gpio.pin;
}
......@@ -101,25 +96,20 @@ gpio_set(gpio_t gpio) {
static inline void
__attribute__((__always_inline__))
gpio_clear(gpio_t gpio) {
if (gpio.pin == 0xFF) {
return;
}
gpio.port->BSRR = gpio.pin << 16;
//gpio.port->BRR = gpio.pin;
}
/**
* @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
* @retval None
*/
static inline void
__attribute__((__always_inline__))
gpio_toggle(gpio_t gpio) {
if (gpio.pin == 0xFF) {
return;
}
gpio.port->BSRR = (gpio.port->ODR ^ gpio.pin) | (gpio.pin << 16);
}
......@@ -133,8 +123,6 @@ gpio_toggle(gpio_t gpio) {
static inline void
__attribute__((__always_inline__))
led_on(gpio_t gpio) {
if (gpio.pin == 0xFF)
return;
gpio.port->BSRR = gpio.pin;
}
......@@ -148,23 +136,20 @@ led_on(gpio_t gpio) {
static inline void
__attribute__((__always_inline__))
led_off(gpio_t gpio) {
if (gpio.pin == 0xFF)
return;
gpio.port->BSRR = gpio.pin << 16;
//gpio.port->BRR = gpio.pin;
}
/**
* @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
* @retval None
*/
static inline void
__attribute__((__always_inline__))
led_toggle(gpio_t gpio) {
if (gpio.pin == 0xFF)
return;
gpio.port->BSRR = (gpio.port->ODR ^ gpio.pin) | (gpio.pin << 16);
}
......
......@@ -41,6 +41,7 @@
#define BOARD_IRQ_H_
#include <stm32f4xx_hal.h>
#include <stdbool.h>
/**
* @brief enable all interrupts
......@@ -49,7 +50,8 @@
*/
static inline void
__attribute__((__always_inline__))
irq_enable_global(void) {
irq_enable_global(void)
{
__enable_irq();
}
......@@ -64,4 +66,13 @@ irq_disable_global(void) {
__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
/**
* Copyright 2016-2019
* Copyright 2016-2021
*
* Timo Kortbrae,
* Jan Heitmann,
......
......@@ -59,42 +59,43 @@
*
* @retval None
*/
void gpio_init(void) {
void
gpio_init(void)
{
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
__HAL_RCC_GPIOC_CLK_ENABLE();
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.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;
//GPIO_InitStruct.Alternate = 0;
// RXEN
GPIO_InitStruct.Pin = RXEN_PIN.pin;
HAL_GPIO_Init(RXEN_PIN.port, &GPIO_InitStruct);
gpio_clear(RXEN_PIN);
// TXEN
GPIO_InitStruct.Pin = TXEN_PIN.pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM;//<- medium should be fast enough GPIO_SPEED_FAST;
//GPIO_InitStruct.Alternate = 0;
HAL_GPIO_Init(TXEN_PIN.port, &GPIO_InitStruct);
gpio_set(TXEN_PIN);
gpio_clear(TXEN_PIN);
// TXRX_SW
GPIO_InitStruct.Pin = TXRX_SW_PIN.pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM;//<- medium should be fast enough GPIO_SPEED_FAST;
//GPIO_InitStruct.Alternate = 0;
HAL_GPIO_Init(TXRX_SW_PIN.port, &GPIO_InitStruct);
gpio_clear(TXRX_SW_PIN);
//<<<<<<< FIXME move partly (?) to txamp implementation
//
// LEDs, all same setup
//
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
//GPIO_InitStruct.Alternate = 0;
GPIO_InitStruct.Pin = LED_1.pin;
......@@ -125,7 +126,8 @@ void gpio_init(void) {
*
* @retval None
*/
void pin_debug_init(void) {
void pin_debug_init(void)
{
__HAL_RCC_GPIOC_CLK_ENABLE();
GPIO_InitTypeDef GPIO_InitStruct;
......@@ -165,6 +167,6 @@ void pin_debug_init(void) {
pin_debug_clear(DEBUG_PIN_7);
pin_debug_clear(DEBUG_PIN_8);
pin_debug_clear(DEBUG_PIN_9);
}
}
#endif
/**
* Copyright 2016-2019
* Copyright 2016-2021
*
* Timo Kortbrae,
* Jan Heitmann,
......
Subproject commit e1dad976ae340ef9ce08cee5ae8c757b2d0c4d7a
Subproject commit 3046c75c4218af6ffca8ab186b42021c9cb5dc96
......@@ -116,6 +116,7 @@
#include "aci_sniffmode.h"
/******************************************************************************
* Defines *
******************************************************************************/
......@@ -261,28 +262,13 @@ int main(void)
irq_enable_global();
// START DEBUGGING snippet to generate data
// const char * teststring = "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef";
// mm_packet_t * pkt = packetpool_get();
//
// packet_clear(pkt);
// pkt->header.type = 0x00;
// pkt->header.len = strlen(teststring);
// MM_STATUS_WRITE(*pkt, MM_FEC_OFFSET, MM_FEC_MASK, 1);
// memcpy(pkt->payload, (uint8_t *)teststring, pkt->header.len);
//
// dbg("%s (%u)\n", pkt->payload, pkt->header.len);
//
// packetqueue_insert(&TXQ, pkt);
// END DEBUGGING snippet to generate data
freq_init();
agc_init(true);
adda_activateSampling();
batvoltage_init();
while (true) {
if ( sync_checkSync() ) {
if (sync_checkSync()) {
bool ret = false;
// ranging
......@@ -366,6 +352,7 @@ cbModemReceive(mm_packet_t * pkt)
ranging_processPong(pkt);
}
// insert new rx packet in queue and signal (GPIO)
packetqueue_insert(&RXQ, pkt);
return packetpool_get();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment