2009-11-29 08:50:13 +00:00
|
|
|
/*
|
2011-03-18 18:38:08 +00:00
|
|
|
ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
|
2013-02-02 10:58:09 +00:00
|
|
|
2011,2012,2013 Giovanni Di Sirio.
|
2009-11-29 08:50:13 +00:00
|
|
|
|
|
|
|
This file is part of ChibiOS/RT.
|
|
|
|
|
|
|
|
ChibiOS/RT is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
ChibiOS/RT is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2010-02-07 11:11:45 +00:00
|
|
|
* @file templates/spi_lld.h
|
|
|
|
* @brief SPI Driver subsystem low level driver header template.
|
|
|
|
*
|
2010-10-25 18:48:13 +00:00
|
|
|
* @addtogroup SPI
|
2009-11-29 08:50:13 +00:00
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _SPI_LLD_H_
|
|
|
|
#define _SPI_LLD_H_
|
|
|
|
|
2010-11-01 17:29:56 +00:00
|
|
|
#if HAL_USE_SPI || defined(__DOXYGEN__)
|
2009-11-29 08:50:13 +00:00
|
|
|
|
2009-12-19 10:08:08 +00:00
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver constants. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
2009-11-29 08:50:13 +00:00
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver pre-compile time settings. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
2009-12-19 10:08:08 +00:00
|
|
|
/*===========================================================================*/
|
|
|
|
/* Derived constants and error checks. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
2009-11-29 08:50:13 +00:00
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver data structures and types. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
2010-10-11 11:48:03 +00:00
|
|
|
/**
|
|
|
|
* @brief Type of a structure representing an SPI driver.
|
|
|
|
*/
|
|
|
|
typedef struct SPIDriver SPIDriver;
|
2010-10-10 15:14:49 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief SPI notification callback type.
|
|
|
|
*
|
|
|
|
* @param[in] spip pointer to the @p SPIDriver object triggering the
|
|
|
|
* callback
|
|
|
|
*/
|
|
|
|
typedef void (*spicallback_t)(SPIDriver *spip);
|
|
|
|
|
2009-11-29 08:50:13 +00:00
|
|
|
/**
|
2010-02-21 07:24:53 +00:00
|
|
|
* @brief Driver configuration structure.
|
2010-09-07 13:37:22 +00:00
|
|
|
* @note Implementations may extend this structure to contain more,
|
|
|
|
* architecture dependent, fields.
|
2009-11-29 08:50:13 +00:00
|
|
|
*/
|
|
|
|
typedef struct {
|
2010-10-10 15:14:49 +00:00
|
|
|
/**
|
2011-03-18 18:38:08 +00:00
|
|
|
* @brief Operation complete callback.
|
2010-10-10 15:14:49 +00:00
|
|
|
*/
|
2011-03-08 10:09:57 +00:00
|
|
|
spicallback_t end_cb;
|
2010-10-11 11:48:03 +00:00
|
|
|
/* End of the mandatory fields.*/
|
2009-11-29 08:50:13 +00:00
|
|
|
} SPIConfig;
|
|
|
|
|
|
|
|
/**
|
2010-09-07 13:37:22 +00:00
|
|
|
* @brief Structure representing an SPI driver.
|
|
|
|
* @note Implementations may extend this structure to contain more,
|
|
|
|
* architecture dependent, fields.
|
2009-11-29 08:50:13 +00:00
|
|
|
*/
|
2010-10-11 11:48:03 +00:00
|
|
|
struct SPIDriver {
|
2009-11-29 08:50:13 +00:00
|
|
|
/**
|
2010-02-21 07:24:53 +00:00
|
|
|
* @brief Driver state.
|
2009-11-29 08:50:13 +00:00
|
|
|
*/
|
2011-03-08 10:09:57 +00:00
|
|
|
spistate_t state;
|
2010-10-12 15:19:15 +00:00
|
|
|
/**
|
|
|
|
* @brief Current configuration data.
|
|
|
|
*/
|
2011-03-08 10:09:57 +00:00
|
|
|
const SPIConfig *config;
|
2010-10-10 16:28:34 +00:00
|
|
|
#if SPI_USE_WAIT || defined(__DOXYGEN__)
|
|
|
|
/**
|
2011-03-18 18:38:08 +00:00
|
|
|
* @brief Waiting thread.
|
2010-10-10 16:28:34 +00:00
|
|
|
*/
|
2011-03-08 10:09:57 +00:00
|
|
|
Thread *thread;
|
2010-10-10 16:28:34 +00:00
|
|
|
#endif /* SPI_USE_WAIT */
|
2009-11-29 08:50:13 +00:00
|
|
|
#if SPI_USE_MUTUAL_EXCLUSION || defined(__DOXYGEN__)
|
|
|
|
#if CH_USE_MUTEXES || defined(__DOXYGEN__)
|
|
|
|
/**
|
|
|
|
* @brief Mutex protecting the bus.
|
|
|
|
*/
|
2011-03-08 10:09:57 +00:00
|
|
|
Mutex mutex;
|
2009-11-29 08:50:13 +00:00
|
|
|
#elif CH_USE_SEMAPHORES
|
2011-03-08 10:09:57 +00:00
|
|
|
Semaphore semaphore;
|
2009-11-29 08:50:13 +00:00
|
|
|
#endif
|
|
|
|
#endif /* SPI_USE_MUTUAL_EXCLUSION */
|
2010-10-11 11:48:03 +00:00
|
|
|
#if defined(SPI_DRIVER_EXT_FIELDS)
|
|
|
|
SPI_DRIVER_EXT_FIELDS
|
|
|
|
#endif
|
2009-11-29 08:50:13 +00:00
|
|
|
/* End of the mandatory fields.*/
|
2010-10-11 11:48:03 +00:00
|
|
|
};
|
2009-11-29 08:50:13 +00:00
|
|
|
|
2009-12-29 11:12:05 +00:00
|
|
|
/*===========================================================================*/
|
|
|
|
/* Driver macros. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
2009-11-29 08:50:13 +00:00
|
|
|
/*===========================================================================*/
|
|
|
|
/* External declarations. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
void spi_lld_init(void);
|
|
|
|
void spi_lld_start(SPIDriver *spip);
|
|
|
|
void spi_lld_stop(SPIDriver *spip);
|
|
|
|
void spi_lld_select(SPIDriver *spip);
|
|
|
|
void spi_lld_unselect(SPIDriver *spip);
|
|
|
|
void spi_lld_ignore(SPIDriver *spip, size_t n);
|
|
|
|
void spi_lld_exchange(SPIDriver *spip, size_t n,
|
|
|
|
const void *txbuf, void *rxbuf);
|
|
|
|
void spi_lld_send(SPIDriver *spip, size_t n, const void *txbuf);
|
|
|
|
void spi_lld_receive(SPIDriver *spip, size_t n, void *rxbuf);
|
2010-10-30 11:18:28 +00:00
|
|
|
uint16_t spi_lld_polled_exchange(SPIDriver *spip, uint16_t frame);
|
2009-11-29 08:50:13 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-11-01 17:29:56 +00:00
|
|
|
#endif /* HAL_USE_SPI */
|
2009-11-29 08:50:13 +00:00
|
|
|
|
|
|
|
#endif /* _SPI_LLD_H_ */
|
|
|
|
|
|
|
|
/** @} */
|