3 Commits 3f56ba872d ... c146508c3a

Author SHA1 Message Date
  Michael Buesch c146508c3a Add support for compiling with a c++ compiler 5 years ago
  Michael Buesch 5108220bf1 Add hooks for building the project in a simulator environment 5 years ago
  Michael Buesch ca9e23209b tests: Add more stubs 5 years ago

+ 1 - 1
firmware/debug_uart.c

@@ -106,7 +106,7 @@ void debug_print_int32(const char __flash *prefix, int32_t value)
 {
 	char buf[10 + 1 + 1];
 
-#ifndef __CHECKER__
+#if !defined(__CHECKER__) && !defined(SIMULATOR)
 	build_assert(sizeof(long) == sizeof(value));
 #endif
 	ltoa(value, buf, 10);

+ 1 - 1
firmware/filter.c

@@ -33,7 +33,7 @@ uint16_t lp_filter_u16_run(struct lp_filter_u16 *lp, uint16_t in,
 	lp->filter_buf = buf;
 	out = buf >> filter_shift;
 
-	return (uint16_t)min(out, UINT16_MAX);
+	return (uint16_t)min(out, (uint16_t)UINT16_MAX);
 }
 
 fixpt_t lp_filter_fixpt_run(struct lp_filter_fixpt *lp, fixpt_t in,

+ 25 - 14
firmware/main.c

@@ -70,6 +70,27 @@ void early_init(void)
 	wdt_enable(WDTO_2S);
 }
 
+/* One iteration of the main loop. */
+static void main_loop_once(void)
+{
+	wdt_reset();
+
+	/* Handle measurement results (if any).
+	 * This will also run the controllers, if needed.
+	 */
+	measure_work();
+
+	/* Handle user interface events. */
+	menu_work();
+	display_work();
+	buttons_work();
+	settings_work();
+}
+
+#ifndef RUN_MAIN_LOOP
+# define RUN_MAIN_LOOP	1
+#endif
+
 /* Main entry point. */
 int main(void) _mainfunc;
 int main(void)
@@ -109,18 +130,8 @@ int main(void)
 
 	wdt_enable(WDTO_250MS);
 	irq_enable();
-	while (1) {
-		wdt_reset();
-
-		/* Handle measurement results (if any).
-		 * This will also run the controllers, if needed.
-		 */
-		measure_work();
-
-		/* Handle user interface events. */
-		menu_work();
-		display_work();
-		buttons_work();
-		settings_work();
-	}
+	while (RUN_MAIN_LOOP)
+		main_loop_once();
+
+	return 0;
 }

+ 26 - 8
firmware/measure.c

