/* Name: uart.c * Project: AVR USB driver for CDC interface on Low-Speed USB * Author: Osamu Tamura * Creation Date: 2006-06-18 * Tabsize: 4 * Copyright: (c) 2006 by Recursion Co., Ltd. * License: Proprietary, free under certain conditions. See Documentation. * * 2006-07-08 adapted to higher baudrate by T.Kitazawa */ /* General Description: This module implements the UART rx/tx system of the USB-CDC driver. */ #include #include #include /* needed by usbdrv.h */ #include "oddebug.h" #include "usbdrv.h" #include "uart.h" extern uchar sendEmptyFrame; /* UART buffer */ uchar urptr, uwptr, irptr, iwptr; uchar rx_buf[RX_SIZE+HW_CDC_BULK_IN_SIZE], tx_buf[TX_SIZE]; void uartInit(ulong baudrate, uchar parity, uchar stopbits, uchar databits) { usbDWord_t br; br.dword = ((F_CPU>>3)+(baudrate>>1)) / baudrate - 1; UCSR0A |= (1<>1)< RS-232C */ while( (UCSR0A&(1<HW_CDC_BULK_OUT_SIZE ) { usbEnableAllRequests(); } } /* device <= RS-232C */ while( UCSR0A&(1<HW_CDC_BULK_IN_SIZE) bytesRead = HW_CDC_BULK_IN_SIZE; next = urptr + bytesRead; if( next>=RX_SIZE ) { next &= RX_MASK; for( i=0; io- PB0, PC1 -|>o- PB1) to connect to RS-232C line directly. ( <= 2400 bps ) (atmega48/88 only) */ ISR( PCINT1_vect, ISR_NAKED ) { asm volatile( "out %0, r16" "\n\t" "in r16, __SREG__" "\n\t" "out %1, r16" "\n\t" "in r16, %2" "\n\t" "com r16" "\n\t" "out %3, r16" "\n\t" "in r16, %1" "\n\t" "out __SREG__, r16" "\n\t" "in r16, %0" "\n\t" : : "I" (_SFR_IO_ADDR(GPIOR0)), "I" (_SFR_IO_ADDR(GPIOR1)), "I" (_SFR_IO_ADDR(PINC)), "I" (_SFR_IO_ADDR(PORTB)) ); reti(); } #endif