Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
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 \
00059 DDRH |= 0x40; \
00060 PORTH |= 0x40; \
00061 usart_control_t * const uc = &usart_control_##N; \
00062 uint8_t st = UCSR##N##A; \
00063 \
00064 hl_wakeup_memory (); \
00065 \
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 \
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 \
00089 hl_wakeup_memory (); \
00090 \
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 \
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