2009-11-29 08:50:13 +00:00
|
|
|
/*
|
2013-03-30 10:32:37 +00:00
|
|
|
ChibiOS/RT - Copyright (C) 2006-2013 Giovanni Di Sirio
|
2009-11-29 08:50:13 +00:00
|
|
|
|
2013-03-30 10:32:37 +00:00
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
2009-11-29 08:50:13 +00:00
|
|
|
|
2013-03-30 10:32:37 +00:00
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
2009-11-29 08:50:13 +00:00
|
|
|
|
2013-03-30 10:32:37 +00:00
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
2009-11-29 08:50:13 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
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. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
2013-02-25 13:10:39 +00:00
|
|
|
/**
|
|
|
|
* @name Configuration options
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* @brief SPI driver enable switch.
|
|
|
|
* @details If set to @p TRUE the support for SPI1 is included.
|
|
|
|
*/
|
|
|
|
#if !defined(PLATFORM_SPI_USE_SPI1) || defined(__DOXYGEN__)
|
|
|
|
#define PLATFORM_SPI_USE_SPI1 FALSE
|
|
|
|
#endif
|
|
|
|
/** @} */
|
|
|
|
|
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. */
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
2013-02-25 13:10:39 +00:00
|
|
|
#if PLATFORM_SPI_USE_SPI1 && !defined(__DOXYGEN__)
|
|
|
|
extern SPIDriver SPID1;
|
|
|
|
#endif
|
|
|
|
|
2009-11-29 08:50:13 +00:00
|
|
|
#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_ */
|
|
|
|
|
|
|
|
/** @} */
|