Skip to content

Commit

Permalink
Merge pull request #26 from ps2/dev
Browse files Browse the repository at this point in the history
Version 0.7
  • Loading branch information
ps2 committed Mar 22, 2016
2 parents 02f7164 + 83d6b0b commit f4b93e4
Show file tree
Hide file tree
Showing 17 changed files with 98 additions and 18 deletions.
36 changes: 36 additions & 0 deletions Makefile.srfstick
Original file line number Diff line number Diff line change
@@ -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 $<
10 changes: 5 additions & 5 deletions commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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) {
Expand Down Expand Up @@ -74,15 +74,15 @@ 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;

send_channel = serial_rx_byte();
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);
Expand Down
6 changes: 6 additions & 0 deletions hardware.h
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
3 changes: 1 addition & 2 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -49,4 +49,3 @@ int main(void)
get_command();
}
}

2 changes: 1 addition & 1 deletion radio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion radio.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
20 changes: 17 additions & 3 deletions spi1_alt2/serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@ 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
#define SPI_MODE_SIZE 1
#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;


/***************************************************************************
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion spi1_alt2/serial.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include <stdint.h>
#include "hardware.h"

volatile uint16_t timerCounter = 0;
volatile uint32_t timerCounter = 0;

void init_timer() {
union {
Expand Down
2 changes: 1 addition & 1 deletion timer.h
Original file line number Diff line number Diff line change
@@ -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();
Expand Down
5 changes: 5 additions & 0 deletions uart0_alt1/serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion uart0_alt1/serial.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 5 additions & 0 deletions uart1_alt2/serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion uart1_alt2/serial.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 10 additions & 0 deletions usb_ep0/hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
5 changes: 5 additions & 0 deletions usb_ep0/serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -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( );
Expand Down
2 changes: 1 addition & 1 deletion usb_ep0/serial.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit f4b93e4

Please sign in to comment.