cc2420.h
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
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #ifndef __CC2420_H__
00043 #define __CC2420_H__
00044
00045 #include "contiki.h"
00046 #include "dev/spi.h"
00047 #include "dev/radio.h"
00048 #include "dev/cc2420_const.h"
00049
00050 int cc2420_init(void);
00051
00052 #define CC2420_MAX_PACKET_LEN 127
00053
00054 int cc2420_set_channel(int channel);
00055 int cc2420_get_channel(void);
00056
00057 void cc2420_set_pan_addr(unsigned pan,
00058 unsigned addr,
00059 const uint8_t *ieee_addr);
00060
00061 extern signed char cc2420_last_rssi;
00062 extern uint8_t cc2420_last_correlation;
00063
00064 int cc2420_rssi(void);
00065
00066 extern const struct radio_driver cc2420_driver;
00067
00068
00069
00070
00071 void cc2420_set_txpower(uint8_t power);
00072 int cc2420_get_txpower(void);
00073 #define CC2420_TXPOWER_MAX 31
00074 #define CC2420_TXPOWER_MIN 0
00075
00076
00077
00078
00079
00080 int cc2420_interrupt(void);
00081
00082
00083 extern rtimer_clock_t cc2420_time_of_arrival,
00084 cc2420_time_of_departure;
00085 extern int cc2420_authority_level_of_sender;
00086
00087 int cc2420_on(void);
00088 int cc2420_off(void);
00089
00090 void cc2420_set_cca_threshold(int value);
00091
00092
00093
00094
00095
00096 #define CC2420_STROBE(s) \
00097 do { \
00098 CC2420_SPI_ENABLE(); \
00099 SPI_WRITE(s); \
00100 CC2420_SPI_DISABLE(); \
00101 } while (0)
00102
00103
00104
00105
00106 #define CC2420_WRITE_REG(adr,data) \
00107 do { \
00108 CC2420_SPI_ENABLE(); \
00109 SPI_WRITE_FAST(adr); \
00110 SPI_WRITE_FAST((uint8_t)((data) >> 8)); \
00111 SPI_WRITE_FAST((uint8_t)(data & 0xff)); \
00112 SPI_WAITFORTx_ENDED(); \
00113 SPI_WRITE(0); \
00114 CC2420_SPI_DISABLE(); \
00115 } while(0)
00116
00117
00118 #define CC2420_READ_REG(adr,data) \
00119 do { \
00120 CC2420_SPI_ENABLE(); \
00121 SPI_WRITE(adr | 0x40); \
00122 data = (uint8_t)SPI_RXBUF; \
00123 SPI_TXBUF = 0; \
00124 SPI_WAITFOREORx(); \
00125 data = SPI_RXBUF << 8; \
00126 SPI_TXBUF = 0; \
00127 SPI_WAITFOREORx(); \
00128 data |= SPI_RXBUF; \
00129 CC2420_SPI_DISABLE(); \
00130 } while(0)
00131
00132 #define CC2420_READ_FIFO_BYTE(data) \
00133 do { \
00134 CC2420_SPI_ENABLE(); \
00135 SPI_WRITE(CC2420_RXFIFO | 0x40); \
00136 (void)SPI_RXBUF; \
00137 SPI_READ(data); \
00138 clock_delay(1); \
00139 CC2420_SPI_DISABLE(); \
00140 } while(0)
00141
00142 #define CC2420_READ_FIFO_BUF(buffer,count) \
00143 do { \
00144 uint8_t i; \
00145 CC2420_SPI_ENABLE(); \
00146 SPI_WRITE(CC2420_RXFIFO | 0x40); \
00147 (void)SPI_RXBUF; \
00148 for(i = 0; i < (count); i++) { \
00149 SPI_READ(((uint8_t *)(buffer))[i]); \
00150 } \
00151 clock_delay(1); \
00152 CC2420_SPI_DISABLE(); \
00153 } while(0)
00154
00155 #define CC2420_WRITE_FIFO_BUF(buffer,count) \
00156 do { \
00157 uint8_t i; \
00158 CC2420_SPI_ENABLE(); \
00159 SPI_WRITE_FAST(CC2420_TXFIFO); \
00160 for(i = 0; i < (count); i++) { \
00161 SPI_WRITE_FAST(((uint8_t *)(buffer))[i]); \
00162 } \
00163 SPI_WAITFORTx_ENDED(); \
00164 CC2420_SPI_DISABLE(); \
00165 } while(0)
00166
00167
00168 #define CC2420_WRITE_RAM(buffer,adr,count) \
00169 do { \
00170 uint8_t i; \
00171 CC2420_SPI_ENABLE(); \
00172 SPI_WRITE_FAST(0x80 | ((adr) & 0x7f)); \
00173 SPI_WRITE_FAST(((adr) >> 1) & 0xc0); \
00174 for(i = 0; i < (count); i++) { \
00175 SPI_WRITE_FAST(((uint8_t*)(buffer))[i]); \
00176 } \
00177 SPI_WAITFORTx_ENDED(); \
00178 CC2420_SPI_DISABLE(); \
00179 } while(0)
00180
00181
00182 #define CC2420_READ_RAM(buffer,adr,count) \
00183 do { \
00184 uint8_t i; \
00185 CC2420_SPI_ENABLE(); \
00186 SPI_WRITE(0x80 | ((adr) & 0x7f)); \
00187 SPI_WRITE((((adr) >> 1) & 0xc0) | 0x20); \
00188 SPI_RXBUF; \
00189 for(i = 0; i < (count); i++) { \
00190 SPI_READ(((uint8_t*)(buffer))[i]); \
00191 } \
00192 CC2420_SPI_DISABLE(); \
00193 } while(0)
00194
00195
00196 #define CC2420_GET_STATUS(s) \
00197 do { \
00198 CC2420_SPI_ENABLE(); \
00199 SPI_WRITE(CC2420_SNOP); \
00200 s = SPI_RXBUF; \
00201 CC2420_SPI_DISABLE(); \
00202 } while (0)
00203
00204 #endif