Added initial support for board=apimote2
[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 #ifndef _GNU_ASSEMBLER_
12 #include <msp430.h>
13 #endif
14
15 //LED on P5.4 (LED1 red)
16 #define PLEDOUT P5OUT
17 #define PLEDDIR P5DIR
18 #define PLEDPIN BIT4
19 //LED on P5.5 (LED2 green)
20 #define PLED2OUT P5OUT
21 #define PLED2DIR P5DIR
22 #define PLED2PIN BIT5
23 //LED on P5.6 (LED3 blue)
24 #define PLED3OUT P5OUT
25 #define PLED3DIR P5DIR
26 #define PLED3PIN BIT6
27
28
29 #define SPIOUT P3OUT
30 #define SPIDIR P3DIR
31 #define SPIIN  P3IN
32 #define SPIREN P3REN
33
34 /* INITPLATFORM         PX.7  PX.6  PX.5  PX.4  PX.3  PX.2  PX.1  PX.0
35                         HUM   HUM   HUM   RGIO1 RGIO0 PDVCC UART1TX PKT_INT
36   P1DIR = 0xe0 11100000 Out   Out   Out   In    In    In    In    In
37   P1OUT = 0x00                                              Out??
38                         UsrInt GIO3 NC    1Wire GIO2 UART1RX GIO1 GIO0
39   P2DIR = 0x7b 01111011 In    Out   Out   Out   Out   In    Out   Out
40   P2OUT = 0x10 00010000                   Hi
41                         U1RX  U1TX  U0RX  U0TX  RSCLK R_SO  R_SI  NC
42   P3DIR = 0xf1 11110001 Out   Out   Out   Out   In    In    In    Out
43   P3OUT = 0x00
44                         FHold RRST RVREFEN F_CS NC    R_CS  R_SFD NC
45   P4DIR = 0xfd 11111101 Out   Out   Out   Out   Out   Out   In    Out
46   P4OUT = 0xfd 11111101 Hi    Hi    Hi    Hi    Hi    Hi    Lo    Hi
47                         SVSoutLED3  LED2  LED1  NC    NC    NC    NC
48   P5DIR = 0xff 11111111 Out   Out   Out   Out   Out   Out   Out   Out
49   P5OUT = 0xff 11111111 Hi    Hi    Hi    Hi    Hi    Hi    Hi    Hi
50                         SVSin DAC0  ADC5  ADC4  ADC3  ADC2  ADC1  ADC0
51   P6DIR = 0xff 11111111 Out   Out   Out   Out   Out   Out   Out   Out
52   P6OUT = 0x00
53 */
54
55 /* For the radio to be used:
56    4.6 (!RST) must be low
57    4.5 (VREF_EN) must be high
58    4.2 (!CS) must be low for the transaction.
59 */
60
61 #define INITPLATFORM \
62   P1DIR = 0xe0;\
63   P1OUT = 0x00;\
64   P2DIR = 0x7b;\
65   P2OUT = 0x10;\
66   P3DIR = 0xf1;\
67   P3OUT = 0x00;\
68   P4DIR = 0xfd;\
69   P4OUT = 0xFd;\
70   P5DIR = 0xff;\
71   P5OUT = 0xff;\
72   P6DIR = 0xff;\
73   P6OUT = 0x00;
74
75 //Radio CS is P4.2
76 #define SETSS P4OUT|=BIT2
77 #define CLRSS P4OUT&=~BIT2
78 #define DIRSS P4DIR|=BIT2
79
80 //Flash CS is P4.4, redefine only for the SPI app.
81 #ifdef SPIAPPLICATION
82 #undef SETSS
83 #undef CLRSS
84 #undef DIRSS
85 #define SETSS P4OUT|=BIT4
86 #define CLRSS P4OUT&=~BIT4
87 #define DIRSS P4DIR|=BIT4
88 #endif
89
90 //CC2420 Chip Enable
91 #define SETCE P4OUT|=BIT6
92 #define CLRCE P4OUT&=~BIT6
93 #define DIRCE P4DIR|=BIT6
94
95 //CC2420 signals
96 #define SFD   (P4IN&BIT1)
97 #define FIFOP (P1IN&BIT0)
98 #define FIFO  (P1IN&BIT3)
99
100
101 // network byte order converters
102 #define htons(x) ((((uint16_t)(x) & 0xFF00) >> 8) | \
103                                  (((uint16_t)(x) & 0x00FF) << 8))
104 #define htonl(x) ((((uint32_t)(x) & 0xFF000000) >> 24) | \
105                                   (((uint32_t)(x) & 0x00FF0000) >> 8) | \
106                                   (((uint32_t)(x) & 0x0000FF00) << 8) | \
107                                   (((uint32_t)(x) & 0x000000FF) << 24))
108
109 #define ntohs htons
110 #define ntohl htonl
111