00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifndef BASE_RDK2XX_H
00031 #define BASE_RDK2XX_H
00032
00033
00034 #ifndef PB0
00035 # define PB0 (0)
00036 # define PB1 (1)
00037 # define PB2 (2)
00038 # define PB3 (3)
00039 # define PB4 (4)
00040 # define PB5 (5)
00041 # define PB6 (6)
00042 # define PB7 (7)
00043 # define PD4 (4)
00044 #endif
00045
00046 #ifndef DEFAULT_SPI_RATE
00047 # define DEFAULT_SPI_RATE (SPI_RATE_1_2)
00048 #endif
00049
00050
00051 #ifndef RADIO_TYPE
00052 # define RADIO_TYPE (RADIO_AT86RF230)
00053 #endif
00054
00055
00056
00057 #define DDR_TRX_RESET DDRB
00058 #define PORT_TRX_RESET PORTB
00059 #define MASK_TRX_RESET (_BV(5))
00061 #define TRX_RESET_INIT() DDR_TRX_RESET |= MASK_TRX_RESET
00062 #define TRX_RESET_HIGH() PORT_TRX_RESET |= MASK_TRX_RESET
00063 #define TRX_RESET_LOW() PORT_TRX_RESET &= ~MASK_TRX_RESET
00065 #define PORT_TRX_SLPTR PORTB
00066 #define DDR_TRX_SLPTR DDRB
00067 #define MASK_TRX_SLPTR (_BV(PB4))
00070 #define TRX_SLPTR_INIT() DDR_TRX_SLPTR |= MASK_TRX_SLPTR
00071
00072 #define TRX_SLPTR_HIGH() PORT_TRX_SLPTR |= MASK_TRX_SLPTR
00073
00074 #define TRX_SLPTR_LOW() PORT_TRX_SLPTR &= ~MASK_TRX_SLPTR
00075
00076
00077
00078 # define TRX_IRQ_vect INT0_vect
00079 # define TRX_IRQ _BV(INT0)
00085 # define TRX_IRQ_INIT() do{\
00086 EICRA = _BV(ISC00) | _BV(ISC01);\
00087 EIMSK |= _BV(INT0);\
00088 } while(0)
00089
00091 #define DI_TRX_IRQ() {EIMSK &= (~(TRX_IRQ));}
00092
00094 #define EI_TRX_IRQ() {EIMSK |= (TRX_IRQ);}
00095
00100 #define TRX_TSTAMP_REG TCNT1
00101
00102
00103 #define DDR_SPI (DDRB)
00104 #define PORT_SPI (PORTB)
00106 #define SPI_MOSI _BV(PB2)
00107 #define SPI_MISO _BV(PB3)
00108 #define SPI_SCK _BV(PB1)
00109 #define SPI_SS _BV(PB0)
00111 #define SPI_DATA_REG SPDR
00117 static inline void SPI_INIT(uint8_t spirate)
00118 {
00119
00120 PORT_SPI |= SPI_SCK | SPI_SS;
00121 DDR_SPI |= SPI_MOSI | SPI_SCK | SPI_SS;
00122 DDR_SPI &= ~SPI_MISO;
00123
00124 SPCR = (_BV(SPE) | _BV(MSTR));
00125
00126 SPCR &= ~(_BV(SPR1) | _BV(SPR0) );
00127 SPSR &= ~_BV(SPI2X);
00128
00129 SPCR |= (spirate & 0x03);
00130 SPSR |= ((spirate >> 2) & 0x01);
00131
00132 }
00133
00135 #define SPI_SELN_LOW() uint8_t sreg = SREG; cli(); PORT_SPI &=~SPI_SS
00136
00137 #define SPI_SELN_HIGH() PORT_SPI |= SPI_SS; SREG = sreg
00138
00139 #define SPI_WAITFOR() do { while((SPSR & _BV(SPIF)) == 0);} while(0)
00140
00141
00142 #endif
00143