Restructure include hierarchy

This commit is contained in:
2020-02-12 21:00:35 +01:00
parent d80ce20675
commit f04a5c7930
26 changed files with 49 additions and 46 deletions

View File

@@ -0,0 +1,129 @@
#ifndef __ADCMEAS_H__
#define __ADCMEAS_H__
#include <stdbool.h>
#include <stdint.h>
#include <stm32/stm32f4xx.h>
/**
* @brief Moving average filter coefficient for PT1000 measurement
*/
#define ADC_PT1000_FILTER_WEIGHT 0.005f
/**
* @brief ADC channel number of PT1000 sensor input
*/
#define ADC_PT1000_CHANNEL 2U
#define ADC_PT1000_PORT GPIOA
#define ADC_PT1000_PORT_RCC_MASK RCC_AHB1ENR_GPIOAEN
#define ADC_PT1000_PIN 2U
#define ADC_FILTER_STARTUP_CYCLES 800U
#define ADC_PT1000_SAMPLE_CNT_DELAY 1000U
#define ADC_PT1000_DMA_AVG_SAMPLES 6U
/**
* @brief Lower value for valid input range for PT1000 measurement
*
* If the input of the PT1000 sensor is below this value, an error is thrown. This is used to disable the temperature control loop
*/
#define ADC_PT1000_LOWER_WATCHDOG 200U
/**
* @brief Upper value for valid input range for PT1000 measurement
*
* If the input of the PT1000 sensor is above this value, an error is thrown. This is used to disable the temperature control loop
*/
#define ADC_PT1000_UPPER_WATCHDOG 4000U
enum adc_pt1000_error {ADC_PT1000_NO_ERR= 0, ADC_PT1000_WATCHDOG_ERROR=(1UL<<0), ADC_PT1000_OVERFLOW=(1UL<<1)};
/**
* @brief This function sets up the ADC measurement fo the external PT1000 temperature sensor
*
* Used peripherals:
* - Timer 2 for sampling control
* - ADC1
*
* The filter weight \f$\alpha\f$ is configured for @ref ADC_PT1000_FILTER_WEIGHT
*
*/
void adc_pt1000_setup_meas();
/**
* @brief Set moving average filter parameters
*
* The sampled resistance value is filtered with an exponential average filter
* specified by following difference equation:
*
* \f$ y[n] = (1-\alpha)y[n-1] + \alpha x[n] \f$
*
* @param alpha
*/
void adc_pt1000_set_moving_average_filter_param(float alpha);
/**
* @brief Set the calibration data for the PT1000 measurement
*
* The resulting resistance reading is
* \f$R_{corrected} = (1 + \sigma) R_{raw} + O\f$
*
* @param offset Offset \f$O\f$
* @param sensitivity_deviation Sensitivity Deviation \f$\sigma\f$ after offset correction
*/
void adc_pt1000_set_resistance_calibration(float offset, float sensitivity_deviation, bool active);
/**
* @brief Get the state and values of the resistance calibration
* @param offset Offset
* @param sensitivity_deviation Sensitivity deviation
* @param active Active state of the correction
*/
void adc_pt1000_get_resistance_calibration(float *offset, float *sensitivity_deviation, bool *active);
/**
* @brief Get the current reistance value
*
* If the reistance calibration is enabled, this function applies the calculations of the raw reistance reading and
* returns the corrected value.
*
* If an ADC error is set, the status is negative. The status is 2 during the first measurements with a given filter setting. Technically, the resistance value is
* correct but the filter is not stable yet.
* Use adc_pt1000_check_error to check the error and reinitialize the ADC.
*
*
* @param[out] resistance Resistance output in Ohms
* @return Status
*/
int adc_pt1000_get_current_resistance(float *resistance);
/**
* @brief Stream the raw ADC data to an array in memory.
*
* Streaming is done using DMA2 Stream0.
* This function is used for gathering fullspeed sampling data for external interfaces or calibration
*
* @param adc_array Array to stream data to
* @param length Amount of data points to be measured
* @param flag_to_set This flag is set to 1 once the data has been measured and is transferred. A negative value indicates an error
* @return 0 if measurement could be started
*/
int adc_pt1000_stream_raw_value_to_memory(float *adc_array, uint32_t length, volatile uint8_t *flag_to_set);
void adc_pt1000_convert_raw_value_array_to_resistance(float *resistance_dest, float *raw_source, uint32_t count);
/**
* @brief Check if the ADC measurement experienced any kind of error (DMA, Analog Watchdog, etc...)
*
* In case of an error, it may be necessary to call adc_pt1000_setup_meas() again in order to recover from the error
*/
enum adc_pt1000_error adc_pt1000_check_error();
void adc_pt1000_clear_error();
void adc_pt1000_disable();
#endif // __ADCMEAS_H__

