mirror of
https://codeberg.org/SiB64/turbo_weather.git
synced 2026-05-01 15:14:22 +02:00
Compare commits
2 commits
e62e03f550
...
1eb7e9c40a
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1eb7e9c40a | ||
|
|
83fa8725f0 |
12 changed files with 64 additions and 80 deletions
22
src/Makefile
22
src/Makefile
|
|
@ -8,7 +8,7 @@ all: $(PROJ).hex
|
||||||
|
|
||||||
SN_bate = 1
|
SN_bate = 1
|
||||||
MCU_bate = attiny424
|
MCU_bate = attiny424
|
||||||
C_FILES_bate = uart.c rtc.c calib.c mul.c adc.c spi.c
|
C_FILES_bate = uart.c rtc.c spi.c adc.c calib.c mul.c
|
||||||
|
|
||||||
BATE_PERIOD=76
|
BATE_PERIOD=76
|
||||||
bate_CFLAGS = -DPERIOD=$(BATE_PERIOD)
|
bate_CFLAGS = -DPERIOD=$(BATE_PERIOD)
|
||||||
|
|
@ -39,7 +39,7 @@ OBJS = $(patsubst %.c, %.o, $(C_FILES))
|
||||||
|
|
||||||
-include *.d
|
-include *.d
|
||||||
|
|
||||||
LDFLAGS =
|
LDFLAGS = -Teeprom.ld
|
||||||
|
|
||||||
%.elf: %.o $(OBJS)
|
%.elf: %.o $(OBJS)
|
||||||
$(CC) $(CFLAGS) -Wl,-Map=$*.map,--cref $^ --output $@ $(LDFLAGS)
|
$(CC) $(CFLAGS) -Wl,-Map=$*.map,--cref $^ --output $@ $(LDFLAGS)
|
||||||
|
|
@ -47,10 +47,12 @@ LDFLAGS =
|
||||||
OBJCOPY = avr-objcopy
|
OBJCOPY = avr-objcopy
|
||||||
|
|
||||||
%.hex: %.elf
|
%.hex: %.elf
|
||||||
$(OBJCOPY) -O ihex -R .eeprom $< $@
|
$(OBJCOPY) -O ihex -R .eeprom -R .eemap $< $@
|
||||||
|
|
||||||
|
%.eeprom: %.elf
|
||||||
|
$(OBJCOPY) -O ihex -j .eemap --change-section-lma .eemap=0 $< $@
|
||||||
|
|
||||||
|
|
||||||
pMCU-attiny414 = t414
|
|
||||||
pMCU-attiny424 = t424
|
pMCU-attiny424 = t424
|
||||||
|
|
||||||
#
|
#
|
||||||
|
|
@ -109,9 +111,10 @@ ad: $(PROJ).ad
|
||||||
%.burn: %.hex
|
%.burn: %.hex
|
||||||
$(AD) -U flash:w:$<
|
$(AD) -U flash:w:$<
|
||||||
|
|
||||||
%.verify: %.hex
|
%.verify: %.hex %.eeprom
|
||||||
-$(AD) -qq -U fuses:v:"$(fuses_$*)":m
|
-$(AD) -qq -U fuses:v:"$(fuses_$*)":m
|
||||||
-$(AD) -qq -U userrow:v:"$(BATE_CONFIG)":m
|
-$(AD) -qq -U userrow:v:"$(BATE_CONFIG)":m
|
||||||
|
-$(AD) -qq -U eeprom:v:$(word 2, $^)
|
||||||
-$(AD) -qq -U flash:v:$<
|
-$(AD) -qq -U flash:v:$<
|
||||||
|
|
||||||
fuse: $(PROJ).fuse$F
|
fuse: $(PROJ).fuse$F
|
||||||
|
|
@ -149,14 +152,9 @@ clean:
|
||||||
|
|
||||||
.PHONY: eeprom.eeprom
|
.PHONY: eeprom.eeprom
|
||||||
eeprom.eeprom:
|
eeprom.eeprom:
|
||||||
$(AVRDUDE) -p $(pMCU-$(MCU)) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) \
|
$(AD) -U eeprom:r:$@
|
||||||
-U eeprom:r:$@:r
|
|
||||||
|
|
||||||
%.eeprom.burn: %.eeprom
|
%.eeprom.burn: %.eeprom
|
||||||
$(AVRDUDE) -p $(pMCU-$(MCU)) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) \
|
$(AD) -U eeprom:v:$< || $(AD) -U eeprom:w:$<
|
||||||
-U 'eeprom:v:$<:r' \
|
|
||||||
|| $(AVRDUDE) -p $(pMCU-$(MCU)) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) \
|
|
||||||
-U 'eeprom:w:$<:r'
|
|
||||||
|
|
||||||
calib: calib.c mul.c
|
calib: calib.c mul.c
|
||||||
gcc -DCALIB_DEBUG -o $@ $<
|
gcc -DCALIB_DEBUG -o $@ $<
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
#include "adc.h"
|
#include "adc.h"
|
||||||
#include "bate.h"
|
#include "bate.h"
|
||||||
|
#include "eeprom.h"
|
||||||
#include <avr/interrupt.h>
|
#include <avr/interrupt.h>
|
||||||
|
|
||||||
enum adc_conf_parameter {
|
enum adc_conf_parameter {
|
||||||
|
|
@ -17,7 +18,7 @@ enum adc_conf_parameter {
|
||||||
V_BAT = ADC_MUXPOS_AIN7_gc,
|
V_BAT = ADC_MUXPOS_AIN7_gc,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct adc_conf adc_conf[N_ADC] = {
|
struct adc_conf adc_conf[N_ADC] ADC_CONF_ADDR = {
|
||||||
{ // Internal Temperature
|
{ // Internal Temperature
|
||||||
.mode = MODE,
|
.mode = MODE,
|
||||||
.ref = REF | ADC_REFSEL_1024MV_gc,
|
.ref = REF | ADC_REFSEL_1024MV_gc,
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,6 @@
|
||||||
#include <avr/io.h>
|
#include <avr/io.h>
|
||||||
#define ADC ADC0
|
#define ADC ADC0
|
||||||
|
|
||||||
#define N_ADC 6
|
|
||||||
|
|
||||||
struct adc_conf {
|
struct adc_conf {
|
||||||
uint8_t mode;
|
uint8_t mode;
|
||||||
uint8_t ref;
|
uint8_t ref;
|
||||||
|
|
@ -14,6 +12,8 @@ struct adc_conf {
|
||||||
uint8_t inn;
|
uint8_t inn;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#define N_ADC (32/sizeof(struct adc_conf))
|
||||||
|
|
||||||
extern uint16_t adc_readings[N_ADC];
|
extern uint16_t adc_readings[N_ADC];
|
||||||
extern uint8_t adc_current;
|
extern uint8_t adc_current;
|
||||||
|
|
||||||
|
|
|
||||||
11
src/bate.c
11
src/bate.c
|
|
@ -419,13 +419,8 @@ int main()
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t test_calib = config.calib_test;
|
uint8_t test_calib = config.calib_test;
|
||||||
static const union bate testdata[4] = {
|
if (test_calib > N_TESTDATA)
|
||||||
{ .W = { 0xabaf, 0x3c99, 0xa31a, 0xb589}, .D = { 0x470c, 0x773f }, }, // 21.2 °C, 1021.7 mbar
|
test_calib = N_TESTDATA;
|
||||||
{ .W = { 0xabaf, 0x3c99, 0xa31a, 0xb589}, .D = { 0x1a51, 0x6fed }, }, // 7.5 °C, 5.4 mbar
|
|
||||||
{ .W = { 0xaa3d, 0x35d9, 0xcbe5, 0xb736}, .D = { 0x4bb7, 0x7487 }, }, // 17.7 °C, 1023.0 mbar
|
|
||||||
{ .W = { 0xaa3d, 0x35d9, 0xcbe5, 0xb736}, .D = { 0x1e25, 0x650a }, }, // -11.3 °C, 2.4 mbar
|
|
||||||
};
|
|
||||||
|
|
||||||
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;
|
uint8_t trigger_clock = 0;
|
||||||
|
|
@ -512,7 +507,7 @@ int main()
|
||||||
|
|
||||||
const union bate *b = &bate;
|
const union bate *b = &bate;
|
||||||
if (test_calib)
|
if (test_calib)
|
||||||
b = testdata + (--test_calib & 3);
|
b = testdata + --test_calib;
|
||||||
if (config.send & SEND_HEX)
|
if (config.send & SEND_HEX)
|
||||||
send_hex('B', b->b, sizeof(union bate), 3);
|
send_hex('B', b->b, sizeof(union bate), 3);
|
||||||
if (config.send & SEND_CALIB) {
|
if (config.send & SEND_CALIB) {
|
||||||
|
|
|
||||||
19
src/calib.c
19
src/calib.c
|
|
@ -7,6 +7,9 @@
|
||||||
|
|
||||||
#ifdef CALIB_DEBUG
|
#ifdef CALIB_DEBUG
|
||||||
# include <stdio.h>
|
# include <stdio.h>
|
||||||
|
# define TESTDATA_ADDR
|
||||||
|
#else
|
||||||
|
# include "eeprom.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "calib.h"
|
#include "calib.h"
|
||||||
|
|
@ -74,14 +77,6 @@ void bate_calib(const union bate *bate, struct pressure *pt)
|
||||||
printf(" %.1f °C %.1f mbar\n\n", TEMP/10., P/10.);
|
printf(" %.1f °C %.1f mbar\n\n", TEMP/10., P/10.);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const union bate testdata[] = {
|
|
||||||
{ .w = { 0xA691, 0x0A97, 0x989F, 0xAF28, 0x4896, 0x71F4 }, },
|
|
||||||
{ .W = { 0xabaf, 0x3c99, 0xa31a, 0xb589}, .D = { 0x470c, 0x773f }, }, // 21.2 °C, 1021.7 mbar
|
|
||||||
{ .W = { 0xabaf, 0x3c99, 0xa31a, 0xb589}, .D = { 0x1a51, 0x6fed }, }, // 7.5 °C, 5.4 mbar
|
|
||||||
{ .W = { 0xaa3d, 0x35d9, 0xcbe5, 0xb736}, .D = { 0x4bb7, 0x7487 }, }, // 17.7 °C, 1023.0 mbar
|
|
||||||
{ .W = { 0xaa3d, 0x35d9, 0xcbe5, 0xb736}, .D = { 0x1e25, 0x650a }, }, // -11.3 °C, 2.4 mbar
|
|
||||||
};
|
|
||||||
|
|
||||||
#define MUL_DEBUG
|
#define MUL_DEBUG
|
||||||
#include "mul.c"
|
#include "mul.c"
|
||||||
|
|
||||||
|
|
@ -93,3 +88,11 @@ int main()
|
||||||
return 0;
|
return 0;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const union bate testdata[] TESTDATA_ADDR = {
|
||||||
|
{ .w = { 0xA691, 0x0A97, 0x989F, 0xAF28, 0x4896, 0x71F4 }, },
|
||||||
|
{ .W = { 0xabaf, 0x3c99, 0xa31a, 0xb589}, .D = { 0x470c, 0x773f }, }, // 21.2 °C, 1021.7 mbar
|
||||||
|
{ .W = { 0xabaf, 0x3c99, 0xa31a, 0xb589}, .D = { 0x1a51, 0x6fed }, }, // 7.5 °C, 5.4 mbar
|
||||||
|
{ .W = { 0xaa3d, 0x35d9, 0xcbe5, 0xb736}, .D = { 0x4bb7, 0x7487 }, }, // 17.7 °C, 1023.0 mbar
|
||||||
|
{ .W = { 0xaa3d, 0x35d9, 0xcbe5, 0xb736}, .D = { 0x1e25, 0x650a }, }, // -11.3 °C, 2.4 mbar
|
||||||
|
};
|
||||||
|
|
|
||||||
|
|
@ -24,4 +24,6 @@ struct pressure {
|
||||||
uint16_t p;
|
uint16_t p;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#define N_TESTDATA (96/sizeof(union bate))
|
||||||
void bate_calib(const union bate *bate, struct pressure *pt);
|
void bate_calib(const union bate *bate, struct pressure *pt);
|
||||||
|
extern const union bate testdata[N_TESTDATA];
|
||||||
|
|
|
||||||
38
src/eeprom.h
38
src/eeprom.h
|
|
@ -1,36 +1,4 @@
|
||||||
|
|
||||||
#include <stdint.h>
|
#define EEPROM(a) __attribute__((__section__(".eeprom")))
|
||||||
#include <avr/io.h>
|
#define ADC_CONF_ADDR EEPROM(0x1400)
|
||||||
#include <avr/eeprom.h>
|
#define TESTDATA_ADDR EEPROM(0x1420)
|
||||||
|
|
||||||
// Entirely unsafe EEPROM access. Just wait 5ms between calls
|
|
||||||
// int = byte
|
|
||||||
|
|
||||||
static inline
|
|
||||||
void unsafe_eeprom_write_byte(uint8_t *addr, uint8_t data)
|
|
||||||
{
|
|
||||||
EEARL = (uint8_t)(uint16_t)addr;
|
|
||||||
EEDR = data;
|
|
||||||
EECR |= (1<<EEMPE);
|
|
||||||
EECR |= (1<<EEPE);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline
|
|
||||||
uint8_t unsafe_eeprom_read_byte(uint8_t *addr)
|
|
||||||
{
|
|
||||||
EEARL = (uint8_t)(uint16_t)addr;
|
|
||||||
EECR |= (1<<EERE);
|
|
||||||
return EEDR;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline
|
|
||||||
void unsafe_eeprom_read_block(void *dest, void *src, uint8_t size)
|
|
||||||
{
|
|
||||||
uint8_t *d = dest;
|
|
||||||
uint8_t a = (uint8_t)(uint16_t)src;
|
|
||||||
while (size--) {
|
|
||||||
EEARL = a++;
|
|
||||||
EECR |= (1<<EERE);
|
|
||||||
*(d++) = EEDR;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
17
src/eeprom.ld
Normal file
17
src/eeprom.ld
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
/*
|
||||||
|
// place section .eemap into the eeprom
|
||||||
|
// The symbols resolve to the direct map in data space.
|
||||||
|
*/
|
||||||
|
MEMORY
|
||||||
|
{
|
||||||
|
eemap : ORIGIN = 0x1400, LENGTH = 0x80
|
||||||
|
eedef : ORIGIN = 0x810000, LENGTH = 0x80
|
||||||
|
}
|
||||||
|
SECTIONS
|
||||||
|
{
|
||||||
|
.eemap 0x1400:
|
||||||
|
{
|
||||||
|
*(.eeprom)
|
||||||
|
} >eemap AT >eedef
|
||||||
|
}
|
||||||
|
INSERT BEFORE .eeprom
|
||||||
|
|
@ -12,8 +12,8 @@
|
||||||
|
|
||||||
#define Bit(x) (1<<(x))
|
#define Bit(x) (1<<(x))
|
||||||
|
|
||||||
uint32_t clock;
|
volatile uint32_t clock;
|
||||||
uint8_t clock_tick;
|
volatile uint8_t clock_tick;
|
||||||
|
|
||||||
void init_rtc(uint8_t p)
|
void init_rtc(uint8_t p)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,6 @@
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
extern uint32_t clock;
|
volatile extern uint32_t clock;
|
||||||
extern uint8_t clock_tick;
|
volatile extern uint8_t clock_tick;
|
||||||
void init_rtc(uint8_t p);
|
void init_rtc(uint8_t p);
|
||||||
|
|
|
||||||
12
src/uart.c
12
src/uart.c
|
|
@ -28,7 +28,7 @@ void init_uart(uint16_t div)
|
||||||
PORTB.PIN3CTRL = PORT_PULLUPEN_bm | PORT_ISC_BOTHEDGES_gc;
|
PORTB.PIN3CTRL = PORT_PULLUPEN_bm | PORT_ISC_BOTHEDGES_gc;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t rx_tick;
|
volatile uint8_t rx_tick;
|
||||||
|
|
||||||
ISR(PORTB_PORT_vect, ISR_NAKED)
|
ISR(PORTB_PORT_vect, ISR_NAKED)
|
||||||
{
|
{
|
||||||
|
|
@ -54,8 +54,8 @@ uint8_t uart_tick()
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t uart_tx[128];
|
uint8_t uart_tx[128];
|
||||||
uint8_t uart_tx_w;
|
volatile uint8_t uart_tx_w;
|
||||||
uint8_t uart_tx_r;
|
volatile uint8_t uart_tx_r;
|
||||||
static const uint8_t uart_tx_m = sizeof(uart_tx) - 1;
|
static const uint8_t uart_tx_m = sizeof(uart_tx) - 1;
|
||||||
|
|
||||||
static inline void tx()
|
static inline void tx()
|
||||||
|
|
@ -121,10 +121,10 @@ void send_char(uint8_t c)
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t uart_rx[16];
|
uint8_t uart_rx[16];
|
||||||
static uint8_t uart_rx_w;
|
volatile uint8_t uart_rx_w;
|
||||||
uint8_t uart_rx_n;
|
volatile uint8_t uart_rx_n;
|
||||||
static const uint8_t uart_rx_m = sizeof(uart_rx) - 1;
|
static const uint8_t uart_rx_m = sizeof(uart_rx) - 1;
|
||||||
uint8_t uart_rx_mes;
|
volatile uint8_t uart_rx_mes;
|
||||||
|
|
||||||
ISR(USART0_RXC_vect)
|
ISR(USART0_RXC_vect)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -12,12 +12,12 @@ uint8_t uart_busy();
|
||||||
void send_char(uint8_t c);
|
void send_char(uint8_t c);
|
||||||
uint8_t send_char_nosleep(uint8_t c);
|
uint8_t send_char_nosleep(uint8_t c);
|
||||||
extern uint8_t uart_tx[];
|
extern uint8_t uart_tx[];
|
||||||
extern uint8_t uart_tx_w;
|
extern volatile uint8_t uart_tx_w;
|
||||||
extern uint8_t uart_tx_r;
|
extern volatile uint8_t uart_tx_r;
|
||||||
|
|
||||||
extern uint8_t uart_rx[];
|
extern uint8_t uart_rx[];
|
||||||
extern uint8_t uart_rx_n;
|
extern volatile uint8_t uart_rx_n;
|
||||||
extern uint8_t uart_rx_mes;
|
extern volatile uint8_t uart_rx_mes;
|
||||||
void rx_dismiss(uint8_t n);
|
void rx_dismiss(uint8_t n);
|
||||||
|
|
||||||
static inline
|
static inline
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue