Compare commits

..

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

12 changed files with 80 additions and 64 deletions

View file

@ -8,7 +8,7 @@ all: $(PROJ).hex
SN_bate = 1
MCU_bate = attiny424
C_FILES_bate = uart.c rtc.c spi.c adc.c calib.c mul.c
C_FILES_bate = uart.c rtc.c calib.c mul.c adc.c spi.c
BATE_PERIOD=76
bate_CFLAGS = -DPERIOD=$(BATE_PERIOD)
@ -39,7 +39,7 @@ OBJS = $(patsubst %.c, %.o, $(C_FILES))
-include *.d
LDFLAGS = -Teeprom.ld
LDFLAGS =
%.elf: %.o $(OBJS)
$(CC) $(CFLAGS) -Wl,-Map=$*.map,--cref $^ --output $@ $(LDFLAGS)
@ -47,12 +47,10 @@ LDFLAGS = -Teeprom.ld
OBJCOPY = avr-objcopy
%.hex: %.elf
$(OBJCOPY) -O ihex -R .eeprom -R .eemap $< $@
%.eeprom: %.elf
$(OBJCOPY) -O ihex -j .eemap --change-section-lma .eemap=0 $< $@
$(OBJCOPY) -O ihex -R .eeprom $< $@
pMCU-attiny414 = t414
pMCU-attiny424 = t424
#
@ -111,10 +109,9 @@ ad: $(PROJ).ad
%.burn: %.hex
$(AD) -U flash:w:$<
%.verify: %.hex %.eeprom
%.verify: %.hex
-$(AD) -qq -U fuses:v:"$(fuses_$*)":m
-$(AD) -qq -U userrow:v:"$(BATE_CONFIG)":m
-$(AD) -qq -U eeprom:v:$(word 2, $^)
-$(AD) -qq -U flash:v:$<
fuse: $(PROJ).fuse$F
@ -152,9 +149,14 @@ clean:
.PHONY: eeprom.eeprom
eeprom.eeprom:
$(AD) -U eeprom:r:$@
$(AVRDUDE) -p $(pMCU-$(MCU)) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) \
-U eeprom:r:$@:r
%.eeprom.burn: %.eeprom
$(AD) -U eeprom:v:$< || $(AD) -U eeprom:w:$<
$(AVRDUDE) -p $(pMCU-$(MCU)) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) \
-U 'eeprom:v:$<:r' \
|| $(AVRDUDE) -p $(pMCU-$(MCU)) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) \
-U 'eeprom:w:$<:r'
calib: calib.c mul.c
gcc -DCALIB_DEBUG -o $@ $<

View file

