You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

106 lines
4.2 KiB

  1. #ifndef __TARGET_H__
  2. #define __TARGET_H__
  3. #include <avr/io.h>
  4. /* *********************************************************************** */
  5. /*
  6. * using ATmega168 @16MHz:
  7. * Fuse E: 0xFA (512 words bootloader)
  8. * Fuse H: 0xDD (2.7V BOD)
  9. * Fuse L: 0xFF (external crystal)
  10. */
  11. #define F_CPU 16000000
  12. #define RFM12_ADDRESS TWAR
  13. /* *********************************************************************** */
  14. /* 1ms @16MHz */
  15. #define TIMER_RELOAD 250
  16. #define TIMER_COUNT 3
  17. #define TIMER_TIM_INIT() { \
  18. TCCR0A = 0x00; \
  19. TCCR0B = 0x00; \
  20. TIMSK0 = (1<<TOIE0); \
  21. }
  22. /* Timer0: FCPU/64, overflow interrupt */
  23. #define TIMER_TIM_ENABLE() { TCCR0B |= ((1<<CS01) | (1<<CS00)); }
  24. #define TIMER_TIM_DISABLE() { TCCR0B &= ~((1<<CS01) | (1<<CS00)); }
  25. #define TIMER_TIM_RUNNING() (TCCR0B & ((1<<CS00) | (1<<CS01) | (1<<CS02)))
  26. #define TIMER_TIM_RELOAD(x) { TCNT0 = (0xFF - (x)); }
  27. #define TIMER_TIM_VECT TIMER0_OVF_vect
  28. /* *********************************************************************** */
  29. #define EVENT_COUNT 16
  30. /* *********************************************************************** */
  31. #define LED_INIT() { DDRD |= ((1<<PORTD5) | (1<<PORTD6)); LED_OFF(); }
  32. #define LED_GN_ON() PORTD &= ~(1<<PORTD5)
  33. #define LED_GN_OFF() PORTD |= (1<<PORTD5)
  34. #define LED_GN_TOGGLE() PORTD ^= (1<<PORTD5)
  35. #define LED_RT_ON() PORTD &= ~(1<<PORTD6)
  36. #define LED_RT_OFF() PORTD |= (1<<PORTD6)
  37. #define LED_OFF() PORTD |= ((1<<PORTD5) | (1<<PORTD6))
  38. /* *********************************************************************** */
  39. #define UART_BAUDRATE 19200
  40. #define UART_RXBUF_SIZE 16
  41. #define UART_TXBUF_SIZE 128
  42. /* *********************************************************************** */
  43. #define PWM_TIM_16BIT 1
  44. #define PWM_DELAY_COUNT 4
  45. #define PWM_TIM_INIT() { \
  46. DDRB |= (1<<PORTB1) | (1<<PORTB2); \
  47. /* Timer1: 8MHz, FastModePWM, overflow interrupt */ \
  48. TCCR1A = (1<<WGM11) | (0<<WGM10); \
  49. TCCR1B = (1<<WGM12) | (1<<WGM13); \
  50. TIMSK1 = (1<<TOIE1); \
  51. ICR1 = 0xFFFF; \
  52. }
  53. #define PWM_TIM_ENABLE() { TCCR1B |= (1<<CS10); }
  54. #define PWM_TIM_DISABLE() { TCCR1B &= ~(1<<CS10); }
  55. #define PWM_TIM_RUNNING() (TCCR1B & ((1<<CS10) | (1<<CS11) | (1<<CS12)))
  56. #define PWM_TIM_CHECK() (TCCR1A & ((1<<COM1A1) | (1<<COM1B1)))
  57. #define PWM_TIM_VECT TIMER1_OVF_vect
  58. #define PWM_CH0_PORT PORTB
  59. #define PWM_CH0_NUM 1
  60. #define PWM_CH0_OFF() { PWM_CH0_PORT &= ~(1<<PWM_CH0_NUM); TCCR1A &= ~(1<<COM1A1); }
  61. #define PWM_CH0_ON() { PWM_CH0_PORT |= (1<<PWM_CH0_NUM); TCCR1A &= ~(1<<COM1A1); }
  62. #define PWM_CH0_PWM(x) { PWM_CH0_PORT &= ~(1<<PWM_CH0_NUM); TCCR1A |= (1<<COM1A1); OCR1A = x; }
  63. #define PWM_CH1_PORT PORTB
  64. #define PWM_CH1_NUM 2
  65. #define PWM_CH1_OFF() { PWM_CH1_PORT &= ~(1<<PWM_CH1_NUM); TCCR1A &= ~(1<<COM1B1); }
  66. #define PWM_CH1_ON() { PWM_CH1_PORT |= (1<<PWM_CH1_NUM); TCCR1A &= ~(1<<COM1B1); }
  67. #define PWM_CH1_PWM(x) { PWM_CH1_PORT &= ~(1<<PWM_CH1_NUM); TCCR1A |= (1<<COM1B1); OCR1B = x; }
  68. /* *********************************************************************** */
  69. #define RFM12_INT_INIT() EICRA |= (1<<ISC11)
  70. #define RFM12_INT_ON() EIMSK |= (1<<INT1)
  71. #define RFM12_INT_OFF() EIMSK &= ~(1<<INT1)
  72. #define RFM12_INT_CLEAR() EIFR = INTF1
  73. #define RFM12_INT_VECT INT1_vect
  74. #define RFM12_CS_INIT() DDRD |= (1<<PORTD7)
  75. #define RFM12_CS_ACTIVE() PORTD &= ~(1<<PORTD7)
  76. #define RFM12_CS_INACTIVE() PORTD |= (1<<PORTD7)
  77. #define RFM12_SPI_INIT() { /* SS, SCK and MOSI are outputs */ \
  78. DDRB |= (1<<PORTB2) | (1<<PORTB3) | (1<<PORTB5); \
  79. /* SPI Master, F_CPU /16 */ \
  80. SPCR = (1<<SPE) | (1<<MSTR) | (1<<SPR0); \
  81. }
  82. /* *********************************************************************** */
  83. #endif /* __TARGET_H__ */