From 3ce320b1618b5c1a2232a6887c5fef780872171c Mon Sep 17 00:00:00 2001 From: Bernhard Tittelbach Date: Thu, 17 May 2012 06:14:29 +0000 Subject: debugging test attempts git-svn-id: https://svn.spreadspace.org/mur.sat@418 7de4ea59-55d0-425e-a1af-a3118ea81d4c --- software/hhd70dongle/Makefile | 64 ++++--- software/hhd70dongle/c1101lib.c | 43 ++++- software/hhd70dongle/c1101lib.h | 30 +-- software/hhd70dongle/hhd70dongle.c | 201 ++++++++++----------- software/hhd70dongle/pcusbhid/Makefile | 7 +- .../hhd70dongle/pcusbhid/rawhid_testinterface.c | 9 +- software/hhd70dongle/pcusbhid/reset.c | 22 +++ software/hhd70dongle/spi.c | 1 - software/hhd70dongle/util.c | 96 ++++++++++ software/hhd70dongle/util.h | 41 +++++ 10 files changed, 353 insertions(+), 161 deletions(-) create mode 100644 software/hhd70dongle/pcusbhid/reset.c create mode 100644 software/hhd70dongle/util.c create mode 100644 software/hhd70dongle/util.h (limited to 'software/hhd70dongle') 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 -## -## 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 . -## - -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 +## +## 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 . +## + +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 . * */ -#include "avr/io.h" -#include "util/delay.h" +#include +#include #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 - * - * 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 . - * - */ -#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< + * + * 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 . + * + */ +#include +#include +//#include + +#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< 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 +#include + +#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 + * + * 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 . + * + */ +#include +#include +#include +#include "util.h" + +void reset(void) +{ + cli(); + // disable watchdog, if enabled + // disable all peripherals + UDCON = 1; + USBCON = (1<> (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 + * + * 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 . + * + */ + +#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 -- cgit v1.2.3