Improving CC2420 packet reception.
[goodfet] / firmware / platforms / telosb.h
1 /*! \file telosb.h
2   \author Travis Goodspeed
3   \brief Port descriptions for the TelosB platform.
4   
5   This file defines the Telos B hardware, so that the GoodFET firmware
6   may be loaded onto it.  Adjustments include the !CS line of the CC2420
7   radio, the choice of serial port, and the LEDs.
8
9 */
10
11 #ifdef MSP430
12 #include <io.h>
13 #endif
14
15 //LED on P5.4
16 #define PLEDOUT P5OUT
17 #define PLEDDIR P5DIR
18 #define PLEDPIN BIT4
19
20
21 #define SPIOUT P3OUT
22 #define SPIDIR P3DIR
23 #define SPIIN  P3IN
24 #define SPIREN P3REN
25
26
27 /* For the radio to be used:
28    4.6 (!RST) must be low
29    4.5 (VREF_EN) must be high
30    4.2 (!CS) must be low for the transaction.
31 */
32
33 #define INITPLATFORM \
34   P1DIR = 0xe0;\
35   P1OUT = 0x00;\
36   P2DIR = 0x7b;\
37   P2OUT = 0x10;\
38   P3DIR = 0xf1;\
39   P3OUT = 0x00;\
40   P4DIR = 0xfd;\
41   P4OUT = 0xFd;\
42   P5DIR = 0xff;\
43   P5OUT = 0xff;\
44   P6DIR = 0xff;\
45   P6OUT = 0x00;
46
47 //Radio CS is P4.2
48 #define SETSS P4OUT|=BIT2
49 #define CLRSS P4OUT&=~BIT2
50 #define DIRSS P4DIR|=BIT2
51
52
53 //Flash CS is P4.4, redefine only for the SPI app.
54 #ifdef SPIAPPLICATION
55 #undef SETSS
56 #undef CLRSS
57 #undef DIRSS
58 #define SETSS P4OUT|=BIT4
59 #define CLRSS P4OUT&=~BIT4
60 #define DIRSS P4DIR|=BIT4
61 #endif
62
63 //CC2420 Chip Enable
64 #define SETCE P4OUT|=BIT6
65 #define CLRCE P4OUT&=~BIT6
66 #define DIRCE P4DIR|=BIT6
67
68 //CC2420 signals
69 #define SFD   (P4IN&BIT1)
70 #define FIFOP (P4IN&BIT0) 
71
72 // network byte order converters
73 #define htons(x) ((((uint16_t)(x) & 0xFF00) >> 8) | \
74                                  (((uint16_t)(x) & 0x00FF) << 8))
75 #define htonl(x) ((((uint32_t)(x) & 0xFF000000) >> 24) | \
76                                   (((uint32_t)(x) & 0x00FF0000) >> 8) | \
77                                   (((uint32_t)(x) & 0x0000FF00) << 8) | \
78                                   (((uint32_t)(x) & 0x000000FF) << 24))
79
80 #define ntohs htons
81 #define ntohl htonl
82