mirror of
https://codeberg.org/SiB64/turbo_weather.git
synced 2026-05-01 15:14:22 +02:00
Compare commits
2 commits
1eb7e9c40a
...
763ab24e9e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
763ab24e9e | ||
|
|
365d7382c1 |
4 changed files with 88 additions and 73 deletions
38
src/Makefile
38
src/Makefile
|
|
@ -67,28 +67,20 @@ pMCU-attiny424 = t424
|
||||||
|
|
||||||
# WDT
|
# WDT
|
||||||
fuse0_bate= 0x00
|
fuse0_bate= 0x00
|
||||||
|
|
||||||
# BOD
|
# BOD
|
||||||
fuse1_bate= 0x00
|
fuse1_bate= 0x00
|
||||||
|
|
||||||
# OSC, 20 MHz
|
# OSC, 20 MHz
|
||||||
fuse2_bate= 0x7e
|
fuse2_bate= 0x7e
|
||||||
|
|
||||||
# ???
|
# ???
|
||||||
fuse4_bate= 0xff
|
fuse4_bate= 0xff
|
||||||
|
|
||||||
# SYS0 (default 0xf6) RESET, EEPROM erase
|
# SYS0 (default 0xf6) RESET, EEPROM erase
|
||||||
fuse5_bate= 0xf7
|
fuse5_bate= 0xf7
|
||||||
|
|
||||||
# SYS1 startup time (64ms)
|
# SYS1 startup time (64ms)
|
||||||
fuse6_bate= 0xff
|
fuse6_bate= 0xff
|
||||||
|
|
||||||
# APPEND
|
# APPEND
|
||||||
fuse7_bate= 0x00
|
fuse7_bate= 0x00
|
||||||
|
|
||||||
# BOOTEND
|
# BOOTEND
|
||||||
fuse8_bate= 0x00
|
fuse8_bate= 0x00
|
||||||
|
|
||||||
fuses_bate =$(patsubst %, 0x%, 00 00 7e ff ff f7 ff 00 00)
|
fuses_bate =$(patsubst %, 0x%, 00 00 7e ff ff f7 ff 00 00)
|
||||||
|
|
||||||
AVRDUDEPROG = avrdude
|
AVRDUDEPROG = avrdude
|
||||||
|
|
@ -125,23 +117,25 @@ fuse: $(PROJ).fuse$F
|
||||||
|
|
||||||
# see bate.c: Configuration in USERROW
|
# see bate.c: Configuration in USERROW
|
||||||
BC_MAGIC = 0xba
|
BC_MAGIC = 0xba
|
||||||
BC_VERS = 3
|
BC_VERS = 4
|
||||||
BC_CLK = 1
|
|
||||||
BC_PWR = 0x04
|
|
||||||
BC_SEND = 0x17
|
|
||||||
BC_TRIG = 0x08
|
BC_TRIG = 0x08
|
||||||
BC_MCLK = 0
|
BC_SEND = 0x1b
|
||||||
BC_MDEL = 2
|
BC_PWR = 0x04
|
||||||
BC_PIT = 0xff
|
BC_TEST = 5
|
||||||
BC_BAUD = 0 0
|
|
||||||
BC_TEST = 0
|
|
||||||
BC_PERIOD= 9
|
|
||||||
BC_SPI = 0xff
|
BC_SPI = 0xff
|
||||||
|
BC_MDEL = 2
|
||||||
|
BC_PER = 59 0
|
||||||
|
BC_CPER = 15 14
|
||||||
|
|
||||||
BATE_CONFIG = $(BC_MAGIC) $(BC_VERS) $(BC_CLK) \
|
BC_CLK = 1
|
||||||
$(BC_PWR) $(BC_SEND) $(BC_TRIG) \
|
BC_MCLK = 0
|
||||||
$(BC_MCLK) $(BC_MDEL) $(BC_PIT) $(BC_BAUD) \
|
BC_BAUD = 0 0
|
||||||
$(BC_TEST) $(BC_PERIOD) $(BC_SPI)
|
BC_PIT = 0xff
|
||||||
|
|
||||||
|
BATE_CONFIG = $(BC_MAGIC) $(BC_VERS) \
|
||||||
|
$(BC_TRIG) $(BC_SEND) $(BC_PWR) $(BC_TEST) \
|
||||||
|
$(BC_SPI) $(BC_MDEL) $(BC_PER) $(BC_CPER) \
|
||||||
|
$(BC_CLK) $(BC_MCLK) $(BC_BAUD) $(BC_PIT)
|
||||||
|
|
||||||
bate.config:
|
bate.config:
|
||||||
$(AD) -U userrow:v:"$(BATE_CONFIG)":m \
|
$(AD) -U userrow:v:"$(BATE_CONFIG)":m \
|
||||||
|
|
|
||||||
21
src/adc.c
21
src/adc.c
|
|
@ -95,13 +95,13 @@ ISR(ADC0_RESRDY_vect)
|
||||||
if (i >= N_ADC)
|
if (i >= N_ADC)
|
||||||
goto stop;
|
goto stop;
|
||||||
adc_readings[i] = *(volatile uint16_t *) &ADC.RESULT;
|
adc_readings[i] = *(volatile uint16_t *) &ADC.RESULT;
|
||||||
while (++i < N_ADC) {
|
if (++i < N_ADC) {
|
||||||
const struct adc_conf *c = adc_conf + i;
|
const struct adc_conf *c = adc_conf + i;
|
||||||
if (c->mode && c->mode != 0xff) {
|
if (c->mode || c->mode == 0xff)
|
||||||
adc_current = i;
|
goto stop;
|
||||||
start_conversion(c);
|
adc_current = i;
|
||||||
return;
|
start_conversion(c);
|
||||||
}
|
return;
|
||||||
}
|
}
|
||||||
stop:
|
stop:
|
||||||
ADC.CTRLA = 0;
|
ADC.CTRLA = 0;
|
||||||
|
|
@ -126,7 +126,7 @@ ISR(ADC0_RESRDY_vect, ISR_NAKED)
|
||||||
"push r31" "\n\t"
|
"push r31" "\n\t"
|
||||||
"lds r24, adc_current" "\n\t"
|
"lds r24, adc_current" "\n\t"
|
||||||
"cpi r24, %[NADC]" "\n\t"
|
"cpi r24, %[NADC]" "\n\t"
|
||||||
"brsh 4f" "\n\t"
|
"brsh 3f" "\n\t"
|
||||||
"mov r30, r24" "\n\t"
|
"mov r30, r24" "\n\t"
|
||||||
"ldi r31, 0" "\n\t"
|
"ldi r31, 0" "\n\t"
|
||||||
"lsl r30" "\n\t"
|
"lsl r30" "\n\t"
|
||||||
|
|
@ -137,7 +137,7 @@ ISR(ADC0_RESRDY_vect, ISR_NAKED)
|
||||||
"lds r25, %[RESULT]+1" "\n\t"
|
"lds r25, %[RESULT]+1" "\n\t"
|
||||||
"std Z+1, r25" "\n\t"
|
"std Z+1, r25" "\n\t"
|
||||||
"cpi r24, %[NADC]-1" "\n\t"
|
"cpi r24, %[NADC]-1" "\n\t"
|
||||||
"brsh 4f" "\n\t"
|
"brsh 3f" "\n\t"
|
||||||
"subi r24, 0xff" "\n\t"
|
"subi r24, 0xff" "\n\t"
|
||||||
"mov r30, r24" "\n\t"
|
"mov r30, r24" "\n\t"
|
||||||
"ldi r31, 0" "\n\t"
|
"ldi r31, 0" "\n\t"
|
||||||
|
|
@ -168,11 +168,6 @@ ISR(ADC0_RESRDY_vect, ISR_NAKED)
|
||||||
"pop r24" "\n\t"
|
"pop r24" "\n\t"
|
||||||
"reti" "\n"
|
"reti" "\n"
|
||||||
"3:" "\n\t"
|
"3:" "\n\t"
|
||||||
"adiw r30, 4" "\n\t"
|
|
||||||
"subi r24, 0xff" "\n\t"
|
|
||||||
"cpi r24, %[NADC]" "\n\t"
|
|
||||||
"brlo 1b" "\n"
|
|
||||||
"4:" "\n\t"
|
|
||||||
"clr r24" "\n\t"
|
"clr r24" "\n\t"
|
||||||
"sts %[CTRLA], r24" "\n\t"
|
"sts %[CTRLA], r24" "\n\t"
|
||||||
"ldi r24, %[NADC]" "\n\t"
|
"ldi r24, %[NADC]" "\n\t"
|
||||||
|
|
|
||||||
66
src/bate.c
66
src/bate.c
|
|
@ -357,13 +357,14 @@ void read_bate()
|
||||||
|
|
||||||
struct config config = {
|
struct config config = {
|
||||||
.power = STOP_MCLK,
|
.power = STOP_MCLK,
|
||||||
.send = SEND_BOOT_MESSAGE | SEND_CLOCK | SEND_HEX | SEND_ADC,
|
.send = SEND_CONFIG | SEND_CLOCK | SEND_BATED | SEND_ADC,
|
||||||
.cpu_clk = CLKCTRL_PDIV_2X_gc | 1,
|
.cpu_clk = CLKCTRL_PDIV_2X_gc | 1,
|
||||||
|
.pit_period = RTC_CLKSEL_INT1K_gc,
|
||||||
|
.spi_div = SPI_PRESC_DIV64_gc,
|
||||||
.triggers = TRIGGER_CLOCK,
|
.triggers = TRIGGER_CLOCK,
|
||||||
.mclk_delay = 2,
|
.mclk_delay = 2,
|
||||||
.pit_period = RTC_CLKSEL_INT1K_gc,
|
.period = 59,
|
||||||
.period = 9,
|
.cperiod = 3599,
|
||||||
.spi_div = SPI_PRESC_DIV64_gc,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static const struct config *userrow = (struct config *) & USERROW;
|
static const struct config *userrow = (struct config *) & USERROW;
|
||||||
|
|
@ -410,20 +411,20 @@ int main()
|
||||||
sei();
|
sei();
|
||||||
|
|
||||||
send_str("\nV Turbo Weather V0.03\n");
|
send_str("\nV Turbo Weather V0.03\n");
|
||||||
if (config.send & SEND_BOOT_MESSAGE) {
|
|
||||||
send_hex('S', (uint8_t *)&SIGROW, sizeof(SIGROW_t), 0);
|
|
||||||
send_hex('F', (uint8_t *)&FUSE, sizeof(FUSE_t), 1);
|
|
||||||
send_hex('U', (uint8_t *)&USERROW, sizeof(USERROW_t), 1);
|
|
||||||
send_hex('C', (uint8_t *)&config, sizeof(struct config), 1);
|
|
||||||
send_hex('E', (uint8_t *)adc_conf, sizeof(adc_conf), 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t test_calib = config.calib_test;
|
uint8_t test_calib = config.calib_test;
|
||||||
if (test_calib > N_TESTDATA)
|
if (test_calib > N_TESTDATA)
|
||||||
test_calib = N_TESTDATA;
|
test_calib = N_TESTDATA;
|
||||||
|
|
||||||
|
uint8_t n_adc = 0;
|
||||||
|
while (n_adc < N_ADC && adc_conf[n_adc].mode && adc_conf[n_adc].mode != 0xff)
|
||||||
|
n_adc++;
|
||||||
|
|
||||||
uint8_t trigger = TRIGGER_CONT | TRIGGER_ONCE;
|
uint8_t trigger = TRIGGER_CONT | TRIGGER_ONCE;
|
||||||
uint8_t mclk_delay = 0;
|
uint8_t mclk_delay = 0;
|
||||||
uint8_t trigger_clock = 0;
|
static uint16_t trigger_clock = 0;
|
||||||
|
static uint16_t config_clock = 0;
|
||||||
|
uint8_t send_config = 1;
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
DEBUG_COUNTER(mainloops);
|
DEBUG_COUNTER(mainloops);
|
||||||
|
|
@ -434,8 +435,9 @@ int main()
|
||||||
continue;
|
continue;
|
||||||
adc_current = 0xff;
|
adc_current = 0xff;
|
||||||
send_hex('A', (uint8_t *)adc_readings,
|
send_hex('A', (uint8_t *)adc_readings,
|
||||||
sizeof(adc_readings), 3);
|
2*n_adc, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (uart_busy()) {
|
if (uart_busy()) {
|
||||||
uart_tick();
|
uart_tick();
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -450,12 +452,19 @@ int main()
|
||||||
trigger |= TRIGGER_UART;
|
trigger |= TRIGGER_UART;
|
||||||
if (uart_break_p())
|
if (uart_break_p())
|
||||||
trigger |= TRIGGER_BREAK;
|
trigger |= TRIGGER_BREAK;
|
||||||
|
|
||||||
if (clock_tick) {
|
if (clock_tick) {
|
||||||
clock_tick = 0;
|
clock_tick = 0;
|
||||||
if (!trigger_clock--) {
|
if (test_calib)
|
||||||
|
trigger |= TRIGGER_CLOCK;
|
||||||
|
else if (!trigger_clock--) {
|
||||||
trigger |= TRIGGER_CLOCK;
|
trigger |= TRIGGER_CLOCK;
|
||||||
trigger_clock = config.period;
|
trigger_clock = config.period;
|
||||||
}
|
}
|
||||||
|
if (!config_clock-- && config.send & SEND_CONFIG) {
|
||||||
|
send_config = 1;
|
||||||
|
config_clock = config.cperiod;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!(trigger & config.triggers)) {
|
if (!(trigger & config.triggers)) {
|
||||||
if (config.power & POWER_DOWN) {
|
if (config.power & POWER_DOWN) {
|
||||||
|
|
@ -500,17 +509,17 @@ int main()
|
||||||
if (config.send & SEND_CLOCK) {
|
if (config.send & SEND_CLOCK) {
|
||||||
send_str("T 0x");
|
send_str("T 0x");
|
||||||
send_hex_long(time);
|
send_hex_long(time);
|
||||||
send_str(" 0x");
|
|
||||||
send_hex_byte(trigger);
|
|
||||||
send_char('\n');
|
send_char('\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
const union bate *b = &bate;
|
const union bate *b = &bate;
|
||||||
if (test_calib)
|
if (test_calib)
|
||||||
b = testdata + --test_calib;
|
b = testdata + test_calib;
|
||||||
if (config.send & SEND_HEX)
|
if (config.send & SEND_BATEW || send_config || test_calib)
|
||||||
send_hex('B', b->b, sizeof(union bate), 3);
|
send_hex('W', b->b, 8, 3);
|
||||||
if (config.send & SEND_CALIB) {
|
if (config.send & SEND_BATED || test_calib)
|
||||||
|
send_hex('D', b->b+8, 4, 3);
|
||||||
|
if (config.send & SEND_CALIB || test_calib) {
|
||||||
bate_calib(b, &pressure);
|
bate_calib(b, &pressure);
|
||||||
send_str("P ");
|
send_str("P ");
|
||||||
send_str(decimal_str(pressure.p, 1));
|
send_str(decimal_str(pressure.p, 1));
|
||||||
|
|
@ -518,9 +527,22 @@ int main()
|
||||||
send_str(decimal_str(pressure.T-2732, 1));
|
send_str(decimal_str(pressure.T-2732, 1));
|
||||||
send_str(" °C\n");
|
send_str(" °C\n");
|
||||||
}
|
}
|
||||||
if (config.send & SEND_DEBUG) {
|
if (test_calib)
|
||||||
DEBUG_PRINT(0x77, 00);
|
test_calib--;
|
||||||
|
|
||||||
|
if (send_config) {
|
||||||
|
send_config = 0;
|
||||||
|
send_hex('S', (uint8_t *)&SIGROW, sizeof(SIGROW_t), 0);
|
||||||
|
send_hex('F', (uint8_t *)&FUSE, sizeof(FUSE_t), 1);
|
||||||
|
send_hex('U', (uint8_t *)&USERROW, sizeof(USERROW_t), 1);
|
||||||
|
send_hex('C', (uint8_t *)&config, sizeof(struct config), 1);
|
||||||
|
send_hex('E', (uint8_t *)adc_conf, sizeof(adc_conf), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (config.send & SEND_DEBUG) {
|
||||||
|
DEBUG_PRINT(0x77, trigger);
|
||||||
|
}
|
||||||
|
|
||||||
uart_tick();
|
uart_tick();
|
||||||
trigger = TRIGGER_CONT;
|
trigger = TRIGGER_CONT;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
40
src/bate.h
40
src/bate.h
|
|
@ -9,24 +9,26 @@
|
||||||
// Configuration
|
// Configuration
|
||||||
|
|
||||||
struct config {
|
struct config {
|
||||||
uint8_t magic;
|
uint8_t magic;
|
||||||
uint8_t version;
|
uint8_t version;
|
||||||
uint8_t cpu_clk;
|
uint8_t triggers;
|
||||||
uint8_t power;
|
uint8_t send;
|
||||||
uint8_t send;
|
uint8_t power;
|
||||||
uint8_t triggers;
|
uint8_t calib_test;
|
||||||
uint8_t mclk_period;
|
uint8_t spi_div;
|
||||||
uint8_t mclk_delay;
|
uint8_t mclk_delay;
|
||||||
uint8_t pit_period;
|
uint16_t period;
|
||||||
uint16_t baud_div;
|
uint16_t cperiod;
|
||||||
uint8_t calib_test;
|
uint8_t cpu_clk;
|
||||||
uint8_t period;
|
uint8_t mclk_period;
|
||||||
uint8_t spi_div;
|
uint16_t baud_div;
|
||||||
|
uint8_t pit_period;
|
||||||
|
uint8_t pad;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum magic_flags {
|
enum magic_flags {
|
||||||
USE_USERROW = 0xBA,
|
USE_USERROW = 0xBA,
|
||||||
USE_VERSION = 0x03,
|
USE_VERSION = 0x04,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -36,11 +38,13 @@ enum power_flags {
|
||||||
STOP_MCLK = 0x04,
|
STOP_MCLK = 0x04,
|
||||||
};
|
};
|
||||||
enum send_flags {
|
enum send_flags {
|
||||||
SEND_BOOT_MESSAGE = 0x01,
|
SEND_CONFIG = 0x01,
|
||||||
SEND_CLOCK = 0x02,
|
SEND_BATED = 0x02,
|
||||||
SEND_HEX = 0x04,
|
SEND_BATEW = 0x04,
|
||||||
SEND_CALIB = 0x08,
|
SEND_CLOCK = 0x08,
|
||||||
SEND_ADC = 0x10,
|
SEND_ADC = 0x10,
|
||||||
|
SEND_CALIB = 0x20,
|
||||||
|
SEND_VOLT = 0x40,
|
||||||
SEND_DEBUG = 0x80,
|
SEND_DEBUG = 0x80,
|
||||||
};
|
};
|
||||||
enum trigger_flags {
|
enum trigger_flags {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue