Update AVR XMEGA SPI low level driver.

git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@14696 27425a3e-05d8-49a3-a47f-9c15f0e5edd8
This commit is contained in:
Theodore Ateba 2021-08-22 09:13:40 +00:00
parent c8ab0b918e
commit e9eb2e7e6a
2 changed files with 48 additions and 103 deletions

View File

@ -1,5 +1,5 @@
/*
ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
ChibiOS - Copyright (C) 2015..2021 Theodore Ateba
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@ -113,7 +113,7 @@ static void spi_set_stransfer_mode(SPI_MODE_t mode) {
case SPI_TRANSFER_MODE1:
SPIC.CTRL = (SPIC.CTRL & ~SPI_MODE_gm) | SPI_MODE_1_gc;
break;
case SPI_TRANSFER_MODE2:
SPIC.CTRL = (SPIC.CTRL & ~SPI_MODE_gm) | SPI_MODE_2_gc;
break;
@ -142,7 +142,7 @@ static void spi_set_clock_prescaler(SPI_PRESCALER_t prescaler) {
case SPI_PRESCALER_16:
SPIC.CTRL = (SPIC.CTRL & ~SPI_PRESCALER_gm) | SPI_PRESCALER_DIV4_gc;
break;
case SPI_PRESCALER_64:
SPIC.CTRL = (SPIC.CTRL & ~SPI_PRESCALER_gm) | SPI_PRESCALER_DIV4_gc;
break;
@ -171,7 +171,7 @@ static void spi_set_clock_prescaler(SPI_PRESCALER_t prescaler) {
case SPI_INT_LEVEL_LOW:
SPIC.INTCTRL = (SPIC.INTCTRL & ~SPI_INTLVL_gm) | SPI_INTLVL_LO_gc;
break;
case SPI_INT_LEVEL_MEDIUM:
SPIC.INTCTRL = (SPIC.INTCTRL & ~SPI_INTLVL_gm) | SPI_INTLVL_MED_gc;
break;
@ -278,7 +278,7 @@ void spi_lld_start(SPIDriver *spip) {
// SPI interrupt disabled,
// SPI enabled,
// SPI master enabled.
spip->spi->INTCTRL = SPI_INTLVL_OFF_gc;
spip->spi->CTRL = (spip->config->clk2x ? SPI_CLK2X_bm : 0) |
@ -370,6 +370,20 @@ void spi_lld_exchange(SPIDriver *spip, size_t n, const void *txbuf, void *rxbuf)
spip->spi->DATA = (spip->txbuf ? spip->txbuf[0] : DUMMY_SPI_SEND_VALUE);
}
#if (SPI_SUPPORTS_CIRCULAR == TRUE) || defined(__DOXYGEN__)
/**
* @brief Aborts the ongoing SPI operation, if any.
*
* @param[in] spip pointer to the @p SPIDriver object
*
* @notapi
*/
void spi_lld_abort(SPIDriver *spip) {
/* Stopping SPI.*/
}
#endif /* SPI_SUPPORTS_CIRCULAR == TRUE */
/**
* @brief Exchanges one frame using a polled wait.

View File

@ -1,5 +1,5 @@
/*
ChibiOS - Copyright (C) 2016..2018 Theodore Ateba
ChibiOS - Copyright (C) 2016..2021 Theodore Ateba
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@ -125,107 +125,34 @@
/* Driver data structures and types. */
/*==========================================================================*/
/**
* @brief Type of a structure representing an SPI driver.
*/
typedef struct SPIDriver SPIDriver;
/**
* @brief SPI notification callback type.
*
* @param[in] spip pointer to the @p SPIDriver object triggering the
* callback
*/
typedef void (*spicallback_t)(SPIDriver *spip);
/**
* @brief Driver configuration structure.
* @note Implementations may extend this structure to contain more,
* architecture dependent, fields.
*/
typedef struct {
/**
* @brief Operation complete callback.
*/
spicallback_t end_cb;
/* End of the mandatory fields. */
/**
* @brief Port used of Slave Select
*/
ioportid_t ssport;
/**
* @brief Pad used of Slave Select
*/
uint8_t sspad;
/**
* @brief SPI Control Register initialization data.
*/
//uint8_t spcr;
SPI_PRESCALER_t prescaler; // Clock divider
SPI_MODE_t mode; // SPI mode 1, 2, ...
bool master; // Master or slave
bool dord; // Data order, LSB or MSB first
bool clk2x; // SPI double speed mode.
SPI_INTLVL_t irqlevel; // SPI interrupt service level
} SPIConfig;
/**
* @brief Structure representing an SPI driver.
* @note Implementations may extend this structure to contain more,
* architecture dependent, fields.
*/
struct SPIDriver {
/**
* @brief Driver state.
*/
spistate_t state;
/**
* @brief Current configuration data.
*/
const SPIConfig *config;
#if SPI_USE_WAIT || defined(__DOXYGEN__)
/**
* @brief Waiting thread.
*/
thread_reference_t thread;
#endif /* SPI_USE_WAIT */
#if SPI_USE_MUTUAL_EXCLUSION || defined(__DOXYGEN__)
/**
* @brief Mutex protecting the bus.
*/
mutex_t mutex;
#endif /* SPI_USE_MUTUAL_EXCLUSION */
#if defined(SPI_DRIVER_EXT_FIELDS)
SPI_DRIVER_EXT_FIELDS
#endif
/* End of the mandatory fields. */
/**
* @brief Pointer to the SPI register module.
*/
SPI_t *spi;
/**
* @brief Pointer to the buffer with data to send.
*/
const uint8_t *txbuf;
/**
* @brief Pointer to the buffer to store received data.
*/
uint8_t *rxbuf;
/**
* @brief Number of bytes of data to exchange.
*/
size_t exbytes;
/**
* @brief Current index in buffer when exchanging data.
*/
size_t exidx;
};
/*==========================================================================*/
/* Driver macros. */
/*==========================================================================*/
/**
* @brief Circular mode support flag.
*/
#define SPI_SUPPORTS_CIRCULAR TRUE
#define spi_lld_driver_fields \
SPI_t *spi; \
const uint8_t *txbuf; \
uint8_t *rxbuf; \
size_t exbytes; \
size_t exidx;
/**
* @brief Low level fields of the SPI configuration structure.
*/
#define spi_lld_config_fields \
SPI_PRESCALER_t prescaler; \
SPI_MODE_t mode; \
bool master; \
bool dord; \
bool clk2x; \
SPI_INTLVL_t irqlevel;
/**
* @brief Ignores data on the SPI bus.
* @details This asynchronous function starts the transmission of a series of
@ -292,6 +219,10 @@ extern "C" {
void spi_lld_exchange(SPIDriver *spip, size_t n,
const void *txbuf, void *rxbuf);
#if (SPI_SUPPORTS_CIRCULAR == TRUE) || defined(__DOXYGEN__)
void spi_lld_abort(SPIDriver *spip);
#endif
//#if AVR_SPI_USE_16BIT_POLLED_EXCHANGE
// uint16_t spi_lld_polled_exchange(SPIDriver *spip, uint16_t frame);
//#else