Contiki-NG
mmc-arch.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016, Benoît Thébaudeau <benoit@wsystem.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 are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  *
15  * 3. Neither the name of the copyright holder nor the names of its contributors
16  * may be used to endorse or promote products derived from this software
17  * without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 /**
32  * \addtogroup mmc
33  * @{
34  *
35  * \defgroup mmc-arch SD/MMC architecture-specific definitions
36  *
37  * SD/MMC device driver architecture-specific definitions.
38  * @{
39  *
40  * \file
41  * Header file for the SD/MMC device driver architecture-specific definitions.
42  */
43 #ifndef MMC_ARCH_H_
44 #define MMC_ARCH_H_
45 
46 #include <stddef.h>
47 #include <stdbool.h>
48 #include <stdint.h>
49 
50 /** \brief Callback of the SD/MMC driver to call when the card-detection signal
51  * changes.
52  * \param dev Device
53  * \param cd Whether a card is detected
54  * \note Using this function is not mandatory. This only allows to detect a card
55  * replacement between two successive calls to the SD/MMC driver API.
56  */
57 void mmc_arch_cd_changed_callback(uint8_t dev, bool cd);
58 
59 /** \brief Gets the state of the card-detection signal.
60  * \param dev Device
61  * \return Whether a card is detected
62  */
63 bool mmc_arch_get_cd(uint8_t dev);
64 
65 /** \brief Gets the state of the write-protection signal.
66  * \param dev Device
67  * \return Whether the card is write-protected
68  */
69 bool mmc_arch_get_wp(uint8_t dev);
70 
71 /** \brief Sets the SPI /CS signal as indicated.
72  * \param dev Device
73  * \param sel Whether to assert /CS
74  */
75 void mmc_arch_spi_select(uint8_t dev, bool sel);
76 
77 /** \brief Sets the SPI clock frequency.
78  * \param dev Device
79  * \param freq Frequency (Hz)
80  */
81 void mmc_arch_spi_set_clock_freq(uint8_t dev, uint32_t freq);
82 
83 /** \brief Performs an SPI transfer.
84  * \param dev Device
85  * \param tx_buf Pointer to the transmission buffer, or \c NULL
86  * \param tx_cnt Number of bytes to transmit, or \c 0
87  * \param rx_buf Pointer to the reception buffer, or \c NULL
88  * \param rx_cnt Number of bytes to receive, or \c 0
89  */
90 void mmc_arch_spi_xfer(uint8_t dev, const void *tx_buf, size_t tx_cnt,
91  void *rx_buf, size_t rx_cnt);
92 
93 #endif /* MMC_ARCH_H_ */
94 
95 /**
96  * @}
97  * @}
98  */
bool mmc_arch_get_wp(uint8_t dev)
Gets the state of the write-protection signal.
Definition: mmc-arch.c:92
bool mmc_arch_get_cd(uint8_t dev)
Gets the state of the card-detection signal.
Definition: mmc-arch.c:73
void mmc_arch_spi_select(uint8_t dev, bool sel)
Sets the SPI /CS signal as indicated.
Definition: mmc-arch.c:98
void mmc_arch_spi_set_clock_freq(uint8_t dev, uint32_t freq)
Sets the SPI clock frequency.
Definition: mmc-arch.c:108
void mmc_arch_cd_changed_callback(uint8_t dev, bool cd)
Callback of the SD/MMC driver to call when the card-detection signal changes.
Definition: mmc.c:312
void mmc_arch_spi_xfer(uint8_t dev, const void *tx_buf, size_t tx_cnt, void *rx_buf, size_t rx_cnt)
Performs an SPI transfer.
Definition: mmc-arch.c:114