From a86d9d26bd040d74f0ab50417cbbc4e01985c8f0 Mon Sep 17 00:00:00 2001 From: optixx Date: Sun, 20 Sep 2009 13:03:03 +0200 Subject: [PATCH] add buffered rx uart --- avr/usbload/Makefile | 4 +-- avr/usbload/config.h | 2 +- avr/usbload/shell.c | 65 ++++++++++++++++++++++++++++++++++++++++++++ avr/usbload/shell.h | 24 ++++++++++++++++ avr/usbload/uart.c | 4 +-- 5 files changed, 94 insertions(+), 5 deletions(-) create mode 100644 avr/usbload/shell.c create mode 100644 avr/usbload/shell.h diff --git a/avr/usbload/Makefile b/avr/usbload/Makefile index ded3f75..8bc5e17 100644 --- a/avr/usbload/Makefile +++ b/avr/usbload/Makefile @@ -33,13 +33,13 @@ ifeq ($(DEBUG),1) OBJECTS = usbdrv/usbdrv.o usbdrv/usbdrvasm.o usbdrv/oddebug.o \ main.o usb_bulk.o uart.o fifo.o sram.o crc.o debug.o \ dump.o timer.o watchdog.o rle.c loader.o info.o shared_memory.o \ - pwm.o irq.o command.o testing.o + pwm.o shell.o irq.o command.o testing.o else LDFLAGS =-Wl,-u CFLAGS =-Iusbdrv -I. -DDEBUG_LEVEL=0 -DNO_DEBUG -DNO_INFO OBJECTS = usbdrv/usbdrv.o usbdrv/usbdrvasm.o usbdrv/oddebug.o main.o usb_bulk.o \ uart.o fifo.o sram.o crc.o debug.o dump.o timer.o watchdog.o rle.c loader.o \ - pwm.o info.o shared_memory.o command.o irq.o + pwm.o shell.o info.o shared_memory.o command.o irq.o endif COMPILE = avr-gcc -Wall -Os -DF_CPU=$(F_CPU) $(CFLAGS) -mmcu=$(DEVICE) diff --git a/avr/usbload/config.h b/avr/usbload/config.h index 53c7d42..5759072 100644 --- a/avr/usbload/config.h +++ b/avr/usbload/config.h @@ -47,7 +47,7 @@ #define HW_VERSION "2.6" #define SW_VERSION "1.0" -#define DO_CRC_CHECK_LOADER 1 +#define DO_CRC_CHECK_LOADER 0 #define DO_CRC_CHECK 0 #define DO_SHM_SCRATCHPAD 1 #define DO_SHM 1 diff --git a/avr/usbload/shell.c b/avr/usbload/shell.c new file mode 100644 index 0000000..9cadb15 --- /dev/null +++ b/avr/usbload/shell.c @@ -0,0 +1,65 @@ +/* + * ===================================================================================== + * + * ________ .__ __ ________ ____ ________ + * \_____ \ __ __|__| ____ | | __\______ \ _______ _/_ |/ _____/ + * / / \ \| | \ |/ ___\| |/ / | | \_/ __ \ \/ /| / __ \ + * / \_/. \ | / \ \___| < | ` \ ___/\ / | \ |__\ \ + * \_____\ \_/____/|__|\___ >__|_ \/_______ /\___ >\_/ |___|\_____ / + * \__> \/ \/ \/ \/ \/ + * + * www.optixx.org + * + * + * Version: 1.0 + * Created: 07/21/2009 03:32:16 PM + * Author: david@optixx.org + * + * ===================================================================================== + */ + #include + #include + #include + #include + + #include "pwm.h" + #include "debug.h" + #include "info.h" + #include "sram.h" + + #define RECEIVE_BUF_LEN 40 + + uint8_t recv_buf[RECEIVE_BUF_LEN]; + volatile uint8_t recv_counter = 0; + volatile uint8_t cr = 0; + +ISR(USART0_RX_vect) // Interrupt for UART Byte received +{ + UCSR0B &= (255 - (1<'); + } + recv_buf[recv_counter] = UDR0; + uart_putc(recv_buf[recv_counter]); /* do a echo, maybe should reside not in interrupt */ + if (recv_buf[recv_counter] == 0x0d) { + /* recv_buf[recv_counter] = 0; */ + cr = 1; // found a CR, so the application should do something + recv_buf[++recv_counter]='\0'; // terminate string + recv_counter = 0; + uart_putc('\n'); + } else { + // we accept backspace or delete + if ((recv_buf[recv_counter] == 0x08 || recv_buf[recv_counter] == 0x7f) && recv_counter > 0) { + recv_counter--; + } else { + recv_counter++; + } + } + UCSR0B |= (1<__|_ \/_______ /\___ >\_/ |___|\_____ / + * \__> \/ \/ \/ \/ \/ + * + * www.optixx.org + * + * + * Version: 1.0 + * Created: 07/21/2009 03:32:16 PM + * Author: david@optixx.org + * + * ===================================================================================== + */ + +#ifndef __SHELL_H__ +#define __SHELL_H__ + + #endif diff --git a/avr/usbload/uart.c b/avr/usbload/uart.c index f336d2f..14a03a1 100644 --- a/avr/usbload/uart.c +++ b/avr/usbload/uart.c @@ -52,7 +52,7 @@ void uart_init(void) } - +/* ISR(USART0_RX_vect) { uint8_t c; @@ -62,7 +62,7 @@ ISR(USART0_RX_vect) intflags.rx_int = 1; } } - +*/ void uart_putc(uint8_t c) {