Contiki 2.6

platform-conf.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2010, Swedish Institute of Computer Science.
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  * 3. Neither the name of the Institute nor the names of its contributors
00014  *    may be used to endorse or promote products derived from this software
00015  *    without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
00018  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
00021  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00022  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00023  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00024  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00025  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00026  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00027  * SUCH DAMAGE.
00028  */
00029 
00030 /**
00031  * \file
00032  *         Platform configuration for the Z1 platform
00033  * \author
00034  *         Joakim Eriksson <joakime@sics.se>
00035  */
00036 
00037 #ifndef __PLATFORM_CONF_H__
00038 #define __PLATFORM_CONF_H__
00039 
00040 /*
00041  * Definitions below are dictated by the hardware and not really
00042  * changeable!
00043  */
00044 #define ZOLERTIA_Z1 1  /* Enric */
00045 
00046 #define PLATFORM_HAS_LEDS   1
00047 #define PLATFORM_HAS_BUTTON 1
00048 
00049 /* CPU target speed in Hz */
00050 #define F_CPU 8000000uL /* 8MHz by default */
00051 //Enric #define F_CPU 3900000uL /*2457600uL*/
00052 
00053 /* Our clock resolution, this is the same as Unix HZ. */
00054 #define CLOCK_CONF_SECOND 128UL
00055 
00056 #define BAUD2UBR(baud) ((F_CPU/baud))
00057 
00058 #define CCIF
00059 #define CLIF
00060 
00061 #define HAVE_STDINT_H
00062 #include "msp430def.h"
00063 
00064 /* XXX Temporary place for defines that are lacking in mspgcc4's gpio.h */
00065 #ifdef __IAR_SYSTEMS_ICC__
00066 #ifndef P1SEL2_
00067 #define P1SEL2_              (0x0041u)  /* Port 1 Selection 2*/
00068 DEFC(   P1SEL2             , P1SEL2_)
00069 #endif
00070 #ifndef P5SEL2_
00071 #define P5SEL2_              (0x0045u)  /* Port 5 Selection 2*/
00072 DEFC(   P5SEL2             , P5SEL2_)
00073 #endif
00074 #else /* __IAR_SYSTEMS_ICC__ */
00075 #ifdef __GNUC__
00076 #ifndef P1SEL2_
00077   #define P1SEL2_             0x0041  /* Port 1 Selection 2*/
00078   sfrb(P1SEL2, P1SEL2_);
00079 #endif
00080 #ifndef P5SEL2_
00081   #define P5SEL2_             0x0045  /* Port 5 Selection 2*/
00082   sfrb(P5SEL2, P5SEL2_);
00083 #endif
00084 #endif /* __GNUC__ */
00085 #endif /* __IAR_SYSTEMS_ICC__ */
00086 
00087 /* Types for clocks and uip_stats */
00088 typedef unsigned short uip_stats_t;
00089 typedef unsigned long clock_time_t;
00090 typedef unsigned long off_t;
00091 
00092 /* the low-level radio driver */
00093 #define NETSTACK_CONF_RADIO   cc2420_driver
00094 
00095 /*
00096  * Definitions below are dictated by the hardware and not really
00097  * changeable!
00098  */
00099 
00100 /* LED ports */
00101 #define LEDS_PxDIR P5DIR
00102 #define LEDS_PxOUT P5OUT
00103 #define LEDS_CONF_RED    0x10
00104 #define LEDS_CONF_GREEN  0x40
00105 #define LEDS_CONF_YELLOW 0x20
00106 
00107 /* DCO speed resynchronization for more robust UART, etc. */
00108 #define DCOSYNCH_CONF_ENABLED 0
00109 #define DCOSYNCH_CONF_PERIOD 30
00110 
00111 #define ROM_ERASE_UNIT_SIZE  512
00112 #define XMEM_ERASE_UNIT_SIZE (64*1024L)
00113 
00114 
00115 #define CFS_CONF_OFFSET_TYPE    long
00116 
00117 /* Use the first 64k of external flash for node configuration */
00118 #define NODE_ID_XMEM_OFFSET     (0 * XMEM_ERASE_UNIT_SIZE)
00119 
00120 /* Use the second 64k of external flash for codeprop. */
00121 #define EEPROMFS_ADDR_CODEPROP  (1 * XMEM_ERASE_UNIT_SIZE)
00122 
00123 #define CFS_XMEM_CONF_OFFSET    (2 * XMEM_ERASE_UNIT_SIZE)
00124 #define CFS_XMEM_CONF_SIZE      (1 * XMEM_ERASE_UNIT_SIZE)
00125 
00126 #define CFS_RAM_CONF_SIZE 4096
00127 
00128 /*
00129  * SPI bus configuration for the TMote Sky.
00130  */
00131 
00132 /* SPI input/output registers. */
00133 #define SPI_TXBUF UCB0TXBUF
00134 #define SPI_RXBUF UCB0RXBUF
00135 
00136                                 /* USART0 Tx ready? */
00137 #define SPI_WAITFOREOTx() while ((UCB0STAT & UCBUSY) != 0)
00138                                 /* USART0 Rx ready? */
00139 #define SPI_WAITFOREORx() while ((IFG2 & UCB0RXIFG) == 0)
00140                                 /* USART0 Tx buffer ready? */
00141 #define SPI_WAITFORTxREADY() while ((IFG2 & UCB0TXIFG) == 0)
00142 
00143 #define MOSI           1  /* P3.1 - Output: SPI Master out - slave in (MOSI) */
00144 #define MISO           2  /* P3.2 - Input:  SPI Master in - slave out (MISO) */
00145 #define SCK            3  /* P3.3 - Output: SPI Serial Clock (SCLK) */
00146 
00147 /*
00148  * SPI bus - M25P80 external flash configuration.
00149  */
00150 //#define FLASH_PWR     3       /* P4.3 Output */ ALWAYS POWERED ON Z1
00151 #define FLASH_CS        4       /* P4.4 Output */
00152 #define FLASH_HOLD      7       /* P5.7 Output */
00153 
00154 /* Enable/disable flash access to the SPI bus (active low). */
00155 
00156 #define SPI_FLASH_ENABLE()  ( P4OUT &= ~BV(FLASH_CS) )
00157 #define SPI_FLASH_DISABLE() ( P4OUT |=  BV(FLASH_CS) )
00158 
00159 #define SPI_FLASH_HOLD()                ( P5OUT &= ~BV(FLASH_HOLD) )
00160 #define SPI_FLASH_UNHOLD()              ( P5OUT |=  BV(FLASH_HOLD) )
00161 
00162 
00163 /*
00164  * SPI bus - CC2420 pin configuration.
00165  */
00166 
00167 #define CC2420_CONF_SYMBOL_LOOP_COUNT 1302      /* 326us msp430X @ 8MHz */
00168 
00169 /* P1.2 - Input: FIFOP from CC2420 */
00170 #define CC2420_FIFOP_PORT(type)   P1##type
00171 #define CC2420_FIFOP_PIN          2
00172 /* P1.3 - Input: FIFO from CC2420 */
00173 #define CC2420_FIFO_PORT(type)     P1##type
00174 #define CC2420_FIFO_PIN            3
00175 /* P1.4 - Input: CCA from CC2420 */
00176 #define CC2420_CCA_PORT(type)      P1##type
00177 #define CC2420_CCA_PIN             4
00178 /* P4.1 - Input:  SFD from CC2420 */
00179 #define CC2420_SFD_PORT(type)      P4##type
00180 #define CC2420_SFD_PIN             1
00181  /* P3.0 - Output: SPI Chip Select (CS_N) */
00182 #define CC2420_CSN_PORT(type)      P3##type
00183 #define CC2420_CSN_PIN             0
00184 /* P4.5 - Output: VREG_EN to CC2420 */
00185 #define CC2420_VREG_PORT(type)     P4##type
00186 #define CC2420_VREG_PIN            5
00187 /* P4.6 - Output: RESET_N to CC2420 */
00188 #define CC2420_RESET_PORT(type)    P4##type
00189 #define CC2420_RESET_PIN           6
00190 
00191 
00192 #define CC2420_IRQ_VECTOR PORT1_VECTOR
00193 
00194 /* Pin status. */
00195 #define CC2420_FIFOP_IS_1 (!!(CC2420_FIFOP_PORT(IN) & BV(CC2420_FIFOP_PIN)))
00196 #define CC2420_FIFO_IS_1  (!!(CC2420_FIFO_PORT(IN) & BV(CC2420_FIFO_PIN)))
00197 #define CC2420_CCA_IS_1   (!!(CC2420_CCA_PORT(IN) & BV(CC2420_CCA_PIN)))
00198 #define CC2420_SFD_IS_1   (!!(CC2420_SFD_PORT(IN) & BV(CC2420_SFD_PIN)))
00199 
00200 /* The CC2420 reset pin. */
00201 #define SET_RESET_INACTIVE()   (CC2420_RESET_PORT(OUT) |=  BV(CC2420_RESET_PIN))
00202 #define SET_RESET_ACTIVE()     (CC2420_RESET_PORT(OUT) &= ~BV(CC2420_RESET_PIN))
00203 
00204 /* CC2420 voltage regulator enable pin. */
00205 #define SET_VREG_ACTIVE()       (CC2420_VREG_PORT(OUT) |=  BV(CC2420_VREG_PIN))
00206 #define SET_VREG_INACTIVE()     (CC2420_VREG_PORT(OUT) &= ~BV(CC2420_VREG_PIN))
00207 
00208 /* CC2420 rising edge trigger for external interrupt 0 (FIFOP). */
00209 #define CC2420_FIFOP_INT_INIT() do {                  \
00210     CC2420_FIFOP_PORT(IES) &= ~BV(CC2420_FIFOP_PIN);  \
00211     CC2420_CLEAR_FIFOP_INT();                         \
00212   } while(0)
00213 
00214 /* FIFOP on external interrupt 0. */
00215 #define CC2420_ENABLE_FIFOP_INT()  do {CC2420_FIFOP_PORT(IE) |= BV(CC2420_FIFOP_PIN);} while(0)
00216 #define CC2420_DISABLE_FIFOP_INT() do {CC2420_FIFOP_PORT(IE) &= ~BV(CC2420_FIFOP_PIN);} while(0)
00217 #define CC2420_CLEAR_FIFOP_INT()   do {CC2420_FIFOP_PORT(IFG) &= ~BV(CC2420_FIFOP_PIN);} while(0)
00218 
00219 /*
00220  * Enables/disables CC2420 access to the SPI bus (not the bus).
00221  * (Chip Select)
00222  */
00223 
00224  /* ENABLE CSn (active low) */
00225 #define CC2420_SPI_ENABLE()     (CC2420_CSN_PORT(OUT) &= ~BV(CC2420_CSN_PIN))
00226  /* DISABLE CSn (active low) */
00227 #define CC2420_SPI_DISABLE()    (CC2420_CSN_PORT(OUT) |=  BV(CC2420_CSN_PIN))
00228 #define CC2420_SPI_IS_ENABLED() ((CC2420_CSN_PORT(OUT) & BV(CC2420_CSN_PIN)) != BV(CC2420_CSN_PIN))
00229 
00230 #endif /* __PLATFORM_CONF_H__ */