From d91ec8d7860f09fb486b0ffc09b67bbd19066a45 Mon Sep 17 00:00:00 2001 From: Stuart Longland Date: Sun, 4 Sep 2016 06:57:36 +1000 Subject: [PATCH] Move setpoint definitions to separate header. This will get copied over to setpoints.h, where the developer can customise them. If they do so, and I have to change things, the Makefile will warn them of this. --- .gitignore | 1 + Makefile | 10 ++++++- powerctl.c | 32 +++------------------ setpoints.h.dist | 72 ++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 86 insertions(+), 29 deletions(-) create mode 100644 setpoints.h.dist diff --git a/.gitignore b/.gitignore index 2641cde..adc4415 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ *.o *.elf *.hex +setpoints.h diff --git a/Makefile b/Makefile index 9afaffa..17d5668 100644 --- a/Makefile +++ b/Makefile @@ -43,8 +43,16 @@ clean: $(SIZE) -d $@ powerctl.elf: powerctl.o uart.o -powerctl.o: board.h +powerctl.o: board.h setpoints.h uart.o: uartcfg.h uart.h +setpoints.h: setpoints.h.dist + @if [ -f $@ ]; then \ + echo "Existing $@ found. Please compare this file with"; \ + echo "$^ to check for any new definitions and merge as"; \ + echo "required."; \ + exit 1; \ + fi + cp $^ $@ %.pgm: %.ihex avrdude $(PROG_ARGS) -p $(PROG_DEV) -U flash:w:$^:i diff --git a/powerctl.c b/powerctl.c index 9165a17..7ce9f24 100644 --- a/powerctl.c +++ b/powerctl.c @@ -9,6 +9,7 @@ #endif #include "board.h" +#include "setpoints.h" /*! ADMUX setting for selecting 1.1V reference */ #define ADC_REF_1V1 (2 << REFS0) @@ -58,10 +59,6 @@ static volatile uint16_t adc_temp = 0; * How long before we next take a reading? */ static volatile uint16_t adc_timeout = 0; -/*! - * How many Timer1 ticks between ADC readings? - */ -#define ADC_TIMEOUT (1200) /*! * State of the battery. @@ -82,35 +79,14 @@ static volatile uint8_t batt_state_counter = 0; * How long before we can consider switching sources. */ static volatile uint8_t src_timeout = 0; -#define SRC_TIMEOUT (15) /*!< How long to wait before switching */ /*! * How long before we change LED states? */ static volatile uint8_t led_timeout = 0; -#define LED_TIMEOUT (150) -/* - * Temperature ranges and fan PWM settings - */ -#define TEMP_MIN (270 << 6) /*!< ~20°C, approx ADC reading */ -#define TEMP_MAX (300 << 6) /*!< ~30°C, approx ADC reading */ -#define FAN_PWM_MIN (88) /*!< Minimum PWM value */ -#define FAN_PWM_MAX (255) /*!< Maximum PWM value */ /*! Fan kick-start timeout */ static volatile uint8_t fan_timeout = 0; -#define FAN_TIMEOUT (5) - -/* - * ADC Voltage divider settings - */ -#define VDIV_R1 (1500ULL) /*!< R1 = 1.5kOhm */ -#define VDIV_R2 (100ULL) /*!< R2 = 100 Ohm */ -/* - * ADC settings - */ -#define ADC_REF (1100ULL) /*!< AREF = 1.1mV */ -#define ADC_MAX (65535ULL) /*!< ADLAR = 1 */ /*! * Macro for computing ADC measurements. This assumes the input to the @@ -130,15 +106,15 @@ static volatile uint8_t fan_timeout = 0; /*! * "Critical" battery voltage. This is considered a serious condition. */ -#define VBATT_CRIT ADC_READ(11800) +#define VBATT_CRIT ADC_READ(VBATT_CRIT_MV) /*! * "Low" battery voltage. Indication that we should turn a charger on. */ -#define VBATT_LOW ADC_READ(12000) +#define VBATT_LOW ADC_READ(VBATT_LOW_MV) /*! * "High" battery voltage. Indication we should turn the charger off. */ -#define VBATT_HIGH ADC_READ(13500) +#define VBATT_HIGH ADC_READ(VBATT_HIGH_MV) /* Debug messages */ #ifdef DEBUG diff --git a/setpoints.h.dist b/setpoints.h.dist new file mode 100644 index 0000000..944bef9 --- /dev/null +++ b/setpoints.h.dist @@ -0,0 +1,72 @@ +#ifndef _SETPOINTS_H +#define _SETPOINTS_H +/*! + * Personal Cloud power controller firmware + * (C) 2016 Stuart Longland + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +/*! + * How many Timer1 ticks between ADC readings? + */ +#define ADC_TIMEOUT (1200) + +/*! + * How long to wait before switching charging sources? + */ +#define SRC_TIMEOUT (15) + +/*! + * How long before we change LED states? + */ +#define LED_TIMEOUT (150) + +/* + * Temperature ranges and fan PWM settings + */ +#define TEMP_MIN (270 << 6) /*!< ~20°C, approx ADC reading */ +#define TEMP_MAX (300 << 6) /*!< ~30°C, approx ADC reading */ +#define FAN_PWM_MIN (88) /*!< Minimum PWM value */ +#define FAN_PWM_MAX (255) /*!< Maximum PWM value */ + +/*! Fan kick-start timeout */ +#define FAN_TIMEOUT (5) + +/* + * ADC Voltage divider settings + */ +#define VDIV_R1 (1500ULL) /*!< R1 = 1.5kOhm */ +#define VDIV_R2 (100ULL) /*!< R2 = 100 Ohm */ +/* + * ADC settings + */ +#define ADC_REF (1100ULL) /*!< AREF = 1.1mV */ +#define ADC_MAX (65535ULL) /*!< ADLAR = 1 */ + +/*! + * "Critical" battery voltage. This is considered a serious condition. + */ +#define VBATT_CRIT_MV (11800) +/*! + * "Low" battery voltage. Indication that we should turn a charger on. + */ +#define VBATT_LOW_MV (12000) +/*! + * "High" battery voltage. Indication we should turn the charger off. + */ +#define VBATT_HIGH_MV (13500) + +#endif