Contiki 3.x
board-spi.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014, Texas Instruments Incorporated - http://www.ti.com/
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 copyright holder nor the names of its
14  * contributors may be used to endorse or promote products derived
15  * from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
20  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
28  * OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 /*---------------------------------------------------------------------------*/
31 /**
32  * \addtogroup cc26xx-srf-tag
33  * @{
34  *
35  * \defgroup common-cc26xx-peripherals CC13xx/CC26xx peripheral driver pool
36  *
37  * Drivers for peripherals present on more than one CC13xx/CC26xx board. For
38  * example, the same external flash driver is used for both the part found on
39  * the Sensortag as well as the part on the LaunchPad.
40  *
41  * @{
42  *
43  * \defgroup sensortag-cc26xx-spi SensorTag/LaunchPad SPI functions
44  * @{
45  *
46  * \file
47  * Header file for the Sensortag/LaunchPad SPI Driver
48  */
49 /*---------------------------------------------------------------------------*/
50 #ifndef BOARD_SPI_H_
51 #define BOARD_SPI_H_
52 /*---------------------------------------------------------------------------*/
53 #include <stdlib.h>
54 #include <stdint.h>
55 #include <stdbool.h>
56 /*---------------------------------------------------------------------------*/
57 /**
58  * \brief Initialize the SPI interface
59  * \param bit_rate The bit rate to use
60  * \param clk_pin The IOID for the clock pin. This can be IOID_0 etc
61  * \return none
62  *
63  * This function will make sure the peripheral is powered, clocked and
64  * initialised. A chain of calls to board_spi_read(), board_spi_write() and
65  * board_spi_flush() must be preceded by a call to this function. It is
66  * recommended to call board_spi_close() after such chain of calls.
67  */
68 void board_spi_open(uint32_t bit_rate, uint32_t clk_pin);
69 
70 /**
71  * \brief Close the SPI interface
72  * \return True when successful.
73  *
74  * This function will stop clocks to the SSI module and will set MISO, MOSI
75  * and CLK to a low leakage state. It is recommended to call this function
76  * after a chain of calls to board_spi_read() and board_spi_write()
77  */
78 void board_spi_close(void);
79 
80 /**
81  * \brief Clear data from the SPI interface
82  * \return none
83  */
84 void board_spi_flush(void);
85 
86 /**
87  * \brief Read from an SPI device
88  * \param buf The buffer to store data
89  * \param length The number of bytes to read
90  * \return True when successful.
91  *
92  * Calls to this function must be preceded by a call to board_spi_open(). It is
93  * recommended to call board_spi_close() at the end of an operation.
94  */
95 bool board_spi_read(uint8_t *buf, size_t length);
96 
97 /**
98  * \brief Write to an SPI device
99  * \param buf The buffer with the data to write
100  * \param length The number of bytes to write
101  * \return True when successful.
102  *
103  * Calls to this function must be preceded by a call to board_spi_open(). It is
104  * recommended to call board_spi_close() at the end of an operation.
105  */
106 bool board_spi_write(const uint8_t *buf, size_t length);
107 /*---------------------------------------------------------------------------*/
108 #endif /* BOARD_SPI_H_ */
109 /*---------------------------------------------------------------------------*/
110 /**
111  * @}
112  * @}
113  * @}
114  */
void board_spi_close()
Close the SPI interface.
Definition: board-spi.c:145
bool board_spi_write(const uint8_t *buf, size_t len)
Write to an SPI device.
Definition: board-spi.c:64
bool board_spi_read(uint8_t *buf, size_t len)
Read from an SPI device.
Definition: board-spi.c:83
void board_spi_open(uint32_t bit_rate, uint32_t clk_pin)
Initialize the SPI interface.
Definition: board-spi.c:116
void board_spi_flush()
Clear data from the SPI interface.
Definition: board-spi.c:105