1
0
mirror of https://github.com/sjlongland/cluster-powerctl.git synced 2025-09-13 12:03:14 +10:00

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.
This commit is contained in:
Stuart Longland 2016-09-04 06:57:36 +10:00
parent 772d5b9d30
commit d91ec8d786
Signed by: stuartl
GPG Key ID: 4DFA191410BDE3B7
4 changed files with 86 additions and 29 deletions

1
.gitignore vendored
View File

@ -3,3 +3,4 @@
*.o
*.elf
*.hex
setpoints.h

View File

@ -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

View File

@ -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

72
setpoints.h.dist Normal file
View File

@ -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