Subversion Repositories HomeAutomation

Rev

Rev 378 | Blame | Compare with Previous | Last modification | View Log | SVN | RSS feed

  1. #ifndef AVR_CFG_H_
  2. #define AVR_CFG_H_
  3.  
  4. //#define TIMER2 /* For using Timer2 istead of Timer0 */
  5.  
  6. #if defined(__AVR_ATmega8__)
  7.  
  8. #if defined(TIMER2)
  9.     #define TIMEBASE_COUNTER TCNT2
  10.     #define TIMEBASE_RELOAD (F_CPU / 1000 / 64)
  11.     #define TIMEBASE_INIT()            \
  12.         TCNT2 = TIMEBASE_RELOAD;       \
  13.         TIFR  |= (1<<TOV2);            \
  14.         TIMSK |= (1<<TOIE2);           \
  15.         TCCR0 = (1<<CS22);
  16.     #define TIMEBASE_VECTOR TIMER2_OVF_vect
  17. #else
  18.     #define TIMEBASE_COUNTER TCNT0
  19.     #define TIMEBASE_RELOAD (F_CPU / 1000 / 64)
  20.     #define TIMEBASE_INIT()            \
  21.         TCNT0 = TIMEBASE_RELOAD;       \
  22.         TIFR  |= (1<<TOV0);            \
  23.         TIMSK |= (1<<TOIE0);           \
  24.         TCCR0 = (1<<CS01) | (1<<CS00);
  25.     #define TIMEBASE_VECTOR TIMER0_OVF_vect
  26. #endif
  27.  
  28. #define UART_INIT()                   \
  29.     UCSRB = _BV(RXEN)|_BV(TXEN);      \
  30.     UBRRL = (F_CPU / 16 / F_BAUD) - 1;
  31. #define UART_PUTCHAR(_c_)               \
  32.     loop_until_bit_is_set(UCSRA, UDRE); \
  33.     UDR = (_c_);
  34. #define UART_GETCHAR(_c_)              \
  35.     loop_until_bit_is_set(UCSRA, RXC); \
  36.     (_c_) = UDR;
  37.  
  38. #define IVSEL_REG GICR
  39. #define INT1_REG GICR
  40.  
  41. #elif defined(__AVR_ATmega88__)
  42. #if defined(TIMER2)
  43.     /* Use timer2 */
  44.     #define TIMEBASE_COUNTER TCNT2
  45.     #define TIMEBASE_RELOAD (F_CPU / 1000 / 64)
  46.     #if (TIMEBASE_RELOAD > 255)
  47.     # error System frequency too high for timebase prescaler 64.
  48.     #endif
  49.     #define TIMEBASE_INIT()            \
  50.         TCNT2 = TIMEBASE_RELOAD;       \
  51.         TIFR2  |= (1<<TOV2);           \
  52.         TIMSK2 |= (1<<TOIE2);          \
  53.         TCCR2B = (1<<CS22);
  54.     #define TIMEBASE_VECTOR TIMER2_OVF_vect
  55. #else /* Use timer0*/
  56.     #define TIMEBASE_COUNTER TCNT0
  57.     #define TIMEBASE_RELOAD (F_CPU / 1000 / 64)
  58.     #if (TIMEBASE_RELOAD > 255)
  59.     # error System frequency too high for timebase prescaler 64.
  60.     #endif
  61.     #define TIMEBASE_INIT()            \
  62.         TCNT0 = TIMEBASE_RELOAD;       \
  63.         TIFR0  |= (1<<TOV0);           \
  64.         TIMSK0 |= (1<<TOIE0);          \
  65.         TCCR0B = (1<<CS01) | (1<<CS00);
  66.     #define TIMEBASE_VECTOR TIMER0_OVF_vect
  67. #endif
  68.  
  69. #define UART_INIT()                    \
  70.     UCSR0B = _BV(RXEN0)|_BV(TXEN0);    \
  71.     UBRR0L = (F_CPU / 16 / F_BAUD) - 1;
  72. #define UART_PUTCHAR(_c_)                 \
  73.     loop_until_bit_is_set(UCSR0A, UDRE0); \
  74.     UDR0 = (_c_);
  75. #define UART_GETCHAR(_c_)              \
  76.     loop_until_bit_is_set(UCSR0A, RXC0); \
  77.     (_c_) = UDR0;
  78.  
  79. #define IVSEL_REG MCUCR
  80. #define INT1_REG EIMSK
  81.  
  82. #else
  83. #error AVR specifics not defined!
  84. #endif
  85.  
  86. #endif /*AVR_CFG_H_*/
  87.