#include "USART0.h" //-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ISR(USART0_TX_vect){ if (USART0STR.TxSendedCount == USART0STR.TxBufCount){ *USART0STR.USART->UCRSB&=~((1<UDR=USART0STR.TX_BUF[USART0STR.TxSendedCount]; USART0STR.TxSendedCount++; } } //-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ISR(USART0_RX_vect){ TIMSK4=0; TCNT4=0; // Timeout Timer4 On, clkI/O/8 (From prescaller) TCCR4B=2; TIMSK4=1<UDR; USART0STR.RxBufCount++; } } //-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ISR(TIMER4_COMPA_vect) { TCCR4B=0; TCNT4=0; TIMSK4=0; // Timeout TIMER3 off *USART0STR.USART->UCRSB&=~((1< Z USART0_RX_DDR&=~(1< Z *USART0STR.USART->UCRSA=0; *USART0STR.USART->UCRSB=(1<UCRSC=(1<UBRR = (F_CPU/16UL)/Baudrate-1; OCR4A = 4015; } //-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- uint8_t USART0_IsNewRxMessage(void) { return USART0STR.RxComplete; } //-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- uint8_t USART0_IsRxError(void) { return USART0STR.RxError; } //-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- uint16_t USART0_getRxBufSize(void) { return USART0STR.RxBufCount; } //-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- volatile uint8_t *USART0_getRxBuf(void) { return &USART0STR.RX_BUF[0]; } //-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- volatile uint8_t *USART0_getTxBuf(void) { return &USART0STR.TX_BUF[0]; } //-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- void USART0_copyRxBuf(uint8_t *Dst, uint16_t StartPos, uint16_t Count) { memcpy(Dst, &USART0STR.RX_BUF[StartPos], Count); } //-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- uint8_t USART0_IsTxActive(void){ if (USART0STR.TxComplete) return 0; else return 1; } //-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- void USART0_SendByteBuf(uint8_t *Buf, uint16_t Count){ if ( (!USART0STR.TxComplete) || (Count == 0) || (Count > USART0_BUF_SIZE) ) { return; } memcpy(USART0STR.TX_BUF, Buf, Count); USART0_TX_DDR|=1< out USART0STR.TxComplete = 0; USART0STR.TxBufCount = Count; USART0STR.TxSendedCount = 1; *USART0STR.USART->UCRSB|=(1<UDR = USART0STR.TX_BUF[0]; } //-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- void USART0_SendTxBuf(uint16_t Count){ if ( (!USART0STR.TxComplete) || (Count == 0) || (Count > USART0_BUF_SIZE) ) { return; } USART0_TX_DDR|=1< out USART0STR.TxComplete = 0; USART0STR.TxBufCount = Count; USART0STR.TxSendedCount = 1; *USART0STR.USART->UCRSB|=(1<UDR = USART0STR.TX_BUF[0]; } //-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- void USART0_RxTransferRestart(void){ //USART0_RX_TIMER_STOP(); //We are already doing this in IRQ //(void) USART0STR.USART->SR; //(void) USART0STR.USART->DR; *USART0STR.USART->UCRSB|=(1<CR1 |= (1U<