Contiki 3.x
mrf24j40_arch.h
Go to the documentation of this file.
1 /*
2  * Contiki SeedEye Platform project
3  *
4  * Copyright (c) 2012,
5  * Scuola Superiore Sant'Anna (http://www.sssup.it) and
6  * Consorzio Nazionale Interuniversitario per le Telecomunicazioni
7  * (http://www.cnit.it).
8  *
9  * All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  * notice, this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  * notice, this list of conditions and the following disclaimer in the
18  * documentation and/or other materials provided with the distribution.
19  * 3. Neither the name of the Institute nor the names of its contributors
20  * may be used to endorse or promote products derived from this software
21  * without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33  * SUCH DAMAGE.
34  *
35  */
36 
37 /**
38  * \addtogroup mrf24j40 MRF24J40 Driver
39  *
40  * @{
41  */
42 
43 /**
44  * \file mrf24j40_arch.h
45  * \brief MRF24J40 Specific Arch Conf
46  * \author Giovanni Pellerano <giovanni.pellerano@evilaliv3.org>
47  * \date 2012-03-21
48  */
49 
50 #ifndef MRF24J40_ARCH_H_
51 #define MRF24J40_ARCH_H_
52 
53 #include "p32xxxx.h"
54 
55 #include <stdint.h>
56 
57 #include "dev/radio.h"
58 
59 /* Pin Mapping */
60 #define MRF24J40_RESETn PORTGbits.RG15
61 #define MRF24J40_INT PORTAbits.RA15
62 #define MRF24J40_CSn PORTFbits.RF12
63 #define MRF24J40_WAKE PORTGbits.RG12
64 
65 /* Pin Tri-States */
66 #define MRF24J40_TRIS_RESETn TRISGbits.TRISG1
67 #define MRF24J40_TRIS_INT TRISAbits.TRISA15
68 #define MRF24J40_TRIS_CSn TRISFbits.TRISF12
69 #define MRF24J40_TRIS_WAKE TRISGbits.TRISG12
70 
71 /* RESET low/high */
72 #define MRF24J40_HARDRESET_LOW() MRF24J40_RESETn = 0
73 #define MRF24J40_HARDRESET_HIGH() MRF24J40_RESETn = 1
74 #define MRF24J40_CSn_LOW() MRF24J40_CSn = 0
75 #define MRF24J40_CSn_HIGH() MRF24J40_CSn = 1
76 
77 /* Spi port Mapping */
78 #ifdef __USE_MRF24J40_SPI_PORT_1__
79 #define MRF24J40_SPI_PORT_INIT pic32_spi1_init
80 #define MRF24J40_SPI_PORT_WRITE pic32_spi1_write
81 #define MRF24J40_SPI_PORT_READ pic32_spi1_read
82 #elif defined __USE_MRF24J40_SPI_PORT_1A__
83 #define MRF24J40_SPI_PORT_INIT pic32_spi1A_init
84 #define MRF24J40_SPI_PORT_WRITE pic32_spi1A_write
85 #define MRF24J40_SPI_PORT_READ pic32_spi1A_read
86 #elif defined __USE_MRF24J40_SPI_PORT_2A__
87 #define MRF24J40_SPI_PORT_INIT pic32_spi2A_init
88 #define MRF24J40_SPI_PORT_WRITE pic32_spi2A_write
89 #define MRF24J40_SPI_PORT_READ pic32_spi2A_read
90 #elif defined __USE_MRF24J40_SPI_PORT_3A__
91 #define MRF24J40_SPI_PORT_INIT pic32_spi3A_init
92 #define MRF24J40_SPI_PORT_WRITE pic32_spi3A_write
93 #define MRF24J40_SPI_PORT_READ pic32_spi3A_read
94 #else
95 #define MRF24J40_SPI_PORT_INIT pic32_spi3A_init
96 #define MRF24J40_SPI_PORT_WRITE pic32_spi3A_write
97 #define MRF24J40_SPI_PORT_READ pic32_spi3A_read
98 #endif
99 
100 /* IRC Configuration */
101 #define MRF24J40_ISR() ISR(_EXTERNAL_4_VECTOR)
102 #define MRF24J40_INTERRUPT_FLAG_SET() IFS0SET = _IFS0_INT4IF_MASK
103 #define MRF24J40_INTERRUPT_FLAG_CLR() IFS0CLR = _IFS0_INT4IF_MASK
104 #define MRF24J40_INTERRUPT_ENABLE_SET() IEC0SET = _IEC0_INT4IE_MASK
105 #define MRF24J40_INTERRUPT_ENABLE_CLR() IEC0CLR = _IEC0_INT4IE_MASK
106 #define MRF24J40_INTERRUPT_ENABLE_STAT() IEC0bits.INT4IE
107 
108 #define MRF24J40_PINDIRECTION_INIT() \
109 do { \
110  MRF24J40_TRIS_RESETn = 0; \
111  MRF24J40_TRIS_INT = 1; \
112  MRF24J40_TRIS_CSn = 0; \
113  MRF24J40_TRIS_WAKE = 0; \
114 } while(0)
115 
116 #define MRF24J40_INTERRUPT_INIT(p, s) \
117 do { \
118  MRF24J40_INTERRUPT_ENABLE_CLR(); \
119  MRF24J40_INTERRUPT_FLAG_CLR(); \
120  INTCONCLR = _INTCON_INT4EP_MASK; \
121  IPC4CLR = _IPC4_INT4IP_MASK | _IPC4_INT4IS_MASK; \
122  IPC4SET = (p << _IPC4_INT4IP_POSITION) | (s << _IPC4_INT4IS_POSITION); \
123  MRF24J40_INTERRUPT_ENABLE_SET(); \
124 } while(0)
125 
126 #endif /* MRF24J40_ARCH_H_ */
127 
128 /** @} */
Header file for the radio API