@ -4,7 +4,6 @@
#include "adc.h"
#include "bate.h"
#include "eeprom.h"
#include <avr/interrupt.h>
enum adc_conf_parameter {
@ -18,7 +17,7 @@ enum adc_conf_parameter {
V_BAT = ADC_MUXPOS_AIN7_gc,
};
struct adc_conf adc_conf[N_ADC] ADC_CONF_ADDR = {
struct adc_conf adc_conf[N_ADC] = {
{ // Internal Temperature
.mode = MODE,
.ref = REF | ADC_REFSEL_1024MV_gc,

View file

@ -5,6 +5,8 @@
#include <avr/io.h>
#define ADC ADC0
#define N_ADC 6
struct adc_conf {
uint8_t mode;
uint8_t ref;
@ -12,8 +14,6 @@ struct adc_conf {
uint8_t inn;
};
#define N_ADC (32/sizeof(struct adc_conf))
extern uint16_t adc_readings[N_ADC];
extern uint8_t adc_current;

View file

@ -419,8 +419,13 @@ int main()
}
uint8_t test_calib = config.calib_test;
if (test_calib > N_TESTDATA)
test_calib = N_TESTDATA;
static const union bate testdata[4] = {
{ .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
};
uint8_t trigger = TRIGGER_CONT | TRIGGER_ONCE;
uint8_t mclk_delay = 0;
uint8_t trigger_clock = 0;
@ -507,7 +512,7 @@ int main()
const union bate *b = &bate;
if (test_calib)
b = testdata + --test_calib;
b = testdata + (--test_calib & 3);
if (config.send & SEND_HEX)
send_hex('B', b->b, sizeof(union bate), 3);
if (config.send & SEND_CALIB) {

View file

@ -7,9 +7,6 @@
#ifdef CALIB_DEBUG
# include <stdio.h>
# define TESTDATA_ADDR
#else
# include "eeprom.h"
#endif
#include "calib.h"
@ -77,6 +74,14 @@ void bate_calib(const union bate *bate, struct pressure *pt)
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
#include "mul.c"
@ -88,11 +93,3 @@ int main()
return 0;
#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
};

View file

@ -24,6 +24,4 @@ struct pressure {
uint16_t p;
};
#define N_TESTDATA (96/sizeof(union bate))
void bate_calib(const union bate *bate, struct pressure *pt);
extern const union bate testdata[N_TESTDATA];

View file

@ -1,4 +1,36 @@
#define EEPROM(a) __attribute__((__section__(".eeprom")))
#define ADC_CONF_ADDR EEPROM(0x1400)
#define TESTDATA_ADDR EEPROM(0x1420)
#include <stdint.h>
#include <avr/io.h>
#include <avr/eeprom.h>
// 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;
}
}

View file

@ -1,17 +0,0 @@
/*
// 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

View file

@ -12,8 +12,8 @@
#define Bit(x) (1<<(x))
volatile uint32_t clock;
volatile uint8_t clock_tick;
uint32_t clock;
uint8_t clock_tick;
void init_rtc(uint8_t p)
{

View file

@ -4,6 +4,6 @@
#include <stdint.h>
volatile extern uint32_t clock;
volatile extern uint8_t clock_tick;
extern uint32_t clock;
extern uint8_t clock_tick;
void init_rtc(uint8_t p);

View file

@ -28,7 +28,7 @@ void init_uart(uint16_t div)
PORTB.PIN3CTRL = PORT_PULLUPEN_bm | PORT_ISC_BOTHEDGES_gc;
}
volatile uint8_t rx_tick;
uint8_t rx_tick;
ISR(PORTB_PORT_vect, ISR_NAKED)
{
@ -54,8 +54,8 @@ uint8_t uart_tick()
}
uint8_t uart_tx[128];
volatile uint8_t uart_tx_w;
volatile uint8_t uart_tx_r;
uint8_t uart_tx_w;
uint8_t uart_tx_r;
static const uint8_t uart_tx_m = sizeof(uart_tx) - 1;
static inline void tx()
@ -121,10 +121,10 @@ void send_char(uint8_t c)
}
uint8_t uart_rx[16];
volatile uint8_t uart_rx_w;
volatile uint8_t uart_rx_n;
static uint8_t uart_rx_w;
uint8_t uart_rx_n;
static const uint8_t uart_rx_m = sizeof(uart_rx) - 1;
volatile uint8_t uart_rx_mes;
uint8_t uart_rx_mes;
ISR(USART0_RXC_vect)
{

View file

@ -12,12 +12,12 @@ uint8_t uart_busy();
void send_char(uint8_t c);
uint8_t send_char_nosleep(uint8_t c);
extern uint8_t uart_tx[];
extern volatile uint8_t uart_tx_w;
extern volatile uint8_t uart_tx_r;
extern uint8_t uart_tx_w;
extern uint8_t uart_tx_r;
extern uint8_t uart_rx[];
extern volatile uint8_t uart_rx_n;
extern volatile uint8_t uart_rx_mes;
extern uint8_t uart_rx_n;
extern uint8_t uart_rx_mes;
void rx_dismiss(uint8_t n);
static inline