View File

@@ -0,0 +1,47 @@
#ifndef __DIGIO_H__
#define __DIGIO_H__
#include <stdbool.h>
#include <stdint.h>
#include <helper-macros/helper-macros.h>
#define DIGIO_PORT GPIOB
#define DIGIO_RCC_MASK RCC_AHB1ENR_GPIOBEN
#define DIGIO_PINS 4,5,6,7
#ifdef DEBUGBUILD
#define DIGIO_INOUT_DEFAULT 0,0,0,0
#define DIGIO_ALTFUNC_DEFAULT 0,0,0,0
#else
#define DIGIO_INOUT_DEFAULT 0,0,2,2
#define DIGIO_ALTFUNC_DEFAULT 0,0,7,7
#endif
#define BEEPER_PORT GPIOB
#define BEEPER_RCC_MASK RCC_AHB1ENR_GPIOBEN
void digio_setup_default_all();
void digio_setup_pin(uint8_t num, uint8_t in_out, uint8_t alt_func);
void digio_set(uint8_t num, int val);
int digio_get(uint8_t num);
#define LED_PORT GPIOB
#define LED_RCC_MASK RCC_AHB1ENR_GPIOBEN
#define LED_PINS 2,3
void led_setup();
void led_set(uint8_t num, int val);
int led_get(uint8_t num);
#define LOUDSPEAKER_PORT GPIOB
#define LOUDSPEAKER_RCC_MASK RCC_AHB1ENR_GPIOBEN
#define LOUDSPEAKER_PIN 1
void loudspeaker_setup();
void loudspeaker_set(int val);
int loudspeaker_get();
#endif /* __DIGIO_H__ */

View File

@@ -0,0 +1,13 @@
#ifndef __SHELL_H__
#define __SHELL_H__
#include <stddef.h>
#include <shellmatta.h>
shellmatta_handle_t shell_init(void);
void shell_handle_input(shellmatta_handle_t shell, const char *data, size_t len);
void shell_print_string(shellmatta_handle_t shell, const char *string);
#endif /* __SHELL_H__ */

View File

@@ -0,0 +1,43 @@
#ifndef __SYSTICK_H__
#define __SYSTICK_H__
#include <stdint.h>
/**
* @brief Reload value for the systick timer.
*
* This value has to be configured to set the systick to a one milliscond tick interval
* The default value is 168000, which results in a 1ms tick for 168 MHz CPU speed
*/
#define SYSTICK_RELOAD (168000UL)
/**
* @brief Variable used by the systick_wait_ms function
*/
extern volatile uint32_t wait_tick_ms;
/**
* @brief Systemclock in milliseconds.
*
* This value must not be reset during the whole runtime.
*
*/
extern volatile uint64_t global_tick_ms;
/**
* @brief Setup the Systick timer to generate a 1 ms tick
*/
void systick_setup(void);
/**
* @brief Wait for x milliseconds
*
* This function is not reentrant and must not be called from an interrupt
*
* @warning Do not use in interrupt context
* @param ms wait time in ms
*/
void systick_wait_ms(uint32_t ms);
#endif /* __SYSTICK_H__ */