diff --git a/Makefile.srfstick b/Makefile.srfstick new file mode 100755 index 0000000..43ff864 --- /dev/null +++ b/Makefile.srfstick @@ -0,0 +1,36 @@ +SERIAL_TYPE := usb_ep0 +SERIAL_PARAMS := -DSRF_STICK + +BOARD_TYPE := SRF_STICK +BOARD_PARAMS := -DSRF_STICK + +TARGET_DEVICE := CC1111 + + +SRC = \ + hal.c \ + usb.c \ + usb_descriptors.c + +ADB=$(SRC:.c=.adb) +ASM=$(SRC:.c=.asm) +LNK=$(SRC:.c=.lnk) +LST=$(SRC:.c=.lst) +REL=$(SRC:.c=.rel) +RST=$(SRC:.c=.rst) +SYM=$(SRC:.c=.sym) + +PCDB=$(PROGS:.hex=.cdb) +PLNK=$(PROGS:.hex=.lnk) +PMAP=$(PROGS:.hex=.map) +PMEM=$(PROGS:.hex=.mem) +PAOM=$(PROGS:.hex=) +include common.mk + +hal.rel: ${SERIAL_TYPE}/hal.c + $(CC) $(CFLAGS) -o output/${TARGET_BUILD}/$@ -c $< + +usb_descriptors.rel: ${SERIAL_TYPE}/usb_descriptors.c + $(CC) $(CFLAGS) -o output/${TARGET_BUILD}/$@ -c $< +usb.rel: ${SERIAL_TYPE}/usb.c + $(CC) $(CFLAGS) -o output/${TARGET_BUILD}/$@ -c $< diff --git a/commands.c b/commands.c index 95bfd48..4eaf79f 100644 --- a/commands.c +++ b/commands.c @@ -22,10 +22,10 @@ CommandHandler handlers[] = { void cmd_get_packet() { uint8_t channel; - uint16_t timeout_ms; + uint32_t timeout_ms; uint8_t result; channel = serial_rx_byte(); - timeout_ms = serial_rx_word(); + timeout_ms = serial_rx_long(); result = get_packet_and_write_to_serial(channel, timeout_ms); if (result != 0) { serial_tx_byte(result); @@ -38,7 +38,7 @@ void cmd_get_state() { } void cmd_get_version() { - serial_tx_str("subg_rfspy 0.6"); + serial_tx_str("subg_rfspy 0.7"); } void do_cmd(uint8_t cmd) { @@ -74,7 +74,7 @@ void cmd_send_and_listen() { uint8_t repeat_count; uint8_t delay_ms; uint8_t listen_channel; - uint16_t timeout_ms; + uint32_t timeout_ms; uint8_t retry_count; uint8_t result; @@ -82,7 +82,7 @@ void cmd_send_and_listen() { repeat_count = serial_rx_byte(); delay_ms = serial_rx_byte(); listen_channel = serial_rx_byte(); - timeout_ms = serial_rx_word(); + timeout_ms = serial_rx_long(); retry_count = serial_rx_byte(); send_packet_from_serial(send_channel, repeat_count, delay_ms); diff --git a/hardware.h b/hardware.h index ec27a9e..f84bfd5 100644 --- a/hardware.h +++ b/hardware.h @@ -32,6 +32,12 @@ #define GREEN_LED P1_7 #define BLUE_LED P1_7 #define SYSTEM_CLOCK_MHZ 24 +#elif SRF_STICK +#define HARDWARE_FLOW_CONTROL_CONFIG 0x02; /* 8N1, NO flow control, high stop bit */ +#define HARDWARE_LED_INIT P1DIR |= BIT7; +#define GREEN_LED P1_7 +#define BLUE_LED P1_6 +#define SYSTEM_CLOCK_MHZ 24 #endif diff --git a/main.c b/main.c index abdd9df..45afea4 100644 --- a/main.c +++ b/main.c @@ -17,7 +17,7 @@ void rx1_isr(void) __interrupt URX1_VECTOR; void tx1_isr(void) __interrupt UTX1_VECTOR; #endif -#ifdef TI_DONGLE +#if TI_DONGLE || SRF_STICK void usb_isr() __interrupt 6; #endif int main(void) @@ -49,4 +49,3 @@ int main(void) get_command(); } } - diff --git a/radio.c b/radio.c index 94c8f1b..963520e 100644 --- a/radio.c +++ b/radio.c @@ -204,7 +204,7 @@ void resend_from_tx_buf(uint8_t channel) { while(MARCSTATE!=MARC_STATE_IDLE); } -uint8_t get_packet_and_write_to_serial(uint8_t channel, uint16_t timeout_ms) { +uint8_t get_packet_and_write_to_serial(uint8_t channel, uint32_t timeout_ms) { uint8_t read_idx = 0; uint8_t d_byte = 0; diff --git a/radio.h b/radio.h index c7165b4..a1a6fbd 100644 --- a/radio.h +++ b/radio.h @@ -7,7 +7,7 @@ void configure_radio(); // 0 = timed out // 1 = got packet // 2 = rx interrupted by serial -uint8_t get_packet_and_write_to_serial(uint8_t channel, uint16_t timeout_ms); +uint8_t get_packet_and_write_to_serial(uint8_t channel, uint32_t timeout_ms); void send_packet_from_serial(uint8_t channel, uint8_t repeat_count, uint8_t delay_ms); diff --git a/spi1_alt2/serial.c b/spi1_alt2/serial.c index e10f62a..eaebb8e 100644 --- a/spi1_alt2/serial.c +++ b/spi1_alt2/serial.c @@ -16,6 +16,8 @@ volatile uint8_t output_size = 0; volatile uint8_t output_head_idx = 0; volatile uint8_t output_tail_idx = 0; +volatile uint8_t ready_to_send = 0; + volatile uint8_t serial_data_available; #define SPI_MODE_WAIT 0 @@ -23,8 +25,8 @@ volatile uint8_t serial_data_available; #define SPI_MODE_XFER 2 volatile uint8_t spi_mode; -volatile uint8_t master_send_size; -volatile uint8_t slave_send_size; +volatile uint8_t master_send_size = 0; +volatile uint8_t slave_send_size = 0; /*************************************************************************** @@ -96,7 +98,12 @@ void rx1_isr(void) __interrupt URX1_VECTOR { value = U1DBUF; if (spi_mode == SPI_MODE_WAIT && value == 0x99) { - slave_send_size = output_size; + if (ready_to_send) { + slave_send_size = output_size; + ready_to_send = 0; + } else { + slave_send_size = 0; + } spi_mode = SPI_MODE_SIZE; U1DBUF = slave_send_size; return; @@ -172,6 +179,10 @@ uint16_t serial_rx_word() { return (serial_rx_byte() << 8) + serial_rx_byte(); } +uint32_t serial_rx_long() { + return ((uint32_t)serial_rx_word() << 16) + serial_rx_word(); +} + void serial_tx_byte(uint8_t tx_byte) { if (output_size >= SPI_BUF_LEN) { // drop oldest byte @@ -182,6 +193,9 @@ void serial_tx_byte(uint8_t tx_byte) { } } spi_output_buf[output_head_idx] = tx_byte; + if (tx_byte == 0) { + ready_to_send = 1; + } output_head_idx++; if (output_head_idx >= SPI_BUF_LEN) { output_head_idx = 0; diff --git a/spi1_alt2/serial.h b/spi1_alt2/serial.h index f8010e0..2b20f2b 100644 --- a/spi1_alt2/serial.h +++ b/spi1_alt2/serial.h @@ -9,6 +9,6 @@ void configure_serial(); void serial_tx_byte(uint8_t); void serial_tx_str(const char *str); uint8_t serial_rx_byte(); -uint16_t serial_rx_word(); +uint32_t serial_rx_long(); #endif diff --git a/timer.c b/timer.c index 5c220cf..d56b9b0 100644 --- a/timer.c +++ b/timer.c @@ -2,7 +2,7 @@ #include #include "hardware.h" -volatile uint16_t timerCounter = 0; +volatile uint32_t timerCounter = 0; void init_timer() { union { diff --git a/timer.h b/timer.h index ff53e66..82157a3 100644 --- a/timer.h +++ b/timer.h @@ -1,7 +1,7 @@ #ifndef TIMER_H #define TIMER_H -volatile extern uint16_t timerCounter; +volatile extern uint32_t timerCounter; void init_timer(); void reset_timer(); diff --git a/uart0_alt1/serial.c b/uart0_alt1/serial.c index ee39471..77b2dca 100644 --- a/uart0_alt1/serial.c +++ b/uart0_alt1/serial.c @@ -43,6 +43,11 @@ uint16_t serial_rx_word() { return (serial_rx_byte() << 8) + serial_rx_byte(); } +uint32_t serial_rx_long() { + return ((uint32_t)serial_rx_word() << 16) + serial_rx_word(); +} + + void serial_tx_byte(uint8_t tx_byte) { UTX0IF = 0; U0DBUF = tx_byte; diff --git a/uart0_alt1/serial.h b/uart0_alt1/serial.h index e510b50..388485a 100644 --- a/uart0_alt1/serial.h +++ b/uart0_alt1/serial.h @@ -7,6 +7,6 @@ void configure_serial(); void serial_tx_byte(uint8_t); void serial_tx_str(const char *str); uint8_t serial_rx_byte(); -uint16_t serial_rx_word(); +uint32_t serial_rx_long(); #endif diff --git a/uart1_alt2/serial.c b/uart1_alt2/serial.c index 0e6174c..0d1185c 100644 --- a/uart1_alt2/serial.c +++ b/uart1_alt2/serial.c @@ -43,6 +43,11 @@ uint16_t serial_rx_word() { return (serial_rx_byte() << 8) + serial_rx_byte(); } +uint32_t serial_rx_long() { + return ((uint32_t)serial_rx_word() << 16) + serial_rx_word(); +} + + void serial_tx_byte(uint8_t tx_byte) { UTX1IF = 0; U1DBUF = tx_byte; diff --git a/uart1_alt2/serial.h b/uart1_alt2/serial.h index f170015..c41e29c 100644 --- a/uart1_alt2/serial.h +++ b/uart1_alt2/serial.h @@ -7,6 +7,6 @@ void configure_serial(); void serial_tx_byte(uint8_t); void serial_tx_str(const char *str); uint8_t serial_rx_byte(); -uint16_t serial_rx_word(); +uint32_t serial_rx_long(); #endif diff --git a/usb_ep0/hal.c b/usb_ep0/hal.c index 0c1bdc6..f74304b 100644 --- a/usb_ep0/hal.c +++ b/usb_ep0/hal.c @@ -35,12 +35,22 @@ void led_off() { void usb_up() { // Bring up the USB link +#ifdef TI_DONGLE P1DIR |= 1; P1_0 = 1; +#elif SRF_STICK + P2DIR |= 1; + P2_0 = 1; +#endif } void usb_down() { // Bring down the USB link +#ifdef TI_DONGLE P1_0 = 0; P1DIR &= ~1; +#elif SRF_STICK + P2_0 = 0; + P2DIR &= ~1; +#endif } diff --git a/usb_ep0/serial.c b/usb_ep0/serial.c index 1e4b805..b566847 100644 --- a/usb_ep0/serial.c +++ b/usb_ep0/serial.c @@ -45,6 +45,11 @@ uint16_t serial_rx_word() { return (serial_rx_byte() << 8) + serial_rx_byte(); } +uint32_t serial_rx_long() { + return ((uint32_t)serial_rx_word() << 16) + serial_rx_word(); +} + + void flush_serial( ) { GREEN_LED ^= 1; usb_flush( ); diff --git a/usb_ep0/serial.h b/usb_ep0/serial.h index c463bf8..8cbc08e 100644 --- a/usb_ep0/serial.h +++ b/usb_ep0/serial.h @@ -9,7 +9,7 @@ void serial_tx_str(const char *str); void run_command_from_serial(); uint8_t serial_rx_byte(); uint8_t serial_has_bytes(); -uint16_t serial_rx_word(); +uint32_t serial_rx_long(); void flush_serial( ); #endif