summaryrefslogtreecommitdiff
path: root/software
diff options
context:
space:
mode:
authorBernhard Tittelbach <xro@realraum.at>2012-05-17 06:14:29 +0000
committerBernhard Tittelbach <xro@realraum.at>2012-05-17 06:14:29 +0000
commit3ce320b1618b5c1a2232a6887c5fef780872171c (patch)
treee43bc1a76ea617225cd26c026696578aa7440b8b /software
parentspi and c1101 code shuffling (diff)
debugging test attempts
git-svn-id: https://svn.spreadspace.org/mur.sat@418 7de4ea59-55d0-425e-a1af-a3118ea81d4c
Diffstat (limited to 'software')
-rw-r--r--software/hhd70dongle/Makefile64
-rw-r--r--software/hhd70dongle/c1101lib.c43
-rw-r--r--software/hhd70dongle/c1101lib.h30
-rw-r--r--software/hhd70dongle/hhd70dongle.c201
-rw-r--r--software/hhd70dongle/pcusbhid/Makefile7
-rw-r--r--software/hhd70dongle/pcusbhid/rawhid_testinterface.c9
-rw-r--r--software/hhd70dongle/pcusbhid/reset.c22
-rw-r--r--software/hhd70dongle/spi.c1
-rw-r--r--software/hhd70dongle/util.c96
-rw-r--r--software/hhd70dongle/util.h41
10 files changed, 353 insertions, 161 deletions
diff --git a/software/hhd70dongle/Makefile b/software/hhd70dongle/Makefile
index 80c92b8..c12e4c6 100644
--- a/software/hhd70dongle/Makefile
+++ b/software/hhd70dongle/Makefile
@@ -1,28 +1,36 @@
-##
-## spreadspace teensy utils
-##
-##
-## Copyright (C) 2011 Christian Pointner <equinox@spreadspace.org>
-##
-## This file is part of spreadspace teensy utils.
-##
-## spreadspace teensy utils is free software: you can redistribute it and/or modify
-## it under the terms of the GNU General Public License as published by
-## the Free Software Foundation, either version 3 of the License, or
-## any later version.
-##
-## spreadspace teensy utils is distributed in the hope that it will be useful,
-## but WITHOUT ANY WARRANTY; without even the implied warranty of
-## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-## GNU General Public License for more details.
-##
-## You should have received a copy of the GNU General Public License
-## along with spreadspace teensy utils. If not, see <http://www.gnu.org/licenses/>.
-##
-
-NAME := hhd70dongle
-OBJ := hhd70dongle.o led.o spi.o usb_rawhid.o c1101lib.o
-BOARD_TYPE := teensy2
-
-include ../teensy.include.mk
-CFLAGS += -std=gnu99
+##
+## spreadspace teensy utils
+##
+##
+## Copyright (C) 2011 Christian Pointner <equinox@spreadspace.org>
+##
+## This file is part of spreadspace teensy utils.
+##
+## spreadspace teensy utils is free software: you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation, either version 3 of the License, or
+## any later version.
+##
+## spreadspace teensy utils is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with spreadspace teensy utils. If not, see <http://www.gnu.org/licenses/>.
+##
+
+NAME := hhd70dongle
+OBJ := hhd70dongle.o led.o spi.o usb_rawhid.o c1101lib.o util.o
+BOARD_TYPE := teensy2
+
+include ../teensy.include.mk
+CFLAGS += -std=gnu99
+
+DFU_PRO_TARGET := atmega32u4
+
+.phony: flash
+flash: $(NAME).hex
+ sudo dfu-programmer $(DFU_PRO_TARGET) erase
+ sudo dfu-programmer $(DFU_PRO_TARGET) flash $<
+ sudo dfu-programmer $(DFU_PRO_TARGET) start
diff --git a/software/hhd70dongle/c1101lib.c b/software/hhd70dongle/c1101lib.c
index 26d5fb9..8f9f5a7 100644
--- a/software/hhd70dongle/c1101lib.c
+++ b/software/hhd70dongle/c1101lib.c
@@ -29,25 +29,43 @@
* along with mur.sat. If not, see <http://www.gnu.org/licenses/>.
*
*/
-#include "avr/io.h"
-#include "util/delay.h"
+#include <avr/io.h>
+#include <util/delay.h>
#include "c1101lib.h"
#include "spi.h"
-//#include "usb_rawhid.h"
+#include "usb_rawhid.h"
+#include "util.h"
/**** Helper Functions ****/
+#define SPIC1101_MAX_WAIT 1024
+unsigned int attempts = 0;
char spi_c1101_exchange(char *data, int len)
{
+ char sb;
+ uint8_t debug_sb[6];
char rbyte;
spi_cs_enable();
- while (len--)
+ attempts = 0;
+ while (len-- > 0)
{
- while ( ! (SPIC1101_SB_CHIPRDY(spi_read_byte())));
+ //~ while ( ! (SPIC1101_SB_CHIPRDY(spi_read_byte())));
spi_write_byte(*(data++));
+ usb_rawhid_send((uint8_t*)"spi byte written",255);
+ do
+ {
+ usb_rawhid_send((uint8_t*)"wait chipready",255);
+ sb = spi_read_byte();
+ debug_sprint_int16hex(debug_sb, sb);
+ usb_rawhid_send(debug_sb,255);
+ if (attempts++ > SPIC1101_MAX_WAIT)
+ return -1;
+ } while ( ! (SPIC1101_SB_CHIPRDY(sb)));
+ usb_rawhid_send((uint8_t*)"spi chipready",255);
}
rbyte = spi_read_byte();
+ usb_rawhid_send((uint8_t*)"spi byte read",255);
spi_cs_disable();
return rbyte;
}
@@ -133,8 +151,19 @@ int spi_c1101_write_txfifo(char *buffer, int len)
/**** External Functions ****/
+char c1101_getVersion(void)
+{
+ return spi_c1101_read_register(SPIC1101_ADDR_VERSION);
+}
+
+char c1101_getPartNum(void)
+{
+ return spi_c1101_read_register(SPIC1101_ADDR_PARTNUM);
+}
+
+
//max len: 64 bytes
-void writeTXFifo(char *buffer, unsigned int len)
+void c1101_writeTXFifo(char *buffer, unsigned int len)
{
//check TXBYTES.NUM_TXBYTES
// never write more bytes than avaiblabe or doom ensues
@@ -143,7 +172,7 @@ void writeTXFifo(char *buffer, unsigned int len)
}
//max returned: 64 bytes
-int readRXFifo(char *buffer)
+int c1101_readRXFifo(char *buffer)
{
//check RXBYTES.NUM_RXBYTES
// never read more bytes than avaiblabe or we will read garbage
diff --git a/software/hhd70dongle/c1101lib.h b/software/hhd70dongle/c1101lib.h
index 7224a61..64cf876 100644
--- a/software/hhd70dongle/c1101lib.h
+++ b/software/hhd70dongle/c1101lib.h
@@ -114,31 +114,33 @@
#define SPIC1101_ADDR_RCCTRL1_STATUS (0x3C | 0xC0)
#define SPIC1101_ADDR_RCCTRL0_STATUS (0x3D | 0xC0)
-
#define SPIC1101_ADDR_FIFO_READ (0x3F | 0x80)
#define SPIC1101_ADDR_FIFO_READ_BURST (0x3F | 0x80 | 0xC0)
#define SPIC1101_ADDR_FIFO_WRITE 0x3F
#define SPIC1101_ADDR_FIFO_WRITE_BURST (0x3F | 0x40)
-#define SPIC1101_SB_CHIPRDY(x) x & 0b1000000
-#define SPIC1101_SB_IDLE(x) (x & 0b0111000) == 0b000000
-#define SPIC1101_SB_RXMODE(x) (x & 0b0111000) == 0b001000
-#define SPIC1101_SB_TXMODE(x) (x & 0b0111000) == 0b010000
-#define SPIC1101_SB_FSTXON(x) (x & 0b0111000) == 0b011000
-#define SPIC1101_SB_CALIBRATE(x) (x & 0b0111000) == 0b100000
-#define SPIC1101_SB_SETTLING(x) (x & 0b0111000) == 0b101000
-#define SPIC1101_SB_RXFIFO_OVERFLOW(x) (x & 0b0111000b) == 0b110000
-#define SPIC1101_SB_TXFIFO_OVERFLOW(x) (x & 0b0111000b) == 0b111000
-#define SPIC1101_SB_FIFO_BYTES_AVAILABLE(x) (x & 0b0000111)
+#define SPIC1101_SB_CHIPRDY(x) x & 0b10000000
+#define SPIC1101_SB_IDLE(x) (x & 0b01110000) == 0
+#define SPIC1101_SB_RXMODE(x) (x & 0b01110000) == 0b0010000
+#define SPIC1101_SB_TXMODE(x) (x & 0b01110000) == 0b0100000
+#define SPIC1101_SB_FSTXON(x) (x & 0b01110000) == 0b0110000
+#define SPIC1101_SB_CALIBRATE(x) (x & 0b01110000) == 0b1000000
+#define SPIC1101_SB_SETTLING(x) (x & 0b01110000) == 0b1010000
+#define SPIC1101_SB_RXFIFO_OVERFLOW(x) (x & 0b01110000) == 0b1100000
+#define SPIC1101_SB_TXFIFO_OVERFLOW(x) (x & 0b01110000) == 0b1110000
+#define SPIC1101_SB_FIFO_BYTES_AVAILABLE(x) (x & 0b00001111)
+
+char c1101_getVersion(void);
+char c1101_getPartNum(void);
//max len: 64 bytes
-void writeTXFifo(char *buffer, unsigned int len);
+void c1101_writeTXFifo(char *buffer, unsigned int len);
//max returned: 64 bytes
-int readRXFifo(char *buffer);
+int c1101_readRXFifo(char *buffer);
//set WakeOnRadio to enabled (true) or disabled(false)
-void setWOR(int enable);
+void c1101_setWOR(int enable);
#endif
diff --git a/software/hhd70dongle/hhd70dongle.c b/software/hhd70dongle/hhd70dongle.c
index 7e11d45..3d7fa95 100644
--- a/software/hhd70dongle/hhd70dongle.c
+++ b/software/hhd70dongle/hhd70dongle.c
@@ -1,104 +1,97 @@
-/*
- *
- * mur.sat
- *
- * Somewhen in the year 2012, mur.at will have a nano satellite launched
- * into a low earth orbit (310 km above the surface of our planet). The
- * satellite itself is a TubeSat personal satellite kit, developed and
- * launched by interorbital systems. mur.sat is a joint venture of mur.at,
- * ESC im Labor and realraum.
- *
- * Please visit the project hompage at sat.mur.at for further information.
- *
- *
- * Copyright (C) 2012 Bernhard Tittelbach <xro@realraum.at>
- *
- * This file is part of mur.sat.
- *
- * mur.sat is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * any later version.
- *
- * mur.sat is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with mur.sat. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-#include "avr/io.h"
-#include "util/delay.h"
-
-#include "led.h"
-#include "spi.h"
-#include "usb_rawhid.h"
-
-#define ADCMUX_INTERNALTEMP 0b100111
-#define ADCMUX_ADC12 0b100100
-
-#define CPU_PRESCALE(n) (CLKPR = 0x80, CLKPR = (n))
-#define ADC_PRESCALER 0
-uint8_t read_buffer[64]; // buffer for reading usb signals
-uint8_t write_buffer[64]; // buffer for writing usb signals
-
-//TODOs:
-// * make as much use of sleep modes as possible
-// * use adc noise canceler (i.e. automatic sampling during cpu sleep)
-// * define and listen for an usb_hid reset command -> jump to bootload address
-// * read atmega temp
-// * safely save state in eeprom (2 memory regions, only use the one with the "written successfully bit" which is written last)
-
-
-int16_t adc_read(uint8_t mux)
-{
- uint8_t low;
- char aref = 0b11000000;
- ADCSRA = (1<<ADEN) | ADC_PRESCALER; // enable ADC
- ADCSRB = (1<<ADHSM) | (mux & 0x20); // high speed mode
- ADMUX = aref | (mux & 0x1F); // configure mux input
- ADCSRA = (1<<ADEN) | ADC_PRESCALER | (1<<ADSC); // start the conversion
- while (ADCSRA & (1<<ADSC)) ; // wait for result
- low = ADCL; // must read LSB first
- ADCSRA &= ~(1<<ADEN); // disable ADC
- return (ADCH << 8) | low; // must read MSB only once!
-}
-
-int main(void)
-{
- CPU_PRESCALE(0);
- led_init();
- spi_init();
- usb_init();
- // set PB5/ADC12 to INPUT (c1101 temp sensor)
- DDRB &= ~(1<<DDB5);
- while (!usb_configured()) /* wait */ ;
-
- //int8_t r = usb_rawhid_recv(read_buffer, 0);
- //usb_rawhid_send(write_buffer, 23);
-
- usb_rawhid_send("hhd70dongle ready",17);
-
- int16_t c1101_temp = adc_read(ADCMUX_ADC12);
- int16_t internal_temp = adc_read(ADCMUX_INTERNALTEMP);
-
- for(;;)
- {
- _delay_ms(250);
- led_toggle();
- c1101_temp = adc_read(ADCMUX_ADC12);
- internal_temp = adc_read(ADCMUX_INTERNALTEMP);
- usb_rawhid_send("temp c1101: ",12);
- write_buffer[0] = '0' + c1101_temp/26;
- write_buffer[1] = 0;
- usb_rawhid_send(write_buffer,1);
- usb_rawhid_send("temp atmega: ",13);
- write_buffer[0] = '0' + internal_temp/26;
- usb_rawhid_send(write_buffer,1);
- //~ char buf[10];
- //~ unsigned int len;
- //~ spi_read(sizeof(buf),buf,&len);
- }
-}
+/*
+ *
+ * mur.sat
+ *
+ * Somewhen in the year 2012, mur.at will have a nano satellite launched
+ * into a low earth orbit (310 km above the surface of our planet). The
+ * satellite itself is a TubeSat personal satellite kit, developed and
+ * launched by interorbital systems. mur.sat is a joint venture of mur.at,
+ * ESC im Labor and realraum.
+ *
+ * Please visit the project hompage at sat.mur.at for further information.
+ *
+ *
+ * Copyright (C) 2012 Bernhard Tittelbach <xro@realraum.at>
+ *
+ * This file is part of mur.sat.
+ *
+ * mur.sat is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * any later version.
+ *
+ * mur.sat is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with mur.sat. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+#include <avr/io.h>
+#include <util/delay.h>
+//#include <avr/stdio.h>
+
+#include "led.h"
+#include "util.h"
+#include "spi.h"
+#include "c1101lib.h"
+#include "usb_rawhid.h"
+
+#define ADCMUX_INTERNALTEMP 0b100111
+#define ADCMUX_ADC12 0b100100
+
+#define CPU_PRESCALE(n) (CLKPR = 0x80, CLKPR = (n))
+uint8_t read_buffer[64]; // buffer for reading usb signals
+uint8_t write_buffer[64]; // buffer for writing usb signals
+
+//TODOs:
+// * make as much use of sleep modes as possible
+// * use adc noise canceler (i.e. automatic sampling during cpu sleep)
+// * define and listen for an usb_hid reset command -> jump to bootload address
+// * read atmega temp
+// * safely save state in eeprom (2 memory regions, only use the one with the "written successfully bit" which is written last)
+
+int main(void)
+{
+ CPU_PRESCALE(0);
+ led_init();
+ spi_init();
+ usb_init();
+ // set PB5/ADC12 to INPUT (c1101 temp sensor)
+ DDRB &= ~(1<<DDB5);
+ while (!usb_configured()) /* wait */ ;
+
+ //int8_t r = usb_rawhid_recv(read_buffer, 0);
+ //usb_rawhid_send(write_buffer, 23);
+
+ usb_rawhid_send((uint8_t*)"hhd70dongle ready",17);
+
+ for(;;)
+ {
+ _delay_ms(250);
+ led_toggle();
+ usb_rawhid_recv(read_buffer,20);
+ if (read_buffer[0] == 'r')
+ reset();
+ usb_rawhid_send((uint8_t*)"temp c1101:",255);
+ debug_sprint_int16hex(write_buffer, adc_read(ADCMUX_ADC12));
+ usb_rawhid_send(write_buffer,255);
+ _delay_ms(250);
+ usb_rawhid_send((uint8_t*)"temp atmega:",255);
+ debug_sprint_int16hex(write_buffer, adc_read(ADCMUX_INTERNALTEMP));
+ usb_rawhid_send(write_buffer,255);
+ _delay_ms(250);
+ usb_rawhid_send((uint8_t*)"c1101 partnum:",255);
+ debug_sprint_int16hex(write_buffer, c1101_getPartNum());
+ usb_rawhid_send(write_buffer,255);
+ _delay_ms(250);
+ usb_rawhid_send((uint8_t*)"c1101 version:",255);
+ debug_sprint_int16hex(write_buffer, c1101_getVersion());
+ usb_rawhid_send(write_buffer,255);
+ //~ char buf[10];
+ //~ unsigned int len;
+ //~ spi_read(sizeof(buf),buf,&len);
+ }
+}
diff --git a/software/hhd70dongle/pcusbhid/Makefile b/software/hhd70dongle/pcusbhid/Makefile
index c6689ed..cd0f018 100644
--- a/software/hhd70dongle/pcusbhid/Makefile
+++ b/software/hhd70dongle/pcusbhid/Makefile
@@ -35,8 +35,7 @@ endif
OBJS = $(PROG).o hid.o
-
-all: $(TARGET)
+all: $(TARGET) reset
$(PROG): $(OBJS)
$(CC) -o $(PROG) $(OBJS) $(LIBS)
@@ -53,6 +52,10 @@ $(PROG).dmg: $(PROG)
hid.o: hid_$(OS).c hid.h
$(CC) $(CFLAGS) -c -o $@ $<
+reset: reset.o hid.o
+ $(CC) -o $@ $+ $(LIBS)
+ $(STRIP) $@
+
reset.o: reset.c
$(CC) $(CFLAGS) -c -o $@ $<
diff --git a/software/hhd70dongle/pcusbhid/rawhid_testinterface.c b/software/hhd70dongle/pcusbhid/rawhid_testinterface.c
index 8f19c4f..1d47daa 100644
--- a/software/hhd70dongle/pcusbhid/rawhid_testinterface.c
+++ b/software/hhd70dongle/pcusbhid/rawhid_testinterface.c
@@ -59,18 +59,17 @@ int main (int argc, char *argv[])
while (1)
{
- num = rawhid_recv(0, buf, BUF_LEN, 220);
+ num = rawhid_recv(0, buf, BUF_LEN, 250);
if (num < 0)
{
printf("\nerror reading, device went offline\n");
rawhid_close(0);
return 0;
}
- else if (num == 0)
+ if (num > 0)
{
- sleep(1.0);
+ buf[num]='\0';
+ printf("%s\n",buf);
}
- buf[num]='\0';
- printf("%s\n",buf);
}
}
diff --git a/software/hhd70dongle/pcusbhid/reset.c b/software/hhd70dongle/pcusbhid/reset.c
new file mode 100644
index 0000000..7955b1b
--- /dev/null
+++ b/software/hhd70dongle/pcusbhid/reset.c
@@ -0,0 +1,22 @@
+#include <stdio.h>
+#include <string.h>
+
+#include "hid.h"
+
+
+void sendstr(char * tosend)
+{
+ rawhid_send(0, tosend, strlen(tosend),1000);
+}
+
+int main (int argc, char *argv[])
+{
+ // C-based example is 16C0:0480:FFAB:0200
+ int r = rawhid_open(1, 0x16C0, 0x0481, 0xFFAB, 0x0200);
+ if (r <= 0) {
+ printf("no rawhid device found\n");
+ return -1;
+ }
+ sendstr("r"); // clear the buffer
+ return 0;
+}
diff --git a/software/hhd70dongle/spi.c b/software/hhd70dongle/spi.c
index c7172ce..e676fbf 100644
--- a/software/hhd70dongle/spi.c
+++ b/software/hhd70dongle/spi.c
@@ -70,7 +70,6 @@ void spi_cs_disable(void)
}
//synchronous
-//MSB first
void spi_write_byte(char byte)
{
SPDR = byte; //Load byte to Data register
diff --git a/software/hhd70dongle/util.c b/software/hhd70dongle/util.c
new file mode 100644
index 0000000..b1f7e85
--- /dev/null
+++ b/software/hhd70dongle/util.c
@@ -0,0 +1,96 @@
+/*
+ *
+ * mur.sat
+ *
+ * Somewhen in the year 2012, mur.at will have a nano satellite launched
+ * into a low earth orbit (310 km above the surface of our planet). The
+ * satellite itself is a TubeSat personal satellite kit, developed and
+ * launched by interorbital systems. mur.sat is a joint venture of mur.at,
+ * ESC im Labor and realraum.
+ *
+ * Please visit the project hompage at sat.mur.at for further information.
+ *
+ *
+ * Copyright (C) 2012 Bernhard Tittelbach <xro@realraum.at>
+ *
+ * This file is part of mur.sat.
+ *
+ * mur.sat is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * any later version.
+ *
+ * mur.sat is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with mur.sat. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+#include <avr/io.h>
+#include <avr/interrupt.h>
+#include <util/delay.h>
+#include "util.h"
+
+void reset(void)
+{
+ cli();
+ // disable watchdog, if enabled
+ // disable all peripherals
+ UDCON = 1;
+ USBCON = (1<<FRZCLK); // disable USB
+ UCSR1B = 0;
+ _delay_ms(5);
+ #if defined(__AVR_AT90USB162__) // Teensy 1.0
+ EIMSK = 0; PCICR = 0; SPCR = 0; ACSR = 0; EECR = 0;
+ TIMSK0 = 0; TIMSK1 = 0; UCSR1B = 0;
+ DDRB = 0; DDRC = 0; DDRD = 0;
+ PORTB = 0; PORTC = 0; PORTD = 0;
+ asm volatile("jmp 0x3E00");
+ #elif defined(__AVR_ATmega32U4__) // Teensy 2.0
+ EIMSK = 0; PCICR = 0; SPCR = 0; ACSR = 0; EECR = 0; ADCSRA = 0;
+ TIMSK0 = 0; TIMSK1 = 0; TIMSK3 = 0; TIMSK4 = 0; UCSR1B = 0; TWCR = 0;
+ DDRB = 0; DDRC = 0; DDRD = 0; DDRE = 0; DDRF = 0; TWCR = 0;
+ PORTB = 0; PORTC = 0; PORTD = 0; PORTE = 0; PORTF = 0;
+ asm volatile("jmp 0x7E00");
+ #elif defined(__AVR_AT90USB646__) // Teensy++ 1.0
+ EIMSK = 0; PCICR = 0; SPCR = 0; ACSR = 0; EECR = 0; ADCSRA = 0;
+ TIMSK0 = 0; TIMSK1 = 0; TIMSK2 = 0; TIMSK3 = 0; UCSR1B = 0; TWCR = 0;
+ DDRA = 0; DDRB = 0; DDRC = 0; DDRD = 0; DDRE = 0; DDRF = 0;
+ PORTA = 0; PORTB = 0; PORTC = 0; PORTD = 0; PORTE = 0; PORTF = 0;
+ asm volatile("jmp 0xFC00");
+ #elif defined(__AVR_AT90USB1286__) // Teensy++ 2.0
+ EIMSK = 0; PCICR = 0; SPCR = 0; ACSR = 0; EECR = 0; ADCSRA = 0;
+ TIMSK0 = 0; TIMSK1 = 0; TIMSK2 = 0; TIMSK3 = 0; UCSR1B = 0; TWCR = 0;
+ DDRA = 0; DDRB = 0; DDRC = 0; DDRD = 0; DDRE = 0; DDRF = 0;
+ PORTA = 0; PORTB = 0; PORTC = 0; PORTD = 0; PORTE = 0; PORTF = 0;
+ asm volatile("jmp 0x1FC00");
+ #endif
+}
+
+int16_t adc_read(uint8_t mux)
+{
+ uint8_t low;
+ char aref = 0b11000000;
+ ADCSRA = (1<<ADEN) | ADC_PRESCALER; // enable ADC
+ ADCSRB = (1<<ADHSM) | (mux & 0x20); // high speed mode
+ ADMUX = aref | (mux & 0x1F); // configure mux input
+ ADCSRA = (1<<ADEN) | ADC_PRESCALER | (1<<ADSC); // start the conversion
+ while (ADCSRA & (1<<ADSC)) ; // wait for result
+ low = ADCL; // must read LSB first
+ ADCSRA &= ~(1<<ADEN); // disable ADC
+ return (ADCH << 8) | low; // must read MSB only once!
+}
+
+void debug_sprint_int16hex(uint8_t *buffer, int16_t num)
+{
+ int c,n;
+ for (c=0; c<4; c++)
+ {
+ n = (num >> (3-c)*4 ) & 15;
+ buffer[c] = n + ((n < 10) ? '0' : 'A' - 10);
+ }
+ buffer[4]=0;
+} \ No newline at end of file
diff --git a/software/hhd70dongle/util.h b/software/hhd70dongle/util.h
new file mode 100644
index 0000000..870cf3f
--- /dev/null
+++ b/software/hhd70dongle/util.h
@@ -0,0 +1,41 @@
+/*
+ *
+ * mur.sat
+ *
+ * Somewhen in the year 2012, mur.at will have a nano satellite launched
+ * into a low earth orbit (310 km above the surface of our planet). The
+ * satellite itself is a TubeSat personal satellite kit, developed and
+ * launched by interorbital systems. mur.sat is a joint venture of mur.at,
+ * ESC im Labor and realraum.
+ *
+ * Please visit the project hompage at sat.mur.at for further information.
+ *
+ *
+ * Copyright (C) 2012 Bernhard Tittelbach <xro@realraum.at>
+ *
+ * This file is part of mur.sat.
+ *
+ * mur.sat is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * any later version.
+ *
+ * mur.sat is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with mur.sat. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef MURSAT_util_h_INCLUDED
+#define MURSAT_util_h_INCLUDED
+#define ADC_PRESCALER 0
+
+void reset(void);
+int16_t adc_read(uint8_t mux);
+void debug_sprint_int16hex(uint8_t *buffer, int16_t num);
+
+#endif