• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

usarts_int.h

Go to the documentation of this file.
00001 /* internal definitions for USARTS */
00002 /* Copyright (C) 2010 Holger Dietze
00003  *
00004  *   This program is free software; you can redistribute it and/or modify
00005  *   it under the terms of the GNU General Public License as published by
00006  *   the Free Software Foundation; either version 2 of the License, or
00007  *   (at your option) version 3.
00008  *
00009  *   This program is distributed in the hope that it will be useful,
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *   GNU General Public License for more details.
00013  *
00014  *   You should have received a copy of the GNU General Public License along
00015  *   with this program; if not, see <http://www.gnu.org/licenses/>.
00016  */
00017 
00018 #ifndef USARTS_INT_H
00019 #define USARTS_INT_H
00020 
00026 #include "xpal_power.h"
00027 
00029 #define UCSRnA(UC) (UC->base[0])
00030 
00031 #define UCSRnB(UC) (UC->base[&UCSR0B-&UCSR0A])
00032 
00033 #define UCSRnC(UC) (UC->base[&UCSR0C-&UCSR0A])
00034 
00035 #define UBRRnL(UC) (UC->base[&UBRR0L-&UCSR0A])
00036 
00037 #define UBRRnH(UC) (UC->base[&UBRR0H-&UCSR0A])
00038 
00039 #define UBRRn(UC)  (*((volatile uint16_t *)(&UC->base[(volatile uint8_t*)&UBRR0-&UCSR0A])))
00040 
00041 #define UDRn(UC)   (UC->base[&UDR0-&UCSR0A])
00042 
00044 #define USART_DEF_CTRL(N) \
00045   static const char usart_name_##N[] PROGMEM = "USART"#N;               \
00046   usart_control_t usart_control_##N =                                   \
00047     { .name = usart_name_##N,                                           \
00048       .base = (uint8_t * const)&(UCSR##N##A),                           \
00049       .prr = (N == 0 ? &PRR0 : &PRR1),                                  \
00050       .prusart = _BV(PRUSART##N),                                       \
00051     };
00052 
00054 #define USART_DEF_RXINT(N)                                              \
00055   extern usart_control_t usart_control_##N;                             \
00056   ISR(USART##N##_RX_vect,ISR_BLOCK)                                     \
00057   {                                                                     \
00058         /*debug thomas*/        \
00059         DDRH |= 0x40;           \
00060         PORTH |= 0x40;          \
00061     usart_control_t * const uc = &usart_control_##N;                    \
00062     uint8_t st = UCSR##N##A;                                            \
00063     /* make sure FIFO buffer is usable */                               \
00064     hl_wakeup_memory ();                                                \
00065     /* loop until hardware RX buffer is empty - reduces INT load */     \
00066     do {                                                                \
00067       fifo_item_t it;                                                   \
00068       it.flags = ((st & _BV(FE0)) ? USART_FRAME_ERROR : 0)              \
00069         | ((st & _BV(UPE0)) ? USART_PARITY_ERROR : 0);                  \
00070       it.data = UDR##N;                                                 \
00071       if (it.data == uc->ts_trigger) {                                  \
00072         uc->timestamp = TCNT2;                                          \
00073         it.flags |= USART_TIMESTAMPED;                                  \
00074       }                                                                 \
00075       fifo_putQ_item (&uc->rxbuf, it);                                  \
00076     } while(((st = UCSR##N##A) & _BV(RXC##N)));                         \
00077     hl_pwr_SetWakeSource (HL_PWR_WAKE_BY_USART##N);                     \
00078         /*debug thomas*/                \
00079         PORTH &= ~(0x40);               \
00080   }
00081 
00083 #define USART_DEF_TXINT(N)                                              \
00084   extern usart_control_t usart_control_##N;                             \
00085   ISR(USART##N##_UDRE_vect,ISR_BLOCK)                                   \
00086   {                                                                     \
00087     usart_control_t * const uc = &usart_control_##N;                    \
00088     /* make sure FIFO buffer is usable */                               \
00089     hl_wakeup_memory ();                                                \
00090     /* refill hardware buffer from FIFO */                              \
00091     if (!fifo_is_empty (&uc->txbuf)) {                                  \
00092       UDR##N = (uint8_t)fifo_getQ_item (&uc->txbuf).data;               \
00093       if (!fifo_is_empty (&uc->txbuf)) {                                \
00094         return;                                                         \
00095       }                                                                 \
00096     }                                                                   \
00097     /* disable further interrupts as we have no new data yet */         \
00098     UCSR##N##B &= ~_BV(UDRIE##N);                                       \
00099     hl_pwr_SetWakeSource (HL_PWR_WAKE_BY_USART##N);                     \
00100   }
00101 
00103 #define USART_DEF_TXCINT(N)                                             \
00104   extern usart_control_t usart_control_##N;                             \
00105   ISR(USART##N##_TX_vect)                                               \
00106   {                                                                     \
00107     usart_control_t * const uc = &usart_control_##N;                    \
00108     uc->tx_empty = 1;                                                   \
00109     hl_pwr_SetWakeSource (HL_PWR_WAKE_BY_USART##N);                     \
00110   }                                                                     
00111 
00112 
00113 #endif

Generated by  doxygen 1.7.1