Compare commits
No commits in common. "bf69d871f451180b905a99dcaf2897370944222c" and "b53d1914cfd4117584694dec1324c8a8278690cb" have entirely different histories.
bf69d871f4
...
b53d1914cf
6 changed files with 57 additions and 115 deletions
4
Makefile
4
Makefile
|
|
@ -59,8 +59,8 @@ lfuse_sologse=0xA0
|
|||
|
||||
lfuse_chaos=0xef
|
||||
chaos_CFLAGS = -I.
|
||||
chaos.o: ads8688.h ltc1655.h spi_slave.h tick.h hvosc.h hvled.h
|
||||
chaos.s: ads8688.h ltc1655.h spi_slave.h tick.h hvosc.h hvled.h
|
||||
chaos.o: ads8688.h ltc1655.h spi_slave.h tick.h hvosc.h
|
||||
chaos.s: ads8688.h ltc1655.h spi_slave.h tick.h hvosc.h
|
||||
|
||||
%.lfuse:
|
||||
$(AVRDUDE) -p $(pMCU-$(MCU)) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) \
|
||||
|
|
|
|||
|
|
@ -2,11 +2,11 @@
|
|||
#define ADC_SDI 4
|
||||
#define ADC_SCK 5
|
||||
#define ADC_CE 7
|
||||
#define ADC_SDO 1
|
||||
#define ADC_SDO 2
|
||||
#define ADC_PO PORTD
|
||||
#define ADC_PI PORTD
|
||||
#define ADC_PO_IO _SFR_IO_ADDR(ADC_PO)
|
||||
#define ADC_PI_IO _SFR_IO_ADDR(ADC_PI)
|
||||
#define ADC_PI PORTB
|
||||
#define PORTB_IO 0x05
|
||||
#define PORTD_IO 0x0b
|
||||
static inline void ads8688_init()
|
||||
{
|
||||
DDRD |= 0xb0;
|
||||
|
|
@ -26,7 +26,7 @@ static inline void ads8688_write(unsigned char c, unsigned char i)
|
|||
"nop" "\n\t"
|
||||
"cbi %[p], %[ck]" "\n"
|
||||
:
|
||||
:[p] "n" (ADC_PO_IO),
|
||||
:[p] "n" (PORTD_IO),
|
||||
[d] "n" (ADC_SDI),
|
||||
[ck] "n" (ADC_SCK),
|
||||
[c] "r" (c),
|
||||
|
|
@ -34,6 +34,12 @@ static inline void ads8688_write(unsigned char c, unsigned char i)
|
|||
}
|
||||
static inline void ads8688_read(unsigned char *r, unsigned char *rr, unsigned char i)
|
||||
{
|
||||
#if 0
|
||||
ADC_PO |= (1<<ADC_SCK);
|
||||
if (ADC_PI & (1<<ADC_SDO)) *r |= 1<<i;
|
||||
if (!(ADC_PI & (1<<ADC_SDO))) *r &=~(1<<i);
|
||||
ADC_PO &=~ (1<<ADC_SCK);
|
||||
#else
|
||||
// qq is a dummy requested here to avoid load/store between bytes.
|
||||
|
||||
__asm__("sbi %[pk], %[ck]" "\n\t"
|
||||
|
|
@ -49,13 +55,14 @@ static inline void ads8688_read(unsigned char *r, unsigned char *rr, unsigned ch
|
|||
"nop" "\n"
|
||||
:[q] "+d" (*r), // ORI needs r16..r31
|
||||
[qq] "+d" (*rr)
|
||||
:[pk] "n" (ADC_PO_IO),
|
||||
[pd] "n" (ADC_PI_IO),
|
||||
:[pk] "n" (PORTD_IO),
|
||||
[pd] "n" (PORTB_IO),
|
||||
[d] "n" (ADC_SDO),
|
||||
[ck] "n" (ADC_SCK),
|
||||
[i] "n" (1<<i),
|
||||
[ii] "n" (0xff&~(1<<i))
|
||||
);
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline void ads8688_frame(const unsigned char *c, unsigned char *r)
|
||||
|
|
@ -85,7 +92,7 @@ static inline void ads8688_frame(const unsigned char *c, unsigned char *r)
|
|||
__asm__("nop" "\n\t"
|
||||
"cbi %[p], %[d]" "\n"
|
||||
:
|
||||
:[p] "n" (ADC_PO_IO),
|
||||
:[p] "n" (PORTD_IO),
|
||||
[d] "n" (ADC_SDI)
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -2,8 +2,6 @@
|
|||
|
||||
// ATmega32M1
|
||||
|
||||
#define upcase(c) (!((c)&0x20))
|
||||
|
||||
const char *revision =
|
||||
|
||||
"$Id$";
|
||||
|
|
@ -20,7 +18,6 @@ void ads8688_cmd(const unsigned char *c, unsigned char *r);
|
|||
void ltc1655_cmd(const unsigned char *c);
|
||||
void ads8688_config();
|
||||
|
||||
#include "hvled.h"
|
||||
#include "tick.h"
|
||||
#include "hvosc.h"
|
||||
|
||||
|
|
@ -49,7 +46,7 @@ static inline unsigned int avradc_data()
|
|||
{
|
||||
unsigned int r = ADCL;
|
||||
r |= ADCH << 8;
|
||||
r |= ADMUX << 11;
|
||||
r |= ADMUX << 13;
|
||||
return r;
|
||||
}
|
||||
|
||||
|
|
@ -108,8 +105,7 @@ struct {
|
|||
unsigned char portc_on;
|
||||
unsigned char portc_off;
|
||||
unsigned char hvosc_freq;
|
||||
unsigned char hvosc_dc;
|
||||
unsigned char padding[2];
|
||||
unsigned char padding[1];
|
||||
} conf = {
|
||||
.wdt_timeout = 10, // 2 min
|
||||
.wdt_tick_period = TICK_NS(100000L), // 100µs
|
||||
|
|
@ -117,8 +113,7 @@ struct {
|
|||
.avradc = 0x7f, // off
|
||||
.adcconf = 0x8500,// RST
|
||||
.ddrc = 2, // OC1B HVOSC
|
||||
.hvosc_freq = 51,
|
||||
.hvosc_dc = 9,
|
||||
.hvosc_freq = 88, // 125 kHz
|
||||
};
|
||||
|
||||
enum {
|
||||
|
|
@ -132,7 +127,6 @@ enum {
|
|||
FLAG2_PORTC = 1,
|
||||
FLAG2_PC_HV = 2,
|
||||
FLAG2_HVOSC = 4,
|
||||
FLAG2_HVLED = 8,
|
||||
};
|
||||
|
||||
void conf_init()
|
||||
|
|
@ -140,23 +134,19 @@ void conf_init()
|
|||
tick_init(conf.tick_period);
|
||||
if (conf.flags & FLAG_WDT)
|
||||
wdt_init(conf.wdt_mode);
|
||||
if (conf.flags2 & FLAG2_HVOSC) {
|
||||
conf.ddrc |= 2;
|
||||
hvosc_init(conf.hvosc_freq, conf.hvosc_dc);
|
||||
}
|
||||
if (conf.flags & FLAG_ADCCONF)
|
||||
ads8688_config();
|
||||
if (conf.flags & FLAG_DACADC)
|
||||
conf.dac = dacadc_read();
|
||||
if (conf.flags & FLAG_RAMP)
|
||||
dac_ramp(conf.dac_nominal);
|
||||
if (conf.flags & FLAG_ADC)
|
||||
avradc_enable(conf.avradc);
|
||||
if (conf.flags & FLAG_DAC)
|
||||
avrdac_set(conf.avrdac);
|
||||
if (conf.flags2 & FLAG2_HVLED) {
|
||||
conf.ddrc |= LED_MASK;
|
||||
led_init();
|
||||
if (conf.flags & FLAG_ADCCONF)
|
||||
ads8688_config();
|
||||
if (conf.flags & FLAG_DACADC)
|
||||
conf.dac = dacadc_read();
|
||||
if (conf.flags2 & FLAG2_HVOSC) {
|
||||
conf.ddrc |= 2;
|
||||
hvosc_init(conf.hvosc_freq);
|
||||
}
|
||||
if (conf.flags2 & FLAG2_PORTC) {
|
||||
PORTC = conf.portc;
|
||||
|
|
@ -164,16 +154,6 @@ void conf_init()
|
|||
}
|
||||
}
|
||||
|
||||
static inline void led_hv()
|
||||
{
|
||||
if (conf.flags2 & FLAG2_HVLED) {
|
||||
if (conf.dac == conf.dac_off)
|
||||
led_toggle(LED_GREEN);
|
||||
else
|
||||
led_toggle(LED_RED);
|
||||
}
|
||||
}
|
||||
|
||||
unsigned long adc_sum[8];
|
||||
unsigned int adc_noise[8];
|
||||
unsigned char adc_n[8];
|
||||
|
|
@ -201,7 +181,6 @@ int main()
|
|||
spi_slave_Rx(cmd, 3);
|
||||
resp[0] = cmd[0];
|
||||
sreg = disable_irq();
|
||||
led_hv();
|
||||
if (conf.wdt_mode == WDT_MODE_LIVE)
|
||||
wdt_kick();
|
||||
switch (cmd[0]) {
|
||||
|
|
@ -235,7 +214,7 @@ int main()
|
|||
if (conf.flags2 & FLAG2_PC_HV)
|
||||
PORTC = conf.portc_on;
|
||||
if (conf.flags2 & FLAG2_HVOSC)
|
||||
hvosc_init(conf.hvosc_freq, conf.hvosc_dc);
|
||||
hvosc_init(conf.hvosc_freq);
|
||||
int2frame(conf.dac, resp+1);
|
||||
if (conf.wdt_mode >= WDT_MODE_HV)
|
||||
wdt_kick();
|
||||
|
|
@ -244,14 +223,10 @@ int main()
|
|||
dac_ramp(conf.dac_nominal);
|
||||
continue;
|
||||
case 'Q':
|
||||
conf.hvosc_freq = frame2int(cmd+1);
|
||||
case 'q':
|
||||
resp[1] = conf.hvosc_freq;
|
||||
resp[2] = conf.hvosc_dc;
|
||||
if (upcase(cmd[0])) {
|
||||
conf.hvosc_freq = cmd[1];
|
||||
conf.hvosc_dc = cmd[2];
|
||||
}
|
||||
hvosc_init(conf.hvosc_freq, conf.hvosc_dc);
|
||||
int2frame(conf.hvosc_freq, resp+1);
|
||||
hvosc_init(conf.hvosc_freq);
|
||||
break;
|
||||
case 'I':
|
||||
int2frame(tick_freq(), resp+1);
|
||||
|
|
@ -266,17 +241,20 @@ int main()
|
|||
ads8688_cmd(cmd+1, resp+1);
|
||||
break;
|
||||
case 'T':
|
||||
resp[1] = adc_status;
|
||||
resp[2] = adc_error;
|
||||
enable_irq(sreg);
|
||||
spi_slave_Tx(resp, 3);
|
||||
if (cmd[1])
|
||||
adc_read(cmd[1], cmd[2]);
|
||||
continue;
|
||||
case 't':
|
||||
resp[1] = adc_status;
|
||||
resp[2] = adc_error;
|
||||
enable_irq(sreg);
|
||||
spi_slave_Tx(resp, 3);
|
||||
if (cmd[1]) {
|
||||
if (upcase(cmd[0]))
|
||||
adc_read(cmd[1], cmd[2]);
|
||||
else
|
||||
if (cmd[1])
|
||||
adc_dac = dacadc_read();
|
||||
}
|
||||
continue;
|
||||
case 'R':
|
||||
c = cmd[1] & 7;
|
||||
|
|
@ -340,12 +318,8 @@ int main()
|
|||
resp[2] = conf.padding[0];
|
||||
break;
|
||||
}
|
||||
if (cmd[2]==1) {
|
||||
enable_irq(sreg);
|
||||
spi_slave_Tx(resp, 3);
|
||||
if (cmd[2]==1)
|
||||
conf_init();
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
case 'B':
|
||||
c = cmd[1] & 0x7f;
|
||||
|
|
@ -375,9 +349,7 @@ int main()
|
|||
PORTC = conf.portc = cmd[2];
|
||||
break;
|
||||
case 'O':
|
||||
case 'o':
|
||||
resp[2] = DDRC;
|
||||
if (upcase(cmd[1]))
|
||||
DDRC = conf.ddrc = cmd[2];
|
||||
break;
|
||||
case 'A':
|
||||
|
|
@ -402,12 +374,9 @@ int main()
|
|||
break;
|
||||
}
|
||||
break;
|
||||
case 'Y': // peek
|
||||
case 'y': // poke
|
||||
case 'Y':
|
||||
resp[1] = cmd[1];
|
||||
resp[2] = *(unsigned char *)(cmd[1]+0);
|
||||
if (!upcase(cmd[0]))
|
||||
*(unsigned char *)(cmd[1]+0) = cmd[2];
|
||||
break;
|
||||
}
|
||||
enable_irq(sreg);
|
||||
|
|
@ -528,7 +497,7 @@ ISR(WDT_vect)
|
|||
if (conf.flags2 & FLAG2_PC_HV)
|
||||
PORTC = conf.portc_off;
|
||||
if (conf.flags2 & FLAG2_HVOSC)
|
||||
hvosc_init(0, 0);
|
||||
hvosc_init(0);
|
||||
}
|
||||
tick_init(conf.tick_period);
|
||||
if (conf.wdt_save_addr && !wdt_saved) {
|
||||
|
|
|
|||
|
|
@ -1,33 +0,0 @@
|
|||
#include "avr/io.h"
|
||||
#define LED1 2
|
||||
#define LED2 3
|
||||
#define LED_PORT PORTC
|
||||
#define LED_GREEN (1<<LED1)
|
||||
#define LED_RED (1<<LED2)
|
||||
#define LED_MASK (LED_GREEN | LED_RED)
|
||||
|
||||
static inline void led_init()
|
||||
{
|
||||
DDRC |= LED_MASK;
|
||||
}
|
||||
|
||||
static uint8_t led_status()
|
||||
{
|
||||
return LED_PORT & LED_MASK;
|
||||
}
|
||||
static inline void led_off()
|
||||
{
|
||||
LED_PORT &=~ LED_MASK;
|
||||
}
|
||||
static inline void led_on(uint8_t color)
|
||||
{
|
||||
LED_PORT &= ~(LED_MASK & ~color);
|
||||
LED_PORT |= color;
|
||||
}
|
||||
static inline void led_toggle(uint8_t color)
|
||||
{
|
||||
if (led_status() == color)
|
||||
LED_PORT &=~ color;
|
||||
else
|
||||
led_on(color);
|
||||
}
|
||||
|
|
@ -1,20 +1,19 @@
|
|||
#include "avr/io.h"
|
||||
|
||||
static inline void hvosc_init(unsigned char freq, unsigned char dc)
|
||||
static inline void hvosc_init(unsigned char freq)
|
||||
{
|
||||
if (!dc || freq <= dc) {
|
||||
if (!freq) {
|
||||
TCCR1A = 0;
|
||||
return;
|
||||
}
|
||||
PRR &=~ (1<<PRTIM1);
|
||||
DDRC |= (1<<PC1);
|
||||
DDRD |= (1<<PD2);
|
||||
__asm__("NOP");
|
||||
TCCR1A = (2<<COM1A0) | (3<<COM1B0) | (2<<WGM10);
|
||||
TCCR1B = (1<<CS10) | (2<<WGM12);
|
||||
TCCR1B = (1<<CS10) | (3<<WGM12);
|
||||
ICR1H = 0;
|
||||
ICR1L = freq;
|
||||
OCR1AH = 0;
|
||||
OCR1AL = dc;
|
||||
OCR1AL = freq>>1;
|
||||
OCR1BH = 0;
|
||||
OCR1BL = freq-dc;
|
||||
OCR1BL = freq>>1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@
|
|||
#define DAC_SDI 4
|
||||
#define DAC_SCK 5
|
||||
#define DAC_CE 6
|
||||
#define DAC_PORT PORTD
|
||||
#define DAC_PORT_IO _SFR_IO_ADDR(DAC_PORT)
|
||||
#define DAC_PO PORTD
|
||||
#define PORTD_IO 0x0b
|
||||
|
||||
static inline void ltc1655_init()
|
||||
{
|
||||
|
|
@ -24,7 +24,7 @@ static inline void ltc1655_bit(unsigned char c, unsigned char i)
|
|||
"nop" "\n\t"
|
||||
"sbi %[p], %[k]" "\n"
|
||||
::
|
||||
[p] "n" (DAC_PORT_IO),
|
||||
[p] "n" (PORTD_IO),
|
||||
[d] "n" (DAC_SDI),
|
||||
[k] "n" (DAC_SCK),
|
||||
[c] "r" (c),
|
||||
|
|
@ -33,8 +33,8 @@ static inline void ltc1655_bit(unsigned char c, unsigned char i)
|
|||
|
||||
static inline void ltc1655_frame(const unsigned char *c)
|
||||
{
|
||||
DAC_PORT &=~ (1<<DAC_SCK);
|
||||
DAC_PORT &=~ (1<<DAC_CE);
|
||||
DAC_PO &=~ (1<<DAC_SCK);
|
||||
DAC_PO &=~ (1<<DAC_CE);
|
||||
ltc1655_bit(c[1],7);
|
||||
ltc1655_bit(c[1],6);
|
||||
ltc1655_bit(c[1],5);
|
||||
|
|
@ -58,6 +58,6 @@ static inline void ltc1655_frame(const unsigned char *c)
|
|||
"nop" "\n\t"
|
||||
"nop" "\n"
|
||||
);
|
||||
DAC_PORT &=~ (1<<DAC_SCK);
|
||||
DAC_PORT |= (1<<DAC_CE);
|
||||
DAC_PO &=~ (1<<DAC_SCK);
|
||||
DAC_PO |= (1<<DAC_CE);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue