8fb28572d9af3c73eabe822fbc3f251905f0071b
[goodfet] / firmware / platforms / z1.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
35 /* For the radio to be used:
36    4.6 (!RST) must be low
37    4.5 (VREF_EN) must be high
38    4.2 (!CS) must be low for the transaction.
39 */
40
41 #define INITPLATFORM \
42   P1DIR = 0xe0;\
43   P1OUT = 0x00;\
44   P2DIR = 0x7b;\
45   P2OUT = 0x10;\
46   P3DIR = 0xf1;\
47   P3OUT = 0x00;\
48   P4DIR = 0xfd;\
49   P4OUT = 0xFd;\
50   P5DIR = 0xff;\
51   P5OUT = 0xff;\
52   P6DIR = 0xff;\
53   P6OUT = 0x00;
54
55 //Radio CS is P4.2
56 #define SETSS P4OUT|=BIT2
57 #define CLRSS P4OUT&=~BIT2
58 #define DIRSS P4DIR|=BIT2
59
60 //Flash CS is P4.4, redefine only for the SPI app.
61 #ifdef SPIAPPLICATION
62 #undef SETSS
63 #undef CLRSS
64 #undef DIRSS
65 #define SETSS P4OUT|=BIT4
66 #define CLRSS P4OUT&=~BIT4
67 #define DIRSS P4DIR|=BIT4
68 #endif
69
70 //CC2420 Chip Enable
71 #define SETCE P4OUT|=BIT6
72 #define CLRCE P4OUT&=~BIT6
73 #define DIRCE P4DIR|=BIT6
74
75 //CC2420 signals
76 #define SFD   (P4IN&BIT1)
77 #define FIFOP (P1IN&BIT0)
78 #define FIFO  (P1IN&BIT3)
79
80 //GPIO Expansion Pins
81 #define GIO0  (P2OUT&BIT0)
82 #define GIO0HIGH P2OUT|=BIT0
83 #define GIO0LOW P2OUT&=~BIT0
84 #define GIO0OUT P2OUT
85 #define GIO0DIR P2DIR
86 #define GIO0PIN BIT0
87
88 // network byte order converters
89 #define htons(x) ((((uint16_t)(x) & 0xFF00) >> 8) | \
90                                  (((uint16_t)(x) & 0x00FF) << 8))
91 #define htonl(x) ((((uint32_t)(x) & 0xFF000000) >> 24) | \
92                                   (((uint32_t)(x) & 0x00FF0000) >> 8) | \
93                                   (((uint32_t)(x) & 0x0000FF00) << 8) | \
94                                   (((uint32_t)(x) & 0x000000FF) << 24))
95
96 #define ntohs htons
97 #define ntohl htonl
98