Skip to content

Commit

Permalink
Merge branch 'hang-fix' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
ps2 committed Mar 29, 2016
2 parents 825707b + d92cece commit 8bdc59d
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Makefile.spi1_alt2
Original file line number Diff line number Diff line change
@@ -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 :=
Expand Down
2 changes: 1 addition & 1 deletion Makefile.uart1_alt2
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
SERIAL_TYPE := uart1_alt2
SERIAL_PARAMS :=
SERIAL_PARAMS := -DUSES_USART1_RX_ISR

BOARD_TYPE := RILEYLINK
BOARD_PARAMS :=
Expand Down
6 changes: 6 additions & 0 deletions hardware.h
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
6 changes: 5 additions & 1 deletion main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{

Expand Down
25 changes: 25 additions & 0 deletions tools/cause_hang.py
Original file line number Diff line number Diff line change
@@ -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')

52 changes: 47 additions & 5 deletions uart1_alt2/serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}

Expand Down Expand Up @@ -64,3 +105,4 @@ void serial_tx_str(const char *str) {
}



4 changes: 3 additions & 1 deletion uart1_alt2/serial.h
Original file line number Diff line number Diff line change
@@ -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);
Expand Down

0 comments on commit 8bdc59d

Please sign in to comment.