Contiki 3.x
Communication.h
1 /*
2  * Copyright (c) 2014, Analog Devices, Inc.
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  *
14  * 3. Neither the name of the copyright holder nor the names of its
15  * contributors may be used to endorse or promote products derived
16  * from this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
27  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
29  * OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31 /**
32  * \author Dragos Bogdan <Dragos.Bogdan@Analog.com>
33  */
34 
35 #ifndef __COMMUNICATION_H__
36 #define __COMMUNICATION_H__
37 
38 /******************************************************************************/
39 /*************************** Macros Definitions *******************************/
40 /******************************************************************************/
41 #define SPI_MISO PMOD1_MISO
42 
43 #define GPIO1_PIN_OUT PMOD1_GPIO1_PIN_OUT
44 #define GPIO1_LOW PMOD1_GPIO1_LOW
45 #define GPIO1_HIGH PMOD1_GPIO1_HIGH
46 
47 #define GPIO2_PIN_OUT PMOD1_GPIO2_PIN_OUT
48 #define GPIO2_LOW PMOD1_GPIO2_LOW
49 #define GPIO2_HIGH PMOD1_GPIO2_HIGH
50 
51 #define GPIO3_PIN_OUT PMOD1_GPIO3_PIN_OUT
52 #define GPIO3_LOW PMOD1_GPIO3_LOW
53 #define GPIO3_HIGH PMOD1_GPIO3_HIGH
54 
55 #define GPIO4_PIN_OUT PMOD1_GPIO4_PIN_OUT
56 #define GPIO4_LOW PMOD1_GPIO4_LOW
57 #define GPIO4_HIGH PMOD1_GPIO4_HIGH
58 
59 /******************************************************************************/
60 /************************ Functions Declarations ******************************/
61 /******************************************************************************/
62 
63 enum CSI_Bus {
64  CSI00,
65  CSI01,
66  CSI10,
67  CSI11,
68  CSI20,
69  CSI21,
70  CSI30,
71  CSI31,
72 };
73 
74 /*! Initializes the SPI communication peripheral. */
75 char SPI_Init(enum CSI_Bus bus,
76  char lsbFirst,
77  long clockFreq,
78  char clockPol,
79  char clockEdg);
80 
81 /*! Writes data to SPI. */
82 char SPI_Write(enum CSI_Bus bus,
83  char slaveDeviceId,
84  unsigned char *data,
85  char bytesNumber);
86 
87 /*! Reads data from SPI. */
88 char SPI_Read(enum CSI_Bus bus,
89  char slaveDeviceId,
90  unsigned char *data,
91  char bytesNumber);
92 
93 /*! Initializes the I2C communication peripheral. */
94 char I2C_Init(long clockFreq);
95 
96 /*! Writes data to a slave device. */
97 char I2C_Write(char slaveAddress,
98  unsigned char *dataBuffer,
99  char bytesNumber,
100  char stopBit);
101 
102 /*! Reads data from a slave device. */
103 char I2C_Read(char slaveAddress,
104  unsigned char *dataBuffer,
105  char bytesNumber,
106  char stopBit);
107 
108 #endif /* __COMMUNICATION_H__ */