; Serial interface using the ATmega8/88 USART.
; This is part of the Z80-CP/M emulator written by Sprite_tm.
;
; Copyright (C) 2010 Leo C.
;
; This file is part of avrcpm.
;
; avrcpm is free software: you can redistribute it and/or modify it
; under the terms of the GNU General Public License as published by
; the Free Software Foundation, either version 3 of the License, or
; (at your option) any later version.
;
; avrcpm is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with avrcpm. If not, see .
;
; $Id$
;
#define SSER_BIT_TC (F_CPU+BAUD/2) / BAUD
#define RXBUFMASK RXBUFSIZE-1
#define TXBUFMASK TXBUFSIZE-1
.dseg
srx_state:
.byte 1
srx_char_to:
.byte 1
srx_dr:
.byte 1
;srx_lastedge:
; .byte 2
stx_bitcount:
.byte 1
stx_dr:
.byte 1
rxcount:
.byte 1
rxidx_w:
.byte 1
rxidx_r:
.byte 1
txcount:
.byte 1
txidx_w:
.byte 1
txidx_r:
.byte 1
rxfifo:
.byte RXBUFSIZE
txfifo:
.byte TXBUFSIZE
.cseg
; Init
uart_init:
; - Init clock/timer system and serial port
; Init timer 1 as
; - Soft UART TX (OC1A/OCR1A).
; - Soft UART RX (ICP1/ICR1).
; - 1ms System timer is already configured at this point.
ldi temp,(1< framing error --> break
sts srx_state,_0
sbr intstat,(1<= TXBUFSIZE)
ldi zl,low(txfifo) ;
ldi zh,high(txfifo) ;
lds temp,txidx_w ;
add zl,temp ;
brcc PC+2 ;
inc zh ;
inc temp ;
andi temp,TXBUFMASK ;
sts txidx_w,temp ; txidx_w = ++txidx_w % TXBUFSIZE
pop temp ;
st z,temp ; txfifo[txidx_w] = char
cli
lds zh,txcount
inc zh
sts txcount,zh
dec zh
brne sputc_e
; Enable transmitter
inm8 zh,TIMSK1
ori zh,(1<