Contiki 3.x
platform-conf.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010, Swedish Institute of Computer Science.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * 3. Neither the name of the Institute nor the names of its contributors
14  * may be used to endorse or promote products derived from this software
15  * without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  *
29  */
30 
31 /**
32  * \file
33  * A brief description of what this file is
34  * \author
35  * Niclas Finne <nfi@sics.se>
36  * Joakim Eriksson <joakime@sics.se>
37  */
38 
39 #ifndef PLATFORM_CONF_H_
40 #define PLATFORM_CONF_H_
41 
42 /*
43  * Definitions below are dictated by the hardware and not really
44  * changeable!
45  */
46  /* Platform name, type, and MCU clock rate */
47 #define PLATFORM_NAME "MicaZ"
48 #define PLATFORM_TYPE MICAZ
49 #ifndef F_CPU
50 #define F_CPU 7372800UL
51 #endif
52 
53 /* The AVR tick interrupt usually is done with an 8 bit counter around 128 Hz.
54  * 125 Hz needs slightly more overhead during the interrupt, as does a 32 bit
55  * clock_time_t.
56  */
57  /* Clock ticks per second */
58 #define CLOCK_CONF_SECOND 128
59 #if 1
60 /* 16 bit counter overflows every ~10 minutes */
61 typedef unsigned short clock_time_t;
62 #define CLOCK_LT(a,b) ((signed short)((a)-(b)) < 0)
63 #define INFINITE_TIME 0xffff
64 #define RIME_CONF_BROADCAST_ANNOUNCEMENT_MAX_TIME INFINITE_TIME/CLOCK_CONF_SECOND /* Default uses 600 */
65 #define COLLECT_CONF_BROADCAST_ANNOUNCEMENT_MAX_TIME INFINITE_TIME/CLOCK_CONF_SECOND /* Default uses 600 */
66 #else
67 typedef unsigned long clock_time_t;
68 #define CLOCK_LT(a,b) ((signed long)((a)-(b)) < 0)
69 #define INFINITE_TIME 0xffffffff
70 #endif
71 /* These routines are not part of the contiki core but can be enabled in cpu/avr/clock.c */
72 void clock_delay_msec(uint16_t howlong);
73 void clock_adjust_ticks(clock_time_t howmany);
74 
75 /* LED ports */
76 #define LEDS_PxDIR DDRA // port direction register
77 #define LEDS_PxOUT PORTA // port register
78 #define LEDS_CONF_RED 0x04 //red led
79 #define LEDS_CONF_GREEN 0x02 // green led
80 #define LEDS_CONF_YELLOW 0x01 // yellow led
81 
82 /* COM port to be used for SLIP connection */
83 #define SLIP_PORT RS232_PORT_0
84 
85 /* Pre-allocated memory for loadable modules heap space (in bytes)*/
86 #define MMEM_CONF_SIZE 256
87 
88 /* Use the following address for code received via the codeprop
89  * facility
90  */
91 #define EEPROMFS_ADDR_CODEPROP 0x8000
92 
93 #define EEPROM_NODE_ID_START 0x00
94 
95 
96 #define NETSTACK_CONF_RADIO cc2420_driver
97 
98 
99 /*
100  * SPI bus configuration for the TMote Sky.
101  */
102 
103 /* SPI input/output registers. */
104 #define SPI_TXBUF SPDR
105 #define SPI_RXBUF SPDR
106 
107 #define BV(bitno) _BV(bitno)
108 
109 #define SPI_WAITFOREOTx() do { while (!(SPSR & BV(SPIF))); } while (0)
110 #define SPI_WAITFOREORx() do { while (!(SPSR & BV(SPIF))); } while (0)
111 
112 #define SCK 1 /* - Output: SPI Serial Clock (SCLK) - ATMEGA128 PORTB, PIN1 */
113 #define MOSI 2 /* - Output: SPI Master out - slave in (MOSI) - ATMEGA128 PORTB, PIN2 */
114 #define MISO 3 /* - Input: SPI Master in - slave out (MISO) - ATMEGA128 PORTB, PIN3 */
115 
116 /*
117  * SPI bus - M25P80 external flash configuration.
118  */
119 
120 #define FLASH_PWR 3 /* P4.3 Output */
121 #define FLASH_CS 4 /* P4.4 Output */
122 #define FLASH_HOLD 7 /* P4.7 Output */
123 
124 /* Enable/disable flash access to the SPI bus (active low). */
125 
126 #define SPI_FLASH_ENABLE() ( P4OUT &= ~BV(FLASH_CS) )
127 #define SPI_FLASH_DISABLE() ( P4OUT |= BV(FLASH_CS) )
128 
129 #define SPI_FLASH_HOLD() ( P4OUT &= ~BV(FLASH_HOLD) )
130 #define SPI_FLASH_UNHOLD() ( P4OUT |= BV(FLASH_HOLD) )
131 
132 /*
133  * SPI bus - CC2420 pin configuration.
134  */
135 
136 #define CC2420_CONF_SYMBOL_LOOP_COUNT 500
137 
138 /*
139  * SPI bus - CC2420 pin configuration.
140  */
141 
142 #define FIFO_P 6
143 #define FIFO 7
144 #define CCA 6
145 
146 #define SFD 4
147 #define CSN 0
148 #define VREG_EN 5
149 #define RESET_N 6
150 
151 
152 /* - Input: FIFOP from CC2420 - ATMEGA128 PORTE, PIN6 */
153 #define CC2420_FIFOP_PORT(type) P##type##E
154 #define CC2420_FIFOP_PIN 6
155 /* - Input: FIFO from CC2420 - ATMEGA128 PORTB, PIN7 */
156 #define CC2420_FIFO_PORT(type) P##type##B
157 #define CC2420_FIFO_PIN 7
158 /* - Input: CCA from CC2420 - ATMEGA128 PORTD, PIN6 */
159 #define CC2420_CCA_PORT(type) P##type##D
160 #define CC2420_CCA_PIN 6
161 /* - Input: SFD from CC2420 - ATMEGA128 PORTD, PIN4 */
162 #define CC2420_SFD_PORT(type) P##type##D
163 #define CC2420_SFD_PIN 4
164 /* - Output: SPI Chip Select (CS_N) - ATMEGA128 PORTB, PIN0 */
165 #define CC2420_CSN_PORT(type) P##type##B
166 #define CC2420_CSN_PIN 0
167 /* - Output: VREG_EN to CC2420 - ATMEGA128 PORTA, PIN5 */
168 #define CC2420_VREG_PORT(type) P##type##A
169 #define CC2420_VREG_PIN 5
170 /* - Output: RESET_N to CC2420 - ATMEGA128 PORTA, PIN6 */
171 #define CC2420_RESET_PORT(type) P##type##A
172 #define CC2420_RESET_PIN 6
173 
174 #define CC2420_IRQ_VECTOR INT6_vect
175 
176 /* Pin status. */
177 #define CC2420_FIFOP_IS_1 (!!(CC2420_FIFOP_PORT(IN) & BV(CC2420_FIFOP_PIN)))
178 #define CC2420_FIFO_IS_1 (!!(CC2420_FIFO_PORT(IN) & BV(CC2420_FIFO_PIN)))
179 #define CC2420_CCA_IS_1 (!!(CC2420_CCA_PORT(IN) & BV(CC2420_CCA_PIN)))
180 #define CC2420_SFD_IS_1 (!!(CC2420_SFD_PORT(IN) & BV(CC2420_SFD_PIN)))
181 
182 /* The CC2420 reset pin. */
183 #define SET_RESET_INACTIVE() (CC2420_RESET_PORT(ORT) |= BV(CC2420_RESET_PIN))
184 #define SET_RESET_ACTIVE() (CC2420_RESET_PORT(ORT) &= ~BV(CC2420_RESET_PIN))
185 
186 /* CC2420 voltage regulator enable pin. */
187 #define SET_VREG_ACTIVE() (CC2420_VREG_PORT(ORT) |= BV(CC2420_VREG_PIN))
188 #define SET_VREG_INACTIVE() (CC2420_VREG_PORT(ORT) &= ~BV(CC2420_VREG_PIN))
189 
190 /* CC2420 rising edge trigger for external interrupt 6 (FIFOP).
191  * Enable the external interrupt request for INT6.
192  * See Atmega128 datasheet about EICRB Register
193  */
194 #define CC2420_FIFOP_INT_INIT() do {\
195  EICRB |= 0x30; \
196  CC2420_CLEAR_FIFOP_INT(); \
197 } while (0)
198 
199 /* FIFOP on external interrupt 6. */
200 #define CC2420_ENABLE_FIFOP_INT() do { EIMSK |= 0x40; } while (0)
201 #define CC2420_DISABLE_FIFOP_INT() do { EIMSK &= ~0x40; } while (0)
202 #define CC2420_CLEAR_FIFOP_INT() do { EIFR = 0x40; } while (0)
203 
204 /*
205  * Enables/disables CC2420 access to the SPI bus (not the bus).
206  * (Chip Select)
207  */
208 #define CC2420_SPI_ENABLE() (PORTB &= ~BV(CSN)) /* ENABLE CSn (active low) */
209 #define CC2420_SPI_DISABLE() (PORTB |= BV(CSN)) /* DISABLE CSn (active low) */
210 
211 #endif /* PLATFORM_CONF_H_ */
void clock_delay_msec(uint16_t howlong)
Delay up to 65535 milliseconds.
Definition: clock.c:260
void clock_adjust_ticks(clock_time_t howmany)
Adjust the system current clock time.
Definition: clock.c:289