diff --git a/Makefile.spi1_alt2 b/Makefile.spi1_alt2 index bd0fe2f..9c5d037 100755 --- a/Makefile.spi1_alt2 +++ b/Makefile.spi1_alt2 @@ -1,5 +1,5 @@ SERIAL_TYPE := spi1_alt2 -SERIAL_PARAMS := -DUSES_USART1_ISR +SERIAL_PARAMS := -DUSES_USART1_TX_ISR -DUSES_USART1_RX_ISR BOARD_TYPE := RILEYLINK BOARD_PARAMS := diff --git a/Makefile.uart1_alt2 b/Makefile.uart1_alt2 index b473d1d..35a89c3 100755 --- a/Makefile.uart1_alt2 +++ b/Makefile.uart1_alt2 @@ -1,5 +1,5 @@ SERIAL_TYPE := uart1_alt2 -SERIAL_PARAMS := +SERIAL_PARAMS := -DUSES_USART1_RX_ISR BOARD_TYPE := RILEYLINK BOARD_PARAMS := diff --git a/hardware.h b/hardware.h index f84bfd5..1dbf9d5 100644 --- a/hardware.h +++ b/hardware.h @@ -38,6 +38,12 @@ #define GREEN_LED P1_7 #define BLUE_LED P1_6 #define SYSTEM_CLOCK_MHZ 24 +#elif TI_MINIDEV +#define HARDWARE_FLOW_CONTROL_CONFIG 0xc0; /* 8N1, hw flow control, high stop bit */ +#define HARDWARE_LED_INIT P1DIR |= BIT0|BIT1; +#define GREEN_LED P1_0 +#define BLUE_LED P1_1 +#define SYSTEM_CLOCK_MHZ 26 #endif diff --git a/main.c b/main.c index 45afea4..94d5ffa 100644 --- a/main.c +++ b/main.c @@ -12,14 +12,18 @@ void t1_isr(void) __interrupt T1_VECTOR; void rftxrx_isr(void) __interrupt RFTXRX_VECTOR; void rf_isr(void) __interrupt RF_VECTOR; -#ifdef USES_USART1_ISR +#ifdef USES_USART1_RX_ISR void rx1_isr(void) __interrupt URX1_VECTOR; +#endif + +#ifdef USES_USART1_TX_ISR void tx1_isr(void) __interrupt UTX1_VECTOR; #endif #if TI_DONGLE || SRF_STICK void usb_isr() __interrupt 6; #endif + int main(void) { diff --git a/tools/cause_hang.py b/tools/cause_hang.py new file mode 100755 index 0000000..3b00432 --- /dev/null +++ b/tools/cause_hang.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python + +from serial_rf_spy import SerialRfSpy +import sys +import binascii +import time +from datetime import datetime + +if len(sys.argv) < 1: + print "usage: test.py serialport" + sys.exit(2) + +serial_device = sys.argv[1] + +rl = SerialRfSpy(serial_device) +rl.sync() +params = bytearray("00000000000033e800a968e55658e568d555d26000".decode('hex')) +rl.send_command(SerialRfSpy.CMD_SEND_AND_LISTEN, params) +params = bytearray("0000000a50".decode('hex')) +rl.send_command(SerialRfSpy.CMD_GET_PACKET, params) +resp = rl.get_response() +print "resp1 = %s" % str(resp).encode('hex') +resp = rl.get_response() +print "resp2 = %s" % str(resp).encode('hex') + diff --git a/uart1_alt2/serial.c b/uart1_alt2/serial.c index 0d1185c..70956ce 100644 --- a/uart1_alt2/serial.c +++ b/uart1_alt2/serial.c @@ -4,9 +4,24 @@ #include "serial.h" #include "radio.h" +#define SERIAL_BUF_LEN 220 + +volatile uint8_t __xdata serial_input_buf[SERIAL_BUF_LEN]; +volatile uint8_t input_size = 0; +volatile uint8_t input_head_idx = 0; +volatile uint8_t input_tail_idx = 0; + +volatile uint8_t __xdata serial_output_buf[SERIAL_BUF_LEN]; +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; + void configure_serial() { - // UART1 Alt. 2 // P1.4 - CT // P1.5 - RT @@ -19,23 +34,49 @@ void configure_serial() P0SEL &= ~0x3c; /////////////////////////////////////////////////////////////// - // Initialize bitrate (U0BAUD.BAUD_M, U0GCR.BAUD_E) + // Initialize bitrate (U1BAUD.BAUD_M, U1GCR.BAUD_E) // Bitrate 19200 - U1BAUD = 163; +#if SYSTEM_CLOCK_MHZ == 26 + U1BAUD = 131; +#else + U1BAUD = 163; +#endif U1GCR = (U0GCR&~0x1F) | 9; U1UCR |= HARDWARE_FLOW_CONTROL_CONFIG; // Flush, and configure hw flow control // Enable receive U1CSR |= 0x40; URX1IF = 0; + IEN0 |= 0x88; +} +void rx1_isr(void) __interrupt URX1_VECTOR { + URX1IF = 0; + if (input_size < SERIAL_BUF_LEN) { + serial_input_buf[input_head_idx] = U1DBUF; + input_head_idx++; + if (input_head_idx >= SERIAL_BUF_LEN) { + input_head_idx = 0; + } + input_size++; + serial_data_available = 1; + } else { + // overflow + } } uint8_t serial_rx_byte() { uint8_t s_data; while(!SERIAL_DATA_AVAILABLE); // URX1IF - s_data = U1DBUF; - URX1IF = 0; + s_data = serial_input_buf[input_tail_idx]; + input_tail_idx++; + if (input_tail_idx >= SERIAL_BUF_LEN) { + input_tail_idx = 0; + } + input_size--; + if (input_size == 0) { + serial_data_available = 0; + } return s_data; } @@ -64,3 +105,4 @@ void serial_tx_str(const char *str) { } + diff --git a/uart1_alt2/serial.h b/uart1_alt2/serial.h index c41e29c..2b20f2b 100644 --- a/uart1_alt2/serial.h +++ b/uart1_alt2/serial.h @@ -1,7 +1,9 @@ #ifndef SERIAL_H #define SERIAL_H -#define SERIAL_DATA_AVAILABLE URX1IF +#define SERIAL_DATA_AVAILABLE serial_data_available + +extern volatile uint8_t serial_data_available; void configure_serial(); void serial_tx_byte(uint8_t);