The Big Refactoring of 2019: folder structure #723
This commit is contained in:
parent
ebe58122c6
commit
372eb51f37
|
@ -58,6 +58,7 @@
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
#include "aux_pid.h"
|
#include "aux_pid.h"
|
||||||
#include "accelerometer.h"
|
#include "accelerometer.h"
|
||||||
|
#include "counter64.h"
|
||||||
|
|
||||||
#if HAL_USE_ADC || defined(__DOXYGEN__)
|
#if HAL_USE_ADC || defined(__DOXYGEN__)
|
||||||
#include "AdcConfiguration.h"
|
#include "AdcConfiguration.h"
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
/*
|
||||||
|
* counter64.cpp
|
||||||
|
*
|
||||||
|
* Created on: Mar 31, 2019
|
||||||
|
* @author Andrey Belomutskiy, (c) 2012-2019
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "counter64.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The main use-case of this class is to keep track of a 64-bit global number of CPU ticks from reset.
|
||||||
|
*
|
||||||
|
* stm32f4 hardware has a 32-bit Cycle Count Register (CYCCNT), which is incremented with every CPU cycle.
|
||||||
|
* With 32 bits and 168MHz speed this counter overflows every 4B/168M = 23 seconds. The job of this class is to
|
||||||
|
* keep track of the current CYCCNT value, detect these overflows, and provide a nice,
|
||||||
|
* clean 64 bit global cycle counter.
|
||||||
|
*
|
||||||
|
* In order for this to function, it's your responsibility to invoke offer() method at least once a second.
|
||||||
|
*/
|
||||||
|
Overflow64Counter::Overflow64Counter() {
|
||||||
|
state.highBits = 0;
|
||||||
|
state.lowBits = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* in order to have atomic writes this should be invoked within a critical section
|
||||||
|
*/
|
||||||
|
void updateAndSet(State64 *state, uint32_t value) {
|
||||||
|
if (value < state->lowBits) {
|
||||||
|
// new value less than previous value means there was an overflow in that 32 bit counter
|
||||||
|
state->highBits += 0x100000000LL;
|
||||||
|
}
|
||||||
|
state->lowBits = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if EFI_UNIT_TEST
|
||||||
|
efitime_t Overflow64Counter::update(uint32_t value) {
|
||||||
|
updateAndSet(&state, value);
|
||||||
|
return state.highBits + state.lowBits;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
/*
|
||||||
|
* counter64.h
|
||||||
|
*
|
||||||
|
* Created on: Mar 31, 2019
|
||||||
|
* @author Andrey Belomutskiy, (c) 2012-2019
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef UTIL_CONTAINERS_COUNTER64_H_
|
||||||
|
#define UTIL_CONTAINERS_COUNTER64_H_
|
||||||
|
|
||||||
|
#include "global.h"
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
// todo: would probably be better to keep the high bits as 32 bit field to be sure
|
||||||
|
volatile efitime_t highBits;
|
||||||
|
volatile uint32_t lowBits;
|
||||||
|
} State64;
|
||||||
|
|
||||||
|
void updateAndSet(State64 *state, uint32_t value);
|
||||||
|
|
||||||
|
class Overflow64Counter
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Overflow64Counter();
|
||||||
|
|
||||||
|
efitime_t get();
|
||||||
|
#if EFI_UNIT_TEST
|
||||||
|
efitime_t update(uint32_t value);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
State64 state;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* UTIL_CONTAINERS_COUNTER64_H_ */
|
|
@ -2,7 +2,7 @@
|
||||||
* data_buffer.h
|
* data_buffer.h
|
||||||
*
|
*
|
||||||
* @date Dec 8, 2012
|
* @date Dec 8, 2012
|
||||||
* @author Andrey Belomutskiy, (c) 2012-2017
|
* @author Andrey Belomutskiy, (c) 2012-2019
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef DATA_BUFFER_H_
|
#ifndef DATA_BUFFER_H_
|
||||||
|
|
|
@ -7,39 +7,6 @@
|
||||||
|
|
||||||
#include "efilib2.h"
|
#include "efilib2.h"
|
||||||
|
|
||||||
/**
|
|
||||||
* The main use-case of this class is to keep track of a 64-bit global number of CPU ticks from reset.
|
|
||||||
*
|
|
||||||
* stm32f4 hardware has a 32-bit Cycle Count Register (CYCCNT), which is incremented with every CPU cycle.
|
|
||||||
* With 32 bits and 168MHz speed this counter overflows every 4B/168M = 23 seconds. The job of this class is to
|
|
||||||
* keep track of the current CYCCNT value, detect these overflows, and provide a nice,
|
|
||||||
* clean 64 bit global cycle counter.
|
|
||||||
*
|
|
||||||
* In order for this to function, it's your responsibility to invoke offer() method at least once a second.
|
|
||||||
*/
|
|
||||||
Overflow64Counter::Overflow64Counter() {
|
|
||||||
state.highBits = 0;
|
|
||||||
state.lowBits = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* in order to have atomic writes this should be invoked within a critical section
|
|
||||||
*/
|
|
||||||
void updateAndSet(State64 *state, uint32_t value) {
|
|
||||||
if (value < state->lowBits) {
|
|
||||||
// new value less than previous value means there was an overflow in that 32 bit counter
|
|
||||||
state->highBits += 0x100000000LL;
|
|
||||||
}
|
|
||||||
state->lowBits = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if EFI_UNIT_TEST
|
|
||||||
efitime_t Overflow64Counter::update(uint32_t value) {
|
|
||||||
updateAndSet(&state, value);
|
|
||||||
return state.highBits + state.lowBits;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* See also getRemainingStack()
|
* See also getRemainingStack()
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -10,31 +10,11 @@
|
||||||
|
|
||||||
#include "global.h"
|
#include "global.h"
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
// todo: would probably be better to keep the high bits as 32 bit field to be sure
|
|
||||||
volatile efitime_t highBits;
|
|
||||||
volatile uint32_t lowBits;
|
|
||||||
} State64;
|
|
||||||
|
|
||||||
void updateAndSet(State64 *state, uint32_t value);
|
|
||||||
/**
|
/**
|
||||||
* @return for a given stack memory region returns how much stack was ever used
|
* @return for a given stack memory region returns how much stack was ever used
|
||||||
*/
|
*/
|
||||||
int getMaxUsedStack(uint8_t *ptr, int size);
|
int getMaxUsedStack(uint8_t *ptr, int size);
|
||||||
|
|
||||||
class Overflow64Counter
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Overflow64Counter();
|
|
||||||
|
|
||||||
efitime_t get();
|
|
||||||
#if EFI_UNIT_TEST
|
|
||||||
efitime_t update(uint32_t value);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
State64 state;
|
|
||||||
};
|
|
||||||
|
|
||||||
#if (EFI_PROD_CODE || EFI_SIMULATOR)
|
#if (EFI_PROD_CODE || EFI_SIMULATOR)
|
||||||
#define GET_TIMESTAMP() port_rt_get_counter_value()
|
#define GET_TIMESTAMP() port_rt_get_counter_value()
|
||||||
#else
|
#else
|
||||||
|
|
|
@ -9,6 +9,7 @@ UTILSRC_CPP = $(UTIL_DIR)/containers/cyclic_buffer.cpp \
|
||||||
$(PROJECT_DIR)/util/datalogging.cpp \
|
$(PROJECT_DIR)/util/datalogging.cpp \
|
||||||
$(PROJECT_DIR)/util/loggingcentral.cpp \
|
$(PROJECT_DIR)/util/loggingcentral.cpp \
|
||||||
$(UTIL_DIR)/containers/listener_array.cpp \
|
$(UTIL_DIR)/containers/listener_array.cpp \
|
||||||
|
$(UTIL_DIR)/containers/counter64.cpp \
|
||||||
$(PROJECT_DIR)/util/cli_registry.cpp \
|
$(PROJECT_DIR)/util/cli_registry.cpp \
|
||||||
$(PROJECT_DIR)/util/pid.cpp \
|
$(PROJECT_DIR)/util/pid.cpp \
|
||||||
$(PROJECT_DIR)/util/biquad.cpp \
|
$(PROJECT_DIR)/util/biquad.cpp \
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#include "crc.h"
|
#include "crc.h"
|
||||||
#include "fl_stack.h"
|
#include "fl_stack.h"
|
||||||
#include "io_pins.h"
|
#include "io_pins.h"
|
||||||
|
#include "counter64.h"
|
||||||
#include "efi_gpio.h"
|
#include "efi_gpio.h"
|
||||||
#include "efilib.h"
|
#include "efilib.h"
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue