Compare commits

..

No commits in common. "763ab24e9e94cd14e4570757e332896d334a3be1" and "1eb7e9c40ac430989d2dee18ad258fb5ab9156b5" have entirely different histories.

4 changed files with 73 additions and 88 deletions

View file

@ -67,20 +67,28 @@ pMCU-attiny424 = t424
# WDT
fuse0_bate= 0x00
# BOD
fuse1_bate= 0x00
# OSC, 20 MHz
fuse2_bate= 0x7e
# ???
fuse4_bate= 0xff
# SYS0 (default 0xf6) RESET, EEPROM erase
fuse5_bate= 0xf7
# SYS1 startup time (64ms)
fuse6_bate= 0xff
# APPEND
fuse7_bate= 0x00
# BOOTEND
fuse8_bate= 0x00
fuses_bate =$(patsubst %, 0x%, 00 00 7e ff ff f7 ff 00 00)
AVRDUDEPROG = avrdude
@ -117,25 +125,23 @@ fuse: $(PROJ).fuse$F
# see bate.c: Configuration in USERROW
BC_MAGIC = 0xba
BC_VERS = 4
BC_TRIG = 0x08
BC_SEND = 0x1b
BC_PWR = 0x04
BC_TEST = 5
BC_SPI = 0xff
BC_MDEL = 2
BC_PER = 59 0
BC_CPER = 15 14
BC_VERS = 3
BC_CLK = 1
BC_PWR = 0x04
BC_SEND = 0x17
BC_TRIG = 0x08
BC_MCLK = 0
BC_BAUD = 0 0
BC_MDEL = 2
BC_PIT = 0xff
BC_BAUD = 0 0
BC_TEST = 0
BC_PERIOD= 9
BC_SPI = 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 = $(BC_MAGIC) $(BC_VERS) $(BC_CLK) \
$(BC_PWR) $(BC_SEND) $(BC_TRIG) \
$(BC_MCLK) $(BC_MDEL) $(BC_PIT) $(BC_BAUD) \
$(BC_TEST) $(BC_PERIOD) $(BC_SPI)
bate.config:
$(AD) -U userrow:v:"$(BATE_CONFIG)":m \

View file

@ -95,14 +95,14 @@ ISR(ADC0_RESRDY_vect)
if (i >= N_ADC)
goto stop;
adc_readings[i] = *(volatile uint16_t *) &ADC.RESULT;
if (++i < N_ADC) {
while (++i < N_ADC) {
const struct adc_conf *c = adc_conf + i;
if (c->mode || c->mode == 0xff)
goto stop;
if (c->mode && c->mode != 0xff) {
adc_current = i;
start_conversion(c);
return;
}
}
stop:
ADC.CTRLA = 0;
adc_current = N_ADC;
@ -126,7 +126,7 @@ ISR(ADC0_RESRDY_vect, ISR_NAKED)
"push r31" "\n\t"
"lds r24, adc_current" "\n\t"
"cpi r24, %[NADC]" "\n\t"
"brsh 3f" "\n\t"
"brsh 4f" "\n\t"
"mov r30, r24" "\n\t"
"ldi r31, 0" "\n\t"
"lsl r30" "\n\t"
@ -137,7 +137,7 @@ ISR(ADC0_RESRDY_vect, ISR_NAKED)
"lds r25, %[RESULT]+1" "\n\t"
"std Z+1, r25" "\n\t"
"cpi r24, %[NADC]-1" "\n\t"
"brsh 3f" "\n\t"
"brsh 4f" "\n\t"
"subi r24, 0xff" "\n\t"
"mov r30, r24" "\n\t"
"ldi r31, 0" "\n\t"
@ -168,6 +168,11 @@ ISR(ADC0_RESRDY_vect, ISR_NAKED)
"pop r24" "\n\t"
"reti" "\n"
"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"
"sts %[CTRLA], r24" "\n\t"
"ldi r24, %[NADC]" "\n\t"

View file

@ -357,14 +357,13 @@ void read_bate()
struct config config = {
.power = STOP_MCLK,
.send = SEND_CONFIG | SEND_CLOCK | SEND_BATED | SEND_ADC,
.send = SEND_BOOT_MESSAGE | SEND_CLOCK | SEND_HEX | SEND_ADC,
.cpu_clk = CLKCTRL_PDIV_2X_gc | 1,
.pit_period = RTC_CLKSEL_INT1K_gc,
.spi_div = SPI_PRESC_DIV64_gc,
.triggers = TRIGGER_CLOCK,
.mclk_delay = 2,
.period = 59,
.cperiod = 3599,
.pit_period = RTC_CLKSEL_INT1K_gc,
.period = 9,
.spi_div = SPI_PRESC_DIV64_gc,
};
static const struct config *userrow = (struct config *) & USERROW;
@ -411,20 +410,20 @@ int main()
sei();
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;
if (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 mclk_delay = 0;
static uint16_t trigger_clock = 0;
static uint16_t config_clock = 0;
uint8_t send_config = 1;
uint8_t trigger_clock = 0;
while (1) {
DEBUG_COUNTER(mainloops);
@ -435,9 +434,8 @@ int main()
continue;
adc_current = 0xff;
send_hex('A', (uint8_t *)adc_readings,
2*n_adc, 3);
sizeof(adc_readings), 3);
}
if (uart_busy()) {
uart_tick();
continue;
@ -452,19 +450,12 @@ int main()
trigger |= TRIGGER_UART;
if (uart_break_p())
trigger |= TRIGGER_BREAK;
if (clock_tick) {
clock_tick = 0;
if (test_calib)
trigger |= TRIGGER_CLOCK;
else if (!trigger_clock--) {
if (!trigger_clock--) {
trigger |= TRIGGER_CLOCK;
trigger_clock = config.period;
}
if (!config_clock-- && config.send & SEND_CONFIG) {
send_config = 1;
config_clock = config.cperiod;
}
}
if (!(trigger & config.triggers)) {
if (config.power & POWER_DOWN) {
@ -509,17 +500,17 @@ int main()
if (config.send & SEND_CLOCK) {
send_str("T 0x");
send_hex_long(time);
send_str(" 0x");
send_hex_byte(trigger);
send_char('\n');
}
const union bate *b = &bate;
if (test_calib)
b = testdata + test_calib;
if (config.send & SEND_BATEW || send_config || test_calib)
send_hex('W', b->b, 8, 3);
if (config.send & SEND_BATED || test_calib)
send_hex('D', b->b+8, 4, 3);
if (config.send & SEND_CALIB || test_calib) {
b = testdata + --test_calib;
if (config.send & SEND_HEX)
send_hex('B', b->b, sizeof(union bate), 3);
if (config.send & SEND_CALIB) {
bate_calib(b, &pressure);
send_str("P ");
send_str(decimal_str(pressure.p, 1));
@ -527,22 +518,9 @@ int main()
send_str(decimal_str(pressure.T-2732, 1));
send_str(" °C\n");
}
if (test_calib)
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);
DEBUG_PRINT(0x77, 00);
}
uart_tick();
trigger = TRIGGER_CONT;
}

View file

@ -11,24 +11,22 @@
struct config {
uint8_t magic;
uint8_t version;
uint8_t triggers;
uint8_t send;
uint8_t power;
uint8_t calib_test;
uint8_t spi_div;
uint8_t mclk_delay;
uint16_t period;
uint16_t cperiod;
uint8_t cpu_clk;
uint8_t power;
uint8_t send;
uint8_t triggers;
uint8_t mclk_period;
uint16_t baud_div;
uint8_t mclk_delay;
uint8_t pit_period;
uint8_t pad;
uint16_t baud_div;
uint8_t calib_test;
uint8_t period;
uint8_t spi_div;
};
enum magic_flags {
USE_USERROW = 0xBA,
USE_VERSION = 0x04,
USE_VERSION = 0x03,
};
@ -38,13 +36,11 @@ enum power_flags {
STOP_MCLK = 0x04,
};
enum send_flags {
SEND_CONFIG = 0x01,
SEND_BATED = 0x02,
SEND_BATEW = 0x04,
SEND_CLOCK = 0x08,
SEND_BOOT_MESSAGE = 0x01,
SEND_CLOCK = 0x02,
SEND_HEX = 0x04,
SEND_CALIB = 0x08,
SEND_ADC = 0x10,
SEND_CALIB = 0x20,
SEND_VOLT = 0x40,
SEND_DEBUG = 0x80,
};
enum trigger_flags {