@@ -72,18 +72,36 @@ struct meas_context {
 };
 
 static struct meas_context meas = {
-	.channels[MEAS_CHAN_CURRENT] = {
-		.config		= &meascurr_config,
+	.channels = {
+		/* MEAS_CHAN_CURRENT */
+		{
+			.config				= &meascurr_config,
+			.old_report_value		= 0,
 #if CONF_ADJ
-		.adjustment	= FLOAT_TO_FIXPT(0),
+			.adjustment			= FLOAT_TO_FIXPT(0),
 #endif
-	},
-	.channels[MEAS_CHAN_TEMP] = {
-		.config		= &meastemp_config,
+			.plaus_timeout			= false,
+			.plaus_timeout_timer_running	= false,
+			.plaus_timeout_timer		= { },
+		},
+		/* MEAS_CHAN_TEMP */
+		{
+			.config				= &meastemp_config,
+			.old_report_value		= 0,
 #if CONF_ADJ
-		.adjustment	= FLOAT_TO_FIXPT(0),
+			.adjustment			= FLOAT_TO_FIXPT(0),
 #endif
+			.plaus_timeout			= false,
+			.plaus_timeout_timer_running	= false,
+			.plaus_timeout_timer		= { },
+
+		},
 	},
+	.active_chan		= 0,
+	.avg_count		= 0,
+	.avg_sum		= 0,
+	.avg_timer		= { },
+	.result_available	= false,
 };
 
 
@@ -192,7 +210,7 @@ static void measure_handle_result(void)
 	fixpt_t phys;
 	enum measure_plausibility plaus;
 
-	active_chan_id = meas.active_chan;
+	active_chan_id = (enum measure_chan)meas.active_chan;
 	active_chan = &meas.channels[active_chan_id];
 	config = active_chan->config;
 

+ 2 - 2
firmware/pwm_current.c

@@ -60,8 +60,8 @@ void pwmcurr_init(void)
 	DDRB |= (1 << DDB1);
 
 	/* Set frequency and initial duty cycle. */
-	ICR1 = PWMCURR_MAX_DUTY;
-	OCR1A = PWMCURR_MAX_DUTY;
+	ICR1 = (uint16_t)PWMCURR_MAX_DUTY;
+	OCR1A = (uint16_t)PWMCURR_MAX_DUTY;
 	/* Enable timer: Fast PWM (Mode 14), OC1A clr/set, PS 256 */
 	TCCR1A = (1 << COM1A1) | (0 << COM1A0) |
 		 (0 << COM1B1) | (0 << COM1B0) |

+ 40 - 25
firmware/settings.c

@@ -31,6 +31,12 @@
 #include <avr/eeprom.h>
 
 
+#ifndef ee_addr_t
+typedef uint16_t ee_addr_t;
+#define ee_addr_t ee_addr_t
+#endif
+
+
 struct settings_context {
 	struct timer store_timer;
 	bool store_request;
@@ -54,45 +60,54 @@ static struct settings_context settings;
 
 /* The permanent EEPROM storage. */
 static struct settings EEMEM ee_settings[NR_EE_SETTINGS] = {
-	[0 ... NR_EE_SETTINGS - 1] = {
-		.temp_k[TEMPBOOST_NORMAL] = {
+	{
+		.temp_k = {
+			/* TEMPBOOST_NORMAL */
+			{
 			.kp		= FLOAT_TO_FIXPT(CONTRTEMP_PID_KP_NORMAL),
 			.ki		= FLOAT_TO_FIXPT(CONTRTEMP_PID_KI_NORMAL),
 			.kd		= FLOAT_TO_FIXPT(CONTRTEMP_PID_KD_NORMAL),
 			.d_decay_div	= FLOAT_TO_FIXPT(CONTRTEMP_PID_D_DECAY_NORMAL),
-		},
+			},
 #if CONF_BOOST
-		.temp_k[TEMPBOOST_BOOST1] = {
+			/* TEMPBOOST_BOOST1 */
+			{
 			.kp		= FLOAT_TO_FIXPT(CONTRTEMP_PID_KP_BOOST1),
 			.ki		= FLOAT_TO_FIXPT(CONTRTEMP_PID_KI_BOOST1),
 			.kd		= FLOAT_TO_FIXPT(CONTRTEMP_PID_KD_BOOST1),
 			.d_decay_div	= FLOAT_TO_FIXPT(CONTRTEMP_PID_D_DECAY_BOOST1),
-		},
-		.temp_k[TEMPBOOST_BOOST2] = {
+			},
+			/* TEMPBOOST_BOOST2 */
+			{
 			.kp		= FLOAT_TO_FIXPT(CONTRTEMP_PID_KP_BOOST2),
 			.ki		= FLOAT_TO_FIXPT(CONTRTEMP_PID_KI_BOOST2),
 			.kd		= FLOAT_TO_FIXPT(CONTRTEMP_PID_KD_BOOST2),
 			.d_decay_div	= FLOAT_TO_FIXPT(CONTRTEMP_PID_D_DECAY_BOOST2),
+			},
+#endif
 		},
+#if CONF_IDLE
+		.temp_idle_setpoint	= FLOAT_TO_FIXPT(CONTRTEMP_DEF_IDLE_SETPOINT),
 #endif
-		.temp_setpoint[0]	= FLOAT_TO_FIXPT(PRESET_DEFAULT0),
+		.temp_setpoint		= {
+			FLOAT_TO_FIXPT(PRESET_DEFAULT0),
 #if CONF_PRESETS
-		.temp_setpoint[1]	= FLOAT_TO_FIXPT(PRESET_DEFAULT1),
-		.temp_setpoint[2]	= FLOAT_TO_FIXPT(PRESET_DEFAULT2),
-		.temp_setpoint[3]	= FLOAT_TO_FIXPT(PRESET_DEFAULT3),
-		.temp_setpoint[4]	= FLOAT_TO_FIXPT(PRESET_DEFAULT4),
-		.temp_setpoint[5]	= FLOAT_TO_FIXPT(PRESET_DEFAULT5),
+			FLOAT_TO_FIXPT(PRESET_DEFAULT1),
+			FLOAT_TO_FIXPT(PRESET_DEFAULT2),
+			FLOAT_TO_FIXPT(PRESET_DEFAULT3),
+			FLOAT_TO_FIXPT(PRESET_DEFAULT4),
+			FLOAT_TO_FIXPT(PRESET_DEFAULT5),
 #endif
+		},
 		.temp_setpoint_active	= PRESET_DEFAULT_INDEX,
-#if CONF_IDLE
-		.temp_idle_setpoint	= FLOAT_TO_FIXPT(CONTRTEMP_DEF_IDLE_SETPOINT),
-#endif
-		.serial		= 0,
+		.temp_adj		= INT_TO_FIXPT(0),
+		.reserved		= { },
+		.serial			= 0,
 	},
 };
 
 
-static uint8_t ee_read_byte(uint16_t addr)
+static uint8_t ee_read_byte(ee_addr_t addr)
 {
 	uint8_t data;
 
@@ -104,9 +119,9 @@ static uint8_t ee_read_byte(uint16_t addr)
 	return data;
 }
 
-static void ee_read_block(void *dest, uint16_t addr, uint8_t count)
+static void ee_read_block(void *dest, ee_addr_t addr, uint8_t count)
 {
-	uint8_t *d = dest;
+	uint8_t *d = (uint8_t *)dest;
 
 	for ( ; count; count--, d++, addr++)
 		*d = ee_read_byte(addr);
@@ -114,7 +129,7 @@ static void ee_read_block(void *dest, uint16_t addr, uint8_t count)
 
 ISR(EE_READY_vect)
 {
-	uint16_t address;
+	ee_addr_t address;
 	uint8_t data;
 	uint8_t offset;
 	uint8_t index = 0u;
@@ -124,7 +139,7 @@ ISR(EE_READY_vect)
 #endif
 	offset = settings.ee_write_offset;
 
-	address = (uint16_t)((uint8_t *)&ee_settings[index] + offset);
+	address = (ee_addr_t)((uint8_t *)&ee_settings[index] + offset);
 	data = *((uint8_t *)&settings.cache + offset);
 
 	EEAR = address;
@@ -200,7 +215,7 @@ void settings_init(void)
 #endif
 	uint8_t found_index = 0u;
 
-#ifndef __CHECKER__
+#if !defined(__CHECKER__) && !defined(SIMULATOR)
 	build_assert(sizeof(struct settings) == 64);
 #endif
 	build_assert(SEA_SIZE(struct settings, temp_k) >= NR_BOOST_MODES);
@@ -211,14 +226,14 @@ void settings_init(void)
 	 * The latest setting is the one with the largest
 	 * index. However, wrap around must be considered.
 	 */
-	serial = ee_read_byte((uint16_t)&ee_settings[0].serial);
+	serial = ee_read_byte((ee_addr_t)&ee_settings[0].serial);
 	next_index = 0;
 	do {
 		found_index = next_index;
 
 		next_index = ring_next(next_index, ARRAY_SIZE(ee_settings) + 1u);
 
-		next_serial = ee_read_byte((uint16_t)&ee_settings[next_index].serial);
+		next_serial = ee_read_byte((ee_addr_t)&ee_settings[next_index].serial);
 		if (next_serial != ((serial + 1u) & 0xFFu))
 			break;
 
@@ -229,6 +244,6 @@ void settings_init(void)
 
 	/* Read settings from EEPROM. */
 	ee_read_block(&settings.cache,
-		      (uint16_t)&ee_settings[found_index],
+		      (ee_addr_t)&ee_settings[found_index],
 		      sizeof(settings.cache));
 }

+ 1 - 1
firmware/tests/Makefile

@@ -1,5 +1,5 @@
 CPPFLAGS	:= -I.. -Ifake -DF_CPU=8000000UL \
-		   -DTESTSUITE=1
+		   -DTESTSUITE=1 -D_DEFAULT_SOURCE
 CFLAGS		:= -std=c11 -g -O2 -Wall -Wextra -Wno-unused-parameter -Wswitch-enum \
 		   -Wsuggest-attribute=noreturn -Wundef -Wpointer-arith \
 		   -Wcast-qual -Wlogical-op -Wshadow -Wconversion \

+ 75 - 0
firmware/tests/fake/avr/eeprom.h

@@ -0,0 +1,75 @@
+#ifndef FAKE_EEPROM_H_
+#define FAKE_EEPROM_H_
+
+
+#define EEMEM
+
+#define eeprom_is_ready()	1
+#define eeprom_busy_wait()	do { } while (!eeprom_is_ready())
+
+static inline uint8_t eeprom_read_byte (const uint8_t *p)
+{
+	return 0u;
+}
+
+static inline uint16_t eeprom_read_word (const uint16_t *p)
+{
+	return 0u;
+}
+
+static inline uint32_t eeprom_read_dword (const uint32_t *p)
+{
+	return 0u;
+}
+
+static inline float eeprom_read_float (const float *p)
+{
+	return 0.0f;
+}
+
+static inline void eeprom_read_block (void *d, const void *s, size_t n)
+{
+}
+
+static inline void eeprom_write_byte (uint8_t *p, uint8_t v)
+{
+}
+
+static inline void eeprom_write_word (uint16_t *p, uint16_t v)
+{
+}
+
+static inline void eeprom_write_dword (uint32_t *p, uint32_t v)
+{
+}
+
+static inline void eeprom_write_float (float *p, float v)
+{
+}
+
+static inline void eeprom_write_block (const void *s, void *d, size_t n)
+{
+}
+
+static inline void eeprom_update_byte (uint8_t *p, uint8_t v)
+{
+}
+
+static inline void eeprom_update_word (uint16_t *p, uint16_t v)
+{
+}
+
+static inline void eeprom_update_dword (uint32_t *p, uint32_t v)
+{
+}
+
+static inline void eeprom_update_float (float *p, float v)
+{
+}
+
+static inline void eeprom_update_block (const void *s, void *d, size_t n)
+{
+}
+
+
+#endif /* FAKE_EEPROM_H_ */

+ 19 - 2
firmware/tests/fake/avr/interrupt.h

@@ -1,6 +1,23 @@
 #include "avr/io.h"
 
-#define cli()	__asm__ __volatile__("" : : : "memory")
-#define sei()	__asm__ __volatile__("" : : : "memory")
+#ifndef _cli_handler
+# define _cli_handler()  do { } while (0)
+#endif
+
+#ifndef _sei_handler
+# define _sei_handler()  do { } while (0)
+#endif
+
+#define cli()	do {						\
+		__asm__ __volatile__("" : : : "memory");	\
+		_cli_handler();					\
+		__asm__ __volatile__("" : : : "memory");	\
+	} while (0)
+
+#define sei()	do {						\
+		__asm__ __volatile__("" : : : "memory");	\
+		_sei_handler();					\
+		__asm__ __volatile__("" : : : "memory");	\
+	} while (0)
 
 #define ISR(name)	void name(void)

+ 0 - 0
firmware/tests/fake/avr/io.h


Some files were not shown because too many files changed in this diff